Changeset 83c3123 in mainline for uspace/lib/usbhost/src/usb_endpoint_manager.c
- Timestamp:
- 2011-10-27T11:40:06Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7265558
- Parents:
- 4267908
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/usb_endpoint_manager.c
r4267908 r83c3123 35 35 36 36 #define BUCKET_COUNT 7 37 38 37 #define MAX_KEYS (3) 39 typedef struct { 40 link_t link; 41 size_t bw; 42 endpoint_t *ep; 43 } node_t; 44 /*----------------------------------------------------------------------------*/ 45 static hash_index_t node_hash(unsigned long key[]) 38 39 static hash_index_t usb_hash(unsigned long key[]) 46 40 { 47 41 /* USB endpoints use 4 bits, thus ((key[0] << 4) | key[1]) … … 50 44 } 51 45 /*----------------------------------------------------------------------------*/ 52 static int node_compare(unsigned long key[], hash_count_t keys, link_t *item)46 static int ep_compare(unsigned long key[], hash_count_t keys, link_t *item) 53 47 { 54 48 assert(item); 55 node_t *node = hash_table_get_instance(item, node_t, link); 56 assert(node); 57 assert(node->ep); 49 endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link); 50 assert(ep); 58 51 bool match = true; 59 52 switch (keys) { 60 53 case 3: 61 54 match = match && 62 ((key[2] == node->ep->direction) 63 || (node->ep->direction == USB_DIRECTION_BOTH)); 55 ((key[2] == ep->direction) 56 || (ep->direction == USB_DIRECTION_BOTH) 57 || (key[2] == USB_DIRECTION_BOTH)); 64 58 case 2: 65 match = match && (key[1] == (unsigned long) node->ep->endpoint);59 match = match && (key[1] == (unsigned long)ep->endpoint); 66 60 case 1: 67 match = match && (key[0] == (unsigned long) node->ep->address);61 match = match && (key[0] == (unsigned long)ep->address); 68 62 break; 69 63 default: … … 73 67 } 74 68 /*----------------------------------------------------------------------------*/ 75 static void node_remove(link_t *item)69 static void ep_remove(link_t *item) 76 70 { 77 71 assert(item); 78 node_t *node = hash_table_get_instance(item, node_t, link); 79 endpoint_destroy(node->ep); 80 free(node); 81 } 82 /*----------------------------------------------------------------------------*/ 83 static void node_toggle_reset_filtered(link_t *item, void *arg) 72 endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link); 73 endpoint_destroy(ep); 74 } 75 /*----------------------------------------------------------------------------*/ 76 static void toggle_reset_filtered(link_t *item, void *arg) 84 77 { 85 78 assert(item); 86 node_t *node = hash_table_get_instance(item, node_t, link);87 usb_target_t *target = arg;88 endpoint_toggle_reset_filtered( node->ep, *target);79 endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link); 80 const usb_target_t *target = arg; 81 endpoint_toggle_reset_filtered(ep, *target); 89 82 } 90 83 /*----------------------------------------------------------------------------*/ 91 84 static hash_table_operations_t op = { 92 .hash = node_hash,93 .compare = node_compare,94 .remove_callback = node_remove,85 .hash = usb_hash, 86 .compare = ep_compare, 87 .remove_callback = ep_remove, 95 88 }; 96 89 /*----------------------------------------------------------------------------*/ … … 161 154 assert(instance->bw_count); 162 155 assert(ep); 163 const size_t bw= instance->bw_count(ep->speed, ep->transfer_type,156 ep->bandwidth = instance->bw_count(ep->speed, ep->transfer_type, 164 157 data_size, ep->max_packet_size); 165 158 166 159 fibril_mutex_lock(&instance->guard); 167 160 168 if ( bw> instance->free_bw) {161 if (ep->bandwidth > instance->free_bw) { 169 162 fibril_mutex_unlock(&instance->guard); 170 163 return ENOSPC; … … 181 174 } 182 175 183 node_t *node = malloc(sizeof(node_t)); 184 if (node == NULL) { 185 fibril_mutex_unlock(&instance->guard); 186 return ENOMEM; 187 } 188 189 node->bw = bw; 190 node->ep = ep; 191 link_initialize(&node->link); 192 193 hash_table_insert(&instance->ep_table, key, &node->link); 194 instance->free_bw -= bw; 176 hash_table_insert(&instance->ep_table, key, &ep->link); 177 instance->free_bw -= ep->bandwidth; 195 178 fibril_mutex_unlock(&instance->guard); 196 179 return EOK; … … 210 193 } 211 194 212 node_t *node = hash_table_get_instance(item, node_t, link);213 if ( node->ep->active) {195 endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link); 196 if (ep->active) { 214 197 fibril_mutex_unlock(&instance->guard); 215 198 return EBUSY; 216 199 } 217 200 218 instance->free_bw += node->bw;201 instance->free_bw += ep->bandwidth; 219 202 hash_table_remove(&instance->ep_table, key, MAX_KEYS); 220 203 … … 224 207 /*----------------------------------------------------------------------------*/ 225 208 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance, 226 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 227 size_t *bw) 209 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction) 228 210 { 229 211 assert(instance); … … 236 218 return NULL; 237 219 } 238 const node_t *node = hash_table_get_instance(item, node_t, link); 239 if (bw) 240 *bw = node->bw; 220 endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link); 241 221 242 222 fibril_mutex_unlock(&instance->guard); 243 return node->ep;223 return ep; 244 224 } 245 225 /*----------------------------------------------------------------------------*/ … … 272 252 fibril_mutex_lock(&instance->guard); 273 253 hash_table_apply(&instance->ep_table, 274 node_toggle_reset_filtered, &reset_target);254 toggle_reset_filtered, &reset_target); 275 255 fibril_mutex_unlock(&instance->guard); 276 256 } … … 285 265 fibril_mutex_lock(&instance->guard); 286 266 hash_table_apply(&instance->ep_table, 287 node_toggle_reset_filtered, &reset_target);267 toggle_reset_filtered, &reset_target); 288 268 fibril_mutex_unlock(&instance->guard); 289 269 }
Note:
See TracChangeset
for help on using the changeset viewer.