Changeset c21e6a5 in mainline for uspace/drv/bus/usb/uhci/uhci_batch.c


Ignore:
Timestamp:
2018-02-05T00:54:08Z (7 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

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.