Changeset 0cd8089 in mainline
- Timestamp:
- 2011-10-31T14:59:04Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 67f55e7b
- Parents:
- 5e07cbc0
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/hc.c
r5e07cbc0 r0cd8089 127 127 assert(hub_fun); 128 128 129 const usb_address_t hub_address = 130 usb_device_manager_get_free_address( 131 &instance->generic.dev_manager, USB_SPEED_FULL); 132 if (hub_address <= 0) { 129 /* Try to get address 1 for root hub. */ 130 instance->rh.address = 1; 131 int ret = usb_device_manager_request_address( 132 &instance->generic.dev_manager, &instance->rh.address, false, 133 USB_SPEED_FULL); 134 if (ret != EOK) { 133 135 usb_log_error("Failed to get OHCI root hub address: %s\n", 134 str_error(hub_address)); 135 return hub_address; 136 } 137 instance->rh.address = hub_address; 138 usb_device_manager_bind( 139 &instance->generic.dev_manager, hub_address, hub_fun->handle); 136 str_error(ret)); 137 return ret; 138 } 139 usb_device_manager_bind_address(&instance->generic.dev_manager, 140 instance->rh.address, hub_fun->handle); 140 141 141 142 #define CHECK_RET_UNREG_RETURN(ret, message...) \ … … 143 144 usb_log_error(message); \ 144 145 usb_endpoint_manager_remove_ep( \ 145 &instance->generic.ep_manager, hub_address, 0, USB_DIRECTION_BOTH, \146 NULL, NULL);\147 usb_device_manager_release ( \148 &instance->generic.dev_manager, hub_address); \146 &instance->generic.ep_manager, instance->rh.address, 0, \ 147 USB_DIRECTION_BOTH, NULL, NULL); \ 148 usb_device_manager_release_address( \ 149 &instance->generic.dev_manager, instance->rh.address); \ 149 150 return ret; \ 150 151 } else (void)0 151 int ret = usb_endpoint_manager_add_ep( 152 &instance->generic.ep_manager, hub_address, 0, USB_DIRECTION_BOTH, 153 USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64, 0, NULL, NULL); 152 ret = usb_endpoint_manager_add_ep( 153 &instance->generic.ep_manager, instance->rh.address, 0, 154 USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64, 155 0, NULL, NULL); 154 156 CHECK_RET_UNREG_RETURN(ret, 155 157 "Failed to register root hub control endpoint: %s.\n", -
uspace/drv/bus/usb/vhc/connhost.c
r5e07cbc0 r0cd8089 62 62 VHC_DATA(vhc, fun); 63 63 64 usb_address_t addr = usb_device_manager_get_free_address( 65 &vhc->dev_manager, USB_SPEED_HIGH); 66 if (addr < 0) { 67 return addr; 64 usb_address_t addr = 1; 65 const int ret = usb_device_manager_request_address( 66 &vhc->dev_manager, &addr, false, USB_SPEED_HIGH); 67 if (ret < 0) { 68 return ret; 68 69 } 69 70 … … 88 89 usb_log_debug("Binding handle %" PRIun " to address %d.\n", 89 90 handle, address); 90 usb_device_manager_bind (&vhc->dev_manager, address, handle);91 usb_device_manager_bind_address(&vhc->dev_manager, address, handle); 91 92 92 93 return EOK; … … 118 119 VHC_DATA(vhc, fun); 119 120 usb_log_debug("Releasing address %d...\n", address); 120 usb_device_manager_release (&vhc->dev_manager, address);121 usb_device_manager_release_address(&vhc->dev_manager, address); 121 122 122 123 return ENOTSUP; -
uspace/lib/usbhost/include/usb/host/usb_device_manager.h
r5e07cbc0 r0cd8089 68 68 usb_device_manager_t *instance, usb_speed_t max_speed); 69 69 70 usb_address_t usb_device_manager_get_free_address( 71 usb_ device_manager_t *instance, usb_speed_t speed);70 int usb_device_manager_request_address(usb_device_manager_t *instance, 71 usb_address_t *address, bool strict, usb_speed_t speed); 72 72 73 int usb_device_manager_bind (usb_device_manager_t *instance,73 int usb_device_manager_bind_address(usb_device_manager_t *instance, 74 74 usb_address_t address, devman_handle_t handle); 75 75 76 int usb_device_manager_release (usb_device_manager_t *instance,76 int usb_device_manager_release_address(usb_device_manager_t *instance, 77 77 usb_address_t address); 78 78 -
uspace/lib/usbhost/src/iface.c
r5e07cbc0 r0cd8089 105 105 106 106 usb_log_debug("Address request speed: %s.\n", usb_str_speed(speed)); 107 *address = 108 usb_device_manager_get_free_address(&hcd->dev_manager, speed); 109 usb_log_debug("Address request with result: %d.\n", *address); 110 if (*address <= 0) 111 return *address; 112 return EOK; 107 return usb_device_manager_request_address( 108 &hcd->dev_manager, address, false, speed); 113 109 } 114 110 /*----------------------------------------------------------------------------*/ … … 128 124 129 125 usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle); 130 return usb_device_manager_bind(&hcd->dev_manager, address, handle); 126 return usb_device_manager_bind_address( 127 &hcd->dev_manager, address, handle); 131 128 } 132 129 /*----------------------------------------------------------------------------*/ … … 160 157 assert(hcd); 161 158 usb_log_debug("Address release %d.\n", address); 162 usb_device_manager_release (&hcd->dev_manager, address);159 usb_device_manager_release_address(&hcd->dev_manager, address); 163 160 return EOK; 164 161 } -
uspace/lib/usbhost/src/usb_device_manager.c
r5e07cbc0 r0cd8089 38 38 #include <usb/host/usb_device_manager.h> 39 39 40 /** Get a free USB address 41 * 42 * @param[in] instance Device manager structure to use. 43 * @param[in] speed Speed of the device requiring address. 44 * @return Free address, or error code. 45 */ 46 static usb_address_t usb_device_manager_get_free_address( 47 usb_device_manager_t *instance) 48 { 49 50 usb_address_t new_address = instance->last_address; 51 do { 52 new_address = (new_address + 1) % USB_ADDRESS_COUNT; 53 if (new_address == USB_ADDRESS_DEFAULT) 54 new_address = 1; 55 if (new_address == instance->last_address) { 56 return ENOSPC; 57 } 58 } while (instance->devices[new_address].occupied); 59 60 assert(new_address != USB_ADDRESS_DEFAULT); 61 instance->last_address = new_address; 62 63 return new_address; 64 } 65 /*----------------------------------------------------------------------------*/ 40 66 /** Initialize device manager structure. 41 67 * … … 54 80 instance->devices[i].speed = USB_SPEED_MAX; 55 81 } 56 // TODO: is this hack enough?57 // (it is needed to allow smooth registration at default address)58 instance->devices[0].occupied = true;59 82 instance->last_address = 0; 60 83 instance->max_speed = max_speed; … … 62 85 } 63 86 /*----------------------------------------------------------------------------*/ 64 /** Get a free USB address 65 * 66 * @param[in] instance Device manager structure to use. 67 * @param[in] speed Speed of the device requiring address. 68 * @return Free address, or error code. 69 */ 70 usb_address_t usb_device_manager_get_free_address( 71 usb_device_manager_t *instance, usb_speed_t speed) 72 { 73 assert(instance); 87 /** Request USB address. 88 * @param instance usb_device_manager 89 * @param address Pointer to requested address value, place to store new address 90 * @parma strict Fail if the requested address is not available. 91 * @return Error code. 92 * @note Default address is only available in strict mode. 93 */ 94 int usb_device_manager_request_address(usb_device_manager_t *instance, 95 usb_address_t *address, bool strict, usb_speed_t speed) 96 { 97 assert(instance); 98 assert(address); 74 99 if (speed > instance->max_speed) 75 100 return ENOTSUP; 76 fibril_mutex_lock(&instance->guard); 77 78 usb_address_t new_address = instance->last_address; 79 do { 80 ++new_address; 81 if (new_address > USB11_ADDRESS_MAX) 82 new_address = 1; // NOTE it should be safe to put 0 here 83 // TODO Use mod 84 if (new_address == instance->last_address) { 101 102 if ((*address) < 0 || (*address) >= USB_ADDRESS_COUNT) 103 return EINVAL; 104 105 fibril_mutex_lock(&instance->guard); 106 /* Only grant default address to strict requests */ 107 if (( (*address) == USB_ADDRESS_DEFAULT) && !strict) { 108 *address = instance->last_address; 109 } 110 111 if (instance->devices[*address].occupied) { 112 if (strict) { 85 113 fibril_mutex_unlock(&instance->guard); 86 return ENO SPC;114 return ENOENT; 87 115 } 88 } while (instance->devices[new_address].occupied); 89 90 assert(new_address != USB_ADDRESS_DEFAULT); 91 assert(instance->devices[new_address].occupied == false); 92 assert(instance->devices[new_address].handle == 0); 93 94 instance->devices[new_address].occupied = true; 95 instance->devices[new_address].speed = speed; 96 instance->last_address = new_address; 97 98 fibril_mutex_unlock(&instance->guard); 99 return new_address; 116 *address = usb_device_manager_get_free_address(instance); 117 } 118 assert(instance->devices[*address].occupied == false); 119 assert(instance->devices[*address].handle == 0); 120 121 instance->devices[*address].occupied = true; 122 instance->devices[*address].speed = speed; 123 124 fibril_mutex_unlock(&instance->guard); 125 return EOK; 100 126 } 101 127 /*----------------------------------------------------------------------------*/ … … 107 133 * @return Error code. 108 134 */ 109 int usb_device_manager_bind (usb_device_manager_t *instance,135 int usb_device_manager_bind_address(usb_device_manager_t *instance, 110 136 usb_address_t address, devman_handle_t handle) 111 137 { … … 137 163 * @return Error code. 138 164 */ 139 int usb_device_manager_release (165 int usb_device_manager_release_address( 140 166 usb_device_manager_t *instance, usb_address_t address) 141 167 {
Note:
See TracChangeset
for help on using the changeset viewer.