diff options
Diffstat (limited to 'firmware/ata_idle_notify.c')
-rw-r--r-- | firmware/ata_idle_notify.c | 61 |
1 files changed, 9 insertions, 52 deletions
diff --git a/firmware/ata_idle_notify.c b/firmware/ata_idle_notify.c index 1fc6605ac6..a97c3538da 100644 --- a/firmware/ata_idle_notify.c +++ b/firmware/ata_idle_notify.c | |||
@@ -23,60 +23,31 @@ | |||
23 | #include "kernel.h" | 23 | #include "kernel.h" |
24 | #include "string.h" | 24 | #include "string.h" |
25 | 25 | ||
26 | #if USING_ATA_CALLBACK | 26 | void register_ata_idle_func(ata_idle_notify function) |
27 | static ata_idle_notify ata_idle_notify_funcs[MAX_ATA_CALLBACKS]; | ||
28 | static int ata_callback_count = 0; | ||
29 | #endif | ||
30 | |||
31 | |||
32 | bool register_ata_idle_func(ata_idle_notify function) | ||
33 | { | 27 | { |
34 | #if USING_ATA_CALLBACK | 28 | #if USING_ATA_CALLBACK |
35 | int i; | 29 | add_event(DISK_EVENT_SPINUP, function); |
36 | if (ata_callback_count >= MAX_ATA_CALLBACKS) | ||
37 | return false; | ||
38 | for (i=0; i<MAX_ATA_CALLBACKS; i++) | ||
39 | { | ||
40 | if (ata_idle_notify_funcs[i] == NULL) | ||
41 | { | ||
42 | ata_idle_notify_funcs[i] = function; | ||
43 | ata_callback_count++; | ||
44 | return true; | ||
45 | } | ||
46 | else if (ata_idle_notify_funcs[i] == function) | ||
47 | return true; | ||
48 | } | ||
49 | return false; | ||
50 | #else | 30 | #else |
51 | function(); /* just call the function now */ | 31 | function(); /* just call the function now */ |
52 | /* this _may_ cause problems later if the calling function | 32 | /* this _may_ cause problems later if the calling function |
53 | sets a variable expecting the callback to unset it, because | 33 | sets a variable expecting the callback to unset it, because |
54 | the callback will be run before this function exits, so before the var is set */ | 34 | the callback will be run before this function exits, so before the var is set */ |
55 | return true; | ||
56 | #endif | 35 | #endif |
57 | } | 36 | } |
58 | 37 | ||
59 | #if USING_ATA_CALLBACK | 38 | #if USING_ATA_CALLBACK |
60 | void unregister_ata_idle_func(ata_idle_notify func, bool run) | 39 | void unregister_ata_idle_func(ata_idle_notify func, bool run) |
61 | { | 40 | { |
62 | int i; | 41 | remove_event(DISK_EVENT_SPINUP, func); |
63 | for (i=0; i<MAX_ATA_CALLBACKS; i++) | 42 | |
64 | { | 43 | if (run) |
65 | if (ata_idle_notify_funcs[i] == func) | 44 | func(); |
66 | { | ||
67 | ata_idle_notify_funcs[i] = NULL; | ||
68 | ata_callback_count--; | ||
69 | if (run) func(); | ||
70 | } | ||
71 | } | ||
72 | return; | ||
73 | } | 45 | } |
74 | 46 | ||
75 | bool call_ata_idle_notifys(bool force) | 47 | bool call_ata_idle_notifys(bool force) |
76 | { | 48 | { |
77 | int i; | ||
78 | static int lock_until = 0; | 49 | static int lock_until = 0; |
79 | ata_idle_notify function; | 50 | |
80 | if (!force) | 51 | if (!force) |
81 | { | 52 | { |
82 | if (TIME_BEFORE(current_tick,lock_until) ) | 53 | if (TIME_BEFORE(current_tick,lock_until) ) |
@@ -84,22 +55,8 @@ bool call_ata_idle_notifys(bool force) | |||
84 | } | 55 | } |
85 | lock_until = current_tick + 30*HZ; | 56 | lock_until = current_tick + 30*HZ; |
86 | 57 | ||
87 | for (i = 0; i < MAX_ATA_CALLBACKS; i++) | 58 | send_event(DISK_EVENT_SPINUP, true, NULL); |
88 | { | 59 | |
89 | if (ata_idle_notify_funcs[i]) | ||
90 | { | ||
91 | function = ata_idle_notify_funcs[i]; | ||
92 | ata_idle_notify_funcs[i] = NULL; | ||
93 | function(); | ||
94 | ata_callback_count--; | ||
95 | } | ||
96 | } | ||
97 | return true; | 60 | return true; |
98 | } | 61 | } |
99 | |||
100 | void ata_idle_notify_init(void) | ||
101 | { | ||
102 | ata_callback_count = 0; | ||
103 | memset(ata_idle_notify_funcs, 0, sizeof(ata_idle_notify_funcs)); | ||
104 | } | ||
105 | #endif | 62 | #endif |