Ignore:
Timestamp:
2013-08-07T15:00:36Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
14dd4c9
Parents:
2757247
Message:

usb: Switch to using port number as device identifier.

Port number info will be needed for HS SPLIT transactions. Moreover,
it can be used to produce predictable, persistent device names.

Switch port_number from size_t to unsigned. There are max 256 ports so
even short would be enough.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    r2757247 r0918382f  
    7777} usb_dev_t;
    7878
    79 static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port,
    80     usb_address_t *id);
    81 static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
    82     usb_address_t id);
     79static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
     80static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
    8381
    8482
     
    164162}
    165163
    166 static int device_enumerate(ddf_fun_t *fun, usb_device_handle_t *handle)
     164static int device_enumerate(ddf_fun_t *fun, unsigned port)
    167165{
    168166        assert(fun);
     
    171169        assert(ddf_dev);
    172170        assert(dev);
    173         usb_address_t address = 0;
    174         unsigned port = 0; //TODO provide real value here
    175         usb_log_debug("Device %d reported a new USB device\n", dev->address);
    176         const int ret = hcd_ddf_new_device(ddf_dev, dev, port, &address);
    177         if (ret == EOK && handle)
    178                 *handle = address;
    179         return ret;
    180 }
    181 
    182 static int device_remove(ddf_fun_t *fun, usb_device_handle_t handle)
     171        usb_log_debug("Hub %d reported a new USB device on port: %u\n",
     172            dev->address, port);
     173        return hcd_ddf_new_device(ddf_dev, dev, port);
     174}
     175
     176static int device_remove(ddf_fun_t *fun, unsigned port)
    183177{
    184178        assert(fun);
     
    187181        assert(ddf_dev);
    188182        assert(dev);
    189         usb_log_debug("Hub `%s' reported removal of device %d\n",
    190             ddf_fun_get_name(fun), (int)handle);
    191         return hcd_ddf_remove_device(ddf_dev, dev, (usb_address_t)handle);
     183        usb_log_debug("Hub `%s' reported removal of device on port %u\n",
     184            ddf_fun_get_name(fun), port);
     185        return hcd_ddf_remove_device(ddf_dev, dev, port);
    192186}
    193187
     
    405399
    406400static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
    407     usb_address_t id)
     401    unsigned port)
    408402{
    409403        assert(device);
     
    421415        list_foreach(hub->devices, it) {
    422416                victim = list_get_instance(it, usb_dev_t, link);
    423                 if (victim->address == id)
     417                if (victim->port == port)
    424418                        break;
    425419        }
    426         if (victim && victim->address == id) {
     420        if (victim && victim->port == port) {
    427421                list_remove(&victim->link);
    428422                fibril_mutex_unlock(&hc_dev->guard);
     
    432426                        hcd_release_address(hcd, victim->address);
    433427                } else {
    434                         usb_log_warning("Failed to unbind device %d: %s\n",
    435                             id, str_error(ret));
     428                        usb_log_warning("Failed to unbind device `%s': %s\n",
     429                            ddf_fun_get_name(victim->fun), str_error(ret));
    436430                }
    437431                return EOK;
     
    440434}
    441435
    442 static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port,
    443     usb_address_t *id)
     436static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port)
    444437{
    445438        assert(device);
     
    552545                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
    553546                hcd_release_address(hcd, target.address);
    554                 return ret;
    555         }
    556         if (ret == EOK && id)
    557                 *id = target.address;
     547        }
    558548
    559549        return ret;
     
    574564
    575565        hcd_reserve_default_address(hcd, speed);
    576         const int ret = hcd_ddf_new_device(device, NULL, 0, NULL);
     566        const int ret = hcd_ddf_new_device(device, NULL, 0);
    577567        hcd_release_default_address(hcd);
    578568        return ret;
Note: See TracChangeset for help on using the changeset viewer.