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