Changeset 9b2f69e in mainline for uspace/drv/bus/usb/xhci/transfers.c


Ignore:
Timestamp:
2017-10-15T20:08:16Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b7db009
Parents:
816f5f4
Message:

Setting up endpoint contexts (almost) properly. Boilerplate for interrupt transfers. Simplified TRB ring initialization.

File:
1 edited

Legend:

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

    r816f5f4 r9b2f69e  
    266266}
    267267
    268 int xhci_schedule_bulk_transfer(xhci_hc_t* hc, usb_transfer_batch_t* batch) {
     268int xhci_schedule_bulk_transfer(xhci_hc_t* hc, usb_transfer_batch_t* batch)
     269{
    269270        if (batch->setup_size) {
    270271                usb_log_warning("Setup packet present for a bulk transfer.");
     
    276277
    277278        xhci_transfer_t *transfer = xhci_transfer_alloc(batch);
    278         memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size);
     279        if (!transfer->direction) {
     280                // Sending stuff from host to device, we need to copy the actual data.
     281                memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size);
     282        }
    279283
    280284        xhci_trb_t trb;
     
    300304}
    301305
     306int xhci_schedule_interrupt_transfer(xhci_hc_t* hc, usb_transfer_batch_t* batch)
     307{
     308        /* FIXME: Removing the next 2 rows causes QEMU to crash lol */
     309        usb_log_warning("Interrupt transfers not yet implemented!");
     310        return ENOTSUP;
     311
     312        if (batch->setup_size) {
     313                usb_log_warning("Setup packet present for a interrupt transfer.");
     314        }
     315
     316        xhci_endpoint_t *xhci_ep = xhci_endpoint_get(batch->ep);
     317        uint8_t slot_id = xhci_ep->device->slot_id;
     318        xhci_trb_ring_t* ring = hc->dcbaa_virt[slot_id].trs[batch->ep->target.endpoint];
     319
     320        xhci_transfer_t *transfer = xhci_transfer_alloc(batch);
     321        if (!transfer->direction) {
     322                // Sending stuff from host to device, we need to copy the actual data.
     323                memcpy(transfer->hc_buffer, batch->buffer, batch->buffer_size);
     324        }
     325
     326        xhci_trb_t trb;
     327        memset(&trb, 0, sizeof(xhci_trb_t));
     328        trb.parameter = addr_to_phys(transfer->hc_buffer);
     329
     330        // data size (sent for OUT, or buffer size)
     331        TRB_CTRL_SET_XFER_LEN(trb, batch->buffer_size);
     332        // FIXME: TD size 4.11.2.4
     333        TRB_CTRL_SET_TD_SIZE(trb, 1);
     334
     335        // we want an interrupt after this td is done
     336        TRB_CTRL_SET_IOC(trb, 1);
     337
     338        TRB_CTRL_SET_TRB_TYPE(trb, XHCI_TRB_TYPE_NORMAL);
     339
     340        xhci_trb_ring_enqueue(ring, &trb, &transfer->interrupt_trb_phys);
     341        list_append(&transfer->link, &hc->transfers);
     342
     343        const uint8_t target = 2 * batch->ep->target.endpoint
     344                + (batch->ep->direction == USB_DIRECTION_IN ? 1 : 0);
     345        usb_log_debug("Ringing doorbell for slot_id = %d, target = %d", slot_id, target);
     346        return hc_ring_doorbell(hc, slot_id, target);
     347}
     348
    302349int xhci_handle_transfer_event(xhci_hc_t* hc, xhci_trb_t* trb)
    303350{
Note: See TracChangeset for help on using the changeset viewer.