audk/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c

216 lines
5.7 KiB
C
Raw Normal View History

ShellPkg: Add acpiview tool to dump ACPI tables This program is provided to allow examination of ACPI table contents from the UEFI Shell. This can help with investigations, especially at that stage where the tables are not enabling an OS to boot. The program is not exhaustive, and only encapsulates detailed knowledge of a limited number of table types. Default behaviour is to display the content of all tables installed. 'Known' table types will be parsed and displayed with descriptions and field values. Where appropriate a degree of consistency checking is done and errors may be reported in the output. Other table types will be displayed as an array of Hexadecimal bytes. To facilitate debugging, the -s and -d options can be used to generate a binary file image of a table that can be copied elsewhere for investigation using tools such as those provided by acpica.org. This is especially relevant for AML type tables like DSDT and SSDT. The inspiration for this is the existing smbiosview Debug1 Shell command. Many tables are not explicitly handled, in part because no examples are available for our testing. The program is designed to be extended to new tables with minimal effort, and contributions are invited. Change-Id: Ifa23dc80ab8ab042c56e88424847e796a8122a7c Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Evan Lloyd <evan.lloyd@arm.com> Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Evan Lloyd <evan.lloyd@arm.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2018-04-20 10:08:22 +02:00
/**
ACPI table parser
Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <IndustryStandard/Acpi.h>
#include <Library/UefiLib.h>
#include "AcpiParser.h"
#include "AcpiTableParser.h"
#include "AcpiView.h"
/** A list of registered ACPI table parsers.
*/
STATIC ACPI_TABLE_PARSER mTableParserList[MAX_ACPI_TABLE_PARSERS];
/** Register the ACPI table Parser
This function registers the ACPI table parser.
@param [in] Signature The ACPI table signature.
@param [in] ParserProc The ACPI table parser.
@retval EFI_SUCCESS The parser is registered.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
@retval EFI_ALREADY_STARTED The parser for the Table
was already registered.
@retval EFI_OUT_OF_RESOURCES No space to register the
parser.
*/
EFI_STATUS
EFIAPI
RegisterParser (
IN UINT32 Signature,
IN PARSE_ACPI_TABLE_PROC ParserProc
)
{
UINT32 index;
if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
return EFI_INVALID_PARAMETER;
}
// Search if a parser is already installed
for (index = 0;
index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
index++)
{
if (Signature == mTableParserList[index].Signature) {
if (mTableParserList[index].Parser != NULL) {
return EFI_ALREADY_STARTED;
}
}
}
// Find the first free slot and register the parser
for (index = 0;
index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
index++)
{
if (mTableParserList[index].Signature == ACPI_PARSER_SIGNATURE_NULL) {
mTableParserList[index].Signature = Signature;
mTableParserList[index].Parser = ParserProc;
return EFI_SUCCESS;
}
}
// No free slot found
return EFI_OUT_OF_RESOURCES;
}
/** Deregister the ACPI table Parser
This function deregisters the ACPI table parser.
@param [in] Signature The ACPI table signature.
@retval EFI_SUCCESS The parser was deregistered.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
@retval EFI_NOT_FOUND A registered parser was not found.
*/
EFI_STATUS
EFIAPI
DeregisterParser (
IN UINT32 Signature
)
{
UINT32 index;
if (Signature == ACPI_PARSER_SIGNATURE_NULL) {
return EFI_INVALID_PARAMETER;
}
for (index = 0;
index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
index++)
{
if (Signature == mTableParserList[index].Signature) {
mTableParserList[index].Signature = ACPI_PARSER_SIGNATURE_NULL;
mTableParserList[index].Parser = NULL;
return EFI_SUCCESS;
}
}
// No matching registered parser found.
return EFI_NOT_FOUND;
}
/** Get the ACPI table Parser
This function returns the ACPI table parser proc from the list of
registered parsers.
@param [in] Signature The ACPI table signature.
@param [out] ParserProc Pointer to a ACPI table parser proc.
@retval EFI_SUCCESS The parser was returned successfully.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
@retval EFI_NOT_FOUND A registered parser was not found.
*/
EFI_STATUS
EFIAPI
GetParser (
IN UINT32 Signature,
OUT PARSE_ACPI_TABLE_PROC * ParserProc
)
{
UINT32 index;
if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
return EFI_INVALID_PARAMETER;
}
for (index = 0;
index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
index++)
{
if (Signature == mTableParserList[index].Signature) {
*ParserProc = mTableParserList[index].Parser;
return EFI_SUCCESS;
}
}
// No matching registered parser found.
return EFI_NOT_FOUND;
}
/** This function processes the ACPI tables.
This function calls ProcessTableReportOptions() to list the ACPI
tables, perform binary dump of the tables and determine if the
ACPI fields should be traced.
This function also invokes the parser for the ACPI tables.
This function also performs a RAW dump of the ACPI table including
the unknown/unparsed ACPI tables and validates the checksum.
@param [in] Ptr Pointer to the start of the ACPI
table data buffer.
*/
VOID
EFIAPI
ProcessAcpiTable (
IN UINT8* Ptr
)
{
EFI_STATUS Status;
BOOLEAN Trace;
CONST UINT32* AcpiTableSignature;
CONST UINT32* AcpiTableLength;
CONST UINT8* AcpiTableRevision;
PARSE_ACPI_TABLE_PROC ParserProc;
ParseAcpiHeader (
Ptr,
&AcpiTableSignature,
&AcpiTableLength,
&AcpiTableRevision
);
Trace = ProcessTableReportOptions (
*AcpiTableSignature,
Ptr,
*AcpiTableLength
);
if (Trace) {
DumpRaw (Ptr, *AcpiTableLength);
VerifyChecksum (TRUE, Ptr, *AcpiTableLength);
}
Status = GetParser (*AcpiTableSignature, &ParserProc);
if (EFI_ERROR (Status)) {
// No registered parser found, do default handling.
if (Trace) {
DumpAcpiHeader (Ptr);
}
return;
}
ParserProc (
Trace,
Ptr,
*AcpiTableLength,
*AcpiTableRevision
);
}