Skip to content

Commit

Permalink
Remove the data library and introduce the metadata policy (#109)
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

This change pairs with the latest update from mu_feature_config, where
it starts to host the data library definition.

The configuration policy creator module is also updated to consume the
newly created `gProfileFlavorNames` to demonstrate the usage of such
data.

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, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] 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

This was tested on QEMU Q35 and SBSA platforms.

## Integration Instructions

N/A
  • Loading branch information
kuqin12 committed Jun 22, 2023
1 parent 59c3267 commit e916e31
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 95 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BuildConfig.conf

# Ignore cloned dependencies
/Common
/Features
/Silicon
/MU_BASECORE

Expand Down
4 changes: 2 additions & 2 deletions .pytool/CISettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ def GetDependencies(self):
"Branch": "release/202302"
},
{
"Path": "MU_FEATURE_DFCI",
"Path": "Features/MU_FEATURE_DFCI",
"Url": "https://github.com/microsoft/mu_feature_dfci.git",
"Branch": "main"
},
{
"Path": "MU_FEATURE_CONFIG",
"Path": "Features/MU_FEATURE_CONFIG",
"Url": "https://github.com/microsoft/mu_feature_config.git",
"Branch": "main"
}
Expand Down
33 changes: 33 additions & 0 deletions OemPkg/Include/Guid/OemConfigMetadataPolicy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @file
This file defines GUIDs and data structures for the OEM Config Metadata Policy.
Copyright (c) Microsoft Corporation.
**/

#include <Uefi.h>

#ifndef OEM_CONFIG_METADATA_POLICY_H_
#define OEM_CONFIG_METADATA_POLICY_H_

#define OEM_CONFIG_METADATA_POLICY_GUID \
{ \
0X44E9778F, 0X3DAF, 0X46BA, { 0XB1, 0X86, 0X78, 0X4D, 0X0B, 0X05, 0X50, 0X72 } \
}

#define OEM_CONFIG_METADATA_POLICY_SIZE sizeof(OEM_CONFIG_METADATA_POLICY)

#define GENERIC_PROFILE_FLAVOR_NAME "GN"

#pragma pack(1)

typedef struct {
UINT32 ActiveProfileIndex;
CHAR8 ActiveProfileFlavorName[PROFILE_FLAVOR_NAME_LENGTH];
} OEM_CONFIG_METADATA_POLICY;

#pragma pack()

extern EFI_GUID gOemConfigMetadataPolicyGuid;

#endif // OEM_CONFIG_METADATA_POLICY_H_

This file was deleted.

This file was deleted.

106 changes: 66 additions & 40 deletions OemPkg/OemConfigPolicyCreatorPei/OemConfigPolicyCreatorPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,34 @@
**/

#include <Uefi.h>
#include <ConfigStdStructDefs.h>

#include <Ppi/Policy.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Guid/VariableFormat.h>
#include <Guid/OemConfigMetadataPolicy.h>
#include <Library/ConfigVariableListLib.h>
#include <Library/ConfigKnobShimLib.h>
#include <Library/SafeIntLib.h>
#include <Library/PolicyLib.h>
#include <Library/ActiveProfileIndexSelectorLib.h>
#include <ConfigStdStructDefs.h>

// these externs are provided by PlatformConfigDataLib
extern KNOB_DATA gKnobData[];
extern UINTN gNumKnobs;
// number of profile overrides (i.e. into gProfileData)
// this does not count the generic profile, which is not
// in gProfileData, but rather in gKnobData's defaults
extern UINTN gNumProfiles;
extern PROFILE gProfileData[];
#include <Library/PlatformConfigDataLib.h>

/**
Helper function to apply profile overrides. This function is only
called if the active profile index has been validated to be within
the acceptable range.
@param[in] ActiveProfileIndex The validated index into gProfileData
@retval EFI_SUCCESS Successfully applied the input profile index
@retval !EFI_SUCCESS Failed to apply the input profile index, applied generic profile instead
**/
STATIC
VOID
EFI_STATUS
ApplyProfileOverrides (
UINT32 ActiveProfileIndex
)
Expand All @@ -62,6 +59,10 @@ ApplyProfileOverrides (
// write the default value for each knob we may have passed to its cache address so we can
// have a clean generic profile. We didn't apply the knob for this value of i, so decrement
// before we start
if (i == 0) {
return EFI_INVALID_PARAMETER;
}

i--;
for ( ; i > 0; i--) {
Knob = ActiveProfile->Overrides[i].Knob;
Expand All @@ -74,11 +75,13 @@ ApplyProfileOverrides (
CopyMem (gKnobData[Knob].CacheValueAddress, gKnobData[Knob].DefaultValueAddress, gKnobData[Knob].ValueSize);

ASSERT (FALSE);
return;
return EFI_INVALID_PARAMETER;
}

CopyMem (gKnobData[Knob].CacheValueAddress, ActiveProfile->Overrides[i].Value, gKnobData[Knob].ValueSize);
}

return EFI_SUCCESS;
}

/**
Expand All @@ -100,17 +103,19 @@ CreateConfPolicy (
OUT UINT16 *ConfPolicySize
)
{
EFI_STATUS Status;
UINT32 i;
UINT32 NeededSize = 0;
UINT32 Offset = 0;
CHAR16 UnicodeName[CONF_VAR_NAME_LEN]; // get a buffer of the max name size
CONFIG_VAR_LIST_ENTRY VarListEntry;
UINTN VarListSize;
VOID *ConfListPtr;
UINT32 UnicodeNameSize;
UINT32 TmpNeededSize;
UINT32 ActiveProfileIndex;
EFI_STATUS Status;
UINT32 i;
UINT32 NeededSize = 0;
UINT32 Offset = 0;
CHAR16 UnicodeName[CONF_VAR_NAME_LEN]; // get a buffer of the max name size
CONFIG_VAR_LIST_ENTRY VarListEntry;
UINTN VarListSize;
VOID *ConfListPtr;
UINT32 UnicodeNameSize;
UINT32 TmpNeededSize;
UINT32 ActiveProfileIndex;
OEM_CONFIG_METADATA_POLICY ConfigMetadata;
CHAR8 *ProfileName;

// first figure out how much space we need to allocate for the ConfPolicy
for (i = 0; i < gNumKnobs; i++) {
Expand Down Expand Up @@ -169,22 +174,27 @@ CreateConfPolicy (
if (EFI_ERROR (Status)) {
// if we fail to get the active profile index, default to the generic profile
DEBUG ((DEBUG_ERROR, "%a failed to get active profile index! Defaulting to generic profile\n", __FUNCTION__));
ActiveProfileIndex = MAX_UINT32;
ActiveProfileIndex = GENERIC_PROFILE_INDEX;
}

if ((ActiveProfileIndex >= 0) && (ActiveProfileIndex < gNumProfiles)) {
// if ActiveProfileIndex == MAX_UINT32, we are using the generic profile and don't
// if ActiveProfileIndex == GENERIC_PROFILE_INDEX, we are using the generic profile and don't
// look for any profile overrides. Otherwise, ensure that the active profile index
// is valid, otherwise use the generic profile. If it is valid, apply those overrides.
ApplyProfileOverrides (ActiveProfileIndex);
} else if (ActiveProfileIndex != MAX_UINT32) {
Status = ApplyProfileOverrides (ActiveProfileIndex);
if (EFI_ERROR (Status)) {
// if we failed to apply the profile, we defaulted to the generic profile
// mark that here so we report it in the config metadata policy
ActiveProfileIndex = GENERIC_PROFILE_INDEX;
}
} else if (ActiveProfileIndex != GENERIC_PROFILE_INDEX) {
DEBUG ((
DEBUG_ERROR,
"%a bad value of ActiveProfileIndex returned: %d, defaulting to generic profile\n",
__FUNCTION__,
ActiveProfileIndex
));
ActiveProfileIndex = MAX_UINT32;
ActiveProfileIndex = GENERIC_PROFILE_INDEX;
}

// now go through and populate the Conf Policy
Expand Down Expand Up @@ -255,6 +265,32 @@ CreateConfPolicy (
goto CreatePolicyExit;
}

// Publish the config metadata policy
ConfigMetadata.ActiveProfileIndex = ActiveProfileIndex;
if (ConfigMetadata.ActiveProfileIndex == GENERIC_PROFILE_INDEX) {
ProfileName = (CHAR8 *)GENERIC_PROFILE_FLAVOR_NAME;
} else {
ProfileName = gProfileFlavorNames[ActiveProfileIndex];
}

Status = AsciiStrCpyS (&ConfigMetadata.ActiveProfileFlavorName[0], PROFILE_FLAVOR_NAME_LENGTH, ProfileName);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a Failed to copy flavor name! Status (%r)\n", __FUNCTION__, Status));
goto CreatePolicyExit;
}

Status = SetPolicy (
&gOemConfigMetadataPolicyGuid,
POLICY_ATTRIBUTE_FINALIZED,
&ConfigMetadata,
OEM_CONFIG_METADATA_POLICY_SIZE
);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a Failed to set config metadata policy! Status (%r)\n", __func__, Status));
goto CreatePolicyExit;
}

CreatePolicyExit:
if (EFI_ERROR (Status)) {
*ConfPolicySize = 0;
Expand Down Expand Up @@ -283,23 +319,13 @@ OemConfigPolicyCreatorPeiEntry (
)
{
EFI_STATUS Status;
POLICY_PPI *PolPpi = NULL;
VOID *ConfPolicy = NULL;
UINT16 ConfPolicySize = 0;

DEBUG ((DEBUG_INFO, "%a - Entry.\n", __FUNCTION__));

// First locate policy ppi.
Status = PeiServicesLocatePpi (&gPeiPolicyPpiGuid, 0, NULL, (VOID *)&PolPpi);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a Failed to locate Policy PPI - %r\n", __FUNCTION__, Status));
ASSERT (FALSE);
goto Exit;
}

// Oem can choose to do any Oem specific things to config here such as enforcing static only config or
// selecting a configuration profile based on some criteria

Status = CreateConfPolicy (&ConfPolicy, &ConfPolicySize);

if (EFI_ERROR (Status) || (ConfPolicy == NULL) || (ConfPolicySize == 0)) {
Expand All @@ -311,7 +337,7 @@ OemConfigPolicyCreatorPeiEntry (
// Publish immutable config policy
// Policy Service will receive gOemConfigPolicyGuid and publish it as a PPI so that the Silicon Policy Creator can
// have a depex on it and map it to Silicon Policies
Status = PolPpi->SetPolicy (&gOemConfigPolicyGuid, POLICY_ATTRIBUTE_FINALIZED, ConfPolicy, ConfPolicySize);
Status = SetPolicy (&gOemConfigPolicyGuid, POLICY_ATTRIBUTE_FINALIZED, ConfPolicy, ConfPolicySize);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a Failed to set config policy! Status (%r)\n", __FUNCTION__, Status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
ConfigKnobShimLib
SafeIntLib
ActiveProfileIndexSelectorLib
PolicyLib

[Ppis]
gPeiPolicyPpiGuid ## CONSUMES
gEfiPeiReadOnlyVariable2PpiGuid ## CONSUMES

[Guids]
gOemConfigPolicyGuid # Guid that config policy is filed under
gOemConfigMetadataPolicyGuid # Guid that config metadata policy is filed under

[Depex]
gPeiPolicyPpiGuid AND # Needed to file config policy
Expand Down
5 changes: 5 additions & 0 deletions OemPkg/OemPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
# Oem Config Policy Guid
gOemConfigPolicyGuid = { 0xba320ade, 0xe132, 0x4c99, { 0xa3, 0xdf, 0x74, 0xd6, 0x73, 0xea, 0x6f, 0x76 } }

#
# Guid that the config metadata policy is registered under
# 44E9778F-3DAF-46BA-B186-784D0B055072
gOemConfigMetadataPolicyGuid = { 0x44e9778f, 0x3daf, 0x46ba, { 0xb1, 0x86, 0x78, 0x4d, 0x0b, 0x05, 0x50, 0x72 } }

[Protocols]
gMsButtonServicesProtocolGuid = { 0xe0084c50, 0x3efd, 0x43f7, { 0x88, 0xdf, 0x19, 0x4d, 0xf2, 0xd1, 0x60, 0xf0 }}

Expand Down
5 changes: 3 additions & 2 deletions OemPkg/OemPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@

[LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.UEFI_APPLICATION]
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
PolicyLib|PolicyServicePkg/Library/DxePolicyLib/DxePolicyLib.inf

[LibraryClasses.common.PEIM]
PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
Expand All @@ -109,6 +110,7 @@
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
ConfigKnobShimLib|SetupDataPkg/Library/ConfigKnobShimLib/ConfigKnobShimPeiLib/ConfigKnobShimPeiLib.inf
PolicyLib|PolicyServicePkg/Library/PeiPolicyLib/PeiPolicyLib.inf
###############################################################
#
# Components Section - list of the modules and components that will be processed by compilation
Expand Down Expand Up @@ -144,11 +146,10 @@
OemPkg/Library/OemMfciLib/OemMfciLibPei.inf
OemPkg/Library/OemMfciLib/OemMfciLibDxe.inf
OemPkg/FrontpageButtonsVolumeUp/FrontpageButtonsVolumeUp.inf
OemPkg/Library/PlatformConfigDataNullLib/PlatformConfigDataNullLib.inf
OemPkg/OemConfigPolicyCreatorPei/OemConfigPolicyCreatorPei.inf {
<LibraryClasses>
# platform data lib
NULL|OemPkg/Library/PlatformConfigDataNullLib/PlatformConfigDataNullLib.inf
NULL|SetupDataPkg/Library/PlatformConfigDataLibNull/PlatformConfigDataLibNull.inf
}
OemPkg/Library/ActiveProfileIndexSelectorPcdLib/ActiveProfileIndexSelectorPcdLib.inf

Expand Down

0 comments on commit e916e31

Please sign in to comment.