Changeset df6ded8 in mainline for uspace/lib/drv/include


Ignore:
Timestamp:
2018-02-28T16:37:50Z (8 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
Location:
uspace/lib/drv/include
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/include/usb_iface.h

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
     3 * Copyright (c) 2018 Ondrej Hlavaty, Michal Staruch
    34 * All rights reserved.
    45 *
     
    3233 */
    3334/** @file
    34  * @brief USB interface definition.
     35 * @brief USB device interface definition.
    3536 */
    3637
     
    4041#include "ddf/driver.h"
    4142#include <async.h>
     43#include <usbhc_iface.h>
    4244
    4345typedef async_sess_t usb_dev_session_t;
    4446
    45 /** USB speeds. */
    46 typedef enum {
    47         /** USB 1.1 low speed (1.5Mbits/s). */
    48         USB_SPEED_LOW,
    49         /** USB 1.1 full speed (12Mbits/s). */
    50         USB_SPEED_FULL,
    51         /** USB 2.0 high speed (480Mbits/s). */
    52         USB_SPEED_HIGH,
    53         /** Psuedo-speed serving as a boundary. */
    54         USB_SPEED_MAX
    55 } usb_speed_t;
    56 
    57 /** USB endpoint number type.
    58  * Negative values could be used to indicate error.
    59  */
    60 typedef int16_t usb_endpoint_t;
    61 
    62 /** USB address type.
    63  * Negative values could be used to indicate error.
    64  */
    65 typedef int16_t usb_address_t;
    66 
    67 /** USB transfer type. */
    68 typedef enum {
    69         USB_TRANSFER_CONTROL = 0,
    70         USB_TRANSFER_ISOCHRONOUS = 1,
    71         USB_TRANSFER_BULK = 2,
    72         USB_TRANSFER_INTERRUPT = 3
    73 } usb_transfer_type_t;
    74 
    75 /** USB data transfer direction. */
    76 typedef enum {
    77         USB_DIRECTION_IN,
    78         USB_DIRECTION_OUT,
    79         USB_DIRECTION_BOTH
    80 } usb_direction_t;
    81 
    82 /** USB complete address type.
    83  * Pair address + endpoint is identification of transaction recipient.
    84  */
    85 typedef union {
    86         struct {
    87                 usb_address_t address;
    88                 usb_endpoint_t endpoint;
    89         } __attribute__((packed));
    90         uint32_t packed;
    91 } usb_target_t;
     47typedef struct {
     48        usb_address_t address;  /**< Current USB address */
     49        uint8_t depth;          /**< Depth in the hub hiearchy */
     50        usb_speed_t speed;      /**< Speed of the device */
     51        devman_handle_t handle; /**< Handle to DDF function of the HC driver */
     52        /** Interface set by multi interface driver,  -1 if none */
     53        int iface;
     54} usb_device_desc_t;
    9255
    9356extern usb_dev_session_t *usb_dev_connect(devman_handle_t);
     
    9558extern void usb_dev_disconnect(usb_dev_session_t *);
    9659
    97 extern errno_t usb_get_my_interface(async_exch_t *, int *);
    98 extern errno_t usb_get_my_device_handle(async_exch_t *, devman_handle_t *);
    99 
    100 extern errno_t usb_reserve_default_address(async_exch_t *, usb_speed_t);
    101 extern errno_t usb_release_default_address(async_exch_t *);
    102 
    103 extern errno_t usb_device_enumerate(async_exch_t *, unsigned port);
    104 extern errno_t usb_device_remove(async_exch_t *, unsigned port);
    105 
    106 extern errno_t usb_register_endpoint(async_exch_t *, usb_endpoint_t,
    107     usb_transfer_type_t, usb_direction_t, size_t, unsigned, unsigned);
    108 extern errno_t usb_unregister_endpoint(async_exch_t *, usb_endpoint_t,
    109     usb_direction_t);
    110 extern errno_t usb_read(async_exch_t *, usb_endpoint_t, uint64_t, void *, size_t,
    111     size_t *);
    112 extern errno_t usb_write(async_exch_t *, usb_endpoint_t, uint64_t, const void *,
    113     size_t);
    114 
    115 /** Callback for outgoing transfer. */
    116 typedef void (*usb_iface_transfer_out_callback_t)(errno_t, void *);
    117 
    118 /** Callback for incoming transfer. */
    119 typedef void (*usb_iface_transfer_in_callback_t)(errno_t, size_t, void *);
     60extern errno_t usb_get_my_description(async_exch_t *, usb_device_desc_t *);
    12061
    12162/** USB device communication interface. */
    12263typedef struct {
    123         errno_t (*get_my_interface)(ddf_fun_t *, int *);
    124         errno_t (*get_my_device_handle)(ddf_fun_t *, devman_handle_t *);
    125 
    126         errno_t (*reserve_default_address)(ddf_fun_t *, usb_speed_t);
    127         errno_t (*release_default_address)(ddf_fun_t *);
    128 
    129         errno_t (*device_enumerate)(ddf_fun_t *, unsigned);
    130         errno_t (*device_remove)(ddf_fun_t *, unsigned);
    131 
    132         errno_t (*register_endpoint)(ddf_fun_t *, usb_endpoint_t,
    133             usb_transfer_type_t, usb_direction_t, size_t, unsigned, unsigned);
    134         errno_t (*unregister_endpoint)(ddf_fun_t *, usb_endpoint_t,
    135             usb_direction_t);
    136 
    137         errno_t (*read)(ddf_fun_t *, usb_endpoint_t, uint64_t, uint8_t *, size_t,
    138             usb_iface_transfer_in_callback_t, void *);
    139         errno_t (*write)(ddf_fun_t *, usb_endpoint_t, uint64_t, const uint8_t *,
    140             size_t, usb_iface_transfer_out_callback_t, void *);
     64        errno_t (*get_my_description)(ddf_fun_t *, usb_device_desc_t *);
    14165} usb_iface_t;
    14266
  • uspace/lib/drv/include/usbhc_iface.h

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
    3  * Copyright (c) 2011 Jan Vesely
     3 * Copyright (c) 2017 Ondrej Hlavaty
    44 * All rights reserved.
    55 *
     
    3232 * @{
    3333 */
    34 
    3534/** @file
    36  * @brief USB host controller interface definition.
     35 * @brief USB host controler interface definition. This is the interface of
     36 * USB host controller function, which can be used by usb device drivers.
    3737 */
    3838
     
    4141
    4242#include "ddf/driver.h"
    43 #include <usb_iface.h>
    44 #include <stdbool.h>
    45 
    46 extern errno_t usbhc_read(async_exch_t *, usb_address_t, usb_endpoint_t,
    47     uint64_t, void *, size_t, size_t *);
    48 extern errno_t usbhc_write(async_exch_t *, usb_address_t, usb_endpoint_t,
    49     uint64_t, const void *, size_t);
    50 
    51 /** Callback for outgoing transfer. */
    52 typedef void (*usbhc_iface_transfer_out_callback_t)(errno_t, void *);
    53 
    54 /** Callback for incoming transfer. */
    55 typedef void (*usbhc_iface_transfer_in_callback_t)(errno_t, size_t, void *);
    56 
    57 /** USB host controller communication interface. */
     43#include <async.h>
     44
     45/** USB speeds. */
     46typedef enum {
     47        /** USB 1.1 low speed (1.5Mbits/s). */
     48        USB_SPEED_LOW,
     49        /** USB 1.1 full speed (12Mbits/s). */
     50        USB_SPEED_FULL,
     51        /** USB 2.0 high speed (480Mbits/s). */
     52        USB_SPEED_HIGH,
     53        /** USB 3.0 super speed (5Gbits/s). */
     54        USB_SPEED_SUPER,
     55        /** Psuedo-speed serving as a boundary. */
     56        USB_SPEED_MAX
     57} usb_speed_t;
     58
     59/** USB endpoint number type.
     60 * Negative values could be used to indicate error.
     61 */
     62typedef uint16_t usb_endpoint_t;
     63
     64/** USB address type.
     65 * Negative values could be used to indicate error.
     66 */
     67typedef uint16_t usb_address_t;
     68
     69/**
     70 * USB Stream ID type.
     71 */
     72typedef uint16_t usb_stream_t;
     73
     74/** USB transfer type. */
     75typedef enum {
     76        USB_TRANSFER_CONTROL = 0,
     77        USB_TRANSFER_ISOCHRONOUS = 1,
     78        USB_TRANSFER_BULK = 2,
     79        USB_TRANSFER_INTERRUPT = 3,
     80} usb_transfer_type_t;
     81
     82#define USB_TRANSFER_COUNT  (USB_TRANSFER_INTERRUPT + 1)
     83
     84/** USB data transfer direction. */
     85typedef enum {
     86        USB_DIRECTION_IN,
     87        USB_DIRECTION_OUT,
     88        USB_DIRECTION_BOTH,
     89} usb_direction_t;
     90
     91#define USB_DIRECTION_COUNT  (USB_DIRECTION_BOTH + 1)
     92
     93/** USB complete address type.
     94 * Pair address + endpoint is identification of transaction recipient.
     95 */
     96typedef union {
     97        struct {
     98                usb_address_t address;
     99                usb_endpoint_t endpoint;
     100                usb_stream_t stream;
     101        } __attribute__((packed));
     102        uint64_t packed;
     103} usb_target_t;
     104
     105// FIXME: DMA buffers shall be part of libdrv anyway.
     106typedef uintptr_t dma_policy_t;
     107
     108typedef struct dma_buffer {
     109        void *virt;
     110        dma_policy_t policy;
     111} dma_buffer_t;
     112
     113typedef struct usb_pipe_desc {
     114        /** Endpoint number. */
     115        usb_endpoint_t endpoint_no;
     116
     117        /** Endpoint transfer type. */
     118        usb_transfer_type_t transfer_type;
     119
     120        /** Endpoint direction. */
     121        usb_direction_t direction;
     122
     123        /**
     124         * Maximum size of one transfer. Non-periodic endpoints may handle
     125         * bigger transfers, but those can be split into multiple USB transfers.
     126         */
     127        size_t max_transfer_size;
     128
     129        /** Constraints on buffers to be transferred without copying */
     130        dma_policy_t transfer_buffer_policy;
     131} usb_pipe_desc_t;
     132
     133typedef struct usb_pipe_transfer_request {
     134        usb_direction_t dir;
     135        usb_endpoint_t endpoint;
     136        usb_stream_t stream;
     137
     138        uint64_t setup;                 /**< Valid iff the transfer is of control type */
     139
     140        /**
     141         * The DMA buffer to share. Must be at least offset + size large. Is
     142         * patched after being transmitted over IPC, so the pointer is still
     143         * valid.
     144         */
     145        dma_buffer_t buffer;
     146        size_t offset;                  /**< Offset to the buffer */
     147        size_t size;                    /**< Requested size. */
     148} usbhc_iface_transfer_request_t;
     149
     150/** This structure follows standard endpoint descriptor + superspeed companion
     151 * descriptor, and exists to avoid dependency of libdrv on libusb. Keep the
     152 * internal fields named exactly like their source (because we want to use the
     153 * same macros to access them).
     154 * Callers shall fill it with bare contents of respective descriptors (in usb endianity).
     155 */
     156typedef struct usb_endpoint_descriptors {
     157        struct {
     158                uint8_t endpoint_address;
     159                uint8_t attributes;
     160                uint16_t max_packet_size;
     161                uint8_t poll_interval;
     162        } endpoint;
     163
     164        /* Superspeed companion descriptor */
     165        struct companion_desc_t {
     166                uint8_t max_burst;
     167                uint8_t attributes;
     168                uint16_t bytes_per_interval;
     169        } companion;
     170} usb_endpoint_descriptors_t;
     171
     172extern errno_t usbhc_reserve_default_address(async_exch_t *);
     173extern errno_t usbhc_release_default_address(async_exch_t *);
     174
     175extern errno_t usbhc_device_enumerate(async_exch_t *, unsigned, usb_speed_t);
     176extern errno_t usbhc_device_remove(async_exch_t *, unsigned);
     177
     178extern errno_t usbhc_register_endpoint(async_exch_t *, usb_pipe_desc_t *, const usb_endpoint_descriptors_t *);
     179extern errno_t usbhc_unregister_endpoint(async_exch_t *, const usb_pipe_desc_t *);
     180
     181extern errno_t usbhc_transfer(async_exch_t *, const usbhc_iface_transfer_request_t *, size_t *);
     182
     183/** Callback for outgoing transfer */
     184typedef errno_t (*usbhc_iface_transfer_callback_t)(void *, int, size_t);
     185
     186/** USB device communication interface. */
    58187typedef struct {
    59         errno_t (*read)(ddf_fun_t *, usb_target_t, uint64_t, uint8_t *, size_t,
    60             usbhc_iface_transfer_in_callback_t, void *);
    61         errno_t (*write)(ddf_fun_t *, usb_target_t, uint64_t, const uint8_t *,
    62             size_t, usbhc_iface_transfer_out_callback_t, void *);
     188        errno_t (*default_address_reservation)(ddf_fun_t *, bool);
     189
     190        errno_t (*device_enumerate)(ddf_fun_t *, unsigned, usb_speed_t);
     191        errno_t (*device_remove)(ddf_fun_t *, unsigned);
     192
     193        errno_t (*register_endpoint)(ddf_fun_t *, usb_pipe_desc_t *, const usb_endpoint_descriptors_t *);
     194        errno_t (*unregister_endpoint)(ddf_fun_t *, const usb_pipe_desc_t *);
     195
     196        errno_t (*transfer)(ddf_fun_t *, const usbhc_iface_transfer_request_t *,
     197            usbhc_iface_transfer_callback_t, void *);
    63198} usbhc_iface_t;
    64 
    65199
    66200#endif
Note: See TracChangeset for help on using the changeset viewer.