MdeModulePkg UsbBusPei: Fix wrong buffer length used to read hub desc
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusPei / HubPeim.h
CommitLineData
4b1bf81c 1/** @file\r
2Constants definitions for Usb Hub Peim\r
3\r
72750e3b 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
4b1bf81c 5 \r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions\r
8of the BSD License which accompanies this distribution. The\r
9full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#ifndef _PEI_HUB_PEIM_H_\r
18#define _PEI_HUB_PEIM_H_\r
19\r
20\r
21//\r
22// Hub feature numbers\r
23//\r
24#define C_HUB_LOCAL_POWER 0\r
25#define C_HUB_OVER_CURRENT 1\r
26\r
27//\r
28// Hub class code & sub class code\r
29//\r
30#define CLASS_CODE_HUB 0x09\r
31#define SUB_CLASS_CODE_HUB 0\r
32\r
33//\r
34// Hub Status & Hub Change bit masks\r
35//\r
36#define HUB_STATUS_LOCAL_POWER 0x0001\r
37#define HUB_STATUS_OVERCURRENT 0x0002\r
38\r
39#define HUB_CHANGE_LOCAL_POWER 0x0001\r
40#define HUB_CHANGE_OVERCURRENT 0x0002\r
41\r
42//\r
43// Hub Characteristics\r
44//\r
45#define HUB_CHAR_LPSM 0x0003\r
46#define HUB_CHAR_COMPOUND 0x0004\r
47#define HUB_CHAR_OCPM 0x0018\r
48\r
49//\r
50// Standard hub request and request type\r
51// By [Spec-USB20/Chapter-11.24]\r
52//\r
53#define USB_HUB_CLEAR_FEATURE 0x01\r
54#define USB_HUB_CLEAR_FEATURE_REQ_TYPE 0x20\r
55\r
56#define USB_HUB_CLEAR_FEATURE_PORT 0x01\r
57#define USB_HUB_CLEAR_FEATURE_PORT_REQ_TYPE 0x23\r
58\r
59#define USB_HUB_GET_BUS_STATE 0x02\r
60#define USB_HUB_GET_BUS_STATE_REQ_TYPE 0xA3\r
61\r
62#define USB_HUB_GET_DESCRIPTOR 0x06\r
63#define USB_HUB_GET_DESCRIPTOR_REQ_TYPE 0xA0\r
64\r
65#define USB_HUB_GET_HUB_STATUS 0x00\r
66#define USB_HUB_GET_HUB_STATUS_REQ_TYPE 0xA0\r
67\r
68#define USB_HUB_GET_PORT_STATUS 0x00\r
69#define USB_HUB_GET_PORT_STATUS_REQ_TYPE 0xA3\r
70\r
71#define USB_HUB_SET_DESCRIPTOR 0x07\r
72#define USB_HUB_SET_DESCRIPTOR_REQ_TYPE 0x20\r
73\r
74#define USB_HUB_SET_HUB_FEATURE 0x03\r
75#define USB_HUB_SET_HUB_FEATURE_REQ_TYPE 0x20\r
76\r
77#define USB_HUB_SET_PORT_FEATURE 0x03\r
78#define USB_HUB_SET_PORT_FEATURE_REQ_TYPE 0x23\r
79\r
80#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)\r
81#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)\r
82\r
d987459f
SZ
83#define USB_HUB_REQ_SET_DEPTH 12\r
84\r
4b1bf81c 85#define MAXBYTES 8\r
86#pragma pack(1)\r
87//\r
88// Hub descriptor, the last two fields are of variable lenght.\r
89//\r
90typedef struct {\r
91 UINT8 Length;\r
92 UINT8 DescriptorType;\r
93 UINT8 NbrPorts;\r
94 UINT8 HubCharacteristics[2];\r
95 UINT8 PwrOn2PwrGood;\r
96 UINT8 HubContrCurrent;\r
97 UINT8 Filler[MAXBYTES];\r
98} EFI_USB_HUB_DESCRIPTOR;\r
99\r
100typedef struct {\r
101 UINT16 HubStatus;\r
102 UINT16 HubChangeStatus;\r
103} EFI_USB_HUB_STATUS;\r
104\r
105#pragma pack()\r
106/**\r
107 Get a given hub port status.\r
108\r
109 @param PeiServices General-purpose services that are available to every PEIM.\r
110 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
111 @param Port Usb hub port number (starting from 1).\r
112 @param PortStatus Current Hub port status and change status.\r
113\r
114 @retval EFI_SUCCESS Port status is obtained successfully.\r
115 @retval EFI_DEVICE_ERROR Cannot get the port status due to a hardware error.\r
116 @retval Others Other failure occurs.\r
117\r
118**/\r
119EFI_STATUS\r
120PeiHubGetPortStatus (\r
121 IN EFI_PEI_SERVICES **PeiServices,\r
122 IN PEI_USB_IO_PPI *UsbIoPpi,\r
123 IN UINT8 Port,\r
124 OUT UINT32 *PortStatus\r
125 );\r
126\r
127/**\r
128 Set specified feature to a given hub port.\r
129\r
130 @param PeiServices General-purpose services that are available to every PEIM.\r
131 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
132 @param Port Usb hub port number (starting from 1).\r
133 @param Value New feature value.\r
134\r
135 @retval EFI_SUCCESS Port feature is set successfully.\r
136 @retval EFI_DEVICE_ERROR Cannot set the port feature due to a hardware error.\r
137 @retval Others Other failure occurs.\r
138\r
139**/\r
140EFI_STATUS\r
141PeiHubSetPortFeature (\r
142 IN EFI_PEI_SERVICES **PeiServices,\r
143 IN PEI_USB_IO_PPI *UsbIoPpi,\r
144 IN UINT8 Port,\r
145 IN UINT8 Value\r
146 );\r
147\r
148/**\r
149 Set specified feature to a given hub.\r
150\r
151 @param PeiServices General-purpose services that are available to every PEIM.\r
152 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
153 @param Value New feature value.\r
154\r
155 @retval EFI_SUCCESS Port feature is set successfully.\r
156 @retval EFI_DEVICE_ERROR Cannot set the port feature due to a hardware error.\r
157 @retval Others Other failure occurs.\r
158\r
159**/\r
160EFI_STATUS\r
161PeiHubSetHubFeature (\r
162 IN EFI_PEI_SERVICES **PeiServices,\r
163 IN PEI_USB_IO_PPI *UsbIoPpi,\r
164 IN UINT8 Value\r
165 );\r
166\r
167/**\r
168 Get a given hub status.\r
169\r
170 @param PeiServices General-purpose services that are available to every PEIM.\r
171 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
172 @param HubStatus Current Hub status and change status.\r
173\r
174 @retval EFI_SUCCESS Hub status is obtained successfully.\r
175 @retval EFI_DEVICE_ERROR Cannot get the hub status due to a hardware error.\r
176 @retval Others Other failure occurs.\r
177\r
178**/\r
179EFI_STATUS\r
180PeiHubGetHubStatus (\r
181 IN EFI_PEI_SERVICES **PeiServices,\r
182 IN PEI_USB_IO_PPI *UsbIoPpi,\r
183 OUT UINT32 *HubStatus\r
184 );\r
185\r
186/**\r
187 Clear specified feature on a given hub port.\r
188\r
189 @param PeiServices General-purpose services that are available to every PEIM.\r
190 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
191 @param Port Usb hub port number (starting from 1).\r
192 @param Value Feature value that will be cleared from the hub port.\r
193\r
194 @retval EFI_SUCCESS Port feature is cleared successfully.\r
195 @retval EFI_DEVICE_ERROR Cannot clear the port feature due to a hardware error.\r
196 @retval Others Other failure occurs.\r
197\r
198**/\r
199EFI_STATUS\r
200PeiHubClearPortFeature (\r
201 IN EFI_PEI_SERVICES **PeiServices,\r
202 IN PEI_USB_IO_PPI *UsbIoPpi,\r
203 IN UINT8 Port,\r
204 IN UINT8 Value\r
205 );\r
206\r
207/**\r
208 Clear specified feature on a given hub.\r
209\r
210 @param PeiServices General-purpose services that are available to every PEIM.\r
211 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
212 @param Value Feature value that will be cleared from the hub port.\r
213\r
214 @retval EFI_SUCCESS Hub feature is cleared successfully.\r
215 @retval EFI_DEVICE_ERROR Cannot clear the hub feature due to a hardware error.\r
216 @retval Others Other failure occurs.\r
217\r
218**/\r
219EFI_STATUS\r
220PeiHubClearHubFeature (\r
221 IN EFI_PEI_SERVICES **PeiServices,\r
222 IN PEI_USB_IO_PPI *UsbIoPpi,\r
223 IN UINT8 Value\r
224 );\r
225\r
226/**\r
227 Get a given hub descriptor.\r
228\r
229 @param PeiServices General-purpose services that are available to every PEIM.\r
72750e3b 230 @param PeiUsbDevice Indicates the hub controller device.\r
4b1bf81c 231 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
232 @param DescriptorSize The length of Hub Descriptor buffer.\r
233 @param HubDescriptor Caller allocated buffer to store the hub descriptor if\r
234 successfully returned.\r
235\r
236 @retval EFI_SUCCESS Hub descriptor is obtained successfully.\r
237 @retval EFI_DEVICE_ERROR Cannot get the hub descriptor due to a hardware error.\r
238 @retval Others Other failure occurs.\r
239\r
240**/\r
241EFI_STATUS\r
242PeiGetHubDescriptor (\r
243 IN EFI_PEI_SERVICES **PeiServices,\r
72750e3b 244 IN PEI_USB_DEVICE *PeiUsbDevice,\r
4b1bf81c 245 IN PEI_USB_IO_PPI *UsbIoPpi,\r
246 IN UINTN DescriptorSize,\r
247 OUT EFI_USB_HUB_DESCRIPTOR *HubDescriptor\r
248 );\r
249\r
250/**\r
251 Configure a given hub.\r
252\r
253 @param PeiServices General-purpose services that are available to every PEIM.\r
254 @param PeiUsbDevice Indicating the hub controller device that will be configured\r
255\r
256 @retval EFI_SUCCESS Hub configuration is done successfully.\r
257 @retval EFI_DEVICE_ERROR Cannot configure the hub due to a hardware error.\r
258\r
259**/\r
260EFI_STATUS\r
261PeiDoHubConfig (\r
262 IN EFI_PEI_SERVICES **PeiServices,\r
263 IN PEI_USB_DEVICE *PeiUsbDevice\r
264 );\r
265\r
266/**\r
267 Send reset signal over the given root hub port.\r
268\r
269 @param PeiServices General-purpose services that are available to every PEIM.\r
270 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
271 @param PortNum Usb hub port number (starting from 1).\r
272\r
273**/\r
274VOID\r
275PeiResetHubPort (\r
276 IN EFI_PEI_SERVICES **PeiServices,\r
277 IN PEI_USB_IO_PPI *UsbIoPpi,\r
278 IN UINT8 PortNum\r
279 );\r
280\r
281#endif\r
282\r
283\r