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 This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include "CommonHeader.h"
25 #include "PlatformEarlyInit.h"
27 extern EFI_PEI_PPI_DESCRIPTOR mPpiStall
[];
29 EFI_PEI_RESET_PPI mResetPpi
= { ResetSystem
};
31 EFI_PEI_PPI_DESCRIPTOR mPpiList
[1] = {
33 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
40 This function reset the entire platform, including all processor and devices, and
43 @param PeiServices General purpose services available to every PEIM.
45 @retval EFI_SUCCESS if it completed successfully.
50 IN CONST EFI_PEI_SERVICES
**PeiServices
58 This function provides a blocking stall for reset at least the given number of microseconds
59 stipulated in the final argument.
61 @param PeiServices General purpose services available to every PEIM.
63 @param this Pointer to the local data for the interface.
65 @param Microseconds number of microseconds for which to stall.
67 @retval EFI_SUCCESS the function provided at least the required stall.
72 IN CONST EFI_PEI_SERVICES
**PeiServices
,
73 IN CONST EFI_PEI_STALL_PPI
*This
,
77 MicroSecondDelay (Microseconds
);
83 This function will be called when MRC is done.
85 @param PeiServices General purpose services available to every PEIM.
87 @param NotifyDescriptor Information about the notify event..
89 @param Ppi The notify context.
91 @retval EFI_SUCCESS If the function completed successfully.
95 MemoryDiscoveredPpiNotifyCallback (
96 IN EFI_PEI_SERVICES
**PeiServices
,
97 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
102 EFI_BOOT_MODE BootMode
;
104 EFI_SMRAM_DESCRIPTOR
*SmramDescriptor
;
105 UINTN NumSmramRegions
;
106 UINT32 RmuMainBaseAddress
;
108 UINT8 CpuAddressWidth
;
110 MTRR_SETTINGS MtrrSettings
;
111 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariableServices
;
115 DEBUG ((EFI_D_INFO
, "Platform PEIM Memory Callback\n"));
118 SmramDescriptor
= NULL
;
119 RmuMainBaseAddress
= 0;
121 PERF_START (NULL
, "SetCache", NULL
, 0);
123 InfoPostInstallMemory (&RmuMainBaseAddress
, &SmramDescriptor
, &NumSmramRegions
);
124 ASSERT (SmramDescriptor
!= NULL
);
125 ASSERT (RmuMainBaseAddress
!= 0);
127 MemoryLength
= ((UINT64
) RmuMainBaseAddress
) + 0x10000;
129 Status
= PeiServicesGetBootMode (&BootMode
);
130 ASSERT_EFI_ERROR (Status
);
133 // Get current MTRR settings
135 MtrrGetAllMtrrs (&MtrrSettings
);
138 // Set all DRAM cachability to CacheWriteBack
140 Status
= MtrrSetMemoryAttributeInMtrrSettings (&MtrrSettings
, 0, MemoryLength
, CacheWriteBack
);
141 ASSERT_EFI_ERROR (Status
);
144 // RTC:28208 - System hang/crash when entering probe mode(ITP) when relocating SMBASE
145 // Workaround to make default SMRAM UnCachable
147 Status
= MtrrSetMemoryAttributeInMtrrSettings (&MtrrSettings
, 0x30000, SIZE_64KB
, CacheUncacheable
);
148 ASSERT_EFI_ERROR (Status
);
151 // Set new MTRR settings
153 MtrrSetAllMtrrs (&MtrrSettings
);
155 PERF_END (NULL
, "SetCache", NULL
, 0);
160 Status
= PeiServicesLocatePpi (
161 &gEfiPeiReadOnlyVariable2PpiGuid
, // GUID
163 NULL
, // EFI_PEI_PPI_DESCRIPTOR
164 (VOID
**)&VariableServices
// PPI
166 ASSERT_EFI_ERROR (Status
);
169 // Detect MOR request by the OS.
172 DataSize
= sizeof (MorControl
);
173 Status
= VariableServices
->GetVariable (
175 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
176 &gEfiMemoryOverwriteControlDataGuid
,
182 // If OS requested a memory overwrite perform it now for Embedded SRAM
184 if (MOR_CLEAR_MEMORY_VALUE (MorControl
)) {
185 DEBUG ((EFI_D_INFO
, "Clear Embedded SRAM per MOR request.\n"));
186 if (PcdGet32 (PcdESramMemorySize
) > 0) {
187 if (PcdGet32 (PcdEsramStage1Base
) == 0) {
189 // ZeroMem() generates an ASSERT() if Buffer parameter is NULL.
190 // Clear byte at 0 and start clear operation at address 1.
193 ZeroMem ((VOID
*)1, (UINTN
)PcdGet32 (PcdESramMemorySize
) - 1);
196 (VOID
*)(UINTN
)PcdGet32 (PcdEsramStage1Base
),
197 (UINTN
)PcdGet32 (PcdESramMemorySize
)
204 // Install PeiReset for PeiResetSystem service
206 Status
= PeiServicesInstallPpi (&mPpiList
[0]);
207 ASSERT_EFI_ERROR (Status
);
210 // Do QNC initialization after MRC
212 PeiQNCPostMemInit ();
214 Status
= PeiServicesInstallPpi (&mPpiStall
[0]);
215 ASSERT_EFI_ERROR (Status
);
218 // Set E000/F000 Routing
220 RegData32
= QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID
, QNC_MSG_FSBIC_REG_HMISC
);
221 RegData32
|= (BIT2
|BIT1
);
222 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID
, QNC_MSG_FSBIC_REG_HMISC
, RegData32
);
224 if (BootMode
== BOOT_IN_RECOVERY_MODE
) {
225 Status
= PeimInitializeRecovery (PeiServices
);
226 ASSERT_EFI_ERROR (Status
);
227 } else if (BootMode
== BOOT_ON_S3_RESUME
) {
230 PeiServicesInstallFvInfoPpi (
232 (VOID
*) (UINTN
) PcdGet32 (PcdFlashFvMainBase
),
233 PcdGet32 (PcdFlashFvMainSize
),
239 // Publish the FVMAIN FV so the DXE Phase can dispatch drivers from this FV
240 // and produce Load File Protocols for UEFI Applications in this FV.
243 PcdGet32 (PcdFlashFvMainBase
),
244 PcdGet32 (PcdFlashFvMainSize
)
248 // Publish the Payload FV so the DXE Phase can dispatch drivers from this FV
249 // and produce Load File Protocols for UEFI Applications in this FV.
252 PcdGet32 (PcdFlashFvPayloadBase
),
253 PcdGet32 (PcdFlashFvPayloadSize
)
258 // Build flash HOB, it's going to be used by GCD and E820 building
259 // Map full SPI flash decode range (regardless of smaller SPI flash parts installed)
261 BuildResourceDescriptorHob (
262 EFI_RESOURCE_FIRMWARE_DEVICE
,
263 (EFI_RESOURCE_ATTRIBUTE_PRESENT
|
264 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
265 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
),
266 (SIZE_4GB
- SIZE_8MB
),
271 // Create a CPU hand-off information
273 CpuAddressWidth
= 32;
274 AsmCpuid (CPUID_EXTENDED_FUNCTION
, &RegEax
, NULL
, NULL
, NULL
);
275 if (RegEax
>= CPUID_VIR_PHY_ADDRESS_SIZE
) {
276 AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE
, &RegEax
, NULL
, NULL
, NULL
);
277 CpuAddressWidth
= (UINT8
) (RegEax
& 0xFF);
279 DEBUG ((EFI_D_INFO
, "CpuAddressWidth: %d\n", CpuAddressWidth
));
281 BuildCpuHob (CpuAddressWidth
, 16);
283 ASSERT_EFI_ERROR (Status
);