Changes in uspace/lib/usb/src/hcdhubd.c [4144630:7972b51] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hcdhubd.c
r4144630 r7972b51 105 105 * @return Error code. 106 106 */ 107 int usb_hcd_add_root_hub(usb_hc_device_t *dev) { 107 int usb_hcd_add_root_hub(usb_hc_device_t *dev) 108 { 108 109 char *id; 109 int rc = asprintf(&id, "usb&hc=%s&hub", dev->generic->name);110 int rc = asprintf(&id, "usb&hc=%s&hub", hc_driver->name); 110 111 if (rc <= 0) { 111 112 return rc; … … 128 129 129 130 /** Adds a child device fibril worker. */ 130 static int fibril_add_child_device(void *arg) { 131 static int fibril_add_child_device(void *arg) 132 { 131 133 struct child_device_info *child_info 132 134 = (struct child_device_info *) arg; 133 135 int rc; 136 137 async_usleep(1000); 134 138 135 139 device_t *child = create_device(); … … 152 156 153 157 printf("%s: adding child device `%s' with match \"%s\"\n", 154 158 hc_driver->name, child->name, match_id->id); 155 159 rc = child_device_register(child, child_info->parent); 156 160 printf("%s: child device `%s' registration: %s\n", 157 161 hc_driver->name, child->name, str_error(rc)); 158 162 159 163 if (rc != EOK) { … … 193 197 */ 194 198 int usb_hc_add_child_device(device_t *parent, const char *name, 195 const char *match_id, bool create_fibril) { 199 const char *match_id, bool create_fibril) 200 { 196 201 printf("%s: about to add child device `%s' (%s)\n", hc_driver->name, 197 name, match_id); 202 name, match_id); 203 204 /* 205 * Seems that creating fibril which postpones the action 206 * is the best solution. 207 */ 208 create_fibril = true; 198 209 199 210 struct child_device_info *child_info 200 = malloc(sizeof(struct child_device_info));211 = malloc(sizeof(struct child_device_info)); 201 212 202 213 child_info->parent = parent; … … 222 233 * @return USB device address or error code. 223 234 */ 224 usb_address_t usb_get_address_by_handle(devman_handle_t handle) { 235 usb_address_t usb_get_address_by_handle(devman_handle_t handle) 236 { 225 237 /* TODO: search list of attached devices. */ 226 238 return ENOENT; 227 239 } 228 240 229 usb_address_t usb_use_free_address(usb_hc_device_t * this_hcd) {230 //is there free address?231 link_t * addresses = &this_hcd->addresses;232 if (list_empty(addresses)) return -1;233 link_t * link_addr = addresses;234 bool found = false;235 usb_address_list_t * range = NULL;236 while (!found) {237 link_addr = link_addr->next;238 if (link_addr == addresses) return -2;239 range = list_get_instance(link_addr,240 usb_address_list_t, link);241 if (range->upper_bound - range->lower_bound > 0) {242 found = true;243 }244 }245 //now we have interval246 int result = range->lower_bound;247 ++(range->lower_bound);248 if (range->upper_bound - range->lower_bound == 0) {249 list_remove(&range->link);250 free(range);251 }252 return result;253 }254 255 void usb_free_used_address(usb_hc_device_t * this_hcd, usb_address_t addr) {256 //check range257 if (addr < usb_lowest_address || addr > usb_highest_address)258 return;259 link_t * addresses = &this_hcd->addresses;260 link_t * link_addr = addresses;261 //find 'good' interval262 usb_address_list_t * found_range = NULL;263 bool found = false;264 while (!found) {265 link_addr = link_addr->next;266 if (link_addr == addresses) {267 found = true;268 } else {269 usb_address_list_t * range = list_get_instance(link_addr,270 usb_address_list_t, link);271 if ( (range->lower_bound - 1 == addr) ||272 (range->upper_bound == addr)) {273 found = true;274 found_range = range;275 }276 if (range->lower_bound - 1 > addr) {277 found = true;278 }279 280 }281 }282 if (found_range == NULL) {283 //no suitable range found284 usb_address_list_t * result_range =285 (usb_address_list_t*) malloc(sizeof (usb_address_list_t));286 result_range->lower_bound = addr;287 result_range->upper_bound = addr + 1;288 list_insert_before(&result_range->link, link_addr);289 } else {290 //we have good range291 if (found_range->lower_bound - 1 == addr) {292 --found_range->lower_bound;293 } else {294 //only one possible case295 ++found_range->upper_bound;296 if (found_range->link.next != addresses) {297 usb_address_list_t * next_range =298 list_get_instance( &found_range->link.next,299 usb_address_list_t, link);300 //check neighbour range301 if (next_range->lower_bound == addr + 1) {302 //join ranges303 found_range->upper_bound = next_range->upper_bound;304 list_remove(&next_range->link);305 free(next_range);306 }307 }308 }309 }310 311 }312 313 241 /** 314 242 * @}
Note:
See TracChangeset
for help on using the changeset viewer.