Changeset 9a790ad1 in mainline


Ignore:
Timestamp:
2011-08-31T23:28:37Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7bce1fc
Parents:
4e9ecf4
Message:

uhci: simplify uhci_batch initialization

remove per type/direction functions and use a generic one,
nice array will provide suitable PIDs

File:
1 edited

Legend:

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

    r4e9ecf4 r9a790ad1  
    4747static void batch_control(uhci_transfer_batch_t *uhci_batch,
    4848    usb_packet_id data_stage, usb_packet_id status_stage);
    49 static void batch_data(uhci_transfer_batch_t *uhci_batch, usb_packet_id pid);
     49static void batch_data(uhci_transfer_batch_t *uhci_batch);
    5050/*----------------------------------------------------------------------------*/
    5151static void uhci_transfer_batch_dispose(uhci_transfer_batch_t *uhci_batch)
     
    7272}
    7373/*----------------------------------------------------------------------------*/
    74 static void (*batch_setup[4][3])(uhci_transfer_batch_t*);
     74static void (* const batch_setup[4][3])(uhci_transfer_batch_t*);
    7575/*----------------------------------------------------------------------------*/
    7676/** Allocate memory and initialize internal data structure.
     
    106106        CHECK_NULL_DISPOSE_RETURN(uhci_batch,
    107107            "Failed to allocate UHCI batch.\n");
    108 
     108        link_initialize(&uhci_batch->link);
    109109        uhci_batch->td_count =
    110110            (usb_batch->buffer_size + usb_batch->ep->max_packet_size - 1)
     
    203203}
    204204
    205 #define LOG_BATCH_INITIALIZED(batch, name) \
    206         usb_log_debug2("Batch %p %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
    207             (batch), (name), USB_TRANSFER_BATCH_ARGS(*(batch)))
    208 
    209 /*----------------------------------------------------------------------------*/
    210 /** Prepares control write transfer.
    211  *
    212  * @param[in] instance Batch structure to use.
    213  *
    214  * Uses generic control function with pids OUT and IN.
    215  */
    216 static void control_write(uhci_transfer_batch_t *uhci_batch)
    217 {
    218         batch_control(uhci_batch, USB_PID_OUT, USB_PID_IN);
    219         LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "control write");
    220 }
    221 /*----------------------------------------------------------------------------*/
    222 /** Prepares control read transfer.
    223  *
    224  * @param[in] instance Batch structure to use.
    225  *
    226  * Uses generic control with pids IN and OUT.
    227  */
    228 static void control_read(uhci_transfer_batch_t *uhci_batch)
    229 {
    230         batch_control(uhci_batch, USB_PID_IN, USB_PID_OUT);
    231         LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "control read");
    232 }
    233 /*----------------------------------------------------------------------------*/
    234 /** Prepare interrupt in transfer.
    235  *
    236  * @param[in] instance Batch structure to use.
    237  *
    238  * Data transfer with PID_IN.
    239  */
    240 static void interrupt_in(uhci_transfer_batch_t *uhci_batch)
    241 {
    242         batch_data(uhci_batch, USB_PID_IN);
    243         LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "interrupt in");
    244 }
    245 /*----------------------------------------------------------------------------*/
    246 /** Prepare interrupt out transfer.
    247  *
    248  * @param[in] instance Batch structure to use.
    249  *
    250  * Data transfer with PID_OUT.
    251  */
    252 static void interrupt_out(uhci_transfer_batch_t *uhci_batch)
    253 {
    254         batch_data(uhci_batch, USB_PID_OUT);
    255         LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "interrupt out");
    256 }
    257 /*----------------------------------------------------------------------------*/
    258 /** Prepare bulk in transfer.
    259  *
    260  * @param[in] instance Batch structure to use.
    261  *
    262  * Data transfer with PID_IN.
    263  */
    264 static void bulk_in(uhci_transfer_batch_t *uhci_batch)
    265 {
    266         batch_data(uhci_batch, USB_PID_IN);
    267         LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "bulk in");
    268 }
    269 /*----------------------------------------------------------------------------*/
    270 /** Prepare bulk out transfer.
    271  *
    272  * @param[in] instance Batch structure to use.
    273  *
    274  * Data transfer with PID_OUT.
    275  */
    276 static void bulk_out(uhci_transfer_batch_t *uhci_batch)
    277 {
    278         batch_data(uhci_batch, USB_PID_OUT);
    279         LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "bulk out");
    280 }
     205#define LOG_BATCH_INITIALIZED(batch, name, dir) \
     206        usb_log_debug2("Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
     207            (batch), (name), (dir), USB_TRANSFER_BATCH_ARGS(*(batch)))
     208
    281209/*----------------------------------------------------------------------------*/
    282210/** Prepare generic data transfer
     
    288216 * The last transfer is marked with IOC flag.
    289217 */
    290 static void batch_data(uhci_transfer_batch_t *uhci_batch, usb_packet_id pid)
    291 {
    292         assert(uhci_batch);
    293         assert(uhci_batch->usb_batch);
    294 
     218static void batch_data(uhci_transfer_batch_t *uhci_batch)
     219{
     220        assert(uhci_batch);
     221        assert(uhci_batch->usb_batch);
     222        static const usb_packet_id pids[] = {
     223                [USB_DIRECTION_IN] = USB_PID_IN,
     224                [USB_DIRECTION_OUT] = USB_PID_OUT,
     225        };
     226        assert(uhci_batch->usb_batch->ep->direction == USB_DIRECTION_OUT ||
     227            uhci_batch->usb_batch->ep->direction == USB_DIRECTION_IN);
     228
     229        const usb_packet_id pid = pids[uhci_batch->usb_batch->ep->direction];
    295230        const bool low_speed =
    296231            uhci_batch->usb_batch->ep->speed == USB_SPEED_LOW;
     
    326261        td_set_ioc(&uhci_batch->tds[td - 1]);
    327262        endpoint_toggle_set(uhci_batch->usb_batch->ep, toggle);
     263        LOG_BATCH_INITIALIZED(uhci_batch->usb_batch,
     264            usb_str_transfer_type(uhci_batch->usb_batch->ep->transfer_type),
     265            usb_str_direction(uhci_batch->usb_batch->ep->direction));
    328266}
    329267/*----------------------------------------------------------------------------*/
     
    397335static void batch_setup_control(uhci_transfer_batch_t *uhci_batch)
    398336{
     337        assert(uhci_batch);
     338        assert(uhci_batch->usb_batch);
     339        assert(uhci_batch->usb_batch->setup_buffer);
    399340        // TODO Find a better way to do this
    400         assert(uhci_batch);
    401         assert(uhci_batch->usb_batch);
    402         if (uhci_batch->usb_batch->setup_buffer[0] & (1 << 7))
    403                 control_read(uhci_batch);
    404         else
    405                 control_write(uhci_batch);
    406 }
    407 /*----------------------------------------------------------------------------*/
    408 static void (*batch_setup[4][3])(uhci_transfer_batch_t*) =
     341        /* Check first bit of the first setup request byte
     342         * (it signals hc-> dev or dev->hc communication) */
     343        if (uhci_batch->usb_batch->setup_buffer[0] & (1 << 7)) {
     344                batch_control(uhci_batch, USB_PID_IN, USB_PID_OUT);
     345                LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "control", "read");
     346        } else {
     347                batch_control(uhci_batch, USB_PID_OUT, USB_PID_IN);
     348                LOG_BATCH_INITIALIZED(uhci_batch->usb_batch, "control", "write");
     349        }
     350}
     351/*----------------------------------------------------------------------------*/
     352static void (* const batch_setup[4][3])(uhci_transfer_batch_t*) =
    409353{
    410354        { NULL, NULL, batch_setup_control },
    411355        { NULL, NULL, NULL },
    412         { bulk_in, bulk_out, NULL },
    413         { interrupt_in, interrupt_out, NULL },
     356        { batch_data, batch_data, NULL },
     357        { batch_data, batch_data, NULL },
    414358};
    415359/**
Note: See TracChangeset for help on using the changeset viewer.