1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <efi/types.h> 8 9 #define EFI_USB_IO_PROTOCOL_GUID \ 10 {0x2b2f68d6, 0x0cd2, 0x44cf, {0x8e, 0x8b, 0xbb, 0xa2, 0x0b, 0x1b, 0x5b, 0x75}} 11 extern efi_guid UsbIoProtocol; 12 13 typedef enum { 14 EfiUsbDataIn, 15 EfiUsbDataOut, 16 EfiUsbNoData 17 } efi_usb_data_direction; 18 19 #define EFI_USB_NOERROR 0x0000 20 #define EFI_USB_ERR_NOTEXECUTE 0x0001 21 #define EFI_USB_ERR_STALL 0x0002 22 #define EFI_USB_ERR_BUFFER 0x0004 23 #define EFI_USB_ERR_BABBLE 0x0008 24 #define EFI_USB_ERR_NAK 0x0010 25 #define EFI_USB_ERR_CRC 0x0020 26 #define EFI_USB_ERR_TIMEOUT 0x0040 27 #define EFI_USB_ERR_BITSTUFF 0x0080 28 #define EFI_USB_ERR_SYSTEM 0x0100 29 30 typedef struct { 31 uint8_t RequestType; 32 uint8_t Request; 33 uint16_t Value; 34 uint16_t Index; 35 uint16_t Length; 36 } efi_usb_device_request; 37 38 typedef efi_status (*efi_async_usb_transfer_callback) ( 39 void* Data, size_t DataLength, void* Context, uint32_t Status) EFIAPI; 40 41 typedef struct { 42 uint8_t Length; 43 uint8_t DescriptorType; 44 uint16_t BcdUSB; 45 uint8_t DeviceClass; 46 uint8_t DeviceSubClass; 47 uint8_t DeviceProtocol; 48 uint8_t MaxPacketSize0; 49 uint16_t IdVendor; 50 uint16_t IdProduct; 51 uint16_t BcdDevice; 52 uint8_t StrManufacturer; 53 uint8_t StrProduct; 54 uint8_t StrSerialNumber; 55 uint8_t NumConfigurations; 56 } efi_usb_device_descriptor; 57 58 typedef struct { 59 uint8_t Length; 60 uint8_t DescriptorType; 61 uint16_t TotalLength; 62 uint8_t NumInterfaces; 63 uint8_t ConfigurationValue; 64 uint8_t Configuration; 65 uint8_t Attributes; 66 uint8_t MaxPower; 67 } efi_usb_config_descriptor; 68 69 typedef struct { 70 uint8_t Length; 71 uint8_t DescriptorType; 72 uint8_t InterfaceNumber; 73 uint8_t AlternateSetting; 74 uint8_t NumEndpoints; 75 uint8_t InterfaceClass; 76 uint8_t InterfaceSubClass; 77 uint8_t InterfaceProtocol; 78 uint8_t Interface; 79 } efi_usb_interface_descriptor; 80 81 typedef struct { 82 uint8_t Length; 83 uint8_t DescriptorType; 84 uint8_t EndpointAddress; 85 uint8_t Attributes; 86 uint16_t MaxPacketSize; 87 uint8_t Interval; 88 } efi_usb_endpoint_descriptor; 89 90 typedef struct efi_usb_io_protocol { 91 efi_status (*UsbControlTransfer) (struct efi_usb_io_protocol* self, 92 efi_usb_device_request* request, 93 efi_usb_data_direction direction, 94 uint32_t timeout, void* data, 95 size_t data_len, uint32_t* status) EFIAPI; 96 97 efi_status (*UsbBulkTransfer) (struct efi_usb_io_protocol* self, 98 uint8_t endpoint, void* data, 99 size_t data_len, size_t timeout, 100 uint32_t* status) EFIAPI; 101 102 efi_status (*UsbAsyncInterruptTransfer) (struct efi_usb_io_protocol* self, 103 uint8_t endpoint, bool is_new_transfer, 104 size_t polling_interval, 105 size_t data_len, 106 efi_async_usb_transfer_callback interrupt_cb, 107 void* context) EFIAPI; 108 109 efi_status (*UsbSyncInterruptTransfer) (struct efi_usb_io_protocol* self, 110 uint8_t endpoint, void* data, 111 size_t* data_len, size_t timeout, 112 uint32_t* status) EFIAPI; 113 114 efi_status (*UsbIsochronousTransfer) (struct efi_usb_io_protocol* self, 115 uint8_t endpoint, 116 void* data, size_t data_len, 117 uint32_t* status) EFIAPI; 118 119 efi_status (*UsbAsyncIsochronousTransfer) (struct efi_usb_io_protocol* self, 120 uint8_t endpoint, 121 void* data, size_t data_len, 122 efi_async_usb_transfer_callback isoc_cb, 123 void* context) EFIAPI; 124 125 efi_status (*UsbGetDeviceDescriptor) (struct efi_usb_io_protocol* self, 126 efi_usb_device_descriptor* descriptor) EFIAPI; 127 128 efi_status (*UsbGetConfigDescriptor) (struct efi_usb_io_protocol* self, 129 efi_usb_config_descriptor* descriptor) EFIAPI; 130 131 efi_status (*UsbGetInterfaceDescriptor) (struct efi_usb_io_protocol* self, 132 efi_usb_interface_descriptor* descriptor) EFIAPI; 133 134 efi_status (*UsbGetEndpointDescriptor) (struct efi_usb_io_protocol* self, 135 uint8_t endpt_index, 136 efi_usb_endpoint_descriptor* descriptor) EFIAPI; 137 138 efi_status (*UsbGetStringDescriptor) (struct efi_usb_io_protocol* self, 139 uint16_t langid, uint8_t stringid, 140 char16_t** str) EFIAPI; 141 142 efi_status (*UsbGetSupportedLanguages) (struct efi_usb_io_protocol* self, 143 uint16_t** langid_table, 144 uint16_t* table_size) EFIAPI; 145 146 efi_status (*UsbPortReset) (struct efi_usb_io_protocol* self) EFIAPI; 147 } efi_usb_io_protocol; 148