Changeset 4267908 in mainline
- Timestamp:
- 2011-10-27T10:45:08Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 83c3123
- Parents:
- 069b80d
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/ohci.c
r069b80d r4267908 89 89 &dev_to_ohci(fun->dev)->hc.generic.dev_manager; 90 90 91 const usb_address_t addr = usb_device_manager_find(manager, handle); 91 const usb_address_t addr = 92 usb_device_manager_find_address(manager, handle); 92 93 if (addr < 0) { 93 94 return addr; -
uspace/drv/bus/usb/uhci/uhci.c
r069b80d r4267908 101 101 usb_device_manager_t *manager = 102 102 &dev_to_uhci(fun->dev)->hc.generic.dev_manager; 103 const usb_address_t addr = usb_device_manager_find(manager, handle); 103 const usb_address_t addr = 104 usb_device_manager_find_address(manager, handle); 104 105 105 106 if (addr < 0) { -
uspace/drv/bus/usb/vhc/connhost.c
r069b80d r4267908 104 104 { 105 105 VHC_DATA(vhc, fun); 106 bool found = 107 usb_device_manager_find_by_address(&vhc->dev_manager, address, handle); 108 return found ? EOK : ENOENT; 106 return usb_device_manager_get_info_by_address( 107 &vhc->dev_manager, address, handle, NULL); 109 108 } 110 109 … … 518 517 519 518 usb_log_debug("tell_address_rh(handle=%" PRIun ")\n", handle); 520 usb_address_t addr = usb_device_manager_find(&vhc->dev_manager, handle); 519 const usb_address_t addr = 520 usb_device_manager_find_address(&vhc->dev_manager, handle); 521 521 if (addr < 0) { 522 522 return addr; -
uspace/lib/usbhost/include/usb/host/usb_device_manager.h
r069b80d r4267908 49 49 #define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1) 50 50 51 /** Information about attached USB device. */52 struct usb_device_info {53 usb_speed_t speed;54 bool occupied;55 devman_handle_t handle;56 };57 58 51 /** Host controller device manager. 59 * You shall not access members directly but only using functions below.52 * You shall not access members directly. 60 53 */ 61 54 typedef struct { 62 struct usb_device_info devices[USB_ADDRESS_COUNT]; 55 /** Information about attached USB devices. */ 56 struct { 57 usb_speed_t speed; /**< Device speed */ 58 bool occupied; /**< The address is in use. */ 59 devman_handle_t handle; /**< Devman handle of the device. */ 60 } devices[USB_ADDRESS_COUNT]; 63 61 fibril_mutex_t guard; 62 /** The last reserved address */ 64 63 usb_address_t last_address; 65 64 } usb_device_manager_t; … … 76 75 usb_address_t address); 77 76 78 usb_address_t usb_device_manager_find (usb_device_manager_t *instance,77 usb_address_t usb_device_manager_find_address(usb_device_manager_t *instance, 79 78 devman_handle_t handle); 80 79 81 bool usb_device_manager_find_by_address(usb_device_manager_t *instance, 82 usb_address_t address, devman_handle_t *handle); 83 84 usb_speed_t usb_device_manager_get_speed(usb_device_manager_t *instance, 85 usb_address_t address); 80 int usb_device_manager_get_info_by_address(usb_device_manager_t *instance, 81 usb_address_t address, devman_handle_t *handle, usb_speed_t *speed); 86 82 #endif 87 83 /** -
uspace/lib/usbhost/src/iface.c
r069b80d r4267908 147 147 hcd_t *hcd = fun_to_hcd(fun); 148 148 assert(hcd); 149 const bool found = 150 usb_device_manager_find_by_address(&hcd->dev_manager, address, handle); 151 return found ? EOK : ENOENT; 149 return usb_device_manager_get_info_by_address( 150 &hcd->dev_manager, address, handle, NULL); 152 151 } 153 152 /*----------------------------------------------------------------------------*/ … … 180 179 /* Default address is not bound or registered, 181 180 * thus it does not provide speed info. */ 182 const usb_speed_t speed = (address == 0) ? ep_speed : 183 usb_device_manager_get_speed(&hcd->dev_manager, address); 181 usb_speed_t speed = ep_speed; 182 /* NOTE The function will return EINVAL and won't 183 * touch speed variable for default address */ 184 usb_device_manager_get_info_by_address( 185 &hcd->dev_manager, address, NULL, &speed); 184 186 185 187 usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n", … … 192 194 if (!ep) 193 195 return ENOMEM; 194 int ret = EOK;195 196 196 197 if (hcd->ep_add_hook) { 197 ret = hcd->ep_add_hook(hcd, ep); 198 } 199 if (ret != EOK) { 200 endpoint_destroy(ep); 201 return ret; 202 } 203 204 ret = usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size); 198 const int ret = hcd->ep_add_hook(hcd, ep); 199 if (ret != EOK) { 200 endpoint_destroy(ep); 201 return ret; 202 } 203 } 204 205 const int ret = 206 usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size); 205 207 if (ret != EOK) { 206 208 endpoint_destroy(ep); -
uspace/lib/usbhost/src/usb_device_manager.c
r069b80d r4267908 38 38 #include <usb/host/usb_device_manager.h> 39 39 40 /*----------------------------------------------------------------------------*/41 40 /** Initialize device manager structure. 42 41 * … … 77 76 ++new_address; 78 77 if (new_address > USB11_ADDRESS_MAX) 79 new_address = 1; 78 new_address = 1; // NOTE it should be safe to put 0 here 79 // TODO Use mod 80 80 if (new_address == instance->last_address) { 81 81 fibril_mutex_unlock(&instance->guard); … … 86 86 assert(new_address != USB_ADDRESS_DEFAULT); 87 87 assert(instance->devices[new_address].occupied == false); 88 assert(instance->devices[new_address].handle == 0); 88 89 89 90 instance->devices[new_address].occupied = true; … … 131 132 132 133 instance->devices[address].occupied = false; 134 instance->devices[address].handle = 0; 133 135 fibril_mutex_unlock(&instance->guard); 134 136 } … … 140 142 * @return USB Address, or error code. 141 143 */ 142 usb_address_t usb_device_manager_find (144 usb_address_t usb_device_manager_find_address( 143 145 usb_device_manager_t *instance, devman_handle_t handle) 144 146 { … … 157 159 return ENOENT; 158 160 } 159 160 /** Find devman handle a ssigned to USB address.161 * Intentionally refuse to find handle ofdefault address.161 /*----------------------------------------------------------------------------*/ 162 /** Find devman handle and speed assigned to USB address. 163 * Intentionally refuse to work on default address. 162 164 * 163 165 * @param[in] instance Device manager structure to use. 164 166 * @param[in] address Address the caller wants to find. 165 167 * @param[out] handle Where to store found handle. 166 * @return Whether such address is currently occupied. 168 * @param[out] speed Assigned speed. 169 * @return Error code. 167 170 */ 168 bool usb_device_manager_find_by_address(usb_device_manager_t *instance,169 usb_address_t address, devman_handle_t *handle )171 int usb_device_manager_get_info_by_address(usb_device_manager_t *instance, 172 usb_address_t address, devman_handle_t *handle, usb_speed_t *speed) 170 173 { 171 174 assert(instance); 175 if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) { 176 return EINVAL; 177 } 178 172 179 fibril_mutex_lock(&instance->guard); 173 if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) {174 fibril_mutex_unlock(&instance->guard);175 return false;176 }177 180 if (!instance->devices[address].occupied) { 178 181 fibril_mutex_unlock(&instance->guard); 179 return false;182 return ENOENT; 180 183 } 181 184 … … 183 186 *handle = instance->devices[address].handle; 184 187 } 188 if (speed != NULL) { 189 *speed = instance->devices[address].speed; 190 } 185 191 186 192 fibril_mutex_unlock(&instance->guard); 187 return true; 188 } 189 190 /*----------------------------------------------------------------------------*/ 191 /** Get speed associated with the address 192 * 193 * @param[in] instance Device manager structure to use. 194 * @param[in] address Address of the device. 195 * @return USB speed. 196 */ 197 usb_speed_t usb_device_manager_get_speed( 198 usb_device_manager_t *instance, usb_address_t address) 199 { 200 assert(instance); 201 assert(address >= 0); 202 assert(address <= USB11_ADDRESS_MAX); 203 204 return instance->devices[address].speed; 193 return EOK; 205 194 } 206 195 /**
Note:
See TracChangeset
for help on using the changeset viewer.