Changeset 32fb6bce in mainline for uspace/drv/bus/usb/xhci
- Timestamp:
- 2017-12-18T22:50:21Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f70d1c
- Parents:
- 1ea0bbf
- git-author:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
- git-committer:
- Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
r1ea0bbf r32fb6bce 111 111 112 112 uint16_t max_packet_size; 113 if ((err = hcd_get_ep0_max_packet_size(&max_packet_size, hc->hcd, &dev->base)))113 if ((err = hcd_get_ep0_max_packet_size(&max_packet_size, (bus_t *) &hc->bus, &dev->base))) 114 114 return err; 115 115 … … 168 168 169 169 /* Read the device descriptor, derive the match ids */ 170 if ((err = hcd_d df_device_explore(dev))) {170 if ((err = hcd_device_explore(dev))) { 171 171 usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err)); 172 172 goto err_address; … … 233 233 /* Destroy DDF device. */ 234 234 /* XXX: Not a good idea, this method should not destroy devices. */ 235 hcd_ddf_ device_destroy(dev);235 hcd_ddf_fun_destroy(dev); 236 236 237 237 return EOK; … … 501 501 BIND_OP(batch_destroy) 502 502 #undef BIND_OP 503 504 .interrupt = hc_interrupt, 505 .status = hc_status, 506 .batch_schedule = hc_schedule, 503 507 }; 504 508 … … 507 511 assert(bus); 508 512 509 bus_init(&bus->base, hc->hcd,sizeof(xhci_device_t));513 bus_init(&bus->base, sizeof(xhci_device_t)); 510 514 511 515 bus->devices_by_slot = calloc(hc->max_slots, sizeof(xhci_device_t *)); -
uspace/drv/bus/usb/xhci/hc.c
r1ea0bbf r32fb6bce 432 432 * Used only when polling. Shall supplement the irq_commands. 433 433 */ 434 int hc_status(xhci_hc_t *hc, uint32_t *status) 435 { 434 int hc_status(bus_t *bus, uint32_t *status) 435 { 436 xhci_hc_t *hc = bus_to_hc(bus); 436 437 int ip = XHCI_REG_RD(hc->rt_regs->ir, XHCI_INTR_IP); 437 438 if (ip) { … … 449 450 } 450 451 451 int hc_schedule( xhci_hc_t *hc,usb_transfer_batch_t *batch)452 int hc_schedule(usb_transfer_batch_t *batch) 452 453 { 453 454 assert(batch); 454 assert(batch->ep);455 xhci_hc_t *hc = bus_to_hc(endpoint_get_bus(batch->ep)); 455 456 456 457 if (!batch->target.address) { … … 532 533 } 533 534 534 void hc_interrupt(xhci_hc_t *hc, uint32_t status) 535 { 535 void hc_interrupt(bus_t *bus, uint32_t status) 536 { 537 xhci_hc_t *hc = bus_to_hc(bus); 536 538 status = xhci2host(32, status); 537 539 -
uspace/drv/bus/usb/xhci/hc.h
r1ea0bbf r32fb6bce 51 51 52 52 typedef struct xhci_hc { 53 /** Common HC device header */ 54 hc_device_t base; 55 53 56 /* MMIO range */ 54 57 addr_range_t mmio_range; … … 86 89 xhci_port_speed_t speeds [16]; 87 90 uint8_t speed_to_psiv [USB_SPEED_MAX]; 91 } xhci_hc_t; 88 92 89 /* TODO: Hack. Figure out a better way. */ 90 hcd_t *hcd; 91 } xhci_hc_t; 93 static inline xhci_hc_t *bus_to_hc(bus_t *bus) 94 { 95 assert(bus); 96 return member_to_inst(bus, xhci_hc_t, bus); 97 } 92 98 93 99 typedef struct xhci_endpoint xhci_endpoint_t; … … 99 105 int hc_irq_code_gen(irq_code_t *, xhci_hc_t *, const hw_res_list_parsed_t *); 100 106 int hc_start(xhci_hc_t *, bool); 101 int hc_schedule(xhci_hc_t *hc, usb_transfer_batch_t *batch);102 int hc_status(xhci_hc_t *, uint32_t *);103 void hc_interrupt(xhci_hc_t *, uint32_t);104 107 void hc_fini(xhci_hc_t *); 105 108 int hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned); … … 113 116 int hc_update_endpoint(xhci_hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *); 114 117 118 int hc_schedule(usb_transfer_batch_t *batch); 119 int hc_status(bus_t *, uint32_t *); 120 void hc_interrupt(bus_t *, uint32_t); 121 115 122 #endif 116 123 -
uspace/drv/bus/usb/xhci/main.c
r1ea0bbf r32fb6bce 47 47 #define NAME "xhci" 48 48 49 static int hc_driver_init(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *); 50 static int hcd_irq_code_gen(irq_code_t *, hcd_t *, const hw_res_list_parsed_t *); 51 static int hcd_claim(hcd_t *, ddf_dev_t *); 52 static int hcd_start(hcd_t *, bool); 53 static int hcd_status(hcd_t *, uint32_t *); 54 static void hcd_interrupt(hcd_t *, uint32_t); 55 static int hcd_schedule(hcd_t *, usb_transfer_batch_t *); 56 static void hc_driver_fini(hcd_t *); 49 static inline xhci_hc_t *hcd_to_hc(hc_device_t *hcd) 50 { 51 assert(hcd); 52 return (xhci_hc_t *) hcd; 53 } 57 54 58 static const ddf_hc_driver_t xhci_ddf_hc_driver = { 59 .name = "XHCI-PCI", 60 .init = hc_driver_init, 55 static int hcd_hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res) 56 { 57 int err; 58 xhci_hc_t *hc = hcd_to_hc(hcd); 59 hc_device_setup(hcd, (bus_t *) &hc->bus); 60 61 if ((err = hc_init_mmio(hc, hw_res))) 62 return err; 63 64 if ((err = hc_init_memory(hc, hcd->ddf_dev))) 65 return err; 66 67 return EOK; 68 } 69 70 static int hcd_irq_code_gen(irq_code_t *code, hc_device_t *hcd, const hw_res_list_parsed_t *hw_res) 71 { 72 xhci_hc_t *hc = hcd_to_hc(hcd); 73 return hc_irq_code_gen(code, hc, hw_res); 74 } 75 76 static int hcd_claim(hc_device_t *hcd) 77 { 78 xhci_hc_t *hc = hcd_to_hc(hcd); 79 return hc_claim(hc, hcd->ddf_dev); 80 } 81 82 static int hcd_start(hc_device_t *hcd) 83 { 84 xhci_hc_t *hc = hcd_to_hc(hcd); 85 return hc_start(hc, hcd->irq_cap >= 0); 86 } 87 88 static int hcd_hc_gone(hc_device_t *hcd) 89 { 90 xhci_hc_t *hc = hcd_to_hc(hcd); 91 hc_fini(hc); 92 return EOK; 93 } 94 95 static const hc_driver_t xhci_driver = { 96 .name = NAME, 97 .hc_device_size = sizeof(xhci_hc_t), 98 99 .hc_add = hcd_hc_add, 61 100 .irq_code_gen = hcd_irq_code_gen, 62 101 .claim = hcd_claim, 63 102 .start = hcd_start, 64 .setup_root_hub = NULL, 65 .fini = hc_driver_fini, 66 .ops = { 67 .schedule = hcd_schedule, 68 .irq_hook = hcd_interrupt, 69 .status_hook = hcd_status, 70 } 103 .hc_gone = hcd_hc_gone, 71 104 }; 72 73 static int hc_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *hw_res, ddf_dev_t *device)74 {75 int err;76 77 xhci_hc_t *hc = malloc(sizeof(xhci_hc_t));78 if (!hc)79 return ENOMEM;80 81 if ((err = hc_init_mmio(hc, hw_res)))82 goto err;83 84 hc->hcd = hcd;85 86 if ((err = hc_init_memory(hc, device)))87 goto err;88 89 hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops, &hc->bus.base);90 91 return EOK;92 err:93 free(hc);94 return err;95 }96 97 static int hcd_irq_code_gen(irq_code_t *code, hcd_t *hcd, const hw_res_list_parsed_t *hw_res)98 {99 xhci_hc_t *hc = hcd_get_driver_data(hcd);100 assert(hc);101 102 return hc_irq_code_gen(code, hc, hw_res);103 }104 105 static int hcd_claim(hcd_t *hcd, ddf_dev_t *dev)106 {107 xhci_hc_t *hc = hcd_get_driver_data(hcd);108 assert(hc);109 110 return hc_claim(hc, dev);111 }112 113 static int hcd_start(hcd_t *hcd, bool irq)114 {115 xhci_hc_t *hc = hcd_get_driver_data(hcd);116 assert(hc);117 118 return hc_start(hc, irq);119 }120 121 static int hcd_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)122 {123 xhci_hc_t *hc = hcd_get_driver_data(hcd);124 assert(hc);125 126 return hc_schedule(hc, batch);127 }128 129 static int hcd_status(hcd_t *hcd, uint32_t *status)130 {131 xhci_hc_t *hc = hcd_get_driver_data(hcd);132 assert(hc);133 assert(status);134 135 return hc_status(hc, status);136 }137 138 static void hcd_interrupt(hcd_t *hcd, uint32_t status)139 {140 xhci_hc_t *hc = hcd_get_driver_data(hcd);141 assert(hc);142 143 hc_interrupt(hc, status);144 }145 146 static void hc_driver_fini(hcd_t *hcd)147 {148 xhci_hc_t *hc = hcd_get_driver_data(hcd);149 assert(hc);150 151 hc_fini(hc);152 153 free(hc);154 }155 156 /** Initializes a new ddf driver instance of XHCI hcd.157 *158 * @param[in] device DDF instance of the device to initialize.159 * @return Error code.160 */161 static int xhci_dev_add(ddf_dev_t *device)162 {163 usb_log_info("Adding device %s", ddf_dev_get_name(device));164 return hcd_ddf_add_hc(device, &xhci_ddf_hc_driver);165 }166 167 static int xhci_fun_online(ddf_fun_t *fun)168 {169 return hcd_ddf_device_online(fun);170 }171 172 static int xhci_fun_offline(ddf_fun_t *fun)173 {174 return hcd_ddf_device_offline(fun);175 }176 177 178 static const driver_ops_t xhci_driver_ops = {179 .dev_add = xhci_dev_add,180 .fun_online = xhci_fun_online,181 .fun_offline = xhci_fun_offline182 };183 184 static const driver_t xhci_driver = {185 .name = NAME,186 .driver_ops = &xhci_driver_ops187 };188 189 105 190 106 /** Initializes global driver structures (NONE). … … 200 116 log_init(NAME); 201 117 logctl_set_log_level(NAME, LVL_DEBUG2); 202 return ddf_driver_main(&xhci_driver);118 return hc_driver_main(&xhci_driver); 203 119 } 204 120 -
uspace/drv/bus/usb/xhci/rh.c
r1ea0bbf r32fb6bce 94 94 xhci_bus_t *bus = &rh->hc->bus; 95 95 96 device_t *dev = hcd_ddf_ device_create(rh->hc_device, &bus->base);96 device_t *dev = hcd_ddf_fun_create(&rh->hc->base); 97 97 if (!dev) { 98 98 usb_log_error("Failed to create USB device function."); … … 132 132 133 133 err_usb_dev: 134 hcd_ddf_ device_destroy(dev);134 hcd_ddf_fun_destroy(dev); 135 135 return err; 136 136 }
Note:
See TracChangeset
for help on using the changeset viewer.
