Changeset 059d507 in mainline
- Timestamp:
- 2013-07-26T13:40:58Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2838486
- Parents:
- b0fc92c
- Location:
- uspace/lib/usbhost
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/include/usb/host/usb_device_manager.h
rb0fc92c r059d507 57 57 usb_speed_t speed; /**< Device speed */ 58 58 bool occupied; /**< The address is in use. */ 59 devman_handle_t handle; /**< Devman handle of the device. */60 59 } devices[USB_ADDRESS_COUNT]; 61 60 /** Maximum speed allowed. */ … … 73 72 usb_address_t *address, bool strict, usb_speed_t speed); 74 73 75 int usb_device_manager_bind_address(usb_device_manager_t *instance,76 usb_address_t address, devman_handle_t handle);77 78 74 int usb_device_manager_release_address(usb_device_manager_t *instance, 79 75 usb_address_t address); 80 76 81 usb_address_t usb_device_manager_find_address(usb_device_manager_t *instance,82 devman_handle_t handle);83 84 77 int usb_device_manager_get_info_by_address(usb_device_manager_t *instance, 85 usb_address_t address, devman_handle_t *handle,usb_speed_t *speed);78 usb_address_t address, usb_speed_t *speed); 86 79 #endif 87 80 /** -
uspace/lib/usbhost/src/ddf_helpers.c
rb0fc92c r059d507 301 301 return ret; 302 302 } 303 304 ret = usb_device_manager_bind_address(&dev_to_hcd(parent)->dev_manager,305 address, ddf_fun_get_handle(fun));306 if (ret != EOK)307 usb_log_warning("Failed to bind address: %s.\n",308 str_error(ret));309 303 310 304 list_append(&info->link, &hc_dev->devices); … … 408 402 /* This checks whether the default address is reserved and gets speed */ 409 403 int ret = usb_device_manager_get_info_by_address(&hcd->dev_manager, 410 USB_ADDRESS_DEFAULT, NULL,&speed);404 USB_ADDRESS_DEFAULT, &speed); 411 405 if (ret != EOK) { 412 406 return ret; -
uspace/lib/usbhost/src/hcd.c
rb0fc92c r059d507 138 138 usb_speed_t speed = USB_SPEED_MAX; 139 139 const int ret = usb_device_manager_get_info_by_address( 140 &hcd->dev_manager, target.address, NULL,&speed);140 &hcd->dev_manager, target.address, &speed); 141 141 if (ret != EOK) { 142 142 return ret; -
uspace/lib/usbhost/src/usb_device_manager.c
rb0fc92c r059d507 75 75 for (unsigned i = 0; i < USB_ADDRESS_COUNT; ++i) { 76 76 instance->devices[i].occupied = false; 77 instance->devices[i].handle = 0;78 77 instance->devices[i].speed = USB_SPEED_MAX; 79 78 } … … 115 114 } 116 115 assert(instance->devices[*address].occupied == false); 117 assert(instance->devices[*address].handle == 0);118 116 assert(*address != USB_ADDRESS_DEFAULT || strict); 119 117 … … 121 119 instance->devices[*address].speed = speed; 122 120 123 fibril_mutex_unlock(&instance->guard);124 return EOK;125 }126 127 /** Bind USB address to devman handle.128 *129 * @param[in] instance Device manager structure to use.130 * @param[in] address Device address131 * @param[in] handle Devman handle of the device.132 * @return Error code.133 * @note Won't accept binding for default address.134 */135 int usb_device_manager_bind_address(usb_device_manager_t *instance,136 usb_address_t address, devman_handle_t handle)137 {138 if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) {139 return EINVAL;140 }141 assert(instance);142 143 fibril_mutex_lock(&instance->guard);144 /* Not reserved */145 if (!instance->devices[address].occupied) {146 fibril_mutex_unlock(&instance->guard);147 return ENOENT;148 }149 /* Already bound */150 if (instance->devices[address].handle != 0) {151 fibril_mutex_unlock(&instance->guard);152 return EEXISTS;153 }154 instance->devices[address].handle = handle;155 121 fibril_mutex_unlock(&instance->guard); 156 122 return EOK; … … 178 144 179 145 instance->devices[address].occupied = false; 180 instance->devices[address].handle = 0;181 146 fibril_mutex_unlock(&instance->guard); 182 147 return EOK; 183 148 } 184 149 185 /** Find USB address associated with the device. 186 * 187 * @param[in] instance Device manager structure to use. 188 * @param[in] handle Devman handle of the device seeking its address. 189 * @return USB Address, or error code. 190 */ 191 usb_address_t usb_device_manager_find_address( 192 usb_device_manager_t *instance, devman_handle_t handle) 193 { 194 assert(instance); 195 fibril_mutex_lock(&instance->guard); 196 for (usb_address_t address = 1; address <= USB11_ADDRESS_MAX; ++address) 197 { 198 if (instance->devices[address].handle == handle) { 199 assert(instance->devices[address].occupied); 200 fibril_mutex_unlock(&instance->guard); 201 return address; 202 } 203 } 204 fibril_mutex_unlock(&instance->guard); 205 return ENOENT; 206 } 207 208 /** Find devman handle and speed assigned to USB address. 150 /** Get speed assigned to USB address. 209 151 * 210 152 * @param[in] instance Device manager structure to use. 211 153 * @param[in] address Address the caller wants to find. 212 * @param[out] handle Where to store found handle.213 154 * @param[out] speed Assigned speed. 214 155 * @return Error code. 215 156 */ 216 157 int usb_device_manager_get_info_by_address(usb_device_manager_t *instance, 217 usb_address_t address, devman_handle_t *handle,usb_speed_t *speed)158 usb_address_t address, usb_speed_t *speed) 218 159 { 219 160 assert(instance); … … 228 169 } 229 170 230 if (handle != NULL) {231 *handle = instance->devices[address].handle;232 }233 171 if (speed != NULL) { 234 172 *speed = instance->devices[address].speed;
Note:
See TracChangeset
for help on using the changeset viewer.