Changes in uspace/lib/usb/src/hcdhubd.c [4144630:4317827] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/hcdhubd.c
r4144630 r4317827 51 51 */ 52 52 static int add_device(device_t *dev) { 53 bool is_hc = str_cmp(dev->name, USB_HUB_DEVICE_NAME) != 0; 54 printf("%s: add_device(name=\"%s\")\n", hc_driver->name, dev->name); 55 56 if (is_hc) { 57 /* 58 * We are the HC itself. 59 */ 60 return usb_add_hc_device(dev); 61 } else { 62 /* 63 * We are some (maybe deeply nested) hub. 64 * Thus, assign our own operations and explore already 65 * connected devices. 66 */ 67 return usb_add_hub_device(dev); 68 } 53 return ENOTSUP; 69 54 } 70 55 … … 105 90 * @return Error code. 106 91 */ 107 int usb_hcd_add_root_hub(usb_hc_device_t *dev) { 92 int usb_hcd_add_root_hub(device_t *dev) 93 { 108 94 char *id; 109 int rc = asprintf(&id, "usb&h c=%s&hub", dev->generic->name);95 int rc = asprintf(&id, "usb&hub"); 110 96 if (rc <= 0) { 111 97 return rc; 112 98 } 113 99 114 rc = usb_hc_add_child_device(dev ->generic, USB_HUB_DEVICE_NAME, id, true);100 rc = usb_hc_add_child_device(dev, USB_HUB_DEVICE_NAME, id, true); 115 101 if (rc != EOK) { 116 102 free(id); … … 128 114 129 115 /** Adds a child device fibril worker. */ 130 static int fibril_add_child_device(void *arg) { 116 static int fibril_add_child_device(void *arg) 117 { 131 118 struct child_device_info *child_info 132 119 = (struct child_device_info *) arg; 133 120 int rc; 121 122 async_usleep(1000); 134 123 135 124 device_t *child = create_device(); … … 152 141 153 142 printf("%s: adding child device `%s' with match \"%s\"\n", 154 143 hc_driver->name, child->name, match_id->id); 155 144 rc = child_device_register(child, child_info->parent); 156 145 printf("%s: child device `%s' registration: %s\n", 157 146 hc_driver->name, child->name, str_error(rc)); 158 147 159 148 if (rc != EOK) { … … 193 182 */ 194 183 int usb_hc_add_child_device(device_t *parent, const char *name, 195 const char *match_id, bool create_fibril) { 184 const char *match_id, bool create_fibril) 185 { 196 186 printf("%s: about to add child device `%s' (%s)\n", hc_driver->name, 197 name, match_id); 187 name, match_id); 188 189 /* 190 * Seems that creating fibril which postpones the action 191 * is the best solution. 192 */ 193 create_fibril = true; 198 194 199 195 struct child_device_info *child_info 200 = malloc(sizeof(struct child_device_info));196 = malloc(sizeof(struct child_device_info)); 201 197 202 198 child_info->parent = parent; … … 222 218 * @return USB device address or error code. 223 219 */ 224 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 { 225 222 /* TODO: search list of attached devices. */ 226 223 return ENOENT; 227 224 } 228 225 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 226 /** 314 227 * @}
Note:
See TracChangeset
for help on using the changeset viewer.