|
30 | 30 |
|
31 | 31 | #include <sof/notifier.h> |
32 | 32 | #include <sof/sof.h> |
33 | | -#include <sof/lock.h> |
34 | 33 | #include <sof/list.h> |
35 | | - |
36 | | -/* General purpose notifiers */ |
37 | | - |
38 | | -struct notify { |
39 | | - spinlock_t lock; |
40 | | - struct list_item list; /* list of notifiers */ |
41 | | -}; |
42 | | - |
43 | | -static struct notify _notify; |
| 34 | +#include <sof/alloc.h> |
44 | 35 |
|
45 | 36 | void notifier_register(struct notifier *notifier) |
46 | 37 | { |
47 | | - spin_lock(&_notify.lock); |
48 | | - list_item_prepend(¬ifier->list, &_notify.list); |
49 | | - spin_unlock(&_notify.lock); |
| 38 | + struct notify *notify = *arch_notify_get(); |
| 39 | + |
| 40 | + spin_lock(¬ify->lock); |
| 41 | + list_item_prepend(¬ifier->list, ¬ify->list); |
| 42 | + spin_unlock(¬ify->lock); |
50 | 43 | } |
51 | 44 |
|
52 | 45 | void notifier_unregister(struct notifier *notifier) |
53 | 46 | { |
54 | | - spin_lock(&_notify.lock); |
| 47 | + struct notify *notify = *arch_notify_get(); |
| 48 | + |
| 49 | + spin_lock(¬ify->lock); |
55 | 50 | list_item_del(¬ifier->list); |
56 | | - spin_unlock(&_notify.lock); |
| 51 | + spin_unlock(¬ify->lock); |
57 | 52 | } |
58 | 53 |
|
59 | 54 | void notifier_event(int id, int message, void *event_data) |
60 | 55 | { |
| 56 | + struct notify *notify = *arch_notify_get(); |
61 | 57 | struct list_item *wlist; |
62 | 58 | struct notifier *n; |
63 | 59 |
|
64 | | - spin_lock(&_notify.lock); |
| 60 | + spin_lock(¬ify->lock); |
65 | 61 |
|
66 | | - if (list_is_empty(&_notify.list)) |
| 62 | + if (list_is_empty(¬ify->list)) |
67 | 63 | goto out; |
68 | 64 |
|
69 | 65 | /* iterate through notifiers and send event to interested clients */ |
70 | | - list_for_item(wlist, &_notify.list) { |
| 66 | + list_for_item(wlist, ¬ify->list) { |
71 | 67 |
|
72 | 68 | n = container_of(wlist, struct notifier, list); |
73 | 69 | if (n->id == id) |
74 | 70 | n->cb(message, n->cb_data, event_data); |
75 | 71 | } |
76 | 72 |
|
77 | 73 | out: |
78 | | - spin_unlock(&_notify.lock); |
| 74 | + spin_unlock(¬ify->lock); |
79 | 75 | } |
80 | 76 |
|
81 | 77 | void init_system_notify(struct sof *sof) |
82 | 78 | { |
83 | | - list_init(&_notify.list); |
84 | | - spinlock_init(&_notify.lock); |
| 79 | + struct notify **notify = arch_notify_get(); |
| 80 | + *notify = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(**notify)); |
| 81 | + |
| 82 | + list_init(&(*notify)->list); |
| 83 | + spinlock_init(&(*notify)->lock); |
| 84 | +} |
| 85 | + |
| 86 | +void free_system_notify(void) |
| 87 | +{ |
| 88 | + struct notify *notify = *arch_notify_get(); |
| 89 | + |
| 90 | + spin_lock(¬ify->lock); |
| 91 | + list_item_del(¬ify->list); |
| 92 | + spin_unlock(¬ify->lock); |
85 | 93 | } |
0 commit comments