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