Changeset dc5f2fb in mainline
- Timestamp:
- 2011-05-07T15:22:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d2bff2f
- Parents:
- 62265ce
- Location:
- uspace/drv/ohci
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/main.c
r62265ce rdc5f2fb 43 43 #define NAME "ohci" 44 44 45 static int ohci_add_device(ddf_dev_t *device); 45 /** Initializes a new ddf driver instance of OHCI hcd. 46 * 47 * @param[in] device DDF instance of the device to initialize. 48 * @return Error code. 49 */ 50 static int ohci_add_device(ddf_dev_t *device) 51 { 52 usb_log_debug("ohci_add_device() called\n"); 53 assert(device); 54 55 int ret = device_setup_ohci(device); 56 if (ret != EOK) { 57 usb_log_error("Failed to initialize OHCI driver: %s.\n", 58 str_error(ret)); 59 return ret; 60 } 61 usb_log_info("Controlling new OHCI device '%s'.\n", device->name); 62 63 return EOK; 64 } 46 65 /*----------------------------------------------------------------------------*/ 47 66 static driver_ops_t ohci_driver_ops = { … … 53 72 .driver_ops = &ohci_driver_ops 54 73 }; 55 /*----------------------------------------------------------------------------*/56 /** Initializes a new ddf driver instance of OHCI hcd.57 *58 * @param[in] device DDF instance of the device to initialize.59 * @return Error code.60 */61 int ohci_add_device(ddf_dev_t *device)62 {63 usb_log_debug("ohci_add_device() called\n");64 assert(device);65 ohci_t *ohci = malloc(sizeof(ohci_t));66 if (ohci == NULL) {67 usb_log_error("Failed to allocate OHCI driver.\n");68 return ENOMEM;69 }70 71 int ret = device_setup_ohci(device, ohci);72 if (ret != EOK) {73 usb_log_error("Failed to initialize OHCI driver: %s.\n",74 str_error(ret));75 return ret;76 }77 // device->driver_data = ohci;78 hc_register_hub(&ohci->hc, ohci->rh_fun);79 80 usb_log_info("Controlling new OHCI device `%s'.\n", device->name);81 82 return EOK;83 }84 74 /*----------------------------------------------------------------------------*/ 85 75 /** Initializes global driver structures (NONE). -
uspace/drv/ohci/ohci.c
r62265ce rdc5f2fb 44 44 #include "iface.h" 45 45 #include "pci.h" 46 #include "hc.h" 47 #include "root_hub.h" 48 49 typedef struct ohci { 50 ddf_fun_t *hc_fun; 51 ddf_fun_t *rh_fun; 52 53 hc_t hc; 54 rh_t rh; 55 } ohci_t; 56 57 static inline ohci_t * dev_to_ohci(ddf_dev_t *dev) 58 { 59 assert(dev); 60 assert(dev->driver_data); 61 return dev->driver_data; 62 } 46 63 47 64 /** IRQ handling callback, identifies device … … 53 70 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call) 54 71 { 55 assert(dev); 56 assert(dev->driver_data); 57 hc_t *hc = &((ohci_t*)dev->driver_data)->hc; 58 uint16_t status = IPC_GET_ARG1(*call); 72 hc_t *hc = &dev_to_ohci(dev)->hc; 59 73 assert(hc); 74 const uint16_t status = IPC_GET_ARG1(*call); 60 75 hc_interrupt(hc, status); 61 76 } … … 71 86 { 72 87 assert(fun); 73 usb_device_keeper_t *manager = & ((ohci_t*)fun->dev->driver_data)->hc.manager;88 usb_device_keeper_t *manager = &dev_to_ohci(fun->dev)->hc.manager; 74 89 75 90 usb_address_t addr = usb_device_keeper_find(manager, handle); … … 95 110 { 96 111 assert(handle); 97 ddf_fun_t *hc_fun = ((ohci_t*)fun->dev->driver_data)->hc_fun; 98 assert(hc_fun != NULL); 112 assert(fun); 113 ddf_fun_t *hc_fun = dev_to_ohci(fun->dev)->hc_fun; 114 assert(hc_fun); 99 115 100 116 *handle = hc_fun->handle; … … 102 118 } 103 119 /*----------------------------------------------------------------------------*/ 104 /** This iface is generic for both RH and HC.*/120 /** Root hub USB interface */ 105 121 static usb_iface_t usb_iface = { 106 122 .get_hc_handle = usb_iface_get_hc_handle, … … 108 124 }; 109 125 /*----------------------------------------------------------------------------*/ 126 /** Standard USB HC options (HC interface) */ 110 127 static ddf_dev_ops_t hc_ops = { 111 128 .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */ 112 129 }; 113 130 /*----------------------------------------------------------------------------*/ 131 /** Standard USB RH options (RH interface) */ 114 132 static ddf_dev_ops_t rh_ops = { 115 133 .interfaces[USB_DEV_IFACE] = &usb_iface, … … 118 136 /** Initialize hc and rh ddf structures and their respective drivers. 119 137 * 138 * @param[in] device DDF instance of the device to use. 120 139 * @param[in] instance OHCI structure to use. 121 * @param[in] device DDF instance of the device to use.122 140 * 123 141 * This function does all the preparatory work for hc and rh drivers: … … 127 145 * - registers interrupt handler 128 146 */ 129 int device_setup_ohci(ddf_dev_t *device, ohci_t *instance) 130 { 131 assert(instance); 147 int device_setup_ohci(ddf_dev_t *device) 148 { 149 ohci_t *instance = malloc(sizeof(ohci_t)); 150 if (instance == NULL) { 151 usb_log_error("Failed to allocate OHCI driver.\n"); 152 return ENOMEM; 153 } 154 155 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \ 156 if (ret != EOK) { \ 157 if (instance->hc_fun) { \ 158 instance->hc_fun->ops = NULL; \ 159 instance->hc_fun->driver_data = NULL; \ 160 ddf_fun_destroy(instance->hc_fun); \ 161 } \ 162 if (instance->rh_fun) { \ 163 instance->rh_fun->ops = NULL; \ 164 instance->rh_fun->driver_data = NULL; \ 165 ddf_fun_destroy(instance->rh_fun); \ 166 } \ 167 free(instance); \ 168 usb_log_error(message); \ 169 return ret; \ 170 } else (void)0 132 171 133 172 instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc"); 134 if (instance->hc_fun == NULL) { 135 usb_log_error("Failed to create HC function.\n"); 136 return ENOMEM; 137 } 173 int ret = instance->hc_fun ? EOK : ENOMEM; 174 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create OHCI HC function.\n"); 138 175 instance->hc_fun->ops = &hc_ops; 139 176 instance->hc_fun->driver_data = &instance->hc; 140 177 141 178 instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh"); 142 if (instance->rh_fun == NULL) { 143 ddf_fun_destroy(instance->hc_fun); 144 usb_log_error("Failed to create RH function.\n"); 145 return ENOMEM; 146 } 179 ret = instance->rh_fun ? EOK : ENOMEM; 180 CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create OHCI RH function.\n"); 147 181 instance->rh_fun->ops = &rh_ops; 148 instance->rh_fun->driver_data = NULL; 149 150 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \ 151 if (ret != EOK) { \ 152 usb_log_error(message); \ 153 instance->hc_fun->ops = NULL; \ 154 instance->hc_fun->driver_data = NULL; \ 155 instance->rh_fun->ops = NULL; \ 156 instance->rh_fun->driver_data = NULL; \ 157 ddf_fun_destroy(instance->hc_fun); \ 158 ddf_fun_destroy(instance->rh_fun); \ 159 return ret; \ 160 } 161 162 uintptr_t mem_reg_base = 0; 163 size_t mem_reg_size = 0; 182 183 uintptr_t reg_base = 0; 184 size_t reg_size = 0; 164 185 int irq = 0; 165 186 166 int ret = 167 pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq); 168 CHECK_RET_DEST_FUN_RETURN(ret, 187 ret = pci_get_my_registers(device, ®_base, ®_size, &irq); 188 CHECK_RET_DEST_FREE_RETURN(ret, 169 189 "Failed to get memory addresses for %" PRIun ": %s.\n", 170 190 device->handle, str_error(ret)); 171 191 usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n", 172 (void *) mem_reg_base, mem_reg_size, irq);192 (void *) reg_base, reg_size, irq); 173 193 174 194 bool interrupts = false; … … 189 209 #endif 190 210 191 ret = hc_init(&instance->hc, mem_reg_base, mem_reg_size, interrupts);192 CHECK_RET_DEST_F UN_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret);211 ret = hc_init(&instance->hc, reg_base, reg_size, interrupts); 212 CHECK_RET_DEST_FREE_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret); 193 213 194 214 #define CHECK_RET_FINI_RETURN(ret, message...) \ 195 215 if (ret != EOK) { \ 196 216 hc_fini(&instance->hc); \ 197 CHECK_RET_DEST_F UN_RETURN(ret, message); \198 } 217 CHECK_RET_DEST_FREE_RETURN(ret, message); \ 218 } else (void)0 199 219 200 220 /* It does no harm if we register this on polling */ … … 212 232 213 233 hc_start_hw(&instance->hc); 234 hc_register_hub(&instance->hc, instance->rh_fun); 214 235 return EOK; 215 236 -
uspace/drv/ohci/ohci.h
r62265ce rdc5f2fb 38 38 #include <ddf/driver.h> 39 39 40 #include "hc.h" 41 #include "root_hub.h" 42 43 typedef struct ohci { 44 ddf_fun_t *hc_fun; 45 ddf_fun_t *rh_fun; 46 47 hc_t hc; 48 rh_t rh; 49 } ohci_t; 50 51 int device_setup_ohci(ddf_dev_t *device, ohci_t *instance); 40 int device_setup_ohci(ddf_dev_t *device); 52 41 53 42 #endif -
uspace/drv/ohci/pci.c
r62265ce rdc5f2fb 58 58 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no) 59 59 { 60 assert(dev != NULL); 60 assert(dev); 61 assert(mem_reg_address); 62 assert(mem_reg_size); 63 assert(irq_no); 61 64 62 65 int parent_phone = devman_parent_device_connect(dev->handle,
Note:
See TracChangeset
for help on using the changeset viewer.