@@ -485,14 +485,14 @@ Split1GPageTo2M (
485
485
486
486
@param[in] PageTableBase Base address of page table (CR3).
487
487
@param[in] Address Start address of a page to be set as read-only.
488
- @param[in] Level4Paging Level 4 paging flag .
488
+ @param[in] LevelOfPaging Level of paging.
489
489
490
490
**/
491
491
VOID
492
492
SetPageTablePoolReadOnly (
493
493
IN UINTN PageTableBase ,
494
494
IN EFI_PHYSICAL_ADDRESS Address ,
495
- IN BOOLEAN Level4Paging
495
+ IN UINT8 LevelOfPaging
496
496
)
497
497
{
498
498
UINTN Index ;
@@ -502,9 +502,9 @@ SetPageTablePoolReadOnly (
502
502
UINT64 * PageTable ;
503
503
UINT64 * NewPageTable ;
504
504
UINT64 PageAttr ;
505
- UINT64 LevelSize [5 ];
506
- UINT64 LevelMask [5 ];
507
- UINTN LevelShift [5 ];
505
+ UINT64 LevelSize [6 ];
506
+ UINT64 LevelMask [6 ];
507
+ UINTN LevelShift [6 ];
508
508
UINTN Level ;
509
509
UINT64 PoolUnitSize ;
510
510
@@ -521,23 +521,26 @@ SetPageTablePoolReadOnly (
521
521
LevelShift [2 ] = PAGING_L2_ADDRESS_SHIFT ;
522
522
LevelShift [3 ] = PAGING_L3_ADDRESS_SHIFT ;
523
523
LevelShift [4 ] = PAGING_L4_ADDRESS_SHIFT ;
524
+ LevelShift [5 ] = PAGING_L5_ADDRESS_SHIFT ;
524
525
525
526
LevelMask [1 ] = PAGING_4K_ADDRESS_MASK_64 ;
526
527
LevelMask [2 ] = PAGING_2M_ADDRESS_MASK_64 ;
527
528
LevelMask [3 ] = PAGING_1G_ADDRESS_MASK_64 ;
528
- LevelMask [4 ] = PAGING_1G_ADDRESS_MASK_64 ;
529
+ LevelMask [4 ] = PAGING_512G_ADDRESS_MASK_64 ;
530
+ LevelMask [5 ] = PAGING_256T_ADDRESS_MASK_64 ;
529
531
530
532
LevelSize [1 ] = SIZE_4KB ;
531
533
LevelSize [2 ] = SIZE_2MB ;
532
534
LevelSize [3 ] = SIZE_1GB ;
533
535
LevelSize [4 ] = SIZE_512GB ;
536
+ LevelSize [5 ] = SIZE_256TB ;
534
537
535
538
AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask ) &
536
539
PAGING_1G_ADDRESS_MASK_64 ;
537
540
PageTable = (UINT64 * )(UINTN )PageTableBase ;
538
541
PoolUnitSize = PAGE_TABLE_POOL_UNIT_SIZE ;
539
542
540
- for (Level = ( Level4Paging ) ? 4 : 3 ; Level > 0 ; -- Level ) {
543
+ for (Level = LevelOfPaging ; Level > 0 ; -- Level ) {
541
544
Index = ((UINTN )RShiftU64 (Address , LevelShift [Level ]));
542
545
Index &= PAGING_PAE_INDEX_MASK ;
543
546
@@ -607,13 +610,13 @@ SetPageTablePoolReadOnly (
607
610
Prevent the memory pages used for page table from been overwritten.
608
611
609
612
@param[in] PageTableBase Base address of page table (CR3).
610
- @param[in] Level4Paging Level 4 paging flag .
613
+ @param[in] LevelOfPaging Level of paging.
611
614
612
615
**/
613
616
VOID
614
617
EnablePageTableProtection (
615
- IN UINTN PageTableBase ,
616
- IN BOOLEAN Level4Paging
618
+ IN UINTN PageTableBase ,
619
+ IN UINT8 LevelOfPaging
617
620
)
618
621
{
619
622
PAGE_TABLE_POOL * HeadPool ;
@@ -642,7 +645,7 @@ EnablePageTableProtection (
642
645
// protection to them one by one.
643
646
//
644
647
while (PoolSize > 0 ) {
645
- SetPageTablePoolReadOnly (PageTableBase , Address , Level4Paging );
648
+ SetPageTablePoolReadOnly (PageTableBase , Address , LevelOfPaging );
646
649
Address += PAGE_TABLE_POOL_UNIT_SIZE ;
647
650
PoolSize -= PAGE_TABLE_POOL_UNIT_SIZE ;
648
651
}
@@ -696,7 +699,7 @@ CreateIdentityMappingPageTables (
696
699
UINTN TotalPagesNum ;
697
700
UINTN BigPageAddress ;
698
701
VOID * Hob ;
699
- BOOLEAN Page5LevelEnabled ;
702
+ UINT8 LevelOfPaging ;
700
703
BOOLEAN Page1GSupport ;
701
704
PAGE_TABLE_1G_ENTRY * PageDirectory1GEntry ;
702
705
UINT64 AddressEncMask ;
@@ -743,16 +746,16 @@ CreateIdentityMappingPageTables (
743
746
//
744
747
// If cpu has already run in 64bit long mode PEI, Page table Level in DXE must align with previous level.
745
748
//
746
- Cr4 .UintN = AsmReadCr4 ();
747
- Page5LevelEnabled = (Cr4 .Bits .LA57 != 0 ) ;
748
- if (Page5LevelEnabled ) {
749
+ Cr4 .UintN = AsmReadCr4 ();
750
+ LevelOfPaging = (Cr4 .Bits .LA57 == 1 ) ? 5 : 4 ;
751
+ if (LevelOfPaging == 5 ) {
749
752
ASSERT (PcdGetBool (PcdUse5LevelPageTable ));
750
753
}
751
754
} else {
752
755
//
753
756
// If cpu runs in 32bit protected mode PEI, Page table Level in DXE is decided by PCD and feature capability.
754
757
//
755
- Page5LevelEnabled = FALSE ;
758
+ LevelOfPaging = 4 ;
756
759
if (PcdGetBool (PcdUse5LevelPageTable )) {
757
760
AsmCpuidEx (
758
761
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS ,
@@ -763,20 +766,20 @@ CreateIdentityMappingPageTables (
763
766
NULL
764
767
);
765
768
if (EcxFlags .Bits .FiveLevelPage != 0 ) {
766
- Page5LevelEnabled = TRUE ;
769
+ LevelOfPaging = 5 ;
767
770
}
768
771
}
769
772
}
770
773
771
- DEBUG ((DEBUG_INFO , "AddressBits=%u 5LevelPaging =%u 1GPage=%u\n" , PhysicalAddressBits , Page5LevelEnabled , Page1GSupport ));
774
+ DEBUG ((DEBUG_INFO , "AddressBits=%u LevelOfPaging =%u 1GPage=%u\n" , PhysicalAddressBits , LevelOfPaging , Page1GSupport ));
772
775
773
776
//
774
777
// IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses
775
778
// when 5-Level Paging is disabled,
776
779
// due to either unsupported by HW, or disabled by PCD.
777
780
//
778
781
ASSERT (PhysicalAddressBits <= 52 );
779
- if (! Page5LevelEnabled && (PhysicalAddressBits > 48 )) {
782
+ if (( LevelOfPaging != 5 ) && (PhysicalAddressBits > 48 )) {
780
783
PhysicalAddressBits = 48 ;
781
784
}
782
785
@@ -811,7 +814,7 @@ CreateIdentityMappingPageTables (
811
814
//
812
815
// Substract the one page occupied by PML5 entries if 5-Level Paging is disabled.
813
816
//
814
- if (! Page5LevelEnabled ) {
817
+ if (LevelOfPaging != 5 ) {
815
818
TotalPagesNum -- ;
816
819
}
817
820
@@ -831,7 +834,7 @@ CreateIdentityMappingPageTables (
831
834
// By architecture only one PageMapLevel4 exists - so lets allocate storage for it.
832
835
//
833
836
PageMap = (VOID * )BigPageAddress ;
834
- if (Page5LevelEnabled ) {
837
+ if (LevelOfPaging == 5 ) {
835
838
//
836
839
// By architecture only one PageMapLevel5 exists - so lets allocate storage for it.
837
840
//
@@ -853,7 +856,7 @@ CreateIdentityMappingPageTables (
853
856
PageMapLevel4Entry = (VOID * )BigPageAddress ;
854
857
BigPageAddress += SIZE_4KB ;
855
858
856
- if (Page5LevelEnabled ) {
859
+ if (LevelOfPaging == 5 ) {
857
860
//
858
861
// Make a PML5 Entry
859
862
//
@@ -947,7 +950,7 @@ CreateIdentityMappingPageTables (
947
950
ZeroMem (PageMapLevel4Entry , (512 - IndexOfPml4Entries ) * sizeof (PAGE_MAP_AND_DIRECTORY_POINTER ));
948
951
}
949
952
950
- if (Page5LevelEnabled ) {
953
+ if (LevelOfPaging == 5 ) {
951
954
Cr4 .UintN = AsmReadCr4 ();
952
955
Cr4 .Bits .LA57 = 1 ;
953
956
AsmWriteCr4 (Cr4 .UintN );
@@ -961,7 +964,7 @@ CreateIdentityMappingPageTables (
961
964
// Protect the page table by marking the memory used for page table to be
962
965
// read-only.
963
966
//
964
- EnablePageTableProtection ((UINTN )PageMap , TRUE );
967
+ EnablePageTableProtection ((UINTN )PageMap , LevelOfPaging );
965
968
966
969
//
967
970
// Set IA32_EFER.NXE if necessary.
0 commit comments