Rev 4252 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4252 | Rev 4348 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Jakub Jermar |
2 | * Copyright (c) 2009 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup generic |
29 | /** @addtogroup generic |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief Kernel event notifications. |
34 | * @brief Kernel event notifications. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <ipc/event.h> |
37 | #include <ipc/event.h> |
38 | #include <ipc/event_types.h> |
38 | #include <ipc/event_types.h> |
39 | #include <mm/slab.h> |
39 | #include <mm/slab.h> |
40 | #include <arch/types.h> |
40 | #include <arch/types.h> |
41 | #include <synch/spinlock.h> |
41 | #include <synch/spinlock.h> |
42 | #include <console/console.h> |
42 | #include <console/console.h> |
43 | #include <memstr.h> |
43 | #include <memstr.h> |
44 | #include <errno.h> |
44 | #include <errno.h> |
45 | #include <arch.h> |
45 | #include <arch.h> |
46 | 46 | ||
47 | /** |
47 | /** |
48 | * The events array. |
48 | * The events array. |
49 | * Arranging the events in this two-dimensional array should decrease the |
49 | * Arranging the events in this two-dimensional array should decrease the |
50 | * likelyhood of cacheline ping-pong. |
50 | * likelyhood of cacheline ping-pong. |
51 | */ |
51 | */ |
52 | static event_t events[EVENT_END]; |
52 | static event_t events[EVENT_END]; |
53 | 53 | ||
54 | /** Initialize kernel events. */ |
54 | /** Initialize kernel events. */ |
55 | void event_init(void) |
55 | void event_init(void) |
56 | { |
56 | { |
57 | unsigned int i; |
57 | unsigned int i; |
58 | 58 | ||
59 | for (i = 0; i < EVENT_END; i++) { |
59 | for (i = 0; i < EVENT_END; i++) { |
60 | spinlock_initialize(&events[i].lock, "event.lock"); |
60 | spinlock_initialize(&events[i].lock, "event.lock"); |
61 | events[i].answerbox = NULL; |
61 | events[i].answerbox = NULL; |
62 | events[i].counter = 0; |
62 | events[i].counter = 0; |
63 | events[i].method = 0; |
63 | events[i].method = 0; |
64 | } |
64 | } |
65 | } |
65 | } |
66 | 66 | ||
67 | static int |
67 | static int |
68 | event_subscribe(event_type_t evno, unative_t method, answerbox_t *answerbox) |
68 | event_subscribe(event_type_t evno, unative_t method, answerbox_t *answerbox) |
69 | { |
69 | { |
70 | if (evno >= EVENT_END) |
70 | if (evno >= EVENT_END) |
71 | return ELIMIT; |
71 | return ELIMIT; |
72 | 72 | ||
73 | spinlock_lock(&events[evno].lock); |
73 | spinlock_lock(&events[evno].lock); |
74 | 74 | ||
75 | int res; |
75 | int res; |
76 | 76 | ||
77 | if (events[evno].answerbox == NULL) { |
77 | if (events[evno].answerbox == NULL) { |
78 | events[evno].answerbox = answerbox; |
78 | events[evno].answerbox = answerbox; |
79 | events[evno].method = method; |
79 | events[evno].method = method; |
80 | events[evno].counter = 0; |
80 | events[evno].counter = 0; |
81 | res = EOK; |
81 | res = EOK; |
82 | } else |
82 | } else |
83 | res = EEXISTS; |
83 | res = EEXISTS; |
84 | 84 | ||
85 | spinlock_unlock(&events[evno].lock); |
85 | spinlock_unlock(&events[evno].lock); |
86 | 86 | ||
87 | return res; |
87 | return res; |
88 | } |
88 | } |
89 | 89 | ||
90 | unative_t sys_event_subscribe(unative_t evno, unative_t method) |
90 | unative_t sys_event_subscribe(unative_t evno, unative_t method) |
91 | { |
91 | { |
92 | return (unative_t) event_subscribe((event_type_t) evno, (unative_t) |
92 | return (unative_t) event_subscribe((event_type_t) evno, (unative_t) |
93 | method, &TASK->answerbox); |
93 | method, &TASK->answerbox); |
94 | } |
94 | } |
95 | 95 | ||
96 | bool event_is_subscribed(event_type_t evno) |
96 | bool event_is_subscribed(event_type_t evno) |
97 | { |
97 | { |
98 | bool res; |
98 | bool res; |
99 | 99 | ||
100 | ASSERT(evno < EVENT_END); |
100 | ASSERT(evno < EVENT_END); |
101 | 101 | ||
102 | spinlock_lock(&events[evno].lock); |
102 | spinlock_lock(&events[evno].lock); |
103 | res = events[evno].answerbox != NULL; |
103 | res = events[evno].answerbox != NULL; |
104 | spinlock_unlock(&events[evno].lock); |
104 | spinlock_unlock(&events[evno].lock); |
105 | 105 | ||
106 | return res; |
106 | return res; |
107 | } |
107 | } |
108 | 108 | ||
109 | 109 | ||
110 | void event_cleanup_answerbox(answerbox_t *answerbox) |
110 | void event_cleanup_answerbox(answerbox_t *answerbox) |
111 | { |
111 | { |
112 | unsigned int i; |
112 | unsigned int i; |
113 | 113 | ||
114 | for (i = 0; i < EVENT_END; i++) { |
114 | for (i = 0; i < EVENT_END; i++) { |
115 | spinlock_lock(&events[i].lock); |
115 | spinlock_lock(&events[i].lock); |
116 | if (events[i].answerbox == answerbox) { |
116 | if (events[i].answerbox == answerbox) { |
117 | events[i].answerbox = NULL; |
117 | events[i].answerbox = NULL; |
118 | events[i].counter = 0; |
118 | events[i].counter = 0; |
119 | events[i].method = 0; |
119 | events[i].method = 0; |
120 | } |
120 | } |
121 | spinlock_unlock(&events[i].lock); |
121 | spinlock_unlock(&events[i].lock); |
122 | } |
122 | } |
123 | } |
123 | } |
124 | 124 | ||
125 | void |
125 | void |
126 | event_notify(event_type_t evno, unative_t a1, unative_t a2, unative_t a3, |
126 | event_notify(event_type_t evno, unative_t a1, unative_t a2, unative_t a3, |
127 | unative_t a4, unative_t a5) |
127 | unative_t a4, unative_t a5) |
128 | { |
128 | { |
129 | ASSERT(evno < EVENT_END); |
129 | ASSERT(evno < EVENT_END); |
130 | 130 | ||
131 | spinlock_lock(&events[evno].lock); |
131 | spinlock_lock(&events[evno].lock); |
132 | if (events[evno].answerbox != NULL) { |
132 | if (events[evno].answerbox != NULL) { |
133 | call_t *call = ipc_call_alloc(FRAME_ATOMIC); |
133 | call_t *call = ipc_call_alloc(FRAME_ATOMIC); |
134 | if (call) { |
134 | if (call) { |
135 | call->flags |= IPC_CALL_NOTIF; |
135 | call->flags |= IPC_CALL_NOTIF; |
136 | call->priv = ++events[evno].counter; |
136 | call->priv = ++events[evno].counter; |
137 | IPC_SET_METHOD(call->data, events[evno].method); |
137 | IPC_SET_METHOD(call->data, events[evno].method); |
138 | IPC_SET_ARG1(call->data, a1); |
138 | IPC_SET_ARG1(call->data, a1); |
139 | IPC_SET_ARG2(call->data, a2); |
139 | IPC_SET_ARG2(call->data, a2); |
140 | IPC_SET_ARG3(call->data, a3); |
140 | IPC_SET_ARG3(call->data, a3); |
141 | IPC_SET_ARG4(call->data, a4); |
141 | IPC_SET_ARG4(call->data, a4); |
142 | IPC_SET_ARG5(call->data, a5); |
142 | IPC_SET_ARG5(call->data, a5); |
143 | 143 | ||
144 | spinlock_lock(&events[evno].answerbox->irq_lock); |
144 | spinlock_lock(&events[evno].answerbox->irq_lock); |
145 | list_append(&call->link, &events[evno].answerbox->irq_notifs); |
145 | list_append(&call->link, &events[evno].answerbox->irq_notifs); |
146 | spinlock_unlock(&events[evno].answerbox->irq_lock); |
146 | spinlock_unlock(&events[evno].answerbox->irq_lock); |
147 | 147 | ||
148 | waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST); |
148 | waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST); |
149 | } |
149 | } |
150 | } |
150 | } |
151 | spinlock_unlock(&events[evno].lock); |
151 | spinlock_unlock(&events[evno].lock); |
152 | } |
152 | } |
153 | 153 | ||
154 | /** @} |
154 | /** @} |
155 | */ |
155 | */ |
156 | 156 |