Ignore:
File:
1 edited

Legend:

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

    rd4da860 ra6afb4c  
    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>
     43#include <async.h>
    4544
    46 extern int usbhc_read(async_exch_t *, usb_address_t, usb_endpoint_t,
    47     uint64_t, void *, size_t, size_t *);
    48 extern int usbhc_write(async_exch_t *, usb_address_t, usb_endpoint_t,
    49     uint64_t, const void *, size_t);
     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;
    5058
    51 /** Callback for outgoing transfer. */
    52 typedef void (*usbhc_iface_transfer_out_callback_t)(int, void *);
     59/** USB endpoint number type.
     60 * Negative values could be used to indicate error.
     61 */
     62typedef uint16_t usb_endpoint_t;
    5363
    54 /** Callback for incoming transfer. */
    55 typedef void (*usbhc_iface_transfer_in_callback_t)(int, size_t, void *);
     64/** USB address type.
     65 * Negative values could be used to indicate error.
     66 */
     67typedef uint16_t usb_address_t;
    5668
    57 /** USB host controller communication interface. */
     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
     105typedef struct usb_pipe_desc {
     106        /** Endpoint number. */
     107        usb_endpoint_t endpoint_no;
     108
     109        /** Endpoint transfer type. */
     110        usb_transfer_type_t transfer_type;
     111
     112        /** Endpoint direction. */
     113        usb_direction_t direction;
     114
     115        /** Maximum size of one transfer */
     116        size_t max_transfer_size;
     117} usb_pipe_desc_t;
     118
     119/** This structure follows standard endpoint descriptor + superspeed companion
     120 * descriptor, and exists to avoid dependency of libdrv on libusb. Keep the
     121 * internal fields named exactly like their source (because we want to use the
     122 * same macros to access them).
     123 * Callers shall fill it with bare contents of respective descriptors (in usb endianity).
     124 */
     125typedef struct usb_endpoint_descriptors {
     126        struct {
     127                uint8_t endpoint_address;
     128                uint8_t attributes;
     129                uint16_t max_packet_size;
     130                uint8_t poll_interval;
     131        } endpoint;
     132
     133        /* Superspeed companion descriptor */
     134        struct companion_desc_t {
     135                uint8_t max_burst;
     136                uint8_t attributes;
     137                uint16_t bytes_per_interval;
     138        } companion;
     139} usb_endpoint_descriptors_t;
     140
     141extern int usbhc_reserve_default_address(async_exch_t *);
     142extern int usbhc_release_default_address(async_exch_t *);
     143
     144extern int usbhc_device_enumerate(async_exch_t *, unsigned, usb_speed_t);
     145extern int usbhc_device_remove(async_exch_t *, unsigned);
     146
     147extern int usbhc_register_endpoint(async_exch_t *, usb_pipe_desc_t *, const usb_endpoint_descriptors_t *);
     148extern int usbhc_unregister_endpoint(async_exch_t *, const usb_pipe_desc_t *);
     149
     150extern int usbhc_read(async_exch_t *, usb_endpoint_t, uint64_t, void *, size_t,
     151    size_t *);
     152extern int usbhc_write(async_exch_t *, usb_endpoint_t, uint64_t, const void *,
     153    size_t);
     154
     155/** Callback for outgoing transfer */
     156typedef int (*usbhc_iface_transfer_callback_t)(void *, int, size_t);
     157
     158/** USB device communication interface. */
    58159typedef struct {
    59         int (*read)(ddf_fun_t *, usb_target_t, uint64_t, uint8_t *, size_t,
    60             usbhc_iface_transfer_in_callback_t, void *);
    61         int (*write)(ddf_fun_t *, usb_target_t, uint64_t, const uint8_t *,
    62             size_t, usbhc_iface_transfer_out_callback_t, void *);
     160        int (*default_address_reservation)(ddf_fun_t *, bool);
     161
     162        int (*device_enumerate)(ddf_fun_t *, unsigned, usb_speed_t);
     163        int (*device_remove)(ddf_fun_t *, unsigned);
     164
     165        int (*register_endpoint)(ddf_fun_t *, usb_pipe_desc_t *, const usb_endpoint_descriptors_t *);
     166        int (*unregister_endpoint)(ddf_fun_t *, const usb_pipe_desc_t *);
     167
     168        int (*read)(ddf_fun_t *, usb_target_t,
     169                uint64_t, char *, size_t,
     170                usbhc_iface_transfer_callback_t, void *);
     171        int (*write)(ddf_fun_t *, usb_target_t,
     172                uint64_t, const char *, size_t,
     173                usbhc_iface_transfer_callback_t, void *);
    63174} usbhc_iface_t;
    64 
    65175
    66176#endif
Note: See TracChangeset for help on using the changeset viewer.