Changeset c21e6a5 in mainline for uspace/drv/bus/usb/uhci


Ignore:
Timestamp:
2018-02-05T00:54:08Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
af16ebe
Parents:
65c059f
git-author:
Ondřej Hlavatý <aearsis@…> (2018-02-05 00:27:40)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-02-05 00:54:08)
Message:

usbhost: prepare buffers for transfers in library

Location:
uspace/drv/bus/usb/uhci
Files:
3 edited

Legend:

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

    r65c059f rc21e6a5  
    6161{
    6262        assert(uhci_batch);
    63         free32(uhci_batch->device_buffer);
     63        dma_buffer_free(&uhci_batch->uhci_dma_buffer);
    6464        free(uhci_batch);
    6565}
     
    110110
    111111        const size_t total_size = (sizeof(td_t) * uhci_batch->td_count)
    112             + sizeof(qh_t) + setup_size + usb_batch->buffer_size;
    113         uhci_batch->device_buffer = malloc32(total_size);
    114         if (!uhci_batch->device_buffer) {
     112            + sizeof(qh_t) + setup_size;
     113
     114        if (dma_buffer_alloc(&uhci_batch->uhci_dma_buffer, total_size)) {
    115115                usb_log_error("Failed to allocate UHCI buffer.");
    116116                return ENOMEM;
    117117        }
    118         memset(uhci_batch->device_buffer, 0, total_size);
    119 
    120         uhci_batch->tds = uhci_batch->device_buffer;
    121         uhci_batch->qh =
    122             (uhci_batch->device_buffer + (sizeof(td_t) * uhci_batch->td_count));
     118        memset(uhci_batch->uhci_dma_buffer.virt, 0, total_size);
     119
     120        uhci_batch->tds = uhci_batch->uhci_dma_buffer.virt;
     121        uhci_batch->qh = (qh_t *) &uhci_batch->tds[uhci_batch->td_count];
    123122
    124123        qh_init(uhci_batch->qh);
    125124        qh_set_element_td(uhci_batch->qh, &uhci_batch->tds[0]);
    126125
    127         void *dest =
    128             uhci_batch->device_buffer + (sizeof(td_t) * uhci_batch->td_count)
    129             + sizeof(qh_t);
     126        void *setup_buffer = uhci_transfer_batch_setup_buffer(uhci_batch);
     127        assert(setup_buffer == (void *) (uhci_batch->qh + 1));
    130128        /* Copy SETUP packet data to the device buffer */
    131         memcpy(dest, usb_batch->setup.buffer, setup_size);
    132         dest += setup_size;
    133         /* Copy generic data unless they are provided by the device */
    134         if (usb_batch->dir != USB_DIRECTION_IN) {
    135                 memcpy(dest, usb_batch->buffer, usb_batch->buffer_size);
    136         }
     129        memcpy(setup_buffer, usb_batch->setup.buffer, setup_size);
     130
    137131        usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT
    138132            " memory structures ready.", usb_batch,
     
    196190        }
    197191
    198         if (batch->dir == USB_DIRECTION_IN) {
    199                 assert(batch->transferred_size <= batch->buffer_size);
    200                 memcpy(batch->buffer,
    201                     uhci_transfer_batch_data_buffer(uhci_batch),
    202                     batch->transferred_size);
    203         }
     192        assert(batch->transferred_size <= batch->buffer_size);
    204193
    205194        return true;
  • uspace/drv/bus/usb/uhci/uhci_batch.h

    r65c059f rc21e6a5  
    6161        /** Number of TDs used by the transfer */
    6262        size_t td_count;
    63         /** Data buffer, must be accessible by the UHCI hw */
    64         void *device_buffer;
     63        /* Setup data */
     64        char *setup_buffer;
     65        /** Backing TDs + setup_buffer */
     66        dma_buffer_t uhci_dma_buffer;
    6567        /** List element */
    6668        link_t link;
     
    8082{
    8183        assert(uhci_batch);
    82         assert(uhci_batch->device_buffer);
    83         return uhci_batch->device_buffer + sizeof(qh_t) +
     84        return uhci_batch->uhci_dma_buffer.virt + sizeof(qh_t) +
    8485            uhci_batch->td_count * sizeof(td_t);
    8586}
     
    9394{
    9495        assert(uhci_batch);
    95         return uhci_transfer_batch_setup_buffer(uhci_batch) +
    96             (uhci_batch->base.ep->transfer_type == USB_TRANSFER_CONTROL ? USB_SETUP_PACKET_SIZE : 0);
     96        return uhci_batch->base.dma_buffer.virt;
    9797}
    9898
  • uspace/drv/bus/usb/uhci/uhci_rh.c

    r65c059f rc21e6a5  
    107107                batch->error = virthub_base_request(&instance->base, batch->target,
    108108                    batch->dir, (void*) batch->setup.buffer,
    109                     batch->buffer, batch->buffer_size, &batch->transferred_size);
     109                    batch->dma_buffer.virt, batch->buffer_size, &batch->transferred_size);
    110110                if (batch->error == ENAK)
    111111                        async_usleep(instance->base.endpoint_descriptor.poll_interval * 1000);
Note: See TracChangeset for help on using the changeset viewer.