Path: blob/main/sys/contrib/edk2/Include/IndustryStandard/Usb.h
96339 views
/** @file1Support for USB 2.0 standard.23Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>4Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>56SPDX-License-Identifier: BSD-2-Clause-Patent78**/910#ifndef __USB_H__11#define __USB_H__1213//14// Subset of Class and Subclass definitions from USB Specs15//1617//18// Usb mass storage class code19//20#define USB_MASS_STORE_CLASS 0x082122//23// Usb mass storage subclass code, specify the command set used.24//25#define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands26#define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device27#define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device28#define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device29#define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device.30#define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set3132//33// Usb mass storage protocol code, specify the transport protocol34//35#define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt36#define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt37#define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport3839//40// Standard device request and request type41// USB 2.0 spec, Section 9.442//43#define USB_DEV_GET_STATUS 0x0044#define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device45#define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface46#define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint4748#define USB_DEV_CLEAR_FEATURE 0x0149#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device50#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface51#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint5253#define USB_DEV_SET_FEATURE 0x0354#define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device55#define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface56#define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint5758#define USB_DEV_SET_ADDRESS 0x0559#define USB_DEV_SET_ADDRESS_REQ_TYPE 0x006061#define USB_DEV_GET_DESCRIPTOR 0x0662#define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x806364#define USB_DEV_SET_DESCRIPTOR 0x0765#define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x006667#define USB_DEV_GET_CONFIGURATION 0x0868#define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x806970#define USB_DEV_SET_CONFIGURATION 0x0971#define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x007273#define USB_DEV_GET_INTERFACE 0x0A74#define USB_DEV_GET_INTERFACE_REQ_TYPE 0x817576#define USB_DEV_SET_INTERFACE 0x0B77#define USB_DEV_SET_INTERFACE_REQ_TYPE 0x017879#define USB_DEV_SYNCH_FRAME 0x0C80#define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x828182//83// USB standard descriptors and reqeust84//85#pragma pack(1)8687///88/// Format of Setup Data for USB Device Requests89/// USB 2.0 spec, Section 9.390///91typedef struct {92UINT8 RequestType;93UINT8 Request;94UINT16 Value;95UINT16 Index;96UINT16 Length;97} USB_DEVICE_REQUEST;9899///100/// Standard Device Descriptor101/// USB 2.0 spec, Section 9.6.1102///103typedef struct {104UINT8 Length;105UINT8 DescriptorType;106UINT16 BcdUSB;107UINT8 DeviceClass;108UINT8 DeviceSubClass;109UINT8 DeviceProtocol;110UINT8 MaxPacketSize0;111UINT16 IdVendor;112UINT16 IdProduct;113UINT16 BcdDevice;114UINT8 StrManufacturer;115UINT8 StrProduct;116UINT8 StrSerialNumber;117UINT8 NumConfigurations;118} USB_DEVICE_DESCRIPTOR;119120///121/// Standard Configuration Descriptor122/// USB 2.0 spec, Section 9.6.3123///124typedef struct {125UINT8 Length;126UINT8 DescriptorType;127UINT16 TotalLength;128UINT8 NumInterfaces;129UINT8 ConfigurationValue;130UINT8 Configuration;131UINT8 Attributes;132UINT8 MaxPower;133} USB_CONFIG_DESCRIPTOR;134135///136/// Standard Interface Association Descriptor137/// USB 3.0 spec, Section 9.6.4138///139typedef struct {140UINT8 Length;141UINT8 DescriptorType;142UINT8 FirstInterface;143UINT8 InterfaceCount;144UINT8 FunctionClass;145UINT8 FunctionSubclass;146UINT8 FunctionProtocol;147UINT8 FunctionDescriptionStringIndex;148} USB_INTERFACE_ASSOCIATION_DESCRIPTOR;149150///151/// Standard Interface Descriptor152/// USB 2.0 spec, Section 9.6.5153///154typedef struct {155UINT8 Length;156UINT8 DescriptorType;157UINT8 InterfaceNumber;158UINT8 AlternateSetting;159UINT8 NumEndpoints;160UINT8 InterfaceClass;161UINT8 InterfaceSubClass;162UINT8 InterfaceProtocol;163UINT8 Interface;164} USB_INTERFACE_DESCRIPTOR;165166///167/// Standard Endpoint Descriptor168/// USB 2.0 spec, Section 9.6.6169///170typedef struct {171UINT8 Length;172UINT8 DescriptorType;173UINT8 EndpointAddress;174UINT8 Attributes;175UINT16 MaxPacketSize;176UINT8 Interval;177} USB_ENDPOINT_DESCRIPTOR;178179///180/// UNICODE String Descriptor181/// USB 2.0 spec, Section 9.6.7182///183typedef struct {184UINT8 Length;185UINT8 DescriptorType;186CHAR16 String[1];187} EFI_USB_STRING_DESCRIPTOR;188189#pragma pack()190191typedef enum {192//193// USB request type194//195USB_REQ_TYPE_STANDARD = (0x00 << 5),196USB_REQ_TYPE_CLASS = (0x01 << 5),197USB_REQ_TYPE_VENDOR = (0x02 << 5),198199//200// Standard control transfer request type, or the value201// to fill in EFI_USB_DEVICE_REQUEST.Request202//203USB_REQ_GET_STATUS = 0x00,204USB_REQ_CLEAR_FEATURE = 0x01,205USB_REQ_SET_FEATURE = 0x03,206USB_REQ_SET_ADDRESS = 0x05,207USB_REQ_GET_DESCRIPTOR = 0x06,208USB_REQ_SET_DESCRIPTOR = 0x07,209USB_REQ_GET_CONFIG = 0x08,210USB_REQ_SET_CONFIG = 0x09,211USB_REQ_GET_INTERFACE = 0x0A,212USB_REQ_SET_INTERFACE = 0x0B,213USB_REQ_SYNCH_FRAME = 0x0C,214215//216// Usb control transfer target217//218USB_TARGET_DEVICE = 0,219USB_TARGET_INTERFACE = 0x01,220USB_TARGET_ENDPOINT = 0x02,221USB_TARGET_OTHER = 0x03,222223//224// USB Descriptor types225//226USB_DESC_TYPE_DEVICE = 0x01,227USB_DESC_TYPE_CONFIG = 0x02,228USB_DESC_TYPE_STRING = 0x03,229USB_DESC_TYPE_INTERFACE = 0x04,230USB_DESC_TYPE_ENDPOINT = 0x05,231USB_DESC_TYPE_INTERFACE_ASSOCIATION = 0x0b,232USB_DESC_TYPE_HID = 0x21,233USB_DESC_TYPE_REPORT = 0x22,234USB_DESC_TYPE_CS_INTERFACE = 0x24,235USB_DESC_TYPE_CS_ENDPOINT = 0x25,236237//238// Features to be cleared by CLEAR_FEATURE requests239//240USB_FEATURE_ENDPOINT_HALT = 0,241242//243// USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt244//245USB_ENDPOINT_CONTROL = 0x00,246USB_ENDPOINT_ISO = 0x01,247USB_ENDPOINT_BULK = 0x02,248USB_ENDPOINT_INTERRUPT = 0x03,249250USB_ENDPOINT_TYPE_MASK = 0x03,251USB_ENDPOINT_DIR_IN = 0x80,252253//254// Use 200 ms to increase the error handling response time255//256EFI_USB_INTERRUPT_DELAY = 2000000257} USB_TYPES_DEFINITION;258259//260// HID constants definition, see Device Class Definition261// for Human Interface Devices (HID) rev1.11262//263264//265// HID standard GET_DESCRIPTOR request.266//267#define USB_HID_GET_DESCRIPTOR_REQ_TYPE 0x81268269//270// HID specific requests.271//272#define USB_HID_CLASS_GET_REQ_TYPE 0xa1273#define USB_HID_CLASS_SET_REQ_TYPE 0x21274275//276// HID report item format277//278#define HID_ITEM_FORMAT_SHORT 0279#define HID_ITEM_FORMAT_LONG 1280281//282// Special tag indicating long items283//284#define HID_ITEM_TAG_LONG 15285286//287// HID report descriptor item type (prefix bit 2,3)288//289#define HID_ITEM_TYPE_MAIN 0290#define HID_ITEM_TYPE_GLOBAL 1291#define HID_ITEM_TYPE_LOCAL 2292#define HID_ITEM_TYPE_RESERVED 3293294//295// HID report descriptor main item tags296//297#define HID_MAIN_ITEM_TAG_INPUT 8298#define HID_MAIN_ITEM_TAG_OUTPUT 9299#define HID_MAIN_ITEM_TAG_FEATURE 11300#define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10301#define HID_MAIN_ITEM_TAG_END_COLLECTION 12302303//304// HID report descriptor main item contents305//306#define HID_MAIN_ITEM_CONSTANT 0x001307#define HID_MAIN_ITEM_VARIABLE 0x002308#define HID_MAIN_ITEM_RELATIVE 0x004309#define HID_MAIN_ITEM_WRAP 0x008310#define HID_MAIN_ITEM_NONLINEAR 0x010311#define HID_MAIN_ITEM_NO_PREFERRED 0x020312#define HID_MAIN_ITEM_NULL_STATE 0x040313#define HID_MAIN_ITEM_VOLATILE 0x080314#define HID_MAIN_ITEM_BUFFERED_BYTE 0x100315316//317// HID report descriptor collection item types318//319#define HID_COLLECTION_PHYSICAL 0320#define HID_COLLECTION_APPLICATION 1321#define HID_COLLECTION_LOGICAL 2322323//324// HID report descriptor global item tags325//326#define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0327#define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1328#define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2329#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3330#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4331#define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5332#define HID_GLOBAL_ITEM_TAG_UNIT 6333#define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7334#define HID_GLOBAL_ITEM_TAG_REPORT_ID 8335#define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9336#define HID_GLOBAL_ITEM_TAG_PUSH 10337#define HID_GLOBAL_ITEM_TAG_POP 11338339//340// HID report descriptor local item tags341//342#define HID_LOCAL_ITEM_TAG_USAGE 0343#define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1344#define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2345#define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3346#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4347#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5348#define HID_LOCAL_ITEM_TAG_STRING_INDEX 7349#define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8350#define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9351#define HID_LOCAL_ITEM_TAG_DELIMITER 10352353//354// HID report types355//356#define HID_INPUT_REPORT 1357#define HID_OUTPUT_REPORT 2358#define HID_FEATURE_REPORT 3359360//361// HID class protocol request362//363#define EFI_USB_GET_REPORT_REQUEST 0x01364#define EFI_USB_GET_IDLE_REQUEST 0x02365#define EFI_USB_GET_PROTOCOL_REQUEST 0x03366#define EFI_USB_SET_REPORT_REQUEST 0x09367#define EFI_USB_SET_IDLE_REQUEST 0x0a368#define EFI_USB_SET_PROTOCOL_REQUEST 0x0b369370#pragma pack(1)371///372/// Descriptor header for Report/Physical Descriptors373/// HID 1.1, section 6.2.1374///375typedef struct hid_class_descriptor {376UINT8 DescriptorType;377UINT16 DescriptorLength;378} EFI_USB_HID_CLASS_DESCRIPTOR;379380///381/// The HID descriptor identifies the length and type382/// of subordinate descriptors for a device.383/// HID 1.1, section 6.2.1384///385typedef struct hid_descriptor {386UINT8 Length;387UINT8 DescriptorType;388UINT16 BcdHID;389UINT8 CountryCode;390UINT8 NumDescriptors;391EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc[1];392} EFI_USB_HID_DESCRIPTOR;393394#pragma pack()395396#endif397398399