REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1907

Add a pcd named PcdRuntimeServicesSupport, RuntimeDxe driver would
set variable L"RuntimeServicesSupported" base on this pcd. The varialbe
would indicate whether the runtime services is supported or not in
runtime phase. If the pcd's value is 0x3FFF, that means all runtime
services is supported at runtime, then the variable wouldn't be set.
Refer to UEFI spec 2.8, Section 8.1.

Cc: Jian J Wang <jian.j.w...@intel.com>
Cc: Hao A Wu <hao.a...@intel.com>
Cc: Ray Ni <ray...@intel.com>
Cc: Star Zeng <star.z...@intel.com>
Cc: Liming gao <liming....@intel.com>
Cc: Sean Brogan <sean.bro...@microsoft.com>
Cc: Michael Turner <michael.tur...@microsoft.com>
Cc: Bret Barkelew <bret.barke...@microsoft.com>
Cc: Laszlo Ersek <ler...@redhat.com>
Signed-off-by: Zhichao Gao <zhichao....@intel.com>
---
 MdeModulePkg/Core/RuntimeDxe/Runtime.c      | 65 ++++++++++++++++++++-
 MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf |  8 ++-
 2 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Core/RuntimeDxe/Runtime.c 
b/MdeModulePkg/Core/RuntimeDxe/Runtime.c
index c52b2b7ecf..394baf230a 100644
--- a/MdeModulePkg/Core/RuntimeDxe/Runtime.c
+++ b/MdeModulePkg/Core/RuntimeDxe/Runtime.c
@@ -35,7 +35,7 @@ Revision History:
   Table now contains an item named CalculateCrc32.
 
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -359,6 +359,65 @@ RuntimeDriverSetVirtualAddressMap (
   return EFI_SUCCESS;
 }
 
+/**
+  Set the L"RuntimeServicesSupported" variable depend on the pcd 
PcdRuntimeServicesSupport.
+
+  Firstly try to get the variable, it may be set in other dxe driver. If it is 
set, then return
+  EFI_SUCCESS. If it isn't present, try to set it.
+
+  @retval EFI_SUCCESS       The variable is already set.
+          EFI_NOT_FOUND     All runtime services are supported at runtime. No 
variable is set.
+          Others            Error to get variable or set variable. Unexpected.
+**/
+static
+EFI_STATUS
+SetRuntimeServicesSupported (
+  VOID
+  )
+{
+  EFI_STATUS    Status;
+  UINT16        RuntimeServicesSupported;
+  UINT32        Attributes;
+  UINTN         DataSize;
+
+  //
+  // Firstly try to get L"RuntimeServicesSupported" variable
+  //
+  Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
+  DataSize = sizeof (UINT16);
+  Status = gRT->GetVariable (
+                  L"RuntimeServicesSupported",
+                  &gEfiGlobalVariableGuid,
+                  &Attributes,
+                  &DataSize,
+                  &RuntimeServicesSupported
+                  );
+
+  if (Status == EFI_NOT_FOUND) {
+    //
+    // L"RuntimeServicesSupported" isn't set yet. Then set it if
+    // some of the RuntimeServices is unsupported.
+    //
+    RuntimeServicesSupported = PcdGet16 (PcdRuntimeServicesSupport);
+    if (RuntimeServicesSupported != 0x3FFF) {
+      Status = gRT->SetVariable (
+                      L"RuntimeServicesSupported",
+                      &gEfiGlobalVariableGuid,
+                      EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
+                      sizeof (UINT16),
+                      &RuntimeServicesSupported
+                      );
+    } else {
+      //
+      // Set Status to EFI_NOT_FOUND to indicate not such variable
+      //
+      Status = EFI_NOT_FOUND;
+    }
+  }
+
+  return Status;
+}
+
 /**
   Entry Point for Runtime driver.
 
@@ -401,6 +460,10 @@ RuntimeDriverInitialize (
   gRT->SetVirtualAddressMap = RuntimeDriverSetVirtualAddressMap;
   gRT->ConvertPointer       = RuntimeDriverConvertPointer;
 
+  Status = SetRuntimeServicesSupported ();
+
+  ASSERT (Status == EFI_NOT_FOUND || Status == EFI_SUCCESS);
+
   //
   // Install the Runtime Architectural Protocol onto a new handle
   //
diff --git a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf 
b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
index 694c7690fa..48ecec9e99 100644
--- a/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+++ b/MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
@@ -5,7 +5,7 @@
 #  CalculateCrc32 boot services table, SetVirtualAddressMap & ConvertPointer
 #  runtime services table.
 #
-#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -53,6 +53,12 @@
   gEfiRuntimeArchProtocolGuid                   ## PRODUCES
   gEfiLoadedImageProtocolGuid                   ## CONSUMES
 
+[Guids]
+  gEfiGlobalVariableGuid                        ## SOMETIMES_CONSUMES   ## 
Variable L"RuntimeServicesSupported"
+
+[Pcd]
+  gEfiMdePkgTokenSpaceGuid.PcdRuntimeServicesSupport            ## 
SOME_TIMES_CONSUMES
+
 [depex]
   TRUE
 
-- 
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44031): https://edk2.groups.io/g/devel/message/44031
Mute This Topic: https://groups.io/mt/32524671/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to