Changeset 83c3123 in mainline
- Timestamp:
- 2011-10-27T11:40:06Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7265558
- Parents:
- 4267908
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/vhc/connhost.c
r4267908 r83c3123 143 143 VHC_DATA(vhc, fun); 144 144 145 endpoint_t *ep = endpoint_ get(146 address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1 );145 endpoint_t *ep = endpoint_create( 146 address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1, 0); 147 147 if (ep == NULL) { 148 148 return ENOMEM; … … 414 414 415 415 endpoint_t *ep = usb_endpoint_manager_get_ep(&vhc->ep_manager, 416 target.address, target.endpoint, USB_DIRECTION_IN , NULL);416 target.address, target.endpoint, USB_DIRECTION_IN); 417 417 if (ep == NULL) { 418 418 return ENOENT; … … 456 456 457 457 endpoint_t *ep = usb_endpoint_manager_get_ep(&vhc->ep_manager, 458 target.address, target.endpoint, USB_DIRECTION_OUT , NULL);458 target.address, target.endpoint, USB_DIRECTION_OUT); 459 459 if (ep == NULL) { 460 460 return ENOENT; -
uspace/lib/usbhost/include/usb/host/endpoint.h
r4267908 r83c3123 36 36 #define LIBUSBHOST_HOST_ENDPOINT_H 37 37 38 #include <assert.h>39 38 #include <bool.h> 40 39 #include <adt/list.h> 41 40 #include <fibril_synch.h> 42 43 41 #include <usb/usb.h> 44 42 45 43 typedef struct endpoint { 44 link_t link; 46 45 usb_address_t address; 47 46 usb_endpoint_t endpoint; … … 50 49 usb_speed_t speed; 51 50 size_t max_packet_size; 51 size_t bandwidth; 52 52 unsigned toggle:1; 53 53 fibril_mutex_t guard; … … 62 62 } endpoint_t; 63 63 64 endpoint_t * endpoint_ get(usb_address_t address, usb_endpoint_t endpoint,64 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint, 65 65 usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed, 66 size_t max_packet_size); 67 66 size_t max_packet_size, size_t bw); 68 67 void endpoint_destroy(endpoint_t *instance); 69 68 … … 71 70 void *data, void (*destroy_hook)(endpoint_t *), 72 71 int (*toggle_get)(void *), void (*toggle_set)(void *, int)); 73 74 72 void endpoint_clear_hc_data(endpoint_t *instance); 75 73 76 74 void endpoint_use(endpoint_t *instance); 77 78 75 void endpoint_release(endpoint_t *instance); 79 76 80 77 int endpoint_toggle_get(endpoint_t *instance); 81 82 78 void endpoint_toggle_set(endpoint_t *instance, int toggle); 83 84 79 void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target); 85 80 #endif -
uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h
r4267908 r83c3123 72 72 73 73 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance, 74 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction, 75 size_t *bw); 74 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction); 76 75 77 76 void usb_endpoint_manager_reset_if_need( … … 84 83 size_t data_size) 85 84 { 86 endpoint_t *ep = endpoint_get( 87 address, endpoint, direction, type, speed, max_packet_size); 85 assert(instance); 86 const size_t bw = 87 instance->bw_count(speed, type, data_size, max_packet_size); 88 89 endpoint_t *ep = endpoint_create( 90 address, endpoint, direction, type, speed, max_packet_size, bw); 88 91 if (!ep) 89 92 return ENOMEM; -
uspace/lib/usbhost/src/endpoint.c
r4267908 r83c3123 39 39 #include <usb/host/endpoint.h> 40 40 41 endpoint_t * endpoint_ get(usb_address_t address, usb_endpoint_t endpoint,41 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint, 42 42 usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed, 43 size_t max_packet_size )43 size_t max_packet_size, size_t bw) 44 44 { 45 45 endpoint_t *instance = malloc(sizeof(endpoint_t)); … … 51 51 instance->speed = speed; 52 52 instance->max_packet_size = max_packet_size; 53 instance->bandwidth = bw; 53 54 instance->toggle = 0; 54 55 instance->active = false; … … 57 58 instance->hc_data.toggle_get = NULL; 58 59 instance->hc_data.toggle_set = NULL; 60 link_initialize(&instance->link); 59 61 fibril_mutex_initialize(&instance->guard); 60 62 fibril_condvar_initialize(&instance->avail); -
uspace/lib/usbhost/src/iface.c
r4267908 r83c3123 49 49 assert(hcd); 50 50 51 int ret;52 53 size_t res_bw;54 51 endpoint_t *ep = usb_endpoint_manager_get_ep(&hcd->ep_manager, 55 target.address, target.endpoint, direction , &res_bw);52 target.address, target.endpoint, direction); 56 53 if (ep == NULL) { 57 54 usb_log_error("Endpoint(%d:%d) not registered for %s.\n", … … 65 62 const size_t bw = bandwidth_count_usb11( 66 63 ep->speed, ep->transfer_type, size, ep->max_packet_size); 67 if (res_bw < bw) { 64 /* Check if we have enough bandwidth reserved */ 65 if (ep->bandwidth < bw) { 68 66 usb_log_error("Endpoint(%d:%d) %s needs %zu bw " 69 67 "but only %zu is reserved.\n", 70 target.address, target.endpoint, name, bw, res_bw);68 ep->address, ep->endpoint, name, bw, ep->bandwidth); 71 69 return ENOSPC; 72 70 } … … 84 82 } 85 83 86 ret = hcd->schedule(hcd, batch);84 const int ret = hcd->schedule(hcd, batch); 87 85 if (ret != EOK) 88 86 usb_transfer_batch_dispose(batch); … … 190 188 max_packet_size, interval); 191 189 192 endpoint_t *ep = endpoint_get( 193 address, endpoint, direction, transfer_type, speed, max_packet_size); 190 endpoint_t *ep = 191 endpoint_create(address, endpoint, direction, transfer_type, 192 speed, max_packet_size, 0); 194 193 if (!ep) 195 194 return ENOMEM; -
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.