Changes in uspace/drv/uhci-hcd/main.c [e0df6c2:fb78ae72] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/main.c
re0df6c2 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 60 /*----------------------------------------------------------------------------*/ 57 61 static usb_iface_t hc_usb_iface = { 58 62 .get_hc_handle = usb_iface_get_hc_handle 59 63 }; 60 64 /*----------------------------------------------------------------------------*/ 61 65 static device_ops_t uhci_ops = { 62 66 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 63 67 .interfaces[USBHC_DEV_IFACE] = &uhci_iface 64 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 } 65 93 66 94 static int uhci_add_device(device_t *device) … … 75 103 int irq; 76 104 77 int r c = pci_get_my_registers(device,78 &io_reg_base, &io_reg_size, &irq);105 int ret = 106 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 79 107 80 if (rc != EOK) { 81 usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n", 82 rc, device->handle); 83 return rc; 84 } 85 108 CHECK_RET_RETURN(ret, 109 "Failed(%d) to get I/O addresses:.\n", ret, device->handle); 86 110 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n", 87 111 io_reg_base, io_reg_size, irq); 88 112 113 ret = pci_enable_interrupts(device); 114 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 115 89 116 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); 90 if (!uhci_hc) { 91 usb_log_error("Failed to allocaete memory for uhci hcd driver.\n"); 92 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; 93 125 } 94 126 95 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); 96 129 if (ret != EOK) { 97 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); 98 133 return ret; 99 134 } 135 100 136 device_t *rh; 101 137 ret = setup_root_hub(&rh, device); 102 103 138 if (ret != EOK) { 104 139 usb_log_error("Failed to setup uhci root hub.\n"); 105 /* TODO: destroy uhci here */ 140 uhci_fini(uhci_hc); 141 free(uhci_hc); 106 142 return ret; 107 143 } … … 110 146 if (ret != EOK) { 111 147 usb_log_error("Failed to register root hub.\n"); 112 /* TODO: destroy uhci here */ 148 uhci_fini(uhci_hc); 149 free(uhci_hc); 150 free(rh); 113 151 return ret; 114 152 } 115 153 116 154 device->driver_data = uhci_hc; 117 118 155 return EOK; 119 156 } 120 121 static driver_ops_t uhci_driver_ops = { 122 .add_device = uhci_add_device, 123 }; 124 125 static driver_t uhci_driver = { 126 .name = NAME, 127 .driver_ops = &uhci_driver_ops 128 }; 129 157 /*----------------------------------------------------------------------------*/ 130 158 int main(int argc, char *argv[]) 131 159 { 132 /* 133 * Do some global initializations. 134 */ 135 sleep(5); 136 usb_log_enable(USB_LOG_LEVEL_INFO, NAME); 160 sleep(3); 161 usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME); 137 162 138 163 return driver_main(&uhci_driver);
Note:
See TracChangeset
for help on using the changeset viewer.