Changeset 1102eca in mainline for uspace/lib/usbhost/src/bus.c
- Timestamp:
- 2018-01-08T17:17:38Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bdd8842c
- Parents:
- eb928c4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/bus.c
reb928c4 r1102eca 32 32 /** @file 33 33 * 34 * The Bus is a structure that serves as an interface of the HC driver 35 * implementation for the usbhost library. Every HC driver that uses libusbhost 36 * must use a bus_t (or its child), fill it with bus_ops and present it to the 37 * library. The library then handles the DDF interface and translates it to the 38 * bus callbacks. 34 39 */ 35 40 … … 44 49 45 50 /** 46 * Initializes the b us structure.51 * Initializes the base bus structure. 47 52 */ 48 53 void bus_init(bus_t *bus, size_t device_size) … … 57 62 } 58 63 64 /** 65 * Initialize the device_t structure belonging to a bus. 66 */ 59 67 int bus_device_init(device_t *dev, bus_t *bus) 60 68 { … … 72 80 } 73 81 82 /** 83 * Create a name of the ddf function node. 84 */ 74 85 int bus_device_set_default_name(device_t *dev) 75 86 { … … 84 95 } 85 96 97 /** 98 * Invoke the device_enumerate bus operation. 99 */ 86 100 int bus_device_enumerate(device_t *dev) 87 101 { … … 95 109 } 96 110 111 /** 112 * Invoke the device_remove bus operation. 113 */ 97 114 int bus_device_remove(device_t *dev) 98 115 { … … 106 123 } 107 124 125 /** 126 * Invoke the device_online bus operation. 127 */ 108 128 int bus_device_online(device_t *dev) 109 129 { … … 117 137 } 118 138 139 /** 140 * Invoke the device_offline bus operation. 141 */ 119 142 int bus_device_offline(device_t *dev) 120 143 { … … 128 151 } 129 152 153 /** 154 * Create and register new endpoint to the bus. 155 * 156 * @param[in] device The device of which the endpoint shall be created 157 * @param[in] desc Endpoint descriptors as reported by the device 158 * @param[out] out_ep The resulting new endpoint reference, if any. Can be NULL. 159 */ 130 160 int bus_endpoint_add(device_t *device, const usb_endpoint_descriptors_t *desc, endpoint_t **out_ep) 131 161 { … … 135 165 bus_t *bus = device->bus; 136 166 167 const bus_ops_t *register_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_register); 168 if (!register_ops) 169 return ENOTSUP; 170 137 171 const bus_ops_t *create_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_create); 138 const bus_ops_t *register_ops = BUS_OPS_LOOKUP(bus->ops, endpoint_register); 139 if (!create_ops || !register_ops) 140 return ENOTSUP; 141 142 endpoint_t *ep = create_ops->endpoint_create(device, desc); 143 if (!ep) 144 return ENOMEM; 172 endpoint_t *ep; 173 if (create_ops) { 174 ep = create_ops->endpoint_create(device, desc); 175 if (!ep) 176 return ENOMEM; 177 } else { 178 ep = calloc(1, sizeof(endpoint_t)); 179 if (!ep) 180 return ENOMEM; 181 endpoint_init(ep, device, desc); 182 } 145 183 146 184 /* Bus reference */ … … 186 224 } 187 225 188 /** Searches for an endpoint. Returns a reference. 226 /** 227 * Search for an endpoint. Returns a reference. 189 228 */ 190 229 endpoint_t *bus_find_endpoint(device_t *device, usb_endpoint_t endpoint) … … 204 243 } 205 244 245 /** 246 * Remove an endpoint from the device. Consumes a reference. 247 */ 206 248 int bus_endpoint_remove(endpoint_t *ep) 207 249 { … … 233 275 endpoint_del_ref(ep); 234 276 277 /* Given reference */ 278 endpoint_del_ref(ep); 279 235 280 return EOK; 236 281 } 237 282 283 /** 284 * Reserve the default address on the bus. Also, report the speed of the device 285 * that is listening on the default address. 286 * 287 * The speed is then used for devices enumerated while the address is reserved. 288 */ 238 289 int bus_reserve_default_address(bus_t *bus, usb_speed_t speed) 239 290 { … … 251 302 } 252 303 304 /** 305 * Release the default address. 306 */ 253 307 void bus_release_default_address(bus_t *bus) 254 308 { … … 257 311 } 258 312 259 /** Prepare generic usb_transfer_batch and schedule it. 313 /** 314 * Initiate a transfer on the bus. Finds the target endpoint, creates 315 * a transfer batch and schedules it. 316 * 260 317 * @param device Device for which to send the batch 261 * @param target address and endpoint number. 262 * @param setup_data Data to use in setup stage (Control communication type) 263 * @param in Callback for device to host communication. 264 * @param out Callback for host to device communication. 318 * @param target The target of the transfer. 319 * @param direction A direction of the transfer. 320 * @param data A pointer to the data buffer. 321 * @param size Size of the data buffer. 322 * @param setup_data Data to use in the setup stage (Control communication type) 323 * @param on_complete Callback which is called after the batch is complete 265 324 * @param arg Callback parameter. 266 325 * @param name Communication identifier (for nicer output). … … 301 360 } sync_data_t; 302 361 362 /** 363 * Callback for finishing the transfer. Wake the issuing thread. 364 */ 303 365 static int sync_transfer_complete(void *arg, int error, size_t transfered_size) 304 366 { … … 314 376 } 315 377 378 /** 379 * Issue a transfer on the bus, wait for result. 380 * 381 * @param device Device for which to send the batch 382 * @param target The target of the transfer. 383 * @param direction A direction of the transfer. 384 * @param data A pointer to the data buffer. 385 * @param size Size of the data buffer. 386 * @param setup_data Data to use in the setup stage (Control communication type) 387 * @param name Communication identifier (for nicer output). 388 */ 316 389 ssize_t bus_device_send_batch_sync(device_t *device, usb_target_t target, 317 390 usb_direction_t direction, char *data, size_t size, uint64_t setup_data, … … 330 403 fibril_mutex_lock(&sd.done_mtx); 331 404 while (!sd.done) { 332 fibril_condvar_wait_timeout(&sd.done_cv, &sd.done_mtx, 3000000); 333 if (!sd.done) 334 usb_log_debug2("Still waiting..."); 405 fibril_condvar_wait(&sd.done_cv, &sd.done_mtx); 335 406 } 336 407 fibril_mutex_unlock(&sd.done_mtx);
Note:
See TracChangeset
for help on using the changeset viewer.