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