Changeset 6210a333 in mainline for uspace/drv/bus/usb/uhci/hc.c


Ignore:
Timestamp:
2013-09-21T05:09:46Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
19d21728
Parents:
30e8ab4
Message:

uhci, ohci: Cleanup irq code generation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/hc.c

    r30e8ab4 r6210a333  
    9090
    9191
    92 /** Get number of PIO ranges used in IRQ code.
    93  * @return Number of ranges.
    94  */
    95 size_t hc_irq_pio_range_count(void)
    96 {
    97         return sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t);
    98 }
    99 
    100 /** Get number of commands used in IRQ code.
    101  * @return Number of commands.
    102  */
    103 size_t hc_irq_cmd_count(void)
    104 {
    105         return sizeof(uhci_irq_commands) / sizeof(irq_cmd_t);
    106 }
    107 
    10892/** Generate IRQ code.
    109  * @param[out] ranges PIO ranges buffer.
    110  * @param[in] ranges_size Size of the ranges buffer (bytes).
    111  * @param[out] cmds Commands buffer.
    112  * @param[in] cmds_size Size of the commands buffer (bytes).
     93 * @param[out] code IRQ code structure.
    11394 * @param[in] regs Device's register range.
    11495 *
    11596 * @return Error code.
    11697 */
    117 int
    118 hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[],
    119     size_t cmds_size, addr_range_t *regs)
    120 {
    121         if ((ranges_size < sizeof(uhci_irq_pio_ranges)) ||
    122             (cmds_size < sizeof(uhci_irq_commands)) ||
    123             (RNGSZ(*regs) < sizeof(uhci_regs_t)))
     98int hc_gen_irq_code(irq_code_t *code, addr_range_t *regs)
     99{
     100        assert(code);
     101
     102        if (RNGSZ(*regs) < sizeof(uhci_regs_t))
    124103                return EOVERFLOW;
    125104
    126         memcpy(ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges));
    127         ranges[0].base = RNGABS(*regs);
    128 
    129         memcpy(cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
     105        code->ranges = malloc(sizeof(uhci_irq_pio_ranges));
     106        if (code->ranges == NULL)
     107                return ENOMEM;
     108
     109        code->cmds = malloc(sizeof(uhci_irq_commands));
     110        if (code->cmds == NULL) {
     111                free(code->ranges);
     112                return ENOMEM;
     113        }
     114
     115        code->rangecount = ARRAY_SIZE(uhci_irq_pio_ranges);
     116        code->cmdcount = ARRAY_SIZE(uhci_irq_commands);
     117
     118        memcpy(code->ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges));
     119        code->ranges[0].base = RNGABS(*regs);
     120
     121        memcpy(code->cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
    130122        uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(*regs);
    131         cmds[0].addr = (void*)&registers->usbsts;
    132         cmds[3].addr = (void*)&registers->usbsts;
     123        code->cmds[0].addr = (void*)&registers->usbsts;
     124        code->cmds[3].addr = (void*)&registers->usbsts;
    133125
    134126        return EOK;
     
    148140{
    149141        assert(device);
    150         irq_pio_range_t irq_ranges[hc_irq_pio_range_count()];
    151         irq_cmd_t irq_cmds[hc_irq_cmd_count()];
    152 
    153         int ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
    154             sizeof(irq_cmds), regs);
     142
     143        irq_code_t irq_code = { 0 };
     144
     145        int ret = hc_gen_irq_code(&irq_code, regs);
    155146        if (ret != EOK) {
    156147                usb_log_error("Failed to generate IRQ commands: %s.\n",
     
    158149                return ret;
    159150        }
    160 
    161         irq_code_t irq_code = {
    162                 .rangecount = hc_irq_pio_range_count(),
    163                 .ranges = irq_ranges,
    164                 .cmdcount = hc_irq_cmd_count(),
    165                 .cmds = irq_cmds
    166         };
     151        //TODO we leak memory here
    167152
    168153        /* Register handler to avoid interrupt lockup */
Note: See TracChangeset for help on using the changeset viewer.