mirror of
https://github.com/acidanthera/audk.git
synced 2025-04-08 17:05:09 +02:00
DynamicTablesPkg: FdtHwInfoParserLib: Refactor to prepare for other archs
To allow other architectures to potentially re-use the serial port parser and make the code arch neutral, make the MainDispatcher() function arch specific. Other architectures can choose which parse/dispatcher are desired to be called through the configuration of the HwInfoParserTable. Suggested-by: Sunil V L <sunilvl@ventanamicro.com> Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
This commit is contained in:
parent
e2fda42a22
commit
4bb08e8863
@ -0,0 +1,83 @@
|
||||
/** @file
|
||||
Arm Flattened Device Tree parser library for KvmTool.
|
||||
|
||||
Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
|
||||
#include "FdtHwInfoParser.h"
|
||||
#include "Arm/BootArch/ArmBootArchParser.h"
|
||||
#include "Arm/GenericTimer/ArmGenericTimerParser.h"
|
||||
#include "Arm/Gic/ArmGicDispatcher.h"
|
||||
#include "Pci/ArmPciConfigSpaceParser.h"
|
||||
#include "Serial/ArmSerialPortParser.h"
|
||||
|
||||
/** Ordered table of parsers/dispatchers.
|
||||
|
||||
A parser parses a Device Tree to populate a specific CmObj type. None,
|
||||
one or many CmObj can be created by the parser.
|
||||
The created CmObj are then handed to the parser's caller through the
|
||||
HW_INFO_ADD_OBJECT interface.
|
||||
This can also be a dispatcher. I.e. a function that not parsing a
|
||||
Device Tree but calling other parsers.
|
||||
*/
|
||||
STATIC CONST FDT_HW_INFO_PARSER_FUNC HwInfoParserTable[] = {
|
||||
ArmBootArchInfoParser,
|
||||
ArmGenericTimerInfoParser,
|
||||
ArmGicDispatcher,
|
||||
ArmPciConfigInfoParser,
|
||||
SerialPortDispatcher
|
||||
};
|
||||
|
||||
/** Main dispatcher: sequentially call the parsers/dispatchers
|
||||
of the HwInfoParserTable.
|
||||
|
||||
A parser parses a Device Tree to populate a specific CmObj type. None,
|
||||
one or many CmObj can be created by the parser.
|
||||
The created CmObj are then handed to the parser's caller through the
|
||||
HW_INFO_ADD_OBJECT interface.
|
||||
This can also be a dispatcher. I.e. a function that not parsing a
|
||||
Device Tree but calling other parsers.
|
||||
|
||||
@param [in] FdtParserHandle A handle to the parser instance.
|
||||
@param [in] FdtBranch When searching for DT node name, restrict
|
||||
the search to this Device Tree branch.
|
||||
|
||||
@retval EFI_SUCCESS The function completed successfully.
|
||||
@retval EFI_ABORTED An error occurred.
|
||||
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
||||
@retval EFI_NOT_FOUND Not found.
|
||||
@retval EFI_UNSUPPORTED Unsupported.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArchFdtHwInfoMainDispatcher (
|
||||
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
|
||||
IN INT32 FdtBranch
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Index;
|
||||
|
||||
if (fdt_check_header (FdtParserHandle->Fdt) < 0) {
|
||||
ASSERT (0);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < ARRAY_SIZE (HwInfoParserTable); Index++) {
|
||||
Status = HwInfoParserTable[Index](
|
||||
FdtParserHandle,
|
||||
FdtBranch
|
||||
);
|
||||
if (EFI_ERROR (Status) &&
|
||||
(Status != EFI_NOT_FOUND))
|
||||
{
|
||||
// If EFI_NOT_FOUND, the parser didn't find information in the DT.
|
||||
// Don't trigger an error.
|
||||
ASSERT (0);
|
||||
return Status;
|
||||
}
|
||||
} // for
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
@ -6,82 +6,6 @@
|
||||
**/
|
||||
|
||||
#include "FdtHwInfoParser.h"
|
||||
#include "Arm/BootArch/ArmBootArchParser.h"
|
||||
#include "Arm/GenericTimer/ArmGenericTimerParser.h"
|
||||
#include "Arm/Gic/ArmGicDispatcher.h"
|
||||
#include "Pci/ArmPciConfigSpaceParser.h"
|
||||
#include "Serial/ArmSerialPortParser.h"
|
||||
|
||||
/** Ordered table of parsers/dispatchers.
|
||||
|
||||
A parser parses a Device Tree to populate a specific CmObj type. None,
|
||||
one or many CmObj can be created by the parser.
|
||||
The created CmObj are then handed to the parser's caller through the
|
||||
HW_INFO_ADD_OBJECT interface.
|
||||
This can also be a dispatcher. I.e. a function that not parsing a
|
||||
Device Tree but calling other parsers.
|
||||
*/
|
||||
STATIC CONST FDT_HW_INFO_PARSER_FUNC HwInfoParserTable[] = {
|
||||
ArmBootArchInfoParser,
|
||||
ArmGenericTimerInfoParser,
|
||||
ArmGicDispatcher,
|
||||
ArmPciConfigInfoParser,
|
||||
SerialPortDispatcher
|
||||
};
|
||||
|
||||
/** Main dispatcher: sequentially call the parsers/dispatchers
|
||||
of the HwInfoParserTable.
|
||||
|
||||
A parser parses a Device Tree to populate a specific CmObj type. None,
|
||||
one or many CmObj can be created by the parser.
|
||||
The created CmObj are then handed to the parser's caller through the
|
||||
HW_INFO_ADD_OBJECT interface.
|
||||
This can also be a dispatcher. I.e. a function that not parsing a
|
||||
Device Tree but calling other parsers.
|
||||
|
||||
@param [in] FdtParserHandle A handle to the parser instance.
|
||||
@param [in] FdtBranch When searching for DT node name, restrict
|
||||
the search to this Device Tree branch.
|
||||
|
||||
@retval EFI_SUCCESS The function completed successfully.
|
||||
@retval EFI_ABORTED An error occurred.
|
||||
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
||||
@retval EFI_NOT_FOUND Not found.
|
||||
@retval EFI_UNSUPPORTED Unsupported.
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
MainDispatcher (
|
||||
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
|
||||
IN INT32 FdtBranch
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Index;
|
||||
|
||||
if (fdt_check_header (FdtParserHandle->Fdt) < 0) {
|
||||
ASSERT (0);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < ARRAY_SIZE (HwInfoParserTable); Index++) {
|
||||
Status = HwInfoParserTable[Index](
|
||||
FdtParserHandle,
|
||||
FdtBranch
|
||||
);
|
||||
if (EFI_ERROR (Status) &&
|
||||
(Status != EFI_NOT_FOUND))
|
||||
{
|
||||
// If EFI_NOT_FOUND, the parser didn't find information in the DT.
|
||||
// Don't trigger an error.
|
||||
ASSERT (0);
|
||||
return Status;
|
||||
}
|
||||
} // for
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/** Initialise the HwInfoParser.
|
||||
|
||||
@ -159,7 +83,7 @@ HwInfoParse (
|
||||
}
|
||||
|
||||
// Call all the parsers from the root node (-1).
|
||||
Status = MainDispatcher (
|
||||
Status = ArchFdtHwInfoMainDispatcher (
|
||||
(FDT_HW_INFO_PARSER_HANDLE)ParserHandle,
|
||||
-1
|
||||
);
|
||||
|
@ -60,4 +60,31 @@ EFI_STATUS
|
||||
IN INT32 FdtBranch
|
||||
);
|
||||
|
||||
/** Main dispatcher: sequentially call the parsers/dispatchers
|
||||
of the HwInfoParserTable.
|
||||
|
||||
A parser parses a Device Tree to populate a specific CmObj type. None,
|
||||
one or many CmObj can be created by the parser.
|
||||
The created CmObj are then handed to the parser's caller through the
|
||||
HW_INFO_ADD_OBJECT interface.
|
||||
This can also be a dispatcher. I.e. a function that not parsing a
|
||||
Device Tree but calling other parsers.
|
||||
|
||||
@param [in] FdtParserHandle A handle to the parser instance.
|
||||
@param [in] FdtBranch When searching for DT node name, restrict
|
||||
the search to this Device Tree branch.
|
||||
|
||||
@retval EFI_SUCCESS The function completed successfully.
|
||||
@retval EFI_ABORTED An error occurred.
|
||||
@retval EFI_INVALID_PARAMETER Invalid parameter.
|
||||
@retval EFI_NOT_FOUND Not found.
|
||||
@retval EFI_UNSUPPORTED Unsupported.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArchFdtHwInfoMainDispatcher (
|
||||
IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
|
||||
IN INT32 FdtBranch
|
||||
);
|
||||
|
||||
#endif // FDT_HW_INFO_PARSER_H_
|
||||
|
@ -22,6 +22,13 @@
|
||||
FdtHwInfoParser.h
|
||||
FdtUtility.c
|
||||
FdtUtility.h
|
||||
Pci/ArmPciConfigSpaceParser.c
|
||||
Pci/ArmPciConfigSpaceParser.h
|
||||
Serial/ArmSerialPortParser.c
|
||||
Serial/ArmSerialPortParser.h
|
||||
|
||||
[Sources.ARM, Sources.AARCH64]
|
||||
Arm/ArmFdtHwInfoParser.c
|
||||
Arm/BootArch/ArmBootArchParser.c
|
||||
Arm/BootArch/ArmBootArchParser.h
|
||||
Arm/GenericTimer/ArmGenericTimerParser.c
|
||||
@ -38,13 +45,11 @@
|
||||
Arm/Gic/ArmGicMsiFrameParser.h
|
||||
Arm/Gic/ArmGicRParser.c
|
||||
Arm/Gic/ArmGicRParser.h
|
||||
Pci/ArmPciConfigSpaceParser.c
|
||||
Pci/ArmPciConfigSpaceParser.h
|
||||
Serial/ArmSerialPortParser.c
|
||||
Serial/ArmSerialPortParser.h
|
||||
|
||||
[Packages.ARM, Packages.AARCH64]
|
||||
ArmPkg/ArmPkg.dec
|
||||
|
||||
[Packages]
|
||||
ArmPkg/ArmPkg.dec
|
||||
DynamicTablesPkg/DynamicTablesPkg.dec
|
||||
EmbeddedPkg/EmbeddedPkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
Loading…
x
Reference in New Issue
Block a user