2 Private Header file for Usb Host Controller PEIM
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) Microsoft Corporation.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _RECOVERY_EHC_H_
12 #define _RECOVERY_EHC_H_
16 #include <Ppi/UsbController.h>
17 #include <Ppi/Usb2HostController.h>
18 #include <Ppi/IoMmu.h>
19 #include <Ppi/EndOfPeiPhase.h>
21 #include <Library/BaseLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PeimEntryPoint.h>
24 #include <Library/PeiServicesLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/TimerLib.h>
27 #include <Library/IoLib.h>
29 typedef struct _PEI_USB2_HC_DEV PEI_USB2_HC_DEV
;
31 #define EFI_LIST_ENTRY LIST_ENTRY
36 #include "EhciSched.h"
38 #define EFI_USB_SPEED_FULL 0x0000
39 #define EFI_USB_SPEED_LOW 0x0001
40 #define EFI_USB_SPEED_HIGH 0x0002
44 #define EHC_1_MICROSECOND 1
45 #define EHC_1_MILLISECOND (1000 * EHC_1_MICROSECOND)
46 #define EHC_1_SECOND (1000 * EHC_1_MILLISECOND)
49 // EHCI register operation timeout, set by experience
51 #define EHC_RESET_TIMEOUT (1 * EHC_1_SECOND)
52 #define EHC_GENERIC_TIMEOUT (10 * EHC_1_MILLISECOND)
55 // Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9]
57 #define EHC_ROOT_PORT_RECOVERY_STALL (20 * EHC_1_MILLISECOND)
60 // Sync transfer polling interval, set by experience.
62 #define EHC_SYNC_POLL_INTERVAL (6 * EHC_1_MILLISECOND)
64 #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
66 #define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))
67 #define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
68 #define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
70 #define EHC_REG_BIT_IS_SET(Ehc, Offset, Bit) \
71 (EHC_BIT_IS_SET(EhcReadOpReg ((Ehc), (Offset)), (Bit)))
73 #define USB2_HC_DEV_SIGNATURE SIGNATURE_32 ('e', 'h', 'c', 'i')
75 struct _PEI_USB2_HC_DEV
{
77 PEI_USB2_HOST_CONTROLLER_PPI Usb2HostControllerPpi
;
78 EDKII_IOMMU_PPI
*IoMmu
;
79 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor
;
81 // EndOfPei callback is used to stop the EHC DMA operation
82 // after exit PEI phase.
84 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList
;
85 UINT32 UsbHostControllerBaseAddress
;
87 USBHC_MEM_POOL
*MemPool
;
90 // Schedule data shared between asynchronous and periodic
92 // ShortReadStop, as its name indicates, is used to terminate
93 // the short read except the control transfer. EHCI follows
94 // the alternative next QTD point when a short read happens.
95 // For control transfer, even the short read happens, try the
98 PEI_EHC_QTD
*ShortReadStop
;
102 // Asynchronous(bulk and control) transfer schedule data:
103 // ReclaimHead is used as the head of the asynchronous transfer
104 // list. It acts as the reclamation header.
106 PEI_EHC_QH
*ReclaimHead
;
109 // Periodic (interrupt) transfer schedule data:
111 VOID
*PeriodFrame
; // Mapped as common buffer
112 VOID
*PeriodFrameMap
;
114 PEI_EHC_QH
*PeriodOne
;
115 EFI_LIST_ENTRY AsyncIntTransfers
;
118 // EHCI configuration data
120 UINT32 HcStructParams
; // Cache of HC structure parameter, EHC_HCSPARAMS_OFFSET
121 UINT32 HcCapParams
; // Cache of HC capability parameter, HCCPARAMS
122 UINT32 CapLen
; // Capability length
123 UINT32 High32bitAddr
;
126 #define PEI_RECOVERY_USB_EHC_DEV_FROM_EHCI_THIS(a) CR (a, PEI_USB2_HC_DEV, Usb2HostControllerPpi, USB2_HC_DEV_SIGNATURE)
127 #define PEI_RECOVERY_USB_EHC_DEV_FROM_THIS_NOTIFY(a) CR (a, PEI_USB2_HC_DEV, EndOfPeiNotifyList, USB2_HC_DEV_SIGNATURE)
130 @param EhcDev EHCI Device.
132 @retval EFI_SUCCESS EHCI successfully initialized.
133 @retval EFI_ABORTED EHCI was failed to be initialized.
138 IN PEI_USB2_HC_DEV
*EhcDev
142 Initialize the memory management pool for the host controller.
144 @param Ehc The EHCI device.
145 @param Check4G Whether the host controller requires allocated memory
146 from one 4G address space.
147 @param Which4G The 4G memory area each memory allocated should be from.
149 @retval EFI_SUCCESS The memory pool is initialized.
150 @retval EFI_OUT_OF_RESOURCE Fail to init the memory pool.
155 IN PEI_USB2_HC_DEV
*Ehc
,
162 Release the memory management pool.
164 @param Ehc The EHCI device.
165 @param Pool The USB memory pool to free.
167 @retval EFI_DEVICE_ERROR Fail to free the memory pool.
168 @retval EFI_SUCCESS The memory pool is freed.
173 IN PEI_USB2_HC_DEV
*Ehc
,
174 IN USBHC_MEM_POOL
*Pool
179 Allocate some memory from the host controller's memory pool
180 which can be used to communicate with host controller.
182 @param Ehc The EHCI device.
183 @param Pool The host controller's memory pool.
184 @param Size Size of the memory to allocate.
186 @return The allocated memory or NULL.
191 IN PEI_USB2_HC_DEV
*Ehc
,
192 IN USBHC_MEM_POOL
*Pool
,
198 Free the allocated memory back to the memory pool.
200 @param Ehc The EHCI device.
201 @param Pool The memory pool of the host controller.
202 @param Mem The memory to free.
203 @param Size The size of the memory to free.
208 IN PEI_USB2_HC_DEV
*Ehc
,
209 IN USBHC_MEM_POOL
*Pool
,
216 Provides the controller-specific addresses required to access system memory from a
219 @param IoMmu Pointer to IOMMU PPI.
220 @param Operation Indicates if the bus master is going to read or write to system memory.
221 @param HostAddress The system memory address to map to the PCI controller.
222 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
224 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
225 access the hosts HostAddress.
226 @param Mapping A resulting value to pass to Unmap().
228 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
229 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
230 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
231 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
232 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
237 IN EDKII_IOMMU_PPI
*IoMmu
,
238 IN EDKII_IOMMU_OPERATION Operation
,
239 IN VOID
*HostAddress
,
240 IN OUT UINTN
*NumberOfBytes
,
241 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
246 Completes the Map() operation and releases any corresponding resources.
248 @param IoMmu Pointer to IOMMU PPI.
249 @param Mapping The mapping value returned from Map().
254 IN EDKII_IOMMU_PPI
*IoMmu
,
259 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
260 OperationBusMasterCommonBuffer64 mapping.
262 @param IoMmu Pointer to IOMMU PPI.
263 @param Pages The number of pages to allocate.
264 @param HostAddress A pointer to store the base system memory address of the
266 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
267 access the hosts HostAddress.
268 @param Mapping A resulting value to pass to Unmap().
270 @retval EFI_SUCCESS The requested memory pages were allocated.
271 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
272 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
273 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
274 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
278 IoMmuAllocateBuffer (
279 IN EDKII_IOMMU_PPI
*IoMmu
,
281 OUT VOID
**HostAddress
,
282 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
287 Frees memory that was allocated with AllocateBuffer().
289 @param IoMmu Pointer to IOMMU PPI.
290 @param Pages The number of pages to free.
291 @param HostAddress The base system memory address of the allocated range.
292 @param Mapping The mapping value returned from Map().
297 IN EDKII_IOMMU_PPI
*IoMmu
,
299 IN VOID
*HostAddress
,
306 @param IoMmu Pointer to pointer to IOMMU PPI.
311 OUT EDKII_IOMMU_PPI
**IoMmu