Changeset 3afb758 in mainline for uspace/drv/bus/usb/uhci/batch.c
- Timestamp:
- 2011-08-24T15:23:46Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1a02517
- Parents:
- 5fe0a69
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhci/batch.c
r5fe0a69 r3afb758 44 44 45 45 #define DEFAULT_ERROR_COUNT 3 46 static void batch_control_write(usb_transfer_batch_t *instance); 47 static void batch_control_read(usb_transfer_batch_t *instance); 48 49 static void batch_interrupt_in(usb_transfer_batch_t *instance); 50 static void batch_interrupt_out(usb_transfer_batch_t *instance); 51 52 static void batch_bulk_in(usb_transfer_batch_t *instance); 53 static void batch_bulk_out(usb_transfer_batch_t *instance); 46 54 47 55 static void batch_setup_control(usb_transfer_batch_t *batch) … … 93 101 } 94 102 /*----------------------------------------------------------------------------*/ 103 /** Allocate memory and initialize internal data structure. 104 * 105 * @param[in] fun DDF function to pass to callback. 106 * @param[in] ep Communication target 107 * @param[in] buffer Data source/destination. 108 * @param[in] buffer_size Size of the buffer. 109 * @param[in] setup_buffer Setup data source (if not NULL) 110 * @param[in] setup_size Size of setup_buffer (should be always 8) 111 * @param[in] func_in function to call on inbound transfer completion 112 * @param[in] func_out function to call on outbound transfer completion 113 * @param[in] arg additional parameter to func_in or func_out 114 * @return Valid pointer if all structures were successfully created, 115 * NULL otherwise. 116 * 117 * Determines the number of needed transfer descriptors (TDs). 118 * Prepares a transport buffer (that is accessible by the hardware). 119 * Initializes parameters needed for the transfer and callback. 120 */ 95 121 void * uhci_transfer_batch_create(usb_transfer_batch_t *batch) 96 122 { … … 148 174 } 149 175 /*----------------------------------------------------------------------------*/ 150 /** Allocate memory and initialize internal data structure.151 *152 * @param[in] fun DDF function to pass to callback.153 * @param[in] ep Communication target154 * @param[in] buffer Data source/destination.155 * @param[in] buffer_size Size of the buffer.156 * @param[in] setup_buffer Setup data source (if not NULL)157 * @param[in] setup_size Size of setup_buffer (should be always 8)158 * @param[in] func_in function to call on inbound transfer completion159 * @param[in] func_out function to call on outbound transfer completion160 * @param[in] arg additional parameter to func_in or func_out161 * @return Valid pointer if all structures were successfully created,162 * NULL otherwise.163 *164 * Determines the number of needed transfer descriptors (TDs).165 * Prepares a transport buffer (that is accessible by the hardware).166 * Initializes parameters needed for the transfer and callback.167 */168 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,169 char *buffer, size_t buffer_size,170 const char* setup_buffer, size_t setup_size,171 usbhc_iface_transfer_in_callback_t func_in,172 usbhc_iface_transfer_out_callback_t func_out, void *arg)173 {174 assert(ep);175 assert(func_in == NULL || func_out == NULL);176 assert(func_in != NULL || func_out != NULL);177 178 #define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \179 if (ptr == NULL) { \180 usb_log_error(message); \181 if (uhci_data) { \182 uhci_transfer_batch_dispose(uhci_data); \183 } \184 return NULL; \185 } else (void)0186 187 uhci_transfer_batch_t *uhci_data =188 malloc(sizeof(uhci_transfer_batch_t));189 CHECK_NULL_DISPOSE_RETURN(uhci_data,190 "Failed to allocate UHCI batch.\n");191 bzero(uhci_data, sizeof(uhci_transfer_batch_t));192 193 uhci_data->td_count =194 (buffer_size + ep->max_packet_size - 1) / ep->max_packet_size;195 if (ep->transfer_type == USB_TRANSFER_CONTROL) {196 uhci_data->td_count += 2;197 }198 199 assert((sizeof(td_t) % 16) == 0);200 const size_t total_size = (sizeof(td_t) * uhci_data->td_count)201 + sizeof(qh_t) + setup_size + buffer_size;202 uhci_data->device_buffer = malloc32(total_size);203 CHECK_NULL_DISPOSE_RETURN(uhci_data->device_buffer,204 "Failed to allocate UHCI buffer.\n");205 bzero(uhci_data->device_buffer, total_size);206 207 uhci_data->tds = uhci_data->device_buffer;208 uhci_data->qh =209 (uhci_data->device_buffer + (sizeof(td_t) * uhci_data->td_count));210 211 qh_init(uhci_data->qh);212 qh_set_element_td(uhci_data->qh, uhci_data->tds);213 214 usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));215 CHECK_NULL_DISPOSE_RETURN(instance,216 "Failed to allocate batch instance.\n");217 void *setup =218 uhci_data->device_buffer + (sizeof(td_t) * uhci_data->td_count)219 + sizeof(qh_t);220 void *data_buffer = setup + setup_size;221 usb_transfer_batch_init(instance, ep, buffer, data_buffer, buffer_size,222 setup, setup_size, func_in, func_out, arg, fun,223 uhci_data, uhci_transfer_batch_dispose);224 225 memcpy(instance->setup_buffer, setup_buffer, setup_size);226 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT227 " memory structures ready.\n", instance,228 USB_TRANSFER_BATCH_ARGS(*instance));229 return instance;230 }231 176 /*----------------------------------------------------------------------------*/ 232 177 /** Check batch TDs for activity. … … 288 233 * Uses generic control function with pids OUT and IN. 289 234 */ 290 void batch_control_write(usb_transfer_batch_t *instance)235 static void batch_control_write(usb_transfer_batch_t *instance) 291 236 { 292 237 assert(instance); … … 304 249 * Uses generic control with pids IN and OUT. 305 250 */ 306 void batch_control_read(usb_transfer_batch_t *instance)251 static void batch_control_read(usb_transfer_batch_t *instance) 307 252 { 308 253 assert(instance); … … 318 263 * Data transfer with PID_IN. 319 264 */ 320 void batch_interrupt_in(usb_transfer_batch_t *instance)265 static void batch_interrupt_in(usb_transfer_batch_t *instance) 321 266 { 322 267 assert(instance); … … 332 277 * Data transfer with PID_OUT. 333 278 */ 334 void batch_interrupt_out(usb_transfer_batch_t *instance)279 static void batch_interrupt_out(usb_transfer_batch_t *instance) 335 280 { 336 281 assert(instance); … … 348 293 * Data transfer with PID_IN. 349 294 */ 350 void batch_bulk_in(usb_transfer_batch_t *instance)295 static void batch_bulk_in(usb_transfer_batch_t *instance) 351 296 { 352 297 assert(instance); … … 362 307 * Data transfer with PID_OUT. 363 308 */ 364 void batch_bulk_out(usb_transfer_batch_t *instance)309 static void batch_bulk_out(usb_transfer_batch_t *instance) 365 310 { 366 311 assert(instance); … … 380 325 * The last transfer is marked with IOC flag. 381 326 */ 382 void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid)327 static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid) 383 328 { 384 329 assert(instance); … … 431 376 * The last transfer is marked with IOC. 432 377 */ 433 void batch_control(usb_transfer_batch_t *instance,378 static void batch_control(usb_transfer_batch_t *instance, 434 379 usb_packet_id data_stage, usb_packet_id status_stage) 435 380 {
Note:
See TracChangeset
for help on using the changeset viewer.