Changeset a8435eb5 in mainline
- Timestamp:
- 2017-10-12T16:42:26Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0e3e1f6
- Parents:
- f9d787c
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
rf9d787c ra8435eb5 33 33 */ 34 34 35 #include <adt/hash_table.h> 36 #include <adt/hash.h> 35 37 #include <usb/host/endpoint.h> 36 38 #include <usb/debug.h> … … 44 46 #include "endpoint.h" 45 47 48 /** Element of the hash table. */ 49 typedef struct { 50 ht_link_t link; 51 52 /** Endpoint */ 53 endpoint_t *endpoint; 54 } hashed_endpoint_t; 55 46 56 /** Ops receive generic bus_t pointer. */ 47 57 static inline xhci_bus_t *bus_to_xhci_bus(bus_t *bus_base) … … 75 85 } 76 86 87 static int endpoint_find_by_target(xhci_bus_t *bus, usb_target_t target, hashed_endpoint_t **ep) 88 { 89 ht_link_t *link = hash_table_find(&bus->endpoints, &target.packed); 90 if (link == NULL) 91 return ENOENT; 92 93 *ep = hash_table_get_inst(link, hashed_endpoint_t, link); 94 return EOK; 95 } 96 77 97 static int register_endpoint(bus_t *bus_base, endpoint_t *ep) 78 98 { 79 // TODO: Implement me! 80 return ENOTSUP; 99 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 100 assert(bus); 101 102 hashed_endpoint_t *hashed_ep = 103 (hashed_endpoint_t *) malloc(sizeof(hashed_endpoint_t)); 104 if (!hashed_ep) 105 return ENOMEM; 106 107 hashed_ep->endpoint = ep; 108 hash_table_insert(&bus->endpoints, &hashed_ep->link); 109 110 return EOK; 81 111 } 82 112 83 113 static int release_endpoint(bus_t *bus_base, endpoint_t *ep) 84 114 { 85 // TODO: Implement me! 86 return ENOTSUP; 115 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 116 assert(bus); 117 118 hashed_endpoint_t *hashed_ep; 119 int res = endpoint_find_by_target(bus, ep->target, &hashed_ep); 120 if (res != EOK) 121 return res; 122 123 hash_table_remove(&bus->endpoints, &ep->target.packed); 124 free(hashed_ep); 125 126 return EOK; 87 127 } 88 128 89 129 static endpoint_t* find_endpoint(bus_t *bus_base, usb_target_t target, usb_direction_t direction) 90 130 { 91 // TODO: Implement me! 92 return NULL; 131 xhci_bus_t *bus = bus_to_xhci_bus(bus_base); 132 assert(bus); 133 134 hashed_endpoint_t *hashed_ep; 135 int res = endpoint_find_by_target(bus, target, &hashed_ep); 136 if (res != EOK) 137 return NULL; 138 139 return hashed_ep->endpoint; 93 140 } 94 141 … … 154 201 }; 155 202 203 static size_t endpoint_ht_hash(const ht_link_t *item) 204 { 205 hashed_endpoint_t *ep = hash_table_get_inst(item, hashed_endpoint_t, link); 206 return (size_t) ep->endpoint->target.packed; 207 } 208 209 static size_t endpoint_ht_key_hash(void *key) 210 { 211 return (size_t) hash_mix32(*(uint32_t *)key); 212 } 213 214 static bool endpoint_ht_key_equal(void *key, const ht_link_t *item) 215 { 216 hashed_endpoint_t *ep = hash_table_get_inst(item, hashed_endpoint_t, link); 217 return ep->endpoint->target.packed == *(uint32_t *) key; 218 } 219 220 /** Operations for the endpoint hash table. */ 221 static hash_table_ops_t endpoint_ht_ops = { 222 .hash = endpoint_ht_hash, 223 .key_hash = endpoint_ht_key_hash, 224 .key_equal = endpoint_ht_key_equal, 225 .equal = NULL, 226 .remove_callback = NULL 227 }; 228 156 229 int xhci_bus_init(xhci_bus_t *bus, hcd_t *hcd) 157 230 { … … 160 233 bus_init(&bus->base, hcd); 161 234 235 if (!hash_table_create(&bus->endpoints, 0, 0, &endpoint_ht_ops)) { 236 // FIXME: Dealloc base! 237 return ENOMEM; 238 } 239 162 240 bus->base.ops = xhci_bus_ops; 163 241 return EOK; 242 } 243 244 void xhci_bus_fini(xhci_bus_t *bus) 245 { 246 hash_table_destroy(&bus->endpoints); 164 247 } 165 248 /** -
uspace/drv/bus/usb/xhci/bus.h
rf9d787c ra8435eb5 38 38 #define XHCI_BUS_H 39 39 40 #include <adt/hash_table.h> 40 41 #include <usb/usb.h> 41 42 #include <usb/host/bus.h> … … 50 51 * addresses can be just too big. 51 52 */ 53 54 hash_table_t endpoints; 52 55 } xhci_bus_t; 53 56 54 int xhci_bus_init(xhci_bus_t *, hcd_t *hcd); 57 int xhci_bus_init(xhci_bus_t *, hcd_t *); 58 void xhci_bus_fini(xhci_bus_t *); 55 59 56 60 #endif -
uspace/drv/bus/usb/xhci/main.c
rf9d787c ra8435eb5 150 150 151 151 hc_fini(hc); 152 153 // FIXME: Probably move init/fini of XHCI bus into HC. 154 xhci_bus_fini(&hc->bus); 155 152 156 free(hc); 153 157 }
Note:
See TracChangeset
for help on using the changeset viewer.