18#define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
22 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
23 &gEfiPeiMemoryDiscoveredPpiGuid,
70 if (Address !=
NULL) {
95 IN PHYSICAL_ADDRESS BaseAddress,
105 PAGING_MODE PagingMode;
107 BOOLEAN Page5LevelSupport;
109 BOOLEAN Page1GSupport;
112 if (
sizeof (
UINTN) ==
sizeof (UINT64)) {
117 Page5LevelSupport = (Cr4.Bits.LA57 ?
TRUE :
FALSE);
122 Page1GSupport =
FALSE;
127 Page1GSupport =
TRUE;
134 if (Page5LevelSupport) {
135 PagingMode = Page1GSupport ? Paging5Level1GB : Paging5Level;
137 PagingMode = Page1GSupport ? Paging4Level1GB : Paging4Level;
140 PagingMode = PagingPae;
143 MapAttribute.Uint64 = 0;
145 MapMask.Bits.Present = 1;
146 PageTable =
AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64;
152 Status =
PageTableMap (&PageTable, PagingMode, 0, &BufferSize, BaseAddress, Length, &MapAttribute, &MapMask,
NULL);
153 if (Status == EFI_BUFFER_TOO_SMALL) {
163 if (EFI_ERROR (Status)) {
164 return EFI_OUT_OF_RESOURCES;
167 Status =
PageTableMap (&PageTable, PagingMode, (VOID *)(
UINTN)Buffer, &BufferSize, BaseAddress, Length, &MapAttribute, &MapMask,
NULL);
197 MapAttribute.Uint64 = 0;
198 MapMask.Uint64 = MAX_UINT64;
199 MapAttribute.Bits.Present = 1;
200 MapAttribute.Bits.ReadWrite = 1;
205 Status =
PageTableMap (&PageTable, PagingPae, 0, &BufferSize, 0, SIZE_4GB, &MapAttribute, &MapMask,
NULL);
206 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
207 if (Status != EFI_BUFFER_TOO_SMALL) {
215 ASSERT (Buffer !=
NULL);
216 if (Buffer ==
NULL) {
217 return EFI_OUT_OF_RESOURCES;
220 Status =
PageTableMap (&PageTable, PagingPae, Buffer, &BufferSize, 0, SIZE_4GB, &MapAttribute, &MapMask,
NULL);
222 if (EFI_ERROR (Status) || (PageTable == 0)) {
223 return EFI_OUT_OF_RESOURCES;
243 "EnablePaePageTable: Created PageTable = 0x%x, BufferSize = %x\n",
274 StackBase += BASE_4KB;
276 StackBase -=
PcdGet32 (PcdCpuApStackSize);
293 UINTN NumberOfProcessors;
301 if (
PcdGet32 (PcdCpuApStackSize) <= EFI_PAGE_SIZE) {
302 DEBUG ((DEBUG_ERROR,
"PcdCpuApStackSize is not big enough for Stack Guard!\n"));
309 if (EFI_ERROR (Status)) {
310 NumberOfProcessors = 1;
314 ASSERT (StackBase !=
NULL);
315 if (StackBase ==
NULL) {
323 while ((Hob.Raw =
GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) !=
NULL) {
325 &gEfiHobMemoryAllocStackGuid,
333 Hob.Raw = GET_NEXT_HOB (Hob);
336 for (Index = 0; Index < NumberOfProcessors; ++Index) {
337 ASSERT (StackBase[Index] != 0);
344 "Stack Guard set at %lx [cpu%lu]!\n",
345 (UINT64)StackBase[Index],
379 BOOLEAN InitStackGuard;
389 InitStackGuard =
FALSE;
393 InitStackGuard =
PcdGetBool (PcdCpuStackGuard);
401 if ((Cr0.Bits.PG == 0) && (InitStackGuard || (Hob.Raw !=
NULL))) {
402 ASSERT (
sizeof (
UINTN) ==
sizeof (UINT32));
405 if (EFI_ERROR (Status)) {
406 DEBUG ((DEBUG_ERROR,
"MemoryDiscoveredPpiNotifyCallback: Failed to enable PAE page table: %r.\n", Status));
414 if (InitStackGuard) {
418 while (Hob.Raw !=
NULL) {
419 MigratedFvInfo = GET_GUID_HOB_DATA (Hob);
427 Hob.Raw = GET_NEXT_HOB (Hob);
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI GetNextHob(IN UINT16 Type, IN CONST VOID *HobStart)
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
VOID *EFIAPI GetHobList(VOID)
VOID EFIAPI CpuDeadLoop(VOID)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI CpuFlushTlb(VOID)
EFI_STATUS InitializeCpuMpWorker(IN CONST EFI_PEI_SERVICES **PeiServices)
RETURN_STATUS EFIAPI PageTableMap(IN OUT UINTN *PageTable OPTIONAL, IN PAGING_MODE PagingMode, IN VOID *Buffer, IN OUT UINTN *BufferSize, IN UINT64 LinearAddress, IN UINT64 Length, IN IA32_MAP_ATTRIBUTE *Attribute, IN IA32_MAP_ATTRIBUTE *Mask, OUT BOOLEAN *IsModified OPTIONAL)
VOID SetupStackGuardPage(VOID)
BOOLEAN IsIa32PaeSupported(VOID)
EFI_STATUS EFIAPI MemoryDiscoveredPpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
VOID * AllocatePageTableMemory(IN UINTN Pages)
RETURN_STATUS ConvertMemoryPageToNotPresent(IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
EFI_STATUS EnablePaePageTable(VOID)
VOID EFIAPI GetStackBase(IN OUT VOID *Buffer)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
EFI_STATUS EFIAPI PeiServicesAllocatePages(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, OUT EFI_PHYSICAL_ADDRESS *Memory)
UINTN EFIAPI AsmReadCr3(VOID)
UINTN EFIAPI AsmWriteCr3(UINTN Cr3)
UINTN EFIAPI AsmWriteCr4(UINTN Cr4)
UINTN EFIAPI AsmReadCr0(VOID)
UINTN EFIAPI AsmWriteCr0(UINTN Cr0)
UINTN EFIAPI AsmReadCr4(VOID)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define CPUID_VERSION_INFO
#define CPUID_EXTENDED_CPU_SIG
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
EFI_STATUS EFIAPI MpInitLibStartupAllAPs(IN EFI_AP_PROCEDURE Procedure, IN BOOLEAN SingleThread, IN EFI_EVENT WaitEvent OPTIONAL, IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL, OUT UINTN **FailedCpuList OPTIONAL)
EFI_STATUS EFIAPI MpInitLibWhoAmI(OUT UINTN *ProcessorNumber)
EFI_STATUS EFIAPI MpInitLibGetNumberOfProcessors(OUT UINTN *NumberOfProcessors OPTIONAL, OUT UINTN *NumberOfEnabledProcessors OPTIONAL)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_PHYSICAL_ADDRESS MemoryBaseAddress
EFI_HOB_MEMORY_ALLOCATION_HEADER AllocDescriptor
struct CPUID_EXTENDED_CPU_SIG_EDX::@750 Bits
struct CPUID_VERSION_INFO_EDX::@696 Bits