Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7e74911 in mainline


Ignore:
Timestamp:
2017-10-11T20:54:31Z (4 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master
Children:
41924f30
Parents:
63adb18
Message:

Delegated transfer block recycling to the kernel frame allocator. Removed most of the dequeue mechanism.

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

Legend:

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

    r63adb18 r7e74911  
    123123        transfer->batch = batch;
    124124        link_initialize(&transfer->link);
     125        transfer->hc_buffer = malloc32(batch->buffer_size);
     126
    125127        return transfer;
    126128}
     
    128130void xhci_transfer_fini(xhci_transfer_t* transfer) {
    129131        if (transfer) {
     132                free32(transfer->hc_buffer);
    130133                free(transfer);
    131134        }
     
    152155        /* For the TRB formats, see xHCI specification 6.4.1.2 */
    153156        xhci_transfer_t *transfer = xhci_transfer_alloc(batch);
     157        memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size);
    154158
    155159        xhci_trb_t trb_setup;
     
    177181
    178182        if (setup->length > 0) {
    179                 trb_data.parameter = (uintptr_t) addr_to_phys(batch->buffer);
     183                trb_data.parameter = addr_to_phys(transfer->hc_buffer);
    180184
    181185                // data size (sent for OUT, or buffer size)
     
    230234
    231235        xhci_transfer_t *transfer = xhci_transfer_alloc(batch);
     236        memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size);
    232237
    233238        xhci_trb_t trb;
    234239        memset(&trb, 0, sizeof(xhci_trb_t));
    235         trb.parameter = (uintptr_t) addr_to_phys(batch->buffer);
     240        trb.parameter = addr_to_phys(transfer->hc_buffer);
    236241
    237242        // data size (sent for OUT, or buffer size)
     
    292297        return EOK;
    293298}
    294 
    295 xhci_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 
    307 void xhci_transfer_block_fini(xhci_transfer_block_t* block)
    308 {
    309         assert(block);
    310 
    311         free32((void*) block->buffer);
    312         free(block);
    313 }
    314 
    315 int 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 
    323 int 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 
    334 int 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

    r63adb18 r7e74911  
    4545        usb_transfer_batch_t* batch;
    4646
    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. */
     47        void* hc_buffer;                    /* Virtual address of the buffer start. */
    5048} xhci_transfer_t;
    51 
    52 typedef 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;
    6149
    6250int xhci_init_transfers(xhci_hc_t*);
     
    6755int xhci_schedule_bulk_transfer(xhci_hc_t*, usb_transfer_batch_t*);
    6856int xhci_handle_transfer_event(xhci_hc_t*, xhci_trb_t*);
    69 
    70 xhci_transfer_block_t* xhci_transfer_block_alloc(size_t);
    71 void xhci_transfer_block_fini(xhci_transfer_block_t*);
    72 int xhci_dequeue_transfer_block(xhci_hc_t*, size_t, xhci_transfer_block_t**);
    73 int xhci_free_transfer_block(xhci_hc_t*, xhci_transfer_block_t*);
    74 int xhci_schedule_transfer_block(xhci_hc_t*, xhci_transfer_block_t*);
Note: See TracChangeset for help on using the changeset viewer.