Changeset 48ae3ef in mainline
- Timestamp:
- 2011-10-28T21:52:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 57e06ef
- Parents:
- 7265558
- Location:
- uspace
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/hc.c
r7265558 r48ae3ef 142 142 if (ret != EOK) { \ 143 143 usb_log_error(message); \ 144 usb_endpoint_manager_unregister_ep( \ 145 &instance->generic.ep_manager, hub_address, 0, USB_DIRECTION_BOTH);\ 144 usb_endpoint_manager_remove_ep( \ 145 &instance->generic.ep_manager, hub_address, 0, USB_DIRECTION_BOTH, \ 146 NULL, NULL);\ 146 147 usb_device_manager_release( \ 147 148 &instance->generic.dev_manager, hub_address); \ … … 150 151 int ret = usb_endpoint_manager_add_ep( 151 152 &instance->generic.ep_manager, hub_address, 0, USB_DIRECTION_BOTH, 152 USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64, 0 );153 USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64, 0, NULL, NULL); 153 154 CHECK_RET_UNREG_RETURN(ret, 154 155 "Failed to register root hub control endpoint: %s.\n", … … 197 198 instance->generic.schedule = hc_schedule; 198 199 instance->generic.ep_add_hook = ohci_endpoint_init; 200 instance->generic.ep_remove_hook = ohci_endpoint_fini; 199 201 200 202 ret = hc_init_memory(instance); -
uspace/drv/bus/usb/ohci/ohci_endpoint.c
r7265558 r48ae3ef 62 62 } 63 63 /*----------------------------------------------------------------------------*/ 64 /** Disposes hcd endpoint structure65 *66 * @param[in] hcd_ep endpoint structure67 */68 static void ohci_endpoint_fini(endpoint_t *ep)69 {70 ohci_endpoint_t *instance = ep->hc_data.data;71 hc_dequeue_endpoint(instance->hcd->private_data, ep);72 if (instance) {73 free32(instance->ed);74 free32(instance->td);75 free(instance);76 }77 }78 /*----------------------------------------------------------------------------*/79 64 /** Creates new hcd endpoint representation. 80 65 * … … 104 89 ed_init(ohci_ep->ed, ep, ohci_ep->td); 105 90 endpoint_set_hc_data( 106 ep, ohci_ep, ohci_e ndpoint_fini, ohci_ep_toggle_get, ohci_ep_toggle_set);91 ep, ohci_ep, ohci_ep_toggle_get, ohci_ep_toggle_set); 107 92 ohci_ep->hcd = hcd; 108 93 hc_enqueue_endpoint(hcd->private_data, ep); 109 94 return EOK; 110 95 } 96 /*----------------------------------------------------------------------------*/ 97 /** Disposes hcd endpoint structure 98 * 99 * @param[in] hcd_ep endpoint structure 100 */ 101 void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep) 102 { 103 assert(hcd); 104 assert(ep); 105 ohci_endpoint_t *instance = ohci_endpoint_get(ep); 106 hc_dequeue_endpoint(hcd->private_data, ep); 107 if (instance) { 108 free32(instance->ed); 109 free32(instance->td); 110 free(instance); 111 } 112 endpoint_clear_hc_data(ep); 113 } 111 114 /** 112 115 * @} -
uspace/drv/bus/usb/ohci/ohci_endpoint.h
r7265558 r48ae3ef 56 56 57 57 int ohci_endpoint_init(hcd_t *hcd, endpoint_t *ep); 58 void ohci_endpoint_fini(hcd_t *hcd, endpoint_t *ep); 58 59 59 60 /** Get and convert assigned ohci_endpoint_t structure -
uspace/drv/bus/usb/vhc/connhost.c
r7265558 r48ae3ef 140 140 size_t max_packet_size, unsigned int interval) 141 141 { 142 /* TODO: Use usb_endpoint_manager_add_ep */ 143 VHC_DATA(vhc, fun); 144 145 endpoint_t *ep = endpoint_create( 146 address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1, 0); 147 if (ep == NULL) { 148 return ENOMEM; 149 } 150 151 int rc = usb_endpoint_manager_register_ep(&vhc->ep_manager, ep, 1); 152 if (rc != EOK) { 153 endpoint_destroy(ep); 154 return rc; 155 } 156 157 return EOK; 142 VHC_DATA(vhc, fun); 143 144 return usb_endpoint_manager_add_ep(&vhc->ep_manager, 145 address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1, 0, 146 NULL, NULL); 147 158 148 } 159 149 … … 171 161 VHC_DATA(vhc, fun); 172 162 173 int rc = usb_endpoint_manager_ unregister_ep(&vhc->ep_manager,174 address, endpoint, direction );163 int rc = usb_endpoint_manager_remove_ep(&vhc->ep_manager, 164 address, endpoint, direction, NULL, NULL); 175 165 176 166 return rc; … … 413 403 VHC_DATA(vhc, fun); 414 404 415 endpoint_t *ep = usb_endpoint_manager_ get_ep(&vhc->ep_manager,405 endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager, 416 406 target.address, target.endpoint, USB_DIRECTION_IN); 417 407 if (ep == NULL) { … … 455 445 VHC_DATA(vhc, fun); 456 446 457 endpoint_t *ep = usb_endpoint_manager_ get_ep(&vhc->ep_manager,447 endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager, 458 448 target.address, target.endpoint, USB_DIRECTION_OUT); 459 449 if (ep == NULL) { -
uspace/lib/usbhost/include/usb/host/endpoint.h
r7265558 r48ae3ef 54 54 fibril_condvar_t avail; 55 55 volatile bool active; 56 void (*destroy_hook)(struct endpoint *);57 56 struct { 58 57 void *data; … … 68 67 69 68 void endpoint_set_hc_data(endpoint_t *instance, 70 void *data, void (*destroy_hook)(endpoint_t *), 71 int (*toggle_get)(void *), void (*toggle_set)(void *, int)); 69 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)); 72 70 void endpoint_clear_hc_data(endpoint_t *instance); 73 71 -
uspace/lib/usbhost/include/usb/host/hcd.h
r7265558 r48ae3ef 51 51 int (*schedule)(hcd_t *, usb_transfer_batch_t *); 52 52 int (*ep_add_hook)(hcd_t *, endpoint_t *); 53 void (*ep_remove_hook)(hcd_t *, endpoint_t *); 53 54 }; 54 55 /*----------------------------------------------------------------------------*/ … … 65 66 { 66 67 assert(hcd); 67 usb_endpoint_manager_reset_ if_need(68 usb_endpoint_manager_reset_eps_if_need( 68 69 &hcd->ep_manager, target, (const uint8_t *)setup_data); 69 70 } -
uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h
r7265558 r48ae3ef 64 64 size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t)); 65 65 66 void usb_endpoint_manager_destroy(usb_endpoint_manager_t *instance); 66 void usb_endpoint_manager_reset_eps_if_need( 67 usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data); 67 68 68 int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance, 69 endpoint_t *ep, size_t data_size); 70 71 int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance, 69 int usb_endpoint_manager_register_ep( 70 usb_endpoint_manager_t *instance, endpoint_t *ep, size_t data_size); 71 int usb_endpoint_manager_unregister_ep( 72 usb_endpoint_manager_t *instance, endpoint_t *ep); 73 endpoint_t * usb_endpoint_manager_find_ep(usb_endpoint_manager_t *instance, 72 74 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction); 73 75 74 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance, 75 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction); 76 77 void usb_endpoint_manager_reset_if_need( 78 usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data); 79 80 /** Wrapper combining allocation and insertion */ 81 static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance, 76 int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance, 82 77 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 83 78 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size, 84 size_t data_size) 85 { 86 assert(instance); 87 const size_t bw = 88 instance->bw_count(speed, type, data_size, max_packet_size); 79 size_t data_size, int (*callback)(endpoint_t *, void *), void *arg); 89 80 90 endpoint_t *ep = endpoint_create( 91 address, endpoint, direction, type, speed, max_packet_size, bw); 92 if (!ep) 93 return ENOMEM; 94 95 const int ret = 96 usb_endpoint_manager_register_ep(instance, ep, data_size); 97 if (ret != EOK) { 98 endpoint_destroy(ep); 99 } 100 return ret; 101 } 81 int usb_endpoint_manager_remove_ep(usb_endpoint_manager_t *instance, 82 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 83 void (*callback)(endpoint_t *, void *), void *arg); 102 84 #endif 103 85 /** 104 86 * @} 105 87 */ 106 -
uspace/lib/usbhost/src/endpoint.c
r7265558 r48ae3ef 54 54 instance->toggle = 0; 55 55 instance->active = false; 56 instance->destroy_hook = NULL;57 56 instance->hc_data.data = NULL; 58 57 instance->hc_data.toggle_get = NULL; … … 70 69 assert(instance); 71 70 assert(!instance->active); 72 if (instance->hc_data.data) { 73 assert(instance->destroy_hook); 74 instance->destroy_hook(instance); 75 } 71 assert(instance->hc_data.data == NULL); 76 72 free(instance); 77 73 } 78 74 /*----------------------------------------------------------------------------*/ 79 75 void endpoint_set_hc_data(endpoint_t *instance, 80 void *data, void (*destroy_hook)(endpoint_t *), 81 int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 76 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int)) 82 77 { 83 78 assert(instance); 84 instance->destroy_hook = destroy_hook;85 79 instance->hc_data.data = data; 86 80 instance->hc_data.toggle_get = toggle_get; … … 91 85 { 92 86 assert(instance); 93 instance->destroy_hook = NULL;94 87 instance->hc_data.data = NULL; 95 88 instance->hc_data.toggle_get = NULL; -
uspace/lib/usbhost/src/iface.c
r7265558 r48ae3ef 49 49 assert(hcd); 50 50 51 endpoint_t *ep = usb_endpoint_manager_ get_ep(&hcd->ep_manager,51 endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager, 52 52 target.address, target.endpoint, direction); 53 53 if (ep == NULL) { … … 165 165 } 166 166 /*----------------------------------------------------------------------------*/ 167 static int register_helper(endpoint_t *ep, void *arg) 168 { 169 hcd_t *hcd = arg; 170 assert(ep); 171 assert(hcd); 172 if (hcd->ep_add_hook) 173 return hcd->ep_add_hook(hcd, ep); 174 return EOK; 175 } 176 /*----------------------------------------------------------------------------*/ 177 static void unregister_helper(endpoint_t *ep, void *arg) 178 { 179 hcd_t *hcd = arg; 180 assert(ep); 181 assert(hcd); 182 if (hcd->ep_remove_hook) 183 hcd->ep_remove_hook(hcd, ep); 184 } 185 /*----------------------------------------------------------------------------*/ 167 186 static int register_endpoint( 168 187 ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed, … … 188 207 max_packet_size, interval); 189 208 190 endpoint_t *ep = 191 endpoint_create(address, endpoint, direction, transfer_type, 192 speed, max_packet_size, 0); 193 if (!ep) 194 return ENOMEM; 195 196 if (hcd->ep_add_hook) { 197 const int ret = hcd->ep_add_hook(hcd, ep); 198 if (ret != EOK) { 199 endpoint_destroy(ep); 200 return ret; 201 } 202 } 203 204 const int ret = 205 usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size); 206 if (ret != EOK) { 207 endpoint_destroy(ep); 208 } 209 return ret; 209 return usb_endpoint_manager_add_ep(&hcd->ep_manager, address, endpoint, 210 direction, transfer_type, speed, max_packet_size, size, 211 register_helper, hcd); 210 212 } 211 213 /*----------------------------------------------------------------------------*/ … … 219 221 usb_log_debug("Unregister endpoint %d:%d %s.\n", 220 222 address, endpoint, usb_str_direction(direction)); 221 return usb_endpoint_manager_ unregister_ep(&hcd->ep_manager, address,222 endpoint, direction );223 return usb_endpoint_manager_remove_ep(&hcd->ep_manager, address, 224 endpoint, direction, unregister_helper, hcd); 223 225 } 224 226 /*----------------------------------------------------------------------------*/ -
uspace/lib/usbhost/src/usb_endpoint_manager.c
r7265558 r48ae3ef 120 120 } 121 121 /*----------------------------------------------------------------------------*/ 122 int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance,123 endpoint_t *ep, size_t data_size)124 {125 assert(instance);126 assert(instance->bw_count);127 assert(ep);128 ep->bandwidth = instance->bw_count(ep->speed, ep->transfer_type,129 data_size, ep->max_packet_size);130 131 fibril_mutex_lock(&instance->guard);132 133 if (ep->bandwidth > instance->free_bw) {134 fibril_mutex_unlock(&instance->guard);135 return ENOSPC;136 }137 138 /* Check for existence */139 const endpoint_t *endpoint =140 find_locked(instance, ep->address, ep->endpoint, ep->direction);141 if (endpoint != NULL) {142 fibril_mutex_unlock(&instance->guard);143 return EEXISTS;144 }145 list_t *list = get_list(instance, ep->address);146 list_append(&ep->link, list);147 148 instance->free_bw -= ep->bandwidth;149 fibril_mutex_unlock(&instance->guard);150 return EOK;151 }152 /*----------------------------------------------------------------------------*/153 int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance,154 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction)155 {156 assert(instance);157 158 fibril_mutex_lock(&instance->guard);159 endpoint_t *ep = find_locked(instance, address, endpoint, direction);160 if (ep != NULL) {161 list_remove(&ep->link);162 instance->free_bw += ep->bandwidth;163 }164 165 fibril_mutex_unlock(&instance->guard);166 endpoint_destroy(ep);167 return (ep != NULL) ? EOK : EINVAL;168 }169 /*----------------------------------------------------------------------------*/170 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,171 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction)172 {173 assert(instance);174 175 fibril_mutex_lock(&instance->guard);176 endpoint_t *ep = find_locked(instance, address, endpoint, direction);177 fibril_mutex_unlock(&instance->guard);178 179 return ep;180 }181 /*----------------------------------------------------------------------------*/182 122 /** Check setup packet data for signs of toggle reset. 183 123 * … … 188 128 * Really ugly one. 189 129 */ 190 void usb_endpoint_manager_reset_ if_need(130 void usb_endpoint_manager_reset_eps_if_need( 191 131 usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data) 192 132 { … … 234 174 } 235 175 } 176 /*----------------------------------------------------------------------------*/ 177 int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance, 178 endpoint_t *ep, size_t data_size) 179 { 180 assert(instance); 181 assert(instance->bw_count); 182 assert(ep); 183 fibril_mutex_lock(&instance->guard); 184 185 if (ep->bandwidth > instance->free_bw) { 186 fibril_mutex_unlock(&instance->guard); 187 return ENOSPC; 188 } 189 190 /* Check for existence */ 191 const endpoint_t *endpoint = 192 find_locked(instance, ep->address, ep->endpoint, ep->direction); 193 if (endpoint != NULL) { 194 fibril_mutex_unlock(&instance->guard); 195 return EEXISTS; 196 } 197 list_t *list = get_list(instance, ep->address); 198 list_append(&ep->link, list); 199 200 instance->free_bw -= ep->bandwidth; 201 fibril_mutex_unlock(&instance->guard); 202 return EOK; 203 } 204 /*----------------------------------------------------------------------------*/ 205 int usb_endpoint_manager_unregister_ep( 206 usb_endpoint_manager_t *instance, endpoint_t *ep) 207 { 208 assert(instance); 209 if (ep == NULL) 210 return ENOENT; 211 fibril_mutex_lock(&instance->guard); 212 list_remove(&ep->link); 213 fibril_mutex_unlock(&instance->guard); 214 return EOK; 215 } 216 /*----------------------------------------------------------------------------*/ 217 endpoint_t * usb_endpoint_manager_find_ep(usb_endpoint_manager_t *instance, 218 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction) 219 { 220 assert(instance); 221 222 fibril_mutex_lock(&instance->guard); 223 endpoint_t *ep = find_locked(instance, address, endpoint, direction); 224 fibril_mutex_unlock(&instance->guard); 225 226 return ep; 227 } 228 /*----------------------------------------------------------------------------*/ 229 int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance, 230 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 231 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size, 232 size_t data_size, int (*callback)(endpoint_t *, void *), void *arg) 233 { 234 assert(instance); 235 const size_t bw = 236 instance->bw_count(speed, type, data_size, max_packet_size); 237 238 endpoint_t *ep = endpoint_create( 239 address, endpoint, direction, type, speed, max_packet_size, bw); 240 if (!ep) 241 return ENOMEM; 242 243 if (callback) { 244 const int ret = callback(ep, arg); 245 if (ret != EOK) { 246 endpoint_destroy(ep); 247 return ret; 248 } 249 } 250 251 const int ret = 252 usb_endpoint_manager_register_ep(instance, ep, data_size); 253 if (ret != EOK) { 254 endpoint_destroy(ep); 255 } 256 return ret; 257 } 258 /*----------------------------------------------------------------------------*/ 259 int usb_endpoint_manager_remove_ep(usb_endpoint_manager_t *instance, 260 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 261 void (*callback)(endpoint_t *, void *), void *arg) 262 { 263 assert(instance); 264 fibril_mutex_lock(&instance->guard); 265 endpoint_t *ep = find_locked(instance, address, endpoint, direction); 266 if (ep != NULL) { 267 list_remove(&ep->link); 268 instance->free_bw += ep->bandwidth; 269 } 270 fibril_mutex_unlock(&instance->guard); 271 if (ep == NULL) 272 return ENOENT; 273 274 if (callback) { 275 callback(ep, arg); 276 } 277 endpoint_destroy(ep); 278 return EOK; 279 }
Note:
See TracChangeset
for help on using the changeset viewer.