Rev 2183 | Rev 2626 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2183 | Rev 2471 | ||
|---|---|---|---|
| Line 58... | Line 58... | ||
| 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) = code->cmds[i].value; |
| 93 | break; |
93 | break; |
| 94 | case CMD_MEM_WRITE_4: |
94 | case CMD_MEM_WRITE_4: |
| 95 | *((uint32_t *)code->cmds[i].addr) = code->cmds[i].value; |
95 | *((uint32_t *) code->cmds[i].addr) = code->cmds[i].value; |
| 96 | break; |
96 | break; |
| 97 | case CMD_MEM_WRITE_8: |
97 | case CMD_MEM_WRITE_8: |
| 98 | *((uint64_t *)code->cmds[i].addr) = code->cmds[i].value; |
98 | *((uint64_t *) code->cmds[i].addr) = code->cmds[i].value; |
| 99 | break; |
99 | break; |
| 100 | #if defined(ia32) || defined(amd64) |
100 | #if defined(ia32) || defined(amd64) |
| 101 | case CMD_PORT_READ_1: |
101 | case CMD_PORT_READ_1: |
| 102 | dstval = inb((long)code->cmds[i].addr); |
102 | dstval = inb((long) code->cmds[i].addr); |
| 103 | break; |
103 | break; |
| 104 | case CMD_PORT_WRITE_1: |
104 | case CMD_PORT_WRITE_1: |
| 105 | outb((long)code->cmds[i].addr, code->cmds[i].value); |
105 | outb((long) code->cmds[i].addr, code->cmds[i].value); |
| 106 | break; |
106 | break; |
| 107 | #endif |
107 | #endif |
| 108 | #if defined(ia64) && defined(SKI) |
108 | #if defined(ia64) && defined(SKI) |
| 109 | case CMD_IA64_GETCHAR: |
109 | case CMD_IA64_GETCHAR: |
| 110 | dstval = _getc(&ski_uconsole); |
110 | dstval = _getc(&ski_uconsole); |
| Line 122... | Line 122... | ||
| 122 | call->data.args[code->cmds[i].dstarg] = dstval; |
122 | call->data.args[code->cmds[i].dstarg] = dstval; |
| 123 | } |
123 | } |
| 124 | } |
124 | } |
| 125 | } |
125 | } |
| 126 | 126 | ||
| - | 127 | /** Free top-half pseudocode. |
|
| - | 128 | * |
|
| - | 129 | * @param code Pointer to the top-half pseudocode. |
|
| - | 130 | */ |
|
| 127 | static void code_free(irq_code_t *code) |
131 | static void code_free(irq_code_t *code) |
| 128 | { |
132 | { |
| 129 | if (code) { |
133 | if (code) { |
| 130 | free(code->cmds); |
134 | free(code->cmds); |
| 131 | free(code); |
135 | free(code); |
| 132 | } |
136 | } |
| 133 | } |
137 | } |
| 134 | 138 | ||
| - | 139 | /** Copy top-half pseudocode from userspace into the kernel. |
|
| - | 140 | * |
|
| - | 141 | * @param ucode Userspace address of the top-half pseudocode. |
|
| - | 142 | * |
|
| - | 143 | * @return Kernel address of the copied pseudocode. |
|
| - | 144 | */ |
|
| 135 | static irq_code_t * code_from_uspace(irq_code_t *ucode) |
145 | static irq_code_t *code_from_uspace(irq_code_t *ucode) |
| 136 | { |
146 | { |
| 137 | irq_code_t *code; |
147 | irq_code_t *code; |
| 138 | irq_cmd_t *ucmds; |
148 | irq_cmd_t *ucmds; |
| 139 | int rc; |
149 | int rc; |
| 140 | 150 | ||
| Line 148... | Line 158... | ||
| 148 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) { |
158 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) { |
| 149 | free(code); |
159 | free(code); |
| 150 | return NULL; |
160 | return NULL; |
| 151 | } |
161 | } |
| 152 | ucmds = code->cmds; |
162 | ucmds = code->cmds; |
| 153 | code->cmds = malloc(sizeof(code->cmds[0]) * (code->cmdcount), 0); |
163 | code->cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, 0); |
| - | 164 | rc = copy_from_uspace(code->cmds, ucmds, |
|
| 154 | rc = copy_from_uspace(code->cmds, ucmds, sizeof(code->cmds[0]) * (code->cmdcount)); |
165 | sizeof(code->cmds[0]) * code->cmdcount); |
| 155 | if (rc != 0) { |
166 | if (rc != 0) { |
| 156 | free(code->cmds); |
167 | free(code->cmds); |
| 157 | free(code); |
168 | free(code); |
| 158 | return NULL; |
169 | return NULL; |
| 159 | } |
170 | } |
| Line 161... | Line 172... | ||
| 161 | return code; |
172 | return code; |
| 162 | } |
173 | } |
| 163 | 174 | ||
| 164 | /** Unregister task from IRQ notification. |
175 | /** Unregister task from IRQ notification. |
| 165 | * |
176 | * |
| 166 | * @param box Answerbox associated with the notification. |
177 | * @param box Answerbox associated with the notification. |
| 167 | * @param inr IRQ numbe. |
178 | * @param inr IRQ number. |
| 168 | * @param devno Device number. |
179 | * @param devno Device number. |
| 169 | */ |
180 | */ |
| 170 | void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno) |
181 | void ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno) |
| 171 | { |
182 | { |
| 172 | ipl_t ipl; |
183 | ipl_t ipl; |
| 173 | irq_t *irq; |
184 | irq_t *irq; |
| Line 193... | Line 204... | ||
| 193 | interrupts_restore(ipl); |
204 | interrupts_restore(ipl); |
| 194 | } |
205 | } |
| 195 | 206 | ||
| 196 | /** Register an answerbox as a receiving end for IRQ notifications. |
207 | /** Register an answerbox as a receiving end for IRQ notifications. |
| 197 | * |
208 | * |
| 198 | * @param box Receiving answerbox. |
209 | * @param box Receiving answerbox. |
| 199 | * @param inr IRQ number. |
210 | * @param inr IRQ number. |
| 200 | * @param devno Device number. |
211 | * @param devno Device number. |
| 201 | * @param method Method to be associated with the notification. |
212 | * @param method Method to be associated with the notification. |
| 202 | * @param ucode Uspace pointer to top-half pseudocode. |
213 | * @param ucode Uspace pointer to top-half pseudocode. |
| 203 | * |
214 | * |
| 204 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
215 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success. |
| 205 | */ |
216 | */ |
| 206 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode) |
217 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, |
| - | 218 | unative_t method, irq_code_t *ucode) |
|
| 207 | { |
219 | { |
| 208 | ipl_t ipl; |
220 | ipl_t ipl; |
| 209 | irq_code_t *code; |
221 | irq_code_t *code; |
| 210 | irq_t *irq; |
222 | irq_t *irq; |
| 211 | 223 | ||
| 212 | if (ucode) { |
224 | if (ucode) { |
| 213 | code = code_from_uspace(ucode); |
225 | code = code_from_uspace(ucode); |
| 214 | if (!code) |
226 | if (!code) |
| 215 | return EBADMEM; |
227 | return EBADMEM; |
| 216 | } else |
228 | } else { |
| 217 | code = NULL; |
229 | code = NULL; |
| - | 230 | } |
|
| 218 | 231 | ||
| 219 | ipl = interrupts_disable(); |
232 | ipl = interrupts_disable(); |
| 220 | irq = irq_find_and_lock(inr, devno); |
233 | irq = irq_find_and_lock(inr, devno); |
| 221 | if (!irq) { |
234 | if (!irq) { |
| 222 | interrupts_restore(ipl); |
235 | interrupts_restore(ipl); |
| Line 245... | Line 258... | ||
| 245 | interrupts_restore(ipl); |
258 | interrupts_restore(ipl); |
| 246 | 259 | ||
| 247 | return 0; |
260 | return 0; |
| 248 | } |
261 | } |
| 249 | 262 | ||
| 250 | /** Add call to proper answerbox queue. |
263 | /** Add a call to the proper answerbox queue. |
| 251 | * |
264 | * |
| 252 | * Assume irq->lock is locked. |
265 | * Assume irq->lock is locked. |
| 253 | * |
266 | * |
| - | 267 | * @param irq IRQ structure referencing the target answerbox. |
|
| - | 268 | * @param call IRQ notification call. |
|
| 254 | */ |
269 | */ |
| 255 | static void send_call(irq_t *irq, call_t *call) |
270 | static void send_call(irq_t *irq, call_t *call) |
| 256 | { |
271 | { |
| 257 | spinlock_lock(&irq->notif_cfg.answerbox->irq_lock); |
272 | spinlock_lock(&irq->notif_cfg.answerbox->irq_lock); |
| 258 | list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs); |
273 | list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs); |
| 259 | spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock); |
274 | spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock); |
| 260 | 275 | ||
| 261 | waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST); |
276 | waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST); |
| 262 | } |
277 | } |
| 263 | 278 | ||
| 264 | /** Send notification message |
279 | /** Send notification message. |
| 265 | * |
280 | * |
| - | 281 | * @param irq IRQ structure. |
|
| - | 282 | * @param a1 Driver-specific payload argument. |
|
| - | 283 | * @param a2 Driver-specific payload argument. |
|
| - | 284 | * @param a3 Driver-specific payload argument. |
|
| 266 | */ |
285 | */ |
| 267 | void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3) |
286 | void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3) |
| 268 | { |
287 | { |
| 269 | call_t *call; |
288 | call_t *call; |
| 270 | 289 | ||
| Line 287... | Line 306... | ||
| 287 | send_call(irq, call); |
306 | send_call(irq, call); |
| 288 | } |
307 | } |
| 289 | spinlock_unlock(&irq->lock); |
308 | spinlock_unlock(&irq->lock); |
| 290 | } |
309 | } |
| 291 | 310 | ||
| 292 | /** Notify task that an irq had occurred. |
311 | /** Notify a task that an IRQ had occurred. |
| 293 | * |
312 | * |
| 294 | * We expect interrupts to be disabled and the irq->lock already held. |
313 | * We expect interrupts to be disabled and the irq->lock already held. |
| - | 314 | * |
|
| - | 315 | * @param irq IRQ structure. |
|
| 295 | */ |
316 | */ |
| 296 | void ipc_irq_send_notif(irq_t *irq) |
317 | void ipc_irq_send_notif(irq_t *irq) |
| 297 | { |
318 | { |
| 298 | call_t *call; |
319 | call_t *call; |
| 299 | 320 | ||
| Line 321... | Line 342... | ||
| 321 | * |
342 | * |
| 322 | * This function is effective because the answerbox contains |
343 | * This function is effective because the answerbox contains |
| 323 | * list of all irq_t structures that are registered to |
344 | * list of all irq_t structures that are registered to |
| 324 | * send notifications to it. |
345 | * send notifications to it. |
| 325 | * |
346 | * |
| 326 | * @param box Answerbox for which we want to carry out the cleanup. |
347 | * @param box Answerbox for which we want to carry out the cleanup. |
| 327 | */ |
348 | */ |
| 328 | void ipc_irq_cleanup(answerbox_t *box) |
349 | void ipc_irq_cleanup(answerbox_t *box) |
| 329 | { |
350 | { |
| 330 | ipl_t ipl; |
351 | ipl_t ipl; |
| 331 | 352 | ||