[162f919] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
| 3 | * Copyright (c) 2006 Jakub Jermar
|
---|
[162f919] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 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
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 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
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 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
|
---|
| 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
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[cc73a8a1] | 30 | /** @addtogroup genericipc
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
[cc73a8a1] | 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | * @brief IRQ notification framework.
|
---|
[bdc5c516] | 36 | *
|
---|
| 37 | * This framework allows applications to register to receive a notification
|
---|
| 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
|
---|
| 40 | * (read/write port/memory, add information to notification ipc message).
|
---|
| 41 | *
|
---|
| 42 | * The structure of a notification message is as follows:
|
---|
[2b017ba] | 43 | * - METHOD: method as registered by the SYS_IPC_REGISTER_IRQ syscall
|
---|
[43752b6] | 44 | * - ARG1: payload modified by a 'top-half' handler
|
---|
[2b017ba] | 45 | * - ARG2: payload modified by a 'top-half' handler
|
---|
| 46 | * - ARG3: payload modified by a 'top-half' handler
|
---|
[cecb0789] | 47 | * - ARG4: payload modified by a 'top-half' handler
|
---|
| 48 | * - ARG5: payload modified by a 'top-half' handler
|
---|
[43752b6] | 49 | * - in_phone_hash: interrupt counter (may be needed to assure correct order
|
---|
[bdc5c516] | 50 | * in multithreaded drivers)
|
---|
[cecb0789] | 51 | *
|
---|
| 52 | * Note on synchronization for ipc_irq_register(), ipc_irq_unregister(),
|
---|
| 53 | * ipc_irq_cleanup() and IRQ handlers:
|
---|
| 54 | *
|
---|
| 55 | * By always taking all of the uspace IRQ hash table lock, IRQ structure lock
|
---|
| 56 | * and answerbox lock, we can rule out race conditions between the
|
---|
| 57 | * registration functions and also the cleanup function. Thus the observer can
|
---|
| 58 | * either see the IRQ structure present in both the hash table and the
|
---|
| 59 | * answerbox list or absent in both. Views in which the IRQ structure would be
|
---|
| 60 | * linked in the hash table but not in the answerbox list, or vice versa, are
|
---|
| 61 | * not possible.
|
---|
| 62 | *
|
---|
| 63 | * By always taking the hash table lock and the IRQ structure lock, we can
|
---|
| 64 | * rule out a scenario in which we would free up an IRQ structure, which is
|
---|
| 65 | * still referenced by, for example, an IRQ handler. The locking scheme forces
|
---|
| 66 | * us to lock the IRQ structure only after any progressing IRQs on that
|
---|
| 67 | * structure are finished. Because we hold the hash table lock, we prevent new
|
---|
| 68 | * IRQs from taking new references to the IRQ structure.
|
---|
[bdc5c516] | 69 | */
|
---|
| 70 |
|
---|
[162f919] | 71 | #include <arch.h>
|
---|
| 72 | #include <mm/slab.h>
|
---|
| 73 | #include <errno.h>
|
---|
[2b017ba] | 74 | #include <ddi/irq.h>
|
---|
[162f919] | 75 | #include <ipc/ipc.h>
|
---|
| 76 | #include <ipc/irq.h>
|
---|
[e3c762cd] | 77 | #include <syscall/copy.h>
|
---|
[d0c5901] | 78 | #include <console/console.h>
|
---|
[253f35a1] | 79 | #include <print.h>
|
---|
[162f919] | 80 |
|
---|
[cecb0789] | 81 | /** Free the top-half pseudocode.
|
---|
[8b243f2] | 82 | *
|
---|
| 83 | * @param code Pointer to the top-half pseudocode.
|
---|
| 84 | */
|
---|
[162f919] | 85 | static void code_free(irq_code_t *code)
|
---|
| 86 | {
|
---|
| 87 | if (code) {
|
---|
| 88 | free(code->cmds);
|
---|
| 89 | free(code);
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[cecb0789] | 93 | /** Copy the top-half pseudocode from userspace into the kernel.
|
---|
[8b243f2] | 94 | *
|
---|
| 95 | * @param ucode Userspace address of the top-half pseudocode.
|
---|
| 96 | *
|
---|
| 97 | * @return Kernel address of the copied pseudocode.
|
---|
| 98 | */
|
---|
| 99 | static irq_code_t *code_from_uspace(irq_code_t *ucode)
|
---|
[162f919] | 100 | {
|
---|
| 101 | irq_code_t *code;
|
---|
| 102 | irq_cmd_t *ucmds;
|
---|
[e3c762cd] | 103 | int rc;
|
---|
[162f919] | 104 |
|
---|
| 105 | code = malloc(sizeof(*code), 0);
|
---|
[e3c762cd] | 106 | rc = copy_from_uspace(code, ucode, sizeof(*code));
|
---|
| 107 | if (rc != 0) {
|
---|
| 108 | free(code);
|
---|
| 109 | return NULL;
|
---|
| 110 | }
|
---|
[162f919] | 111 |
|
---|
| 112 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) {
|
---|
| 113 | free(code);
|
---|
| 114 | return NULL;
|
---|
| 115 | }
|
---|
| 116 | ucmds = code->cmds;
|
---|
[8b243f2] | 117 | code->cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, 0);
|
---|
| 118 | rc = copy_from_uspace(code->cmds, ucmds,
|
---|
| 119 | sizeof(code->cmds[0]) * code->cmdcount);
|
---|
[e3c762cd] | 120 | if (rc != 0) {
|
---|
| 121 | free(code->cmds);
|
---|
| 122 | free(code);
|
---|
| 123 | return NULL;
|
---|
| 124 | }
|
---|
[162f919] | 125 |
|
---|
| 126 | return code;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[2b017ba] | 129 | /** Register an answerbox as a receiving end for IRQ notifications.
|
---|
| 130 | *
|
---|
[8b243f2] | 131 | * @param box Receiving answerbox.
|
---|
| 132 | * @param inr IRQ number.
|
---|
| 133 | * @param devno Device number.
|
---|
| 134 | * @param method Method to be associated with the notification.
|
---|
| 135 | * @param ucode Uspace pointer to top-half pseudocode.
|
---|
[2b017ba] | 136 | *
|
---|
[8b243f2] | 137 | * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success.
|
---|
[2b017ba] | 138 | */
|
---|
[8b243f2] | 139 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno,
|
---|
| 140 | unative_t method, irq_code_t *ucode)
|
---|
[162f919] | 141 | {
|
---|
| 142 | ipl_t ipl;
|
---|
| 143 | irq_code_t *code;
|
---|
[2b017ba] | 144 | irq_t *irq;
|
---|
[2845930] | 145 | link_t *hlp;
|
---|
[cecb0789] | 146 | unative_t key[] = {
|
---|
| 147 | (unative_t) inr,
|
---|
| 148 | (unative_t) devno
|
---|
| 149 | };
|
---|
[162f919] | 150 |
|
---|
| 151 | if (ucode) {
|
---|
| 152 | code = code_from_uspace(ucode);
|
---|
| 153 | if (!code)
|
---|
| 154 | return EBADMEM;
|
---|
[8b243f2] | 155 | } else {
|
---|
[162f919] | 156 | code = NULL;
|
---|
[8b243f2] | 157 | }
|
---|
[162f919] | 158 |
|
---|
[cecb0789] | 159 | /*
|
---|
| 160 | * Allocate and populate the IRQ structure.
|
---|
| 161 | */
|
---|
| 162 | irq = malloc(sizeof(irq_t), 0);
|
---|
| 163 | irq_initialize(irq);
|
---|
| 164 | irq->devno = devno;
|
---|
| 165 | irq->inr = inr;
|
---|
| 166 | irq->claim = ipc_irq_top_half_claim;
|
---|
[691eb52] | 167 | irq->handler = ipc_irq_top_half_handler;
|
---|
[4874c2d] | 168 | irq->notif_cfg.notify = true;
|
---|
[2b017ba] | 169 | irq->notif_cfg.answerbox = box;
|
---|
| 170 | irq->notif_cfg.method = method;
|
---|
| 171 | irq->notif_cfg.code = code;
|
---|
| 172 | irq->notif_cfg.counter = 0;
|
---|
[b14e35f2] | 173 |
|
---|
[cecb0789] | 174 | /*
|
---|
| 175 | * Enlist the IRQ structure in the uspace IRQ hash table and the
|
---|
| 176 | * answerbox's list.
|
---|
| 177 | */
|
---|
| 178 | ipl = interrupts_disable();
|
---|
| 179 | spinlock_lock(&irq_uspace_hash_table_lock);
|
---|
[2845930] | 180 | hlp = hash_table_find(&irq_uspace_hash_table, key);
|
---|
| 181 | if (hlp) {
|
---|
| 182 | irq_t *hirq = hash_table_get_instance(hlp, irq_t, link);
|
---|
| 183 | /* hirq is locked */
|
---|
| 184 | spinlock_unlock(&hirq->lock);
|
---|
[cecb0789] | 185 | code_free(code);
|
---|
| 186 | spinlock_unlock(&irq_uspace_hash_table_lock);
|
---|
| 187 | free(irq);
|
---|
| 188 | interrupts_restore(ipl);
|
---|
| 189 | return EEXISTS;
|
---|
| 190 | }
|
---|
[2845930] | 191 | spinlock_lock(&irq->lock); /* not really necessary, but paranoid */
|
---|
| 192 | spinlock_lock(&box->irq_lock);
|
---|
[cecb0789] | 193 | hash_table_insert(&irq_uspace_hash_table, key, &irq->link);
|
---|
[b14e35f2] | 194 | list_append(&irq->notif_cfg.link, &box->irq_head);
|
---|
| 195 | spinlock_unlock(&box->irq_lock);
|
---|
[cecb0789] | 196 | spinlock_unlock(&irq->lock);
|
---|
| 197 | spinlock_unlock(&irq_uspace_hash_table_lock);
|
---|
| 198 |
|
---|
| 199 | interrupts_restore(ipl);
|
---|
| 200 | return EOK;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /** Unregister task from IRQ notification.
|
---|
| 204 | *
|
---|
| 205 | * @param box Answerbox associated with the notification.
|
---|
| 206 | * @param inr IRQ number.
|
---|
| 207 | * @param devno Device number.
|
---|
| 208 | */
|
---|
| 209 | int ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno)
|
---|
| 210 | {
|
---|
| 211 | ipl_t ipl;
|
---|
| 212 | unative_t key[] = {
|
---|
| 213 | (unative_t) inr,
|
---|
| 214 | (unative_t) devno
|
---|
| 215 | };
|
---|
| 216 | link_t *lnk;
|
---|
| 217 | irq_t *irq;
|
---|
| 218 |
|
---|
| 219 | ipl = interrupts_disable();
|
---|
| 220 | spinlock_lock(&irq_uspace_hash_table_lock);
|
---|
| 221 | lnk = hash_table_find(&irq_uspace_hash_table, key);
|
---|
| 222 | if (!lnk) {
|
---|
| 223 | spinlock_unlock(&irq_uspace_hash_table_lock);
|
---|
| 224 | interrupts_restore(ipl);
|
---|
| 225 | return ENOENT;
|
---|
| 226 | }
|
---|
| 227 | irq = hash_table_get_instance(lnk, irq_t, link);
|
---|
[2845930] | 228 | /* irq is locked */
|
---|
[cecb0789] | 229 | spinlock_lock(&box->irq_lock);
|
---|
| 230 |
|
---|
| 231 | ASSERT(irq->notif_cfg.answerbox == box);
|
---|
| 232 |
|
---|
| 233 | /* Free up the pseudo code and associated structures. */
|
---|
| 234 | code_free(irq->notif_cfg.code);
|
---|
| 235 |
|
---|
| 236 | /* Remove the IRQ from the answerbox's list. */
|
---|
| 237 | list_remove(&irq->notif_cfg.link);
|
---|
[b14e35f2] | 238 |
|
---|
[2845930] | 239 | /*
|
---|
| 240 | * We need to drop the IRQ lock now because hash_table_remove() will try
|
---|
| 241 | * to reacquire it. That basically violates the natural locking order,
|
---|
| 242 | * but a deadlock in hash_table_remove() is prevented by the fact that
|
---|
| 243 | * we already held the IRQ lock and didn't drop the hash table lock in
|
---|
| 244 | * the meantime.
|
---|
| 245 | */
|
---|
| 246 | spinlock_unlock(&irq->lock);
|
---|
| 247 |
|
---|
[cecb0789] | 248 | /* Remove the IRQ from the uspace IRQ hash table. */
|
---|
| 249 | hash_table_remove(&irq_uspace_hash_table, key, 2);
|
---|
| 250 |
|
---|
| 251 | spinlock_unlock(&irq_uspace_hash_table_lock);
|
---|
| 252 | spinlock_unlock(&box->irq_lock);
|
---|
| 253 |
|
---|
| 254 | /* Free up the IRQ structure. */
|
---|
| 255 | free(irq);
|
---|
| 256 |
|
---|
[162f919] | 257 | interrupts_restore(ipl);
|
---|
[cecb0789] | 258 | return EOK;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
[162f919] | 261 |
|
---|
[cecb0789] | 262 | /** Disconnect all IRQ notifications from an answerbox.
|
---|
| 263 | *
|
---|
| 264 | * This function is effective because the answerbox contains
|
---|
| 265 | * list of all irq_t structures that are registered to
|
---|
| 266 | * send notifications to it.
|
---|
| 267 | *
|
---|
| 268 | * @param box Answerbox for which we want to carry out the cleanup.
|
---|
| 269 | */
|
---|
| 270 | void ipc_irq_cleanup(answerbox_t *box)
|
---|
| 271 | {
|
---|
| 272 | ipl_t ipl;
|
---|
| 273 |
|
---|
| 274 | loop:
|
---|
| 275 | ipl = interrupts_disable();
|
---|
| 276 | spinlock_lock(&irq_uspace_hash_table_lock);
|
---|
| 277 | spinlock_lock(&box->irq_lock);
|
---|
| 278 |
|
---|
| 279 | while (box->irq_head.next != &box->irq_head) {
|
---|
| 280 | link_t *cur = box->irq_head.next;
|
---|
| 281 | irq_t *irq;
|
---|
| 282 | DEADLOCK_PROBE_INIT(p_irqlock);
|
---|
| 283 | unative_t key[2];
|
---|
| 284 |
|
---|
| 285 | irq = list_get_instance(cur, irq_t, notif_cfg.link);
|
---|
| 286 | if (!spinlock_trylock(&irq->lock)) {
|
---|
| 287 | /*
|
---|
| 288 | * Avoid deadlock by trying again.
|
---|
| 289 | */
|
---|
| 290 | spinlock_unlock(&box->irq_lock);
|
---|
| 291 | spinlock_unlock(&irq_uspace_hash_table_lock);
|
---|
| 292 | interrupts_restore(ipl);
|
---|
| 293 | DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD);
|
---|
| 294 | goto loop;
|
---|
| 295 | }
|
---|
| 296 | key[0] = irq->inr;
|
---|
| 297 | key[1] = irq->devno;
|
---|
| 298 |
|
---|
| 299 |
|
---|
| 300 | ASSERT(irq->notif_cfg.answerbox == box);
|
---|
| 301 |
|
---|
| 302 | /* Unlist from the answerbox. */
|
---|
| 303 | list_remove(&irq->notif_cfg.link);
|
---|
| 304 |
|
---|
| 305 | /* Free up the pseudo code and associated structures. */
|
---|
| 306 | code_free(irq->notif_cfg.code);
|
---|
| 307 |
|
---|
[2845930] | 308 | /*
|
---|
| 309 | * We need to drop the IRQ lock now because hash_table_remove()
|
---|
| 310 | * will try to reacquire it. That basically violates the natural
|
---|
| 311 | * locking order, but a deadlock in hash_table_remove() is
|
---|
| 312 | * prevented by the fact that we already held the IRQ lock and
|
---|
| 313 | * didn't drop the hash table lock in the meantime.
|
---|
| 314 | */
|
---|
[cecb0789] | 315 | spinlock_unlock(&irq->lock);
|
---|
[37be841] | 316 |
|
---|
| 317 | /* Remove from the hash table. */
|
---|
| 318 | hash_table_remove(&irq_uspace_hash_table, key, 2);
|
---|
| 319 |
|
---|
[cecb0789] | 320 | free(irq);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | spinlock_unlock(&box->irq_lock);
|
---|
| 324 | spinlock_unlock(&irq_uspace_hash_table_lock);
|
---|
| 325 | interrupts_restore(ipl);
|
---|
[162f919] | 326 | }
|
---|
| 327 |
|
---|
[8b243f2] | 328 | /** Add a call to the proper answerbox queue.
|
---|
[2b017ba] | 329 | *
|
---|
| 330 | * Assume irq->lock is locked.
|
---|
[874621f] | 331 | *
|
---|
[8b243f2] | 332 | * @param irq IRQ structure referencing the target answerbox.
|
---|
| 333 | * @param call IRQ notification call.
|
---|
[2b017ba] | 334 | */
|
---|
| 335 | static void send_call(irq_t *irq, call_t *call)
|
---|
[874621f] | 336 | {
|
---|
[2b017ba] | 337 | spinlock_lock(&irq->notif_cfg.answerbox->irq_lock);
|
---|
| 338 | list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs);
|
---|
| 339 | spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock);
|
---|
[874621f] | 340 |
|
---|
[2b017ba] | 341 | waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST);
|
---|
[874621f] | 342 | }
|
---|
| 343 |
|
---|
[cecb0789] | 344 | /** Apply the top-half pseudo code to find out whether to accept the IRQ or not.
|
---|
[874621f] | 345 | *
|
---|
[8b243f2] | 346 | * @param irq IRQ structure.
|
---|
[cecb0789] | 347 | *
|
---|
| 348 | * @return IRQ_ACCEPT if the interrupt is accepted by the
|
---|
| 349 | * pseudocode. IRQ_DECLINE otherwise.
|
---|
[874621f] | 350 | */
|
---|
[cecb0789] | 351 | irq_ownership_t ipc_irq_top_half_claim(irq_t *irq)
|
---|
[874621f] | 352 | {
|
---|
[cecb0789] | 353 | unsigned int i;
|
---|
| 354 | unative_t dstval;
|
---|
| 355 | irq_code_t *code = irq->notif_cfg.code;
|
---|
| 356 | unative_t *scratch = irq->notif_cfg.scratch;
|
---|
[874621f] | 357 |
|
---|
[cecb0789] | 358 |
|
---|
| 359 | if (!irq->notif_cfg.notify)
|
---|
| 360 | return IRQ_DECLINE;
|
---|
| 361 |
|
---|
| 362 | if (!code)
|
---|
| 363 | return IRQ_DECLINE;
|
---|
| 364 |
|
---|
| 365 | for (i = 0; i < code->cmdcount; i++) {
|
---|
| 366 | unsigned int srcarg = code->cmds[i].srcarg;
|
---|
| 367 | unsigned int dstarg = code->cmds[i].dstarg;
|
---|
[874621f] | 368 |
|
---|
[cecb0789] | 369 | if (srcarg >= IPC_CALL_LEN)
|
---|
| 370 | break;
|
---|
| 371 | if (dstarg >= IPC_CALL_LEN)
|
---|
| 372 | break;
|
---|
| 373 |
|
---|
| 374 | switch (code->cmds[i].cmd) {
|
---|
| 375 | case CMD_PIO_READ_8:
|
---|
| 376 | dstval = pio_read_8((ioport8_t *) code->cmds[i].addr);
|
---|
| 377 | if (dstarg)
|
---|
| 378 | scratch[dstarg] = dstval;
|
---|
| 379 | break;
|
---|
| 380 | case CMD_PIO_READ_16:
|
---|
| 381 | dstval = pio_read_16((ioport16_t *) code->cmds[i].addr);
|
---|
| 382 | if (dstarg)
|
---|
| 383 | scratch[dstarg] = dstval;
|
---|
| 384 | break;
|
---|
| 385 | case CMD_PIO_READ_32:
|
---|
| 386 | dstval = pio_read_32((ioport32_t *) code->cmds[i].addr);
|
---|
| 387 | if (dstarg)
|
---|
| 388 | scratch[dstarg] = dstval;
|
---|
| 389 | break;
|
---|
| 390 | case CMD_PIO_WRITE_8:
|
---|
| 391 | pio_write_8((ioport8_t *) code->cmds[i].addr,
|
---|
| 392 | (uint8_t) code->cmds[i].value);
|
---|
| 393 | break;
|
---|
| 394 | case CMD_PIO_WRITE_16:
|
---|
| 395 | pio_write_16((ioport16_t *) code->cmds[i].addr,
|
---|
| 396 | (uint16_t) code->cmds[i].value);
|
---|
| 397 | break;
|
---|
| 398 | case CMD_PIO_WRITE_32:
|
---|
| 399 | pio_write_32((ioport32_t *) code->cmds[i].addr,
|
---|
| 400 | (uint32_t) code->cmds[i].value);
|
---|
| 401 | break;
|
---|
| 402 | case CMD_BTEST:
|
---|
| 403 | if (srcarg && dstarg) {
|
---|
| 404 | dstval = scratch[srcarg] & code->cmds[i].value;
|
---|
| 405 | scratch[dstarg] = dstval;
|
---|
| 406 | }
|
---|
| 407 | break;
|
---|
| 408 | case CMD_PREDICATE:
|
---|
| 409 | if (srcarg && !scratch[srcarg]) {
|
---|
| 410 | i += code->cmds[i].value;
|
---|
| 411 | continue;
|
---|
| 412 | }
|
---|
| 413 | break;
|
---|
| 414 | case CMD_ACCEPT:
|
---|
| 415 | return IRQ_ACCEPT;
|
---|
| 416 | break;
|
---|
| 417 | case CMD_DECLINE:
|
---|
| 418 | default:
|
---|
| 419 | return IRQ_DECLINE;
|
---|
| 420 | }
|
---|
[874621f] | 421 | }
|
---|
[cecb0789] | 422 |
|
---|
| 423 | return IRQ_DECLINE;
|
---|
[874621f] | 424 | }
|
---|
| 425 |
|
---|
[cecb0789] | 426 |
|
---|
| 427 | /* IRQ top-half handler.
|
---|
[162f919] | 428 | *
|
---|
[2b017ba] | 429 | * We expect interrupts to be disabled and the irq->lock already held.
|
---|
[8b243f2] | 430 | *
|
---|
| 431 | * @param irq IRQ structure.
|
---|
[162f919] | 432 | */
|
---|
[cecb0789] | 433 | void ipc_irq_top_half_handler(irq_t *irq)
|
---|
[162f919] | 434 | {
|
---|
[2b017ba] | 435 | ASSERT(irq);
|
---|
[162f919] | 436 |
|
---|
[2b017ba] | 437 | if (irq->notif_cfg.answerbox) {
|
---|
[cecb0789] | 438 | call_t *call;
|
---|
| 439 |
|
---|
[162f919] | 440 | call = ipc_call_alloc(FRAME_ATOMIC);
|
---|
[cecb0789] | 441 | if (!call)
|
---|
[d8f7362] | 442 | return;
|
---|
[cecb0789] | 443 |
|
---|
[162f919] | 444 | call->flags |= IPC_CALL_NOTIF;
|
---|
[43752b6] | 445 | /* Put a counter to the message */
|
---|
[0c1a5d8a] | 446 | call->priv = ++irq->notif_cfg.counter;
|
---|
[cecb0789] | 447 |
|
---|
[43752b6] | 448 | /* Set up args */
|
---|
[2b017ba] | 449 | IPC_SET_METHOD(call->data, irq->notif_cfg.method);
|
---|
[cecb0789] | 450 | IPC_SET_ARG1(call->data, irq->notif_cfg.scratch[1]);
|
---|
| 451 | IPC_SET_ARG2(call->data, irq->notif_cfg.scratch[2]);
|
---|
| 452 | IPC_SET_ARG3(call->data, irq->notif_cfg.scratch[3]);
|
---|
| 453 | IPC_SET_ARG4(call->data, irq->notif_cfg.scratch[4]);
|
---|
| 454 | IPC_SET_ARG5(call->data, irq->notif_cfg.scratch[5]);
|
---|
[162f919] | 455 |
|
---|
[2b017ba] | 456 | send_call(irq, call);
|
---|
[162f919] | 457 | }
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[cecb0789] | 460 | /** Send notification message.
|
---|
[874621f] | 461 | *
|
---|
[cecb0789] | 462 | * @param irq IRQ structure.
|
---|
| 463 | * @param a1 Driver-specific payload argument.
|
---|
| 464 | * @param a2 Driver-specific payload argument.
|
---|
| 465 | * @param a3 Driver-specific payload argument.
|
---|
| 466 | * @param a4 Driver-specific payload argument.
|
---|
| 467 | * @param a5 Driver-specific payload argument.
|
---|
[162f919] | 468 | */
|
---|
[cecb0789] | 469 | void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3,
|
---|
| 470 | unative_t a4, unative_t a5)
|
---|
[162f919] | 471 | {
|
---|
[cecb0789] | 472 | call_t *call;
|
---|
| 473 |
|
---|
| 474 | spinlock_lock(&irq->lock);
|
---|
| 475 |
|
---|
| 476 | if (irq->notif_cfg.answerbox) {
|
---|
| 477 | call = ipc_call_alloc(FRAME_ATOMIC);
|
---|
| 478 | if (!call) {
|
---|
| 479 | spinlock_unlock(&irq->lock);
|
---|
| 480 | return;
|
---|
[b14e35f2] | 481 | }
|
---|
[cecb0789] | 482 | call->flags |= IPC_CALL_NOTIF;
|
---|
| 483 | /* Put a counter to the message */
|
---|
| 484 | call->priv = ++irq->notif_cfg.counter;
|
---|
[b14e35f2] | 485 |
|
---|
[cecb0789] | 486 | IPC_SET_METHOD(call->data, irq->notif_cfg.method);
|
---|
| 487 | IPC_SET_ARG1(call->data, a1);
|
---|
| 488 | IPC_SET_ARG2(call->data, a2);
|
---|
| 489 | IPC_SET_ARG3(call->data, a3);
|
---|
| 490 | IPC_SET_ARG4(call->data, a4);
|
---|
| 491 | IPC_SET_ARG5(call->data, a5);
|
---|
| 492 |
|
---|
| 493 | send_call(irq, call);
|
---|
[b14e35f2] | 494 | }
|
---|
[cecb0789] | 495 | spinlock_unlock(&irq->lock);
|
---|
[162f919] | 496 | }
|
---|
[b45c443] | 497 |
|
---|
[cc73a8a1] | 498 | /** @}
|
---|
[b45c443] | 499 | */
|
---|