VirtualBox

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

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 3.2 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
10/** Initialise the HwInfoParser.
11
12 The HwInfoParser shall use the information provided by the HwDataSource
13 to initialise the internal state of the parser or to index the data. This
14 internal state shall be linked to the ParserHandle using an implementation
15 defined mechanism.
16
17 @param [in] HwDataSource Pointer to the blob containing the hardware
18 information. It can be a pointer to a Device
19 Tree, an XML file, etc. or any other data
20 structure defined by the HwInfoParser.
21 @param [in] Context A pointer to the caller's context.
22 @param [in] HwInfoAdd Function pointer called by the parser when
23 adding information.
24 @param [out] ParserHandle A handle to the parser instance.
25
26 @retval EFI_SUCCESS The function completed successfully.
27 @retval EFI_INVALID_PARAMETER Invalid parameter.
28**/
29EFI_STATUS
30EFIAPI
31HwInfoParserInit (
32 IN VOID *HwDataSource,
33 IN VOID *Context,
34 IN HW_INFO_ADD_OBJECT HwInfoAdd,
35 OUT HW_INFO_PARSER_HANDLE *ParserHandle
36 )
37{
38 FDT_HW_INFO_PARSER *FdtParserHandle;
39
40 if ((ParserHandle == NULL) ||
41 (HwInfoAdd == NULL) ||
42 (HwDataSource == NULL) ||
43 (fdt_check_header (HwDataSource) < 0))
44 {
45 ASSERT (0);
46 return EFI_INVALID_PARAMETER;
47 }
48
49 FdtParserHandle = AllocateZeroPool (sizeof (FDT_HW_INFO_PARSER));
50 if (FdtParserHandle == NULL) {
51 *ParserHandle = NULL;
52 return EFI_OUT_OF_RESOURCES;
53 }
54
55 // The HwDataSource is a pointer to the FDT data.
56 FdtParserHandle->Fdt = HwDataSource;
57 FdtParserHandle->Context = Context;
58 FdtParserHandle->HwInfoAdd = HwInfoAdd;
59
60 *ParserHandle = (HW_INFO_PARSER_HANDLE)FdtParserHandle;
61 return EFI_SUCCESS;
62}
63
64/** Parse the data provided by the HwDataSource.
65
66 @param [in] ParserHandle A handle to the parser instance.
67
68 @retval EFI_SUCCESS The function completed successfully.
69 @retval EFI_INVALID_PARAMETER Invalid parameter.
70 @retval EFI_OUT_OF_RESOURCES An allocation has failed.
71**/
72EFI_STATUS
73EFIAPI
74HwInfoParse (
75 IN HW_INFO_PARSER_HANDLE ParserHandle
76 )
77{
78 EFI_STATUS Status;
79
80 if (ParserHandle == NULL) {
81 ASSERT (0);
82 return EFI_INVALID_PARAMETER;
83 }
84
85 // Call all the parsers from the root node (-1).
86 Status = ArchFdtHwInfoMainDispatcher (
87 (FDT_HW_INFO_PARSER_HANDLE)ParserHandle,
88 -1
89 );
90 ASSERT_EFI_ERROR (Status);
91 return Status;
92}
93
94/** Cleanup any internal state and resources that were allocated
95 by the HwInfoParser.
96
97 @param [in] ParserHandle A handle to the parser instance.
98
99 @retval EFI_SUCCESS The function completed successfully.
100 @retval EFI_INVALID_PARAMETER Invalid parameter.
101**/
102EFI_STATUS
103EFIAPI
104HwInfoParserShutdown (
105 IN HW_INFO_PARSER_HANDLE ParserHandle
106 )
107{
108 if (ParserHandle == NULL) {
109 ASSERT (0);
110 return EFI_INVALID_PARAMETER;
111 }
112
113 FreePool (ParserHandle);
114
115 return EFI_SUCCESS;
116}
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