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