]>
Commit | Line | Data |
---|---|---|
92870c98 | 1 | /** @file\r |
2 | \r | |
3 | Provides some data structure definitions used by the XHCI host controller driver.\r | |
4 | \r | |
5 | Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef _EFI_XHCI_H_\r | |
17 | #define _EFI_XHCI_H_\r | |
18 | \r | |
19 | #include <Uefi.h>\r | |
20 | \r | |
21 | #include <Protocol/Usb2HostController.h>\r | |
22 | #include <Protocol/PciIo.h>\r | |
23 | \r | |
24 | #include <Guid/EventGroup.h>\r | |
25 | \r | |
26 | #include <Library/BaseLib.h>\r | |
27 | #include <Library/BaseMemoryLib.h>\r | |
28 | #include <Library/UefiDriverEntryPoint.h>\r | |
29 | #include <Library/UefiBootServicesTableLib.h>\r | |
30 | #include <Library/MemoryAllocationLib.h>\r | |
31 | #include <Library/UefiLib.h>\r | |
32 | #include <Library/PcdLib.h>\r | |
33 | #include <Library/DebugLib.h>\r | |
34 | \r | |
35 | #include <IndustryStandard/Pci.h>\r | |
36 | \r | |
37 | typedef struct _USB_XHCI_DEV USB_XHCI_DEV;\r | |
38 | typedef struct _USB_DEV_CONTEXT USB_DEV_CONTEXT;\r | |
39 | \r | |
40 | #include "XhciReg.h"\r | |
41 | #include "XhciSched.h"\r | |
42 | #include "ComponentName.h"\r | |
43 | \r | |
44 | //\r | |
45 | // XHC timeout experience values\r | |
46 | //\r | |
47 | #define XHC_1_MICROSECOND 1\r | |
48 | #define XHC_1_MILLISECOND (1000 * XHC_1_MICROSECOND)\r | |
49 | #define XHC_1_SECOND (1000 * XHC_1_MILLISECOND)\r | |
50 | \r | |
51 | //\r | |
52 | // XHCI register operation timeout, set by experience\r | |
53 | //\r | |
54 | #define XHC_RESET_TIMEOUT (1 * XHC_1_SECOND)\r | |
55 | #define XHC_GENERIC_TIMEOUT (10 * XHC_1_MILLISECOND)\r | |
56 | \r | |
57 | //\r | |
58 | // Wait for roothub port power stable, refers to Spec[XHCI1.0-2.3.9]\r | |
59 | //\r | |
60 | #define XHC_ROOT_PORT_RECOVERY_STALL (20 * XHC_1_MILLISECOND)\r | |
61 | \r | |
62 | //\r | |
63 | // Sync and Async transfer polling interval, set by experience,\r | |
64 | // and the unit of Async is 100us, means 50ms as interval.\r | |
65 | //\r | |
66 | #define XHC_SYNC_POLL_INTERVAL (20 * XHC_1_MILLISECOND)\r | |
67 | #define XHC_ASYNC_POLL_INTERVAL (50 * 10000U)\r | |
68 | \r | |
69 | //\r | |
70 | // XHC raises TPL to TPL_NOTIFY to serialize all its operations\r | |
71 | // to protect shared data structures.\r | |
72 | //\r | |
73 | #define XHC_TPL TPL_NOTIFY\r | |
74 | \r | |
75 | #define CMD_RING_TRB_NUMBER 0x40\r | |
76 | #define TR_RING_TRB_NUMBER 0x40\r | |
77 | #define ERST_NUMBER 0x01\r | |
78 | #define EVENT_RING_TRB_NUMBER 0x80\r | |
79 | \r | |
80 | #define CMD_INTER 0\r | |
81 | #define CTRL_INTER 1\r | |
82 | #define BULK_INTER 2\r | |
83 | #define INT_INTER 3\r | |
84 | #define INT_INTER_ASYNC 4\r | |
85 | \r | |
86 | //\r | |
87 | // Iterate through the doule linked list. This is delete-safe.\r | |
88 | // Don't touch NextEntry\r | |
89 | //\r | |
90 | #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \\r | |
91 | for (Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\\r | |
92 | Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)\r | |
93 | \r | |
94 | #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)\r | |
95 | \r | |
96 | #define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0xFFFFFFFF))\r | |
97 | #define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0xFFFFFFFF))\r | |
98 | #define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))\r | |
99 | \r | |
100 | #define XHC_REG_BIT_IS_SET(Xhc, Offset, Bit) \\r | |
101 | (XHC_BIT_IS_SET(XhcReadOpReg ((Xhc), (Offset)), (Bit)))\r | |
102 | \r | |
103 | #define XHCI_IS_DATAIN(EndpointAddr) XHC_BIT_IS_SET((EndpointAddr), 0x80)\r | |
104 | \r | |
105 | #define USB_XHCI_DEV_SIGNATURE SIGNATURE_32 ('x', 'h', 'c', 'i')\r | |
106 | #define XHC_FROM_THIS(a) CR(a, USB_XHCI_DEV, Usb2Hc, USB_XHCI_DEV_SIGNATURE)\r | |
107 | \r | |
108 | #define USB_DESC_TYPE_HUB 0x29\r | |
109 | #define USB_DESC_TYPE_HUB_SUPER_SPEED 0x2a\r | |
110 | \r | |
111 | //\r | |
112 | // Xhci Data and Ctrl Structures\r | |
113 | //\r | |
114 | #pragma pack(1)\r | |
115 | typedef struct {\r | |
116 | UINT8 ProgInterface;\r | |
117 | UINT8 SubClassCode;\r | |
118 | UINT8 BaseCode;\r | |
119 | } USB_CLASSC;\r | |
120 | \r | |
121 | typedef struct {\r | |
122 | UINT8 Length;\r | |
123 | UINT8 DescType;\r | |
124 | UINT8 NumPorts;\r | |
125 | UINT16 HubCharacter;\r | |
126 | UINT8 PwrOn2PwrGood;\r | |
127 | UINT8 HubContrCurrent;\r | |
128 | UINT8 Filler[16];\r | |
129 | } EFI_USB_HUB_DESCRIPTOR;\r | |
130 | #pragma pack()\r | |
131 | \r | |
132 | struct _USB_XHCI_DEV {\r | |
133 | UINT32 Signature;\r | |
134 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
135 | UINT64 OriginalPciAttributes;\r | |
136 | \r | |
137 | EFI_USB2_HC_PROTOCOL Usb2Hc;\r | |
138 | \r | |
139 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
140 | \r | |
141 | //\r | |
142 | // ExitBootServicesEvent is used to set OS semaphore and\r | |
143 | // stop the XHC DMA operation after exit boot service.\r | |
144 | //\r | |
145 | EFI_EVENT ExitBootServiceEvent;\r | |
146 | EFI_EVENT PollTimer;\r | |
147 | LIST_ENTRY AsyncIntTransfers;\r | |
148 | \r | |
149 | UINT8 CapLength; ///< Capability Register Length\r | |
150 | XHC_HCSPARAMS1 HcSParams1; ///< Structural Parameters 1\r | |
151 | XHC_HCSPARAMS2 HcSParams2; ///< Structural Parameters 2\r | |
152 | XHC_HCCPARAMS HcCParams; ///< Capability Parameters\r | |
153 | UINT32 DBOff; ///< Doorbell Offset\r | |
154 | UINT32 RTSOff; ///< Runtime Register Space Offset\r | |
155 | UINT16 MaxInterrupt;\r | |
156 | UINT32 PageSize;\r | |
157 | UINT64 *ScratchBuf;\r | |
158 | UINT32 MaxScratchpadBufs;\r | |
159 | UINT32 ExtCapRegBase;\r | |
160 | UINT32 UsbLegSupOffset;\r | |
161 | UINT64 *DCBAA;\r | |
162 | UINT32 MaxSlotsEn;\r | |
163 | //\r | |
164 | // Cmd Transfer Ring\r | |
165 | //\r | |
166 | TRANSFER_RING CmdRing;\r | |
167 | //\r | |
168 | // CmdEventRing\r | |
169 | //\r | |
170 | EVENT_RING CmdEventRing;\r | |
171 | //\r | |
172 | // ControlTREventRing\r | |
173 | //\r | |
174 | EVENT_RING CtrlTrEventRing;\r | |
175 | //\r | |
176 | // BulkTREventRing\r | |
177 | //\r | |
178 | EVENT_RING BulkTrEventRing;\r | |
179 | //\r | |
180 | // IntTREventRing\r | |
181 | //\r | |
182 | EVENT_RING IntTrEventRing;\r | |
183 | //\r | |
184 | // AsyncIntTREventRing\r | |
185 | //\r | |
186 | EVENT_RING AsynIntTrEventRing;\r | |
187 | //\r | |
188 | // Misc\r | |
189 | //\r | |
190 | EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r | |
191 | \r | |
192 | };\r | |
193 | \r | |
194 | struct _USB_DEV_CONTEXT {\r | |
195 | //\r | |
196 | // Whether this entry in UsbDevContext array is used or not.\r | |
197 | //\r | |
198 | BOOLEAN Enabled;\r | |
199 | //\r | |
200 | // The slot id assigned to the new device through XHCI's Enable_Slot cmd.\r | |
201 | //\r | |
202 | UINT8 SlotId;\r | |
203 | //\r | |
204 | // The route string presented an attached usb device.\r | |
205 | //\r | |
206 | USB_DEV_ROUTE RouteString;\r | |
207 | //\r | |
208 | // The route string of parent device if it exists. Otherwise it's zero.\r | |
209 | //\r | |
210 | USB_DEV_ROUTE ParentRouteString;\r | |
211 | //\r | |
212 | // The actual device address assigned by XHCI through Address_Device command.\r | |
213 | //\r | |
214 | UINT8 XhciDevAddr;\r | |
215 | //\r | |
216 | // The requested device address from UsbBus driver through Set_Address standard usb request.\r | |
217 | // As XHCI spec replaces this request with Address_Device command, we have to record the\r | |
218 | // requested device address and establish a mapping relationship with the actual device address.\r | |
219 | // Then UsbBus driver just need to be aware of the requested device address to access usb device\r | |
220 | // through EFI_USB2_HC_PROTOCOL. Xhci driver would be responsible for translating it to actual\r | |
221 | // device address and access the actual device.\r | |
222 | //\r | |
223 | UINT8 BusDevAddr;\r | |
224 | //\r | |
225 | // The pointer to the input device context.\r | |
226 | //\r | |
227 | VOID *InputContext;\r | |
228 | //\r | |
229 | // The pointer to the output device context.\r | |
230 | //\r | |
231 | VOID *OutputDevContxt;\r | |
232 | //\r | |
233 | // The transfer queue for every endpoint.\r | |
234 | //\r | |
235 | VOID *EndpointTransferRing[31];\r | |
236 | //\r | |
237 | // The device descriptor which is stored to support XHCI's Evaluate_Context cmd.\r | |
238 | //\r | |
239 | EFI_USB_DEVICE_DESCRIPTOR DevDesc;\r | |
240 | //\r | |
241 | // As a usb device may include multiple configuration descriptors, we dynamically allocate an array\r | |
242 | // to store them.\r | |
243 | // Note that every configuration descriptor stored here includes those lower level descriptors,\r | |
244 | // such as Interface descriptor, Endpoint descriptor, and so on.\r | |
245 | // These information is used to support XHCI's Config_Endpoint cmd.\r | |
246 | //\r | |
247 | EFI_USB_CONFIG_DESCRIPTOR **ConfDesc;\r | |
248 | };\r | |
249 | \r | |
250 | extern EFI_DRIVER_BINDING_PROTOCOL gXhciDriverBinding;\r | |
251 | extern EFI_COMPONENT_NAME_PROTOCOL gXhciComponentName;\r | |
252 | extern EFI_COMPONENT_NAME2_PROTOCOL gXhciComponentName2;\r | |
253 | extern USB_DEV_CONTEXT UsbDevContext[];\r | |
254 | \r | |
255 | /**\r | |
256 | Test to see if this driver supports ControllerHandle. Any\r | |
257 | ControllerHandle that has Usb2HcProtocol installed will\r | |
258 | be supported.\r | |
259 | \r | |
260 | @param This Protocol instance pointer.\r | |
261 | @param Controller Handle of device to test.\r | |
262 | @param RemainingDevicePath Not used.\r | |
263 | \r | |
264 | @return EFI_SUCCESS This driver supports this device.\r | |
265 | @return EFI_UNSUPPORTED This driver does not support this device.\r | |
266 | \r | |
267 | **/\r | |
268 | EFI_STATUS\r | |
269 | EFIAPI\r | |
270 | XhcDriverBindingSupported (\r | |
271 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
272 | IN EFI_HANDLE Controller,\r | |
273 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
274 | );\r | |
275 | \r | |
276 | /**\r | |
277 | Starting the Usb XHCI Driver.\r | |
278 | \r | |
279 | @param This Protocol instance pointer.\r | |
280 | @param Controller Handle of device to test.\r | |
281 | @param RemainingDevicePath Not used.\r | |
282 | \r | |
283 | @return EFI_SUCCESS supports this device.\r | |
284 | @return EFI_UNSUPPORTED do not support this device.\r | |
285 | @return EFI_DEVICE_ERROR cannot be started due to device Error.\r | |
286 | @return EFI_OUT_OF_RESOURCES cannot allocate resources.\r | |
287 | \r | |
288 | **/\r | |
289 | EFI_STATUS\r | |
290 | EFIAPI\r | |
291 | XhcDriverBindingStart (\r | |
292 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
293 | IN EFI_HANDLE Controller,\r | |
294 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
295 | );\r | |
296 | \r | |
297 | /**\r | |
298 | Stop this driver on ControllerHandle. Support stoping any child handles\r | |
299 | created by this driver.\r | |
300 | \r | |
301 | @param This Protocol instance pointer.\r | |
302 | @param Controller Handle of device to stop driver on.\r | |
303 | @param NumberOfChildren Number of Children in the ChildHandleBuffer.\r | |
304 | @param ChildHandleBuffer List of handles for the children we need to stop.\r | |
305 | \r | |
306 | @return EFI_SUCCESS Success.\r | |
307 | @return EFI_DEVICE_ERROR Fail.\r | |
308 | \r | |
309 | **/\r | |
310 | EFI_STATUS\r | |
311 | EFIAPI\r | |
312 | XhcDriverBindingStop (\r | |
313 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
314 | IN EFI_HANDLE Controller,\r | |
315 | IN UINTN NumberOfChildren,\r | |
316 | IN EFI_HANDLE *ChildHandleBuffer\r | |
317 | );\r | |
318 | \r | |
319 | /**\r | |
320 | Sets a feature for the specified root hub port.\r | |
321 | \r | |
322 | @param This This EFI_USB2_HC_PROTOCOL instance.\r | |
323 | @param PortNumber Root hub port to set.\r | |
324 | @param PortFeature Feature to set.\r | |
325 | \r | |
326 | @retval EFI_SUCCESS The feature specified by PortFeature was set.\r | |
327 | @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.\r | |
328 | @retval EFI_DEVICE_ERROR Can't read register.\r | |
329 | \r | |
330 | **/\r | |
331 | EFI_STATUS\r | |
332 | EFIAPI\r | |
333 | XhcSetRootHubPortFeature (\r | |
334 | IN EFI_USB2_HC_PROTOCOL *This,\r | |
335 | IN UINT8 PortNumber,\r | |
336 | IN EFI_USB_PORT_FEATURE PortFeature\r | |
337 | );\r | |
338 | \r | |
339 | /**\r | |
340 | Clears a feature for the specified root hub port.\r | |
341 | \r | |
342 | @param This A pointer to the EFI_USB2_HC_PROTOCOL instance.\r | |
343 | @param PortNumber Specifies the root hub port whose feature is\r | |
344 | requested to be cleared.\r | |
345 | @param PortFeature Indicates the feature selector associated with the\r | |
346 | feature clear request.\r | |
347 | \r | |
348 | @retval EFI_SUCCESS The feature specified by PortFeature was cleared\r | |
349 | for the USB root hub port specified by PortNumber.\r | |
350 | @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.\r | |
351 | @retval EFI_DEVICE_ERROR Can't read register.\r | |
352 | \r | |
353 | **/\r | |
354 | EFI_STATUS\r | |
355 | EFIAPI\r | |
356 | XhcClearRootHubPortFeature (\r | |
357 | IN EFI_USB2_HC_PROTOCOL *This,\r | |
358 | IN UINT8 PortNumber,\r | |
359 | IN EFI_USB_PORT_FEATURE PortFeature\r | |
360 | );\r | |
361 | \r | |
362 | #endif\r |