]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.h
MdeModulePkg XhciPei/UsbBusPei: Add XHCI recovery support.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / XhciPei / XhcPeim.h
CommitLineData
d987459f
SZ
1/** @file\r
2Private Header file for Usb Host Controller PEIM\r
3\r
4Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
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 _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
33typedef struct _PEI_XHC_DEV PEI_XHC_DEV;\r
34typedef 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
51// The unit is microsecond, setting it as 1s.\r
52//\r
53#define XHC_RESET_TIMEOUT (1 * XHC_1_SECOND)\r
54//\r
55// XHC delay experience value for polling operation.\r
56// The unit is microsecond, set it as 1ms.\r
57//\r
58#define XHC_POLL_DELAY (1 * XHC_1_MILLISECOND)\r
59\r
60//\r
61// Wait for root port state stable.\r
62//\r
63#define XHC_ROOT_PORT_STATE_STABLE (200 * XHC_1_MILLISECOND)\r
64\r
65#define XHC_GENERIC_TIMEOUT (10 * XHC_1_MILLISECOND)\r
66\r
67#define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))\r
68#define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))\r
69#define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))\r
70\r
71#define XHC_REG_BIT_IS_SET(XHC, Offset, Bit) \\r
72 (XHC_BIT_IS_SET(XhcPeiReadOpReg ((XHC), (Offset)), (Bit)))\r
73\r
74#define USB_DESC_TYPE_HUB 0x29\r
75#define USB_DESC_TYPE_HUB_SUPER_SPEED 0x2a\r
76\r
77//\r
78// The RequestType in EFI_USB_DEVICE_REQUEST is composed of\r
79// three fields: One bit direction, 2 bit type, and 5 bit\r
80// target.\r
81//\r
82#define USB_REQUEST_TYPE(Dir, Type, Target) \\r
83 ((UINT8)((((Dir) == EfiUsbDataIn ? 0x01 : 0) << 7) | (Type) | (Target)))\r
84\r
85struct _USB_DEV_CONTEXT {\r
86 //\r
87 // Whether this entry in UsbDevContext array is used or not.\r
88 //\r
89 BOOLEAN Enabled;\r
90 //\r
91 // The slot id assigned to the new device through XHCI's Enable_Slot cmd.\r
92 //\r
93 UINT8 SlotId;\r
94 //\r
95 // The route string presented an attached usb device.\r
96 //\r
97 USB_DEV_ROUTE RouteString;\r
98 //\r
99 // The route string of parent device if it exists. Otherwise it's zero.\r
100 //\r
101 USB_DEV_ROUTE ParentRouteString;\r
102 //\r
103 // The actual device address assigned by XHCI through Address_Device command.\r
104 //\r
105 UINT8 XhciDevAddr;\r
106 //\r
107 // The requested device address from UsbBus driver through Set_Address standard usb request.\r
108 // As XHCI spec replaces this request with Address_Device command, we have to record the\r
109 // requested device address and establish a mapping relationship with the actual device address.\r
110 // Then UsbBus driver just need to be aware of the requested device address to access usb device\r
111 // through EFI_USB2_HC_PROTOCOL. Xhci driver would be responsible for translating it to actual\r
112 // device address and access the actual device.\r
113 //\r
114 UINT8 BusDevAddr;\r
115 //\r
116 // The pointer to the input device context.\r
117 //\r
118 VOID *InputContext;\r
119 //\r
120 // The pointer to the output device context.\r
121 //\r
122 VOID *OutputContext;\r
123 //\r
124 // The transfer queue for every endpoint.\r
125 //\r
126 VOID *EndpointTransferRing[31];\r
127 //\r
128 // The device descriptor which is stored to support XHCI's Evaluate_Context cmd.\r
129 //\r
130 EFI_USB_DEVICE_DESCRIPTOR DevDesc;\r
131 //\r
132 // As a usb device may include multiple configuration descriptors, we dynamically allocate an array\r
133 // to store them.\r
134 // Note that every configuration descriptor stored here includes those lower level descriptors,\r
135 // such as Interface descriptor, Endpoint descriptor, and so on.\r
136 // These information is used to support XHCI's Config_Endpoint cmd.\r
137 //\r
138 EFI_USB_CONFIG_DESCRIPTOR **ConfDesc;\r
139};\r
140\r
141#define USB_XHC_DEV_SIGNATURE SIGNATURE_32 ('x', 'h', 'c', 'i')\r
142\r
143struct _PEI_XHC_DEV {\r
144 UINTN Signature;\r
145 PEI_USB2_HOST_CONTROLLER_PPI Usb2HostControllerPpi;\r
146 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;\r
147 UINT32 UsbHostControllerBaseAddress;\r
148 USBHC_MEM_POOL *MemPool;\r
149\r
150 //\r
151 // XHCI configuration data\r
152 //\r
153 UINT8 CapLength; ///< Capability Register Length\r
154 XHC_HCSPARAMS1 HcSParams1; ///< Structural Parameters 1\r
155 XHC_HCSPARAMS2 HcSParams2; ///< Structural Parameters 2\r
156 XHC_HCCPARAMS HcCParams; ///< Capability Parameters\r
157 UINT32 DBOff; ///< Doorbell Offset\r
158 UINT32 RTSOff; ///< Runtime Register Space Offset\r
159 UINT32 PageSize;\r
160 UINT32 MaxScratchpadBufs;\r
161 UINT64 *ScratchBuf;\r
162 UINT64 *ScratchEntry;\r
163 UINT64 *DCBAA;\r
164 UINT32 MaxSlotsEn;\r
165 //\r
166 // Cmd Transfer Ring\r
167 //\r
168 TRANSFER_RING CmdRing;\r
169 //\r
170 // EventRing\r
171 //\r
172 EVENT_RING EventRing;\r
173\r
174 //\r
175 // Store device contexts managed by XHCI device\r
176 // The array supports up to 255 devices, entry 0 is reserved and should not be used.\r
177 //\r
178 USB_DEV_CONTEXT UsbDevContext[256];\r
179};\r
180\r
181#define PEI_RECOVERY_USB_XHC_DEV_FROM_THIS(a) CR (a, PEI_XHC_DEV, Usb2HostControllerPpi, USB_XHC_DEV_SIGNATURE)\r
182\r
183/**\r
184 Initialize the memory management pool for the host controller.\r
185\r
186 @return Pointer to the allocated memory pool or NULL if failed.\r
187\r
188**/\r
189USBHC_MEM_POOL *\r
190UsbHcInitMemPool (\r
191 VOID\r
192 )\r
193;\r
194\r
195/**\r
196 Release the memory management pool.\r
197\r
198 @param Pool The USB memory pool to free.\r
199\r
200**/\r
201VOID\r
202UsbHcFreeMemPool (\r
203 IN USBHC_MEM_POOL *Pool\r
204 )\r
205;\r
206\r
207/**\r
208 Allocate some memory from the host controller's memory pool\r
209 which can be used to communicate with host controller.\r
210\r
211 @param Pool The host controller's memory pool.\r
212 @param Size Size of the memory to allocate.\r
213\r
214 @return The allocated memory or NULL.\r
215\r
216**/\r
217VOID *\r
218UsbHcAllocateMem (\r
219 IN USBHC_MEM_POOL *Pool,\r
220 IN UINTN Size\r
221 )\r
222;\r
223\r
224/**\r
225 Free the allocated memory back to the memory pool.\r
226\r
227 @param Pool The memory pool of the host controller.\r
228 @param Mem The memory to free.\r
229 @param Size The size of the memory to free.\r
230\r
231**/\r
232VOID\r
233UsbHcFreeMem (\r
234 IN USBHC_MEM_POOL *Pool,\r
235 IN VOID *Mem,\r
236 IN UINTN Size\r
237 )\r
238;\r
239\r
240#endif\r