Changeset 6832245 in mainline for uspace/drv/bus
- Timestamp:
- 2017-12-14T23:01:57Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 837d53d
- Parents:
- bd05140
- git-author:
- Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:54)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:57)
- Location:
- uspace/drv/bus/usb
- Files:
-
- 21 edited
-
ehci/ehci_bus.c (modified) (6 diffs)
-
ehci/ehci_bus.h (modified) (1 diff)
-
ehci/hc.c (modified) (2 diffs)
-
ehci/hc.h (modified) (1 diff)
-
ehci/main.c (modified) (1 diff)
-
ohci/main.c (modified) (1 diff)
-
ohci/ohci_bus.c (modified) (6 diffs)
-
ohci/ohci_bus.h (modified) (1 diff)
-
uhci/hc.c (modified) (6 diffs)
-
uhci/hc.h (modified) (1 diff)
-
uhci/main.c (modified) (1 diff)
-
vhc/main.c (modified) (1 diff)
-
vhc/transfer.c (modified) (1 diff)
-
vhc/vhcd.h (modified) (1 diff)
-
xhci/bus.c (modified) (26 diffs)
-
xhci/bus.h (modified) (1 diff)
-
xhci/endpoint.c (modified) (1 diff)
-
xhci/endpoint.h (modified) (1 diff)
-
xhci/hc.c (modified) (1 diff)
-
xhci/main.c (modified) (1 diff)
-
xhci/rh.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_bus.c
rbd05140 r6832245 79 79 /** Creates new hcd endpoint representation. 80 80 */ 81 static endpoint_t *ehci_endpoint_create( bus_t *bus)81 static endpoint_t *ehci_endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc) 82 82 { 83 assert( bus);83 assert(dev); 84 84 85 85 ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t)); … … 87 87 return NULL; 88 88 89 endpoint_init(&ehci_ep->base, bus); 89 endpoint_init(&ehci_ep->base, dev, desc); 90 91 // TODO: extract USB2 information from desc 90 92 91 93 ehci_ep->qh = malloc32(sizeof(qh_t)); … … 114 116 115 117 116 static int ehci_register_ep( bus_t *bus_base, device_t *dev, endpoint_t *ep, const usb_endpoint_desc_t *desc)118 static int ehci_register_ep(endpoint_t *ep) 117 119 { 120 bus_t *bus_base = endpoint_get_bus(ep); 118 121 ehci_bus_t *bus = (ehci_bus_t *) bus_base; 119 122 ehci_endpoint_t *ehci_ep = ehci_endpoint_get(ep); 123 assert(fibril_mutex_is_locked(&bus_base->guard)); 120 124 121 // TODO utilize desc->usb2 122 123 const int err = bus->parent_ops.register_endpoint(bus_base, dev, ep, desc); 125 const int err = usb2_bus_ops.endpoint_register(ep); 124 126 if (err) 125 127 return err; … … 131 133 } 132 134 133 static int ehci_unregister_ep( bus_t *bus_base,endpoint_t *ep)135 static int ehci_unregister_ep(endpoint_t *ep) 134 136 { 137 bus_t *bus_base = endpoint_get_bus(ep); 135 138 ehci_bus_t *bus = (ehci_bus_t *) bus_base; 136 139 assert(bus); 137 140 assert(ep); 138 141 139 const int err = bus->parent_ops.unregister_endpoint(bus_base,ep);142 const int err = usb2_bus_ops.endpoint_unregister(ep); 140 143 if (err) 141 144 return err; … … 145 148 } 146 149 147 static usb_transfer_batch_t *ehci_ bus_create_batch(bus_t *bus,endpoint_t *ep)150 static usb_transfer_batch_t *ehci_create_batch(endpoint_t *ep) 148 151 { 149 152 ehci_transfer_batch_t *batch = ehci_transfer_batch_create(ep); … … 151 154 } 152 155 153 static void ehci_ bus_destroy_batch(usb_transfer_batch_t *batch)156 static void ehci_destroy_batch(usb_transfer_batch_t *batch) 154 157 { 155 158 ehci_transfer_batch_destroy(ehci_transfer_batch_get(batch)); 156 159 } 157 160 158 int ehci_bus_init(ehci_bus_t *bus, hc_t *hc) 161 static const bus_ops_t ehci_bus_ops = { 162 .parent = &usb2_bus_ops, 163 164 .endpoint_destroy = ehci_endpoint_destroy, 165 .endpoint_create = ehci_endpoint_create, 166 .endpoint_register = ehci_register_ep, 167 .endpoint_unregister = ehci_unregister_ep, 168 .endpoint_set_toggle = ehci_ep_toggle_set, 169 .endpoint_get_toggle = ehci_ep_toggle_get, 170 .endpoint_count_bw = bandwidth_count_usb11, 171 .batch_create = ehci_create_batch, 172 .batch_destroy = ehci_destroy_batch, 173 }; 174 175 int ehci_bus_init(ehci_bus_t *bus, hcd_t *hcd, hc_t *hc) 159 176 { 160 177 assert(hc); 161 178 assert(bus); 162 179 163 // FIXME: Implement the USB2 bw counting.164 usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);180 usb2_bus_t *usb2_bus = (usb2_bus_t *) bus; 181 bus_t *bus_base = (bus_t *) bus; 165 182 166 bus_ops_t *ops = &bus->base.base.ops; 167 bus->parent_ops = *ops; 168 ops->create_endpoint = ehci_endpoint_create; 169 ops->destroy_endpoint = ehci_endpoint_destroy; 170 ops->endpoint_set_toggle = ehci_ep_toggle_set; 171 ops->endpoint_get_toggle = ehci_ep_toggle_get; 172 173 ops->register_endpoint = ehci_register_ep; 174 ops->unregister_endpoint = ehci_unregister_ep; 175 176 ops->create_batch = ehci_bus_create_batch; 177 ops->destroy_batch = ehci_bus_destroy_batch; 183 usb2_bus_init(usb2_bus, hcd, BANDWIDTH_AVAILABLE_USB11); 184 bus_base->ops = &ehci_bus_ops; 178 185 179 186 bus->hc = hc; -
uspace/drv/bus/usb/ehci/ehci_bus.h
rbd05140 r6832245 59 59 usb2_bus_t base; 60 60 hc_t *hc; 61 62 /* Stored original ops from base, they are called in our handlers */63 bus_ops_t parent_ops;64 61 } ehci_bus_t; 65 62 66 int ehci_bus_init(ehci_bus_t *, hc_t *); 63 void ehci_bus_prepare_ops(void); 64 65 int ehci_bus_init(ehci_bus_t *, hcd_t *, hc_t *); 67 66 68 67 /** Get and convert assigned ehci_endpoint_t structure -
uspace/drv/bus/usb/ehci/hc.c
rbd05140 r6832245 149 149 * @return Error code 150 150 */ 151 int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res)151 int hc_init(hc_t *instance, hcd_t *hcd, const hw_res_list_parsed_t *hw_res) 152 152 { 153 153 assert(instance); … … 190 190 &instance->rh, instance->caps, instance->registers, "ehci rh"); 191 191 192 ehci_bus_init(&instance->bus, instance);192 ehci_bus_init(&instance->bus, hcd, instance); 193 193 return EOK; 194 194 } -
uspace/drv/bus/usb/ehci/hc.h
rbd05140 r6832245 85 85 } hc_t; 86 86 87 int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res);87 int hc_init(hc_t *instance, hcd_t *hcd, const hw_res_list_parsed_t *hw_res); 88 88 int hc_start(hc_t *instance, bool interrupts); 89 89 void hc_fini(hc_t *instance); -
uspace/drv/bus/usb/ehci/main.c
rbd05140 r6832245 81 81 return ENOMEM; 82 82 83 const int ret = hc_init(instance, res);83 const int ret = hc_init(instance, hcd, res); 84 84 if (ret == EOK) { 85 85 hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops, &instance->bus.base.base); -
uspace/drv/bus/usb/ohci/main.c
rbd05140 r6832245 83 83 goto err; 84 84 85 if ((err = ohci_bus_init(&instance->bus, instance)))85 if ((err = ohci_bus_init(&instance->bus, hcd, instance))) 86 86 goto err; 87 87 -
uspace/drv/bus/usb/ohci/ohci_bus.c
rbd05140 r6832245 72 72 /** Creates new hcd endpoint representation. 73 73 */ 74 static endpoint_t *ohci_endpoint_create( bus_t *bus)74 static endpoint_t *ohci_endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc) 75 75 { 76 assert( bus);76 assert(dev); 77 77 78 78 ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t)); … … 80 80 return NULL; 81 81 82 endpoint_init(&ohci_ep->base, bus);82 endpoint_init(&ohci_ep->base, dev, desc); 83 83 84 84 ohci_ep->ed = malloc32(sizeof(ed_t)); … … 115 115 116 116 117 static int ohci_register_ep( bus_t *bus_base, device_t *dev, endpoint_t *ep, const usb_endpoint_desc_t *desc)117 static int ohci_register_ep(endpoint_t *ep) 118 118 { 119 bus_t *bus_base = endpoint_get_bus(ep); 119 120 ohci_bus_t *bus = (ohci_bus_t *) bus_base; 120 121 ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ep); 121 122 122 const int err = bus->parent_ops.register_endpoint(bus_base, dev, ep, desc);123 const int err = usb2_bus_ops.endpoint_register(ep); 123 124 if (err) 124 125 return err; … … 130 131 } 131 132 132 static int ohci_unregister_ep( bus_t *bus_base,endpoint_t *ep)133 static int ohci_unregister_ep(endpoint_t *ep) 133 134 { 134 ohci_bus_t *bus = (ohci_bus_t *) bus_base; 135 assert(bus); 135 ohci_bus_t *bus = (ohci_bus_t *) endpoint_get_bus(ep); 136 136 assert(ep); 137 137 138 const int err = bus->parent_ops.unregister_endpoint(bus_base,ep);138 const int err = usb2_bus_ops.endpoint_unregister(ep); 139 139 if (err) 140 140 return err; … … 144 144 } 145 145 146 static usb_transfer_batch_t *ohci_ bus_create_batch(bus_t *bus,endpoint_t *ep)146 static usb_transfer_batch_t *ohci_create_batch(endpoint_t *ep) 147 147 { 148 148 ohci_transfer_batch_t *batch = ohci_transfer_batch_create(ep); … … 150 150 } 151 151 152 static void ohci_ bus_destroy_batch(usb_transfer_batch_t *batch)152 static void ohci_destroy_batch(usb_transfer_batch_t *batch) 153 153 { 154 154 ohci_transfer_batch_destroy(ohci_transfer_batch_get(batch)); 155 155 } 156 156 157 int ohci_bus_init(ohci_bus_t *bus, hc_t *hc) 157 static const bus_ops_t ohci_bus_ops = { 158 .parent = &usb2_bus_ops, 159 160 .endpoint_destroy = ohci_endpoint_destroy, 161 .endpoint_create = ohci_endpoint_create, 162 .endpoint_register = ohci_register_ep, 163 .endpoint_unregister = ohci_unregister_ep, 164 .endpoint_count_bw = bandwidth_count_usb11, 165 .endpoint_set_toggle = ohci_ep_toggle_set, 166 .endpoint_get_toggle = ohci_ep_toggle_get, 167 .batch_create = ohci_create_batch, 168 .batch_destroy = ohci_destroy_batch, 169 }; 170 171 172 int ohci_bus_init(ohci_bus_t *bus, hcd_t *hcd, hc_t *hc) 158 173 { 159 174 assert(hc); 160 175 assert(bus); 161 176 162 usb2_bus_init(&bus->base, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);163 177 164 bus_ops_t *ops = &bus->base.base.ops; 165 bus->parent_ops = *ops; 166 ops->create_endpoint = ohci_endpoint_create; 167 ops->destroy_endpoint = ohci_endpoint_destroy; 168 ops->endpoint_set_toggle = ohci_ep_toggle_set; 169 ops->endpoint_get_toggle = ohci_ep_toggle_get; 178 usb2_bus_t *usb2_bus = (usb2_bus_t *) bus; 179 bus_t *bus_base = (bus_t *) bus; 170 180 171 ops->register_endpoint = ohci_register_ep; 172 ops->unregister_endpoint = ohci_unregister_ep; 173 174 ops->create_batch = ohci_bus_create_batch; 175 ops->destroy_batch = ohci_bus_destroy_batch; 181 usb2_bus_init(usb2_bus, hcd, BANDWIDTH_AVAILABLE_USB11); 182 bus_base->ops = &ohci_bus_ops; 176 183 177 184 bus->hc = hc; -
uspace/drv/bus/usb/ohci/ohci_bus.h
rbd05140 r6832245 60 60 usb2_bus_t base; 61 61 hc_t *hc; 62 63 /* Stored original ops from base, they are called in our handlers */64 bus_ops_t parent_ops;65 62 } ohci_bus_t; 66 63 67 int ohci_bus_init(ohci_bus_t *, hc _t *);64 int ohci_bus_init(ohci_bus_t *, hcd_t *, hc_t *); 68 65 69 66 /** Get and convert assigned ohci_endpoint_t structure -
uspace/drv/bus/usb/uhci/hc.c
rbd05140 r6832245 95 95 96 96 static void hc_init_hw(const hc_t *instance); 97 static int hc_init_mem_structures(hc_t *instance );97 static int hc_init_mem_structures(hc_t *instance, hcd_t *); 98 98 static int hc_init_transfer_lists(hc_t *instance); 99 99 … … 215 215 * interrupt fibrils. 216 216 */ 217 int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res)217 int hc_init(hc_t *instance, hcd_t *hcd, const hw_res_list_parsed_t *hw_res) 218 218 { 219 219 assert(instance); … … 238 238 hw_res->io_ranges.ranges[0].size); 239 239 240 ret = hc_init_mem_structures(instance );240 ret = hc_init_mem_structures(instance, hcd); 241 241 if (ret != EOK) { 242 242 usb_log_error("Failed to init UHCI memory structures: %s.\n", … … 309 309 } 310 310 311 static usb_transfer_batch_t *create_transfer_batch( bus_t *bus,endpoint_t *ep)311 static usb_transfer_batch_t *create_transfer_batch(endpoint_t *ep) 312 312 { 313 313 uhci_transfer_batch_t *batch = uhci_transfer_batch_create(ep); … … 319 319 uhci_transfer_batch_destroy(uhci_transfer_batch_get(batch)); 320 320 } 321 322 static const bus_ops_t uhci_bus_ops = { 323 .parent = &usb2_bus_ops, 324 325 .endpoint_count_bw = bandwidth_count_usb11, 326 .batch_create = create_transfer_batch, 327 .batch_destroy = destroy_transfer_batch, 328 }; 321 329 322 330 /** Initialize UHCI hc memory structures. … … 330 338 * - frame list page (needs to be one UHCI hw accessible 4K page) 331 339 */ 332 int hc_init_mem_structures(hc_t *instance )340 int hc_init_mem_structures(hc_t *instance, hcd_t *hcd) 333 341 { 334 342 int err; 335 343 assert(instance); 336 344 337 if ((err = usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11)))345 if ((err = usb2_bus_init(&instance->bus, hcd, BANDWIDTH_AVAILABLE_USB11))) 338 346 return err; 339 347 340 instance->bus.base.ops.create_batch = create_transfer_batch;341 instance->bus.base.ops.destroy_batch = destroy_transfer_batch;348 bus_t *bus = (bus_t *) &instance->bus; 349 bus->ops = &uhci_bus_ops; 342 350 343 351 /* Init USB frame list page */ -
uspace/drv/bus/usb/uhci/hc.h
rbd05140 r6832245 126 126 } hc_t; 127 127 128 extern int hc_init(hc_t *, const hw_res_list_parsed_t *);128 extern int hc_init(hc_t *, hcd_t *, const hw_res_list_parsed_t *); 129 129 extern void hc_start(hc_t *); 130 130 extern void hc_fini(hc_t *); -
uspace/drv/bus/usb/uhci/main.c
rbd05140 r6832245 80 80 return ENOMEM; 81 81 82 if ((err = hc_init(instance, res)) != EOK)82 if ((err = hc_init(instance, hcd, res)) != EOK) 83 83 goto err; 84 84 -
uspace/drv/bus/usb/vhc/main.c
rbd05140 r6832245 69 69 return ret; 70 70 } 71 vhc_init(vhc );71 vhc_init(vhc, dev_to_hcd(dev)); 72 72 return EOK; 73 73 } -
uspace/drv/bus/usb/vhc/transfer.c
rbd05140 r6832245 157 157 } 158 158 159 int vhc_init(vhc_data_t *instance) 159 static const bus_ops_t vhc_bus_ops = { 160 .parent = &usb2_bus_ops, 161 .endpoint_count_bw = bandwidth_count_usb11, 162 }; 163 164 int vhc_init(vhc_data_t *instance, hcd_t *hcd) 160 165 { 161 166 assert(instance); 162 167 list_initialize(&instance->devices); 163 168 fibril_mutex_initialize(&instance->guard); 164 usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11); 169 usb2_bus_init(&instance->bus, hcd, BANDWIDTH_AVAILABLE_USB11); 170 instance->bus.base.ops = &vhc_bus_ops; 165 171 instance->magic = 0xDEADBEEF; 166 172 return virthub_init(&instance->hub, "root hub"); -
uspace/drv/bus/usb/vhc/vhcd.h
rbd05140 r6832245 77 77 void vhc_virtdev_unplug(vhc_data_t *, uintptr_t); 78 78 79 int vhc_init(vhc_data_t *instance );79 int vhc_init(vhc_data_t *instance, hcd_t *); 80 80 int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch); 81 81 int vhc_transfer_queue_processor(void *arg); -
uspace/drv/bus/usb/xhci/bus.c
rbd05140 r6832245 58 58 }; 59 59 60 static int prepare_endpoint(xhci_endpoint_t *ep, const usb_endpoint_desc_t *desc) 61 { 62 /* Extract information from endpoint_desc */ 63 ep->base.endpoint = desc->endpoint_no; 64 ep->base.direction = desc->direction; 65 ep->base.transfer_type = desc->transfer_type; 66 ep->base.max_packet_size = desc->max_packet_size; 67 ep->base.packets = desc->packets; 68 ep->max_streams = desc->usb3.max_streams; 69 ep->max_burst = desc->usb3.max_burst; 70 ep->mult = desc->usb3.mult; 71 72 if (ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS) { 73 if (ep->base.device->speed <= USB_SPEED_HIGH) { 74 ep->isoch_max_size = desc->max_packet_size * (desc->packets + 1); 75 } 76 else if (ep->base.device->speed == USB_SPEED_SUPER) { 77 ep->isoch_max_size = desc->usb3.bytes_per_interval; 78 } 79 /* Technically there could be superspeed plus too. */ 80 81 /* Allocate and setup isochronous-specific structures. */ 82 ep->isoch_enqueue = 0; 83 ep->isoch_dequeue = XHCI_ISOCH_BUFFER_COUNT - 1; 84 ep->isoch_started = false; 85 86 fibril_mutex_initialize(&ep->isoch_guard); 87 fibril_condvar_initialize(&ep->isoch_avail); 88 } 89 90 return xhci_endpoint_alloc_transfer_ds(ep); 91 } 92 93 static endpoint_t *create_endpoint(bus_t *base); 94 95 static int address_device(xhci_hc_t *hc, xhci_device_t *dev) 60 static endpoint_t *endpoint_create(device_t *, const usb_endpoint_desc_t *); 61 62 static int address_device(xhci_bus_t *bus, xhci_device_t *dev) 96 63 { 97 64 int err; 98 65 99 66 /* Enable new slot. */ 100 if ((err = hc_enable_slot( hc, &dev->slot_id)) != EOK)67 if ((err = hc_enable_slot(bus->hc, &dev->slot_id)) != EOK) 101 68 return err; 102 69 usb_log_debug2("Obtained slot ID: %u.\n", dev->slot_id); 103 70 104 71 /* Create and configure control endpoint. */ 105 endpoint_t *ep0_base = create_endpoint(&hc->bus.base);72 endpoint_t *ep0_base = endpoint_create(&dev->base, &ep0_initial_desc); 106 73 if (!ep0_base) 107 74 goto err_slot; … … 112 79 xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base); 113 80 114 if ((err = prepare_endpoint(ep0, &ep0_initial_desc)))81 if ((err = xhci_endpoint_alloc_transfer_ds(ep0))) 115 82 goto err_ep; 116 83 … … 120 87 121 88 /* Address device */ 122 if ((err = hc_address_device( hc, dev, ep0)))89 if ((err = hc_address_device(bus->hc, dev, ep0))) 123 90 goto err_added; 124 91 … … 135 102 endpoint_del_ref(ep0_base); 136 103 err_slot: 137 hc_disable_slot( hc, dev);104 hc_disable_slot(bus->hc, dev); 138 105 return err; 139 106 } … … 164 131 } 165 132 166 int xhci_bus_enumerate_device(xhci_bus_t *bus, xhci_hc_t *hc,device_t *dev)133 int xhci_bus_enumerate_device(xhci_bus_t *bus, device_t *dev) 167 134 { 168 135 int err; … … 184 151 185 152 /* Assign an address to the device */ 186 if ((err = address_device( hc, xhci_dev))) {153 if ((err = address_device(bus, xhci_dev))) { 187 154 usb_log_error("Failed to setup address of the new device: %s", str_error(err)); 188 155 return err; … … 195 162 fibril_mutex_unlock(&bus->base.guard); 196 163 197 if ((err = setup_ep0_packet_size( hc, xhci_dev))) {164 if ((err = setup_ep0_packet_size(bus->hc, xhci_dev))) { 198 165 usb_log_error("Failed to setup control endpoint of the new device: %s", str_error(err)); 199 166 goto err_address; … … 201 168 202 169 /* Read the device descriptor, derive the match ids */ 203 if ((err = hcd_ddf_device_explore( hc->hcd,dev))) {170 if ((err = hcd_ddf_device_explore(dev))) { 204 171 usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err)); 205 172 goto err_address; … … 213 180 } 214 181 215 static int unregister_endpoint(bus_t *,endpoint_t *);216 217 int xhci_bus_remove_device(xhci_bus_t *bus, xhci_hc_t *hc,device_t *dev)182 static int endpoint_unregister(endpoint_t *); 183 184 int xhci_bus_remove_device(xhci_bus_t *bus, device_t *dev) 218 185 { 219 186 int err; … … 246 213 /* Disable the slot, dropping all endpoints. */ 247 214 const uint32_t slot_id = xhci_dev->slot_id; 248 if ((err = hc_disable_slot( hc, xhci_dev))) {215 if ((err = hc_disable_slot(bus->hc, xhci_dev))) { 249 216 usb_log_warning("Failed to disable slot of device " XHCI_DEV_FMT ": %s", 250 217 XHCI_DEV_ARGS(*xhci_dev), str_error(err)); … … 258 225 continue; 259 226 260 if ((err = unregister_endpoint(&bus->base,&xhci_dev->endpoints[i]->base))) {227 if ((err = endpoint_unregister(&xhci_dev->endpoints[i]->base))) { 261 228 usb_log_warning("Failed to unregister endpoint " XHCI_EP_FMT ": %s", 262 229 XHCI_EP_ARGS(*xhci_dev->endpoints[i]), str_error(err)); … … 278 245 } 279 246 280 static int enumerate_device(bus_t *bus_base, hcd_t *hcd, device_t *dev) 281 { 282 xhci_hc_t *hc = hcd_get_driver_data(hcd); 283 assert(hc); 284 285 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 286 assert(bus); 287 288 return xhci_bus_enumerate_device(bus, hc, dev); 289 } 290 291 static int remove_device(bus_t *bus_base, hcd_t *hcd, device_t *dev) 292 { 293 xhci_hc_t *hc = hcd_get_driver_data(hcd); 294 assert(hc); 295 296 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 297 assert(bus); 298 299 return xhci_bus_remove_device(bus, hc, dev); 300 } 301 302 static int online_device(bus_t *bus_base, hcd_t *hcd, device_t *dev_base) 303 { 304 int err; 305 306 xhci_hc_t *hc = hcd_get_driver_data(hcd); 307 assert(hc); 308 309 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 247 static int device_enumerate(device_t *dev) 248 { 249 xhci_bus_t *bus = bus_to_xhci_bus(dev->bus); 250 return xhci_bus_enumerate_device(bus, dev); 251 } 252 253 static int device_remove(device_t *dev) 254 { 255 xhci_bus_t *bus = bus_to_xhci_bus(dev->bus); 256 return xhci_bus_remove_device(bus, dev); 257 } 258 259 static int device_online(device_t *dev_base) 260 { 261 int err; 262 263 xhci_bus_t *bus = bus_to_xhci_bus(dev_base->bus); 310 264 assert(bus); 311 265 … … 314 268 315 269 /* Transition the device from the Addressed to the Configured state. */ 316 if ((err = hc_configure_device( hc, dev->slot_id))) {270 if ((err = hc_configure_device(bus->hc, dev->slot_id))) { 317 271 usb_log_warning("Failed to configure device " XHCI_DEV_FMT ".", XHCI_DEV_ARGS(*dev)); 318 272 } … … 331 285 } 332 286 333 static int offline_device(bus_t *bus_base, hcd_t *hcd, device_t *dev_base) 334 { 335 int err; 336 337 xhci_hc_t *hc = hcd_get_driver_data(hcd); 338 assert(hc); 339 340 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 287 static int device_offline(device_t *dev_base) 288 { 289 int err; 290 291 xhci_bus_t *bus = bus_to_xhci_bus(dev_base->bus); 341 292 assert(bus); 342 293 … … 370 321 371 322 /* Issue one HC command to simultaneously drop all endpoints except zero. */ 372 if ((err = hc_deconfigure_device( hc, dev->slot_id))) {323 if ((err = hc_deconfigure_device(bus->hc, dev->slot_id))) { 373 324 usb_log_warning("Failed to deconfigure device " XHCI_DEV_FMT ".", 374 325 XHCI_DEV_ARGS(*dev)); … … 388 339 } 389 340 390 static endpoint_t *create_endpoint(bus_t *base) 391 { 392 xhci_bus_t *bus = bus_to_xhci_bus(base); 393 341 static endpoint_t *endpoint_create(device_t *dev, const usb_endpoint_desc_t *desc) 342 { 394 343 xhci_endpoint_t *ep = calloc(1, sizeof(xhci_endpoint_t)); 395 344 if (!ep) 396 345 return NULL; 397 346 398 if (xhci_endpoint_init(ep, bus)) {347 if (xhci_endpoint_init(ep, dev, desc)) { 399 348 free(ep); 400 349 return NULL; … … 404 353 } 405 354 406 static void destroy_endpoint(endpoint_t *ep)355 static void endpoint_destroy(endpoint_t *ep) 407 356 { 408 357 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep); … … 412 361 } 413 362 414 static int register_endpoint(bus_t *bus_base, device_t *device, endpoint_t *ep_base, const usb_endpoint_desc_t *desc)415 { 416 int err; 417 xhci_bus_t *bus = bus_to_xhci_bus( bus_base);363 static int endpoint_register(endpoint_t *ep_base) 364 { 365 int err; 366 xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep_base)); 418 367 xhci_endpoint_t *ep = xhci_endpoint_get(ep_base); 419 368 420 xhci_device_t *dev = xhci_device_get( device);421 422 if ((err = prepare_endpoint(ep, desc)))369 xhci_device_t *dev = xhci_device_get(ep_base->device); 370 371 if ((err = xhci_endpoint_alloc_transfer_ds(ep))) 423 372 return err; 424 373 … … 443 392 } 444 393 445 static int unregister_endpoint(bus_t *bus_base,endpoint_t *ep_base)446 { 447 int err; 448 xhci_bus_t *bus = bus_to_xhci_bus( bus_base);394 static int endpoint_unregister(endpoint_t *ep_base) 395 { 396 int err; 397 xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep_base)); 449 398 xhci_endpoint_t *ep = xhci_endpoint_get(ep_base); 450 399 xhci_device_t *dev = xhci_device_get(ep_base->device); … … 470 419 } 471 420 472 static endpoint_t* find_endpoint(bus_t *bus_base,device_t *dev_base, usb_target_t target, usb_direction_t direction)421 static endpoint_t* device_find_endpoint(device_t *dev_base, usb_target_t target, usb_direction_t direction) 473 422 { 474 423 xhci_device_t *dev = xhci_device_get(dev_base); … … 487 436 } 488 437 489 static size_t count_bw(endpoint_t *ep, size_t size)490 {491 // TODO: Implement me!492 return 0;493 }494 495 438 /* Endpoint ops, optional (have generic fallback) */ 496 439 static bool endpoint_get_toggle(endpoint_t *ep) … … 525 468 } 526 469 527 static usb_transfer_batch_t * create_batch(bus_t *bus,endpoint_t *ep)470 static usb_transfer_batch_t *batch_create(endpoint_t *ep) 528 471 { 529 472 xhci_transfer_t *transfer = xhci_transfer_create(ep); … … 531 474 } 532 475 533 static void destroy_batch(usb_transfer_batch_t *batch)476 static void batch_destroy(usb_transfer_batch_t *batch) 534 477 { 535 478 xhci_transfer_destroy(xhci_transfer_from_batch(batch)); … … 538 481 static const bus_ops_t xhci_bus_ops = { 539 482 #define BIND_OP(op) .op = op, 540 BIND_OP(enumerate_device)541 BIND_OP(remove_device)542 543 BIND_OP(online_device)544 BIND_OP(offline_device)545 546 BIND_OP(create_endpoint)547 BIND_OP(destroy_endpoint)548 549 BIND_OP(register_endpoint)550 BIND_OP(unregister_endpoint)551 BIND_OP(find_endpoint)552 553 483 BIND_OP(reserve_default_address) 554 484 BIND_OP(release_default_address) 555 556 485 BIND_OP(reset_toggle) 557 BIND_OP(count_bw) 558 486 487 BIND_OP(device_enumerate) 488 BIND_OP(device_remove) 489 BIND_OP(device_online) 490 BIND_OP(device_offline) 491 BIND_OP(device_find_endpoint) 492 493 BIND_OP(endpoint_create) 494 BIND_OP(endpoint_destroy) 495 BIND_OP(endpoint_register) 496 BIND_OP(endpoint_unregister) 559 497 BIND_OP(endpoint_get_toggle) 560 498 BIND_OP(endpoint_set_toggle) 561 499 562 BIND_OP( create_batch)563 BIND_OP( destroy_batch)500 BIND_OP(batch_create) 501 BIND_OP(batch_destroy) 564 502 #undef BIND_OP 565 503 }; … … 569 507 assert(bus); 570 508 571 bus_init(&bus->base, sizeof(xhci_device_t));509 bus_init(&bus->base, hc->hcd, sizeof(xhci_device_t)); 572 510 573 511 bus->devices_by_slot = calloc(hc->max_slots, sizeof(xhci_device_t *)); … … 576 514 577 515 bus->hc = hc; 578 bus->base.ops = xhci_bus_ops;516 bus->base.ops = &xhci_bus_ops; 579 517 bus->default_address_speed = USB_SPEED_MAX; 580 518 return EOK; -
uspace/drv/bus/usb/xhci/bus.h
rbd05140 r6832245 58 58 void xhci_bus_fini(xhci_bus_t *); 59 59 60 int xhci_bus_enumerate_device(xhci_bus_t *, xhci_hc_t *,device_t *);61 int xhci_bus_remove_device(xhci_bus_t *, xhci_hc_t *,device_t *);60 int xhci_bus_enumerate_device(xhci_bus_t *, device_t *); 61 int xhci_bus_remove_device(xhci_bus_t *, device_t *); 62 62 63 63 #endif -
uspace/drv/bus/usb/xhci/endpoint.c
rbd05140 r6832245 45 45 #include "endpoint.h" 46 46 47 int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, xhci_bus_t *xhci_bus)47 int xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev, const usb_endpoint_desc_t *desc) 48 48 { 49 49 assert(xhci_ep); 50 assert(xhci_bus); 51 52 bus_t *bus = &xhci_bus->base; 50 53 51 endpoint_t *ep = &xhci_ep->base; 54 52 55 endpoint_init(ep, bus); 53 endpoint_init(ep, dev, desc); 54 55 xhci_ep->max_streams = desc->usb3.max_streams; 56 xhci_ep->max_burst = desc->usb3.max_burst; 57 xhci_ep->mult = desc->usb3.mult; 58 59 if (xhci_ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS) { 60 xhci_ep->isoch_max_size = desc->usb3.bytes_per_interval 61 ? desc->usb3.bytes_per_interval 62 : desc->max_packet_size * (desc->packets + 1); 63 /* Technically there could be superspeed plus too. */ 64 65 /* Allocate and setup isochronous-specific structures. */ 66 xhci_ep->isoch_enqueue = 0; 67 xhci_ep->isoch_dequeue = XHCI_ISOCH_BUFFER_COUNT - 1; 68 xhci_ep->isoch_started = false; 69 70 fibril_mutex_initialize(&xhci_ep->isoch_guard); 71 fibril_condvar_initialize(&xhci_ep->isoch_avail); 72 } 56 73 57 74 return EOK; -
uspace/drv/bus/usb/xhci/endpoint.h
rbd05140 r6832245 149 149 #define XHCI_DEV_ARGS(dev) ddf_fun_get_name((dev).base.fun), (dev).slot_id 150 150 151 int xhci_endpoint_init(xhci_endpoint_t *, xhci_bus_t *);151 int xhci_endpoint_init(xhci_endpoint_t *, device_t *, const usb_endpoint_desc_t *); 152 152 void xhci_endpoint_fini(xhci_endpoint_t *); 153 153 int xhci_endpoint_alloc_transfer_ds(xhci_endpoint_t *); -
uspace/drv/bus/usb/xhci/hc.c
rbd05140 r6832245 212 212 goto err_scratch; 213 213 214 if ((err = xhci_bus_init(&hc->bus, hc))) 215 goto err_cmd; 216 214 217 if ((err = xhci_rh_init(&hc->rh, hc, device))) 215 goto err_cmd; 216 217 if ((err = xhci_bus_init(&hc->bus, hc))) 218 goto err_rh; 219 220 221 return EOK; 222 223 err_rh: 224 xhci_rh_fini(&hc->rh); 218 goto err_bus; 219 220 return EOK; 221 222 err_bus: 223 xhci_bus_fini(&hc->bus); 225 224 err_cmd: 226 225 xhci_fini_commands(hc); -
uspace/drv/bus/usb/xhci/main.c
rbd05140 r6832245 82 82 goto err; 83 83 84 hc->hcd = hcd; 85 84 86 if ((err = hc_init_memory(hc, device))) 85 87 goto err; 86 88 87 89 hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops, &hc->bus.base); 88 hc->hcd = hcd;89 90 90 91 return EOK; -
uspace/drv/bus/usb/xhci/rh.c
rbd05140 r6832245 71 71 rh->hc_device = device; 72 72 73 const int err = device_init(&rh->device.base);73 const int err = bus_device_init(&rh->device.base, &rh->hc->bus.base); 74 74 if (err) 75 75 return err; … … 94 94 xhci_bus_t *bus = &rh->hc->bus; 95 95 96 device_t *dev = hcd_ddf_device_create(rh->hc_device, bus->base.device_size);96 device_t *dev = hcd_ddf_device_create(rh->hc_device, &bus->base); 97 97 if (!dev) { 98 98 usb_log_error("Failed to create USB device function."); … … 109 109 dev->speed = port_speed->usb_speed; 110 110 111 if ((err = xhci_bus_enumerate_device(bus, rh->hc,dev))) {111 if ((err = xhci_bus_enumerate_device(bus, dev))) { 112 112 usb_log_error("Failed to enumerate USB device: %s", str_error(err)); 113 113 return err; … … 115 115 116 116 if (!ddf_fun_get_name(dev->fun)) { 117 device_set_default_name(dev);117 bus_device_set_default_name(dev); 118 118 } 119 119 … … 196 196 197 197 /* Remove device from XHCI bus. */ 198 if ((err = xhci_bus_remove_device(&rh->hc->bus, rh->hc,&dev->base))) {198 if ((err = xhci_bus_remove_device(&rh->hc->bus, &dev->base))) { 199 199 usb_log_warning("Failed to remove device " XHCI_DEV_FMT " from XHCI bus: %s", 200 200 XHCI_DEV_ARGS(*dev), str_error(err));
Note:
See TracChangeset
for help on using the changeset viewer.
