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