Changeset 2770b66 in mainline
- Timestamp:
- 2017-10-15T15:05:06Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 816f5f4
- Parents:
- 20eaa82
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
r20eaa82 r2770b66 79 79 80 80 /* Assign an address to the device */ 81 if ((err = xhci_rh_address_device(&hc->rh, dev ))) {81 if ((err = xhci_rh_address_device(&hc->rh, dev, bus))) { 82 82 usb_log_error("Failed to setup address of the new device: %s", str_error(err)); 83 83 return err; -
uspace/drv/bus/usb/xhci/endpoint.h
r20eaa82 r2770b66 66 66 endpoint_t base; /**< Inheritance. Keep this first. */ 67 67 68 /** Parent device. */ 68 69 xhci_device_t *device; 69 70 } xhci_endpoint_t; 70 71 71 72 typedef struct xhci_device { 73 /** Unique USB address assigned to the device. */ 72 74 usb_address_t address; 73 75 76 /** Slot ID assigned to the device by xHC. */ 74 77 uint32_t slot_id; 75 78 79 /** Associated device in libusbhost. */ 80 device_t *device; 81 82 /** All endpoints of the device. Inactive ones are NULL */ 76 83 xhci_endpoint_t *endpoints[XHCI_DEVICE_MAX_ENDPOINTS]; 84 85 /** Number of non-NULL endpoints. Reference count of sorts. */ 77 86 uint8_t active_endpoint_count; 78 87 } xhci_device_t; -
uspace/drv/bus/usb/xhci/hc.c
r20eaa82 r2770b66 213 213 goto err_scratch; 214 214 215 if ((err = xhci_init_transfers(hc))) 216 goto err_cmd; 217 215 218 if ((err = xhci_rh_init(&hc->rh, hc))) 216 goto err_ cmd;219 goto err_transfers; 217 220 218 221 if ((err = xhci_bus_init(&hc->bus))) … … 224 227 err_rh: 225 228 xhci_rh_fini(&hc->rh); 229 err_transfers: 230 xhci_fini_transfers(hc); 226 231 err_cmd: 227 232 xhci_fini_commands(hc); … … 472 477 case USB_TRANSFER_ISOCHRONOUS: 473 478 /* TODO: Implement me. */ 474 break; 479 usb_log_error("Isochronous transfers are not yet implemented!"); 480 return ENOTSUP; 475 481 case USB_TRANSFER_BULK: 476 482 return xhci_schedule_bulk_transfer(hc, batch); 477 483 case USB_TRANSFER_INTERRUPT: 478 484 /* TODO: Implement me. */ 479 break; 485 usb_log_error("Interrupt transfers are not yet implemented!"); 486 return ENOTSUP; 480 487 } 481 488 … … 617 624 xhci_event_ring_fini(&hc->event_ring); 618 625 hc_dcbaa_fini(hc); 626 xhci_fini_transfers(hc); 619 627 xhci_fini_commands(hc); 620 628 xhci_rh_fini(&hc->rh); -
uspace/drv/bus/usb/xhci/rh.c
r20eaa82 r2770b66 36 36 #include <errno.h> 37 37 #include <str_error.h> 38 #include <usb/request.h> 38 39 #include <usb/debug.h> 39 40 #include <usb/host/utils/malloc32.h> 40 41 #include <usb/host/bus.h> 41 42 #include <usb/host/ddf_helpers.h> 43 #include <usb/host/hcd.h> 42 44 43 45 #include "debug.h" … … 74 76 // TODO: This currently assumes the device is attached to rh directly. 75 77 // Also, we should consider moving a lot of functionailty to xhci bus 76 int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev )78 int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev, xhci_bus_t *bus) 77 79 { 78 80 int err; … … 160 162 usb_log_debug2("Obtained USB address: %d.\n", dev->address); 161 163 162 // TODO: Ask libusbhost to create a control endpoint for EP0. 163 164 // TODO: Save all data structures in the corresponding xhci_device_t. 165 166 return EOK; 167 164 // Ask libusbhost to create a control endpoint for EP0. 165 bus_t *bus_base = &bus->base; 166 usb_target_t ep0_target = { .address = dev->address, .endpoint = 0 }; 167 usb_direction_t ep0_direction = USB_DIRECTION_BOTH; 168 169 // TODO: Should this call be unified with other calls to `bus_add_ep()`? 170 err = bus_add_ep(bus_base, dev, ep0_target.endpoint, ep0_direction, 171 USB_TRANSFER_CONTROL, CTRL_PIPE_MIN_PACKET_SIZE, CTRL_PIPE_MIN_PACKET_SIZE, 1); 172 173 if (err != EOK) 174 goto err_add_ep; 175 176 // Save all data structures in the corresponding xhci_device_t. 177 endpoint_t *ep0_base = bus_find_endpoint(bus_base, ep0_target, ep0_direction); 178 xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base); 179 xhci_device_t *xhci_dev = ep0->device; 180 181 xhci_dev->device = dev; 182 xhci_dev->slot_id = slot_id; 183 184 // TODO: Save anything else? 185 186 return EOK; 187 188 err_add_ep: 168 189 err_dctx: 169 190 if (dctx) { -
uspace/drv/bus/usb/xhci/rh.h
r20eaa82 r2770b66 54 54 55 55 typedef struct hcd_roothub hcd_roothub_t; 56 typedef struct xhci_bus xhci_bus_t; 56 57 57 58 /* XHCI root hub instance */ … … 84 85 void xhci_rh_handle_port_change(xhci_rh_t *); 85 86 86 int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev );87 int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev, xhci_bus_t *bus); 87 88 88 89 #endif -
uspace/drv/bus/usb/xhci/transfers.c
r20eaa82 r2770b66 145 145 transfer->batch = batch; 146 146 link_initialize(&transfer->link); 147 transfer->hc_buffer = malloc32(batch->buffer_size);147 transfer->hc_buffer = batch->buffer_size > 0 ? malloc32(batch->buffer_size) : NULL; 148 148 149 149 return transfer; … … 152 152 void xhci_transfer_fini(xhci_transfer_t* transfer) { 153 153 if (transfer) { 154 free32(transfer->hc_buffer); 154 if (transfer->batch->buffer_size > 0) 155 free32(transfer->hc_buffer); 156 157 usb_transfer_batch_destroy(transfer->batch); 158 155 159 free(transfer); 156 160 } … … 179 183 /* For the TRB formats, see xHCI specification 6.4.1.2 */ 180 184 xhci_transfer_t *transfer = xhci_transfer_alloc(batch); 181 memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size); 185 186 if (!transfer->direction) { 187 // Sending stuff from host to device, we need to copy the actual data. 188 memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size); 189 } 182 190 183 191 xhci_trb_t trb_setup; … … 318 326 batch->transfered_size = batch->buffer_size - TRB_TRANSFER_LENGTH(*trb); 319 327 if (transfer->direction) { 328 memcpy(batch->buffer, transfer->hc_buffer, batch->buffer_size); 329 320 330 /* Device-to-host, IN */ 321 331 if (batch->callback_in)
Note:
See TracChangeset
for help on using the changeset viewer.