Changes in uspace/drv/uhci-hcd/uhci.c [a7e2f0d:57c0a7e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/uhci.c
ra7e2f0d r57c0a7e 61 61 }; 62 62 63 /** Gets USB address of the calling device. 64 * 65 * @param[in] fun UHCI hc function. 66 * @param[in] handle Handle of the device seeking address. 67 * @param[out] address Place to store found address. 68 * @return Error code. 69 */ 70 static int usb_iface_get_address( 71 ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address) 63 static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle, 64 usb_address_t *address) 72 65 { 73 66 assert(fun); … … 106 99 107 100 static bool allowed_usb_packet( 108 bool low_speed, usb_transfer_type_t transfer, size_t size); 109 /*----------------------------------------------------------------------------*/ 110 /** Initializes UHCI hcd driver structure 111 * 112 * @param[in] instance Memory place to initialize. 113 * @param[in] dev DDF device. 114 * @param[in] regs Address of I/O control registers. 115 * @param[in] size Size of I/O control registers. 116 * @return Error code. 117 * @note Should be called only once on any structure. 118 */ 101 bool low_speed, usb_transfer_type_t, size_t size); 102 103 119 104 int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size) 120 105 { … … 171 156 } 172 157 /*----------------------------------------------------------------------------*/ 173 /** Initializes UHCI hcd hw resources.174 *175 * @param[in] instance UHCI structure to use.176 */177 158 void uhci_init_hw(uhci_t *instance) 178 159 { 179 160 assert(instance); 180 regs_t *registers = instance->registers; 181 182 /* Reset everything, who knows what touched it before us */ 183 pio_write_16(®isters->usbcmd, UHCI_CMD_GLOBAL_RESET); 161 162 /* reset everything, who knows what touched it before us */ 163 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET); 184 164 async_usleep(10000); /* 10ms according to USB spec */ 185 pio_write_16(& registers->usbcmd, 0);186 187 /* Reset hc, all states and counters */188 pio_write_16(& registers->usbcmd, UHCI_CMD_HCRESET);165 pio_write_16(&instance->registers->usbcmd, 0); 166 167 /* reset hc, all states and counters */ 168 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET); 189 169 do { async_usleep(10); } 190 while ((pio_read_16(& registers->usbcmd) & UHCI_CMD_HCRESET) != 0);191 192 /* Set framelist pointer */170 while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0); 171 172 /* set framelist pointer */ 193 173 const uint32_t pa = addr_to_phys(instance->frame_list); 194 pio_write_32(& registers->flbaseadd, pa);195 196 /* Enable all interrupts, but resume interrupt */174 pio_write_32(&instance->registers->flbaseadd, pa); 175 176 /* enable all interrupts, but resume interrupt */ 197 177 // pio_write_16(&instance->registers->usbintr, 198 178 // UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET); 199 179 200 uint16_t status = pio_read_16(®isters->usbcmd); 201 if (status != 0) 202 usb_log_warning("Previous command value: %x.\n", status); 203 180 uint16_t status = pio_read_16(&instance->registers->usbcmd); 181 usb_log_warning("Previous command value: %x.\n", status); 204 182 /* Start the hc with large(64B) packet FSBR */ 205 pio_write_16(& registers->usbcmd,183 pio_write_16(&instance->registers->usbcmd, 206 184 UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE); 207 185 } 208 186 /*----------------------------------------------------------------------------*/ 209 /** Initializes UHCI hcd memory structures.210 *211 * @param[in] instance UHCI structure to use.212 * @return Error code213 * @note Should be called only once on any structure.214 */215 187 int uhci_init_mem_structures(uhci_t *instance) 216 188 { … … 224 196 } else (void) 0 225 197 226 /* Init interrupt code */198 /* init interrupt code */ 227 199 instance->interrupt_code.cmds = malloc(sizeof(uhci_cmds)); 228 200 int ret = (instance->interrupt_code.cmds == NULL) ? ENOMEM : EOK; 229 CHECK_RET_DEST_CMDS_RETURN(ret, 230 "Failed to allocate interrupt cmds space.\n"); 201 CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to allocate interrupt cmds space.\n"); 231 202 232 203 { 233 204 irq_cmd_t *interrupt_commands = instance->interrupt_code.cmds; 234 205 memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds)); 235 interrupt_commands[0].addr = 236 (void*)&instance->registers->usbsts; 237 interrupt_commands[1].addr = 238 (void*)&instance->registers->usbsts; 206 interrupt_commands[0].addr = (void*)&instance->registers->usbsts; 207 interrupt_commands[1].addr = (void*)&instance->registers->usbsts; 239 208 instance->interrupt_code.cmdcount = 240 209 sizeof(uhci_cmds) / sizeof(irq_cmd_t); 241 210 } 242 211 243 /* Init transfer lists */212 /* init transfer lists */ 244 213 ret = uhci_init_transfer_lists(instance); 245 CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n");214 CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to initialize transfer lists.\n"); 246 215 usb_log_debug("Initialized transfer lists.\n"); 247 216 248 /* Init USB frame list page*/217 /* frame list initialization */ 249 218 instance->frame_list = get_page(); 250 219 ret = instance ? EOK : ENOMEM; … … 252 221 usb_log_debug("Initialized frame list.\n"); 253 222 254 /* Setall frames to point to the first queue head */223 /* initialize all frames to point to the first queue head */ 255 224 const uint32_t queue = 256 225 instance->transfers_interrupt.queue_head_pa … … 262 231 } 263 232 264 /* Init device keeper*/233 /* init address keeper(libusb) */ 265 234 device_keeper_init(&instance->device_manager); 266 235 usb_log_debug("Initialized device manager.\n"); … … 270 239 } 271 240 /*----------------------------------------------------------------------------*/ 272 /** Initializes UHCI hcd transfer lists.273 *274 * @param[in] instance UHCI structure to use.275 * @return Error code276 * @note Should be called only once on any structure.277 */278 241 int uhci_init_transfer_lists(uhci_t *instance) 279 242 { … … 294 257 CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list."); 295 258 296 ret = transfer_list_init( 297 &instance->transfers_control_full, "CONTROL_FULL"); 259 ret = transfer_list_init(&instance->transfers_control_full, "CONTROL_FULL"); 298 260 CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list."); 299 261 300 ret = transfer_list_init( 301 &instance->transfers_control_slow, "CONTROL_SLOW"); 262 ret = transfer_list_init(&instance->transfers_control_slow, "CONTROL_SLOW"); 302 263 CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list."); 303 264 … … 318 279 #endif 319 280 320 /* Assign pointers to be used during scheduling */ 321 instance->transfers[USB_SPEED_FULL][USB_TRANSFER_INTERRUPT] = 281 instance->transfers[0][USB_TRANSFER_INTERRUPT] = 322 282 &instance->transfers_interrupt; 323 instance->transfers[ USB_SPEED_LOW][USB_TRANSFER_INTERRUPT] =283 instance->transfers[1][USB_TRANSFER_INTERRUPT] = 324 284 &instance->transfers_interrupt; 325 instance->transfers[ USB_SPEED_FULL][USB_TRANSFER_CONTROL] =285 instance->transfers[0][USB_TRANSFER_CONTROL] = 326 286 &instance->transfers_control_full; 327 instance->transfers[ USB_SPEED_LOW][USB_TRANSFER_CONTROL] =287 instance->transfers[1][USB_TRANSFER_CONTROL] = 328 288 &instance->transfers_control_slow; 329 instance->transfers[ USB_SPEED_FULL][USB_TRANSFER_BULK] =289 instance->transfers[0][USB_TRANSFER_BULK] = 330 290 &instance->transfers_bulk_full; 331 291 … … 334 294 } 335 295 /*----------------------------------------------------------------------------*/ 336 /** Schedules batch for execution.337 *338 * @param[in] instance UHCI structure to use.339 * @param[in] batch Transfer batch to schedule.340 * @return Error code341 */342 296 int uhci_schedule(uhci_t *instance, batch_t *batch) 343 297 { … … 347 301 if (!allowed_usb_packet( 348 302 low_speed, batch->transfer_type, batch->max_packet_size)) { 349 usb_log_warning( 350 "Invalid USB packet specified %s SPEED %d %zu.\n", 303 usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n", 351 304 low_speed ? "LOW" : "FULL" , batch->transfer_type, 352 305 batch->max_packet_size); … … 363 316 } 364 317 /*----------------------------------------------------------------------------*/ 365 /** Takes action based on the interrupt cause.366 *367 * @param[in] instance UHCI structure to use.368 * @param[in] status Value of the stsatus regiser at the time of interrupt.369 */370 318 void uhci_interrupt(uhci_t *instance, uint16_t status) 371 319 { 372 320 assert(instance); 373 /* TODO: Check interrupt cause here */374 321 transfer_list_remove_finished(&instance->transfers_interrupt); 375 322 transfer_list_remove_finished(&instance->transfers_control_slow); … … 378 325 } 379 326 /*----------------------------------------------------------------------------*/ 380 /** Polling function, emulates interrupts.381 *382 * @param[in] arg UHCI structure to use.383 * @return EOK384 */385 327 int uhci_interrupt_emulator(void* arg) 386 328 { … … 401 343 } 402 344 /*---------------------------------------------------------------------------*/ 403 /** Debug function, checks consistency of memory structures.404 *405 * @param[in] arg UHCI structure to use.406 * @return EOK407 */408 345 int uhci_debug_checker(void *arg) 409 346 { … … 464 401 async_usleep(UHCI_DEBUGER_TIMEOUT); 465 402 } 466 return EOK;403 return 0; 467 404 #undef QH 468 405 } 469 406 /*----------------------------------------------------------------------------*/ 470 /** Checks transfer packets, for USB validity471 *472 * @param[in] low_speed Transfer speed.473 * @param[in] transfer Transer type474 * @param[in] size Maximum size of used packets475 * @return EOK476 */477 407 bool allowed_usb_packet( 478 408 bool low_speed, usb_transfer_type_t transfer, size_t size)
Note:
See TracChangeset
for help on using the changeset viewer.