Changeset 327f147 in mainline for uspace/drv/bus/usb/xhci


Ignore:
Timestamp:
2017-10-23T19:03:37Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b724494
Parents:
e160bfe8
Message:

usbhost: change parameters of methods

Pass (device_t, usb_target_t) to read and write, which finally allows to drop hash tables and access device right away. Then, all callbacks to complete transfer now uses usb_transfer_batch. This requires libdrv to include libusbhost, but it is not linked against it - it is there only to share definition of usb_transfer_batch_t.

Location:
uspace/drv/bus/usb/xhci
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/bus.c

    re160bfe8 r327f147  
    3333 */
    3434
    35 #include <adt/hash_table.h>
    36 #include <adt/hash.h>
    3735#include <usb/host/utils/malloc32.h>
    3836#include <usb/host/ddf_helpers.h>
     
    5048#include "endpoint.h"
    5149#include "transfers.h"
    52 
    53 /** Element of the hash table. */
    54 typedef struct {
    55         ht_link_t link;
    56 
    57         /** Device */
    58         xhci_device_t *device;
    59 } hashed_device_t;
    60 
    61 static int hashed_device_insert(xhci_bus_t *bus, hashed_device_t **hashed_dev, xhci_device_t *dev);
    62 static int hashed_device_remove(xhci_bus_t *bus, hashed_device_t *hashed_dev);
    63 static int hashed_device_find_by_address(xhci_bus_t *bus, usb_address_t address, hashed_device_t **dev);
    6450
    6551/** TODO: Still some copy-pasta left...
     
    9480        bus->devices_by_slot[xhci_dev->slot_id] = xhci_dev;
    9581
    96         hashed_device_t *hashed_dev = NULL;
    97         if ((err = hashed_device_insert(bus, &hashed_dev, xhci_dev)))
    98                 goto err_address;
    99 
    10082        /* Read the device descriptor, derive the match ids */
    10183        if ((err = hcd_ddf_device_explore(hc->hcd, dev))) {
    10284                usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err));
    103                 goto err_hash;
    104         }
    105 
    106         return EOK;
    107 
    108 err_hash:
    109         bus->devices_by_slot[xhci_dev->slot_id] = NULL;
    110         hashed_device_remove(bus, hashed_dev);
     85                goto err_address;
     86        }
     87
     88        return EOK;
     89
    11190err_address:
    11291        bus_release_address(&bus->base, dev->address);
     
    127106        }
    128107
    129         hashed_device_t *hashed_dev;
    130         int res = hashed_device_find_by_address(bus, dev->address, &hashed_dev);
    131         if (res)
    132                 return res;
    133 
    134         res = hashed_device_remove(bus, hashed_dev);
    135         if (res != EOK)
    136                 return res;
    137 
    138108        // XXX: Ugly here. Move to device_destroy at endpoint.c?
    139109        free32(xhci_dev->dev_ctx);
     
    193163        xhci_endpoint_fini(xhci_ep);
    194164        free(xhci_ep);
    195 }
    196 
    197 static int hashed_device_find_by_address(xhci_bus_t *bus, usb_address_t address, hashed_device_t **dev)
    198 {
    199         ht_link_t *link = hash_table_find(&bus->devices, &address);
    200         if (link == NULL)
    201                 return ENOENT;
    202 
    203         *dev = hash_table_get_inst(link, hashed_device_t, link);
    204         return EOK;
    205 }
    206 
    207 static int xhci_endpoint_find_by_target(xhci_bus_t *bus, usb_target_t target, xhci_endpoint_t **ep)
    208 {
    209         hashed_device_t *dev;
    210         int res = hashed_device_find_by_address(bus, target.address, &dev);
    211         if (res != EOK)
    212                 return res;
    213 
    214         xhci_endpoint_t *ret_ep = xhci_device_get_endpoint(dev->device, target.endpoint);
    215         if (!ret_ep)
    216                 return ENOENT;
    217 
    218         *ep = ret_ep;
    219         return EOK;
    220 }
    221 
    222 static int hashed_device_insert(xhci_bus_t *bus, hashed_device_t **hashed_dev, xhci_device_t *dev)
    223 {
    224         hashed_device_t *ret_dev = (hashed_device_t *) calloc(1, sizeof(hashed_device_t));
    225         if (!ret_dev)
    226                 return ENOMEM;
    227 
    228         ret_dev->device = dev;
    229 
    230         usb_log_info("Device(%d) registered to XHCI bus.", dev->base.address);
    231 
    232         hash_table_insert(&bus->devices, &ret_dev->link);
    233         *hashed_dev = ret_dev;
    234         return EOK;
    235 }
    236 
    237 static int hashed_device_remove(xhci_bus_t *bus, hashed_device_t *hashed_dev)
    238 {
    239         usb_log_info("Device(%d) released from XHCI bus.", hashed_dev->device->base.address);
    240 
    241         hash_table_remove(&bus->devices, &hashed_dev->device->base.address);
    242         free(hashed_dev);
    243 
    244         return EOK;
    245165}
    246166
     
    273193}
    274194
    275 static endpoint_t* find_endpoint(bus_t *bus_base, usb_target_t target, usb_direction_t direction)
    276 {
    277         xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
    278         assert(bus);
    279 
    280         xhci_endpoint_t *ep;
    281         int res = xhci_endpoint_find_by_target(bus, target, &ep);
    282         if (res != EOK)
     195static endpoint_t* find_endpoint(bus_t *bus_base, device_t *dev_base, usb_target_t target, usb_direction_t direction)
     196{
     197        xhci_device_t *dev = xhci_device_get(dev_base);
     198
     199        xhci_endpoint_t *ep = xhci_device_get_endpoint(dev, target.endpoint);
     200        if (!ep)
    283201                return NULL;
    284202
     
    345263};
    346264
    347 static size_t device_ht_hash(const ht_link_t *item)
    348 {
    349         hashed_device_t *dev = hash_table_get_inst(item, hashed_device_t, link);
    350         return (size_t) hash_mix(dev->device->base.address);
    351 }
    352 
    353 static size_t device_ht_key_hash(void *key)
    354 {
    355         return (size_t) hash_mix(*(usb_address_t *)key);
    356 }
    357 
    358 static bool device_ht_key_equal(void *key, const ht_link_t *item)
    359 {
    360         hashed_device_t *dev = hash_table_get_inst(item, hashed_device_t, link);
    361         return dev->device->base.address == *(usb_address_t *) key;
    362 }
    363 
    364 /** Operations for the device hash table. */
    365 static hash_table_ops_t device_ht_ops = {
    366         .hash = device_ht_hash,
    367         .key_hash = device_ht_key_hash,
    368         .key_equal = device_ht_key_equal,
    369         .equal = NULL,
    370         .remove_callback = NULL
    371 };
    372 
    373265int xhci_bus_init(xhci_bus_t *bus, xhci_hc_t *hc)
    374266{
     
    381273                return ENOMEM;
    382274
    383         if (!hash_table_create(&bus->devices, 0, 0, &device_ht_ops)) {
    384                 free(bus->devices_by_slot);
    385                 return ENOMEM;
    386         }
    387 
    388275        bus->base.ops = xhci_bus_ops;
    389276        return EOK;
     
    392279void xhci_bus_fini(xhci_bus_t *bus)
    393280{
    394         // FIXME: Make sure no devices are in the hash table.
    395 
    396         hash_table_destroy(&bus->devices);
     281
    397282}
    398283
  • uspace/drv/bus/usb/xhci/bus.h

    re160bfe8 r327f147  
    3838#define XHCI_BUS_H
    3939
    40 #include <adt/hash_table.h>
    4140#include <usb/usb.h>
    4241#include <usb/host/bus.h>
     
    5049
    5150        xhci_device_t **devices_by_slot;        /**< Devices by Slot ID */
    52 
    53         /** TODO: Do we really need this? */
    54         hash_table_t devices;           /**< Devices by address */
    5551} xhci_bus_t;
    5652
Note: See TracChangeset for help on using the changeset viewer.