2 This file includes a memory call back function notified when MRC is done,
3 following action is performed in this file,
4 1. ICH initialization after MRC.
6 3. Install ResetSystem and FinvFv PPI.
8 5. Create FV HOB and Flash HOB
10 Copyright (c) 2013 - 2016, Intel Corporation.
12 SPDX-License-Identifier: BSD-2-Clause-Patent
17 #include "CommonHeader.h"
19 #include "PlatformEarlyInit.h"
21 extern EFI_PEI_PPI_DESCRIPTOR mPpiStall
[];
23 EFI_PEI_RESET_PPI mResetPpi
= { ResetSystem
};
25 EFI_PEI_PPI_DESCRIPTOR mPpiList
[1] = {
27 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
34 This function reset the entire platform, including all processor and devices, and
37 @param PeiServices General purpose services available to every PEIM.
39 @retval EFI_SUCCESS if it completed successfully.
44 IN CONST EFI_PEI_SERVICES
**PeiServices
52 This function provides a blocking stall for reset at least the given number of microseconds
53 stipulated in the final argument.
55 @param PeiServices General purpose services available to every PEIM.
57 @param this Pointer to the local data for the interface.
59 @param Microseconds number of microseconds for which to stall.
61 @retval EFI_SUCCESS the function provided at least the required stall.
66 IN CONST EFI_PEI_SERVICES
**PeiServices
,
67 IN CONST EFI_PEI_STALL_PPI
*This
,
71 MicroSecondDelay (Microseconds
);
77 This function will be called when MRC is done.
79 @param PeiServices General purpose services available to every PEIM.
81 @param NotifyDescriptor Information about the notify event..
83 @param Ppi The notify context.
85 @retval EFI_SUCCESS If the function completed successfully.
89 MemoryDiscoveredPpiNotifyCallback (
90 IN EFI_PEI_SERVICES
**PeiServices
,
91 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
96 EFI_BOOT_MODE BootMode
;
98 EFI_SMRAM_DESCRIPTOR
*SmramDescriptor
;
99 UINTN NumSmramRegions
;
100 UINT32 RmuMainBaseAddress
;
102 UINT8 CpuAddressWidth
;
104 MTRR_SETTINGS MtrrSettings
;
105 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariableServices
;
109 DEBUG ((EFI_D_INFO
, "Platform PEIM Memory Callback\n"));
112 SmramDescriptor
= NULL
;
113 RmuMainBaseAddress
= 0;
115 PERF_START (NULL
, "SetCache", NULL
, 0);
117 InfoPostInstallMemory (&RmuMainBaseAddress
, &SmramDescriptor
, &NumSmramRegions
);
118 ASSERT (SmramDescriptor
!= NULL
);
119 ASSERT (RmuMainBaseAddress
!= 0);
121 MemoryLength
= ((UINT64
) RmuMainBaseAddress
) + 0x10000;
123 Status
= PeiServicesGetBootMode (&BootMode
);
124 ASSERT_EFI_ERROR (Status
);
127 // Get current MTRR settings
129 MtrrGetAllMtrrs (&MtrrSettings
);
132 // Set all DRAM cachability to CacheWriteBack
134 Status
= MtrrSetMemoryAttributeInMtrrSettings (&MtrrSettings
, 0, MemoryLength
, CacheWriteBack
);
135 ASSERT_EFI_ERROR (Status
);
138 // RTC:28208 - System hang/crash when entering probe mode(ITP) when relocating SMBASE
139 // Workaround to make default SMRAM UnCachable
141 Status
= MtrrSetMemoryAttributeInMtrrSettings (&MtrrSettings
, 0x30000, SIZE_64KB
, CacheUncacheable
);
142 ASSERT_EFI_ERROR (Status
);
145 // Set new MTRR settings
147 MtrrSetAllMtrrs (&MtrrSettings
);
149 PERF_END (NULL
, "SetCache", NULL
, 0);
154 Status
= PeiServicesLocatePpi (
155 &gEfiPeiReadOnlyVariable2PpiGuid
, // GUID
157 NULL
, // EFI_PEI_PPI_DESCRIPTOR
158 (VOID
**)&VariableServices
// PPI
160 ASSERT_EFI_ERROR (Status
);
163 // Detect MOR request by the OS.
166 DataSize
= sizeof (MorControl
);
167 Status
= VariableServices
->GetVariable (
169 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
170 &gEfiMemoryOverwriteControlDataGuid
,
176 // If OS requested a memory overwrite perform it now for Embedded SRAM
178 if (MOR_CLEAR_MEMORY_VALUE (MorControl
)) {
179 DEBUG ((EFI_D_INFO
, "Clear Embedded SRAM per MOR request.\n"));
180 if (PcdGet32 (PcdESramMemorySize
) > 0) {
181 if (PcdGet32 (PcdEsramStage1Base
) == 0) {
183 // ZeroMem() generates an ASSERT() if Buffer parameter is NULL.
184 // Clear byte at 0 and start clear operation at address 1.
187 ZeroMem ((VOID
*)1, (UINTN
)PcdGet32 (PcdESramMemorySize
) - 1);
190 (VOID
*)(UINTN
)PcdGet32 (PcdEsramStage1Base
),
191 (UINTN
)PcdGet32 (PcdESramMemorySize
)
198 // Install PeiReset for PeiResetSystem service
200 Status
= PeiServicesInstallPpi (&mPpiList
[0]);
201 ASSERT_EFI_ERROR (Status
);
204 // Do QNC initialization after MRC
206 PeiQNCPostMemInit ();
208 Status
= PeiServicesInstallPpi (&mPpiStall
[0]);
209 ASSERT_EFI_ERROR (Status
);
212 // Set E000/F000 Routing
214 RegData32
= QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID
, QNC_MSG_FSBIC_REG_HMISC
);
215 RegData32
|= (BIT2
|BIT1
);
216 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID
, QNC_MSG_FSBIC_REG_HMISC
, RegData32
);
218 if (BootMode
== BOOT_IN_RECOVERY_MODE
) {
219 // Do nothing here. A generic RecoveryModule will handle it.
220 } else if (BootMode
== BOOT_ON_S3_RESUME
) {
223 PeiServicesInstallFvInfoPpi (
225 (VOID
*) (UINTN
) PcdGet32 (PcdFlashFvMainBase
),
226 PcdGet32 (PcdFlashFvMainSize
),
232 // Publish the FVMAIN FV so the DXE Phase can dispatch drivers from this FV
233 // and produce Load File Protocols for UEFI Applications in this FV.
236 PcdGet32 (PcdFlashFvMainBase
),
237 PcdGet32 (PcdFlashFvMainSize
)
241 // Publish the Payload FV so the DXE Phase can dispatch drivers from this FV
242 // and produce Load File Protocols for UEFI Applications in this FV.
245 PcdGet32 (PcdFlashFvPayloadBase
),
246 PcdGet32 (PcdFlashFvPayloadSize
)
251 // Build flash HOB, it's going to be used by GCD and E820 building
252 // Map full SPI flash decode range (regardless of smaller SPI flash parts installed)
254 BuildResourceDescriptorHob (
255 EFI_RESOURCE_FIRMWARE_DEVICE
,
256 (EFI_RESOURCE_ATTRIBUTE_PRESENT
|
257 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
258 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
),
259 (SIZE_4GB
- SIZE_8MB
),
264 // Create a CPU hand-off information
266 CpuAddressWidth
= 32;
267 AsmCpuid (CPUID_EXTENDED_FUNCTION
, &RegEax
, NULL
, NULL
, NULL
);
268 if (RegEax
>= CPUID_VIR_PHY_ADDRESS_SIZE
) {
269 AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE
, &RegEax
, NULL
, NULL
, NULL
);
270 CpuAddressWidth
= (UINT8
) (RegEax
& 0xFF);
272 DEBUG ((EFI_D_INFO
, "CpuAddressWidth: %d\n", CpuAddressWidth
));
274 BuildCpuHob (CpuAddressWidth
, 16);
276 ASSERT_EFI_ERROR (Status
);