Rev 2307 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2307 | Rev 2456 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2006 Jakub Jermar |
3 | * Copyright (c) 2006 Jakub Jermar |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup genericipc |
30 | /** @addtogroup genericipc |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | * @brief IRQ notification framework. |
35 | * @brief IRQ notification framework. |
36 | * |
36 | * |
37 | * This framework allows applications to register to receive a notification |
37 | * This framework allows applications to register to receive a notification |
38 | * when interrupt is detected. The application may provide a simple 'top-half' |
38 | * when interrupt is detected. The application may provide a simple 'top-half' |
39 | * handler as part of its registration, which can perform simple operations |
39 | * handler as part of its registration, which can perform simple operations |
40 | * (read/write port/memory, add information to notification ipc message). |
40 | * (read/write port/memory, add information to notification ipc message). |
41 | * |
41 | * |
42 | * The structure of a notification message is as follows: |
42 | * The structure of a notification message is as follows: |
43 | * - METHOD: method as registered by the SYS_IPC_REGISTER_IRQ syscall |
43 | * - METHOD: method as registered by the SYS_IPC_REGISTER_IRQ syscall |
44 | * - ARG1: payload modified by a 'top-half' handler |
44 | * - ARG1: payload modified by a 'top-half' handler |
45 | * - ARG2: payload modified by a 'top-half' handler |
45 | * - ARG2: payload modified by a 'top-half' handler |
46 | * - ARG3: payload modified by a 'top-half' handler |
46 | * - ARG3: payload modified by a 'top-half' handler |
47 | * - in_phone_hash: interrupt counter (may be needed to assure correct order |
47 | * - in_phone_hash: interrupt counter (may be needed to assure correct order |
48 | * in multithreaded drivers) |
48 | * in multithreaded drivers) |
49 | */ |
49 | */ |
50 | 50 | ||
51 | #include <arch.h> |
51 | #include <arch.h> |
52 | #include <mm/slab.h> |
52 | #include <mm/slab.h> |
53 | #include <errno.h> |
53 | #include <errno.h> |
54 | #include <ddi/irq.h> |
54 | #include <ddi/irq.h> |
55 | #include <ipc/ipc.h> |
55 | #include <ipc/ipc.h> |
56 | #include <ipc/irq.h> |
56 | #include <ipc/irq.h> |
57 | #include <syscall/copy.h> |
57 | #include <syscall/copy.h> |
58 | #include <console/console.h> |
58 | #include <console/console.h> |
59 | #include <print.h> |
59 | #include <print.h> |
- | 60 | #include <synch/rcu.h> |
|
- | 61 | #include <adt/listrcu.h> |
|
60 | 62 | ||
61 | /** Execute code associated with IRQ notification. |
63 | /** Execute code associated with IRQ notification. |
62 | * |
64 | * |
63 | * @param call Notification call. |
65 | * @param call Notification call. |
64 | * @param code Top-half pseudocode. |
66 | * @param code Top-half pseudocode. |
65 | */ |
67 | */ |
66 | static void code_execute(call_t *call, irq_code_t *code) |
68 | static void code_execute(call_t *call, irq_code_t *code) |
67 | { |
69 | { |
68 | int i; |
70 | int i; |
69 | unative_t dstval = 0; |
71 | unative_t dstval = 0; |
70 | 72 | ||
71 | if (!code) |
73 | if (!code) |
72 | return; |
74 | return; |
73 | 75 | ||
74 | for (i=0; i < code->cmdcount;i++) { |
76 | for (i=0; i < code->cmdcount;i++) { |
75 | switch (code->cmds[i].cmd) { |
77 | switch (code->cmds[i].cmd) { |
76 | case CMD_MEM_READ_1: |
78 | case CMD_MEM_READ_1: |
77 | dstval = *((uint8_t *)code->cmds[i].addr); |
79 | dstval = *((uint8_t *)code->cmds[i].addr); |
78 | break; |
80 | break; |
79 | case CMD_MEM_READ_2: |
81 | case CMD_MEM_READ_2: |
80 | dstval = *((uint16_t *)code->cmds[i].addr); |
82 | dstval = *((uint16_t *)code->cmds[i].addr); |
81 | break; |
83 | break; |
82 | case CMD_MEM_READ_4: |
84 | case CMD_MEM_READ_4: |
83 | dstval = *((uint32_t *)code->cmds[i].addr); |
85 | dstval = *((uint32_t *)code->cmds[i].addr); |
84 | break; |
86 | break; |
85 | case CMD_MEM_READ_8: |
87 | case CMD_MEM_READ_8: |
86 | dstval = *((uint64_t *)code->cmds[i].addr); |
88 | dstval = *((uint64_t *)code->cmds[i].addr); |
87 | break; |
89 | break; |
88 | case CMD_MEM_WRITE_1: |
90 | case CMD_MEM_WRITE_1: |
89 | *((uint8_t *)code->cmds[i].addr) = code->cmds[i].value; |
91 | *((uint8_t *)code->cmds[i].addr) = code->cmds[i].value; |
90 | break; |
92 | break; |
91 | case CMD_MEM_WRITE_2: |
93 | case CMD_MEM_WRITE_2: |
92 | *((uint16_t *)code->cmds[i].addr) = code->cmds[i].value; |
94 | *((uint16_t *)code->cmds[i].addr) = code->cmds[i].value; |
93 | break; |
95 | break; |
94 | case CMD_MEM_WRITE_4: |
96 | case CMD_MEM_WRITE_4: |
95 | *((uint32_t *)code->cmds[i].addr) = code->cmds[i].value; |
97 | *((uint32_t *)code->cmds[i].addr) = code->cmds[i].value; |
96 | break; |
98 | break; |
97 | case CMD_MEM_WRITE_8: |
99 | case CMD_MEM_WRITE_8: |
98 | *((uint64_t *)code->cmds[i].addr) = code->cmds[i].value; |
100 | *((uint64_t *)code->cmds[i].addr) = code->cmds[i].value; |
99 | break; |
101 | break; |
100 | #if defined(ia32) || defined(amd64) |
102 | #if defined(ia32) || defined(amd64) |
101 | case CMD_PORT_READ_1: |
103 | case CMD_PORT_READ_1: |
102 | dstval = inb((long)code->cmds[i].addr); |
104 | dstval = inb((long)code->cmds[i].addr); |
103 | break; |
105 | break; |
104 | case CMD_PORT_WRITE_1: |
106 | case CMD_PORT_WRITE_1: |
105 | outb((long)code->cmds[i].addr, code->cmds[i].value); |
107 | outb((long)code->cmds[i].addr, code->cmds[i].value); |
106 | break; |
108 | break; |
107 | #endif |
109 | #endif |
108 | #if defined(ia64) && defined(SKI) |
110 | #if defined(ia64) && defined(SKI) |
109 | case CMD_IA64_GETCHAR: |
111 | case CMD_IA64_GETCHAR: |
110 | dstval = _getc(&ski_uconsole); |
112 | dstval = _getc(&ski_uconsole); |
111 | break; |
113 | break; |
112 | #endif |
114 | #endif |
113 | #if defined(ppc32) |
115 | #if defined(ppc32) |
114 | case CMD_PPC32_GETCHAR: |
116 | case CMD_PPC32_GETCHAR: |
115 | dstval = cuda_get_scancode(); |
117 | dstval = cuda_get_scancode(); |
116 | break; |
118 | break; |
117 | #endif |
119 | #endif |
118 | default: |
120 | default: |
119 | break; |
121 | break; |
120 | } |
122 | } |
121 | if (code->cmds[i].dstarg && code->cmds[i].dstarg < 4) { |
123 | if (code->cmds[i].dstarg && code->cmds[i].dstarg < 4) { |
122 | call->data.args[code->cmds[i].dstarg] = dstval; |
124 | call->data.args[code->cmds[i].dstarg] = dstval; |
123 | } |
125 | } |
124 | } |
126 | } |
125 | } |
127 | } |
126 | 128 | ||
127 | static void code_free(irq_code_t *code) |
129 | static void code_free(irq_code_t *code) |
128 | { |
130 | { |
129 | if (code) { |
131 | if (code) { |
130 | free(code->cmds); |
132 | free(code->cmds); |
131 | free(code); |
133 | free(code); |
132 | } |
134 | } |
133 | } |
135 | } |
134 | 136 | ||
135 | static irq_code_t * code_from_uspace(irq_code_t *ucode) |
137 | static irq_code_t * code_from_uspace(irq_code_t *ucode) |
136 | { |
138 | { |
137 | irq_code_t *code; |
139 | irq_code_t *code; |
138 | irq_cmd_t *ucmds; |
140 | irq_cmd_t *ucmds; |
139 | int rc; |
141 | int rc; |
140 | 142 | ||
141 | code = malloc(sizeof(*code), 0); |
143 | code = malloc(sizeof(*code), 0); |
142 | rc = copy_from_uspace(code, ucode, sizeof(*code)); |
144 | rc = copy_from_uspace(code, ucode, sizeof(*code)); |
143 | if (rc != 0) { |
145 | if (rc != 0) { |
144 | free(code); |
146 | free(code); |
145 | return NULL; |
147 | return NULL; |
146 | } |
148 | } |
147 | 149 | ||
148 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) { |
150 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) { |
149 | free(code); |
151 | free(code); |
150 | return NULL; |
152 | return NULL; |
151 | } |
153 | } |
152 | ucmds = code->cmds; |
154 | ucmds = code->cmds; |
153 | code->cmds = malloc(sizeof(code->cmds[0]) * (code->cmdcount), 0); |
155 | code->cmds = malloc(sizeof(code->cmds[0]) * (code->cmdcount), 0); |
154 | rc = copy_from_uspace(code->cmds, ucmds, sizeof(code->cmds[0]) * (code->cmdcount)); |
156 | rc = copy_from_uspace(code->cmds, ucmds, sizeof(code->cmds[0]) * (code->cmdcount)); |
155 | if (rc != 0) { |
157 | if (rc != 0) { |
156 | free(code->cmds); |
158 | free(code->cmds); |
157 | free(code); |
159 | free(code); |
158 | return NULL; |
160 | return NULL; |
159 | } |
161 | } |
160 | 162 | ||
161 | return code; |
163 | return code; |
162 | } |
164 | } |
163 | 165 | ||
164 | /** Unregister task from IRQ notification. |
166 | /** Unregister task from IRQ notification. |
165 | * |
167 | * |
166 | * @param box Answerbox associated with the notification. |
168 | * @param box Answerbox associated with the notification. |
167 | * @param inr IRQ numbe. |
169 | * @param inr IRQ numbe. |
168 | * @param devno Device number. |
170 | * @param devno Device number. |
169 | */ |
171 | */ |
170 | void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno) |
172 | void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno) |
171 | { |
173 | { |
172 | ipl_t ipl; |
174 | ipl_t ipl; |
173 | irq_t *irq; |
175 | irq_t *irq; |
- | 176 | ipc_notif_cfg_t *new_notify, *old_notify; |
|
174 | 177 | ||
175 | ipl = interrupts_disable(); |
178 | ipl = interrupts_disable(); |
176 | irq = irq_find_and_lock(inr, devno); |
179 | irq = irq_find_and_lock(inr, devno); |
177 | if (irq) { |
180 | if (irq) { |
178 | if (irq->notif_cfg.answerbox == box) { |
181 | if (rcu_dereference_pointer(irq->notif_cfg).answerbox == box) { |
179 | code_free(irq->notif_cfg.code); |
182 | new_notify = malloc(sizeof(ipc_notif_cfg_t),0); |
- | 183 | ||
180 | irq->notif_cfg.notify = false; |
184 | new_notify->notify = false; |
181 | irq->notif_cfg.answerbox = NULL; |
185 | new_notify->answerbox = NULL; |
182 | irq->notif_cfg.code = NULL; |
186 | new_notify->code = NULL; |
183 | irq->notif_cfg.method = 0; |
187 | new_notify->method = 0; |
184 | irq->notif_cfg.counter = 0; |
188 | new_notify->counter = 0; |
- | 189 | old_notify = irq->notif_cfg; |
|
- | 190 | copy_link_rcu(&irq->notif_cfg->link, &new_notify->link); |
|
- | 191 | rcu_assign_pointer(old_notify, new_notify); |
|
185 | 192 | ||
186 | spinlock_lock(&box->irq_lock); |
193 | spinlock_lock(&box->irq_lock); |
187 | list_remove(&irq->notif_cfg.link); |
194 | list_remove_rcu(&rcu_dereference_pointer(irq->notif_cfg).link); |
188 | spinlock_unlock(&box->irq_lock); |
195 | spinlock_unlock(&box->irq_lock); |
- | 196 | rcu_sync_callback_normal_alloc(&ipc_notif_free_callback, irq->notif_cfg); |
|
189 | 197 | ||
190 | spinlock_unlock(&irq->lock); |
198 | spinlock_unlock(&irq->lock); |
191 | } |
199 | } |
192 | } |
200 | } |
193 | interrupts_restore(ipl); |
201 | interrupts_restore(ipl); |
194 | } |
202 | } |
195 | 203 | ||
- | 204 | void ipc_notif_free_callback(void* notif) |
|
- | 205 | { |
|
- | 206 | code_free(((ipc_notif_cfg_t *)notif)->code); |
|
- | 207 | free(notif); |
|
- | 208 | ||
- | 209 | } |
|
- | 210 | ||
196 | /** Register an answerbox as a receiving end for IRQ notifications. |
211 | /** Register an answerbox as a receiving end for IRQ notifications. |
197 | * |
212 | * |
198 | * @param box Receiving answerbox. |
213 | * @param box Receiving answerbox. |
199 | * @param inr IRQ number. |
214 | * @param inr IRQ number. |
200 | * @param devno Device number. |
215 | * @param devno Device number. |
201 | * @param method Method to be associated with the notification. |
216 | * @param method Method to be associated with the notification. |
202 | * @param ucode Uspace pointer to top-half pseudocode. |
217 | * @param ucode Uspace pointer to top-half pseudocode. |
203 | * |
218 | * |
204 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
219 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
205 | */ |
220 | */ |
206 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode) |
221 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode) |
207 | { |
222 | { |
208 | ipl_t ipl; |
223 | ipl_t ipl; |
209 | irq_code_t *code; |
224 | irq_code_t *code; |
210 | irq_t *irq; |
225 | irq_t *irq; |
- | 226 | ipc_notif_cfg_t *new_notify, *old_notify; |
|
211 | 227 | ||
212 | if (ucode) { |
228 | if (ucode) { |
213 | code = code_from_uspace(ucode); |
229 | code = code_from_uspace(ucode); |
214 | if (!code) |
230 | if (!code) |
215 | return EBADMEM; |
231 | return EBADMEM; |
216 | } else |
232 | } else |
217 | code = NULL; |
233 | code = NULL; |
218 | 234 | ||
219 | ipl = interrupts_disable(); |
235 | ipl = interrupts_disable(); |
220 | irq = irq_find_and_lock(inr, devno); |
236 | irq = irq_find_and_lock(inr, devno); |
221 | if (!irq) { |
237 | if (!irq) { |
222 | interrupts_restore(ipl); |
238 | interrupts_restore(ipl); |
223 | code_free(code); |
239 | code_free(code); |
224 | return ENOENT; |
240 | return ENOENT; |
225 | } |
241 | } |
226 | 242 | ||
227 | if (irq->notif_cfg.answerbox) { |
243 | if (rcu_dereference_pointer(irq->notif_cfg).answerbox) { |
228 | spinlock_unlock(&irq->lock); |
244 | spinlock_unlock(&irq->lock); |
229 | interrupts_restore(ipl); |
245 | interrupts_restore(ipl); |
230 | code_free(code); |
246 | code_free(code); |
231 | return EEXISTS; |
247 | return EEXISTS; |
232 | } |
248 | } |
233 | - | ||
- | 249 | new_notify = malloc(sizeof(ipc_notif_cfg_t),0); |
|
234 | irq->notif_cfg.notify = true; |
250 | new_notify->notify = true; |
235 | irq->notif_cfg.answerbox = box; |
251 | new_notify->answerbox = box; |
236 | irq->notif_cfg.method = method; |
252 | new_notify->method = method; |
237 | irq->notif_cfg.code = code; |
253 | new_notify->code = code; |
238 | irq->notif_cfg.counter = 0; |
254 | new_notify->counter = 0; |
- | 255 | copy_link_rcu(&irq->notif_cfg->link, &new_notify->link); |
|
- | 256 | old_notify = irq->notif_cfg; |
|
- | 257 | rcu_assign_pointer(irq->notif_cfg, new_notify); |
|
- | 258 | rcu_sync_callback_normal_alloc(&ipc_notif_free_callback, old_notify); |
|
239 | 259 | ||
240 | spinlock_lock(&box->irq_lock); |
260 | spinlock_lock(&box->irq_lock); |
241 | list_append(&irq->notif_cfg.link, &box->irq_head); |
261 | list_append_rcu(&new_notify->link, &box->irq_head); |
242 | spinlock_unlock(&box->irq_lock); |
262 | spinlock_unlock(&box->irq_lock); |
243 | 263 | ||
244 | spinlock_unlock(&irq->lock); |
264 | spinlock_unlock(&irq->lock); |
245 | interrupts_restore(ipl); |
265 | interrupts_restore(ipl); |
246 | 266 | ||
247 | return 0; |
267 | return 0; |
248 | } |
268 | } |
249 | 269 | ||
250 | /** Add call to proper answerbox queue. |
270 | /** Add call to proper answerbox queue. |
251 | * |
271 | * |
252 | * Assume irq->lock is locked. |
272 | * Assume irq->lock is locked. |
253 | * |
273 | * |
254 | */ |
274 | */ |
255 | static void send_call(irq_t *irq, call_t *call) |
275 | static void send_call(irq_t *irq, call_t *call) |
256 | { |
276 | { |
257 | spinlock_lock(&irq->notif_cfg.answerbox->irq_lock); |
277 | spinlock_lock(&rcu_dereference_pointer(irq->notif_cfg).answerbox->irq_lock); |
258 | list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs); |
278 | list_append_rcu(&call->link, &rcu_dereference_pointer(irq->notif_cfg).answerbox->irq_notifs); |
259 | spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock); |
279 | spinlock_unlock(&rcu_dereference_pointer(irq->notif_cfg).answerbox->irq_lock); |
260 | 280 | ||
261 | waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST); |
281 | waitq_wakeup(&rcu_dereference_pointer(irq->notif_cfg).answerbox->wq, WAKEUP_FIRST); |
262 | } |
282 | } |
263 | 283 | ||
264 | /** Send notification message |
284 | /** Send notification message |
265 | * |
285 | * |
266 | */ |
286 | */ |
267 | void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3) |
287 | void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3) |
268 | { |
288 | { |
269 | call_t *call; |
289 | call_t *call; |
270 | 290 | ||
271 | spinlock_lock(&irq->lock); |
291 | spinlock_lock(&irq->lock); |
272 | 292 | ||
273 | if (irq->notif_cfg.answerbox) { |
293 | if (rcu_dereference_pointer(irq->notif_cfg).answerbox) { |
274 | call = ipc_call_alloc(FRAME_ATOMIC); |
294 | call = ipc_call_alloc(FRAME_ATOMIC); |
275 | if (!call) { |
295 | if (!call) { |
276 | spinlock_unlock(&irq->lock); |
296 | spinlock_unlock(&irq->lock); |
277 | return; |
297 | return; |
278 | } |
298 | } |
279 | call->flags |= IPC_CALL_NOTIF; |
299 | call->flags |= IPC_CALL_NOTIF; |
280 | IPC_SET_METHOD(call->data, irq->notif_cfg.method); |
300 | IPC_SET_METHOD(call->data, rcu_dereference_pointer(irq->notif_cfg).method); |
281 | IPC_SET_ARG1(call->data, a1); |
301 | IPC_SET_ARG1(call->data, a1); |
282 | IPC_SET_ARG2(call->data, a2); |
302 | IPC_SET_ARG2(call->data, a2); |
283 | IPC_SET_ARG3(call->data, a3); |
303 | IPC_SET_ARG3(call->data, a3); |
284 | /* Put a counter to the message */ |
304 | /* Put a counter to the message */ |
285 | call->priv = ++irq->notif_cfg.counter; |
305 | call->priv = ++rcu_dereference_pointer(irq->notif_cfg).counter; |
286 | 306 | ||
287 | send_call(irq, call); |
307 | send_call(irq, call); |
288 | } |
308 | } |
289 | spinlock_unlock(&irq->lock); |
309 | spinlock_unlock(&irq->lock); |
290 | } |
310 | } |
291 | 311 | ||
292 | /** Notify task that an irq had occurred. |
312 | /** Notify task that an irq had occurred. |
293 | * |
313 | * |
294 | * We expect interrupts to be disabled and the irq->lock already held. |
314 | * We expect interrupts to be disabled and the irq->lock already held. |
295 | */ |
315 | */ |
296 | void ipc_irq_send_notif(irq_t *irq) |
316 | void ipc_irq_send_notif(irq_t *irq) |
297 | { |
317 | { |
298 | call_t *call; |
318 | call_t *call; |
299 | 319 | ||
300 | ASSERT(irq); |
320 | ASSERT(irq); |
301 | 321 | ||
302 | if (irq->notif_cfg.answerbox) { |
322 | if (rcu_dereference_pointer(irq->notif_cfg).answerbox) { |
303 | call = ipc_call_alloc(FRAME_ATOMIC); |
323 | call = ipc_call_alloc(FRAME_ATOMIC); |
304 | if (!call) { |
324 | if (!call) { |
305 | return; |
325 | return; |
306 | } |
326 | } |
307 | call->flags |= IPC_CALL_NOTIF; |
327 | call->flags |= IPC_CALL_NOTIF; |
308 | /* Put a counter to the message */ |
328 | /* Put a counter to the message */ |
309 | call->priv = ++irq->notif_cfg.counter; |
329 | call->priv = ++rcu_dereference_pointer(irq->notif_cfg).counter; |
310 | /* Set up args */ |
330 | /* Set up args */ |
311 | IPC_SET_METHOD(call->data, irq->notif_cfg.method); |
331 | IPC_SET_METHOD(call->data, rcu_dereference_pointer(irq->notif_cfg).method); |
312 | 332 | ||
313 | /* Execute code to handle irq */ |
333 | /* Execute code to handle irq */ |
314 | code_execute(call, irq->notif_cfg.code); |
334 | code_execute(call, rcu_dereference_pointer(irq->notif_cfg).code); |
315 | 335 | ||
316 | send_call(irq, call); |
336 | send_call(irq, call); |
317 | } |
337 | } |
318 | } |
338 | } |
319 | 339 | ||
320 | /** Disconnect all IRQ notifications from an answerbox. |
340 | /** Disconnect all IRQ notifications from an answerbox. |
321 | * |
341 | * |
322 | * This function is effective because the answerbox contains |
342 | * This function is effective because the answerbox contains |
323 | * list of all irq_t structures that are registered to |
343 | * list of all irq_t structures that are registered to |
324 | * send notifications to it. |
344 | * send notifications to it. |
325 | * |
345 | * |
326 | * @param box Answerbox for which we want to carry out the cleanup. |
346 | * @param box Answerbox for which we want to carry out the cleanup. |
327 | */ |
347 | */ |
328 | void ipc_irq_cleanup(answerbox_t *box) |
348 | void ipc_irq_cleanup(answerbox_t *box) |
329 | { |
349 | { |
330 | ipl_t ipl; |
350 | ipl_t ipl; |
- | 351 | ipc_notif_cfg_t *new_notify, *old_notify; |
|
331 | 352 | ||
332 | loop: |
353 | loop: |
333 | ipl = interrupts_disable(); |
354 | ipl = interrupts_disable(); |
334 | spinlock_lock(&box->irq_lock); |
355 | spinlock_lock(&box->irq_lock); |
335 | 356 | ||
336 | while (box->irq_head.next != &box->irq_head) { |
357 | while (box->irq_head.next != &box->irq_head) { |
337 | link_t *cur = box->irq_head.next; |
358 | link_t *cur = box->irq_head.next; |
338 | irq_t *irq; |
359 | irq_t *irq; |
339 | DEADLOCK_PROBE_INIT(p_irqlock); |
360 | DEADLOCK_PROBE_INIT(p_irqlock); |
340 | 361 | ||
341 | irq = list_get_instance(cur, irq_t, notif_cfg.link); |
362 | irq = list_get_instance(cur, irq_t, notif_cfg->link); |
342 | if (!spinlock_trylock(&irq->lock)) { |
363 | if (!spinlock_trylock(&irq->lock)) { |
343 | /* |
364 | /* |
344 | * Avoid deadlock by trying again. |
365 | * Avoid deadlock by trying again. |
345 | */ |
366 | */ |
346 | spinlock_unlock(&box->irq_lock); |
367 | spinlock_unlock(&box->irq_lock); |
347 | interrupts_restore(ipl); |
368 | interrupts_restore(ipl); |
348 | DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD); |
369 | DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD); |
349 | goto loop; |
370 | goto loop; |
350 | } |
371 | } |
351 | 372 | ||
352 | ASSERT(irq->notif_cfg.answerbox == box); |
373 | ASSERT(irq->notif_cfg->answerbox == box); |
353 | 374 | ||
354 | list_remove(&irq->notif_cfg.link); |
375 | list_remove_rcu(&irq->notif_cfg->link); |
355 | 376 | ||
356 | /* |
- | |
357 | * Don't forget to free any top-half pseudocode. |
377 | new_notify = malloc(sizeof(ipc_notif_cfg_t),0); |
358 | */ |
- | |
359 | code_free(irq->notif_cfg.code); |
378 | new_notify->notify = false; |
360 | - | ||
361 | irq->notif_cfg.notify = false; |
379 | new_notify->answerbox = NULL; |
362 | irq->notif_cfg.answerbox = NULL; |
380 | new_notify->method = 0; |
363 | irq->notif_cfg.code = NULL; |
381 | new_notify->code = NULL; |
364 | irq->notif_cfg.method = 0; |
382 | new_notify->counter = 0; |
- | 383 | copy_link_rcu(&irq->notif_cfg->link, &new_notify->link); |
|
365 | irq->notif_cfg.counter = 0; |
384 | old_notify = irq->notif_cfg; |
- | 385 | rcu_assign_pointer(irq->notif_cfg, new_notify); |
|
- | 386 | rcu_sync_callback_normal_alloc(&ipc_notif_free_callback, old_notify); |
|
366 | 387 | ||
- | 388 | ||
367 | spinlock_unlock(&irq->lock); |
389 | spinlock_unlock(&irq->lock); |
368 | } |
390 | } |
369 | 391 | ||
370 | spinlock_unlock(&box->irq_lock); |
392 | spinlock_unlock(&box->irq_lock); |
371 | interrupts_restore(ipl); |
393 | interrupts_restore(ipl); |
372 | } |
394 | } |
373 | 395 | ||
374 | /** @} |
396 | /** @} |
375 | */ |
397 | */ |
376 | 398 |