Ignore:
File:
1 edited

Legend:

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

    rd930980 rd57122c  
    3535#include <str_error.h>
    3636#include <adt/list.h>
    37 #include <ddi.h>
     37#include <libarch/ddi.h>
    3838
    3939#include <usb/debug.h>
     
    5050static const irq_pio_range_t uhci_irq_pio_ranges[] = {
    5151        {
    52                 .base = 0,
     52                .base = 0,      /* filled later */
    5353                .size = sizeof(uhci_regs_t)
    5454        }
     
    5656
    5757static const irq_cmd_t uhci_irq_commands[] = {
    58         {
    59                 .cmd = CMD_PIO_READ_16,
    60                 .dstarg = 1,
    61                 .addr = NULL
    62         },
    63         {
    64                 .cmd = CMD_AND,
    65                 .srcarg = 1,
    66                 .dstarg = 2,
    67                 .value = UHCI_STATUS_USED_INTERRUPTS | UHCI_STATUS_NM_INTERRUPTS
    68         },
    69         {
    70                 .cmd = CMD_PREDICATE,
    71                 .srcarg = 2,
    72                 .value = 2
    73         },
    74         {
    75                 .cmd = CMD_PIO_WRITE_A_16,
    76                 .srcarg = 1,
    77                 .addr = NULL
    78         },
    79         {
    80                 .cmd = CMD_ACCEPT
    81         }
     58        { .cmd = CMD_PIO_READ_16, .dstarg = 1, .addr = NULL/*filled later*/},
     59        { .cmd = CMD_BTEST, .srcarg = 1, .dstarg = 2,
     60          .value = UHCI_STATUS_USED_INTERRUPTS | UHCI_STATUS_NM_INTERRUPTS },
     61        { .cmd = CMD_PREDICATE, .srcarg = 2, .value = 2 },
     62        { .cmd = CMD_PIO_WRITE_A_16, .srcarg = 1, .addr = NULL/*filled later*/},
     63        { .cmd = CMD_ACCEPT },
    8264};
    8365
     
    9072static int hc_debug_checker(void *arg);
    9173
    92 enum {
    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 };
    101 
     74/*----------------------------------------------------------------------------*/
     75/** Get number of PIO ranges used in IRQ code.
     76 * @return Number of ranges.
     77 */
     78size_t hc_irq_pio_range_count(void)
     79{
     80        return sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t);
     81}
     82/*----------------------------------------------------------------------------*/
     83/** Get number of commands used in IRQ code.
     84 * @return Number of commands.
     85 */
     86size_t hc_irq_cmd_count(void)
     87{
     88        return sizeof(uhci_irq_commands) / sizeof(irq_cmd_t);
     89}
     90/*----------------------------------------------------------------------------*/
    10291/** Generate IRQ code.
    10392 * @param[out] ranges PIO ranges buffer.
     
    129118        return EOK;
    130119}
    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  */
    142 int 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         }
    170 
    171         return EOK;
    172 }
    173 
     120/*----------------------------------------------------------------------------*/
    174121/** Take action based on the interrupt cause.
    175122 *
     
    228175        }
    229176}
    230 
     177/*----------------------------------------------------------------------------*/
    231178/** Initialize UHCI hc driver structure
    232179 *
     
    244191{
    245192        assert(reg_size >= sizeof(uhci_regs_t));
    246         int rc;
     193        int ret;
     194
     195#define CHECK_RET_RETURN(ret, message...) \
     196        if (ret != EOK) { \
     197                usb_log_error(message); \
     198                return ret; \
     199        } else (void) 0
    247200
    248201        instance->hw_interrupts = interrupts;
     
    251204        /* allow access to hc control registers */
    252205        uhci_regs_t *io;
    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 
     206        ret = pio_enable(regs, reg_size, (void **)&io);
     207        CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p: %s.\n",
     208            io, str_error(ret));
    260209        instance->registers = io;
    261210        usb_log_debug(
    262211            "Device registers at %p (%zuB) accessible.\n", io, reg_size);
    263212
    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         }
     213        ret = hc_init_mem_structures(instance);
     214        CHECK_RET_RETURN(ret,
     215            "Failed to initialize UHCI memory structures: %s.\n",
     216            str_error(ret));
     217
     218#undef CHECK_RET_RETURN
    270219
    271220        hcd_init(&instance->generic, USB_SPEED_FULL,
     
    286235        return EOK;
    287236}
    288 
     237/*----------------------------------------------------------------------------*/
    289238/** Initialize UHCI hc hw resources.
    290239 *
     
    328277            UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE);
    329278}
    330 
     279/*----------------------------------------------------------------------------*/
    331280/** Initialize UHCI hc memory structures.
    332281 *
     
    370319        return EOK;
    371320}
    372 
     321/*----------------------------------------------------------------------------*/
    373322/** Initialize UHCI hc transfer lists.
    374323 *
     
    430379
    431380        return EOK;
    432 }
    433 
     381#undef CHECK_RET_CLEAR_RETURN
     382}
     383/*----------------------------------------------------------------------------*/
    434384/** Schedule batch for execution.
    435385 *
     
    459409        return EOK;
    460410}
    461 
     411/*----------------------------------------------------------------------------*/
    462412/** Polling function, emulates interrupts.
    463413 *
     
    482432        return EOK;
    483433}
    484 
     434/*----------------------------------------------------------------------------*/
    485435/** Debug function, checks consistency of memory structures.
    486436 *
Note: See TracChangeset for help on using the changeset viewer.