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 | **/
|
---|
29 | EFI_STATUS
|
---|
30 | EFIAPI
|
---|
31 | HwInfoParserInit (
|
---|
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 | **/
|
---|
72 | EFI_STATUS
|
---|
73 | EFIAPI
|
---|
74 | HwInfoParse (
|
---|
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 | **/
|
---|
102 | EFI_STATUS
|
---|
103 | EFIAPI
|
---|
104 | HwInfoParserShutdown (
|
---|
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 | }
|
---|