Changes in uspace/drv/bus/usb/uhci/hc.c [1ae74c6:7de1988c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhci/hc.c
r1ae74c6 r7de1988c 90 90 static int hc_debug_checker(void *arg); 91 91 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 } 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 }; 108 101 109 102 /** Generate IRQ code. … … 112 105 * @param[out] cmds Commands buffer. 113 106 * @param[in] cmds_size Size of the commands buffer (bytes). 114 * @param[in] regs Physical address of device's registers. 115 * @param[in] reg_size Size of the register area (bytes). 107 * @param[in] regs Device's register range. 116 108 * 117 109 * @return Error code. … … 119 111 int 120 112 hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[], 121 size_t cmds_size, uintptr_t regs, size_t reg_size)113 size_t cmds_size, addr_range_t *regs) 122 114 { 123 115 if ((ranges_size < sizeof(uhci_irq_pio_ranges)) || 124 116 (cmds_size < sizeof(uhci_irq_commands)) || 125 ( reg_size< sizeof(uhci_regs_t)))117 (RNGSZ(*regs) < sizeof(uhci_regs_t))) 126 118 return EOVERFLOW; 127 119 128 120 memcpy(ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges)); 129 ranges[0].base = regs;121 ranges[0].base = RNGABS(*regs); 130 122 131 123 memcpy(cmds, uhci_irq_commands, sizeof(uhci_irq_commands)); 132 uhci_regs_t *registers = (uhci_regs_t *) regs;124 uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(*regs); 133 125 cmds[0].addr = ®isters->usbsts; 134 126 cmds[3].addr = ®isters->usbsts; 127 128 return EOK; 129 } 130 131 /** Register interrupt handler. 132 * 133 * @param[in] device Host controller DDF device 134 * @param[in] regs Register range 135 * @param[in] irq Interrupt number 136 * @paran[in] handler Interrupt handler 137 * 138 * @return EOK on success or negative error code 139 */ 140 int hc_register_irq_handler(ddf_dev_t *device, addr_range_t *regs, int irq, 141 interrupt_handler_t handler) 142 { 143 int rc; 144 irq_pio_range_t irq_ranges[hc_irq_pio_range_count]; 145 irq_cmd_t irq_cmds[hc_irq_cmd_count]; 146 rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds, 147 sizeof(irq_cmds), regs); 148 if (rc != EOK) { 149 usb_log_error("Failed to generate IRQ commands: %s.\n", 150 str_error(rc)); 151 return rc; 152 } 153 154 irq_code_t irq_code = { 155 .rangecount = hc_irq_pio_range_count, 156 .ranges = irq_ranges, 157 .cmdcount = hc_irq_cmd_count, 158 .cmds = irq_cmds 159 }; 160 161 /* Register handler to avoid interrupt lockup */ 162 rc = register_interrupt_handler(device, irq, handler, &irq_code); 163 if (rc != EOK) { 164 usb_log_error("Failed to register interrupt handler: %s.\n", 165 str_error(rc)); 166 return rc; 167 } 135 168 136 169 return EOK; … … 197 230 * 198 231 * @param[in] instance Memory place to initialize. 199 * @param[in] regs Address of I/O control registers. 200 * @param[in] reg_size Size of I/O control registers. 232 * @param[in] regs Range of device's I/O control registers. 201 233 * @param[in] interrupts True if hw interrupts should be used. 202 234 * @return Error code. … … 206 238 * interrupt fibrils. 207 239 */ 208 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts) 209 { 210 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 240 int hc_init(hc_t *instance, addr_range_t *regs, bool interrupts) 241 { 242 assert(regs->size >= sizeof(uhci_regs_t)); 243 int rc; 218 244 219 245 instance->hw_interrupts = interrupts; … … 222 248 /* allow access to hc control registers */ 223 249 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)); 250 rc = pio_enable_range(regs, (void **) &io); 251 if (rc != EOK) { 252 usb_log_error("Failed to gain access to registers at %p: %s.\n", 253 io, str_error(rc)); 254 return rc; 255 } 256 227 257 instance->registers = io; 228 258 usb_log_debug( 229 "Device registers at %p (%zuB) accessible.\n", io, reg _size);230 231 r et= hc_init_mem_structures(instance);232 CHECK_RET_RETURN(ret,233 234 str_error(ret));235 236 #undef CHECK_RET_RETURN 259 "Device registers at %p (%zuB) accessible.\n", io, regs->size); 260 261 rc = hc_init_mem_structures(instance); 262 if (rc != EOK) { 263 usb_log_error("Failed to initialize UHCI memory structures: %s.\n", 264 str_error(rc)); 265 return rc; 266 } 237 267 238 268 hcd_init(&instance->generic, USB_SPEED_FULL, … … 397 427 398 428 return EOK; 399 #undef CHECK_RET_CLEAR_RETURN400 429 } 401 430
Note:
See TracChangeset
for help on using the changeset viewer.