From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: zhichao.gao@intel.com) Received: from mga04.intel.com (mga04.intel.com []) by groups.io with SMTP; Fri, 19 Jul 2019 01:09:55 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2019 01:09:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,281,1559545200"; d="scan'208";a="187951065" Received: from fieedk001.ccr.corp.intel.com ([10.239.33.119]) by fmsmga001.fm.intel.com with ESMTP; 19 Jul 2019 01:09:54 -0700 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Ray Ni , Star Zeng , Liming gao , Sean Brogan , Michael Turner , Bret Barkelew , Laszlo Ersek Subject: [PATCH V2 3/4] MdeModulePkg/RuntimeDxe: Set RuntimeServicesSupport base on Pcd Date: Fri, 19 Jul 2019 16:09:20 +0800 Message-Id: <20190719080921.17516-4-zhichao.gao@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190719080921.17516-1-zhichao.gao@intel.com> References: <20190719080921.17516-1-zhichao.gao@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Hao A Wu Cc: Ray Ni Cc: Star Zeng Cc: Liming gao Cc: Sean Brogan Cc: Michael Turner Cc: Bret Barkelew Cc: Laszlo Ersek Signed-off-by: Zhichao Gao --- 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.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
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.
+# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
# # 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