[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 | */
|
---|
[da1bafb] | 33 |
|
---|
[cc73a8a1] | 34 | /**
|
---|
| 35 | * @file
|
---|
| 36 | * @brief IRQ notification framework.
|
---|
[bdc5c516] | 37 | *
|
---|
| 38 | * This framework allows applications to register to receive a notification
|
---|
| 39 | * when interrupt is detected. The application may provide a simple 'top-half'
|
---|
| 40 | * handler as part of its registration, which can perform simple operations
|
---|
| 41 | * (read/write port/memory, add information to notification ipc message).
|
---|
| 42 | *
|
---|
| 43 | * The structure of a notification message is as follows:
|
---|
[8add9ca5] | 44 | * - IMETHOD: interface and method as registered by the SYS_REGISTER_IRQ
|
---|
[228e490] | 45 | * syscall
|
---|
[43752b6] | 46 | * - ARG1: payload modified by a 'top-half' handler
|
---|
[2b017ba] | 47 | * - ARG2: payload modified by a 'top-half' handler
|
---|
| 48 | * - ARG3: payload modified by a 'top-half' handler
|
---|
[cecb0789] | 49 | * - ARG4: payload modified by a 'top-half' handler
|
---|
| 50 | * - ARG5: payload modified by a 'top-half' handler
|
---|
[43752b6] | 51 | * - in_phone_hash: interrupt counter (may be needed to assure correct order
|
---|
[228e490] | 52 | * in multithreaded drivers)
|
---|
[cecb0789] | 53 | *
|
---|
| 54 | * Note on synchronization for ipc_irq_register(), ipc_irq_unregister(),
|
---|
| 55 | * ipc_irq_cleanup() and IRQ handlers:
|
---|
| 56 | *
|
---|
| 57 | * By always taking all of the uspace IRQ hash table lock, IRQ structure lock
|
---|
| 58 | * and answerbox lock, we can rule out race conditions between the
|
---|
| 59 | * registration functions and also the cleanup function. Thus the observer can
|
---|
| 60 | * either see the IRQ structure present in both the hash table and the
|
---|
| 61 | * answerbox list or absent in both. Views in which the IRQ structure would be
|
---|
| 62 | * linked in the hash table but not in the answerbox list, or vice versa, are
|
---|
| 63 | * not possible.
|
---|
| 64 | *
|
---|
| 65 | * By always taking the hash table lock and the IRQ structure lock, we can
|
---|
| 66 | * rule out a scenario in which we would free up an IRQ structure, which is
|
---|
| 67 | * still referenced by, for example, an IRQ handler. The locking scheme forces
|
---|
| 68 | * us to lock the IRQ structure only after any progressing IRQs on that
|
---|
| 69 | * structure are finished. Because we hold the hash table lock, we prevent new
|
---|
| 70 | * IRQs from taking new references to the IRQ structure.
|
---|
[da1bafb] | 71 | *
|
---|
[bdc5c516] | 72 | */
|
---|
| 73 |
|
---|
[162f919] | 74 | #include <arch.h>
|
---|
| 75 | #include <mm/slab.h>
|
---|
| 76 | #include <errno.h>
|
---|
[2b017ba] | 77 | #include <ddi/irq.h>
|
---|
[162f919] | 78 | #include <ipc/ipc.h>
|
---|
| 79 | #include <ipc/irq.h>
|
---|
[e3c762cd] | 80 | #include <syscall/copy.h>
|
---|
[d0c5901] | 81 | #include <console/console.h>
|
---|
[253f35a1] | 82 | #include <print.h>
|
---|
[162f919] | 83 |
|
---|
[cecb0789] | 84 | /** Free the top-half pseudocode.
|
---|
[8b243f2] | 85 | *
|
---|
[da1bafb] | 86 | * @param code Pointer to the top-half pseudocode.
|
---|
| 87 | *
|
---|
[8b243f2] | 88 | */
|
---|
[162f919] | 89 | static void code_free(irq_code_t *code)
|
---|
| 90 | {
|
---|
| 91 | if (code) {
|
---|
| 92 | free(code->cmds);
|
---|
| 93 | free(code);
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[cecb0789] | 97 | /** Copy the top-half pseudocode from userspace into the kernel.
|
---|
[8b243f2] | 98 | *
|
---|
[da1bafb] | 99 | * @param ucode Userspace address of the top-half pseudocode.
|
---|
| 100 | *
|
---|
| 101 | * @return Kernel address of the copied pseudocode.
|
---|
[8b243f2] | 102 | *
|
---|
| 103 | */
|
---|
| 104 | static irq_code_t *code_from_uspace(irq_code_t *ucode)
|
---|
[162f919] | 105 | {
|
---|
[da1bafb] | 106 | irq_code_t *code = malloc(sizeof(*code), 0);
|
---|
| 107 | int rc = copy_from_uspace(code, ucode, sizeof(*code));
|
---|
[e3c762cd] | 108 | if (rc != 0) {
|
---|
| 109 | free(code);
|
---|
| 110 | return NULL;
|
---|
| 111 | }
|
---|
[162f919] | 112 |
|
---|
| 113 | if (code->cmdcount > IRQ_MAX_PROG_SIZE) {
|
---|
| 114 | free(code);
|
---|
| 115 | return NULL;
|
---|
| 116 | }
|
---|
[da1bafb] | 117 |
|
---|
| 118 | irq_cmd_t *ucmds = code->cmds;
|
---|
[8b243f2] | 119 | code->cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, 0);
|
---|
| 120 | rc = copy_from_uspace(code->cmds, ucmds,
|
---|
| 121 | sizeof(code->cmds[0]) * code->cmdcount);
|
---|
[e3c762cd] | 122 | if (rc != 0) {
|
---|
| 123 | free(code->cmds);
|
---|
| 124 | free(code);
|
---|
| 125 | return NULL;
|
---|
| 126 | }
|
---|
[da1bafb] | 127 |
|
---|
[162f919] | 128 | return code;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[2b017ba] | 131 | /** Register an answerbox as a receiving end for IRQ notifications.
|
---|
| 132 | *
|
---|
[78ffb70] | 133 | * @param box Receiving answerbox.
|
---|
| 134 | * @param inr IRQ number.
|
---|
| 135 | * @param devno Device number.
|
---|
| 136 | * @param imethod Interface and method to be associated with the
|
---|
| 137 | * notification.
|
---|
| 138 | * @param ucode Uspace pointer to top-half pseudocode.
|
---|
| 139 | * @return EOK on success or a negative error code.
|
---|
[2b017ba] | 140 | *
|
---|
| 141 | */
|
---|
[8b243f2] | 142 | int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno,
|
---|
[228e490] | 143 | sysarg_t imethod, irq_code_t *ucode)
|
---|
[162f919] | 144 | {
|
---|
[96b02eb9] | 145 | sysarg_t key[] = {
|
---|
| 146 | (sysarg_t) inr,
|
---|
| 147 | (sysarg_t) devno
|
---|
[cecb0789] | 148 | };
|
---|
[78ffb70] | 149 |
|
---|
| 150 | if ((inr < 0) || (inr > last_inr))
|
---|
| 151 | return ELIMIT;
|
---|
[c822026] | 152 |
|
---|
[da1bafb] | 153 | irq_code_t *code;
|
---|
[162f919] | 154 | if (ucode) {
|
---|
| 155 | code = code_from_uspace(ucode);
|
---|
| 156 | if (!code)
|
---|
| 157 | return EBADMEM;
|
---|
[da1bafb] | 158 | } else
|
---|
[162f919] | 159 | code = NULL;
|
---|
[c822026] | 160 |
|
---|
[cecb0789] | 161 | /*
|
---|
| 162 | * Allocate and populate the IRQ structure.
|
---|
| 163 | */
|
---|
[da1bafb] | 164 | irq_t *irq = malloc(sizeof(irq_t), 0);
|
---|
| 165 |
|
---|
[cecb0789] | 166 | irq_initialize(irq);
|
---|
| 167 | irq->devno = devno;
|
---|
| 168 | irq->inr = inr;
|
---|
| 169 | irq->claim = ipc_irq_top_half_claim;
|
---|
[691eb52] | 170 | irq->handler = ipc_irq_top_half_handler;
|
---|
[4874c2d] | 171 | irq->notif_cfg.notify = true;
|
---|
[2b017ba] | 172 | irq->notif_cfg.answerbox = box;
|
---|
[228e490] | 173 | irq->notif_cfg.imethod = imethod;
|
---|
[2b017ba] | 174 | irq->notif_cfg.code = code;
|
---|
| 175 | irq->notif_cfg.counter = 0;
|
---|
[180255f] | 176 | irq->driver_as = AS;
|
---|
[c822026] | 177 |
|
---|
[cecb0789] | 178 | /*
|
---|
| 179 | * Enlist the IRQ structure in the uspace IRQ hash table and the
|
---|
| 180 | * answerbox's list.
|
---|
| 181 | */
|
---|
[da1bafb] | 182 | irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
|
---|
| 183 |
|
---|
| 184 | link_t *hlp = hash_table_find(&irq_uspace_hash_table, key);
|
---|
[2845930] | 185 | if (hlp) {
|
---|
[da1bafb] | 186 | irq_t *hirq = hash_table_get_instance(hlp, irq_t, link);
|
---|
[c822026] | 187 |
|
---|
[2845930] | 188 | /* hirq is locked */
|
---|
[da1bafb] | 189 | irq_spinlock_unlock(&hirq->lock, false);
|
---|
[cecb0789] | 190 | code_free(code);
|
---|
[da1bafb] | 191 | irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
|
---|
| 192 |
|
---|
[cecb0789] | 193 | free(irq);
|
---|
| 194 | return EEXISTS;
|
---|
| 195 | }
|
---|
[c822026] | 196 |
|
---|
[da1bafb] | 197 | /* Locking is not really necessary, but paranoid */
|
---|
| 198 | irq_spinlock_lock(&irq->lock, false);
|
---|
| 199 | irq_spinlock_lock(&box->irq_lock, false);
|
---|
| 200 |
|
---|
[cecb0789] | 201 | hash_table_insert(&irq_uspace_hash_table, key, &irq->link);
|
---|
[b14e35f2] | 202 | list_append(&irq->notif_cfg.link, &box->irq_head);
|
---|
[c822026] | 203 |
|
---|
[da1bafb] | 204 | irq_spinlock_unlock(&box->irq_lock, false);
|
---|
| 205 | irq_spinlock_unlock(&irq->lock, false);
|
---|
| 206 | irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
|
---|
| 207 |
|
---|
[cecb0789] | 208 | return EOK;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | /** Unregister task from IRQ notification.
|
---|
| 212 | *
|
---|
[78ffb70] | 213 | * @param box Answerbox associated with the notification.
|
---|
| 214 | * @param inr IRQ number.
|
---|
| 215 | * @param devno Device number.
|
---|
| 216 | * @return EOK on success or a negative error code.
|
---|
[cecb0789] | 217 | */
|
---|
| 218 | int ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno)
|
---|
| 219 | {
|
---|
[96b02eb9] | 220 | sysarg_t key[] = {
|
---|
| 221 | (sysarg_t) inr,
|
---|
| 222 | (sysarg_t) devno
|
---|
[cecb0789] | 223 | };
|
---|
[78ffb70] | 224 |
|
---|
| 225 | if ((inr < 0) || (inr > last_inr))
|
---|
| 226 | return ELIMIT;
|
---|
[da1bafb] | 227 |
|
---|
| 228 | irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
|
---|
| 229 | link_t *lnk = hash_table_find(&irq_uspace_hash_table, key);
|
---|
[cecb0789] | 230 | if (!lnk) {
|
---|
[da1bafb] | 231 | irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
|
---|
[cecb0789] | 232 | return ENOENT;
|
---|
| 233 | }
|
---|
[da1bafb] | 234 |
|
---|
| 235 | irq_t *irq = hash_table_get_instance(lnk, irq_t, link);
|
---|
| 236 |
|
---|
[2845930] | 237 | /* irq is locked */
|
---|
[da1bafb] | 238 | irq_spinlock_lock(&box->irq_lock, false);
|
---|
[cecb0789] | 239 |
|
---|
| 240 | ASSERT(irq->notif_cfg.answerbox == box);
|
---|
| 241 |
|
---|
| 242 | /* Free up the pseudo code and associated structures. */
|
---|
| 243 | code_free(irq->notif_cfg.code);
|
---|
[da1bafb] | 244 |
|
---|
| 245 | /* Remove the IRQ from the answerbox's list. */
|
---|
[cecb0789] | 246 | list_remove(&irq->notif_cfg.link);
|
---|
[da1bafb] | 247 |
|
---|
[2845930] | 248 | /*
|
---|
| 249 | * We need to drop the IRQ lock now because hash_table_remove() will try
|
---|
| 250 | * to reacquire it. That basically violates the natural locking order,
|
---|
| 251 | * but a deadlock in hash_table_remove() is prevented by the fact that
|
---|
| 252 | * we already held the IRQ lock and didn't drop the hash table lock in
|
---|
| 253 | * the meantime.
|
---|
| 254 | */
|
---|
[da1bafb] | 255 | irq_spinlock_unlock(&irq->lock, false);
|
---|
| 256 |
|
---|
[cecb0789] | 257 | /* Remove the IRQ from the uspace IRQ hash table. */
|
---|
| 258 | hash_table_remove(&irq_uspace_hash_table, key, 2);
|
---|
| 259 |
|
---|
[da1bafb] | 260 | irq_spinlock_unlock(&box->irq_lock, false);
|
---|
| 261 | irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
|
---|
[cecb0789] | 262 |
|
---|
| 263 | /* Free up the IRQ structure. */
|
---|
| 264 | free(irq);
|
---|
| 265 |
|
---|
| 266 | return EOK;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | /** Disconnect all IRQ notifications from an answerbox.
|
---|
| 270 | *
|
---|
| 271 | * This function is effective because the answerbox contains
|
---|
| 272 | * list of all irq_t structures that are registered to
|
---|
| 273 | * send notifications to it.
|
---|
| 274 | *
|
---|
[da1bafb] | 275 | * @param box Answerbox for which we want to carry out the cleanup.
|
---|
| 276 | *
|
---|
[cecb0789] | 277 | */
|
---|
| 278 | void ipc_irq_cleanup(answerbox_t *box)
|
---|
| 279 | {
|
---|
| 280 | loop:
|
---|
[da1bafb] | 281 | irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
|
---|
| 282 | irq_spinlock_lock(&box->irq_lock, false);
|
---|
[cecb0789] | 283 |
|
---|
| 284 | while (box->irq_head.next != &box->irq_head) {
|
---|
| 285 | DEADLOCK_PROBE_INIT(p_irqlock);
|
---|
| 286 |
|
---|
[da1bafb] | 287 | irq_t *irq = list_get_instance(box->irq_head.next, irq_t,
|
---|
| 288 | notif_cfg.link);
|
---|
| 289 |
|
---|
| 290 | if (!irq_spinlock_trylock(&irq->lock)) {
|
---|
[cecb0789] | 291 | /*
|
---|
| 292 | * Avoid deadlock by trying again.
|
---|
| 293 | */
|
---|
[da1bafb] | 294 | irq_spinlock_unlock(&box->irq_lock, false);
|
---|
| 295 | irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
|
---|
[cecb0789] | 296 | DEADLOCK_PROBE(p_irqlock, DEADLOCK_THRESHOLD);
|
---|
| 297 | goto loop;
|
---|
| 298 | }
|
---|
[da1bafb] | 299 |
|
---|
[96b02eb9] | 300 | sysarg_t key[2];
|
---|
[cecb0789] | 301 | key[0] = irq->inr;
|
---|
| 302 | key[1] = irq->devno;
|
---|
| 303 |
|
---|
| 304 | ASSERT(irq->notif_cfg.answerbox == box);
|
---|
| 305 |
|
---|
| 306 | /* Unlist from the answerbox. */
|
---|
| 307 | list_remove(&irq->notif_cfg.link);
|
---|
| 308 |
|
---|
| 309 | /* Free up the pseudo code and associated structures. */
|
---|
| 310 | code_free(irq->notif_cfg.code);
|
---|
| 311 |
|
---|
[2845930] | 312 | /*
|
---|
| 313 | * We need to drop the IRQ lock now because hash_table_remove()
|
---|
| 314 | * will try to reacquire it. That basically violates the natural
|
---|
| 315 | * locking order, but a deadlock in hash_table_remove() is
|
---|
| 316 | * prevented by the fact that we already held the IRQ lock and
|
---|
| 317 | * didn't drop the hash table lock in the meantime.
|
---|
| 318 | */
|
---|
[da1bafb] | 319 | irq_spinlock_unlock(&irq->lock, false);
|
---|
[37be841] | 320 |
|
---|
| 321 | /* Remove from the hash table. */
|
---|
| 322 | hash_table_remove(&irq_uspace_hash_table, key, 2);
|
---|
| 323 |
|
---|
[cecb0789] | 324 | free(irq);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
[da1bafb] | 327 | irq_spinlock_unlock(&box->irq_lock, false);
|
---|
| 328 | irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
|
---|
[162f919] | 329 | }
|
---|
| 330 |
|
---|
[8b243f2] | 331 | /** Add a call to the proper answerbox queue.
|
---|
[2b017ba] | 332 | *
|
---|
[da1bafb] | 333 | * Assume irq->lock is locked and interrupts disabled.
|
---|
| 334 | *
|
---|
| 335 | * @param irq IRQ structure referencing the target answerbox.
|
---|
| 336 | * @param call IRQ notification call.
|
---|
[874621f] | 337 | *
|
---|
[2b017ba] | 338 | */
|
---|
| 339 | static void send_call(irq_t *irq, call_t *call)
|
---|
[874621f] | 340 | {
|
---|
[da1bafb] | 341 | irq_spinlock_lock(&irq->notif_cfg.answerbox->irq_lock, false);
|
---|
[2b017ba] | 342 | list_append(&call->link, &irq->notif_cfg.answerbox->irq_notifs);
|
---|
[da1bafb] | 343 | irq_spinlock_unlock(&irq->notif_cfg.answerbox->irq_lock, false);
|
---|
| 344 |
|
---|
[2b017ba] | 345 | waitq_wakeup(&irq->notif_cfg.answerbox->wq, WAKEUP_FIRST);
|
---|
[874621f] | 346 | }
|
---|
| 347 |
|
---|
[cecb0789] | 348 | /** Apply the top-half pseudo code to find out whether to accept the IRQ or not.
|
---|
[874621f] | 349 | *
|
---|
[da1bafb] | 350 | * @param irq IRQ structure.
|
---|
| 351 | *
|
---|
| 352 | * @return IRQ_ACCEPT if the interrupt is accepted by the
|
---|
| 353 | * pseudocode, IRQ_DECLINE otherwise.
|
---|
[cecb0789] | 354 | *
|
---|
[874621f] | 355 | */
|
---|
[cecb0789] | 356 | irq_ownership_t ipc_irq_top_half_claim(irq_t *irq)
|
---|
[874621f] | 357 | {
|
---|
[cecb0789] | 358 | irq_code_t *code = irq->notif_cfg.code;
|
---|
[da1bafb] | 359 | uint32_t *scratch = irq->notif_cfg.scratch;
|
---|
[cecb0789] | 360 |
|
---|
| 361 | if (!irq->notif_cfg.notify)
|
---|
| 362 | return IRQ_DECLINE;
|
---|
| 363 |
|
---|
| 364 | if (!code)
|
---|
| 365 | return IRQ_DECLINE;
|
---|
| 366 |
|
---|
[180255f] | 367 | #define CMD_MEM_READ(target) \
|
---|
| 368 | do { \
|
---|
| 369 | void *va = code->cmds[i].addr; \
|
---|
| 370 | if (AS != irq->driver_as) \
|
---|
| 371 | as_switch(AS, irq->driver_as); \
|
---|
| 372 | memcpy_from_uspace(&target, va, (sizeof(target))); \
|
---|
| 373 | if (dstarg) \
|
---|
| 374 | scratch[dstarg] = target; \
|
---|
| 375 | } while(0)
|
---|
| 376 |
|
---|
| 377 | #define CMD_MEM_WRITE(val) \
|
---|
| 378 | do { \
|
---|
| 379 | void *va = code->cmds[i].addr; \
|
---|
| 380 | if (AS != irq->driver_as) \
|
---|
| 381 | as_switch(AS, irq->driver_as); \
|
---|
| 382 | memcpy_to_uspace(va, &val, sizeof(val)); \
|
---|
| 383 | } while (0)
|
---|
| 384 |
|
---|
| 385 | as_t *current_as = AS;
|
---|
[da1bafb] | 386 | size_t i;
|
---|
[cecb0789] | 387 | for (i = 0; i < code->cmdcount; i++) {
|
---|
[da1bafb] | 388 | uint32_t dstval;
|
---|
| 389 | uintptr_t srcarg = code->cmds[i].srcarg;
|
---|
| 390 | uintptr_t dstarg = code->cmds[i].dstarg;
|
---|
[874621f] | 391 |
|
---|
[cecb0789] | 392 | if (srcarg >= IPC_CALL_LEN)
|
---|
| 393 | break;
|
---|
[da1bafb] | 394 |
|
---|
[cecb0789] | 395 | if (dstarg >= IPC_CALL_LEN)
|
---|
| 396 | break;
|
---|
| 397 |
|
---|
| 398 | switch (code->cmds[i].cmd) {
|
---|
| 399 | case CMD_PIO_READ_8:
|
---|
| 400 | dstval = pio_read_8((ioport8_t *) code->cmds[i].addr);
|
---|
| 401 | if (dstarg)
|
---|
| 402 | scratch[dstarg] = dstval;
|
---|
| 403 | break;
|
---|
| 404 | case CMD_PIO_READ_16:
|
---|
| 405 | dstval = pio_read_16((ioport16_t *) code->cmds[i].addr);
|
---|
| 406 | if (dstarg)
|
---|
| 407 | scratch[dstarg] = dstval;
|
---|
| 408 | break;
|
---|
| 409 | case CMD_PIO_READ_32:
|
---|
| 410 | dstval = pio_read_32((ioport32_t *) code->cmds[i].addr);
|
---|
| 411 | if (dstarg)
|
---|
| 412 | scratch[dstarg] = dstval;
|
---|
| 413 | break;
|
---|
| 414 | case CMD_PIO_WRITE_8:
|
---|
| 415 | pio_write_8((ioport8_t *) code->cmds[i].addr,
|
---|
| 416 | (uint8_t) code->cmds[i].value);
|
---|
| 417 | break;
|
---|
| 418 | case CMD_PIO_WRITE_16:
|
---|
| 419 | pio_write_16((ioport16_t *) code->cmds[i].addr,
|
---|
| 420 | (uint16_t) code->cmds[i].value);
|
---|
| 421 | break;
|
---|
| 422 | case CMD_PIO_WRITE_32:
|
---|
| 423 | pio_write_32((ioport32_t *) code->cmds[i].addr,
|
---|
| 424 | (uint32_t) code->cmds[i].value);
|
---|
| 425 | break;
|
---|
[9cdac5a] | 426 | case CMD_PIO_WRITE_A_8:
|
---|
| 427 | if (srcarg) {
|
---|
| 428 | pio_write_8((ioport8_t *) code->cmds[i].addr,
|
---|
| 429 | (uint8_t) scratch[srcarg]);
|
---|
| 430 | }
|
---|
| 431 | break;
|
---|
| 432 | case CMD_PIO_WRITE_A_16:
|
---|
| 433 | if (srcarg) {
|
---|
| 434 | pio_write_16((ioport16_t *) code->cmds[i].addr,
|
---|
| 435 | (uint16_t) scratch[srcarg]);
|
---|
| 436 | }
|
---|
| 437 | break;
|
---|
| 438 | case CMD_PIO_WRITE_A_32:
|
---|
| 439 | if (srcarg) {
|
---|
| 440 | pio_write_32((ioport32_t *) code->cmds[i].addr,
|
---|
| 441 | (uint32_t) scratch[srcarg]);
|
---|
| 442 | }
|
---|
| 443 | break;
|
---|
[180255f] | 444 | case CMD_MEM_READ_8: {
|
---|
| 445 | uint8_t val;
|
---|
| 446 | CMD_MEM_READ(val);
|
---|
| 447 | break;
|
---|
| 448 | }
|
---|
| 449 | case CMD_MEM_READ_16: {
|
---|
| 450 | uint16_t val;
|
---|
| 451 | CMD_MEM_READ(val);
|
---|
| 452 | break;
|
---|
| 453 | }
|
---|
| 454 | case CMD_MEM_READ_32: {
|
---|
| 455 | uint32_t val;
|
---|
| 456 | CMD_MEM_READ(val);
|
---|
| 457 | break;
|
---|
| 458 | }
|
---|
| 459 | case CMD_MEM_WRITE_8: {
|
---|
| 460 | uint8_t val = code->cmds[i].value;
|
---|
| 461 | CMD_MEM_WRITE(val);
|
---|
| 462 | break;
|
---|
| 463 | }
|
---|
| 464 | case CMD_MEM_WRITE_16: {
|
---|
| 465 | uint16_t val = code->cmds[i].value;
|
---|
| 466 | CMD_MEM_WRITE(val);
|
---|
| 467 | break;
|
---|
| 468 | }
|
---|
| 469 | case CMD_MEM_WRITE_32: {
|
---|
| 470 | uint32_t val = code->cmds[i].value;
|
---|
| 471 | CMD_MEM_WRITE(val);
|
---|
| 472 | break;
|
---|
| 473 | }
|
---|
| 474 | case CMD_MEM_WRITE_A_8:
|
---|
| 475 | if (srcarg) {
|
---|
| 476 | uint8_t val = scratch[srcarg];
|
---|
| 477 | CMD_MEM_WRITE(val);
|
---|
| 478 | }
|
---|
| 479 | break;
|
---|
| 480 | case CMD_MEM_WRITE_A_16:
|
---|
| 481 | if (srcarg) {
|
---|
| 482 | uint16_t val = scratch[srcarg];
|
---|
| 483 | CMD_MEM_WRITE(val);
|
---|
| 484 | }
|
---|
| 485 | break;
|
---|
| 486 | case CMD_MEM_WRITE_A_32:
|
---|
| 487 | if (srcarg) {
|
---|
| 488 | uint32_t val = scratch[srcarg];
|
---|
| 489 | CMD_MEM_WRITE(val);
|
---|
| 490 | }
|
---|
| 491 | break;
|
---|
[cecb0789] | 492 | case CMD_BTEST:
|
---|
[da1bafb] | 493 | if ((srcarg) && (dstarg)) {
|
---|
[cecb0789] | 494 | dstval = scratch[srcarg] & code->cmds[i].value;
|
---|
| 495 | scratch[dstarg] = dstval;
|
---|
| 496 | }
|
---|
| 497 | break;
|
---|
| 498 | case CMD_PREDICATE:
|
---|
[da1bafb] | 499 | if ((srcarg) && (!scratch[srcarg])) {
|
---|
[cecb0789] | 500 | i += code->cmds[i].value;
|
---|
| 501 | continue;
|
---|
| 502 | }
|
---|
| 503 | break;
|
---|
| 504 | case CMD_ACCEPT:
|
---|
[180255f] | 505 | if (AS != current_as)
|
---|
| 506 | as_switch(AS, current_as);
|
---|
[cecb0789] | 507 | return IRQ_ACCEPT;
|
---|
| 508 | case CMD_DECLINE:
|
---|
| 509 | default:
|
---|
[180255f] | 510 | if (AS != current_as)
|
---|
| 511 | as_switch(AS, current_as);
|
---|
[cecb0789] | 512 | return IRQ_DECLINE;
|
---|
| 513 | }
|
---|
[874621f] | 514 | }
|
---|
[180255f] | 515 | if (AS != current_as)
|
---|
| 516 | as_switch(AS, current_as);
|
---|
[cecb0789] | 517 |
|
---|
| 518 | return IRQ_DECLINE;
|
---|
[874621f] | 519 | }
|
---|
| 520 |
|
---|
[cecb0789] | 521 | /* IRQ top-half handler.
|
---|
[162f919] | 522 | *
|
---|
[2b017ba] | 523 | * We expect interrupts to be disabled and the irq->lock already held.
|
---|
[8b243f2] | 524 | *
|
---|
[da1bafb] | 525 | * @param irq IRQ structure.
|
---|
| 526 | *
|
---|
[162f919] | 527 | */
|
---|
[cecb0789] | 528 | void ipc_irq_top_half_handler(irq_t *irq)
|
---|
[162f919] | 529 | {
|
---|
[2b017ba] | 530 | ASSERT(irq);
|
---|
[1d432f9] | 531 |
|
---|
| 532 | ASSERT(interrupts_disabled());
|
---|
| 533 | ASSERT(irq_spinlock_locked(&irq->lock));
|
---|
[da1bafb] | 534 |
|
---|
[2b017ba] | 535 | if (irq->notif_cfg.answerbox) {
|
---|
[da1bafb] | 536 | call_t *call = ipc_call_alloc(FRAME_ATOMIC);
|
---|
[cecb0789] | 537 | if (!call)
|
---|
[d8f7362] | 538 | return;
|
---|
[cecb0789] | 539 |
|
---|
[162f919] | 540 | call->flags |= IPC_CALL_NOTIF;
|
---|
[43752b6] | 541 | /* Put a counter to the message */
|
---|
[0c1a5d8a] | 542 | call->priv = ++irq->notif_cfg.counter;
|
---|
[da1bafb] | 543 |
|
---|
[43752b6] | 544 | /* Set up args */
|
---|
[228e490] | 545 | IPC_SET_IMETHOD(call->data, irq->notif_cfg.imethod);
|
---|
[cecb0789] | 546 | IPC_SET_ARG1(call->data, irq->notif_cfg.scratch[1]);
|
---|
| 547 | IPC_SET_ARG2(call->data, irq->notif_cfg.scratch[2]);
|
---|
| 548 | IPC_SET_ARG3(call->data, irq->notif_cfg.scratch[3]);
|
---|
| 549 | IPC_SET_ARG4(call->data, irq->notif_cfg.scratch[4]);
|
---|
| 550 | IPC_SET_ARG5(call->data, irq->notif_cfg.scratch[5]);
|
---|
[da1bafb] | 551 |
|
---|
[2b017ba] | 552 | send_call(irq, call);
|
---|
[162f919] | 553 | }
|
---|
| 554 | }
|
---|
| 555 |
|
---|
[cecb0789] | 556 | /** Send notification message.
|
---|
[874621f] | 557 | *
|
---|
[da1bafb] | 558 | * @param irq IRQ structure.
|
---|
| 559 | * @param a1 Driver-specific payload argument.
|
---|
| 560 | * @param a2 Driver-specific payload argument.
|
---|
| 561 | * @param a3 Driver-specific payload argument.
|
---|
| 562 | * @param a4 Driver-specific payload argument.
|
---|
| 563 | * @param a5 Driver-specific payload argument.
|
---|
| 564 | *
|
---|
[162f919] | 565 | */
|
---|
[96b02eb9] | 566 | void ipc_irq_send_msg(irq_t *irq, sysarg_t a1, sysarg_t a2, sysarg_t a3,
|
---|
| 567 | sysarg_t a4, sysarg_t a5)
|
---|
[162f919] | 568 | {
|
---|
[da1bafb] | 569 | irq_spinlock_lock(&irq->lock, true);
|
---|
| 570 |
|
---|
[cecb0789] | 571 | if (irq->notif_cfg.answerbox) {
|
---|
[da1bafb] | 572 | call_t *call = ipc_call_alloc(FRAME_ATOMIC);
|
---|
[cecb0789] | 573 | if (!call) {
|
---|
[da1bafb] | 574 | irq_spinlock_unlock(&irq->lock, true);
|
---|
[cecb0789] | 575 | return;
|
---|
[b14e35f2] | 576 | }
|
---|
[da1bafb] | 577 |
|
---|
[cecb0789] | 578 | call->flags |= IPC_CALL_NOTIF;
|
---|
| 579 | /* Put a counter to the message */
|
---|
| 580 | call->priv = ++irq->notif_cfg.counter;
|
---|
[da1bafb] | 581 |
|
---|
[228e490] | 582 | IPC_SET_IMETHOD(call->data, irq->notif_cfg.imethod);
|
---|
[cecb0789] | 583 | IPC_SET_ARG1(call->data, a1);
|
---|
| 584 | IPC_SET_ARG2(call->data, a2);
|
---|
| 585 | IPC_SET_ARG3(call->data, a3);
|
---|
| 586 | IPC_SET_ARG4(call->data, a4);
|
---|
| 587 | IPC_SET_ARG5(call->data, a5);
|
---|
| 588 |
|
---|
| 589 | send_call(irq, call);
|
---|
[b14e35f2] | 590 | }
|
---|
[da1bafb] | 591 |
|
---|
| 592 | irq_spinlock_unlock(&irq->lock, true);
|
---|
[162f919] | 593 | }
|
---|
[b45c443] | 594 |
|
---|
[cc73a8a1] | 595 | /** @}
|
---|
[b45c443] | 596 | */
|
---|