Changeset d2bff2f in mainline
- Timestamp:
- 2011-05-07T15:41:47Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 76ef94e
- Parents:
- dc5f2fb
- Location:
- uspace/drv
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/ohci.c
rdc5f2fb rd2bff2f 109 109 ddf_fun_t *fun, devman_handle_t *handle) 110 110 { 111 assert(handle);112 111 assert(fun); 113 112 ddf_fun_t *hc_fun = dev_to_ohci(fun->dev)->hc_fun; 114 113 assert(hc_fun); 115 114 116 *handle = hc_fun->handle; 115 if (handle != NULL) 116 *handle = hc_fun->handle; 117 117 return EOK; 118 118 } … … 170 170 } else (void)0 171 171 172 instance->rh_fun = NULL; 172 173 instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc"); 173 174 int ret = instance->hc_fun ? EOK : ENOMEM; -
uspace/drv/uhci-hcd/hc.c
rdc5f2fb rd2bff2f 60 60 * 61 61 * @param[in] instance Memory place to initialize. 62 * @param[in] fun DDF function.63 62 * @param[in] regs Address of I/O control registers. 64 63 * @param[in] size Size of I/O control registers. … … 69 68 * interrupt fibrils. 70 69 */ 71 int hc_init(hc_t *instance, ddf_fun_t *fun, 72 void *regs, size_t reg_size, bool interrupts) 70 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts) 73 71 { 74 72 assert(reg_size >= sizeof(regs_t)); -
uspace/drv/uhci-hcd/hc.h
rdc5f2fb rd2bff2f 136 136 } hc_t; 137 137 138 int hc_init(hc_t *instance, ddf_fun_t *fun, 139 void *regs, size_t reg_size, bool interupts); 138 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts); 140 139 141 140 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch); -
uspace/drv/uhci-hcd/main.c
rdc5f2fb rd2bff2f 64 64 assert(device); 65 65 66 uhci_t *uhci = malloc(sizeof(uhci_t)); 67 if (uhci == NULL) { 68 usb_log_error("Failed to allocate UHCI driver.\n"); 69 return ENOMEM; 70 } 71 72 int ret = uhci_init(uhci, device); 66 int ret = device_setup_uhci(device); 73 67 if (ret != EOK) { 74 68 usb_log_error("Failed to initialize UHCI driver: %s.\n", … … 76 70 return ret; 77 71 } 78 device->driver_data = uhci;79 80 72 usb_log_info("Controlling new UHCI device '%s'.\n", device->name); 81 73 -
uspace/drv/uhci-hcd/uhci.c
rdc5f2fb rd2bff2f 44 44 #include "pci.h" 45 45 46 #include "hc.h" 47 #include "root_hub.h" 48 49 /** Structure representing both functions of UHCI hc, USB host controller 50 * and USB root hub */ 51 typedef struct uhci { 52 /** Pointer to DDF represenation of UHCI host controller */ 53 ddf_fun_t *hc_fun; 54 /** Pointer to DDF represenation of UHCI root hub */ 55 ddf_fun_t *rh_fun; 56 57 /** Internal driver's represenation of UHCI host controller */ 58 hc_t hc; 59 /** Internal driver's represenation of UHCI root hub */ 60 rh_t rh; 61 } uhci_t; 62 63 static inline uhci_t * dev_to_uhci(ddf_dev_t *dev) 64 { 65 assert(dev); 66 assert(dev->driver_data); 67 return dev->driver_data; 68 } 69 /*----------------------------------------------------------------------------*/ 46 70 /** IRQ handling callback, forward status from call to diver structure. 47 71 * … … 69 93 { 70 94 assert(fun); 71 usb_device_keeper_t *manager = 72 &((uhci_t*)fun->dev->driver_data)->hc.manager; 73 95 usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.manager; 74 96 usb_address_t addr = usb_device_keeper_find(manager, handle); 97 75 98 if (addr < 0) { 76 99 return addr; … … 93 116 ddf_fun_t *fun, devman_handle_t *handle) 94 117 { 95 assert(handle); 96 ddf_fun_t *hc_fun = ((uhci_t*)fun->dev->driver_data)->hc_fun; 97 assert(hc_fun != NULL); 98 99 *handle = hc_fun->handle; 118 assert(fun); 119 ddf_fun_t *hc_fun = dev_to_uhci(fun->dev)->hc_fun; 120 assert(hc_fun); 121 122 if (handle != NULL) 123 *handle = hc_fun->handle; 100 124 return EOK; 101 125 } … … 126 150 static hw_res_ops_t hw_res_iface = { 127 151 .get_resource_list = get_resource_list, 128 .enable_interrupt = NULL 152 .enable_interrupt = NULL, 129 153 }; 130 154 /*----------------------------------------------------------------------------*/ … … 146 170 * - registers interrupt handler 147 171 */ 148 int uhci_init(uhci_t *instance, ddf_dev_t *device) 149 { 150 assert(instance); 151 instance->hc_fun = NULL; 172 int device_setup_uhci(ddf_dev_t *device) 173 { 174 assert(device); 175 uhci_t *instance = malloc(sizeof(uhci_t)); 176 if (instance == NULL) { 177 usb_log_error("Failed to allocate OHCI driver.\n"); 178 return ENOMEM; 179 } 180 181 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \ 182 if (ret != EOK) { \ 183 if (instance->hc_fun) \ 184 instance->hc_fun->ops = NULL; \ 185 instance->hc_fun->driver_data = NULL; \ 186 ddf_fun_destroy(instance->hc_fun); \ 187 if (instance->rh_fun) {\ 188 instance->rh_fun->ops = NULL; \ 189 instance->rh_fun->driver_data = NULL; \ 190 ddf_fun_destroy(instance->rh_fun); \ 191 } \ 192 free(instance); \ 193 usb_log_error(message); \ 194 return ret; \ 195 } else (void)0 196 152 197 instance->rh_fun = NULL; 153 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \ 154 if (ret != EOK) { \ 155 usb_log_error(message); \ 156 if (instance->hc_fun) \ 157 ddf_fun_destroy(instance->hc_fun); \ 158 if (instance->rh_fun) \ 159 ddf_fun_destroy(instance->rh_fun); \ 160 return ret; \ 161 } 162 163 uintptr_t io_reg_base = 0; 164 size_t io_reg_size = 0; 198 instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc"); 199 int ret = (instance->hc_fun == NULL) ? ENOMEM : EOK; 200 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n"); 201 instance->hc_fun->ops = &hc_ops; 202 instance->hc_fun->driver_data = &instance->hc; 203 204 instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh"); 205 ret = (instance->rh_fun == NULL) ? ENOMEM : EOK; 206 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI RH function.\n"); 207 instance->rh_fun->ops = &rh_ops; 208 instance->rh_fun->driver_data = &instance->rh; 209 210 uintptr_t reg_base = 0; 211 size_t reg_size = 0; 165 212 int irq = 0; 166 213 167 int ret = 168 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 169 CHECK_RET_DEST_FUN_RETURN(ret, 214 ret = pci_get_my_registers(device, ®_base, ®_size, &irq); 215 CHECK_RET_DEST_FREE_RETURN(ret, 170 216 "Failed to get I/O addresses for %" PRIun ": %s.\n", 171 217 device->handle, str_error(ret)); 172 218 usb_log_debug("I/O regs at 0x%p (size %zu), IRQ %d.\n", 173 (void *) io_reg_base, io_reg_size, irq);219 (void *) reg_base, reg_size, irq); 174 220 175 221 ret = pci_disable_legacy(device); 176 CHECK_RET_DEST_F UN_RETURN(ret,222 CHECK_RET_DEST_FREE_RETURN(ret, 177 223 "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret)); 178 224 … … 194 240 #endif 195 241 196 instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc"); 197 ret = (instance->hc_fun == NULL) ? ENOMEM : EOK; 198 CHECK_RET_DEST_FUN_RETURN(ret, 199 "Failed(%d) to create HC function: %s.\n", ret, str_error(ret)); 200 201 ret = hc_init(&instance->hc, instance->hc_fun, 202 (void*)io_reg_base, io_reg_size, interrupts); 203 CHECK_RET_DEST_FUN_RETURN(ret, 242 243 ret = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts); 244 CHECK_RET_DEST_FREE_RETURN(ret, 204 245 "Failed(%d) to init uhci-hcd: %s.\n", ret, str_error(ret)); 205 206 instance->hc_fun->ops = &hc_ops;207 instance->hc_fun->driver_data = &instance->hc;208 ret = ddf_fun_bind(instance->hc_fun);209 CHECK_RET_DEST_FUN_RETURN(ret,210 "Failed(%d) to bind UHCI device function: %s.\n",211 ret, str_error(ret));212 #undef CHECK_RET_HC_RETURN213 246 214 247 #define CHECK_RET_FINI_RETURN(ret, message...) \ 215 248 if (ret != EOK) { \ 216 usb_log_error(message); \217 if (instance->hc_fun) \218 ddf_fun_destroy(instance->hc_fun); \219 if (instance->rh_fun) \220 ddf_fun_destroy(instance->rh_fun); \221 249 hc_fini(&instance->hc); \ 250 CHECK_RET_DEST_FREE_RETURN(ret, message); \ 222 251 return ret; \ 223 } 252 } else (void)0 224 253 225 254 /* It does no harm if we register this on polling */ … … 230 259 ret, str_error(ret)); 231 260 232 instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh"); 233 ret = (instance->rh_fun == NULL) ? ENOMEM : EOK; 234 CHECK_RET_FINI_RETURN(ret, 235 "Failed(%d) to create root hub function: %s.\n", 261 ret = ddf_fun_bind(instance->hc_fun); 262 CHECK_RET_FINI_RETURN(ret, 263 "Failed(%d) to bind UHCI device function: %s.\n", 236 264 ret, str_error(ret)); 237 265 … … 241 269 "Failed(%d) to setup UHCI root hub: %s.\n", ret, str_error(ret)); 242 270 243 instance->rh_fun->ops = &rh_ops;244 instance->rh_fun->driver_data = &instance->rh;245 271 ret = ddf_fun_bind(instance->rh_fun); 246 272 CHECK_RET_FINI_RETURN(ret, 247 273 "Failed(%d) to register UHCI root hub: %s.\n", ret, str_error(ret)); 248 274 275 device->driver_data = instance; 249 276 return EOK; 250 277 #undef CHECK_RET_FINI_RETURN -
uspace/drv/uhci-hcd/uhci.h
rdc5f2fb rd2bff2f 38 38 #include <ddf/driver.h> 39 39 40 #include "hc.h" 41 #include "root_hub.h" 42 43 /** Structure representing both functions of UHCI hc, USB host controller 44 * and USB root hub */ 45 typedef struct uhci { 46 /** Pointer to DDF represenation of UHCI host controller */ 47 ddf_fun_t *hc_fun; 48 /** Pointer to DDF represenation of UHCI root hub */ 49 ddf_fun_t *rh_fun; 50 51 /** Internal driver's represenation of UHCI host controller */ 52 hc_t hc; 53 /** Internal driver's represenation of UHCI root hub */ 54 rh_t rh; 55 } uhci_t; 56 57 int uhci_init(uhci_t *instance, ddf_dev_t *device); 40 int device_setup_uhci(ddf_dev_t *device); 58 41 #endif 59 42 /**
Note:
See TracChangeset
for help on using the changeset viewer.