[edk2-devel] [PATCH V2 3/4] MdeModulePkg/RuntimeDxe: Set RuntimeServicesSupport base on Pcd

Michael D Kinney michael.d.kinney at intel.com
Fri Jul 19 16:01:54 UTC 2019


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 at edk2.groups.io [mailto:devel at edk2.groups.io]
> On Behalf Of Gao, Zhichao
> Sent: Friday, July 19, 2019 1:09 AM
> To: devel at edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang at intel.com>; Wu, Hao A
> <hao.a.wu at intel.com>; Ni, Ray <ray.ni at intel.com>; Zeng,
> Star <star.zeng at intel.com>; Gao, Liming
> <liming.gao at intel.com>; Sean Brogan
> <sean.brogan at microsoft.com>; Michael Turner
> <Michael.Turner at microsoft.com>; Bret Barkelew
> <Bret.Barkelew at microsoft.com>; Laszlo Ersek
> <lersek at redhat.com>
> Subject: [edk2-devel] [PATCH V2 3/4]
> MdeModulePkg/RuntimeDxe: Set RuntimeServicesSupport base
> on Pcd
> 
> 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.wang at intel.com>
> Cc: Hao A Wu <hao.a.wu at intel.com>
> Cc: Ray Ni <ray.ni at intel.com>
> Cc: Star Zeng <star.zeng at intel.com>
> Cc: Liming gao <liming.gao at intel.com>
> Cc: Sean Brogan <sean.brogan at microsoft.com>
> Cc: Michael Turner <Michael.Turner at microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew at microsoft.com>
> Cc: Laszlo Ersek <lersek at redhat.com>
> Signed-off-by: Zhichao Gao <zhichao.gao at 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 (#44052): https://edk2.groups.io/g/devel/message/44052
Mute This Topic: https://groups.io/mt/32524671/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list