]>
Commit | Line | Data |
---|---|---|
d987459f SZ |
1 | /** @file\r |
2 | Private Header file for Usb Host Controller PEIM\r | |
3 | \r | |
26b85012 | 4 | Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r |
d987459f SZ |
5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions\r | |
8 | of the BSD License which accompanies this distribution. The\r | |
9 | full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef _RECOVERY_XHC_H_\r | |
18 | #define _RECOVERY_XHC_H_\r | |
19 | \r | |
20 | #include <PiPei.h>\r | |
21 | \r | |
22 | #include <Ppi/UsbController.h>\r | |
23 | #include <Ppi/Usb2HostController.h>\r | |
24 | \r | |
25 | #include <Library/DebugLib.h>\r | |
26 | #include <Library/PeimEntryPoint.h>\r | |
27 | #include <Library/PeiServicesLib.h>\r | |
28 | #include <Library/BaseMemoryLib.h>\r | |
29 | #include <Library/TimerLib.h>\r | |
30 | #include <Library/IoLib.h>\r | |
31 | #include <Library/MemoryAllocationLib.h>\r | |
32 | \r | |
33 | typedef struct _PEI_XHC_DEV PEI_XHC_DEV;\r | |
34 | typedef struct _USB_DEV_CONTEXT USB_DEV_CONTEXT;\r | |
35 | \r | |
36 | #include "UsbHcMem.h"\r | |
37 | #include "XhciReg.h"\r | |
38 | #include "XhciSched.h"\r | |
39 | \r | |
40 | #define CMD_RING_TRB_NUMBER 0x100\r | |
41 | #define TR_RING_TRB_NUMBER 0x100\r | |
42 | #define ERST_NUMBER 0x01\r | |
43 | #define EVENT_RING_TRB_NUMBER 0x200\r | |
44 | \r | |
45 | #define XHC_1_MICROSECOND 1\r | |
46 | #define XHC_1_MILLISECOND (1000 * XHC_1_MICROSECOND)\r | |
47 | #define XHC_1_SECOND (1000 * XHC_1_MILLISECOND)\r | |
48 | \r | |
49 | //\r | |
50 | // XHC reset timeout experience values.\r | |
26cd2d6d | 51 | // The unit is millisecond, setting it as 1s.\r |
d987459f | 52 | //\r |
26cd2d6d | 53 | #define XHC_RESET_TIMEOUT (1000)\r |
d987459f | 54 | \r |
26b85012 FT |
55 | //\r |
56 | // TRSTRCY delay requirement in usb 2.0 spec chapter 7.1.7.5.\r | |
57 | // The unit is microsecond, setting it as 10ms.\r | |
58 | //\r | |
59 | #define XHC_RESET_RECOVERY_DELAY (10 * 1000)\r | |
60 | \r | |
d987459f SZ |
61 | //\r |
62 | // Wait for root port state stable.\r | |
63 | //\r | |
64 | #define XHC_ROOT_PORT_STATE_STABLE (200 * XHC_1_MILLISECOND)\r | |
65 | \r | |
26cd2d6d FT |
66 | //\r |
67 | // XHC generic timeout experience values.\r | |
68 | // The unit is millisecond, setting it as 10s.\r | |
69 | //\r | |
70 | #define XHC_GENERIC_TIMEOUT (10 * 1000)\r | |
d987459f SZ |
71 | \r |
72 | #define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))\r | |
73 | #define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))\r | |
74 | #define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))\r | |
75 | \r | |
76 | #define XHC_REG_BIT_IS_SET(XHC, Offset, Bit) \\r | |
77 | (XHC_BIT_IS_SET(XhcPeiReadOpReg ((XHC), (Offset)), (Bit)))\r | |
78 | \r | |
79 | #define USB_DESC_TYPE_HUB 0x29\r | |
80 | #define USB_DESC_TYPE_HUB_SUPER_SPEED 0x2a\r | |
81 | \r | |
82 | //\r | |
83 | // The RequestType in EFI_USB_DEVICE_REQUEST is composed of\r | |
84 | // three fields: One bit direction, 2 bit type, and 5 bit\r | |
85 | // target.\r | |
86 | //\r | |
87 | #define USB_REQUEST_TYPE(Dir, Type, Target) \\r | |
88 | ((UINT8)((((Dir) == EfiUsbDataIn ? 0x01 : 0) << 7) | (Type) | (Target)))\r | |
89 | \r | |
90 | struct _USB_DEV_CONTEXT {\r | |
91 | //\r | |
92 | // Whether this entry in UsbDevContext array is used or not.\r | |
93 | //\r | |
94 | BOOLEAN Enabled;\r | |
95 | //\r | |
96 | // The slot id assigned to the new device through XHCI's Enable_Slot cmd.\r | |
97 | //\r | |
98 | UINT8 SlotId;\r | |
99 | //\r | |
100 | // The route string presented an attached usb device.\r | |
101 | //\r | |
102 | USB_DEV_ROUTE RouteString;\r | |
103 | //\r | |
104 | // The route string of parent device if it exists. Otherwise it's zero.\r | |
105 | //\r | |
106 | USB_DEV_ROUTE ParentRouteString;\r | |
107 | //\r | |
108 | // The actual device address assigned by XHCI through Address_Device command.\r | |
109 | //\r | |
110 | UINT8 XhciDevAddr;\r | |
111 | //\r | |
112 | // The requested device address from UsbBus driver through Set_Address standard usb request.\r | |
113 | // As XHCI spec replaces this request with Address_Device command, we have to record the\r | |
114 | // requested device address and establish a mapping relationship with the actual device address.\r | |
115 | // Then UsbBus driver just need to be aware of the requested device address to access usb device\r | |
116 | // through EFI_USB2_HC_PROTOCOL. Xhci driver would be responsible for translating it to actual\r | |
117 | // device address and access the actual device.\r | |
118 | //\r | |
119 | UINT8 BusDevAddr;\r | |
120 | //\r | |
121 | // The pointer to the input device context.\r | |
122 | //\r | |
123 | VOID *InputContext;\r | |
124 | //\r | |
125 | // The pointer to the output device context.\r | |
126 | //\r | |
127 | VOID *OutputContext;\r | |
128 | //\r | |
129 | // The transfer queue for every endpoint.\r | |
130 | //\r | |
131 | VOID *EndpointTransferRing[31];\r | |
132 | //\r | |
133 | // The device descriptor which is stored to support XHCI's Evaluate_Context cmd.\r | |
134 | //\r | |
135 | EFI_USB_DEVICE_DESCRIPTOR DevDesc;\r | |
136 | //\r | |
137 | // As a usb device may include multiple configuration descriptors, we dynamically allocate an array\r | |
138 | // to store them.\r | |
139 | // Note that every configuration descriptor stored here includes those lower level descriptors,\r | |
140 | // such as Interface descriptor, Endpoint descriptor, and so on.\r | |
141 | // These information is used to support XHCI's Config_Endpoint cmd.\r | |
142 | //\r | |
143 | EFI_USB_CONFIG_DESCRIPTOR **ConfDesc;\r | |
144 | };\r | |
145 | \r | |
146 | #define USB_XHC_DEV_SIGNATURE SIGNATURE_32 ('x', 'h', 'c', 'i')\r | |
147 | \r | |
148 | struct _PEI_XHC_DEV {\r | |
149 | UINTN Signature;\r | |
150 | PEI_USB2_HOST_CONTROLLER_PPI Usb2HostControllerPpi;\r | |
151 | EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;\r | |
152 | UINT32 UsbHostControllerBaseAddress;\r | |
153 | USBHC_MEM_POOL *MemPool;\r | |
154 | \r | |
155 | //\r | |
156 | // XHCI configuration data\r | |
157 | //\r | |
158 | UINT8 CapLength; ///< Capability Register Length\r | |
159 | XHC_HCSPARAMS1 HcSParams1; ///< Structural Parameters 1\r | |
160 | XHC_HCSPARAMS2 HcSParams2; ///< Structural Parameters 2\r | |
161 | XHC_HCCPARAMS HcCParams; ///< Capability Parameters\r | |
162 | UINT32 DBOff; ///< Doorbell Offset\r | |
163 | UINT32 RTSOff; ///< Runtime Register Space Offset\r | |
164 | UINT32 PageSize;\r | |
165 | UINT32 MaxScratchpadBufs;\r | |
166 | UINT64 *ScratchBuf;\r | |
167 | UINT64 *ScratchEntry;\r | |
168 | UINT64 *DCBAA;\r | |
169 | UINT32 MaxSlotsEn;\r | |
170 | //\r | |
171 | // Cmd Transfer Ring\r | |
172 | //\r | |
173 | TRANSFER_RING CmdRing;\r | |
174 | //\r | |
175 | // EventRing\r | |
176 | //\r | |
177 | EVENT_RING EventRing;\r | |
178 | \r | |
179 | //\r | |
180 | // Store device contexts managed by XHCI device\r | |
181 | // The array supports up to 255 devices, entry 0 is reserved and should not be used.\r | |
182 | //\r | |
183 | USB_DEV_CONTEXT UsbDevContext[256];\r | |
184 | };\r | |
185 | \r | |
186 | #define PEI_RECOVERY_USB_XHC_DEV_FROM_THIS(a) CR (a, PEI_XHC_DEV, Usb2HostControllerPpi, USB_XHC_DEV_SIGNATURE)\r | |
187 | \r | |
188 | /**\r | |
189 | Initialize the memory management pool for the host controller.\r | |
190 | \r | |
191 | @return Pointer to the allocated memory pool or NULL if failed.\r | |
192 | \r | |
193 | **/\r | |
194 | USBHC_MEM_POOL *\r | |
195 | UsbHcInitMemPool (\r | |
196 | VOID\r | |
197 | )\r | |
198 | ;\r | |
199 | \r | |
200 | /**\r | |
201 | Release the memory management pool.\r | |
202 | \r | |
203 | @param Pool The USB memory pool to free.\r | |
204 | \r | |
205 | **/\r | |
206 | VOID\r | |
207 | UsbHcFreeMemPool (\r | |
208 | IN USBHC_MEM_POOL *Pool\r | |
209 | )\r | |
210 | ;\r | |
211 | \r | |
212 | /**\r | |
213 | Allocate some memory from the host controller's memory pool\r | |
214 | which can be used to communicate with host controller.\r | |
215 | \r | |
216 | @param Pool The host controller's memory pool.\r | |
217 | @param Size Size of the memory to allocate.\r | |
218 | \r | |
219 | @return The allocated memory or NULL.\r | |
220 | \r | |
221 | **/\r | |
222 | VOID *\r | |
223 | UsbHcAllocateMem (\r | |
224 | IN USBHC_MEM_POOL *Pool,\r | |
225 | IN UINTN Size\r | |
226 | )\r | |
227 | ;\r | |
228 | \r | |
229 | /**\r | |
230 | Free the allocated memory back to the memory pool.\r | |
231 | \r | |
232 | @param Pool The memory pool of the host controller.\r | |
233 | @param Mem The memory to free.\r | |
234 | @param Size The size of the memory to free.\r | |
235 | \r | |
236 | **/\r | |
237 | VOID\r | |
238 | UsbHcFreeMem (\r | |
239 | IN USBHC_MEM_POOL *Pool,\r | |
240 | IN VOID *Mem,\r | |
241 | IN UINTN Size\r | |
242 | )\r | |
243 | ;\r | |
244 | \r | |
245 | #endif\r |