Changeset 28d9c95 in mainline
- Timestamp:
- 2011-05-17T12:21:55Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d736fe38
- Parents:
- 5f94a0c
- Location:
- uspace/drv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/batch.c
r5f94a0c r28d9c95 44 44 #include "hw_struct/transfer_descriptor.h" 45 45 46 /** OHCI specific data required for USB transfer */ 46 47 typedef struct ohci_transfer_batch { 48 /** Endpoint descriptor of the target endpoint. */ 47 49 ed_t *ed; 50 /** List of TDs needed for the transfer */ 48 51 td_t **tds; 52 /** Number of TDs used by the transfer */ 49 53 size_t td_count; 54 /** Dummy TD to be left at the ED and used by the next transfer */ 50 55 size_t leave_td; 51 char *device_buffer; 56 /** Data buffer, must be accessible byb the OHCI hw. */ 57 void *device_buffer; 52 58 } ohci_transfer_batch_t; 53 59 /*----------------------------------------------------------------------------*/ 60 static void batch_control(usb_transfer_batch_t *instance, 61 usb_direction_t data_dir, usb_direction_t status_dir); 62 static void batch_data(usb_transfer_batch_t *instance); 63 /*----------------------------------------------------------------------------*/ 64 /** Safely destructs ohci_transfer_batch_t structure 65 * 66 * @param[in] ohci_batch Instance to destroy. 67 */ 54 68 static void ohci_transfer_batch_dispose(void *ohci_batch) 55 69 { … … 69 83 } 70 84 /*----------------------------------------------------------------------------*/ 71 static void batch_control(usb_transfer_batch_t *instance, 72 usb_direction_t data_dir, usb_direction_t status_dir); 73 static void batch_data(usb_transfer_batch_t *instance); 74 /*----------------------------------------------------------------------------*/ 85 /** Allocate memory initialize internal structures 86 * 87 * @param[in] fun DDF function to pass to callback. 88 * @param[in] ep Communication target 89 * @param[in] buffer Data source/destination. 90 * @param[in] buffer_size Size of the buffer. 91 * @param[in] setup_buffer Setup data source (if not NULL) 92 * @param[in] setup_size Size of setup_buffer (should be always 8) 93 * @param[in] func_in function to call on inbound transfer completion 94 * @param[in] func_out function to call on outbound transfer completion 95 * @param[in] arg additional parameter to func_in or func_out 96 * @return Valid pointer if all structures were successfully created, 97 * NULL otherwise. 98 * 99 * Allocates and initializes structures needed by the OHCI hw for the transfer. 100 */ 75 101 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep, 76 102 char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size, … … 107 133 } 108 134 109 /* we need one extra place for tdthat is currently assigned to hcd_ep*/135 /* We need an extra place for TD that is currently assigned to hcd_ep*/ 110 136 data->tds = calloc(sizeof(td_t*), data->td_count + 1); 111 137 CHECK_NULL_DISPOSE_RETURN(data->tds, 112 138 "Failed to allocate transfer descriptors.\n"); 113 139 140 /* Add TD left over by the previous transfer */ 114 141 data->tds[0] = hcd_ep->td; 115 142 data->leave_td = 0; … … 123 150 data->ed = hcd_ep->ed; 124 151 152 /* NOTE: OHCI is capable of handling buffer that crosses page boundaries 153 * it is, however, not capable of handling buffer that accupies more 154 * than two pages (the first page is computete using start pointer, the 155 * other using end pointer)*/ 125 156 if (setup_size + buffer_size > 0) { 126 157 data->device_buffer = malloc32(setup_size + buffer_size); … … 135 166 } 136 167 /*----------------------------------------------------------------------------*/ 168 /** Check batch TDs' status. 169 * 170 * @param[in] instance Batch structure to use. 171 * @return False, if there is an active TD, true otherwise. 172 * 173 * Walk all TDs (usually there is just one). Stop with false if there is an 174 * active TD. Stop with true if an error is found. Return true if the walk 175 * completes with the last TD. 176 */ 137 177 bool batch_is_complete(usb_transfer_batch_t *instance) 138 178 { … … 178 218 /* Clear possible ED HALT */ 179 219 data->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG; 180 uint32_t pa = addr_to_phys(hcd_ep->td);220 const uint32_t pa = addr_to_phys(hcd_ep->td); 181 221 assert(pa == (data->ed->td_head & ED_TDHEAD_PTR_MASK)); 182 222 assert(pa == (data->ed->td_tail & ED_TDTAIL_PTR_MASK)); … … 185 225 } 186 226 /*----------------------------------------------------------------------------*/ 227 /** Starts execution of the TD list 228 * 229 * @param[in] instance Batch structure to use 230 */ 187 231 void batch_commit(usb_transfer_batch_t *instance) 188 232 { … … 193 237 } 194 238 /*----------------------------------------------------------------------------*/ 239 /** Prepares control write transfer. 240 * 241 * @param[in] instance Batch structure to use. 242 * 243 * Uses generic control transfer using direction OUT(data stage) and 244 * IN(status stage). 245 */ 195 246 void batch_control_write(usb_transfer_batch_t *instance) 196 247 { … … 203 254 } 204 255 /*----------------------------------------------------------------------------*/ 256 /** Prepares control read transfer. 257 * 258 * @param[in] instance Batch structure to use. 259 * 260 * Uses generic control transfer using direction IN(data stage) and 261 * OUT(status stage). 262 */ 205 263 void batch_control_read(usb_transfer_batch_t *instance) 206 264 { … … 211 269 } 212 270 /*----------------------------------------------------------------------------*/ 271 /** Prepare interrupt in transfer. 272 * 273 * @param[in] instance Batch structure to use. 274 * 275 * Data transfer. 276 */ 213 277 void batch_interrupt_in(usb_transfer_batch_t *instance) 214 278 { … … 219 283 } 220 284 /*----------------------------------------------------------------------------*/ 285 /** Prepare interrupt out transfer. 286 * 287 * @param[in] instance Batch structure to use. 288 * 289 * Data transfer. 290 */ 221 291 void batch_interrupt_out(usb_transfer_batch_t *instance) 222 292 { … … 229 299 } 230 300 /*----------------------------------------------------------------------------*/ 301 /** Prepare bulk in transfer. 302 * 303 * @param[in] instance Batch structure to use. 304 * 305 * Data transfer. 306 */ 231 307 void batch_bulk_in(usb_transfer_batch_t *instance) 232 308 { … … 237 313 } 238 314 /*----------------------------------------------------------------------------*/ 315 /** Prepare bulk out transfer. 316 * 317 * @param[in] instance Batch structure to use. 318 * 319 * Data transfer. 320 */ 239 321 void batch_bulk_out(usb_transfer_batch_t *instance) 240 322 { … … 247 329 } 248 330 /*----------------------------------------------------------------------------*/ 249 ed_t * batch_ed(usb_transfer_batch_t *instance) 250 { 251 assert(instance); 252 ohci_transfer_batch_t *data = instance->private_data; 253 assert(data); 254 return data->ed; 255 } 256 /*----------------------------------------------------------------------------*/ 331 /** Prepare generic control transfer 332 * 333 * @param[in] instance Batch structure to use. 334 * @param[in] data_dir Direction to use for data stage. 335 * @param[in] status_dir Direction to use for status stage. 336 * 337 * Setup stage with toggle 0 and direction BOTH(SETUP_PID) 338 * Data stage with alternating toggle and direction supplied by parameter. 339 * Status stage with toggle 1 and direction supplied by parameter. 340 */ 257 341 void batch_control(usb_transfer_batch_t *instance, 258 342 usb_direction_t data_dir, usb_direction_t status_dir) … … 303 387 } 304 388 /*----------------------------------------------------------------------------*/ 389 /** Prepare generic data transfer 390 * 391 * @param[in] instance Batch structure to use. 392 * 393 * Direction is supplied by the associated ep and toggle is maintained by the 394 * OHCI hw in ED. 395 */ 305 396 void batch_data(usb_transfer_batch_t *instance) 306 397 { -
uspace/drv/ohci/batch.h
r5f94a0c r28d9c95 41 41 #include <usb/host/batch.h> 42 42 43 #include "hw_struct/endpoint_descriptor.h"44 45 43 usb_transfer_batch_t * batch_get( 46 44 ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size, … … 65 63 66 64 void batch_bulk_out(usb_transfer_batch_t *instance); 67 68 ed_t * batch_ed(usb_transfer_batch_t *instance);69 65 #endif 70 66 /** -
uspace/drv/ohci/hw_struct/transfer_descriptor.c
r5f94a0c r28d9c95 44 44 assert(instance); 45 45 bzero(instance, sizeof(td_t)); 46 instance-> 46 instance->status = 0 47 47 | ((dp[dir] & TD_STATUS_DP_MASK) << TD_STATUS_DP_SHIFT) 48 48 | ((CC_NOACCESS2 & TD_STATUS_CC_MASK) << TD_STATUS_CC_SHIFT); -
uspace/drv/uhci-hcd/batch.c
r5f94a0c r28d9c95 45 45 #define DEFAULT_ERROR_COUNT 3 46 46 47 /** UHCI specific data required for USB transfer */ 47 48 typedef struct uhci_transfer_batch { 49 /** Queue head 50 * This QH is used to maintain UHCI schedule structure and the element 51 * pointer points to the first TD of this batch. 52 */ 48 53 qh_t *qh; 54 /** List of TDs needed for the transfer */ 49 55 td_t *tds; 56 /** Number of TDs used by the transfer */ 57 size_t td_count; 58 /** Data buffer, must be accessible by the UHCI hw */ 50 59 void *device_buffer; 51 size_t td_count;52 60 } uhci_transfer_batch_t; 53 61 /*----------------------------------------------------------------------------*/ 54 static void uhci_transfer_batch_dispose(void *uhci_batch)55 {56 uhci_transfer_batch_t *instance = uhci_batch;57 assert(instance);58 free32(instance->device_buffer);59 free(instance);60 }61 /*----------------------------------------------------------------------------*/62 63 62 static void batch_control(usb_transfer_batch_t *instance, 64 63 usb_packet_id data_stage, usb_packet_id status_stage); 65 64 static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid); 66 65 /*----------------------------------------------------------------------------*/ 66 /** Safely destructs uhci_transfer_batch_t structure 67 * 68 * @param[in] uhci_batch Instance to destroy. 69 */ 70 static void uhci_transfer_batch_dispose(void *uhci_batch) 71 { 72 uhci_transfer_batch_t *instance = uhci_batch; 73 assert(instance); 74 free32(instance->device_buffer); 75 free(instance); 76 } 77 /*----------------------------------------------------------------------------*/ 67 78 /** Allocate memory and initialize internal data structure. 68 79 * … … 173 184 instance->error = td_status(&data->tds[i]); 174 185 if (instance->error != EOK) { 175 usb_log_debug("Batch(%p) found error TD(%zu):%" PRIx32 ".\n",176 instance, i, data->tds[i].status);186 usb_log_debug("Batch(%p) found error TD(%zu):%" 187 PRIx32 ".\n", instance, i, data->tds[i].status); 177 188 td_print_status(&data->tds[i]); 178 189 … … 397 408 /*----------------------------------------------------------------------------*/ 398 409 /** Provides access to QH data structure. 410 * 399 411 * @param[in] instance Batch pointer to use. 400 412 * @return Pointer to the QH used by the batch.
Note:
See TracChangeset
for help on using the changeset viewer.