Changes in uspace/drv/uhci-hcd/batch.c [17ceb72:a7e2f0d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
r17ceb72 ra7e2f0d 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbuhcihc28 /** @addtogroup usb 29 29 * @{ 30 30 */ 31 31 /** @file 32 * @brief UHCI driver USB transaction structure32 * @brief UHCI driver 33 33 */ 34 34 #include <errno.h> … … 40 40 #include "batch.h" 41 41 #include "transfer_list.h" 42 #include "uhci _hc.h"42 #include "uhci.h" 43 43 #include "utils/malloc32.h" 44 44 45 45 #define DEFAULT_ERROR_COUNT 3 46 47 static int batch_schedule(batch_t *instance); 46 48 47 49 static void batch_control(batch_t *instance, … … 52 54 static void batch_call_in_and_dispose(batch_t *instance); 53 55 static void batch_call_out_and_dispose(batch_t *instance); 54 55 56 /** Allocate memory and initialize internal data structure. 56 static void batch_dispose(batch_t *instance); 57 58 59 /** Allocates memory and initializes internal data structures. 57 60 * 58 61 * @param[in] fun DDF function to pass to callback. … … 69 72 * @param[in] arg additional parameter to func_in or func_out 70 73 * @param[in] manager Pointer to toggle management structure. 71 * @return Valid pointer if all substructures were successfully created, 72 * NULL otherwise. 73 * 74 * Determines the number of needed packets (TDs). Prepares a transport buffer 75 * (that is accessible by the hardware). Initializes parameters needed for the 76 * transaction and callback. 74 * @return False, if there is an active TD, true otherwise. 77 75 */ 78 76 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target, … … 102 100 bzero(instance, sizeof(batch_t)); 103 101 104 instance->qh = malloc32(sizeof(q h_t));102 instance->qh = malloc32(sizeof(queue_head_t)); 105 103 CHECK_NULL_DISPOSE_RETURN(instance->qh, 106 104 "Failed to allocate batch queue head.\n"); 107 q h_init(instance->qh);105 queue_head_init(instance->qh); 108 106 109 107 instance->packets = (size + max_packet_size - 1) / max_packet_size; … … 116 114 instance->tds, "Failed to allocate transfer descriptors.\n"); 117 115 bzero(instance->tds, sizeof(td_t) * instance->packets); 116 117 // const size_t transport_size = max_packet_size * instance->packets; 118 118 119 119 if (size > 0) { … … 143 143 instance->speed = speed; 144 144 instance->manager = manager; 145 instance->callback_out = func_out; 146 instance->callback_in = func_in; 147 148 qh_set_element_td(instance->qh, addr_to_phys(instance->tds)); 145 146 if (func_out) 147 instance->callback_out = func_out; 148 if (func_in) 149 instance->callback_in = func_in; 150 151 queue_head_set_element_td(instance->qh, addr_to_phys(instance->tds)); 149 152 150 153 usb_log_debug("Batch(%p) %d:%d memory structures ready.\n", … … 153 156 } 154 157 /*----------------------------------------------------------------------------*/ 155 /** Check batch TDs for activity.158 /** Checks batch TDs for activity. 156 159 * 157 160 * @param[in] instance Batch structure to use. 158 161 * @return False, if there is an active TD, true otherwise. 159 *160 * Walk all TDs. Stop with false if there is an active one (it is to be161 * processed). Stop with true if an error is found. Return true if the last TS162 * is reached.163 162 */ 164 163 bool batch_is_complete(batch_t *instance) … … 178 177 usb_log_debug("Batch(%p) found error TD(%d):%x.\n", 179 178 instance, i, instance->tds[i].status); 180 td_print_status(&instance->tds[i]);181 179 182 180 device_keeper_set_toggle(instance->manager, … … 199 197 * 200 198 * @param[in] instance Batch structure to use. 201 *202 * Uses genercir control function with pids OUT and IN.203 199 */ 204 200 void batch_control_write(batch_t *instance) 205 201 { 206 202 assert(instance); 207 /* We are data out, we are supposed to provide data */203 /* we are data out, we are supposed to provide data */ 208 204 memcpy(instance->transport_buffer, instance->buffer, 209 205 instance->buffer_size); … … 211 207 instance->next_step = batch_call_out_and_dispose; 212 208 usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance); 209 batch_schedule(instance); 213 210 } 214 211 /*----------------------------------------------------------------------------*/ … … 216 213 * 217 214 * @param[in] instance Batch structure to use. 218 *219 * Uses generic control with pids IN and OUT.220 215 */ 221 216 void batch_control_read(batch_t *instance) … … 225 220 instance->next_step = batch_call_in_and_dispose; 226 221 usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance); 227 } 228 /*----------------------------------------------------------------------------*/ 229 /** Prepare interrupt in transaction. 230 * 231 * @param[in] instance Batch structure to use. 232 * 233 * Data transaction with PID_IN. 222 batch_schedule(instance); 223 } 224 /*----------------------------------------------------------------------------*/ 225 /** Prepares interrupt in transaction. 226 * 227 * @param[in] instance Batch structure to use. 234 228 */ 235 229 void batch_interrupt_in(batch_t *instance) … … 239 233 instance->next_step = batch_call_in_and_dispose; 240 234 usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance); 241 } 242 /*----------------------------------------------------------------------------*/ 243 /** Prepare interrupt out transaction. 244 * 245 * @param[in] instance Batch structure to use. 246 * 247 * Data transaction with PID_OUT. 235 batch_schedule(instance); 236 } 237 /*----------------------------------------------------------------------------*/ 238 /** Prepares interrupt out transaction. 239 * 240 * @param[in] instance Batch structure to use. 248 241 */ 249 242 void batch_interrupt_out(batch_t *instance) 250 243 { 251 244 assert(instance); 252 /* We are data out, we are supposed to provide data */245 /* we are data out, we are supposed to provide data */ 253 246 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 254 247 batch_data(instance, USB_PID_OUT); 255 248 instance->next_step = batch_call_out_and_dispose; 256 249 usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance); 257 } 258 /*----------------------------------------------------------------------------*/ 259 /** Prepare bulk in transaction. 260 * 261 * @param[in] instance Batch structure to use. 262 * 263 * Data transaction with PID_IN. 250 batch_schedule(instance); 251 } 252 /*----------------------------------------------------------------------------*/ 253 /** Prepares bulk in transaction. 254 * 255 * @param[in] instance Batch structure to use. 264 256 */ 265 257 void batch_bulk_in(batch_t *instance) … … 269 261 instance->next_step = batch_call_in_and_dispose; 270 262 usb_log_debug("Batch(%p) BULK IN initialized.\n", instance); 271 } 272 /*----------------------------------------------------------------------------*/ 273 /** Prepare bulk out transaction. 274 * 275 * @param[in] instance Batch structure to use. 276 * 277 * Data transaction with PID_OUT. 263 batch_schedule(instance); 264 } 265 /*----------------------------------------------------------------------------*/ 266 /** Prepares bulk out transaction. 267 * 268 * @param[in] instance Batch structure to use. 278 269 */ 279 270 void batch_bulk_out(batch_t *instance) 280 271 { 281 272 assert(instance); 282 /* We are data out, we are supposed to provide data */283 273 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 284 274 batch_data(instance, USB_PID_OUT); 285 275 instance->next_step = batch_call_out_and_dispose; 286 276 usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance); 287 } 288 /*----------------------------------------------------------------------------*/ 289 /** Prepare generic data transaction 277 batch_schedule(instance); 278 } 279 /*----------------------------------------------------------------------------*/ 280 /** Prepares generic data transaction 290 281 * 291 282 * @param[in] instance Batch structure to use. 292 283 * @param[in] pid to use for data packets. 293 *294 * Packets with alternating toggle bit and supplied pid value.295 * The last packet is marked with IOC flag.296 284 */ 297 285 void batch_data(batch_t *instance, usb_packet_id pid) … … 330 318 ++packet; 331 319 } 332 td_set_ioc(&instance->tds[packet - 1]);333 320 device_keeper_set_toggle(instance->manager, instance->target, toggle); 334 321 } 335 322 /*----------------------------------------------------------------------------*/ 336 /** Prepare generic control transaction323 /** Prepares generic control transaction 337 324 * 338 325 * @param[in] instance Batch structure to use. 339 326 * @param[in] data_stage to use for data packets. 340 327 * @param[in] status_stage to use for data packets. 341 *342 * Setup stage with toggle 0 and USB_PID_SETUP.343 * Data stage with alternating toggle and pid supplied by parameter.344 * Status stage with toggle 1 and pid supplied by parameter.345 * The last packet is marked with IOC.346 328 */ 347 329 void batch_control(batch_t *instance, … … 387 369 0, 1, false, low_speed, instance->target, status_stage, NULL, NULL); 388 370 389 td_set_ioc(&instance->tds[packet]); 371 372 instance->tds[packet].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 390 373 usb_log_debug2("Control last TD status: %x.\n", 391 374 instance->tds[packet].status); 392 375 } 393 376 /*----------------------------------------------------------------------------*/ 394 /** Prepare data, get error status and call callback in. 395 * 396 * @param[in] instance Batch structure to use. 397 * Copies data from transport buffer, and calls callback with appropriate 398 * parameters. 377 /** Prepares data, gets error status and calls callback in. 378 * 379 * @param[in] instance Batch structure to use. 399 380 */ 400 381 void batch_call_in(batch_t *instance) … … 403 384 assert(instance->callback_in); 404 385 405 /* We are data in, we need data */386 /* we are data in, we need data */ 406 387 memcpy(instance->buffer, instance->transport_buffer, 407 388 instance->buffer_size); … … 416 397 } 417 398 /*----------------------------------------------------------------------------*/ 418 /** Get error status and callcallback out.399 /** Gets error status and calls callback out. 419 400 * 420 401 * @param[in] instance Batch structure to use. … … 432 413 } 433 414 /*----------------------------------------------------------------------------*/ 434 /** Helper function calls callback and correctly disposes of batch structure.415 /** Prepares data, gets error status, calls callback in and dispose. 435 416 * 436 417 * @param[in] instance Batch structure to use. … … 443 424 } 444 425 /*----------------------------------------------------------------------------*/ 445 /** Helper function calls callback and correctly disposes of batch structure.426 /** Gets error status, calls callback out and dispose. 446 427 * 447 428 * @param[in] instance Batch structure to use. … … 454 435 } 455 436 /*----------------------------------------------------------------------------*/ 456 /** Correctly dispose all used data structures.437 /** Correctly disposes all used data structures. 457 438 * 458 439 * @param[in] instance Batch structure to use. … … 469 450 free(instance); 470 451 } 452 /*----------------------------------------------------------------------------*/ 453 int batch_schedule(batch_t *instance) 454 { 455 assert(instance); 456 uhci_t *hc = fun_to_uhci(instance->fun); 457 assert(hc); 458 return uhci_schedule(hc, instance); 459 } 471 460 /** 472 461 * @}
Note:
See TracChangeset
for help on using the changeset viewer.