Skip to content

Commit

Permalink
Support Standalone MM in ConfigKnobShimLib and Autogen (#183)
Browse files Browse the repository at this point in the history
# Preface

Please ensure you have read the [contribution
docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior
to submitting the pull request. In particular,
[pull request
guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices).

## Description

Add Standalone MM support to ConfigKnobShimLib and the autogenerated
headers so that standalone MM modules can use the configuration
interfaces provided by mu_feature_config.

This switches to using PolicyLib as the interface to policy code in the
autogenerated header and adds a standalone MM appropriate get variable
interface to ConfigKnobShimLib.

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [x] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [x] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Tested on a physical platform with standalone MM config knobs enabled.

## Integration Instructions

Follow the integration instructions inthe docs section of this
repository, ensuring there is a separate config XML for standalone MM.
  • Loading branch information
os-d authored May 23, 2023
1 parent 15110a8 commit 8b23409
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ Remove the FDF sections below.
# INF MdeModulePkg/Application/UiApp/UiApp.inf
```

### Standalone MM Configuration

This repository also supports configuration in standalone MM. The expectation is that a separate configuration XML is
used for standalone MM vs PEI/DXE, which produces separate autogenerated headers. All information in this document
is valid, but substitute the standalone MM modules (e.g. ConfigKnobShimLibStandaloneMm) in place of the PEI/DXE ones.

## Profiles Integration

In order to use configuration profiles, the platform must include the above changes as well as csv change files for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
GetConfigKnobFromVariable returns the configuration knob from variable storage if it exists. This function is
abstracted to work with both DXE and PEI.
abstracted to work with PEI, DXE, and Standalone MM.
This function is only expected to be called by GetConfigKnobOverride.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## @file
# Unit tests of the ConfigKnobShimExampleDxeLib instance.
# Unit tests of the ConfigKnobShimDxeLib instance.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010006
BASE_NAME = ConfigKnobShimExampleDxeUnitTest
BASE_NAME = ConfigKnobShimDxeUnitTest
FILE_GUID = 215C2769-14FA-448A-82F3-0B62D968CE84
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/**
GetConfigKnobFromVariable returns the configuration knob from variable storage if it exists. This function is
abstracted to work with both DXE and PEI.
abstracted to work with PEI, DXE, and Standalone MM.
This function is only expected to be called by GetConfigKnob, via the autogen header code for config knobs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/**
GetConfigKnobFromVariable returns the configuration knob from variable storage if it exists. This function is
abstracted to work with both DXE and PEI.
abstracted to work with PEI, DXE, and Standalone MM.
This function is only expected to be called by GetConfigKnobOverride.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## @file
# Unit tests of the ConfigKnobShimExamplePeiLib instance.
# Unit tests of the ConfigKnobShimPeiLib instance.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010006
BASE_NAME = ConfigKnobShimExamplePeiUnitTest
BASE_NAME = ConfigKnobShimPeiUnitTest
FILE_GUID = 94116449-0814-4312-9DF6-1DAE4408D1BC
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/** @file ConfigKnobShimStandaloneMmLib.c
Library interface for an OEM config policy creator to call into to fetch overrides for config values.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <PiPei.h>
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/MmServicesTableLib.h>
#include <Protocol/SmmVariable.h>

#include "../ConfigKnobShimLibCommon.h"

/**
GetConfigKnobFromVariable returns the configuration knob from variable storage if it exists. This function is
abstracted to work with PEI, DXE, and Standalone MM.
This function is only expected to be called by GetConfigKnobOverride.
@param[in] ConfigKnobGuid The GUID of the requested config knob.
@param[in] ConfigKnobName The name of the requested config knob.
@param[out] ConfigKnobData The retrieved data of the requested config knob. The caller will allocate memory for
this buffer and is responsible for freeing it. This parameter is acceptable to be
NULL if the data size is all that is requested.
@param[in out] ConfigKnobDataSize The allocated size of ConfigKnobData. This is expected to be set to the correct
value for the size of ConfigKnobData. If this size is too small for the config knob,
EFI_BUFFER_TOO_SMALL will be returned. This represents a mismatch in the profile
expected size and what is stored in variable storage, so the profile value will
take precedence.
@retval EFI_NOT_FOUND The requested config knob was not found in the policy cache or variable storage. This
is expected when the config knob has not been updated from the profile default.
@retval EFI_BUFFER_TOO_SMALL ConfigKnobDataSize as passed in was too small for this config knob. This is expected
if stale variables exist in flash.
@retval EFI_NOT_READY Variable Services not available.
@retval !EFI_SUCCESS Failed to read variable from variable storage.
@retval EFI_SUCCESS The operation succeeds.
**/
EFI_STATUS
GetConfigKnobFromVariable (
IN EFI_GUID *ConfigKnobGuid,
IN CHAR16 *ConfigKnobName,
OUT VOID *ConfigKnobData,
IN OUT UINTN *ConfigKnobDataSize
)
{
EFI_STATUS Status;
EFI_SMM_VARIABLE_PROTOCOL *MmVariableServices;

Status = gMmst->MmLocateProtocol (
&gEfiSmmVariableProtocolGuid,
NULL,
(VOID **)&MmVariableServices
);

if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
"%a: Failed to locate variable services with status %r, falling back to profile value for config knob %a\n",
__FUNCTION__,
Status,
ConfigKnobName
));

return Status;
}

return MmVariableServices->SmmGetVariable (
ConfigKnobName,
ConfigKnobGuid,
NULL,
ConfigKnobDataSize,
ConfigKnobData
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## @file
# Library interface for an OEM config policy creator to call into to fetch overrides for config values.
#
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010017
BASE_NAME = ConfigKnobShimStandaloneMmLib
FILE_GUID = 675EE92E-8771-413A-8BBE-B87152B910E2
VERSION_STRING = 1.0
MODULE_TYPE = MM_STANDALONE
LIBRARY_CLASS = ConfigKnobShimLib
PI_SPECIFICATION_VERSION = 0x00010032

#
# The following information is for reference only and not required by the
# build tools.
#
# VALID_ARCHITECTURES = IA32 X64 AARCH64
#

[Sources]
ConfigKnobShimStandaloneMmLib.c
../ConfigKnobShimLibCommon.c
../ConfigKnobShimLibCommon.h

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
SetupDataPkg/SetupDataPkg.dec

[LibraryClasses]
BaseLib
DebugLib
BaseMemoryLib
MmServicesTableLib

[Protocols]
gEfiSmmVariableProtocolGuid ## CONSUMES

[Depex]
# Platforms can decide whether variable services are a requirement for config or not
gEfiSmmVariableProtocolGuid
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## @file
# Unit tests of the ConfigKnobShimExampleStandaloneMmLib instance.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010017
BASE_NAME = ConfigKnobShimStandaloneMmUnitTest
FILE_GUID = EA4B9417-78FC-474E-AC35-44AFF09E9099
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 AARCH64
#

[Sources]
../../UnitTest/ConfigKnobShimLibUnitTestCommon.c
../ConfigKnobShimStandaloneMmLib.c
../../ConfigKnobShimLibCommon.c

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
SetupDataPkg/SetupDataPkg.dec

[LibraryClasses]
BaseLib
BaseMemoryLib
DebugLib
MmServicesTableLib
UnitTestLib

[Protocols]
gEfiSmmVariableProtocolGuid ## CONSUMES
Loading

0 comments on commit 8b23409

Please sign in to comment.