Changes in uspace/drv/bus/usb/uhci/hc.c [d930980:d57122c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhci/hc.c
rd930980 rd57122c 35 35 #include <str_error.h> 36 36 #include <adt/list.h> 37 #include < ddi.h>37 #include <libarch/ddi.h> 38 38 39 39 #include <usb/debug.h> … … 50 50 static const irq_pio_range_t uhci_irq_pio_ranges[] = { 51 51 { 52 .base = 0, 52 .base = 0, /* filled later */ 53 53 .size = sizeof(uhci_regs_t) 54 54 } … … 56 56 57 57 static 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 }, 82 64 }; 83 65 … … 90 72 static int hc_debug_checker(void *arg); 91 73 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 */ 78 size_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 */ 86 size_t hc_irq_cmd_count(void) 87 { 88 return sizeof(uhci_irq_commands) / sizeof(irq_cmd_t); 89 } 90 /*----------------------------------------------------------------------------*/ 102 91 /** Generate IRQ code. 103 92 * @param[out] ranges PIO ranges buffer. … … 129 118 return EOK; 130 119 } 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 /*----------------------------------------------------------------------------*/ 174 121 /** Take action based on the interrupt cause. 175 122 * … … 228 175 } 229 176 } 230 177 /*----------------------------------------------------------------------------*/ 231 178 /** Initialize UHCI hc driver structure 232 179 * … … 244 191 { 245 192 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 247 200 248 201 instance->hw_interrupts = interrupts; … … 251 204 /* allow access to hc control registers */ 252 205 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)); 260 209 instance->registers = io; 261 210 usb_log_debug( 262 211 "Device registers at %p (%zuB) accessible.\n", io, reg_size); 263 212 264 r c= 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 270 219 271 220 hcd_init(&instance->generic, USB_SPEED_FULL, … … 286 235 return EOK; 287 236 } 288 237 /*----------------------------------------------------------------------------*/ 289 238 /** Initialize UHCI hc hw resources. 290 239 * … … 328 277 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE); 329 278 } 330 279 /*----------------------------------------------------------------------------*/ 331 280 /** Initialize UHCI hc memory structures. 332 281 * … … 370 319 return EOK; 371 320 } 372 321 /*----------------------------------------------------------------------------*/ 373 322 /** Initialize UHCI hc transfer lists. 374 323 * … … 430 379 431 380 return EOK; 432 } 433 381 #undef CHECK_RET_CLEAR_RETURN 382 } 383 /*----------------------------------------------------------------------------*/ 434 384 /** Schedule batch for execution. 435 385 * … … 459 409 return EOK; 460 410 } 461 411 /*----------------------------------------------------------------------------*/ 462 412 /** Polling function, emulates interrupts. 463 413 * … … 482 432 return EOK; 483 433 } 484 434 /*----------------------------------------------------------------------------*/ 485 435 /** Debug function, checks consistency of memory structures. 486 436 *
Note:
See TracChangeset
for help on using the changeset viewer.