Changeset 63adb18 in mainline


Ignore:
Timestamp:
2017-10-11T18:53:03Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7e74911
Parents:
eaf5e86
Message:

Added transfer block data structure and dequeue mechanism.

Location:
uspace/drv/bus/usb/xhci
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/transfers.c

    reaf5e86 r63adb18  
    292292        return EOK;
    293293}
     294
     295xhci_transfer_block_t* xhci_transfer_block_alloc(size_t buffer_size)
     296{
     297        assert(buffer_size);
     298
     299        xhci_transfer_block_t *block = malloc(sizeof(xhci_transfer_block_t));
     300        block->buffer = (uintptr_t) malloc32(buffer_size);
     301        block->total_size = buffer_size;
     302        block->filled_size = 0;
     303
     304        return block;
     305}
     306
     307void xhci_transfer_block_fini(xhci_transfer_block_t* block)
     308{
     309        assert(block);
     310
     311        free32((void*) block->buffer);
     312        free(block);
     313}
     314
     315int xhci_dequeue_transfer_block(xhci_hc_t* hc, size_t size, xhci_transfer_block_t** block)
     316{
     317        // TODO: obtain block from some global structure at HC
     318
     319        *block = xhci_transfer_block_alloc(size);
     320        return EOK;
     321}
     322
     323int xhci_free_transfer_block(xhci_hc_t* hc, xhci_transfer_block_t* block)
     324{
     325        assert(block);
     326
     327        // TODO: check if the block is not used?
     328        // TODO: recycle block in some global structure at HC
     329        xhci_transfer_block_fini(block);
     330
     331        return EOK;
     332}
     333
     334int xhci_schedule_transfer_block(xhci_hc_t* hc, xhci_transfer_block_t* block)
     335{
     336        usb_transfer_batch_t* batch = block->transfer->batch;
     337        uint8_t slot_id = batch->ep->hc_data.slot_id;
     338        xhci_trb_ring_t* ring = hc->dcbaa_virt[slot_id].trs[batch->ep->endpoint];
     339
     340        xhci_trb_t trb;
     341        memset(&trb, 0, sizeof(xhci_trb_t));
     342        trb.parameter = block->buffer;
     343
     344        TRB_CTRL_SET_XFER_LEN(trb, block->filled_size);
     345        // FIXME: TD size 4.11.2.4
     346        TRB_CTRL_SET_TD_SIZE(trb, 1);
     347
     348        // we want an interrupt after this td is done
     349        TRB_CTRL_SET_IOC(trb, 1);
     350        TRB_CTRL_SET_TRB_TYPE(trb, XHCI_TRB_TYPE_NORMAL);
     351        xhci_trb_ring_enqueue(ring, &trb, &block->transfer->interrupt_trb_phys);
     352
     353        // FIXME: Check return from xhci_trb_ring_enqueue.
     354
     355        hc_ring_doorbell(hc, slot_id, 1);
     356        return EOK;
     357}
  • uspace/drv/bus/usb/xhci/transfers.h

    reaf5e86 r63adb18  
    4444
    4545        usb_transfer_batch_t* batch;
     46
     47        size_t completed_size;       /* Number of successfully transferred bytes. */
     48        size_t scheduled_size;       /* Number of bytes scheduled for transfer. */
     49        list_t active_blocks;        /* List of data blocks transferred right now. */
    4650} xhci_transfer_t;
     51
     52typedef struct {
     53        link_t link;
     54
     55        uintptr_t buffer;            /* Physical address of the buffer start. */
     56        size_t total_size;           /* Total size available in the block. */
     57        size_t filled_size;          /* Size of the data in the block. */
     58
     59        xhci_transfer_t* transfer;   /* Current transfer or NULL. */
     60} xhci_transfer_block_t;
    4761
    4862int xhci_init_transfers(xhci_hc_t*);
     
    5367int xhci_schedule_bulk_transfer(xhci_hc_t*, usb_transfer_batch_t*);
    5468int xhci_handle_transfer_event(xhci_hc_t*, xhci_trb_t*);
     69
     70xhci_transfer_block_t* xhci_transfer_block_alloc(size_t);
     71void xhci_transfer_block_fini(xhci_transfer_block_t*);
     72int xhci_dequeue_transfer_block(xhci_hc_t*, size_t, xhci_transfer_block_t**);
     73int xhci_free_transfer_block(xhci_hc_t*, xhci_transfer_block_t*);
     74int xhci_schedule_transfer_block(xhci_hc_t*, xhci_transfer_block_t*);
Note: See TracChangeset for help on using the changeset viewer.