Changeset 56c167c in mainline for kernel/generic/src/ipc/irq.c


Ignore:
Timestamp:
2012-07-21T13:47:22Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8486c07
Parents:
fb7e545e
Message:

cstyle (no change in functionality)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/irq.c

    rfb7e545e r56c167c  
    3939 * when interrupt is detected. The application may provide a simple 'top-half'
    4040 * handler as part of its registration, which can perform simple operations
    41  * (read/write port/memory, add information to notification ipc message).
     41 * (read/write port/memory, add information to notification IPC message).
    4242 *
    4343 * The structure of a notification message is as follows:
    4444 * - IMETHOD: interface and method as registered by
    4545 *            the SYS_IRQ_REGISTER syscall
    46  * - ARG1: payload modified by a 'top-half' handler
    47  * - ARG2: payload modified by a 'top-half' handler
    48  * - ARG3: payload modified by a 'top-half' handler
    49  * - ARG4: payload modified by a 'top-half' handler
    50  * - ARG5: payload modified by a 'top-half' handler
     46 * - ARG1: payload modified by a 'top-half' handler (scratch[1])
     47 * - ARG2: payload modified by a 'top-half' handler (scratch[2])
     48 * - ARG3: payload modified by a 'top-half' handler (scratch[3])
     49 * - ARG4: payload modified by a 'top-half' handler (scratch[4])
     50 * - ARG5: payload modified by a 'top-half' handler (scratch[5])
    5151 * - in_phone_hash: interrupt counter (may be needed to assure correct order
    5252 *                  in multithreaded drivers)
     
    8787static void ranges_unmap(irq_pio_range_t *ranges, size_t rangecount)
    8888{
    89         size_t i;
    90 
    91         for (i = 0; i < rangecount; i++) {
     89        for (size_t i = 0; i < rangecount; i++) {
    9290#ifdef IO_SPACE_BOUNDARY
    9391                if ((void *) ranges[i].base >= IO_SPACE_BOUNDARY)
     
    10098    irq_cmd_t *cmds, size_t cmdcount)
    10199{
    102         uintptr_t *pbase;
    103         size_t i, j;
    104 
    105100        /* Copy the physical base addresses aside. */
    106         pbase = malloc(rangecount * sizeof(uintptr_t), 0);
    107         for (i = 0; i < rangecount; i++)
     101        uintptr_t *pbase = malloc(rangecount * sizeof(uintptr_t), 0);
     102        for (size_t i = 0; i < rangecount; i++)
    108103                pbase[i] = ranges[i].base;
    109 
     104       
    110105        /* Map the PIO ranges into the kernel virtual address space. */
    111         for (i = 0; i < rangecount; i++) {
     106        for (size_t i = 0; i < rangecount; i++) {
    112107#ifdef IO_SPACE_BOUNDARY
    113108                if ((void *) ranges[i].base < IO_SPACE_BOUNDARY)
     
    122117                }
    123118        }
    124 
     119       
    125120        /* Rewrite the pseudocode addresses from physical to kernel virtual. */
    126         for (i = 0; i < cmdcount; i++) {
     121        for (size_t i = 0; i < cmdcount; i++) {
    127122                uintptr_t addr;
    128123                size_t size;
    129 
     124               
    130125                /* Process only commands that use an address. */
    131126                switch (cmds[i].cmd) {
    132127                case CMD_PIO_READ_8:
    133                 case CMD_PIO_WRITE_8:
    134                 case CMD_PIO_WRITE_A_8:
     128                case CMD_PIO_WRITE_8:
     129                case CMD_PIO_WRITE_A_8:
    135130                        size = 1;
    136131                        break;
    137                 case CMD_PIO_READ_16:
    138                 case CMD_PIO_WRITE_16:
    139                 case CMD_PIO_WRITE_A_16:
     132                case CMD_PIO_READ_16:
     133                case CMD_PIO_WRITE_16:
     134                case CMD_PIO_WRITE_A_16:
    140135                        size = 2;
    141136                        break;
    142                 case CMD_PIO_READ_32:
    143                 case CMD_PIO_WRITE_32:
    144                 case CMD_PIO_WRITE_A_32:
     137                case CMD_PIO_READ_32:
     138                case CMD_PIO_WRITE_32:
     139                case CMD_PIO_WRITE_A_32:
    145140                        size = 4;
    146141                        break;
     
    149144                        continue;
    150145                }
    151 
     146               
    152147                addr = (uintptr_t) cmds[i].addr;
    153148               
     149                size_t j;
    154150                for (j = 0; j < rangecount; j++) {
    155 
    156151                        /* Find the matching range. */
    157152                        if (!iswithin(pbase[j], ranges[j].size, addr, size))
    158153                                continue;
    159 
     154                       
    160155                        /* Switch the command to a kernel virtual address. */
    161156                        addr -= pbase[j];
    162157                        addr += ranges[j].base;
    163 
     158                       
    164159                        cmds[i].addr = (void *) addr;
    165160                        break;
    166161                }
    167 
     162               
    168163                if (j == rangecount) {
    169164                        /*
     
    176171                }
    177172        }
    178 
     173       
    179174        free(pbase);
    180175        return EOK;
     
    207202        irq_pio_range_t *ranges = NULL;
    208203        irq_cmd_t *cmds = NULL;
    209 
     204       
    210205        irq_code_t *code = malloc(sizeof(*code), 0);
    211206        int rc = copy_from_uspace(code, ucode, sizeof(*code));
     
    222217        if (rc != EOK)
    223218                goto error;
    224 
     219       
    225220        cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, 0);
    226221        rc = copy_from_uspace(cmds, code->cmds,
     
    233228        if (rc != EOK)
    234229                goto error;
    235 
     230       
    236231        code->ranges = ranges;
    237232        code->cmds = cmds;
    238 
     233       
    239234        return code;
    240 
     235       
    241236error:
    242237        if (cmds)
    243238                free(cmds);
     239       
    244240        if (ranges)
    245241                free(ranges);
     242       
    246243        free(code);
    247244        return NULL;
     
    250247/** Register an answerbox as a receiving end for IRQ notifications.
    251248 *
    252  * @param box           Receiving answerbox.
    253  * @param inr           IRQ number.
    254  * @param devno         Device number.
    255  * @param imethod       Interface and method to be associated with the
    256  *                      notification.
    257  * @param ucode         Uspace pointer to top-half pseudocode.
    258  * @return              EOK on success or a negative error code.
     249 * @param box     Receiving answerbox.
     250 * @param inr     IRQ number.
     251 * @param devno   Device number.
     252 * @param imethod Interface and method to be associated with the
     253 *                notification.
     254 * @param ucode   Uspace pointer to top-half pseudocode.
     255 *
     256 * @return EOK on success or a negative error code.
    259257 *
    260258 */
     
    266264                (sysarg_t) devno
    267265        };
    268 
     266       
    269267        if ((inr < 0) || (inr > last_inr))
    270268                return ELIMIT;
     
    329327/** Unregister task from IRQ notification.
    330328 *
    331  * @param box           Answerbox associated with the notification.
    332  * @param inr           IRQ number.
    333  * @param devno         Device number.
    334  * @return              EOK on success or a negative error code.
     329 * @param box   Answerbox associated with the notification.
     330 * @param inr   IRQ number.
     331 * @param devno Device number.
     332 *
     333 * @return EOK on success or a negative error code.
     334 *
    335335 */
    336336int ipc_irq_unregister(answerbox_t *box, inr_t inr, devno_t devno)
     
    340340                (sysarg_t) devno
    341341        };
    342 
     342       
    343343        if ((inr < 0) || (inr > last_inr))
    344344                return ELIMIT;
     
    436436                /* Remove from the hash table. */
    437437                hash_table_remove(&irq_uspace_hash_table, key, 2);
    438 
     438               
    439439                /*
    440440                 * Release both locks so that we can free the pseudo code.
     
    442442                irq_spinlock_unlock(&box->irq_lock, false);
    443443                irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
    444 
     444               
    445445                code_free(irq->notif_cfg.code);
    446446                free(irq);
     
    582582{
    583583        ASSERT(irq);
    584 
     584       
    585585        ASSERT(interrupts_disabled());
    586586        ASSERT(irq_spinlock_locked(&irq->lock));
Note: See TracChangeset for help on using the changeset viewer.