Changeset b5f813c in mainline
- Timestamp:
- 2015-07-04T03:28:02Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 55346870
- Parents:
- 2dbfe44
- Location:
- uspace
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_endpoint.c
r2dbfe44 rb5f813c 80 80 { 81 81 assert(ep); 82 hc_t *hc = hcd_get_driver_data(hcd); 83 82 84 ehci_endpoint_t *ehci_ep = malloc(sizeof(ehci_endpoint_t)); 83 85 if (ehci_ep == NULL) … … 95 97 endpoint_set_hc_data( 96 98 ep, ehci_ep, ehci_ep_toggle_get, ehci_ep_toggle_set); 97 hc_enqueue_endpoint(hc d->driver.data, ep);99 hc_enqueue_endpoint(hc, ep); 98 100 return EOK; 99 101 } … … 108 110 assert(hcd); 109 111 assert(ep); 112 hc_t *hc = hcd_get_driver_data(hcd); 113 110 114 ehci_endpoint_t *instance = ehci_endpoint_get(ep); 111 hc_dequeue_endpoint(hc d->driver.data, ep);115 hc_dequeue_endpoint(hc, ep); 112 116 endpoint_clear_hc_data(ep); 113 117 usb_log_debug2("EP(%p): Destroying for %p", instance, ep); -
uspace/drv/bus/usb/ehci/hc.c
r2dbfe44 rb5f813c 273 273 { 274 274 assert(hcd); 275 hc_t *instance = hcd ->driver.data;275 hc_t *instance = hcd_get_driver_data(hcd); 276 276 assert(instance); 277 277 assert(status); … … 294 294 { 295 295 assert(hcd); 296 hc_t *instance = hcd ->driver.data;296 hc_t *instance = hcd_get_driver_data(hcd); 297 297 assert(instance); 298 298 … … 325 325 { 326 326 assert(hcd); 327 hc_t *instance = hcd ->driver.data;327 hc_t *instance = hcd_get_driver_data(hcd); 328 328 status = EHCI_RD(status); 329 329 assert(instance); -
uspace/drv/bus/usb/ehci/main.c
r2dbfe44 rb5f813c 50 50 #define NAME "ehci" 51 51 52 static int ehci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool); 53 static void ehci_driver_fini(hcd_t *); 54 55 static const ddf_hc_driver_t ehci_hc_driver = { 56 .claim = disable_legacy, 57 .hc_speed = USB_SPEED_HIGH, 58 .irq_code_gen = ehci_hc_gen_irq_code, 59 .init = ehci_driver_init, 60 .fini = ehci_driver_fini, 61 .name = "EHCI-PCI", 62 .ops = { 63 .schedule = ehci_hc_schedule, 64 .ep_add_hook = ehci_endpoint_init, 65 .ep_remove_hook = ehci_endpoint_fini, 66 .irq_hook = ehci_hc_interrupt, 67 .status_hook = ehci_hc_status, 68 } 69 }; 70 71 52 72 static int ehci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq) 53 73 { 54 74 assert(hcd); 55 assert(hcd ->driver.data== NULL);75 assert(hcd_get_driver_data(hcd) == NULL); 56 76 57 77 hc_t *instance = malloc(sizeof(hc_t)); … … 61 81 const int ret = hc_init(instance, res, irq); 62 82 if (ret == EOK) 63 hcd_set_implementation(hcd, instance, ehci_hc_schedule, 64 ehci_endpoint_init, ehci_endpoint_fini, ehci_hc_interrupt, 65 ehci_hc_status); 83 hcd_set_implementation(hcd, instance, &ehci_hc_driver.ops); 66 84 return ret; 67 85 } … … 70 88 { 71 89 assert(hcd); 72 if (hcd->driver.data) 73 hc_fini(hcd->driver.data); 90 hc_t *hc = hcd_get_driver_data(hcd); 91 if (hc) 92 hc_fini(hc); 74 93 75 free(hc d->driver.data);76 hcd_set_implementation(hcd, NULL, NULL , NULL, NULL, NULL, NULL);94 free(hc); 95 hcd_set_implementation(hcd, NULL, NULL); 77 96 } 78 79 static int ehci_dev_add(ddf_dev_t *device);80 81 static const driver_ops_t ehci_driver_ops = {82 .dev_add = ehci_dev_add,83 };84 85 static const driver_t ehci_driver = {86 .name = NAME,87 .driver_ops = &ehci_driver_ops88 };89 90 91 static const ddf_hc_driver_t ehci_hc_driver = {92 .claim = disable_legacy,93 .hc_speed = USB_SPEED_HIGH,94 .irq_code_gen = ehci_hc_gen_irq_code,95 .init = ehci_driver_init,96 .fini = ehci_driver_fini,97 .name = "EHCI-PCI"98 };99 97 100 98 /** Initializes a new ddf driver instance of EHCI hcd. … … 111 109 112 110 } 111 112 113 static const driver_ops_t ehci_driver_ops = { 114 .dev_add = ehci_dev_add, 115 }; 116 117 static const driver_t ehci_driver = { 118 .name = NAME, 119 .driver_ops = &ehci_driver_ops 120 }; 121 113 122 114 123 /** Initializes global driver structures (NONE). -
uspace/drv/bus/usb/ohci/hc.c
r2dbfe44 rb5f813c 271 271 assert(hcd); 272 272 assert(status); 273 hc_t *instance = hcd ->driver.data;273 hc_t *instance = hcd_get_driver_data(hcd); 274 274 assert(instance); 275 275 … … 290 290 { 291 291 assert(hcd); 292 hc_t *instance = hcd ->driver.data;292 hc_t *instance = hcd_get_driver_data(hcd); 293 293 assert(instance); 294 294 … … 330 330 { 331 331 assert(hcd); 332 hc_t *instance = hcd ->driver.data;332 hc_t *instance = hcd_get_driver_data(hcd); 333 333 status = OHCI_RD(status); 334 334 assert(instance); -
uspace/drv/bus/usb/ohci/main.c
r2dbfe44 rb5f813c 46 46 47 47 #define NAME "ohci" 48 static int ohci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool); 49 static void ohci_driver_fini(hcd_t *); 50 51 static const ddf_hc_driver_t ohci_hc_driver = { 52 .hc_speed = USB_SPEED_FULL, 53 .irq_code_gen = ohci_hc_gen_irq_code, 54 .init = ohci_driver_init, 55 .fini = ohci_driver_fini, 56 .name = "OHCI", 57 .ops = { 58 .schedule = ohci_hc_schedule, 59 .ep_add_hook = ohci_endpoint_init, 60 .ep_remove_hook = ohci_endpoint_fini, 61 .irq_hook = ohci_hc_interrupt, 62 .status_hook = ohci_hc_status, 63 }, 64 }; 65 48 66 49 67 static int ohci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq) 50 68 { 51 69 assert(hcd); 52 assert(hcd ->driver.data== NULL);70 assert(hcd_get_driver_data(hcd) == NULL); 53 71 54 72 hc_t *instance = malloc(sizeof(hc_t)); … … 58 76 const int ret = hc_init(instance, res, irq); 59 77 if (ret == EOK) 60 hcd_set_implementation(hcd, instance, ohci_hc_schedule, 61 ohci_endpoint_init, ohci_endpoint_fini, ohci_hc_interrupt, 62 ohci_hc_status); 78 hcd_set_implementation(hcd, instance, &ohci_hc_driver.ops); 63 79 return ret; 64 80 } … … 67 83 { 68 84 assert(hcd); 69 if (hcd->driver.data) 70 hc_fini(hcd->driver.data); 85 hc_t *hc = hcd_get_driver_data(hcd); 86 if (hc) 87 hc_fini(hc); 71 88 72 free(hcd->driver.data);73 hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);89 hcd_set_implementation(hcd, NULL, NULL); 90 free(hc); 74 91 } 75 76 static const ddf_hc_driver_t ohci_hc_driver = {77 .hc_speed = USB_SPEED_FULL,78 .irq_code_gen = ohci_hc_gen_irq_code,79 .init = ohci_driver_init,80 .fini = ohci_driver_fini,81 .name = "OHCI"82 };83 92 84 93 /** Initializes a new ddf driver instance of OHCI hcd. -
uspace/drv/bus/usb/ohci/ohci_endpoint.c
r2dbfe44 rb5f813c 95 95 endpoint_set_hc_data( 96 96 ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set); 97 hc_enqueue_endpoint(hcd ->driver.data, ep);97 hc_enqueue_endpoint(hcd_get_driver_data(hcd), ep); 98 98 return EOK; 99 99 } … … 109 109 assert(ep); 110 110 ohci_endpoint_t *instance = ohci_endpoint_get(ep); 111 hc_dequeue_endpoint(hcd->driver.data, ep); 111 hc_dequeue_endpoint(hcd_get_driver_data(hcd), ep); 112 endpoint_clear_hc_data(ep); 112 113 if (instance) { 113 114 free32(instance->ed); … … 115 116 free(instance); 116 117 } 117 endpoint_clear_hc_data(ep);118 118 } 119 119 /** -
uspace/drv/bus/usb/uhci/hc.c
r2dbfe44 rb5f813c 157 157 { 158 158 assert(hcd); 159 hc_t *instance = hcd ->driver.data;159 hc_t *instance = hcd_get_driver_data(hcd); 160 160 assert(instance); 161 161 /* Lower 2 bits are transaction error and transaction complete */ … … 412 412 assert(hcd); 413 413 assert(status); 414 hc_t *instance = hcd ->driver.data;414 hc_t *instance = hcd_get_driver_data(hcd); 415 415 assert(instance); 416 416 … … 435 435 { 436 436 assert(hcd); 437 hc_t *instance = hcd ->driver.data;437 hc_t *instance = hcd_get_driver_data(hcd); 438 438 assert(instance); 439 439 assert(batch); -
uspace/drv/bus/usb/uhci/main.c
r2dbfe44 rb5f813c 48 48 #define NAME "uhci" 49 49 50 static int uhci_driver_init(hcd_t *, const hw_res_list_parsed_t *, bool); 51 static void uhci_driver_fini(hcd_t *); 52 static int disable_legacy(ddf_dev_t *); 53 54 static const ddf_hc_driver_t uhci_hc_driver = { 55 .claim = disable_legacy, 56 .hc_speed = USB_SPEED_FULL, 57 .irq_code_gen = uhci_hc_gen_irq_code, 58 .init = uhci_driver_init, 59 .fini = uhci_driver_fini, 60 .name = "UHCI", 61 .ops = { 62 .schedule = uhci_hc_schedule, 63 .irq_hook = uhci_hc_interrupt, 64 .status_hook = uhci_hc_status, 65 }, 66 }; 67 50 68 static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq) 51 69 { 52 70 assert(hcd); 53 assert(hcd ->driver.data== NULL);71 assert(hcd_get_driver_data(hcd) == NULL); 54 72 55 73 hc_t *instance = malloc(sizeof(hc_t)); … … 59 77 const int ret = hc_init(instance, res, irq); 60 78 if (ret == EOK) 61 hcd_set_implementation(hcd, instance, uhci_hc_schedule, NULL, 62 NULL, uhci_hc_interrupt, uhci_hc_status); 79 hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops); 63 80 return ret; 64 81 } … … 67 84 { 68 85 assert(hcd); 69 if (hcd->driver.data) 70 hc_fini(hcd->driver.data); 86 hc_t *hc = hcd_get_driver_data(hcd); 87 if (hc) 88 hc_fini(hc); 71 89 72 free(hcd->driver.data);73 hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);90 hcd_set_implementation(hcd, NULL, NULL); 91 free(hc); 74 92 } 75 76 static int uhci_dev_add(ddf_dev_t *device);77 78 static const driver_ops_t uhci_driver_ops = {79 .dev_add = uhci_dev_add,80 };81 82 static const driver_t uhci_driver = {83 .name = NAME,84 .driver_ops = &uhci_driver_ops85 };86 93 87 94 /** Call the PCI driver with a request to clear legacy support register … … 106 113 return rc; 107 114 } 108 static const ddf_hc_driver_t uhci_hc_driver = {109 .claim = disable_legacy,110 .hc_speed = USB_SPEED_FULL,111 .irq_code_gen = uhci_hc_gen_irq_code,112 .init = uhci_driver_init,113 .fini = uhci_driver_fini,114 .name = "UHCI"115 };116 117 115 118 116 /** Initialize a new ddf driver instance for uhci hc and hub. … … 121 119 * @return Error code. 122 120 */ 123 int uhci_dev_add(ddf_dev_t *device)121 static int uhci_dev_add(ddf_dev_t *device) 124 122 { 125 123 usb_log_debug2("uhci_dev_add() called\n"); … … 127 125 return hcd_ddf_add_hc(device, &uhci_hc_driver); 128 126 } 127 128 static const driver_ops_t uhci_driver_ops = { 129 .dev_add = uhci_dev_add, 130 }; 131 132 static const driver_t uhci_driver = { 133 .name = NAME, 134 .driver_ops = &uhci_driver_ops 135 }; 136 129 137 130 138 /** Initialize global driver structures (NONE). -
uspace/drv/bus/usb/vhc/main.c
r2dbfe44 rb5f813c 74 74 } 75 75 76 hcd_ops_t vhc_hc_ops = { 77 .schedule = vhc_schedule, 78 }; 79 76 80 static int vhc_dev_add(ddf_dev_t *dev) 77 81 { … … 95 99 } 96 100 97 hcd_set_implementation(dev_to_hcd(dev), data, vhc_schedule, NULL, NULL, NULL, NULL);101 hcd_set_implementation(dev_to_hcd(dev), data, &vhc_hc_ops); 98 102 99 103 /* Add virtual hub device */ -
uspace/drv/bus/usb/vhc/transfer.c
r2dbfe44 rb5f813c 167 167 assert(hcd); 168 168 assert(batch); 169 vhc_data_t *vhc = hcd ->driver.data;169 vhc_data_t *vhc = hcd_get_driver_data(hcd); 170 170 assert(vhc); 171 171 -
uspace/lib/usbhost/include/usb/host/ddf_helpers.h
r2dbfe44 rb5f813c 51 51 52 52 typedef struct { 53 hc _driver_t ops;53 hcd_ops_t ops; 54 54 claim_t claim; 55 55 usb_speed_t hc_speed; -
uspace/lib/usbhost/include/usb/host/hcd.h
r2dbfe44 rb5f813c 55 55 56 56 typedef struct { 57 /** Device specific driver data. */58 void *data;59 57 /** Transfer scheduling, implement in device driver. */ 60 58 schedule_hook_t schedule; … … 67 65 /** Periodic polling hook */ 68 66 status_hook_t status_hook; 69 } hc _driver_t;67 } hcd_ops_t; 70 68 71 69 /** Generic host controller driver structure. */ … … 74 72 usb_bus_t bus; 75 73 76 /** Driver implementation */77 hc_driver_t driver;78 79 74 /** Interrupt replacement fibril */ 80 75 fid_t polling_fibril; 76 77 /** Driver implementation */ 78 hcd_ops_t ops; 79 /** Device specific driver data. */ 80 void * driver_data; 81 81 }; 82 82 … … 85 85 86 86 static inline void hcd_set_implementation(hcd_t *hcd, void *data, 87 schedule_hook_t schedule, ep_add_hook_t add_hook, ep_remove_hook_t rem_hook, 88 interrupt_hook_t irq_hook, status_hook_t status_hook) 87 const hcd_ops_t *ops) 89 88 { 90 89 assert(hcd); 91 hcd->driver.data = data; 92 hcd->driver.schedule = schedule; 93 hcd->driver.ep_add_hook = add_hook; 94 hcd->driver.ep_remove_hook = rem_hook; 95 hcd->driver.irq_hook = irq_hook; 96 hcd->driver.status_hook = status_hook; 90 if (ops) { 91 hcd->driver_data = data; 92 hcd->ops = *ops; 93 } else { 94 memset(&hcd->ops, 0, sizeof(hcd->ops)); 95 } 96 } 97 98 static inline void * hcd_get_driver_data(hcd_t *hcd) 99 { 100 assert(hcd); 101 return hcd->driver_data; 97 102 } 98 103 -
uspace/lib/usbhost/src/ddf_helpers.c
r2dbfe44 rb5f813c 690 690 } 691 691 692 //TODO: Move this to generic ddf? 692 693 int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res) 693 694 { … … 779 780 assert(dev); 780 781 hcd_t *hcd = dev_to_hcd(dev); 781 if (!hcd || !hcd-> driver.irq_hook) {782 if (!hcd || !hcd->ops.irq_hook) { 782 783 usb_log_error("Interrupt on not yet initialized device.\n"); 783 784 return; 784 785 } 785 786 const uint32_t status = IPC_GET_ARG1(*call); 786 hcd-> driver.irq_hook(hcd, status);787 hcd->ops.irq_hook(hcd, status); 787 788 } 788 789 … … 791 792 hcd_t *hcd = arg; 792 793 assert(hcd); 793 if (!hcd-> driver.status_hook || !hcd->driver.irq_hook)794 if (!hcd->ops.status_hook || !hcd->ops.irq_hook) 794 795 return ENOTSUP; 795 796 uint32_t status = 0; 796 while (hcd-> driver.status_hook(hcd, &status) == EOK) {797 hcd-> driver.irq_hook(hcd, status);797 while (hcd->ops.status_hook(hcd, &status) == EOK) { 798 hcd->ops.irq_hook(hcd, status); 798 799 status = 0; 799 800 /* We should wait 1 frame - 1ms here, but this polling is a … … 885 886 886 887 /* Need working irq replacement to setup root hub */ 887 if ((irq < 0) && hcd-> driver.status_hook) {888 if ((irq < 0) && hcd->ops.status_hook) { 888 889 hcd->polling_fibril = fibril_create(interrupt_polling, hcd); 889 890 if (hcd->polling_fibril == 0) { -
uspace/lib/usbhost/src/hcd.c
r2dbfe44 rb5f813c 54 54 assert(ep); 55 55 assert(hcd); 56 if (hcd-> driver.ep_add_hook)57 return hcd-> driver.ep_add_hook(hcd, ep);56 if (hcd->ops.ep_add_hook) 57 return hcd->ops.ep_add_hook(hcd, ep); 58 58 return EOK; 59 59 } … … 68 68 assert(ep); 69 69 assert(hcd); 70 if (hcd-> driver.ep_remove_hook)71 hcd-> driver.ep_remove_hook(hcd, ep);70 if (hcd->ops.ep_remove_hook) 71 hcd->ops.ep_remove_hook(hcd, ep); 72 72 } 73 73 … … 99 99 usb_bus_init(&hcd->bus, bandwidth, bw_count, max_speed); 100 100 101 hcd->driver.data = NULL; 102 hcd->driver.schedule = NULL; 103 hcd->driver.ep_add_hook = NULL; 104 hcd->driver.ep_remove_hook = NULL; 101 hcd_set_implementation(hcd, NULL, NULL); 105 102 } 106 103 … … 127 124 assert(hcd); 128 125 usb_address_t address = 0; 129 return usb_bus_request_address( 130 &hcd->bus, &address, true, speed); 126 return usb_bus_request_address(&hcd->bus, &address, true, speed); 131 127 } 132 128 … … 209 205 return ENOSPC; 210 206 } 211 if (!hcd-> driver.schedule) {207 if (!hcd->ops.schedule) { 212 208 usb_log_error("HCD does not implement scheduler.\n"); 213 209 return ENOTSUP; … … 241 237 } 242 238 243 const int ret = hcd-> driver.schedule(hcd, batch);239 const int ret = hcd->ops.schedule(hcd, batch); 244 240 if (ret != EOK) 245 241 usb_transfer_batch_destroy(batch);
Note:
See TracChangeset
for help on using the changeset viewer.