Skip to content

Commit adb5480

Browse files
authored
Merge branch 'master' into fix_redundant_condition_in_DynamicTablesPkg
2 parents 366914c + 6c6d4d2 commit adb5480

File tree

7 files changed

+136
-12
lines changed

7 files changed

+136
-12
lines changed

ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ GetRootTranslationTableInfo (
4848
OUT UINTN *RootTableEntryCount
4949
)
5050
{
51-
*RootTableLevel = (INTN)(T0SZ - MIN_T0SZ) / BITS_PER_LEVEL;
51+
*RootTableLevel = (T0SZ < MIN_T0SZ) ? -1 : (INTN)(T0SZ - MIN_T0SZ) / BITS_PER_LEVEL;
52+
ASSERT (*RootTableLevel >= 0 || ArmLpa2Enabled ());
5253
*RootTableEntryCount = TT_ENTRY_COUNT >> (INTN)(T0SZ - MIN_T0SZ) % BITS_PER_LEVEL;
5354
}
5455

@@ -241,7 +242,7 @@ GetNextEntryAttribute (
241242

242243
// Increase the level number and scan the sub-level table
243244
GetNextEntryAttribute (
244-
(UINT64 *)GetOutputAddress (Entry, ArmGetTCR () & TCR_DS),
245+
(UINT64 *)GetOutputAddress (Entry, ArmLpa2Enabled ()),
245246
TT_ENTRY_COUNT,
246247
TableLevel + 1,
247248
(BaseAddress + (Index * TT_ADDRESS_AT_LEVEL (TableLevel))),
@@ -329,7 +330,7 @@ SyncCacheConfig (
329330
GetRootTranslationTableInfo (T0SZ, &TableLevel, &TableCount);
330331

331332
// First Attribute of the Page Tables
332-
PageAttribute = GetFirstPageAttribute (FirstLevelTableAddress, TableLevel, ArmGetTCR () & TCR_DS);
333+
PageAttribute = GetFirstPageAttribute (FirstLevelTableAddress, TableLevel, ArmLpa2Enabled ());
333334

334335
// We scan from the start of the memory map (ie: at the address 0x0)
335336
BaseAddressGcdRegion = 0x0;
@@ -458,7 +459,7 @@ GetMemoryRegionRec (
458459
EntryType = *BlockEntry & TT_TYPE_MASK;
459460

460461
if ((TableLevel < 3) && (EntryType == TT_TYPE_TABLE_ENTRY)) {
461-
NextTranslationTable = (UINT64 *)GetOutputAddress (*BlockEntry, ArmGetTCR () & TCR_DS);
462+
NextTranslationTable = (UINT64 *)GetOutputAddress (*BlockEntry, ArmLpa2Enabled ());
462463

463464
// The entry is a page table, so we go to the next level
464465
Status = GetMemoryRegionRec (

MdePkg/Include/AArch64/AArch64Mmu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
#define TTBR_ASID_MASK (0xFF << TTBR_ASID_FIELD)
130130
#define TTBR_BADDR_MASK (0xFFFFFFFFFFFF ) // The width of this field depends on the values in TxSZ. Addr occupies bottom 48bits
131131

132-
#define TCR_DS (1UL << 59)
132+
#define TCR_DS (1UL << 59)
133+
#define TCR_DS_NVHE (1UL << 32)
133134

134135
#define TCR_EL1_T0SZ_FIELD (0)
135136
#define TCR_EL1_EPD0_FIELD (7)

MdePkg/Include/IndustryStandard/Pci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
99
#ifndef _PCI_H_
1010
#define _PCI_H_
1111

12-
#include <IndustryStandard/PciExpress60.h>
12+
#include <IndustryStandard/PciExpress70.h>
1313
#include <IndustryStandard/PciCodeId.h>
1414

1515
#endif

MdePkg/Include/IndustryStandard/PciExpress21.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ typedef union {
348348
UINT32 LowerSkpOsReception : 7;
349349
UINT32 RetimerPresenceDetect : 1;
350350
UINT32 TwoRetimersPresenceDetect : 1;
351-
UINT32 Reserved2 : 6;
351+
UINT32 FRAPresenceDetect : 1;
352+
UINT32 Reserved2 : 5;
352353
UINT32 DrsSupported : 1;
353354
} Bits;
354355
UINT32 Uint32;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/** @file
2+
Support for the PCI Express 7.0 standard.
3+
4+
This header file may not define all structures. Please extend as required.
5+
6+
Copyright (c) 2025, American Megatrends International LLC. All rights reserved.<BR>
7+
SPDX-License-Identifier: BSD-2-Clause-Patent
8+
9+
**/
10+
11+
#ifndef PCIEXPRESS70_H_
12+
#define PCIEXPRESS70_H_
13+
14+
#include <IndustryStandard/PciExpress60.h>
15+
16+
/// The Physical Layer PCI Express Extended Capability definitions.
17+
///
18+
/// Based on section 7.7.8 of PCI Express Base Specification 7.0
19+
///@{
20+
#define PCI_EXPRESS_EXTENDED_CAPABILITY_PHYSICAL_LAYER_128_0_ID 0x0039
21+
#define PCI_EXPRESS_EXTENDED_CAPABILITY_PHYSICAL_LAYER_128_0_VER1 0x1
22+
23+
// Register offsets from Physical Layer PCI-E Ext Cap Header
24+
#define PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_CAPABILITIES_OFFSET 0x04
25+
#define PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_CONTROL_OFFSET 0x08
26+
#define PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_STATUS_OFFSET 0x0C
27+
#define PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_LANE_EQUALIZATION_CONTROL_OFFSET 0x10
28+
29+
#pragma pack(1)
30+
31+
typedef union {
32+
struct {
33+
UINT32 SupportedLinkSpeedsVector2 : 8; // bits 0..7
34+
UINT32 LowerSkpOsGenLnkSpeedsVect2 : 8; // bits 8..15
35+
UINT32 LowerSkpOsRecLnkSpeedsVect2 : 8; // bits 16..23
36+
UINT32 Reserved : 8; // bits 24..31
37+
} Bits;
38+
UINT32 Uint32;
39+
} PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_CAPABILITIES;
40+
41+
typedef union {
42+
struct {
43+
UINT32 Reserved : 32; // Reserved bit 0:31
44+
} Bits;
45+
UINT32 Uint32;
46+
} PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_CONTROL;
47+
48+
typedef union {
49+
struct {
50+
UINT32 EqualizationComplete : 1; // bit 0
51+
UINT32 EqualizationPhase1Success : 1; // bit 1
52+
UINT32 EqualizationPhase2Success : 1; // bit 2
53+
UINT32 EqualizationPhase3Success : 1; // bit 3
54+
UINT32 LinkEqualizationRequest : 1; // bit 4
55+
UINT32 TransmitterPrecodingOn : 1; // bit 5
56+
UINT32 TransmitterPrecodeRequest : 1; // bit 6
57+
UINT32 NoEqualizationNeededRcvd : 1; // bit 7
58+
UINT32 Reserved : 24; // Reserved bit 8:31
59+
} Bits;
60+
UINT32 Uint32;
61+
} PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_STATUS;
62+
63+
typedef union {
64+
struct {
65+
UINT8 DownstreamPortTransmitterPreset : 4; // bit 0..3
66+
UINT8 UpstreamPortTransmitterPreset : 4; // bit 4..7
67+
} Bits;
68+
UINT8 Uint8;
69+
} PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_LANE_EQUALIZATION_CONTROL;
70+
71+
typedef struct {
72+
PCI_EXPRESS_EXTENDED_CAPABILITIES_HEADER Header;
73+
PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_CAPABILITIES Capablities;
74+
PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_CONTROL Control;
75+
PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_STATUS Status;
76+
PCI_EXPRESS_REG_PHYSICAL_LAYER_128_0_LANE_EQUALIZATION_CONTROL LaneEqualizationControl[1];
77+
} PCI_EXPRESS_EXTENDED_CAPABILITIES_PHYSICAL_LAYER_128_0;
78+
///@}
79+
80+
#pragma pack()
81+
82+
#endif

UefiCpuPkg/Include/Library/ArmMmuLib.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,17 @@ ArmSetMemoryAttributes (
7171
IN UINT64 AttributeMask
7272
);
7373

74+
/**
75+
Check whether a 52-bit output address can be described
76+
by the translation tables (FEAT_LPA2).
77+
78+
@retval TRUE 52-bit output address is enabled (LPA2 enabled).
79+
@retval FALSE 52-bit output address is disabled (LPA2 disabled).
80+
81+
**/
82+
BOOLEAN
83+
ArmLpa2Enabled (
84+
VOID
85+
);
86+
7487
#endif // ARM_MMU_LIB_H_

UefiCpuPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ GetRootTableLevel (
142142
IN UINTN T0SZ
143143
)
144144
{
145-
return (INTN)(T0SZ - MIN_T0SZ) / BITS_PER_LEVEL;
145+
INTN RootTableLevel;
146+
147+
RootTableLevel = (T0SZ < MIN_T0SZ) ? -1 : (INTN)(T0SZ - MIN_T0SZ) / BITS_PER_LEVEL;
148+
ASSERT (RootTableLevel >= 0 || ArmLpa2Enabled ());
149+
150+
return RootTableLevel;
146151
}
147152

148153
STATIC
@@ -306,7 +311,7 @@ UpdateRegionMappingRecursive (
306311
// the MMU in order to update page table entries safely, so prefer page
307312
// mappings in that particular case.
308313
//
309-
if ((Level == 0) || (((RegionStart | BlockEnd) & BlockMask) != 0) ||
314+
if ((Level <= 0) || (((RegionStart | BlockEnd) & BlockMask) != 0) ||
310315
((Level < 3) && (((UINT64)PageTable & ~BlockMask) == RegionStart)) ||
311316
IsTableEntry (*Entry, Level))
312317
{
@@ -616,7 +621,7 @@ ArmSetMemoryAttributes (
616621
PageAttributeMask,
617622
ArmGetTTBR0BaseAddress (),
618623
TRUE,
619-
ArmGetTCR () & TCR_DS
624+
ArmLpa2Enabled ()
620625
);
621626
}
622627

@@ -680,7 +685,7 @@ ArmConfigureMmu (
680685
} else if (MaxAddress < SIZE_256TB) {
681686
TCR |= TCR_PS_256TB;
682687
} else if ((MaxAddress < SIZE_4PB) && ArmHas52BitTgran4 ()) {
683-
TCR |= TCR_PS_4PB | TCR_DS;
688+
TCR |= TCR_PS_4PB | TCR_DS_NVHE;
684689
} else {
685690
DEBUG ((
686691
DEBUG_ERROR,
@@ -764,7 +769,7 @@ ArmConfigureMmu (
764769
ZeroMem (TranslationTable, RootTableEntryCount * sizeof (UINT64));
765770

766771
while (MemoryTable->Length != 0) {
767-
Status = FillTranslationTable (TranslationTable, MemoryTable, TCR & TCR_DS);
772+
Status = FillTranslationTable (TranslationTable, MemoryTable, ArmLpa2Enabled ());
768773
if (EFI_ERROR (Status)) {
769774
goto FreeTranslationTable;
770775
}
@@ -811,6 +816,27 @@ ArmConfigureMmu (
811816
return Status;
812817
}
813818

819+
/**
820+
Check whether a 52-bit output address can be described
821+
by the translation tables (FEAT_LPA2).
822+
@retval TRUE 52-bit output address is enabled (LPA2 enabled).
823+
@retval FALSE 52-bit output address is disabled (LPA2 disabled).
824+
825+
**/
826+
BOOLEAN
827+
ArmLpa2Enabled (
828+
VOID
829+
)
830+
{
831+
UINT64 TCR;
832+
833+
TCR = ArmGetTCR ();
834+
835+
return !TranslationRegimeIsDual () ?
836+
((TCR & TCR_DS_NVHE) != 0) :
837+
((TCR & TCR_DS) != 0);
838+
}
839+
814840
RETURN_STATUS
815841
EFIAPI
816842
ArmMmuBaseLibConstructor (

0 commit comments

Comments
 (0)