Changeset 296d22fc in mainline
- Timestamp:
- 2018-01-25T02:05:57Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fa4b12d5
- Parents:
- d369b3b
- git-author:
- Ondřej Hlavatý <aearsis@…> (2018-01-25 02:03:48)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2018-01-25 02:05:57)
- Location:
- uspace/lib/usbhost
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/bus.h
rd369b3b r296d22fc 102 102 */ 103 103 struct bus_ops { 104 /* Undefined operations will be delegated to parent ops */105 const bus_ops_t *parent;106 107 104 /* Global operations on the bus */ 108 105 void (*interrupt)(bus_t *, uint32_t); … … 126 123 void (*batch_destroy)(usb_transfer_batch_t *); /**< Optional */ 127 124 }; 128 129 /**130 * Use this macro to lookup virtual function.131 */132 #define BUS_OPS_LOOKUP(start, fn) ({ bus_ops_t const * ops = (start); while (ops && ops->fn == NULL) ops = ops->parent; ops; })133 125 134 126 /** Endpoint management structure */ -
uspace/lib/usbhost/src/bus.c
rd369b3b r296d22fc 129 129 assert(dev); 130 130 131 const bus_ops_t *ops = BUS_OPS_LOOKUP(dev->bus->ops, device_enumerate); 132 if (!ops) 131 if (!dev->bus->ops->device_enumerate) 133 132 return ENOTSUP; 134 133 … … 138 137 device_setup_tt(dev); 139 138 140 const int r = ops->device_enumerate(dev);139 const int r = dev->bus->ops->device_enumerate(dev); 141 140 if (r) 142 141 return r; … … 208 207 assert(dev->fun != NULL); 209 208 210 const bus_ops_t *ops = BUS_OPS_LOOKUP(dev->bus->ops, device_gone); 211 const bus_ops_t *ep_ops = BUS_OPS_LOOKUP(dev->bus->ops, endpoint_unregister); 209 const bus_ops_t *ops = dev->bus->ops; 212 210 213 211 /* First, block new transfers and operations. */ … … 241 239 242 240 /* Tell the HC to release its resources. */ 243 if (ops )241 if (ops->device_gone) 244 242 ops->device_gone(dev); 245 243 246 244 /* Check whether the driver didn't forgot EP0 */ 247 245 if (dev->endpoints[0]) { 248 if ( ep_ops)249 ep_ops->endpoint_unregister(dev->endpoints[0]);246 if (ops->endpoint_unregister) 247 ops->endpoint_unregister(dev->endpoints[0]); 250 248 /* Release the EP0 bus reference */ 251 249 endpoint_del_ref(dev->endpoints[0]); … … 271 269 272 270 /* First, tell the HC driver. */ 273 const bus_ops_t *ops = BUS_OPS_LOOKUP(dev->bus->ops, device_online);274 if (ops && (rc = ops->device_online(dev))) {271 const bus_ops_t *ops = dev->bus->ops; 272 if (ops->device_online && (rc = ops->device_online(dev))) { 275 273 usb_log_warning("Host controller failed to make device '%s' online: %s", 276 274 ddf_fun_get_name(dev->fun), str_error(rc)); … … 329 327 330 328 /* Tell also the HC driver. */ 331 const bus_ops_t *ops = BUS_OPS_LOOKUP(dev->bus->ops, device_offline);332 if (ops )329 const bus_ops_t *ops = dev->bus->ops; 330 if (ops->device_offline) 333 331 ops->device_offline(dev); 334 332 … … 365 363 bus_t *bus = device->bus; 366 364 367 const bus_ops_t *register_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_register); 368 if (!register_ops) 365 if (!bus->ops->endpoint_register) 369 366 return ENOTSUP; 370 367 371 const bus_ops_t *create_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_create);372 368 endpoint_t *ep; 373 if ( create_ops) {374 ep = create_ops->endpoint_create(device, desc);369 if (bus->ops->endpoint_create) { 370 ep = bus->ops->endpoint_create(device, desc); 375 371 if (!ep) 376 372 return ENOMEM; … … 410 406 err = EEXIST; 411 407 } else { 412 err = register_ops->endpoint_register(ep);408 err = bus->ops->endpoint_register(ep); 413 409 if (!err) 414 410 device->endpoints[idx] = ep; … … 480 476 bus_t *bus = device->bus; 481 477 482 const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, endpoint_unregister); 483 if (!ops) 478 if (!bus->ops->endpoint_unregister) 484 479 return ENOTSUP; 485 480 … … 496 491 497 492 fibril_mutex_lock(&device->guard); 498 ops->endpoint_unregister(ep);493 bus->ops->endpoint_unregister(ep); 499 494 device->endpoints[idx] = NULL; 500 495 fibril_mutex_unlock(&device->guard); -
uspace/lib/usbhost/src/endpoint.c
rd369b3b r296d22fc 97 97 static inline void endpoint_destroy(endpoint_t *ep) 98 98 { 99 const bus_ops_t *ops = BUS_OPS_LOOKUP(get_bus_ops(ep), endpoint_destroy);100 if (ops ) {99 const bus_ops_t *ops = get_bus_ops(ep); 100 if (ops->endpoint_destroy) { 101 101 ops->endpoint_destroy(ep); 102 102 } else { … … 237 237 } 238 238 239 const bus_ops_t *ops = BUS_OPS_LOOKUP(device->bus->ops, batch_schedule);240 if (!ops ) {239 const bus_ops_t *ops = device->bus->ops; 240 if (!ops->batch_schedule) { 241 241 usb_log_error("HCD does not implement scheduler."); 242 242 return ENOTSUP; -
uspace/lib/usbhost/src/hcd.c
rd369b3b r296d22fc 100 100 hc_device_t *hcd = dev_to_hcd(dev); 101 101 102 const bus_ops_t *ops = BUS_OPS_LOOKUP(hcd->bus->ops, interrupt);103 assert(ops);104 105 102 const uint32_t status = IPC_GET_ARG1(*call); 106 ops->interrupt(hcd->bus, status);103 hcd->bus->ops->interrupt(hcd->bus, status); 107 104 } 108 105 … … 115 112 assert(bus); 116 113 117 const bus_ops_t *interrupt_ops = BUS_OPS_LOOKUP(bus->ops, interrupt); 118 const bus_ops_t *status_ops = BUS_OPS_LOOKUP(bus->ops, status); 119 if (!interrupt_ops || !status_ops) 114 if (!bus->ops->interrupt || !bus->ops->status) 120 115 return ENOTSUP; 121 116 122 117 uint32_t status = 0; 123 while ( status_ops->status(bus, &status) == EOK) {124 interrupt_ops->interrupt(bus, status);118 while (bus->ops->status(bus, &status) == EOK) { 119 bus->ops->interrupt(bus, status); 125 120 status = 0; 126 121 /* We should wait 1 frame - 1ms here, but this polling is a … … 265 260 } 266 261 267 const bus_ops_t *ops = BUS_OPS_LOOKUP(hcd->bus->ops, status);262 const bus_ops_t *ops = hcd->bus->ops; 268 263 269 264 /* Need working irq replacement to setup root hub */ 270 if (hcd->irq_cap < 0 && ops ) {265 if (hcd->irq_cap < 0 && ops->status) { 271 266 hcd->polling_fibril = fibril_create(interrupt_polling, hcd->bus); 272 267 if (!hcd->polling_fibril) { -
uspace/lib/usbhost/src/usb_transfer_batch.c
rd369b3b r296d22fc 54 54 55 55 bus_t *bus = endpoint_get_bus(ep); 56 const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, batch_create);57 56 58 if (! ops) {57 if (!bus->ops->batch_create) { 59 58 usb_transfer_batch_t *batch = calloc(1, sizeof(usb_transfer_batch_t)); 60 59 if (!batch) … … 64 63 } 65 64 66 return ops->batch_create(ep);65 return bus->ops->batch_create(ep); 67 66 } 68 67 … … 87 86 88 87 bus_t *bus = endpoint_get_bus(batch->ep); 89 const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, batch_destroy);88 endpoint_t *ep = batch->ep; 90 89 91 /* Batch reference */ 92 endpoint_del_ref(batch->ep); 93 94 if (ops) { 90 if (bus->ops) { 95 91 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " destroying.", 96 92 batch, USB_TRANSFER_BATCH_ARGS(*batch)); 97 ops->batch_destroy(batch);93 bus->ops->batch_destroy(batch); 98 94 } 99 95 else { … … 102 98 free(batch); 103 99 } 100 101 /* Batch reference */ 102 endpoint_del_ref(ep); 104 103 } 105 104
Note:
See TracChangeset
for help on using the changeset viewer.