iPXE
usbio.h
Go to the documentation of this file.
00001 #ifndef _USBIO_H
00002 #define _USBIO_H
00003 
00004 /** @file
00005  *
00006  * EFI_USB_IO_PROTOCOL pseudo Host Controller Interface driver
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <ipxe/list.h>
00013 #include <ipxe/device.h>
00014 #include <ipxe/efi/efi.h>
00015 #include <ipxe/efi/Protocol/UsbIo.h>
00016 #include <ipxe/efi/Protocol/DevicePath.h>
00017 #include <ipxe/usb.h>
00018 
00019 /** USB I/O maximum transfer size
00020  *
00021  * The API provides no way to discover the maximum transfer size.
00022  * Assume the 16kB supported by EHCI.
00023  */
00024 #define USBIO_MTU 16384
00025 
00026 /** USB I/O interrupt ring buffer size
00027  *
00028  * This is a policy decision.
00029  */
00030 #define USBIO_INTR_COUNT 4
00031 
00032 /** A USB interrupt ring buffer */
00033 struct usbio_interrupt_ring {
00034         /** USB I/O endpoint */
00035         struct usbio_endpoint *endpoint;
00036         /** Producer counter */
00037         unsigned int prod;
00038         /** Consumer counter */
00039         unsigned int cons;
00040         /** Data buffers */
00041         void *data[USBIO_INTR_COUNT];
00042         /** Lengths */
00043         size_t len[USBIO_INTR_COUNT];
00044 };
00045 
00046 /** USB I/O ring buffer size
00047  *
00048  * This is a policy decision.
00049  */
00050 #define USBIO_RING_COUNT 64
00051 
00052 /** A USB I/O endpoint */
00053 struct usbio_endpoint {
00054         /** USB I/O device */
00055         struct usbio_device *usbio;
00056         /** USB endpoint */
00057         struct usb_endpoint *ep;
00058         /** List of endpoints */
00059         struct list_head list;
00060         /** USB I/O endpoint operations */
00061         struct usbio_operations *op;
00062 
00063         /** Containing interface number */
00064         unsigned int interface;
00065         /** EFI handle */
00066         EFI_HANDLE handle;
00067         /** USB I/O protocol */
00068         EFI_USB_IO_PROTOCOL *io;
00069 
00070         /** Producer counter */
00071         unsigned int prod;
00072         /** Consumer counter */
00073         unsigned int cons;
00074         /** I/O buffers */
00075         struct io_buffer *iobuf[USBIO_RING_COUNT];
00076         /** Flags */
00077         uint8_t flags[USBIO_RING_COUNT];
00078 
00079         /** Interrupt ring buffer (if applicable) */
00080         struct usbio_interrupt_ring *intr;
00081 };
00082 
00083 /** USB I/O transfer flags */
00084 enum usbio_flags {
00085         /** This is a message transfer */
00086         USBIO_MESSAGE = 0x01,
00087         /** This transfer requires zero-length packet termination */
00088         USBIO_ZLEN = 0x02,
00089 };
00090 
00091 /** USB I/O endpoint operations */
00092 struct usbio_operations {
00093         /** Open endpoint
00094          *
00095          * @v endpoint          Endpoint
00096          * @ret rc              Return status code
00097          */
00098         int ( * open ) ( struct usbio_endpoint *endpoint );
00099         /** Close endpoint
00100          *
00101          * @v endpoint          Endpoint
00102          */
00103         void ( * close ) ( struct usbio_endpoint *endpoint );
00104         /** Poll endpoint
00105          *
00106          * @v endpoint          Endpoint
00107          */
00108         void ( * poll ) ( struct usbio_endpoint *endpoint );
00109 };
00110 
00111 /** A USB I/O protocol interface */
00112 struct usbio_interface {
00113         /** EFI device handle */
00114         EFI_HANDLE handle;
00115         /** USB I/O protocol */
00116         EFI_USB_IO_PROTOCOL *io;
00117         /** Usage count */
00118         unsigned int count;
00119 };
00120 
00121 /** A USB I/O protocol device
00122  *
00123  * We model each externally-provided USB I/O protocol device as a host
00124  * controller containing a root hub with a single port.
00125  */
00126 struct usbio_device {
00127         /** EFI device handle */
00128         EFI_HANDLE handle;
00129         /** USB I/O protocol */
00130         EFI_USB_IO_PROTOCOL *io;
00131         /** Generic device */
00132         struct device dev;
00133 
00134         /** Configuration descriptor */
00135         struct usb_configuration_descriptor *config;
00136 
00137         /** Device path */
00138         EFI_DEVICE_PATH_PROTOCOL *path;
00139         /** Final component of USB device path */
00140         USB_DEVICE_PATH *usbpath;
00141 
00142         /** First interface number */
00143         uint8_t first;
00144         /** USB I/O protocol interfaces */
00145         struct usbio_interface *interface;
00146 
00147         /** USB bus */
00148         struct usb_bus *bus;
00149         /** List of endpoints */
00150         struct list_head endpoints;
00151 };
00152 
00153 #endif /* _USBIO_H */