Changeset 62ba2cbe in mainline for uspace/drv/bus/usb/xhci/hc.c
- Timestamp:
- 2017-06-16T01:25:16Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cb89430
- Parents:
- ce6e001
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/hc.c
rce6e001 r62ba2cbe 36 36 #include <errno.h> 37 37 #include <usb/debug.h> 38 #include <usb/host/ddf_helpers.h> 38 39 #include "debug.h" 39 40 #include "hc.h" 40 41 41 int xhci_hc_gen_irq_code(irq_code_t *code, const hw_res_list_parsed_t *hw_res) 42 const ddf_hc_driver_t xhci_ddf_hc_driver = { 43 .hc_speed = USB_SPEED_SUPER, 44 .init = xhci_hc_init, 45 .fini = xhci_hc_fini, 46 .name = "XHCI-PCI", 47 .ops = { 48 .schedule = xhci_hc_schedule, 49 .irq_hook = xhci_hc_interrupt, 50 .status_hook = xhci_hc_status, 51 } 52 }; 53 54 int xhci_hc_init(hcd_t *hcd, const hw_res_list_parsed_t *hw_res, bool irq) 42 55 { 43 assert(code); 44 assert(hw_res); 56 int err; 45 57 46 usb_log_debug("Gen IRQ code, got %zu IRQs, %zu DMA chs, %zu mem rngs, %zu IO rngs", 47 hw_res->irqs.count, 48 hw_res->dma_channels.count, 49 hw_res->mem_ranges.count, 50 hw_res->io_ranges.count); 51 52 if (hw_res->irqs.count != 1 53 || hw_res->dma_channels.count != 0 54 || hw_res->mem_ranges.count != 1 55 || hw_res->io_ranges.count != 0) { 56 usb_log_debug("Unexpected HW resources, bailing out."); 58 assert(hcd); 59 assert(hcd_get_driver_data(hcd) == NULL); 60 61 if (hw_res->mem_ranges.count != 1) { 62 usb_log_debug("Unexpected MMIO area, bailing out."); 57 63 return EINVAL; 58 64 } 59 65 66 xhci_hc_t *hc = malloc(sizeof(xhci_hc_t)); 67 if (!hc) 68 return ENOMEM; 69 60 70 addr_range_t mmio_range = hw_res->mem_ranges.ranges[0]; 61 71 62 usb_log_debug("M emory mapped regsat %p (size %zu), IRQ %d.\n",72 usb_log_debug("MMIO area at %p (size %zu), IRQ %d.\n", 63 73 RNGABSPTR(mmio_range), RNGSZ(mmio_range), hw_res->irqs.irqs[0]); 64 74 65 xhci_cap_regs_t *cap_regs = NULL; 66 int ret = pio_enable_range(&mmio_range, (void **)&cap_regs); 67 if (ret != EOK) 68 return ret; 75 if ((err = pio_enable_range(&mmio_range, (void **)&hc->cap_regs))) 76 goto err_hc; 69 77 70 xhci_dump_cap_regs( cap_regs);78 xhci_dump_cap_regs(hc->cap_regs); 71 79 72 /* 73 * XHCI uses an Interrupter mechanism. Possibly, we want to set it up here. 74 */ 75 code->rangecount = 0; 76 code->ranges = NULL; 77 code->cmdcount = 0; 78 code->cmds = NULL; 80 uintptr_t base = (uintptr_t) hc->cap_regs; 81 82 hc->op_regs = (xhci_op_regs_t *) (base + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_LENGTH)); 83 hc->rt_regs = (xhci_rt_regs_t *) (base + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_RTSOFF)); 84 hc->db_arry = (xhci_doorbell_t *) (base + XHCI_REG_RD(hc->cap_regs, XHCI_CAP_DBOFF)); 85 86 usb_log_debug("Initialized MMIO reg areas:"); 87 usb_log_debug("\tCapability regs: %p", hc->cap_regs); 88 usb_log_debug("\tOperational regs: %p", hc->op_regs); 89 usb_log_debug("\tRuntime regs: %p", hc->rt_regs); 90 usb_log_debug("\tDoorbell array base: %p", hc->db_arry); 91 92 xhci_dump_state(hc); 93 94 hcd_set_implementation(hcd, hc, &xhci_ddf_hc_driver.ops); 95 96 // TODO: check if everything fits into the mmio_area 79 97 80 98 return EOK; 99 100 err_hc: 101 free(hc); 102 return err; 81 103 } 82 104 … … 98 120 } 99 121 122 void xhci_hc_fini(hcd_t *hcd) 123 { 124 assert(hcd); 125 usb_log_info("Finishing"); 126 127 xhci_hc_t *hc = hcd_get_driver_data(hcd); 128 free(hc); 129 hcd_set_implementation(hcd, NULL, NULL); 130 } 131 100 132 101 133 /**
Note:
See TracChangeset
for help on using the changeset viewer.