Changeset 3afb758 in mainline for uspace/drv/bus/usb/uhci/batch.c


Ignore:
Timestamp:
2011-08-24T15:23:46Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a02517
Parents:
5fe0a69
Message:

UHCI: Remove old code

Add support for hcd_t destruction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/batch.c

    r5fe0a69 r3afb758  
    4444
    4545#define DEFAULT_ERROR_COUNT 3
     46static void batch_control_write(usb_transfer_batch_t *instance);
     47static void batch_control_read(usb_transfer_batch_t *instance);
     48
     49static void batch_interrupt_in(usb_transfer_batch_t *instance);
     50static void batch_interrupt_out(usb_transfer_batch_t *instance);
     51
     52static void batch_bulk_in(usb_transfer_batch_t *instance);
     53static void batch_bulk_out(usb_transfer_batch_t *instance);
    4654
    4755static void batch_setup_control(usb_transfer_batch_t *batch)
     
    93101}
    94102/*----------------------------------------------------------------------------*/
     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 */
    95121void * uhci_transfer_batch_create(usb_transfer_batch_t *batch)
    96122{
     
    148174}
    149175/*----------------------------------------------------------------------------*/
    150 /** Allocate memory and initialize internal data structure.
    151  *
    152  * @param[in] fun DDF function to pass to callback.
    153  * @param[in] ep Communication target
    154  * @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 completion
    159  * @param[in] func_out function to call on outbound transfer completion
    160  * @param[in] arg additional parameter to func_in or func_out
    161  * @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)0
    186 
    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_FMT
    227             " memory structures ready.\n", instance,
    228             USB_TRANSFER_BATCH_ARGS(*instance));
    229         return instance;
    230 }
    231176/*----------------------------------------------------------------------------*/
    232177/** Check batch TDs for activity.
     
    288233 * Uses generic control function with pids OUT and IN.
    289234 */
    290 void batch_control_write(usb_transfer_batch_t *instance)
     235static void batch_control_write(usb_transfer_batch_t *instance)
    291236{
    292237        assert(instance);
     
    304249 * Uses generic control with pids IN and OUT.
    305250 */
    306 void batch_control_read(usb_transfer_batch_t *instance)
     251static void batch_control_read(usb_transfer_batch_t *instance)
    307252{
    308253        assert(instance);
     
    318263 * Data transfer with PID_IN.
    319264 */
    320 void batch_interrupt_in(usb_transfer_batch_t *instance)
     265static void batch_interrupt_in(usb_transfer_batch_t *instance)
    321266{
    322267        assert(instance);
     
    332277 * Data transfer with PID_OUT.
    333278 */
    334 void batch_interrupt_out(usb_transfer_batch_t *instance)
     279static void batch_interrupt_out(usb_transfer_batch_t *instance)
    335280{
    336281        assert(instance);
     
    348293 * Data transfer with PID_IN.
    349294 */
    350 void batch_bulk_in(usb_transfer_batch_t *instance)
     295static void batch_bulk_in(usb_transfer_batch_t *instance)
    351296{
    352297        assert(instance);
     
    362307 * Data transfer with PID_OUT.
    363308 */
    364 void batch_bulk_out(usb_transfer_batch_t *instance)
     309static void batch_bulk_out(usb_transfer_batch_t *instance)
    365310{
    366311        assert(instance);
     
    380325 * The last transfer is marked with IOC flag.
    381326 */
    382 void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid)
     327static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid)
    383328{
    384329        assert(instance);
     
    431376 * The last transfer is marked with IOC.
    432377 */
    433 void batch_control(usb_transfer_batch_t *instance,
     378static void batch_control(usb_transfer_batch_t *instance,
    434379   usb_packet_id data_stage, usb_packet_id status_stage)
    435380{
Note: See TracChangeset for help on using the changeset viewer.