VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c@ 108793

Last change on this file since 108793 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
1/** @file
2 Flattened Device Tree parser library for KvmTool.
3
4 Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6**/
7
8#include "FdtHwInfoParser.h"
9#include "BootArch/ArmBootArchParser.h"
10#include "GenericTimer/ArmGenericTimerParser.h"
11#include "Gic/ArmGicDispatcher.h"
12#include "Pci/ArmPciConfigSpaceParser.h"
13#include "Serial/ArmSerialPortParser.h"
14
15/** Ordered table of parsers/dispatchers.
16
17 A parser parses a Device Tree to populate a specific CmObj type. None,
18 one or many CmObj can be created by the parser.
19 The created CmObj are then handed to the parser's caller through the
20 HW_INFO_ADD_OBJECT interface.
21 This can also be a dispatcher. I.e. a function that not parsing a
22 Device Tree but calling other parsers.
23*/
24STATIC CONST FDT_HW_INFO_PARSER_FUNC HwInfoParserTable[] = {
25 ArmBootArchInfoParser,
26 ArmGenericTimerInfoParser,
27 ArmGicDispatcher,
28 ArmPciConfigInfoParser,
29 SerialPortDispatcher
30};
31
32/** Main dispatcher: sequentially call the parsers/dispatchers
33 of the HwInfoParserTable.
34
35 A parser parses a Device Tree to populate a specific CmObj type. None,
36 one or many CmObj can be created by the parser.
37 The created CmObj are then handed to the parser's caller through the
38 HW_INFO_ADD_OBJECT interface.
39 This can also be a dispatcher. I.e. a function that not parsing a
40 Device Tree but calling other parsers.
41
42 @param [in] FdtParserHandle A handle to the parser instance.
43 @param [in] FdtBranch When searching for DT node name, restrict
44 the search to this Device Tree branch.
45
46 @retval EFI_SUCCESS The function completed successfully.
47 @retval EFI_ABORTED An error occurred.
48 @retval EFI_INVALID_PARAMETER Invalid parameter.
49 @retval EFI_NOT_FOUND Not found.
50 @retval EFI_UNSUPPORTED Unsupported.
51**/
52STATIC
53EFI_STATUS
54EFIAPI
55MainDispatcher (
56 IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
57 IN INT32 FdtBranch
58 )
59{
60 EFI_STATUS Status;
61 UINT32 Index;
62
63 if (fdt_check_header (FdtParserHandle->Fdt) < 0) {
64 ASSERT (0);
65 return EFI_INVALID_PARAMETER;
66 }
67
68 for (Index = 0; Index < ARRAY_SIZE (HwInfoParserTable); Index++) {
69 Status = HwInfoParserTable[Index](
70 FdtParserHandle,
71 FdtBranch
72 );
73 if (EFI_ERROR (Status) &&
74 (Status != EFI_NOT_FOUND))
75 {
76 // If EFI_NOT_FOUND, the parser didn't find information in the DT.
77 // Don't trigger an error.
78 ASSERT (0);
79 return Status;
80 }
81 } // for
82
83 return EFI_SUCCESS;
84}
85
86/** Initialise the HwInfoParser.
87
88 The HwInfoParser shall use the information provided by the HwDataSource
89 to initialise the internal state of the parser or to index the data. This
90 internal state shall be linked to the ParserHandle using an implementation
91 defined mechanism.
92
93 @param [in] HwDataSource Pointer to the blob containing the hardware
94 information. It can be a pointer to a Device
95 Tree, an XML file, etc. or any other data
96 structure defined by the HwInfoParser.
97 @param [in] Context A pointer to the caller's context.
98 @param [in] HwInfoAdd Function pointer called by the parser when
99 adding information.
100 @param [out] ParserHandle A handle to the parser instance.
101
102 @retval EFI_SUCCESS The function completed successfully.
103 @retval EFI_INVALID_PARAMETER Invalid parameter.
104**/
105EFI_STATUS
106EFIAPI
107HwInfoParserInit (
108 IN VOID *HwDataSource,
109 IN VOID *Context,
110 IN HW_INFO_ADD_OBJECT HwInfoAdd,
111 OUT HW_INFO_PARSER_HANDLE *ParserHandle
112 )
113{
114 FDT_HW_INFO_PARSER *FdtParserHandle;
115
116 if ((ParserHandle == NULL) ||
117 (HwInfoAdd == NULL) ||
118 (HwDataSource == NULL) ||
119 (fdt_check_header (HwDataSource) < 0))
120 {
121 ASSERT (0);
122 return EFI_INVALID_PARAMETER;
123 }
124
125 FdtParserHandle = AllocateZeroPool (sizeof (FDT_HW_INFO_PARSER));
126 if (FdtParserHandle == NULL) {
127 *ParserHandle = NULL;
128 return EFI_OUT_OF_RESOURCES;
129 }
130
131 // The HwDataSource is a pointer to the FDT data.
132 FdtParserHandle->Fdt = HwDataSource;
133 FdtParserHandle->Context = Context;
134 FdtParserHandle->HwInfoAdd = HwInfoAdd;
135
136 *ParserHandle = (HW_INFO_PARSER_HANDLE)FdtParserHandle;
137 return EFI_SUCCESS;
138}
139
140/** Parse the data provided by the HwDataSource.
141
142 @param [in] ParserHandle A handle to the parser instance.
143
144 @retval EFI_SUCCESS The function completed successfully.
145 @retval EFI_INVALID_PARAMETER Invalid parameter.
146 @retval EFI_OUT_OF_RESOURCES An allocation has failed.
147**/
148EFI_STATUS
149EFIAPI
150HwInfoParse (
151 IN HW_INFO_PARSER_HANDLE ParserHandle
152 )
153{
154 EFI_STATUS Status;
155
156 if (ParserHandle == NULL) {
157 ASSERT (0);
158 return EFI_INVALID_PARAMETER;
159 }
160
161 // Call all the parsers from the root node (-1).
162 Status = MainDispatcher (
163 (FDT_HW_INFO_PARSER_HANDLE)ParserHandle,
164 -1
165 );
166 ASSERT_EFI_ERROR (Status);
167 return Status;
168}
169
170/** Cleanup any internal state and resources that were allocated
171 by the HwInfoParser.
172
173 @param [in] ParserHandle A handle to the parser instance.
174
175 @retval EFI_SUCCESS The function completed successfully.
176 @retval EFI_INVALID_PARAMETER Invalid parameter.
177**/
178EFI_STATUS
179EFIAPI
180HwInfoParserShutdown (
181 IN HW_INFO_PARSER_HANDLE ParserHandle
182 )
183{
184 if (ParserHandle == NULL) {
185 ASSERT (0);
186 return EFI_INVALID_PARAMETER;
187 }
188
189 FreePool (ParserHandle);
190
191 return EFI_SUCCESS;
192}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette