Changeset 327f147 in mainline for uspace/drv/bus/usb/xhci
- Timestamp:
- 2017-10-23T19:03:37Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b724494
- Parents:
- e160bfe8
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
re160bfe8 r327f147 33 33 */ 34 34 35 #include <adt/hash_table.h>36 #include <adt/hash.h>37 35 #include <usb/host/utils/malloc32.h> 38 36 #include <usb/host/ddf_helpers.h> … … 50 48 #include "endpoint.h" 51 49 #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);64 50 65 51 /** TODO: Still some copy-pasta left... … … 94 80 bus->devices_by_slot[xhci_dev->slot_id] = xhci_dev; 95 81 96 hashed_device_t *hashed_dev = NULL;97 if ((err = hashed_device_insert(bus, &hashed_dev, xhci_dev)))98 goto err_address;99 100 82 /* Read the device descriptor, derive the match ids */ 101 83 if ((err = hcd_ddf_device_explore(hc->hcd, dev))) { 102 84 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 111 90 err_address: 112 91 bus_release_address(&bus->base, dev->address); … … 127 106 } 128 107 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 138 108 // XXX: Ugly here. Move to device_destroy at endpoint.c? 139 109 free32(xhci_dev->dev_ctx); … … 193 163 xhci_endpoint_fini(xhci_ep); 194 164 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;245 165 } 246 166 … … 273 193 } 274 194 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) 195 static 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) 283 201 return NULL; 284 202 … … 345 263 }; 346 264 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 = NULL371 };372 373 265 int xhci_bus_init(xhci_bus_t *bus, xhci_hc_t *hc) 374 266 { … … 381 273 return ENOMEM; 382 274 383 if (!hash_table_create(&bus->devices, 0, 0, &device_ht_ops)) {384 free(bus->devices_by_slot);385 return ENOMEM;386 }387 388 275 bus->base.ops = xhci_bus_ops; 389 276 return EOK; … … 392 279 void xhci_bus_fini(xhci_bus_t *bus) 393 280 { 394 // FIXME: Make sure no devices are in the hash table. 395 396 hash_table_destroy(&bus->devices); 281 397 282 } 398 283 -
uspace/drv/bus/usb/xhci/bus.h
re160bfe8 r327f147 38 38 #define XHCI_BUS_H 39 39 40 #include <adt/hash_table.h>41 40 #include <usb/usb.h> 42 41 #include <usb/host/bus.h> … … 50 49 51 50 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 */55 51 } xhci_bus_t; 56 52
Note:
See TracChangeset
for help on using the changeset viewer.