Changes in / [36c410e:4317827] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified uspace/drv/usbhub/utils.c ¶
r36c410e r4317827 109 109 //********************************************* 110 110 111 static void set_hub_address(device_t *dev, usb_address_t address); 112 111 113 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 112 114 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); … … 122 124 int usb_add_hub_device(device_t *dev) { 123 125 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 126 set_hub_address(dev, 5); 124 127 125 128 check_hub_changes(); … … 139 142 } 140 143 144 /** Sample usage of usb_hc_async functions. 145 * This function sets hub address using standard SET_ADDRESS request. 146 * 147 * @warning This function shall be removed once you are familiar with 148 * the usb_hc_ API. 149 * 150 * @param hc Host controller the hub belongs to. 151 * @param address New hub address. 152 */ 153 static void set_hub_address(device_t *dev, usb_address_t address) { 154 printf(NAME ": setting hub address to %d\n", address); 155 usb_target_t target = {0, 0}; 156 usb_handle_t handle; 157 int rc; 158 159 usb_device_request_setup_packet_t setup_packet = { 160 .request_type = 0, 161 .request = USB_DEVREQ_SET_ADDRESS, 162 .index = 0, 163 .length = 0, 164 }; 165 setup_packet.value = address; 166 167 int hc = usb_drv_hc_connect(dev, 0); 168 169 rc = usb_drv_async_control_write_setup(hc, target, 170 &setup_packet, sizeof (setup_packet), &handle); 171 if (rc != EOK) { 172 return; 173 } 174 175 rc = usb_drv_async_wait_for(handle); 176 if (rc != EOK) { 177 return; 178 } 179 180 rc = usb_drv_async_control_write_status(hc, target, &handle); 181 if (rc != EOK) { 182 return; 183 } 184 185 rc = usb_drv_async_wait_for(handle); 186 if (rc != EOK) { 187 return; 188 } 189 190 printf(NAME ": hub address changed\n"); 191 } 141 192 142 193 /** Check changes on all known hubs. -
TabularUnified uspace/lib/usb/include/usb/hcdhubd.h ¶
r36c410e r4317827 116 116 } usb_hcd_transfer_ops_t; 117 117 118 /**119 * @brief structure holding information about free and used addresses120 *121 * This structure should not be used outside usb hcd driver.122 * You better consider it to be 'private'.123 */124 typedef struct {125 /** lower bound included in the interval */126 usb_address_t lower_bound;127 128 /** upper bound, excluded from the interval */129 usb_address_t upper_bound;130 131 /** */132 link_t link;133 }usb_address_list_t;134 135 118 struct usb_hc_device { 136 119 /** Transfer operations. */ … … 149 132 link_t hubs; 150 133 151 /** Structure with free and used addresses */152 link_t addresses;153 154 134 /** Link to other driven HCs. */ 155 135 link_t link; … … 167 147 int usb_hcd_main(usb_hc_driver_t *); 168 148 int usb_hcd_add_root_hub(device_t *dev); 169 170 /**171 * find first not yet used address on this host controller and use it172 * @param this_hcd173 * @return number in the range of allowed usb addresses or174 * a negative number if not succesful175 */176 usb_address_t usb_use_free_address(usb_hc_device_t * this_hcd);177 178 /**179 * @brief free the address in the address space of this hcd.180 *181 * if address is not used, nothing happens182 * @param this_hcd183 * @param addr184 */185 void usb_free_used_address(usb_hc_device_t * this_hcd, usb_address_t addr );186 149 187 150 -
TabularUnified uspace/lib/usb/src/hcdhubd.c ¶
r36c410e r4317827 114 114 115 115 /** Adds a child device fibril worker. */ 116 static int fibril_add_child_device(void *arg) { 116 static int fibril_add_child_device(void *arg) 117 { 117 118 struct child_device_info *child_info 118 119 = (struct child_device_info *) arg; 119 120 int rc; 120 121 … … 140 141 141 142 printf("%s: adding child device `%s' with match \"%s\"\n", 142 143 hc_driver->name, child->name, match_id->id); 143 144 rc = child_device_register(child, child_info->parent); 144 145 printf("%s: child device `%s' registration: %s\n", 145 146 hc_driver->name, child->name, str_error(rc)); 146 147 147 148 if (rc != EOK) { … … 181 182 */ 182 183 int usb_hc_add_child_device(device_t *parent, const char *name, 183 const char *match_id, bool create_fibril) { 184 const char *match_id, bool create_fibril) 185 { 184 186 printf("%s: about to add child device `%s' (%s)\n", hc_driver->name, 185 187 name, match_id); 186 188 187 189 /* … … 192 194 193 195 struct child_device_info *child_info 194 = malloc(sizeof(struct child_device_info));196 = malloc(sizeof(struct child_device_info)); 195 197 196 198 child_info->parent = parent; … … 216 218 * @return USB device address or error code. 217 219 */ 218 usb_address_t usb_get_address_by_handle(devman_handle_t handle) { 220 usb_address_t usb_get_address_by_handle(devman_handle_t handle) 221 { 219 222 /* TODO: search list of attached devices. */ 220 223 return ENOENT; 221 224 } 222 225 223 usb_address_t usb_use_free_address(usb_hc_device_t * this_hcd) {224 //is there free address?225 link_t * addresses = &this_hcd->addresses;226 if (list_empty(addresses)) return -1;227 link_t * link_addr = addresses;228 bool found = false;229 usb_address_list_t * range = NULL;230 while (!found) {231 link_addr = link_addr->next;232 if (link_addr == addresses) return -2;233 range = list_get_instance(link_addr,234 usb_address_list_t, link);235 if (range->upper_bound - range->lower_bound > 0) {236 found = true;237 }238 }239 //now we have interval240 int result = range->lower_bound;241 ++(range->lower_bound);242 if (range->upper_bound - range->lower_bound == 0) {243 list_remove(&range->link);244 free(range);245 }246 return result;247 }248 249 void usb_free_used_address(usb_hc_device_t * this_hcd, usb_address_t addr) {250 //check range251 if (addr < usb_lowest_address || addr > usb_highest_address)252 return;253 link_t * addresses = &this_hcd->addresses;254 link_t * link_addr = addresses;255 //find 'good' interval256 usb_address_list_t * found_range = NULL;257 bool found = false;258 while (!found) {259 link_addr = link_addr->next;260 if (link_addr == addresses) {261 found = true;262 } else {263 usb_address_list_t * range = list_get_instance(link_addr,264 usb_address_list_t, link);265 if ( (range->lower_bound - 1 == addr) ||266 (range->upper_bound == addr)) {267 found = true;268 found_range = range;269 }270 if (range->lower_bound - 1 > addr) {271 found = true;272 }273 274 }275 }276 if (found_range == NULL) {277 //no suitable range found278 usb_address_list_t * result_range =279 (usb_address_list_t*) malloc(sizeof (usb_address_list_t));280 result_range->lower_bound = addr;281 result_range->upper_bound = addr + 1;282 list_insert_before(&result_range->link, link_addr);283 } else {284 //we have good range285 if (found_range->lower_bound - 1 == addr) {286 --found_range->lower_bound;287 } else {288 //only one possible case289 ++found_range->upper_bound;290 if (found_range->link.next != addresses) {291 usb_address_list_t * next_range =292 list_get_instance( &found_range->link.next,293 usb_address_list_t, link);294 //check neighbour range295 if (next_range->lower_bound == addr + 1) {296 //join ranges297 found_range->upper_bound = next_range->upper_bound;298 list_remove(&next_range->link);299 free(next_range);300 }301 }302 }303 }304 305 }306 307 226 /** 308 227 * @} -
TabularUnified uspace/lib/usb/src/hcdhubd_private.h ¶
r36c410e r4317827 47 47 int usb_add_hc_device(device_t *); 48 48 49 /** lowest allowed usb address */50 extern int usb_lowest_address;51 52 /** highest allowed usb address */53 extern int usb_highest_address;54 55 /**56 * @brief initialize address list of given hcd57 *58 * This function should be used only for hcd initialization.59 * It creates interval list of free addresses, thus it is initialized as60 * list with one interval with whole address space. Using an address shrinks61 * the interval, freeing an address extends an interval or creates a62 * new one.63 *64 * @param hcd65 * @return66 */67 void usb_create_address_list(usb_hc_device_t * hcd);68 69 70 71 72 73 74 49 #endif 75 50 /** -
TabularUnified uspace/lib/usb/src/hcdrv.c ¶
r36c410e r4317827 55 55 usb_hc_driver_t *hc_driver = &hc_driver_fake; 56 56 57 int usb_lowest_address = 1;58 59 int usb_highest_address = 255;60 61 57 static device_ops_t usb_device_ops = { 62 58 .interfaces[USBHC_DEV_IFACE] = &usbhc_interface 63 59 }; 64 65 66 void usb_create_address_list(usb_hc_device_t * hcd){67 list_initialize(&hcd->addresses);68 usb_address_list_t * range =69 (usb_address_list_t*)malloc(sizeof(usb_address_list_t));70 range->lower_bound = usb_lowest_address;71 range->upper_bound = usb_highest_address + 1;72 list_append(&range->link, &hcd->addresses);73 }74 60 75 61 static usb_hc_device_t *usb_hc_device_create(device_t *dev) { … … 78 64 list_initialize(&hc_dev->link); 79 65 list_initialize(&hc_dev->hubs); 80 usb_create_address_list(hc_dev);81 66 list_initialize(&hc_dev->attached_devices); 82 67 hc_dev->transfer_ops = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.