Changeset 1d758fc in mainline for uspace/lib/usbhost/src/endpoint.c


Ignore:
Timestamp:
2018-02-12T10:11:47Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5fe3f954
Parents:
2f762a7
git-author:
Ondřej Hlavatý <aearsis@…> (2018-02-05 03:28:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-02-12 10:11:47)
Message:

usb: rethinking DMA buffers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/endpoint.c

    r2f762a7 r1d758fc  
    7575        ep->max_transfer_size = ep->max_packet_size * ep->packets_per_uframe;
    7676        ep->transfer_buffer_policy = DMA_POLICY_STRICT;
     77        ep->required_transfer_buffer_policy = DMA_POLICY_STRICT;
    7778}
    7879
     
    207208 *
    208209 * @param endpoint Endpoint for which to send the batch
    209  * @param target The target of the transfer.
    210  * @param direction A direction of the transfer.
    211  * @param data A pointer to the data buffer.
    212  * @param size Size of the data buffer.
    213  * @param setup_data Data to use in the setup stage (Control communication type)
    214  * @param on_complete Callback which is called after the batch is complete
    215  * @param arg Callback parameter.
    216  * @param name Communication identifier (for nicer output).
    217  */
    218 errno_t endpoint_send_batch(endpoint_t *ep, usb_target_t target,
    219     usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
    220     usbhc_iface_transfer_callback_t on_complete, void *arg, const char *name)
    221 {
    222         if (!ep)
    223                 return EBADMEM;
     210 */
     211errno_t endpoint_send_batch(endpoint_t *ep, const transfer_request_t *req)
     212{
     213        assert(ep);
     214        assert(req);
    224215
    225216        if (ep->transfer_type == USB_TRANSFER_CONTROL) {
    226                 usb_log_debug("%s %d:%d %zu/%zuB, setup %#016" PRIx64, name,
    227                     target.address, target.endpoint, size, ep->max_packet_size,
    228                     setup_data);
     217                usb_log_debug("%s %d:%d %zu/%zuB, setup %#016" PRIx64, req->name,
     218                    req->target.address, req->target.endpoint,
     219                    req->size, ep->max_packet_size,
     220                    req->setup);
    229221        } else {
    230                 usb_log_debug("%s %d:%d %zu/%zuB", name, target.address,
    231                     target.endpoint, size, ep->max_packet_size);
     222                usb_log_debug("%s %d:%d %zu/%zuB", req->name,
     223                    req->target.address, req->target.endpoint,
     224                    req->size, ep->max_packet_size);
    232225        }
    233226
     
    244237        }
    245238
     239        size_t size = req->size;
    246240        /*
    247241         * Limit transfers with reserved bandwidth to the amount reserved.
    248242         * OUT transfers are rejected, IN can be just trimmed in advance.
    249243         */
    250         if ((ep->transfer_type == USB_TRANSFER_INTERRUPT || ep->transfer_type == USB_TRANSFER_ISOCHRONOUS) && size > ep->max_transfer_size) {
    251                 if (direction == USB_DIRECTION_OUT)
     244        if (size > ep->max_transfer_size &&
     245            (ep->transfer_type == USB_TRANSFER_INTERRUPT
     246             || ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)) {
     247                if (req->dir == USB_DIRECTION_OUT)
    252248                        return ENOSPC;
    253249                else
    254250                        size = ep->max_transfer_size;
    255 
    256251        }
    257252
     
    266261        }
    267262
    268         batch->target = target;
    269         batch->setup.packed = setup_data;
    270         batch->dir = direction;
    271         batch->buffer_size = size;
    272 
    273         errno_t err;
    274         if ((err = usb_transfer_batch_prepare_buffer(batch, data))) {
    275                 usb_log_warning("Failed to prepare buffer for batch: %s", str_error(err));
    276                 usb_transfer_batch_destroy(batch);
    277                 return err;
    278         }
    279 
    280         batch->on_complete = on_complete;
    281         batch->on_complete_data = arg;
     263        batch->target = req->target;
     264        batch->setup.packed = req->setup;
     265        batch->dir = req->dir;
     266        batch->size = size;
     267        batch->offset = req->offset;
     268        batch->dma_buffer = req->buffer;
     269
     270        dma_buffer_acquire(&batch->dma_buffer);
     271
     272        if (batch->offset != 0) {
     273                usb_log_debug("A transfer with nonzero offset requested.");
     274                usb_transfer_batch_bounce(batch);
     275        }
     276
     277        if (usb_transfer_batch_bounce_required(batch))
     278                usb_transfer_batch_bounce(batch);
     279
     280        batch->on_complete = req->on_complete;
     281        batch->on_complete_data = req->arg;
    282282
    283283        const int ret = ops->batch_schedule(batch);
Note: See TracChangeset for help on using the changeset viewer.