Changeset 56db65d in mainline
- Timestamp:
- 2017-10-24T11:06:32Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0206d35
- Parents:
- 894f58c
- Location:
- uspace
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_bus.c
r894f58c r56db65d 114 114 115 115 116 static int ehci_register_ep(bus_t *bus_base, endpoint_t *ep )116 static int ehci_register_ep(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc) 117 117 { 118 118 ehci_bus_t *bus = (ehci_bus_t *) bus_base; 119 119 ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep); 120 120 121 const int err = bus->parent_ops.register_endpoint(bus_base, ep); 121 // TODO utilize desc->usb2 122 123 const int err = bus->parent_ops.register_endpoint(bus_base, ep, desc); 122 124 if (err) 123 125 return err; -
uspace/drv/bus/usb/ohci/ohci_bus.c
r894f58c r56db65d 115 115 116 116 117 static int ohci_register_ep(bus_t *bus_base, endpoint_t *ep )117 static int ohci_register_ep(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc) 118 118 { 119 119 ohci_bus_t *bus = (ohci_bus_t *) bus_base; 120 120 ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep); 121 121 122 const int err = bus->parent_ops.register_endpoint(bus_base, ep );122 const int err = bus->parent_ops.register_endpoint(bus_base, ep, desc); 123 123 if (err) 124 124 return err; -
uspace/drv/bus/usb/xhci/bus.c
r894f58c r56db65d 165 165 } 166 166 167 static int register_endpoint(bus_t *bus_base, endpoint_t *ep )167 static int register_endpoint(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc) 168 168 { 169 169 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 170 170 assert(bus); 171 171 172 usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", ep->target.address, ep->target.endpoint); 172 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; 173 183 174 184 xhci_device_t *xhci_dev = xhci_device_get(ep->device); 175 185 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep); 186 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; 191 192 usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", ep->target.address, ep->target.endpoint); 176 193 return xhci_device_add_endpoint(xhci_dev, xhci_ep); 177 194 } -
uspace/drv/bus/usb/xhci/endpoint.c
r894f58c r56db65d 275 275 assert(&dev->base == ep->base.device); 276 276 assert(dev->base.address == ep->base.target.address); 277 278 // TODO Do not fail hard on runtime conditions 277 279 assert(!dev->endpoints[ep_num]); 278 280 … … 285 287 return EOK; 286 288 } 287 288 // FIXME: Set these from usb_superspeed_endpoint_companion_descriptor_t:289 ep->max_streams = 0;290 ep->max_burst = 0;291 ep->mult = 0;292 289 293 290 /* Set up TRB ring / PSA. */ -
uspace/drv/bus/usb/xhci/rh.c
r894f58c r56db65d 90 90 } 91 91 92 /* FIXME Are these really static? Older HCs fetch it from descriptor. */ 93 /* FIXME Add USB3 options, if applicable. */ 94 static const usb_endpoint_desc_t ep0_desc = { 95 .endpoint_no = 0, 96 .direction = USB_DIRECTION_BOTH, 97 .transfer_type = USB_TRANSFER_CONTROL, 98 .max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE, 99 .packets = 1, 100 }; 101 92 102 // TODO: This currently assumes the device is attached to rh directly. 93 103 // Also, we should consider moving a lot of functionailty to xhci bus … … 112 122 113 123 xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base); 114 /* FIXME: Sync this with xhci_device_add_endpoint. */115 ep0->max_streams = 0;116 ep0->max_burst = 0;117 ep0->mult = 0;118 124 119 125 if ((err = xhci_endpoint_alloc_transfer_ds(ep0))) … … 144 150 fibril_mutex_unlock(&dev->guard); 145 151 146 // XXX: Going around bus, duplicating code147 152 ep0_base->device = dev; 148 ep0_base->target.address = dev->address; 149 ep0_base->target.endpoint = 0; 150 ep0_base->direction = USB_DIRECTION_BOTH; 151 ep0_base->transfer_type = USB_TRANSFER_CONTROL; 152 ep0_base->max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE; 153 ep0_base->packets = 1; 154 ep0_base->bandwidth = CTRL_PIPE_MIN_PACKET_SIZE; 155 156 bus_register_endpoint(&rh->hc->bus.base, ep0_base); 153 154 bus_register_endpoint(&rh->hc->bus.base, ep0_base, &ep0_desc); 157 155 158 156 if (!rh->devices[dev->port - 1]) { -
uspace/lib/usbhost/include/usb/host/bus.h
r894f58c r56db65d 83 83 84 84 endpoint_t *(*create_endpoint)(bus_t *); 85 int (*register_endpoint)(bus_t *, endpoint_t * );85 int (*register_endpoint)(bus_t *, endpoint_t *, const usb_endpoint_desc_t *); 86 86 int (*unregister_endpoint)(bus_t *, endpoint_t *); 87 87 endpoint_t *(*find_endpoint)(bus_t *, device_t*, usb_target_t, usb_direction_t); … … 117 117 int device_init(device_t *); 118 118 119 extern int bus_add_ep(bus_t *bus, device_t *device, usb_endpoint_t endpoint, 120 usb_direction_t dir, usb_transfer_type_t type, size_t max_packet_size, 121 unsigned packets, size_t size); 119 extern int bus_add_ep(bus_t *, device_t *, const usb_endpoint_desc_t *); 122 120 extern int bus_remove_ep(bus_t *, device_t *, usb_target_t, usb_direction_t); 123 121 … … 128 126 129 127 endpoint_t *bus_create_endpoint(bus_t *); 130 int bus_register_endpoint(bus_t *, endpoint_t * );128 int bus_register_endpoint(bus_t *, endpoint_t *, const usb_endpoint_desc_t *); 131 129 int bus_unregister_endpoint(bus_t *, endpoint_t *); 132 130 endpoint_t *bus_find_endpoint(bus_t *, device_t *, usb_target_t, usb_direction_t); -
uspace/lib/usbhost/src/bus.c
r894f58c r56db65d 66 66 } 67 67 68 int bus_add_ep(bus_t *bus, device_t *device, usb_endpoint_t endpoint, 69 usb_direction_t dir, usb_transfer_type_t type, size_t max_packet_size, 70 unsigned packets, size_t size) 68 int bus_add_ep(bus_t *bus, device_t *device, const usb_endpoint_desc_t *desc) 71 69 { 72 70 assert(bus); … … 78 76 return ENOMEM; 79 77 80 ep->target = (usb_target_t) {81 .address = device->address,82 .endpoint = endpoint,83 };84 85 78 ep->device = device; 86 ep->direction = dir; 87 ep->transfer_type = type; 88 ep->max_packet_size = max_packet_size; 89 ep->packets = packets; 90 91 ep->bandwidth = bus_count_bw(ep, size); 92 93 const int err = bus_register_endpoint(bus, ep); 79 const int err = bus_register_endpoint(bus, ep, desc); 94 80 95 81 /* drop Temporary reference */ … … 165 151 } 166 152 167 int bus_register_endpoint(bus_t *bus, endpoint_t *ep )153 int bus_register_endpoint(bus_t *bus, endpoint_t *ep, const usb_endpoint_desc_t *desc) 168 154 { 169 155 assert(bus); … … 174 160 175 161 fibril_mutex_lock(&bus->guard); 176 const int r = bus->ops.register_endpoint(bus, ep );162 const int r = bus->ops.register_endpoint(bus, ep, desc); 177 163 fibril_mutex_unlock(&bus->guard); 178 164 -
uspace/lib/usbhost/src/ddf_helpers.c
r894f58c r56db65d 98 98 assert(dev); 99 99 100 const size_t size = endpoint_desc->max_packet_size;101 102 100 usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n", 103 101 dev->address, endpoint_desc->endpoint_no, … … 106 104 endpoint_desc->max_packet_size, endpoint_desc->usb2.polling_interval); 107 105 108 // FIXME: we now have max_streams and max_burst in endpoint_desc->usb3 struct 109 // Hand it down to XHCI, refactor, whatever 110 111 return bus_add_ep(hcd->bus, dev, endpoint_desc->endpoint_no, 112 endpoint_desc->direction, endpoint_desc->transfer_type, 113 endpoint_desc->max_packet_size, endpoint_desc->packets, 114 size); 106 return bus_add_ep(hcd->bus, dev, endpoint_desc); 115 107 } 116 108 -
uspace/lib/usbhost/src/hcd.c
r894f58c r56db65d 87 87 assert(device->address == target.address); 88 88 89 if (!hcd->ops.schedule) { 90 usb_log_error("HCD does not implement scheduler.\n"); 91 return ENOTSUP; 92 } 93 89 94 endpoint_t *ep = bus_find_endpoint(hcd->bus, device, target, direction); 90 95 if (ep == NULL) { … … 93 98 return ENOENT; 94 99 } 100 101 // TODO cut here aka provide helper to call with instance of endpoint_t in hand 95 102 96 103 usb_log_debug2("%s %d:%d %zu(%zu).\n", … … 104 111 ep->target.address, ep->target.endpoint, name, bw, ep->bandwidth); 105 112 return ENOSPC; 106 }107 if (!hcd->ops.schedule) {108 usb_log_error("HCD does not implement scheduler.\n");109 return ENOTSUP;110 113 } 111 114 -
uspace/lib/usbhost/src/usb2_bus.c
r894f58c r56db65d 91 91 } 92 92 93 static const usb_endpoint_desc_t usb2_default_control_ep = { 94 .endpoint_no = 0, 95 .transfer_type = USB_TRANSFER_CONTROL, 96 .direction = USB_DIRECTION_BOTH, 97 .max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE, 98 .packets = 1, 99 }; 100 101 102 static const usb_target_t usb2_default_target = {{ 103 .address = USB_ADDRESS_DEFAULT, 104 .endpoint = 0, 105 }}; 106 93 107 static int usb2_bus_address_device(bus_t *bus, hcd_t *hcd, device_t *dev) 94 108 { 95 109 int err; 96 97 static const usb_target_t default_target = {{98 .address = USB_ADDRESS_DEFAULT,99 .endpoint = 0,100 }};101 110 102 111 /** Reserve address early, we want pretty log messages */ … … 111 120 /* Add default pipe on default address */ 112 121 usb_log_debug("Device(%d): Adding default target (0:0)", address); 113 err = bus_add_ep(bus, dev, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, 114 CTRL_PIPE_MIN_PACKET_SIZE, CTRL_PIPE_MIN_PACKET_SIZE, 1); 122 err = bus_add_ep(bus, dev, &usb2_default_control_ep); 115 123 if (err != EOK) { 116 124 usb_log_error("Device(%d): Failed to add default target: %s.", … … 126 134 usb_log_debug("Device(%d): Requesting first 8B of device descriptor.", 127 135 address); 128 ssize_t got = hcd_send_batch_sync(hcd, dev, default_target, USB_DIRECTION_IN,136 ssize_t got = hcd_send_batch_sync(hcd, dev, usb2_default_target, USB_DIRECTION_IN, 129 137 (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8, 130 138 "read first 8 bytes of dev descriptor"); … … 134 142 usb_log_error("Device(%d): Failed to get 8B of dev descr: %s.", 135 143 address, str_error(err)); 136 goto err_default_ target;144 goto err_default_control_ep; 137 145 } 138 146 … … 141 149 142 150 usb_log_debug("Device(%d): Setting USB address.", address); 143 err = hcd_send_batch_sync(hcd, dev, default_target, USB_DIRECTION_OUT,151 err = hcd_send_batch_sync(hcd, dev, usb2_default_target, USB_DIRECTION_OUT, 144 152 NULL, 0, *(uint64_t *)&set_address, "set address"); 145 153 if (err != 0) { 146 154 usb_log_error("Device(%d): Failed to set new address: %s.", 147 155 address, str_error(got)); 148 goto err_default_ target;156 goto err_default_control_ep; 149 157 } 150 158 151 159 dev->address = address; 160 161 const usb_endpoint_desc_t control_ep = { 162 .endpoint_no = 0, 163 .transfer_type = USB_TRANSFER_CONTROL, 164 .direction = USB_DIRECTION_BOTH, 165 .max_packet_size = ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)), 166 .packets = ED_MPS_TRANS_OPPORTUNITIES_GET(uint16_usb2host(desc.max_packet_size)), 167 }; 152 168 153 169 /* Register EP on the new address */ 154 170 usb_log_debug("Device(%d): Registering control EP.", address); 155 err = bus_add_ep(bus, dev, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, 156 ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)), 157 ED_MPS_TRANS_OPPORTUNITIES_GET(uint16_usb2host(desc.max_packet_size)), 158 ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size))); 171 err = bus_add_ep(bus, dev, &control_ep); 159 172 if (err != EOK) { 160 173 usb_log_error("Device(%d): Failed to register EP0: %s", 161 174 address, str_error(err)); 162 goto err_default_ target;163 } 164 165 bus_remove_ep(bus, dev, default_target, USB_DIRECTION_BOTH);166 return EOK; 167 168 err_default_ target:169 bus_remove_ep(bus, dev, default_target, USB_DIRECTION_BOTH);175 goto err_default_control_ep; 176 } 177 178 bus_remove_ep(bus, dev, usb2_default_target, USB_DIRECTION_BOTH); 179 return EOK; 180 181 err_default_control_ep: 182 bus_remove_ep(bus, dev, usb2_default_target, USB_DIRECTION_BOTH); 170 183 err_address: 171 184 bus_release_address(bus, address); … … 278 291 * @param endpoint USB endpoint number. 279 292 */ 280 static int usb2_bus_register_ep(bus_t *bus_base, endpoint_t *ep )293 static int usb2_bus_register_ep(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc) 281 294 { 282 295 usb2_bus_t *bus = bus_to_usb2_bus(bus_base); 283 296 assert(ep); 284 297 285 usb_address_t address = ep->target.address; 286 287 if (!usb_address_is_valid(address)) 288 return EINVAL; 289 290 /* Check for speed and address */ 291 if (!bus->devices[address].occupied) 292 return ENOENT; 298 assert(ep->device); 299 300 /* Extract USB2-related information from endpoint_desc */ 301 ep->target = (usb_target_t) {{ 302 .address = ep->device->address, 303 .endpoint = desc->endpoint_no, 304 }}; 305 ep->direction = desc->direction; 306 ep->transfer_type = desc->transfer_type; 307 ep->max_packet_size = desc->max_packet_size; 308 ep->packets = desc->packets; 309 310 ep->bandwidth = bus_base->ops.count_bw(ep, desc->max_packet_size); 293 311 294 312 /* Check for existence */ … … 300 318 return ENOSPC; 301 319 302 list_append(&ep->link, get_list(bus, ep-> target.address));320 list_append(&ep->link, get_list(bus, ep->device->address)); 303 321 bus->free_bw -= ep->bandwidth; 304 322
Note:
See TracChangeset
for help on using the changeset viewer.