Skip to content

Commit 3bb1f83

Browse files
committed
ArmVirtPkg/ArmCcaLib: Use GUID HOB to cache IsRealm value
When run early in the QEMU boot, writing the static variable FlagsInitialised causes a Synchronous Exception. Supposedly the data page containing the static variable isn't mapped writable at this point, but I didn't investigate further. Use a GUID HOB to cache the variable. Signed-off-by: Jean-Philippe Brucker <[email protected]>
1 parent 805a74d commit 3bb1f83

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

ArmVirtPkg/ArmVirtPkg.dec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
gEarly16550UartBaseAddressGuid = { 0xea67ca3e, 0x1f54, 0x436b, { 0x97, 0x88, 0xd4, 0xeb, 0x29, 0xc3, 0x42, 0x67 } }
3838
gArmVirtSystemMemorySizeGuid = { 0x504eccb9, 0x1bf0, 0x4420, { 0x86, 0x5d, 0xdc, 0x66, 0x06, 0xd4, 0x13, 0xbf } }
3939
gArmCcaIpaWidthGuid = { 0xbdb66787, 0xfc8a, 0x412e, { 0xa0, 0x9b, 0x84, 0x96, 0x61, 0x81, 0x72, 0xc0 } }
40+
gArmCcaIsRealmGuid = { 0x0b3bbff3, 0xed27, 0x4228, { 0xa2, 0x99, 0x8e, 0xd5, 0x14, 0xfb, 0xa2, 0x94 } }
4041

4142
[PcdsFeatureFlag]
4243
#

ArmVirtPkg/Library/ArmCcaLib/ArmCcaLib.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <Library/ArmCcaRsiLib.h>
1616
#include <Library/ArmMmuLib.h>
1717
#include <Library/BaseLib.h>
18+
#include <Library/DebugLib.h>
1819

1920
#include <Uefi/UefiMultiPhase.h>
2021
#include <Uefi/UefiSpec.h>
@@ -38,11 +39,12 @@ IsRealm (
3839
UINT32 UefiImpl;
3940
UINT32 RmmImplLow;
4041
UINT32 RmmImplHigh;
41-
STATIC BOOLEAN RealmWorld = FALSE;
42-
STATIC BOOLEAN FlagsInitialised = FALSE;
42+
VOID *Hob;
43+
UINT64 *IsRealmHobData;
44+
BOOLEAN RealmWorld = FALSE;
4345

44-
if (!FlagsInitialised) {
45-
FlagsInitialised = TRUE;
46+
Hob = GetFirstGuidHob (&gArmCcaIsRealmGuid);
47+
if (Hob == NULL) {
4648
if (ArmHasRme ()) {
4749
Status = RsiGetVersion (
4850
&UefiImpl,
@@ -53,9 +55,26 @@ IsRealm (
5355
RealmWorld = TRUE;
5456
}
5557
}
58+
59+
IsRealmHobData = BuildGuidHob (&gArmCcaIsRealmGuid,
60+
sizeof (*IsRealmHobData));
61+
ASSERT (IsRealmHobData != NULL);
62+
if (IsRealmHobData == NULL) {
63+
return FALSE;
64+
}
65+
*IsRealmHobData = RealmWorld;
66+
67+
Hob = GetFirstGuidHob (&gArmCcaIsRealmGuid);
68+
69+
} else {
70+
if (GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (*IsRealmHobData)) {
71+
ASSERT (0);
72+
return FALSE;
73+
}
74+
IsRealmHobData = GET_GUID_HOB_DATA (Hob);
5675
}
5776

58-
return RealmWorld;
77+
return *IsRealmHobData;
5978
}
6079

6180
/**

ArmVirtPkg/Library/ArmCcaLib/ArmCcaLib.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232

3333
[Guids]
3434
gArmCcaIpaWidthGuid
35+
gArmCcaIsRealmGuid

0 commit comments

Comments
 (0)