Changeset 0206d35 in mainline for uspace/drv/bus/usb/xhci/bus.c
- Timestamp:
- 2017-10-25T00:03:57Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c3d926f
- Parents:
- 56db65d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
r56db65d r0206d35 49 49 #include "transfers.h" 50 50 51 /** TODO: Still some copy-pasta left... 52 */ 51 52 /* FIXME Are these really static? Older HCs fetch it from descriptor. */ 53 /* FIXME Add USB3 options, if applicable. */ 54 static const usb_endpoint_desc_t ep0_desc = { 55 .endpoint_no = 0, 56 .direction = USB_DIRECTION_BOTH, 57 .transfer_type = USB_TRANSFER_CONTROL, 58 .max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE, 59 .packets = 1, 60 }; 61 62 static int prepare_endpoint(xhci_endpoint_t *ep, const usb_endpoint_desc_t *desc) 63 { 64 /* Extract information from endpoint_desc */ 65 ep->base.target = (usb_target_t) {{ 66 .address = ep->base.device->address, 67 .endpoint = desc->endpoint_no, 68 }}; 69 ep->base.direction = desc->direction; 70 ep->base.transfer_type = desc->transfer_type; 71 ep->base.max_packet_size = desc->max_packet_size; 72 ep->base.packets = desc->packets; 73 ep->max_streams = desc->usb3.max_streams; 74 ep->max_burst = desc->usb3.max_burst; 75 // TODO add this property to usb_endpoint_desc_t and fetch it from ss companion desc 76 ep->mult = 0; 77 78 return xhci_endpoint_alloc_transfer_ds(ep); 79 } 80 81 static endpoint_t *create_endpoint(bus_t *base); 82 83 static int address_device(xhci_hc_t *hc, xhci_device_t *dev) 84 { 85 int err; 86 87 /* Enable new slot. */ 88 if ((err = hc_enable_slot(hc, &dev->slot_id)) != EOK) 89 return err; 90 usb_log_debug2("Obtained slot ID: %u.\n", dev->slot_id); 91 92 /* Create and configure control endpoint. */ 93 endpoint_t *ep0_base = create_endpoint(&hc->bus.base); 94 if (!ep0_base) 95 goto err_slot; 96 97 /* Temporary reference */ 98 endpoint_add_ref(ep0_base); 99 100 ep0_base->device = &dev->base; 101 xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base); 102 103 if ((err = prepare_endpoint(ep0, &ep0_desc))) 104 goto err_ep; 105 106 /* Address device */ 107 if ((err = hc_address_device(hc, dev, ep0))) 108 goto err_prepared_ep; 109 110 /* Register EP0, passing Temporary reference */ 111 ep0->base.target.address = dev->base.address; 112 dev->endpoints[0] = ep0; 113 114 return EOK; 115 116 err_prepared_ep: 117 xhci_endpoint_free_transfer_ds(ep0); 118 err_ep: 119 endpoint_del_ref(ep0_base); 120 err_slot: 121 hc_disable_slot(hc, dev->slot_id); 122 return err; 123 } 124 53 125 int xhci_bus_enumerate_device(xhci_bus_t *bus, xhci_hc_t *hc, device_t *dev) 54 126 { 55 127 int err; 56 128 xhci_device_t *xhci_dev = xhci_device_get(dev); 57 58 /* TODO: get speed from the default address reservation */59 dev->speed = USB_SPEED_FULL;60 129 61 130 /* Manage TT */ … … 72 141 73 142 /* Assign an address to the device */ 74 if ((err = xhci_rh_address_device(&hc->rh, dev, bus))) {143 if ((err = address_device(hc, xhci_dev))) { 75 144 usb_log_error("Failed to setup address of the new device: %s", str_error(err)); 76 145 return err; 77 146 } 147 148 // TODO: Fetch descriptor of EP0 and reconfigure it accordingly 149 assert(xhci_dev->endpoints[0]); 78 150 79 151 assert(bus->devices_by_slot[xhci_dev->slot_id] == NULL); … … 93 165 } 94 166 167 static int unregister_endpoint(bus_t *, endpoint_t *); 168 95 169 int xhci_bus_remove_device(xhci_bus_t *bus, xhci_hc_t *hc, device_t *dev) 96 170 { … … 98 172 99 173 /* Unregister remaining endpoints. */ 100 for ( size_ti = 0; i < ARRAY_SIZE(xhci_dev->endpoints); ++i) {174 for (unsigned i = 0; i < ARRAY_SIZE(xhci_dev->endpoints); ++i) { 101 175 if (!xhci_dev->endpoints[i]) 102 176 continue; 103 177 104 // FIXME: ignoring return code 105 bus_unregister_endpoint(&bus->base, &xhci_dev->endpoints[i]->base); 178 const int err = unregister_endpoint(&bus->base, &xhci_dev->endpoints[i]->base); 179 if (err) 180 usb_log_warning("Failed to unregister EP (%u:%u): %s", dev->address, i, str_error(err)); 106 181 } 107 182 … … 167 242 static int register_endpoint(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc) 168 243 { 244 int err; 169 245 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 170 246 assert(bus); 171 247 172 248 assert(ep->device); 173 174 /* Extract USB2-related information from endpoint_desc */175 ep->target = (usb_target_t) {{176 .address = ep->device->address,177 .endpoint = desc->endpoint_no,178 }};179 ep->direction = desc->direction;180 ep->transfer_type = desc->transfer_type;181 ep->max_packet_size = desc->max_packet_size;182 ep->packets = desc->packets;183 249 184 250 xhci_device_t *xhci_dev = xhci_device_get(ep->device); 185 251 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep); 186 252 187 xhci_ep->max_streams = desc->usb3.max_streams; 188 xhci_ep->max_burst = desc->usb3.max_burst; 189 // TODO add this property to usb_endpoint_desc_t and fetch it from ss companion desc 190 xhci_ep->mult = 0; 253 if ((err = prepare_endpoint(xhci_ep, desc))) 254 return err; 191 255 192 256 usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", ep->target.address, ep->target.endpoint);
Note:
See TracChangeset
for help on using the changeset viewer.