]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbBusPei/PeiUsbLib.h
e0557f8eea47506e17409300dc5f188de0cd8040
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusPei / PeiUsbLib.h
1 /** @file
2 Common Libarary for PEI USB
3
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #ifndef _PEI_USB_LIB_H_
18 #define _PEI_USB_LIB_H_
19
20
21 //
22 // Standard device request and request type
23 // By [Spec-USB20/Chapter-9.4]
24 //
25 #define USB_DEV_GET_STATUS 0x00
26 #define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device
27 #define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface
28 #define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint
29
30 #define USB_DEV_CLEAR_FEATURE 0x01
31 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
32 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
33 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
34
35 #define USB_DEV_SET_FEATURE 0x03
36 #define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
37 #define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
38 #define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
39
40 #define USB_DEV_SET_ADDRESS 0x05
41 #define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00
42
43 #define USB_DEV_GET_DESCRIPTOR 0x06
44 #define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80
45
46 #define USB_DEV_SET_DESCRIPTOR 0x07
47 #define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00
48
49 #define USB_DEV_GET_CONFIGURATION 0x08
50 #define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80
51
52 #define USB_DEV_SET_CONFIGURATION 0x09
53 #define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00
54
55 #define USB_DEV_GET_INTERFACE 0x0A
56 #define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81
57
58 #define USB_DEV_SET_INTERFACE 0x0B
59 #define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01
60
61 #define USB_DEV_SYNCH_FRAME 0x0C
62 #define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82
63
64 //
65 // USB Descriptor types
66 //
67 #define USB_DT_DEVICE 0x01
68 #define USB_DT_CONFIG 0x02
69 #define USB_DT_STRING 0x03
70 #define USB_DT_INTERFACE 0x04
71 #define USB_DT_ENDPOINT 0x05
72 #define USB_DT_HUB 0x29
73 #define USB_DT_HID 0x21
74
75 //
76 // USB request type
77 //
78 #define USB_TYPE_STANDARD (0x00 << 5)
79 #define USB_TYPE_CLASS (0x01 << 5)
80 #define USB_TYPE_VENDOR (0x02 << 5)
81 #define USB_TYPE_RESERVED (0x03 << 5)
82
83 //
84 // USB request targer device
85 //
86 #define USB_RECIP_DEVICE 0x00
87 #define USB_RECIP_INTERFACE 0x01
88 #define USB_RECIP_ENDPOINT 0x02
89 #define USB_RECIP_OTHER 0x03
90
91 typedef enum {
92 EfiUsbEndpointHalt,
93 EfiUsbDeviceRemoteWakeup
94 } EFI_USB_STANDARD_FEATURE_SELECTOR;
95
96 //
97 // Usb Data recipient type
98 //
99 typedef enum {
100 EfiUsbDevice,
101 EfiUsbInterface,
102 EfiUsbEndpoint
103 } EFI_USB_RECIPIENT;
104
105 /**
106 Get a given usb descriptor.
107
108 @param PeiServices General-purpose services that are available to every PEIM.
109 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
110 @param Value Request Value.
111 @param Index Request Index.
112 @param DescriptorLength Request descriptor Length.
113 @param Descriptor Request descriptor.
114
115
116 @retval EFI_SUCCESS Usb descriptor is obtained successfully.
117 @retval EFI_DEVICE_ERROR Cannot get the usb descriptor due to a hardware error.
118 @retval Others Other failure occurs.
119
120 **/
121 EFI_STATUS
122 PeiUsbGetDescriptor (
123 IN EFI_PEI_SERVICES **PeiServices,
124 IN PEI_USB_IO_PPI *UsbIoPpi,
125 IN UINT16 Value,
126 IN UINT16 Index,
127 IN UINT16 DescriptorLength,
128 OUT VOID *Descriptor
129 );
130
131 /**
132 Set a usb device with a specified address.
133
134 @param PeiServices General-purpose services that are available to every PEIM.
135 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
136 @param AddressValue The address to assign.
137
138 @retval EFI_SUCCESS Usb device address is set successfully.
139 @retval EFI_DEVICE_ERROR Cannot set the usb address due to a hardware error.
140 @retval Others Other failure occurs.
141
142 **/
143 EFI_STATUS
144 PeiUsbSetDeviceAddress (
145 IN EFI_PEI_SERVICES **PeiServices,
146 IN PEI_USB_IO_PPI *UsbIoPpi,
147 IN UINT16 AddressValue
148 );
149
150 /**
151 Clear a given usb feature.
152
153 @param PeiServices General-purpose services that are available to every PEIM.
154 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
155 @param Recipient The recipient of ClearFeature Request, should be one of Device/Interface/Endpoint.
156 @param Value Request Value.
157 @param Target Request Index.
158
159 @retval EFI_SUCCESS Usb feature is cleared successfully.
160 @retval EFI_DEVICE_ERROR Cannot clear the usb feature due to a hardware error.
161 @retval Others Other failure occurs.
162
163 **/
164 EFI_STATUS
165 PeiUsbClearDeviceFeature (
166 IN EFI_PEI_SERVICES **PeiServices,
167 IN PEI_USB_IO_PPI *UsbIoPpi,
168 IN EFI_USB_RECIPIENT Recipient,
169 IN UINT16 Value,
170 IN UINT16 Target
171 );
172
173 /**
174 Configure a usb device to Configuration 1.
175
176 @param PeiServices General-purpose services that are available to every PEIM.
177 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
178
179 @retval EFI_SUCCESS Usb device is set to use Configuration 1 successfully.
180 @retval EFI_DEVICE_ERROR Cannot set the usb device due to a hardware error.
181 @retval Others Other failure occurs.
182
183 **/
184 EFI_STATUS
185 PeiUsbSetConfiguration (
186 IN EFI_PEI_SERVICES **PeiServices,
187 IN PEI_USB_IO_PPI *UsbIoPpi
188 );
189
190 /**
191 Judge if the port is connected with a usb device or not.
192
193 @param PortStatus The usb port status gotten.
194
195 @retval TRUE A usb device is connected with the port.
196 @retval FALSE No usb device is connected with the port.
197
198 **/
199 BOOLEAN
200 IsPortConnect (
201 IN UINT16 PortStatus
202 );
203
204 /**
205 Judge if the port is connected with a low-speed usb device or not.
206
207 @param PortStatus The usb port status gotten.
208
209 @retval TRUE A low-speed usb device is connected with the port.
210 @retval FALSE No low-speed usb device is connected with the port.
211
212 **/
213 UINTN
214 IsPortLowSpeedDeviceAttached (
215 IN UINT16 PortStatus
216 );
217
218 /**
219 Judge if the port is in "connection change" status or not.
220
221 @param PortChangeStatus The usb port change status gotten.
222
223 @retval TRUE The port is in "connection change" status.
224 @retval FALSE The port is NOT in "connection change" status.
225
226 **/
227 BOOLEAN
228 IsPortConnectChange (
229 IN UINT16 PortChangeStatus
230 );
231 #endif