Changes in uspace/drv/uhci-rhd/main.c [f9c03b5:fbefd0e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-rhd/main.c
rf9c03b5 rfbefd0e 44 44 45 45 #define NAME "uhci-rhd" 46 47 46 static int hc_get_my_registers(ddf_dev_t *dev, 48 47 uintptr_t *io_reg_address, size_t *io_reg_size); 49 /*----------------------------------------------------------------------------*/ 50 static int uhci_rh_add_device(ddf_dev_t *device); 48 #if 0 49 /*----------------------------------------------------------------------------*/ 50 static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle) 51 { 52 assert(fun); 53 assert(fun->driver_data); 54 assert(handle); 55 56 *handle = ((uhci_root_hub_t*)fun->driver_data)->hc_handle; 57 58 return EOK; 59 } 60 /*----------------------------------------------------------------------------*/ 61 static usb_iface_t uhci_rh_usb_iface = { 62 .get_hc_handle = usb_iface_get_hc_handle, 63 .get_address = usb_iface_get_address_hub_impl 64 }; 65 /*----------------------------------------------------------------------------*/ 66 static ddf_dev_ops_t uhci_rh_ops = { 67 .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface, 68 }; 69 #endif 70 /*----------------------------------------------------------------------------*/ 71 /** Initialize a new ddf driver instance of UHCI root hub. 72 * 73 * @param[in] device DDF instance of the device to initialize. 74 * @return Error code. 75 */ 76 static int uhci_rh_add_device(ddf_dev_t *device) 77 { 78 if (!device) 79 return ENOTSUP; 80 81 usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle); 82 83 //device->ops = &uhci_rh_ops; 84 uintptr_t io_regs = 0; 85 size_t io_size = 0; 86 87 int ret = hc_get_my_registers(device, &io_regs, &io_size); 88 if (ret != EOK) { 89 usb_log_error("Failed to get registers from parent HC: %s.\n", 90 str_error(ret)); 91 } 92 usb_log_debug("I/O regs at %#X (size %zu).\n", io_regs, io_size); 93 94 uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t)); 95 if (!rh) { 96 usb_log_error("Failed to allocate driver instance.\n"); 97 return ENOMEM; 98 } 99 100 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device); 101 if (ret != EOK) { 102 usb_log_error("Failed to initialize driver instance: %s.\n", 103 str_error(ret)); 104 free(rh); 105 return ret; 106 } 107 108 device->driver_data = rh; 109 usb_log_info("Controlling root hub `%s' (%llu).\n", 110 device->name, device->handle); 111 return EOK; 112 } 51 113 /*----------------------------------------------------------------------------*/ 52 114 static driver_ops_t uhci_rh_driver_ops = { … … 70 132 { 71 133 printf(NAME ": HelenOS UHCI root hub driver.\n"); 134 72 135 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 136 73 137 return ddf_driver_main(&uhci_rh_driver); 74 }75 /*----------------------------------------------------------------------------*/76 /** Initialize a new ddf driver instance of UHCI root hub.77 *78 * @param[in] device DDF instance of the device to initialize.79 * @return Error code.80 */81 static int uhci_rh_add_device(ddf_dev_t *device)82 {83 if (!device)84 return EINVAL;85 86 usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle);87 88 uintptr_t io_regs = 0;89 size_t io_size = 0;90 uhci_root_hub_t *rh = NULL;91 int ret = EOK;92 93 #define CHECK_RET_FREE_RH_RETURN(ret, message...) \94 if (ret != EOK) { \95 usb_log_error(message); \96 if (rh) \97 free(rh); \98 return ret; \99 } else (void)0100 101 ret = hc_get_my_registers(device, &io_regs, &io_size);102 CHECK_RET_FREE_RH_RETURN(ret,103 "Failed(%d) to get registers from HC: %s.\n", ret, str_error(ret));104 usb_log_debug("I/O regs at %#x (size %zu).\n", io_regs, io_size);105 106 rh = malloc(sizeof(uhci_root_hub_t));107 ret = (rh == NULL) ? ENOMEM : EOK;108 CHECK_RET_FREE_RH_RETURN(ret,109 "Failed to allocate rh driver instance.\n");110 111 ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);112 CHECK_RET_FREE_RH_RETURN(ret,113 "Failed(%d) to initialize rh driver instance: %s.\n",114 ret, str_error(ret));115 116 device->driver_data = rh;117 usb_log_info("Controlling root hub '%s' (%llu).\n",118 device->name, device->handle);119 return EOK;120 138 } 121 139 /*----------------------------------------------------------------------------*/ … … 138 156 } 139 157 158 int rc; 159 140 160 hw_resource_list_t hw_resources; 141 int ret = hw_res_get_resource_list(parent_phone, &hw_resources); 142 if (ret != EOK) { 143 async_hangup(parent_phone); 144 return ret; 161 rc = hw_res_get_resource_list(parent_phone, &hw_resources); 162 if (rc != EOK) { 163 goto leave; 145 164 } 146 165 … … 149 168 bool io_found = false; 150 169 151 size_t i = 0;152 for ( ; i < hw_resources.count; i++) {170 size_t i; 171 for (i = 0; i < hw_resources.count; i++) { 153 172 hw_resource_t *res = &hw_resources.resources[i]; 154 if (res->type == IO_RANGE) { 155 io_address = res->res.io_range.address; 173 switch (res->type) 174 { 175 case IO_RANGE: 176 io_address = (uintptr_t) res->res.io_range.address; 156 177 io_size = res->res.io_range.size; 157 178 io_found = true; 179 180 default: 181 break; 158 182 } 159 183 } 160 async_hangup(parent_phone);161 184 162 185 if (!io_found) { 163 return ENOENT; 164 } 186 rc = ENOENT; 187 goto leave; 188 } 189 165 190 if (io_reg_address != NULL) { 166 191 *io_reg_address = io_address; … … 169 194 *io_reg_size = io_size; 170 195 } 171 return EOK; 196 rc = EOK; 197 198 leave: 199 async_hangup(parent_phone); 200 return rc; 172 201 } 173 202 /**
Note:
See TracChangeset
for help on using the changeset viewer.