Ignore:
Timestamp:
2018-02-28T16:37:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b20da0
Parents:
f5e5f73 (diff), b2dca8de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
git-committer:
Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
Message:

Merge github.com:helenos-xhci-team/helenos

This commit merges support for USB 3 and generally refactors, fixes,
extends and cleans up the existing USB framework.

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Jan Vesely
     3 * Copyright (c) 2018 Ondrej Hlavaty
    34 * All rights reserved.
    45 *
     
    3738#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
    3839
    39 #include <usb/host/endpoint.h>
    40 #include <usb/usb.h>
    41 
    42 #include <assert.h>
     40#include <atomic.h>
     41#include <errno.h>
    4342#include <stddef.h>
    4443#include <stdint.h>
     44#include <usb/dma_buffer.h>
     45#include <usb/request.h>
     46#include <usb/usb.h>
    4547#include <usbhc_iface.h>
    4648
    47 #define USB_SETUP_PACKET_SIZE 8
     49#include <usb/host/hcd.h>
     50#include <usb/host/endpoint.h>
     51#include <usb/host/bus.h>
     52
     53typedef struct endpoint endpoint_t;
     54typedef struct bus bus_t;
    4855
    4956/** Structure stores additional data needed for communication with EP */
    5057typedef struct usb_transfer_batch {
     58        /** Target for communication */
     59        usb_target_t target;
     60        /** Direction of the transfer */
     61        usb_direction_t dir;
     62
    5163        /** Endpoint used for communication */
    5264        endpoint_t *ep;
    53         /** Function called on completion (IN version) */
    54         usbhc_iface_transfer_in_callback_t callback_in;
    55         /** Function called on completion (OUT version) */
    56         usbhc_iface_transfer_out_callback_t callback_out;
    57         /** Argument to pass to the completion function */
    58         void *arg;
    59         /** Place for data to send/receive */
    60         char *buffer;
    61         /** Size of memory pointed to by buffer member */
    62         size_t buffer_size;
     65
    6366        /** Place to store SETUP data needed by control transfers */
    64         char setup_buffer[USB_SETUP_PACKET_SIZE];
    65         /** Used portion of setup_buffer member
    66          *
    67          * SETUP buffer must be 8 bytes for control transfers and is left
    68          * unused for all other transfers. Thus, this field is either 0 or 8.
     67        union {
     68                char buffer [USB_SETUP_PACKET_SIZE];
     69                usb_device_request_setup_packet_t packet;
     70                uint64_t packed;
     71        } setup;
     72
     73        /** DMA buffer with enforced policy */
     74        dma_buffer_t dma_buffer;
     75        /** Size of memory buffer */
     76        size_t offset, size;
     77
     78        /**
     79         * In case a bounce buffer is allocated, the original buffer must to be
     80         * stored to be filled after the IN transaction is finished.
    6981         */
    70         size_t setup_size;
     82        char *original_buffer;
     83        bool is_bounced;
    7184
    72         /** Actually used portion of the buffer
    73          * This member is never accessed by functions provided in this header,
    74          * with the exception of usb_transfer_batch_finish. For external use.
    75          */
    76         size_t transfered_size;
    77         /** Indicates success/failure of the communication
    78          * This member is never accessed by functions provided in this header,
    79          * with the exception of usb_transfer_batch_finish. For external use.
    80          */
     85        /** Indicates success/failure of the communication */
    8186        errno_t error;
     87        /** Actually used portion of the buffer */
     88        size_t transferred_size;
     89
     90        /** Function called on completion */
     91        usbhc_iface_transfer_callback_t on_complete;
     92        /** Arbitrary data for the handler */
     93        void *on_complete_data;
    8294} usb_transfer_batch_t;
    8395
    84 /** Printf formatting string for dumping usb_transfer_batch_t. */
     96/**
     97 * Printf formatting string for dumping usb_transfer_batch_t.
     98 *  [address:endpoint speed transfer_type-direction buffer_sizeB/max_packet_size]
     99 * */
    85100#define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
    86101
     
    89104 */
    90105#define USB_TRANSFER_BATCH_ARGS(batch) \
    91         (batch).ep->address, (batch).ep->endpoint, \
    92         usb_str_speed((batch).ep->speed), \
     106        ((batch).ep->device->address), ((batch).ep->endpoint), \
     107        usb_str_speed((batch).ep->device->speed), \
    93108        usb_str_transfer_type_short((batch).ep->transfer_type), \
    94         usb_str_direction((batch).ep->direction), \
    95         (batch).buffer_size, (batch).ep->max_packet_size
     109        usb_str_direction((batch).dir), \
     110        (batch).size, (batch).ep->max_packet_size
    96111
     112/** Wrapper for bus operation. */
     113usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *);
    97114
    98 usb_transfer_batch_t * usb_transfer_batch_create(
    99     endpoint_t *ep,
    100     char *buffer,
    101     size_t buffer_size,
    102     uint64_t setup_buffer,
    103     usbhc_iface_transfer_in_callback_t func_in,
    104     usbhc_iface_transfer_out_callback_t func_out,
    105     void *arg
    106 );
    107 void usb_transfer_batch_destroy(usb_transfer_batch_t *instance);
     115/** Batch initializer. */
     116void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *);
    108117
    109 void usb_transfer_batch_finish_error(const usb_transfer_batch_t *instance,
    110     const void* data, size_t size, errno_t error);
     118/** Buffer handling */
     119bool usb_transfer_batch_bounce_required(usb_transfer_batch_t *);
     120errno_t usb_transfer_batch_bounce(usb_transfer_batch_t *);
    111121
    112 /** Finish batch using stored error value and transferred size.
    113  *
    114  * @param[in] instance Batch structure to use.
    115  * @param[in] data Data to copy to the output buffer.
     122/** Batch finalization. */
     123void usb_transfer_batch_finish(usb_transfer_batch_t *);
     124
     125/** To be called from outside only when the transfer is not going to be finished
     126 * (i.o.w. until successfuly scheduling)
    116127 */
    117 static inline void usb_transfer_batch_finish(
    118     const usb_transfer_batch_t *instance, const void* data)
    119 {
    120         assert(instance);
    121         usb_transfer_batch_finish_error(
    122             instance, data, instance->transfered_size, instance->error);
    123 }
    124 
    125 /** Determine batch direction based on the callbacks present
    126  * @param[in] instance Batch structure to use, non-null.
    127  * @return USB_DIRECTION_IN, or USB_DIRECTION_OUT.
    128  */
    129 static inline usb_direction_t usb_transfer_batch_direction(
    130     const usb_transfer_batch_t *instance)
    131 {
    132         assert(instance);
    133         if (instance->callback_in) {
    134                 assert(instance->callback_out == NULL);
    135                 assert(instance->ep == NULL
    136                     || instance->ep->transfer_type == USB_TRANSFER_CONTROL
    137                     || instance->ep->direction == USB_DIRECTION_IN);
    138                 return USB_DIRECTION_IN;
    139         }
    140         if (instance->callback_out) {
    141                 assert(instance->callback_in == NULL);
    142                 assert(instance->ep == NULL
    143                     || instance->ep->transfer_type == USB_TRANSFER_CONTROL
    144                     || instance->ep->direction == USB_DIRECTION_OUT);
    145                 return USB_DIRECTION_OUT;
    146         }
    147         assert(false);
    148 }
     128void usb_transfer_batch_destroy(usb_transfer_batch_t *);
    149129
    150130#endif
Note: See TracChangeset for help on using the changeset viewer.