Changes in uspace/drv/uhci-hcd/main.c [357a302:fb78ae72] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/main.c
r357a302 rfb78ae72 34 34 #include <driver.h> 35 35 #include <usb_iface.h> 36 #include <device/hw_res.h> 36 37 37 38 #include <errno.h> … … 46 47 #define NAME "uhci-hcd" 47 48 49 static int uhci_add_device(device_t *device); 50 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle); 51 /*----------------------------------------------------------------------------*/ 48 52 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle) 49 53 { … … 54 58 return EOK; 55 59 } 56 57 static int usb_iface_get_address(device_t *dev, devman_handle_t handle, 58 usb_address_t *address) 59 { 60 assert(dev); 61 uhci_t *hc = dev_to_uhci(dev); 62 assert(hc); 63 64 usb_address_t addr = usb_address_keeping_find(&hc->address_manager, 65 handle); 66 if (addr < 0) { 67 return addr; 68 } 69 70 if (address != NULL) { 71 *address = addr; 72 } 73 74 return EOK; 75 } 76 60 /*----------------------------------------------------------------------------*/ 77 61 static usb_iface_t hc_usb_iface = { 78 .get_hc_handle = usb_iface_get_hc_handle, 79 .get_address = usb_iface_get_address 62 .get_hc_handle = usb_iface_get_hc_handle 80 63 }; 81 64 /*----------------------------------------------------------------------------*/ 82 65 static device_ops_t uhci_ops = { 83 66 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 84 67 .interfaces[USBHC_DEV_IFACE] = &uhci_iface 85 68 }; 69 /*----------------------------------------------------------------------------*/ 70 static driver_ops_t uhci_driver_ops = { 71 .add_device = uhci_add_device, 72 }; 73 /*----------------------------------------------------------------------------*/ 74 static driver_t uhci_driver = { 75 .name = NAME, 76 .driver_ops = &uhci_driver_ops 77 }; 78 /*----------------------------------------------------------------------------*/ 79 static void irq_handler(device_t *device, ipc_callid_t iid, ipc_call_t *call) 80 { 81 assert(device); 82 uhci_t *hc = dev_to_uhci(device); 83 uint16_t status = IPC_GET_ARG1(*call); 84 assert(hc); 85 uhci_interrupt(hc, status); 86 } 87 /*----------------------------------------------------------------------------*/ 88 #define CHECK_RET_RETURN(ret, message...) \ 89 if (ret != EOK) { \ 90 usb_log_error(message); \ 91 return ret; \ 92 } 86 93 87 94 static int uhci_add_device(device_t *device) … … 96 103 int irq; 97 104 98 int r c = pci_get_my_registers(device,99 &io_reg_base, &io_reg_size, &irq);105 int ret = 106 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 100 107 101 if (rc != EOK) { 102 usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n", 103 rc, device->handle); 104 return rc; 105 } 106 108 CHECK_RET_RETURN(ret, 109 "Failed(%d) to get I/O addresses:.\n", ret, device->handle); 107 110 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n", 108 111 io_reg_base, io_reg_size, irq); 109 112 113 ret = pci_enable_interrupts(device); 114 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 115 110 116 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); 111 if (!uhci_hc) { 112 usb_log_error("Failed to allocaete memory for uhci hcd driver.\n"); 113 return ENOMEM; 117 ret = (uhci_hc != NULL) ? EOK : ENOMEM; 118 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n"); 119 120 ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size); 121 if (ret != EOK) { 122 usb_log_error("Failed to init uhci-hcd.\n"); 123 free(uhci_hc); 124 return ret; 114 125 } 115 126 116 int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size); 127 ret = register_interrupt_handler(device, irq, irq_handler, 128 &uhci_hc->interrupt_code); 117 129 if (ret != EOK) { 118 usb_log_error("Failed to init uhci-hcd.\n"); 130 usb_log_error("Failed to register interrupt handler.\n"); 131 uhci_fini(uhci_hc); 132 free(uhci_hc); 119 133 return ret; 120 134 } 135 121 136 device_t *rh; 122 137 ret = setup_root_hub(&rh, device); 123 124 138 if (ret != EOK) { 125 139 usb_log_error("Failed to setup uhci root hub.\n"); 126 /* TODO: destroy uhci here */ 140 uhci_fini(uhci_hc); 141 free(uhci_hc); 127 142 return ret; 128 143 } … … 131 146 if (ret != EOK) { 132 147 usb_log_error("Failed to register root hub.\n"); 133 /* TODO: destroy uhci here */ 148 uhci_fini(uhci_hc); 149 free(uhci_hc); 150 free(rh); 134 151 return ret; 135 152 } 136 153 137 154 device->driver_data = uhci_hc; 138 139 155 return EOK; 140 156 } 141 142 static driver_ops_t uhci_driver_ops = { 143 .add_device = uhci_add_device, 144 }; 145 146 static driver_t uhci_driver = { 147 .name = NAME, 148 .driver_ops = &uhci_driver_ops 149 }; 150 157 /*----------------------------------------------------------------------------*/ 151 158 int main(int argc, char *argv[]) 152 159 { 153 /* 154 * Do some global initializations. 155 */ 156 sleep(5); 157 usb_log_enable(USB_LOG_LEVEL_INFO, NAME); 160 sleep(3); 161 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 158 162 159 163 return driver_main(&uhci_driver);
Note:
See TracChangeset
for help on using the changeset viewer.