Changeset 224174f in mainline for uspace/drv/bus/usb/uhci/hc.c


Ignore:
Timestamp:
2013-07-11T13:16:57Z (11 years ago)
Author:
Manuele Conti <conti.ma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2b3e8840, b2c96093
Parents:
990ab7d (diff), 3a67d63 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes

File:
1 edited

Legend:

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

    r990ab7d r224174f  
    9090static int hc_debug_checker(void *arg);
    9191
    92 
    93 /** Get number of PIO ranges used in IRQ code.
    94  * @return Number of ranges.
    95  */
    96 size_t hc_irq_pio_range_count(void)
    97 {
    98         return sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t);
    99 }
    100 
    101 /** Get number of commands used in IRQ code.
    102  * @return Number of commands.
    103  */
    104 size_t hc_irq_cmd_count(void)
    105 {
    106         return sizeof(uhci_irq_commands) / sizeof(irq_cmd_t);
    107 }
     92enum {
     93        /** Number of PIO ranges used in IRQ code */
     94        hc_irq_pio_range_count =
     95            sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t),
     96
     97        /* Number of commands used in IRQ code */
     98        hc_irq_cmd_count =
     99            sizeof(uhci_irq_commands) / sizeof(irq_cmd_t)
     100};
    108101
    109102/** Generate IRQ code.
     
    133126        cmds[0].addr = &registers->usbsts;
    134127        cmds[3].addr = &registers->usbsts;
     128
     129        return EOK;
     130}
     131
     132/** Register interrupt handler.
     133 *
     134 * @param[in] device Host controller DDF device
     135 * @param[in] reg_base Register range base
     136 * @param[in] reg_size Register range size
     137 * @param[in] irq Interrupt number
     138 * @paran[in] handler Interrupt handler
     139 *
     140 * @return EOK on success or negative error code
     141 */
     142int hc_register_irq_handler(ddf_dev_t *device, uintptr_t reg_base, size_t reg_size,
     143    int irq, interrupt_handler_t handler)
     144{
     145        int rc;
     146        irq_pio_range_t irq_ranges[hc_irq_pio_range_count];
     147        irq_cmd_t irq_cmds[hc_irq_cmd_count];
     148        rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
     149            sizeof(irq_cmds), reg_base, reg_size);
     150        if (rc != EOK) {
     151                usb_log_error("Failed to generate IRQ commands: %s.\n",
     152                    str_error(rc));
     153                return rc;
     154        }
     155
     156        irq_code_t irq_code = {
     157                .rangecount = hc_irq_pio_range_count,
     158                .ranges = irq_ranges,
     159                .cmdcount = hc_irq_cmd_count,
     160                .cmds = irq_cmds
     161        };
     162
     163        /* Register handler to avoid interrupt lockup */
     164        rc = register_interrupt_handler(device, irq, handler, &irq_code);
     165        if (rc != EOK) {
     166                usb_log_error("Failed to register interrupt handler: %s.\n",
     167                    str_error(rc));
     168                return rc;
     169        }
    135170
    136171        return EOK;
     
    209244{
    210245        assert(reg_size >= sizeof(uhci_regs_t));
    211         int ret;
    212 
    213 #define CHECK_RET_RETURN(ret, message...) \
    214         if (ret != EOK) { \
    215                 usb_log_error(message); \
    216                 return ret; \
    217         } else (void) 0
     246        int rc;
    218247
    219248        instance->hw_interrupts = interrupts;
     
    222251        /* allow access to hc control registers */
    223252        uhci_regs_t *io;
    224         ret = pio_enable(regs, reg_size, (void **)&io);
    225         CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p: %s.\n",
    226             io, str_error(ret));
     253        rc = pio_enable(regs, reg_size, (void **)&io);
     254        if (rc != EOK) {
     255                usb_log_error("Failed to gain access to registers at %p: %s.\n",
     256                    io, str_error(rc));
     257                return rc;
     258        }
     259
    227260        instance->registers = io;
    228261        usb_log_debug(
    229262            "Device registers at %p (%zuB) accessible.\n", io, reg_size);
    230263
    231         ret = hc_init_mem_structures(instance);
    232         CHECK_RET_RETURN(ret,
    233             "Failed to initialize UHCI memory structures: %s.\n",
    234             str_error(ret));
    235 
    236 #undef CHECK_RET_RETURN
     264        rc = hc_init_mem_structures(instance);
     265        if (rc != EOK) {
     266                usb_log_error("Failed to initialize UHCI memory structures: %s.\n",
     267                    str_error(rc));
     268                return rc;
     269        }
    237270
    238271        hcd_init(&instance->generic, USB_SPEED_FULL,
     
    397430
    398431        return EOK;
    399 #undef CHECK_RET_CLEAR_RETURN
    400432}
    401433
Note: See TracChangeset for help on using the changeset viewer.