Changeset 86341e2 in mainline
- Timestamp:
- 2011-02-28T17:11:27Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d79a101f
- Parents:
- dced52a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/main.c
rdced52a r86341e2 70 70 } 71 71 /*----------------------------------------------------------------------------*/ 72 #define CHECK_RET_RETURN(ret, message...) \73 if (ret != EOK) { \74 usb_log_error(message); \75 return ret; \76 }77 78 72 static int uhci_add_device(ddf_dev_t *device) 79 73 { 80 74 assert(device); 75 uhci_t *hcd = NULL; 76 #define CHECK_RET_FREE_HC_RETURN(ret, message...) \ 77 if (ret != EOK) { \ 78 usb_log_error(message); \ 79 if (hcd != NULL) \ 80 free(hcd); \ 81 return ret; \ 82 } 81 83 82 84 usb_log_info("uhci_add_device() called\n"); … … 88 90 int ret = 89 91 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 90 91 CHECK_RET_RETURN(ret, 92 CHECK_RET_FREE_HC_RETURN(ret, 92 93 "Failed(%d) to get I/O addresses:.\n", ret, device->handle); 93 94 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n", … … 95 96 96 97 // ret = pci_enable_interrupts(device); 97 // CHECK_RET_ RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);98 // CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 98 99 99 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); 100 ret = (uhci_hc != NULL) ? EOK : ENOMEM; 101 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n"); 100 hcd = malloc(sizeof(uhci_t)); 101 ret = (hcd != NULL) ? EOK : ENOMEM; 102 CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to allocate memory for uhci hcd.\n", 103 ret); 102 104 103 ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size); 104 if (ret != EOK) { 105 usb_log_error("Failed to init uhci-hcd.\n"); 106 free(uhci_hc); 107 return ret; 108 } 105 ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size); 106 CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", 107 ret); 108 #undef CHECK_RET_FREE_HC_RETURN 109 109 110 110 /* 111 * We might free uhci_hc, but that does not matter since no one111 * We might free hcd, but that does not matter since no one 112 112 * else would access driver_data anyway. 113 113 */ 114 device->driver_data = uhci_hc; 114 device->driver_data = hcd; 115 116 ddf_fun_t *rh = NULL; 117 #define CHECK_RET_FINI_FREE_RETURN(ret, message...) \ 118 if (ret != EOK) { \ 119 usb_log_error(message); \ 120 if (hcd != NULL) {\ 121 uhci_fini(hcd); \ 122 free(hcd); \ 123 } \ 124 if (rh != NULL) \ 125 free(rh); \ 126 return ret; \ 127 } 128 115 129 ret = register_interrupt_handler(device, irq, irq_handler, 116 &uhci_hc->interrupt_code); 117 if (ret != EOK) { 118 usb_log_error("Failed to register interrupt handler.\n"); 119 uhci_fini(uhci_hc); 120 free(uhci_hc); 121 return ret; 122 } 130 &hcd->interrupt_code); 131 CHECK_RET_FINI_FREE_RETURN(ret, "Failed(%d) to register interrupt handler.\n", 132 ret); 123 133 124 ddf_fun_t *rh;125 134 ret = setup_root_hub(&rh, device); 126 if (ret != EOK) { 127 usb_log_error("Failed to setup uhci root hub.\n"); 128 uhci_fini(uhci_hc); 129 free(uhci_hc); 130 return ret; 131 } 132 rh->driver_data = uhci_hc->ddf_instance; 135 CHECK_RET_FINI_FREE_RETURN(ret, "Failed(%d) to setup UHCI root hub.\n", 136 ret); 137 rh->driver_data = hcd->ddf_instance; 133 138 134 139 ret = ddf_fun_bind(rh); 135 if (ret != EOK) { 136 usb_log_error("Failed to register root hub.\n"); 137 uhci_fini(uhci_hc); 138 free(uhci_hc); 139 free(rh); 140 return ret; 141 } 140 CHECK_RET_FINI_FREE_RETURN(ret, "Failed(%d) to register UHCI root hub.\n", 141 ret); 142 142 143 143 return EOK; 144 #undef CHECK_RET_FINI_FREE_RETURN 144 145 } 145 146 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.