Changes in uspace/drv/uhci-rhd/main.c [fbefd0e:f9c03b5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-rhd/main.c
rfbefd0e rf9c03b5 44 44 45 45 #define NAME "uhci-rhd" 46 46 47 static int hc_get_my_registers(ddf_dev_t *dev, 47 48 uintptr_t *io_reg_address, size_t *io_reg_size); 48 #if 049 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 } 50 static int uhci_rh_add_device(ddf_dev_t *device); 113 51 /*----------------------------------------------------------------------------*/ 114 52 static driver_ops_t uhci_rh_driver_ops = { … … 132 70 { 133 71 printf(NAME ": HelenOS UHCI root hub driver.\n"); 72 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 73 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; 134 85 135 usb_log_ enable(USB_LOG_LEVEL_DEFAULT, NAME);86 usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle); 136 87 137 return ddf_driver_main(&uhci_rh_driver); 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)0 100 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; 138 120 } 139 121 /*----------------------------------------------------------------------------*/ … … 156 138 } 157 139 158 int rc;159 160 140 hw_resource_list_t hw_resources; 161 rc = hw_res_get_resource_list(parent_phone, &hw_resources); 162 if (rc != EOK) { 163 goto leave; 141 int ret = hw_res_get_resource_list(parent_phone, &hw_resources); 142 if (ret != EOK) { 143 async_hangup(parent_phone); 144 return ret; 164 145 } 165 146 … … 168 149 bool io_found = false; 169 150 170 size_t i ;171 for ( i = 0; i < hw_resources.count; i++) {151 size_t i = 0; 152 for (; i < hw_resources.count; i++) { 172 153 hw_resource_t *res = &hw_resources.resources[i]; 173 switch (res->type) 174 { 175 case IO_RANGE: 176 io_address = (uintptr_t) res->res.io_range.address; 154 if (res->type == IO_RANGE) { 155 io_address = res->res.io_range.address; 177 156 io_size = res->res.io_range.size; 178 157 io_found = true; 179 180 default:181 break;182 158 } 183 159 } 160 async_hangup(parent_phone); 184 161 185 162 if (!io_found) { 186 rc = ENOENT; 187 goto leave; 163 return ENOENT; 188 164 } 189 190 165 if (io_reg_address != NULL) { 191 166 *io_reg_address = io_address; … … 194 169 *io_reg_size = io_size; 195 170 } 196 rc = EOK; 197 198 leave: 199 async_hangup(parent_phone); 200 return rc; 171 return EOK; 201 172 } 202 173 /**
Note:
See TracChangeset
for help on using the changeset viewer.