edk2/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c
Leif Lindholm 8aad683e59
Some checks are pending
CodeQL / Analyze (IA32, CryptoPkg) (push) Waiting to run
CodeQL / Analyze (IA32, MdeModulePkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, DynamicTablesPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, FatPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, FmpDevicePkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, IntelFsp2Pkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, IntelFsp2WrapperPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, MdePkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, PcAtChipsetPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, PrmPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, SecurityPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, ShellPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, SourceLevelDebugPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, StandaloneMmPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, UefiCpuPkg) (push) Waiting to run
CodeQL / Analyze (IA32,X64, UnitTestFrameworkPkg) (push) Waiting to run
CodeQL / Analyze (X64, CryptoPkg) (push) Waiting to run
CodeQL / Analyze (X64, MdeModulePkg) (push) Waiting to run
UPL Build / Build UPL VS2022 (FIT_BUILD=FALSE, windows-latest, 3.12, DEBUG, VS2022) (push) Waiting to run
UPL Build / Build UPL VS2022 (FIT_BUILD=TRUE, windows-latest, 3.12, DEBUG, VS2022) (push) Waiting to run
UPL Build / Build UPL GCC (FIT_BUILD=FALSE, ubuntu-latest, 3.12, DEBUG, GCC) (push) Waiting to run
UPL Build / Build UPL GCC (FIT_BUILD=TRUE, ubuntu-latest, 3.12, DEBUG, GCC) (push) Waiting to run
ArmVirtPkg,DynamicTablesPkg,EmbeddedPkg,OvmfPkg: use MdePkg BaseFdtLib
Migrate these packages to use the up-to-date BaseFdtLib instead
of the EmbeddedPkg relic that is going away.

Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
2025-04-30 10:56:03 +00:00

118 lines
3.4 KiB
C

/** @file
Flattened Device Tree parser library for KvmTool.
Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/FdtLib.h>
#include "FdtHwInfoParser.h"
/** Initialise the HwInfoParser.
The HwInfoParser shall use the information provided by the HwDataSource
to initialise the internal state of the parser or to index the data. This
internal state shall be linked to the ParserHandle using an implementation
defined mechanism.
@param [in] HwDataSource Pointer to the blob containing the hardware
information. It can be a pointer to a Device
Tree, an XML file, etc. or any other data
structure defined by the HwInfoParser.
@param [in] Context A pointer to the caller's context.
@param [in] HwInfoAdd Function pointer called by the parser when
adding information.
@param [out] ParserHandle A handle to the parser instance.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_INVALID_PARAMETER Invalid parameter.
**/
EFI_STATUS
EFIAPI
HwInfoParserInit (
IN VOID *HwDataSource,
IN VOID *Context,
IN HW_INFO_ADD_OBJECT HwInfoAdd,
OUT HW_INFO_PARSER_HANDLE *ParserHandle
)
{
FDT_HW_INFO_PARSER *FdtParserHandle;
if ((ParserHandle == NULL) ||
(HwInfoAdd == NULL) ||
(HwDataSource == NULL) ||
(FdtCheckHeader (HwDataSource) < 0))
{
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
FdtParserHandle = AllocateZeroPool (sizeof (FDT_HW_INFO_PARSER));
if (FdtParserHandle == NULL) {
*ParserHandle = NULL;
return EFI_OUT_OF_RESOURCES;
}
// The HwDataSource is a pointer to the FDT data.
FdtParserHandle->Fdt = HwDataSource;
FdtParserHandle->Context = Context;
FdtParserHandle->HwInfoAdd = HwInfoAdd;
*ParserHandle = (HW_INFO_PARSER_HANDLE)FdtParserHandle;
return EFI_SUCCESS;
}
/** Parse the data provided by the HwDataSource.
@param [in] ParserHandle A handle to the parser instance.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_INVALID_PARAMETER Invalid parameter.
@retval EFI_OUT_OF_RESOURCES An allocation has failed.
**/
EFI_STATUS
EFIAPI
HwInfoParse (
IN HW_INFO_PARSER_HANDLE ParserHandle
)
{
EFI_STATUS Status;
if (ParserHandle == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
// Call all the parsers from the root node (-1).
Status = ArchFdtHwInfoMainDispatcher (
(FDT_HW_INFO_PARSER_HANDLE)ParserHandle,
-1
);
ASSERT_EFI_ERROR (Status);
return Status;
}
/** Cleanup any internal state and resources that were allocated
by the HwInfoParser.
@param [in] ParserHandle A handle to the parser instance.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_INVALID_PARAMETER Invalid parameter.
**/
EFI_STATUS
EFIAPI
HwInfoParserShutdown (
IN HW_INFO_PARSER_HANDLE ParserHandle
)
{
if (ParserHandle == NULL) {
ASSERT (0);
return EFI_INVALID_PARAMETER;
}
FreePool (ParserHandle);
return EFI_SUCCESS;
}