Rev 2471 | Rev 2745 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2471 | Rev 2626 | ||
---|---|---|---|
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 | 60 | ||
61 | /** Execute code associated with IRQ notification. |
61 | /** Execute code associated with IRQ notification. |
62 | * |
62 | * |
63 | * @param call Notification call. |
63 | * @param call Notification call. |
64 | * @param code Top-half pseudocode. |
64 | * @param code Top-half pseudocode. |
65 | */ |
65 | */ |
66 | static void code_execute(call_t *call, irq_code_t *code) |
66 | static void code_execute(call_t *call, irq_code_t *code) |
67 | { |
67 | { |
68 | int i; |
68 | int i; |
69 | unative_t dstval = 0; |
69 | unative_t dstval = 0; |
70 | 70 | ||
71 | if (!code) |
71 | if (!code) |
72 | return; |
72 | return; |
73 | 73 | ||
74 | for (i = 0; i < code->cmdcount; i++) { |
74 | for (i = 0; i < code->cmdcount; i++) { |
75 | switch (code->cmds[i].cmd) { |
75 | switch (code->cmds[i].cmd) { |
76 | case CMD_MEM_READ_1: |
76 | case CMD_MEM_READ_1: |
77 | dstval = *((uint8_t *) code->cmds[i].addr); |
77 | dstval = *((uint8_t *) code->cmds[i].addr); |
78 | break; |
78 | break; |
79 | case CMD_MEM_READ_2: |
79 | case CMD_MEM_READ_2: |
80 | dstval = *((uint16_t *) code->cmds[i].addr); |
80 | dstval = *((uint16_t *) code->cmds[i].addr); |
81 | break; |
81 | break; |
82 | case CMD_MEM_READ_4: |
82 | case CMD_MEM_READ_4: |
83 | dstval = *((uint32_t *) code->cmds[i].addr); |
83 | dstval = *((uint32_t *) code->cmds[i].addr); |
84 | break; |
84 | break; |
85 | case CMD_MEM_READ_8: |
85 | case CMD_MEM_READ_8: |
86 | dstval = *((uint64_t *) code->cmds[i].addr); |
86 | dstval = *((uint64_t *) code->cmds[i].addr); |
87 | break; |
87 | break; |
88 | case CMD_MEM_WRITE_1: |
88 | case CMD_MEM_WRITE_1: |
89 | *((uint8_t *) code->cmds[i].addr) = code->cmds[i].value; |
89 | *((uint8_t *) code->cmds[i].addr) = code->cmds[i].value; |
90 | break; |
90 | break; |
91 | case CMD_MEM_WRITE_2: |
91 | case CMD_MEM_WRITE_2: |
92 | *((uint16_t *) code->cmds[i].addr) = code->cmds[i].value; |
92 | *((uint16_t *) code->cmds[i].addr) = |
- | 93 | code->cmds[i].value; |
|
93 | break; |
94 | break; |
94 | case CMD_MEM_WRITE_4: |
95 | case CMD_MEM_WRITE_4: |
95 | *((uint32_t *) code->cmds[i].addr) = code->cmds[i].value; |
96 | *((uint32_t *) code->cmds[i].addr) = |
- | 97 | 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) = |
- | 101 | code->cmds[i].value; |
|
99 | break; |
102 | break; |
100 | #if defined(ia32) || defined(amd64) |
103 | #if defined(ia32) || defined(amd64) |
101 | case CMD_PORT_READ_1: |
104 | case CMD_PORT_READ_1: |
102 | dstval = inb((long) code->cmds[i].addr); |
105 | dstval = inb((long) code->cmds[i].addr); |
103 | break; |
106 | break; |
104 | case CMD_PORT_WRITE_1: |
107 | case CMD_PORT_WRITE_1: |
105 | outb((long) code->cmds[i].addr, code->cmds[i].value); |
108 | outb((long) code->cmds[i].addr, code->cmds[i].value); |
106 | break; |
109 | break; |
107 | #endif |
110 | #endif |
108 | #if defined(ia64) && defined(SKI) |
111 | #if defined(ia64) && defined(SKI) |
109 | case CMD_IA64_GETCHAR: |
112 | case CMD_IA64_GETCHAR: |
110 | dstval = _getc(&ski_uconsole); |
113 | dstval = _getc(&ski_uconsole); |
111 | break; |
114 | break; |
112 | #endif |
115 | #endif |
113 | #if defined(ppc32) |
116 | #if defined(ppc32) |
114 | case CMD_PPC32_GETCHAR: |
117 | case CMD_PPC32_GETCHAR: |
115 | dstval = cuda_get_scancode(); |
118 | dstval = cuda_get_scancode(); |
116 | break; |
119 | break; |
117 | #endif |
120 | #endif |
118 | default: |
121 | default: |
119 | break; |
122 | break; |
120 | } |
123 | } |
121 | if (code->cmds[i].dstarg && code->cmds[i].dstarg < 4) { |
124 | if (code->cmds[i].dstarg && code->cmds[i].dstarg < |
- | 125 | IPC_CALL_LEN) { |
|
122 | call->data.args[code->cmds[i].dstarg] = dstval; |
126 | call->data.args[code->cmds[i].dstarg] = dstval; |
123 | } |
127 | } |
124 | } |
128 | } |
125 | } |
129 | } |
126 | 130 | ||
127 | /** Free top-half pseudocode. |
131 | /** Free top-half pseudocode. |
128 | * |
132 | * |
129 | * @param code Pointer to the top-half pseudocode. |
133 | * @param code Pointer to the top-half pseudocode. |
130 | */ |
134 | */ |
131 | static void code_free(irq_code_t *code) |
135 | static void code_free(irq_code_t *code) |
132 | { |
136 | { |
133 | if (code) { |
137 | if (code) { |
134 | free(code->cmds); |
138 | free(code->cmds); |
135 | free(code); |
139 | free(code); |
136 | } |
140 | } |
137 | } |
141 | } |
138 | 142 | ||
139 | /** Copy top-half pseudocode from userspace into the kernel. |
143 | /** Copy top-half pseudocode from userspace into the kernel. |
140 | * |
144 | * |
141 | * @param ucode Userspace address of the top-half pseudocode. |
145 | * @param ucode Userspace address of the top-half pseudocode. |
142 | * |
146 | * |
143 | * @return Kernel address of the copied pseudocode. |
147 | * @return Kernel address of the copied pseudocode. |
144 | */ |
148 | */ |
145 | static irq_code_t *code_from_uspace(irq_code_t *ucode) |
149 | static irq_code_t *code_from_uspace(irq_code_t *ucode) |
146 | { |
150 | { |
147 | irq_code_t *code; |
151 | irq_code_t *code; |
148 | irq_cmd_t *ucmds; |
152 | irq_cmd_t *ucmds; |
149 | int rc; |
153 | int rc; |
150 | 154 | ||
151 | code = malloc(sizeof(*code), 0); |
155 | code = malloc(sizeof(*code), 0); |
152 | rc = copy_from_uspace(code, ucode, sizeof(*code)); |
156 | rc = copy_from_uspace(code, ucode, sizeof(*code)); |
153 | if (rc != 0) { |
157 | if (rc != 0) { |
154 | free(code); |
158 | free(code); |
155 | return NULL; |
159 | return NULL; |
156 | } |
160 | } |
157 | 161 | ||
158 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) { |
162 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) { |
159 | free(code); |
163 | free(code); |
160 | return NULL; |
164 | return NULL; |
161 | } |
165 | } |
162 | ucmds = code->cmds; |
166 | ucmds = code->cmds; |
163 | code->cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, 0); |
167 | code->cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, 0); |
164 | rc = copy_from_uspace(code->cmds, ucmds, |
168 | rc = copy_from_uspace(code->cmds, ucmds, |
165 | sizeof(code->cmds[0]) * code->cmdcount); |
169 | sizeof(code->cmds[0]) * code->cmdcount); |
166 | if (rc != 0) { |
170 | if (rc != 0) { |
167 | free(code->cmds); |
171 | free(code->cmds); |
168 | free(code); |
172 | free(code); |
169 | return NULL; |
173 | return NULL; |
170 | } |
174 | } |
171 | 175 | ||
172 | return code; |
176 | return code; |
173 | } |
177 | } |
174 | 178 | ||
175 | /** Unregister task from IRQ notification. |
179 | /** Unregister task from IRQ notification. |
176 | * |
180 | * |
177 | * @param box Answerbox associated with the notification. |
181 | * @param box Answerbox associated with the notification. |
178 | * @param inr IRQ number. |
182 | * @param inr IRQ number. |
179 | * @param devno Device number. |
183 | * @param devno Device number. |
180 | */ |
184 | */ |
181 | void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno) |
185 | void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno) |
182 | { |
186 | { |
183 | ipl_t ipl; |
187 | ipl_t ipl; |
184 | irq_t *irq; |
188 | irq_t *irq; |
185 | 189 | ||
186 | ipl = interrupts_disable(); |
190 | ipl = interrupts_disable(); |
187 | irq = irq_find_and_lock(inr, devno); |
191 | irq = irq_find_and_lock(inr, devno); |
188 | if (irq) { |
192 | if (irq) { |
189 | if (irq->notif_cfg.answerbox == box) { |
193 | if (irq->notif_cfg.answerbox == box) { |
190 | code_free(irq->notif_cfg.code); |
194 | code_free(irq->notif_cfg.code); |
191 | irq->notif_cfg.notify = false; |
195 | irq->notif_cfg.notify = false; |
192 | irq->notif_cfg.answerbox = NULL; |
196 | irq->notif_cfg.answerbox = NULL; |
193 | irq->notif_cfg.code = NULL; |
197 | irq->notif_cfg.code = NULL; |
194 | irq->notif_cfg.method = 0; |
198 | irq->notif_cfg.method = 0; |
195 | irq->notif_cfg.counter = 0; |
199 | irq->notif_cfg.counter = 0; |
196 | 200 | ||
197 | spinlock_lock(&box->irq_lock); |
201 | spinlock_lock(&box->irq_lock); |
198 | list_remove(&irq->notif_cfg.link); |
202 | list_remove(&irq->notif_cfg.link); |
199 | spinlock_unlock(&box->irq_lock); |
203 | spinlock_unlock(&box->irq_lock); |
200 | 204 | ||
201 | spinlock_unlock(&irq->lock); |
205 | spinlock_unlock(&irq->lock); |
202 | } |
206 | } |
203 | } |
207 | } |
204 | interrupts_restore(ipl); |
208 | interrupts_restore(ipl); |
205 | } |
209 | } |
206 | 210 | ||
207 | /** Register an answerbox as a receiving end for IRQ notifications. |
211 | /** Register an answerbox as a receiving end for IRQ notifications. |
208 | * |
212 | * |
209 | * @param box Receiving answerbox. |
213 | * @param box Receiving answerbox. |
210 | * @param inr IRQ number. |
214 | * @param inr IRQ number. |
211 | * @param devno Device number. |
215 | * @param devno Device number. |
212 | * @param method Method to be associated with the notification. |
216 | * @param method Method to be associated with the notification. |
213 | * @param ucode Uspace pointer to top-half pseudocode. |
217 | * @param ucode Uspace pointer to top-half pseudocode. |
214 | * |
218 | * |
215 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
219 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
216 | */ |
220 | */ |
217 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, |
221 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, |
218 | unative_t method, irq_code_t *ucode) |
222 | unative_t method, irq_code_t *ucode) |
219 | { |
223 | { |
220 | ipl_t ipl; |
224 | ipl_t ipl; |
221 | irq_code_t *code; |
225 | irq_code_t *code; |
222 | irq_t *irq; |
226 | irq_t *irq; |
223 | 227 | ||
224 | if (ucode) { |
228 | if (ucode) { |
225 | code = code_from_uspace(ucode); |
229 | code = code_from_uspace(ucode); |
226 | if (!code) |
230 | if (!code) |
227 | return EBADMEM; |
231 | return EBADMEM; |
228 | } else { |
232 | } else { |
229 | code = NULL; |
233 | code = NULL; |
230 | } |
234 | } |
231 | 235 | ||
232 | ipl = interrupts_disable(); |
236 | ipl = interrupts_disable(); |
233 | irq = irq_find_and_lock(inr, devno); |
237 | irq = irq_find_and_lock(inr, devno); |
234 | if (!irq) { |
238 | if (!irq) { |
235 | interrupts_restore(ipl); |
239 | interrupts_restore(ipl); |
236 | code_free(code); |
240 | code_free(code); |
237 | return ENOENT; |
241 | return ENOENT; |
238 | } |
242 | } |
239 | 243 | ||
240 | if (irq->notif_cfg.answerbox) { |
244 | if (irq->notif_cfg.answerbox) { |
241 | spinlock_unlock(&irq->lock); |
245 | spinlock_unlock(&irq->lock); |
242 | interrupts_restore(ipl); |
246 | interrupts_restore(ipl); |
243 | code_free(code); |
247 | code_free(code); |
244 | return EEXISTS; |
248 | return EEXISTS; |
245 | } |
249 | } |
246 | 250 | ||
247 | irq->notif_cfg.notify = true; |
251 | irq->notif_cfg.notify = true; |
248 | irq->notif_cfg.answerbox = box; |
252 | irq->notif_cfg.answerbox = box; |
249 | irq->notif_cfg.method = method; |
253 | irq->notif_cfg.method = method; |
250 | irq->notif_cfg.code = code; |
254 | irq->notif_cfg.code = code; |
251 | irq->notif_cfg.counter = 0; |
255 | irq->notif_cfg.counter = 0; |
252 | 256 | ||
253 | spinlock_lock(&box->irq_lock); |
257 | spinlock_lock(&box->irq_lock); |
254 | list_append(&irq->notif_cfg.link, &box->irq_head); |
258 | list_append(&irq->notif_cfg.link, &box->irq_head); |
255 | spinlock_unlock(&box->irq_lock); |
259 | spinlock_unlock(&box->irq_lock); |
256 | 260 | ||
257 | spinlock_unlock(&irq->lock); |
261 | spinlock_unlock(&irq->lock); |
258 | interrupts_restore(ipl); |
262 | interrupts_restore(ipl); |
259 | 263 | ||
260 | return 0; |
264 | return 0; |
261 | } |
265 | } |
262 | 266 | ||
263 | /** Add a call to the proper answerbox queue. |
267 | /** Add a call to the proper answerbox queue. |
264 | * |
268 | * |
265 | * Assume irq->lock is locked. |
269 | * Assume irq->lock is locked. |
266 | * |
270 | * |
267 | * @param irq IRQ structure referencing the target answerbox. |
271 | * @param irq IRQ structure referencing the target answerbox. |
268 | * @param call IRQ notification call. |
272 | * @param call IRQ notification call. |
269 | */ |
273 | */ |
270 | static void send_call(irq_t *irq, call_t *call) |
274 | static void send_call(irq_t *irq, call_t *call) |
271 | { |
275 | { |
272 | spinlock_lock(&irq->notif_cfg.answerbox->irq_lock); |
276 | spinlock_lock(&irq->notif_cfg.answerbox->irq_lock); |
273 | list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs); |
277 | list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs); |
274 | spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock); |
278 | spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock); |
275 | 279 | ||
276 | waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST); |
280 | waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST); |
277 | } |
281 | } |
278 | 282 | ||
279 | /** Send notification message. |
283 | /** Send notification message. |
280 | * |
284 | * |
281 | * @param irq IRQ structure. |
285 | * @param irq IRQ structure. |
282 | * @param a1 Driver-specific payload argument. |
286 | * @param a1 Driver-specific payload argument. |
283 | * @param a2 Driver-specific payload argument. |
287 | * @param a2 Driver-specific payload argument. |
284 | * @param a3 Driver-specific payload argument. |
288 | * @param a3 Driver-specific payload argument. |
- | 289 | * @param a4 Driver-specific payload argument. |
|
- | 290 | * @param a5 Driver-specific payload argument. |
|
285 | */ |
291 | */ |
286 | void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3) |
292 | void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3, |
- | 293 | unative_t a4, unative_t a5) |
|
287 | { |
294 | { |
288 | call_t *call; |
295 | call_t *call; |
289 | 296 | ||
290 | spinlock_lock(&irq->lock); |
297 | spinlock_lock(&irq->lock); |
291 | 298 | ||
292 | if (irq->notif_cfg.answerbox) { |
299 | if (irq->notif_cfg.answerbox) { |
293 | call = ipc_call_alloc(FRAME_ATOMIC); |
300 | call = ipc_call_alloc(FRAME_ATOMIC); |
294 | if (!call) { |
301 | if (!call) { |
295 | spinlock_unlock(&irq->lock); |
302 | spinlock_unlock(&irq->lock); |
296 | return; |
303 | return; |
297 | } |
304 | } |
298 | call->flags |= IPC_CALL_NOTIF; |
305 | call->flags |= IPC_CALL_NOTIF; |
299 | IPC_SET_METHOD(call->data, irq->notif_cfg.method); |
306 | IPC_SET_METHOD(call->data, irq->notif_cfg.method); |
300 | IPC_SET_ARG1(call->data, a1); |
307 | IPC_SET_ARG1(call->data, a1); |
301 | IPC_SET_ARG2(call->data, a2); |
308 | IPC_SET_ARG2(call->data, a2); |
302 | IPC_SET_ARG3(call->data, a3); |
309 | IPC_SET_ARG3(call->data, a3); |
- | 310 | IPC_SET_ARG4(call->data, a4); |
|
- | 311 | IPC_SET_ARG5(call->data, a5); |
|
303 | /* Put a counter to the message */ |
312 | /* Put a counter to the message */ |
304 | call->priv = ++irq->notif_cfg.counter; |
313 | call->priv = ++irq->notif_cfg.counter; |
305 | 314 | ||
306 | send_call(irq, call); |
315 | send_call(irq, call); |
307 | } |
316 | } |
308 | spinlock_unlock(&irq->lock); |
317 | spinlock_unlock(&irq->lock); |
309 | } |
318 | } |
310 | 319 | ||
311 | /** Notify a task that an IRQ had occurred. |
320 | /** Notify a task that an IRQ had occurred. |
312 | * |
321 | * |
313 | * We expect interrupts to be disabled and the irq->lock already held. |
322 | * We expect interrupts to be disabled and the irq->lock already held. |
314 | * |
323 | * |
315 | * @param irq IRQ structure. |
324 | * @param irq IRQ structure. |
316 | */ |
325 | */ |
317 | void ipc_irq_send_notif(irq_t *irq) |
326 | void ipc_irq_send_notif(irq_t *irq) |
318 | { |
327 | { |
319 | call_t *call; |
328 | call_t *call; |
320 | 329 | ||
321 | ASSERT(irq); |
330 | ASSERT(irq); |
322 | 331 | ||
323 | if (irq->notif_cfg.answerbox) { |
332 | if (irq->notif_cfg.answerbox) { |
324 | call = ipc_call_alloc(FRAME_ATOMIC); |
333 | call = ipc_call_alloc(FRAME_ATOMIC); |
325 | if (!call) { |
334 | if (!call) { |
326 | return; |
335 | return; |
327 | } |
336 | } |
328 | call->flags |= IPC_CALL_NOTIF; |
337 | call->flags |= IPC_CALL_NOTIF; |
329 | /* Put a counter to the message */ |
338 | /* Put a counter to the message */ |
330 | call->priv = ++irq->notif_cfg.counter; |
339 | call->priv = ++irq->notif_cfg.counter; |
331 | /* Set up args */ |
340 | /* Set up args */ |
332 | IPC_SET_METHOD(call->data, irq->notif_cfg.method); |
341 | IPC_SET_METHOD(call->data, irq->notif_cfg.method); |
333 | 342 | ||
334 | /* Execute code to handle irq */ |
343 | /* Execute code to handle irq */ |
335 | code_execute(call, irq->notif_cfg.code); |
344 | code_execute(call, irq->notif_cfg.code); |
336 | 345 | ||
337 | send_call(irq, call); |
346 | send_call(irq, call); |
338 | } |
347 | } |
339 | } |
348 | } |
340 | 349 | ||
341 | /** Disconnect all IRQ notifications from an answerbox. |
350 | /** Disconnect all IRQ notifications from an answerbox. |
342 | * |
351 | * |
343 | * This function is effective because the answerbox contains |
352 | * This function is effective because the answerbox contains |
344 | * list of all irq_t structures that are registered to |
353 | * list of all irq_t structures that are registered to |
345 | * send notifications to it. |
354 | * send notifications to it. |
346 | * |
355 | * |
347 | * @param box Answerbox for which we want to carry out the cleanup. |
356 | * @param box Answerbox for which we want to carry out the cleanup. |
348 | */ |
357 | */ |
349 | void ipc_irq_cleanup(answerbox_t *box) |
358 | void ipc_irq_cleanup(answerbox_t *box) |
350 | { |
359 | { |
351 | ipl_t ipl; |
360 | ipl_t ipl; |
352 | 361 | ||
353 | loop: |
362 | loop: |
354 | ipl = interrupts_disable(); |
363 | ipl = interrupts_disable(); |
355 | spinlock_lock(&box->irq_lock); |
364 | spinlock_lock(&box->irq_lock); |
356 | 365 | ||
357 | while (box->irq_head.next != &box->irq_head) { |
366 | while (box->irq_head.next != &box->irq_head) { |
358 | link_t *cur = box->irq_head.next; |
367 | link_t *cur = box->irq_head.next; |
359 | irq_t *irq; |
368 | irq_t *irq; |
360 | DEADLOCK_PROBE_INIT(p_irqlock); |
369 | DEADLOCK_PROBE_INIT(p_irqlock); |
361 | 370 | ||
362 | irq = list_get_instance(cur, irq_t, notif_cfg.link); |
371 | irq = list_get_instance(cur, irq_t, notif_cfg.link); |
363 | if (!spinlock_trylock(&irq->lock)) { |
372 | if (!spinlock_trylock(&irq->lock)) { |
364 | /* |
373 | /* |
365 | * Avoid deadlock by trying again. |
374 | * Avoid deadlock by trying again. |
366 | */ |
375 | */ |
367 | spinlock_unlock(&box->irq_lock); |
376 | spinlock_unlock(&box->irq_lock); |
368 | interrupts_restore(ipl); |
377 | interrupts_restore(ipl); |
369 | DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD); |
378 | DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD); |
370 | goto loop; |
379 | goto loop; |
371 | } |
380 | } |
372 | 381 | ||
373 | ASSERT(irq->notif_cfg.answerbox == box); |
382 | ASSERT(irq->notif_cfg.answerbox == box); |
374 | 383 | ||
375 | list_remove(&irq->notif_cfg.link); |
384 | list_remove(&irq->notif_cfg.link); |
376 | 385 | ||
377 | /* |
386 | /* |
378 | * Don't forget to free any top-half pseudocode. |
387 | * Don't forget to free any top-half pseudocode. |
379 | */ |
388 | */ |
380 | code_free(irq->notif_cfg.code); |
389 | code_free(irq->notif_cfg.code); |
381 | 390 | ||
382 | irq->notif_cfg.notify = false; |
391 | irq->notif_cfg.notify = false; |
383 | irq->notif_cfg.answerbox = NULL; |
392 | irq->notif_cfg.answerbox = NULL; |
384 | irq->notif_cfg.code = NULL; |
393 | irq->notif_cfg.code = NULL; |
385 | irq->notif_cfg.method = 0; |
394 | irq->notif_cfg.method = 0; |
386 | irq->notif_cfg.counter = 0; |
395 | irq->notif_cfg.counter = 0; |
387 | 396 | ||
388 | spinlock_unlock(&irq->lock); |
397 | spinlock_unlock(&irq->lock); |
389 | } |
398 | } |
390 | 399 | ||
391 | spinlock_unlock(&box->irq_lock); |
400 | spinlock_unlock(&box->irq_lock); |
392 | interrupts_restore(ipl); |
401 | interrupts_restore(ipl); |
393 | } |
402 | } |
394 | 403 | ||
395 | /** @} |
404 | /** @} |
396 | */ |
405 | */ |
397 | 406 |