From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: michael.d.kinney@intel.com) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by groups.io with SMTP; Fri, 19 Jul 2019 09:01:56 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2019 09:01:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,283,1559545200"; d="scan'208";a="170938234" Received: from orsmsx105.amr.corp.intel.com ([10.22.225.132]) by orsmga003.jf.intel.com with ESMTP; 19 Jul 2019 09:01:55 -0700 Received: from orsmsx156.amr.corp.intel.com (10.22.240.22) by ORSMSX105.amr.corp.intel.com (10.22.225.132) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 19 Jul 2019 09:01:54 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.128]) by ORSMSX156.amr.corp.intel.com ([169.254.8.199]) with mapi id 14.03.0439.000; Fri, 19 Jul 2019 09:01:54 -0700 From: "Michael D Kinney" To: "devel@edk2.groups.io" , "Gao, Zhichao" , "Kinney, Michael D" , "Rothman, Michael A" CC: "Wang, Jian J" , "Wu, Hao A" , "Ni, Ray" , "Zeng, Star" , "Gao, Liming" , Sean Brogan , Michael Turner , Bret Barkelew , Laszlo Ersek Subject: Re: [edk2-devel] [PATCH V2 3/4] MdeModulePkg/RuntimeDxe: Set RuntimeServicesSupport base on Pcd Thread-Topic: [edk2-devel] [PATCH V2 3/4] MdeModulePkg/RuntimeDxe: Set RuntimeServicesSupport base on Pcd Thread-Index: AQHVPgleyUZYqaxcw0GRuJHDkb00F6bSGRnA Date: Fri, 19 Jul 2019 16:01:54 +0000 Message-ID: References: <20190719080921.17516-1-zhichao.gao@intel.com> <20190719080921.17516-4-zhichao.gao@intel.com> In-Reply-To: <20190719080921.17516-4-zhichao.gao@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Return-Path: michael.d.kinney@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Zhichao, I realized that MdeModulePkg/Core/RuntimeDxe may not be the best place to set this variable. This module has a depex of TRUE, so there is no guarantee that the variable services are available when this module is dispatched. This new variable is only intended to be consumed by OS Loaders and OS Kernels, so the latest time that this variable can be set is Ready To Boot in BDS. All UEFI Services are available when gBds->Entry() is called from the DXE Core, so maybe the best place to set this new variable is in gBds->Entry(). Thanks, Mike > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] > On Behalf Of Gao, Zhichao > Sent: Friday, July 19, 2019 1:09 AM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Wu, Hao A > ; Ni, Ray ; Zeng, > Star ; Gao, Liming > ; Sean Brogan > ; Michael Turner > ; Bret Barkelew > ; Laszlo Ersek > > Subject: [edk2-devel] [PATCH V2 3/4] > MdeModulePkg/RuntimeDxe: Set RuntimeServicesSupport base > on Pcd >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1907 >=20 > 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. >=20 > 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(-) >=20 > 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. >=20 >=20 > -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 >=20 > **/ > @@ -359,6 +359,65 @@ RuntimeDriverSetVirtualAddressMap ( > return EFI_SUCCESS; > } >=20 > +/** > + 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 =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | > + EFI_VARIABLE_RUNTIME_ACCESS; DataSize =3D sizeof > (UINT16); Status =3D > + gRT->GetVariable ( > + L"RuntimeServicesSupported", > + &gEfiGlobalVariableGuid, > + &Attributes, > + &DataSize, > + &RuntimeServicesSupported > + ); > + > + if (Status =3D=3D EFI_NOT_FOUND) { > + // > + // L"RuntimeServicesSupported" isn't set yet. Then > set it if > + // some of the RuntimeServices is unsupported. > + // > + RuntimeServicesSupported =3D PcdGet16 > (PcdRuntimeServicesSupport); > + if (RuntimeServicesSupported !=3D 0x3FFF) { > + Status =3D 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 =3D EFI_NOT_FOUND; > + } > + } > + > + return Status; > +} > + > /** > Entry Point for Runtime driver. >=20 > @@ -401,6 +460,10 @@ RuntimeDriverInitialize ( > gRT->SetVirtualAddressMap =3D > RuntimeDriverSetVirtualAddressMap; > gRT->ConvertPointer =3D > RuntimeDriverConvertPointer; >=20 > + Status =3D SetRuntimeServicesSupported (); > + > + ASSERT (Status =3D=3D EFI_NOT_FOUND || Status =3D=3D > 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 >=20 > +[Guids] > + gEfiGlobalVariableGuid ## > SOMETIMES_CONSUMES ## Variable > L"RuntimeServicesSupported" > + > +[Pcd] > + gEfiMdePkgTokenSpaceGuid.PcdRuntimeServicesSupport > ## SOME_TIMES_CONSUMES > + > [depex] > TRUE >=20 > -- > 2.21.0.windows.1 >=20 >=20 >=20