IsRealm() probes to check if the code is executing
in a Realm context by checking if RME is supported
and then issuing a RSI_VERSION command to check it
is supported.

Instead of calling RSI_VERSION command every time the
IsRealm() is called, cache the world value we are
running in, to return the value in subsequent calls.

Cc: Ard Biesheuvel <ardb+tianoc...@kernel.org>
Cc: Leif Lindholm <quic_llind...@quicinc.com>
Cc: Gerd Hoffmann <kra...@redhat.com>
Signed-off-by: Sami Mujawar <sami.muja...@arm.com>
---
 ArmVirtPkg/Library/ArmCcaLib/ArmCcaLib.c | 31 ++++++++++++--------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/ArmVirtPkg/Library/ArmCcaLib/ArmCcaLib.c 
b/ArmVirtPkg/Library/ArmCcaLib/ArmCcaLib.c
index 
3abb4dfaf567c635b28ff3a7cd5adea064e02510..67ad2824f1f6a8fe4e1fd3f837300097a68775c7
 100644
--- a/ArmVirtPkg/Library/ArmCcaLib/ArmCcaLib.c
+++ b/ArmVirtPkg/Library/ArmCcaLib/ArmCcaLib.c
@@ -35,23 +35,28 @@ IsRealm (
   VOID
   )
 {
-  RETURN_STATUS  Status;
-  UINT32         UefiImpl;
-  UINT32         RmmImplLow;
-  UINT32         RmmImplHigh;
+  RETURN_STATUS   Status;
+  UINT32          UefiImpl;
+  UINT32          RmmImplLow;
+  UINT32          RmmImplHigh;
+  STATIC BOOLEAN  RealmWorld       = FALSE;
+  STATIC BOOLEAN  FlagsInitialised = FALSE;
 
-  if (ArmHasRme ()) {
-    Status = RsiGetVersion (
-               &UefiImpl,
-               &RmmImplLow,
-               &RmmImplHigh
-               );
-    if (!RETURN_ERROR (Status)) {
-      return TRUE;
+  if (!FlagsInitialised) {
+    FlagsInitialised = TRUE;
+    if (ArmHasRme ()) {
+      Status = RsiGetVersion (
+                 &UefiImpl,
+                 &RmmImplLow,
+                 &RmmImplHigh
+                 );
+      if (!RETURN_ERROR (Status)) {
+        RealmWorld = TRUE;
+      }
     }
   }
 
-  return FALSE;
+  return RealmWorld;
 }
 
 /**
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117714): https://edk2.groups.io/g/devel/message/117714
Mute This Topic: https://groups.io/mt/105484265/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to