Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)
Add the framework for running generic post parsing validations. Included is an example ACPI validator that will run validations on ACPI tables that are applicable to all platforms. Currently no validations are implemented in this validator however it will be called from the main AcpiView.c application. Also make AcpiViewConfig use the new VALIDATOR_ID enum when setting and getting ValidatorId. Signed-off-by: Chris Jones <[email protected]> --- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c | 8 ++- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c | 14 ++++-- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h | 6 ++- ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c | 10 +++- ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf | 3 ++ ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c | 19 +++++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c | 52 +++++++++++++++++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h | 53 ++++++++++++++++++++ 8 files changed, 156 insertions(+), 9 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c index 8798410c05c03b98814b0c211d66287cbb6ef0e8..d4d5d907f613589c400544533e950460eed2ce3f 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c @@ -22,6 +22,7 @@ #include "AcpiTableParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" +#include "Validators/AcpiValidation.h" STATIC UINT32 mTableCount; STATIC UINT32 mBinTableCount; @@ -284,10 +285,13 @@ AcpiView ( } else if (GetConsistencyChecking () && (ReportDumpBinFile != ReportOption)) { + // Always run the ACPI validator + RunValidator (ValidatorIdAcpiStandard); + // Run additional validators from command line args ValidatorId = GetValidatorId (); - if (GetValidatorStatus () && (ValidatorId != 0)) { - ASSERT (0); // Validators not implemented yet + if (GetValidatorStatus () && (ValidatorId != ValidatorIdAcpiStandard)) { + RunValidator (ValidatorId); } OriginalAttribute = gST->ConOut->Mode->Attribute; diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c index e9a838812dbc5fc20fdf9ae7371e90f559f4ee2b..98032b7c52eb9125ad2f2fd8c395b8e823edd428 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c @@ -15,7 +15,7 @@ STATIC BOOLEAN mConsistencyCheck; STATIC BOOLEAN mColourHighlighting; STATIC EREPORT_OPTION mReportType; STATIC BOOLEAN mValidatorStatus; -STATIC UINTN mValidatorId; +STATIC VALIDATOR_ID mValidatorId; // User selection of which ACPI table should be checked SELECTED_ACPI_TABLE mSelectedAcpiTable; @@ -35,7 +35,7 @@ AcpiConfigSetDefaults ( mSelectedAcpiTable.Found = FALSE; mConsistencyCheck = TRUE; mValidatorStatus = FALSE; - mValidatorId = 0; + mValidatorId = ValidatorIdAcpiStandard; } /** @@ -224,7 +224,7 @@ SetValidatorStatus ( @return ID of validator to run. **/ -UINTN +VALIDATOR_ID EFIAPI GetValidatorId ( VOID @@ -238,11 +238,17 @@ GetValidatorId ( @param [in] ValidatorId ID of validator. **/ -VOID +EFI_STATUS EFIAPI SetValidatorId ( UINTN ValidatorId ) { + if (ValidatorId >= ValidatorIdMax) { + return EFI_INVALID_PARAMETER; + } + mValidatorId = ValidatorId; + + return EFI_SUCCESS; } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h index c6b1cf38cdd8f653b2ea04479aa625be1393762b..9103973db240b7425d9293bd5ab7cfe7851f7aff 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h @@ -8,6 +8,8 @@ #ifndef ACPI_VIEW_CONFIG_H_ #define ACPI_VIEW_CONFIG_H_ +#include "Validators/AcpiValidation.h" + /** This function returns the colour highlighting status. @@ -81,7 +83,7 @@ SetValidatorStatus ( @return ID of validator to run. **/ -UINTN +VALIDATOR_ID EFIAPI GetValidatorId ( VOID @@ -92,7 +94,7 @@ GetValidatorId ( @param [in] ValidatorId ID of validator. **/ -VOID +EFI_STATUS EFIAPI SetValidatorId ( UINTN ValidatorId diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c index 15d2727ed13b66785b6c1078f214611b29aefd40..0032dda6aee13dad7ba9e1c22b204cf374eb8037 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c @@ -311,7 +311,15 @@ ShellCommandRunAcpiView ( ValidatorIdStr = ShellCommandLineGetValue (Package, L"-r"); if (ValidatorIdStr != NULL) { - SetValidatorId (ShellStrToUintn (ValidatorIdStr)); + Status = SetValidatorId (ShellStrToUintn (ValidatorIdStr)); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_INVALID_PARAMETER; + Print ( + L"ERROR: ValidatorId %d not recognised.\n", + ShellStrToUintn (ValidatorIdStr) + ); + goto Done; + } } if (ShellCommandLineGetFlag (Package, L"-l")) { diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf index 63fc5a1281a894841dac704484c3d4f9481edb46..245ccc811e199ebc511a42989a2024433cbb1a84 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf @@ -49,6 +49,9 @@ [Sources.common] Parsers/Srat/SratParser.c Parsers/Ssdt/SsdtParser.c Parsers/Xsdt/XsdtParser.c + Validators/AcpiValidation.c + Validators/AcpiValidation.h + Validators/AcpiStandard/AcpiStandardValidator.c UefiShellAcpiViewCommandLib.c UefiShellAcpiViewCommandLib.uni diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c new file mode 100644 index 0000000000000000000000000000000000000000..d625c67321a53b8ad0569d98b9071556157394f4 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c @@ -0,0 +1,19 @@ +/** @file + ACPI validations. + + Copyright (c) 2021, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +/** + Entry point for validator, used to run platform agnostic ACPI validations. +**/ +VOID +EFIAPI +AcpiStandardValidate ( + VOID + ) +{ + // Validations not implemented yet. + return; +} diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c new file mode 100644 index 0000000000000000000000000000000000000000..8e12e19f2b67e1c4305585ed1384f82c401ec49e --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c @@ -0,0 +1,52 @@ +/** @file + ACPI post-parsing validation framework. + + Copyright (c) 2021, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <Library/PrintLib.h> +#include <Library/UefiLib.h> +#include "AcpiValidation.h" + +/** + List of all validators that can be run. +**/ +ACPI_VALIDATOR mValidatorList[] = { + { ValidatorIdAcpiStandard, AcpiStandardValidate } +}; + +/** + Run the validator with the given ValidatorId. + + @param [in] ValidatorId The ID of the validator to run. +**/ +VOID +EFIAPI +RunValidator ( + IN UINTN ValidatorId + ) +{ + ACPI_VALIDATOR *Validator; + + if (ValidatorId >= ValidatorIdMax) { + Print ( + L"\nValidatorId is not recognised." \ + L" ValidatorId = %d.", + ValidatorId + ); + return; + } + + Validator = &mValidatorList[ValidatorId]; + if ((Validator == NULL) || (Validator->Id != ValidatorId)) { + Print ( + L"\nValidator cannot be retrieved." \ + L" ValidatorId = %d.", + ValidatorId + ); + return; + } + + Validator->ValidatorProc (); +} diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h new file mode 100644 index 0000000000000000000000000000000000000000..b7c5512ec673318ba2f15a8b986d33bdea6ec458 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h @@ -0,0 +1,53 @@ +/** @file + Header file for post-parsing APCI validation. + + Copyright (c) 2021, Arm Limited. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef ACPI_VALIDATION_H_ +#define ACPI_VALIDATION_H_ + +/** + ID's for all known validators. +**/ +typedef enum { + ValidatorIdAcpiStandard = 0, ///< Platform agnostic ACPI spec checks. + ValidatorIdMax = 1 +} VALIDATOR_ID; + +/** + A function pointer to the entry point of a validator. +**/ +typedef VOID (EFIAPI *EDKII_ACPI_VALIDATOR_PROC)(VOID); + +/** + A validator is made up of an ID and function pointer to the validators entry + point. +**/ +typedef struct AcpiValidator { + VALIDATOR_ID Id; + EDKII_ACPI_VALIDATOR_PROC ValidatorProc; +} ACPI_VALIDATOR; + +/** + Run the validator with the given ValidatorId. + + @param [in] ValidatorId The ID of the validator to run. +**/ +VOID +EFIAPI +RunValidator ( + IN UINTN ValidatorId + ); + +/** + Definition in Acpi/AcpiValidator.c +**/ +VOID +EFIAPI +AcpiStandardValidate ( + VOID + ); + +#endif -- Guid("CE165669-3EF3-493F-B85D-6190EE5B9759") -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84915): https://edk2.groups.io/g/devel/message/84915 Mute This Topic: https://groups.io/mt/87748585/21656 Group Owner: [email protected] Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
