Skip to content

Commit

Permalink
Adding customizable GUID for BERT extra variables support (#122)
Browse files Browse the repository at this point in the history
## Description

Current implement will allow extra variables with names specified under
`PcdBertEntriesVariableNames` and namespace GUID being
`gEfiHardwareErrorVariableGuid` to be collected into BERT table for OS
consumption.

However, variables under `gEfiHardwareErrorVariableGuid` has certain
restrictions that does not allow random variable names to be used and
could potentially clash with `HwErrRec####` occupied by other firmware
entities.

This change will add the flexibility for the platform to specify their
own
variable GUID to be collected during boot for BERT table usage.

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?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?

## How This Was Tested

Tested on QEMU virtual systems and proprietary physical devices.

## Integration Instructions

For platforms that need to support specific CPER formatted variables
coalition into the BERT table, one should override the PCD value of
`gMsWheaPkgTokenSpaceGuid.PcdBertEntriesVariableGuid` of their choices.
Otherwise, `gEfiHardwareErrorVariableGuid` will be the default value and
certain variable naming schema might restrict the specific use case.
  • Loading branch information
kuqin12 authored and kenlautner committed May 14, 2023
1 parent 7f4c330 commit 2dd19af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions MsWheaPkg/HwErrBert/HwErrBert.inf
Expand Up @@ -57,6 +57,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision
gMsWheaPkgTokenSpaceGuid.PcdBertEntriesVariableNames
gMsWheaPkgTokenSpaceGuid.PcdBertEntriesVariableGuid

[Guids]
gEfiHardwareErrorVariableGuid ## CONSUMES
Expand Down
40 changes: 35 additions & 5 deletions MsWheaPkg/HwErrBert/HwErrorBert.c
Expand Up @@ -28,6 +28,7 @@ STATIC EFI_EVENT mExitBootServicesEvent = NULL;
STATIC EFI_EVENT mReadyToBootEvent = NULL;
UINT16 mVarNameListCount = 0;
CHAR16 *mVarNameList = NULL;
EFI_GUID *mVarGuidList = NULL;

/**
Expand All @@ -48,7 +49,7 @@ SetupBert (
EFI_STATUS Status;
BERT_CONTEXT Context;

if (!mVarNameList || (mVarNameListCount == 0)) {
if (!mVarNameList || !mVarGuidList || (mVarNameListCount == 0)) {
DEBUG ((DEBUG_WARN, "%a: leaving because list of entries to catalogue was empty.\n", __FUNCTION__));
return;
}
Expand Down Expand Up @@ -77,7 +78,7 @@ SetupBert (
//
Status = gRT->GetVariable (
NamePtr,
&gEfiHardwareErrorVariableGuid,
&mVarGuidList[Index],
NULL,
&Size,
NULL
Expand All @@ -98,7 +99,7 @@ SetupBert (

Status = gRT->GetVariable (
NamePtr,
&gEfiHardwareErrorVariableGuid,
&mVarGuidList[Index],
NULL,
&Size,
Buffer
Expand Down Expand Up @@ -200,7 +201,19 @@ GenerateVariableList (
goto cleanup;
}

mVarGuidList = ReallocatePool (
mVarNameListCount * sizeof (EFI_GUID),
(mVarNameListCount + 1) * sizeof (EFI_GUID),
mVarGuidList
);
if (mVarGuidList == NULL) {
DEBUG ((DEBUG_ERROR, "%a - %d\n", __FUNCTION__, __LINE__));
Status = EFI_OUT_OF_RESOURCES;
goto cleanup;
}

StrCpyS (&mVarNameList[mVarNameListCount * EFI_HW_ERR_REC_VAR_NAME_LEN], StrLen (Name) + 1, Name);
CopyMem (&mVarGuidList[mVarNameListCount], &gEfiHardwareErrorVariableGuid, sizeof (EFI_GUID));
mVarNameListCount++;
}

Expand Down Expand Up @@ -236,7 +249,7 @@ GenerateVariableList (
DummyVarSize = 0;
Status = gRT->GetVariable (
CurrentName,
&gEfiHardwareErrorVariableGuid,
FixedPcdGetPtr (PcdBertEntriesVariableGuid),
NULL,
&DummyVarSize,
NULL
Expand All @@ -255,7 +268,19 @@ GenerateVariableList (
goto cleanup;
}

mVarGuidList = ReallocatePool (
VarNameUnicodeCount * sizeof (CHAR16),
VarNameUnicodeCount * sizeof (CHAR16) + CurrentSize,
mVarGuidList
);
if (mVarGuidList == NULL) {
DEBUG ((DEBUG_ERROR, "%a - %d\n", __FUNCTION__, __LINE__));
Status = EFI_OUT_OF_RESOURCES;
goto cleanup;
}

StrCpyS (&mVarNameList[VarNameUnicodeCount], CurrentSize / sizeof (CHAR16), CurrentName);
CopyMem (&mVarGuidList[mVarNameListCount], FixedPcdGetPtr (PcdBertEntriesVariableGuid), sizeof (EFI_GUID));
VarNameUnicodeCount += CurrentSize / sizeof (CHAR16);
mVarNameListCount++;
} else if (Status != EFI_NOT_FOUND) {
Expand Down Expand Up @@ -289,6 +314,7 @@ GenerateVariableList (
ASSERT (FALSE);
mVarNameListCount = 0;
mVarNameList = NULL;
mVarGuidList = NULL;
}

DEBUG ((DEBUG_INFO, "%a found %x variables for the BERT table - %r\n", __FUNCTION__, mVarNameListCount, Status));
Expand Down Expand Up @@ -317,7 +343,7 @@ ClearVariables (

NamePtr = mVarNameList;
for (Index = 0; Index < mVarNameListCount; Index++) {
Status = gRT->SetVariable (NamePtr, &gEfiHardwareErrorVariableGuid, 0, 0, NULL);
Status = gRT->SetVariable (NamePtr, &mVarGuidList[Index], 0, 0, NULL);

// Can't really do much if this fails
if (EFI_ERROR (Status)) {
Expand Down Expand Up @@ -360,6 +386,10 @@ ExitBootServicesHandlerCallback (
FreePool (mVarNameList);
}

if (mVarGuidList) {
FreePool (mVarGuidList);
}

return;
}

Expand Down
9 changes: 7 additions & 2 deletions MsWheaPkg/MsWheaPkg.dec
Expand Up @@ -71,6 +71,11 @@
gMsWheaPkgTokenSpaceGuid.PcdDeviceIdentifierGuid|{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}|VOID*|0x00000004

# Variable names intended for extra BERT table entries, should be unicode string separated by ';'.
# Note: The variables for potential BERT candidate should be stored under GUID gEfiHardwareErrorVariableGuid.
# If such variable exists, its content MUST comply with CPER error format.
# Note: The variables for potential BERT candidate should be stored under namespace GUID PcdBertEntriesVariableGuid.
# If such variables exist, its content MUST comply with CPER error format.
gMsWheaPkgTokenSpaceGuid.PcdBertEntriesVariableNames|L""|VOID*|0x00000007

# Variable Guid intended for extra BERT table entries, default to gEfiHardwareErrorVariableGuid.
# Variables stored with PcdBertEntriesVariableGuid as GUID and PcdBertEntriesVariableNames as names
# will be collected and convert into BERT table during boot table for error reporting purpose.
gMsWheaPkgTokenSpaceGuid.PcdBertEntriesVariableGuid|{GUID("414E6BDD-E47B-47CC-B244-BB61020CF516")}|VOID*|0x00000008

0 comments on commit 2dd19af

Please sign in to comment.