Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/hcdhubd.c

    r4144630 r7972b51  
    105105 * @return Error code.
    106106 */
    107 int usb_hcd_add_root_hub(usb_hc_device_t *dev) {
     107int usb_hcd_add_root_hub(usb_hc_device_t *dev)
     108{
    108109        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);
    110111        if (rc <= 0) {
    111112                return rc;
     
    128129
    129130/** Adds a child device fibril worker. */
    130 static int fibril_add_child_device(void *arg) {
     131static int fibril_add_child_device(void *arg)
     132{
    131133        struct child_device_info *child_info
    132                         = (struct child_device_info *) arg;
     134            = (struct child_device_info *) arg;
    133135        int rc;
     136
     137        async_usleep(1000);
    134138
    135139        device_t *child = create_device();
     
    152156
    153157        printf("%s: adding child device `%s' with match \"%s\"\n",
    154                         hc_driver->name, child->name, match_id->id);
     158            hc_driver->name, child->name, match_id->id);
    155159        rc = child_device_register(child, child_info->parent);
    156160        printf("%s: child device `%s' registration: %s\n",
    157                         hc_driver->name, child->name, str_error(rc));
     161            hc_driver->name, child->name, str_error(rc));
    158162
    159163        if (rc != EOK) {
     
    193197 */
    194198int 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{
    196201        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;
    198209
    199210        struct child_device_info *child_info
    200                         = malloc(sizeof (struct child_device_info));
     211            = malloc(sizeof(struct child_device_info));
    201212
    202213        child_info->parent = parent;
     
    222233 * @return USB device address or error code.
    223234 */
    224 usb_address_t usb_get_address_by_handle(devman_handle_t handle) {
     235usb_address_t usb_get_address_by_handle(devman_handle_t handle)
     236{
    225237        /* TODO: search list of attached devices. */
    226238        return ENOENT;
    227239}
    228240
    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 interval
    246         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 range
    257         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' interval
    262         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 found
    284                 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 range
    291                 if (found_range->lower_bound - 1 == addr) {
    292                         --found_range->lower_bound;
    293                 } else {
    294                         //only one possible case
    295                         ++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 range
    301                                 if (next_range->lower_bound == addr + 1) {
    302                                         //join ranges
    303                                         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 
    313241/**
    314242 * @}
Note: See TracChangeset for help on using the changeset viewer.