]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DeviceTreeTableFactory/DeviceTreeTableFactory.c
DynamicTablesPkg: Apply uncrustify changes
[mirror_edk2.git] / DynamicTablesPkg / Drivers / DynamicTableFactoryDxe / DeviceTreeTableFactory / DeviceTreeTableFactory.c
1 /** @file
2 Device Tree Table Factory
3
4 Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 @par Glossary:
9 - Std - Standard
10 **/
11
12 #include <Library/BaseLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/DebugLib.h>
15
16 // Module specific include files.
17 #include <DeviceTreeTableGenerator.h>
18 #include <ConfigurationManagerObject.h>
19 #include <Protocol/ConfigurationManagerProtocol.h>
20 #include <Protocol/DynamicTableFactoryProtocol.h>
21
22 #include "DynamicTableFactory.h"
23
24 extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo;
25
26 /** Return a pointer to the DT table generator.
27
28 @param [in] This Pointer to the Dynamic Table Factory Protocol.
29 @param [in] GeneratorId The DT table generator ID for the
30 requested generator.
31 @param [out] Generator Pointer to the requested DT table
32 generator.
33
34 @retval EFI_SUCCESS Success.
35 @retval EFI_INVALID_PARAMETER A parameter is invalid.
36 @retval EFI_NOT_FOUND The requested generator is not found
37 in the list of registered generators.
38 **/
39 EFI_STATUS
40 EFIAPI
41 GetDtTableGenerator (
42 IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST This,
43 IN CONST DT_TABLE_GENERATOR_ID GeneratorId,
44 OUT CONST DT_TABLE_GENERATOR **CONST Generator
45 )
46 {
47 UINT16 TableId;
48 EDKII_DYNAMIC_TABLE_FACTORY_INFO *FactoryInfo;
49
50 ASSERT (This != NULL);
51
52 FactoryInfo = This->TableFactoryInfo;
53
54 if (Generator == NULL) {
55 DEBUG ((DEBUG_ERROR, "ERROR: Invalid Generator pointer\n"));
56 return EFI_INVALID_PARAMETER;
57 }
58
59 if (!IS_GENERATOR_TYPE_DT (GeneratorId)) {
60 DEBUG ((DEBUG_ERROR, "ERROR: Generator Type is not DT\n"));
61 return EFI_INVALID_PARAMETER;
62 }
63
64 *Generator = NULL;
65 TableId = GET_TABLE_ID (GeneratorId);
66 if (IS_GENERATOR_NAMESPACE_STD (GeneratorId)) {
67 if (TableId >= EStdDtTableIdMax) {
68 ASSERT (TableId < EStdDtTableIdMax);
69 return EFI_INVALID_PARAMETER;
70 }
71
72 if (FactoryInfo->StdDtTableGeneratorList[TableId] != NULL) {
73 *Generator = FactoryInfo->StdDtTableGeneratorList[TableId];
74 } else {
75 return EFI_NOT_FOUND;
76 }
77 } else {
78 if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) {
79 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators));
80 return EFI_INVALID_PARAMETER;
81 }
82
83 if (FactoryInfo->CustomDtTableGeneratorList[TableId] != NULL) {
84 *Generator = FactoryInfo->CustomDtTableGeneratorList[TableId];
85 } else {
86 return EFI_NOT_FOUND;
87 }
88 }
89
90 return EFI_SUCCESS;
91 }
92
93 /** Register DT table factory generator.
94
95 The DT table factory maintains a list of the Standard and OEM DT
96 table generators.
97
98 @param [in] Generator Pointer to the DT table generator.
99
100 @retval EFI_SUCCESS The Generator was registered
101 successfully.
102 @retval EFI_INVALID_PARAMETER The Generator ID is invalid or
103 the Generator pointer is NULL.
104 @retval EFI_ALREADY_STARTED The Generator for the Table ID is
105 already registered.
106 **/
107 EFI_STATUS
108 EFIAPI
109 RegisterDtTableGenerator (
110 IN CONST DT_TABLE_GENERATOR *CONST Generator
111 )
112 {
113 UINT16 TableId;
114
115 if (Generator == NULL) {
116 DEBUG ((DEBUG_ERROR, "ERROR: DT register - Invalid Generator\n"));
117 return EFI_INVALID_PARAMETER;
118 }
119
120 if (!IS_GENERATOR_TYPE_DT (Generator->GeneratorID)) {
121 DEBUG ((
122 DEBUG_ERROR,
123 "ERROR: DT register - Generator" \
124 " Type is not DT\n"
125 ));
126 return EFI_INVALID_PARAMETER;
127 }
128
129 DEBUG ((DEBUG_INFO, "Registering %s\n", Generator->Description));
130
131 TableId = GET_TABLE_ID (Generator->GeneratorID);
132 if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) {
133 if (TableId >= EStdDtTableIdMax) {
134 ASSERT (TableId < EStdDtTableIdMax);
135 return EFI_INVALID_PARAMETER;
136 }
137
138 if (TableFactoryInfo.StdDtTableGeneratorList[TableId] == NULL) {
139 TableFactoryInfo.StdDtTableGeneratorList[TableId] = Generator;
140 } else {
141 return EFI_ALREADY_STARTED;
142 }
143 } else {
144 if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) {
145 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators));
146 return EFI_INVALID_PARAMETER;
147 }
148
149 if (TableFactoryInfo.CustomDtTableGeneratorList[TableId] == NULL) {
150 TableFactoryInfo.CustomDtTableGeneratorList[TableId] = Generator;
151 } else {
152 return EFI_ALREADY_STARTED;
153 }
154 }
155
156 return EFI_SUCCESS;
157 }
158
159 /** Deregister DT generator.
160
161 This function is called by the DT table generator to deregister itself
162 from the DT table factory.
163
164 @param [in] Generator Pointer to the DT table generator.
165
166 @retval EFI_SUCCESS Success.
167 @retval EFI_INVALID_PARAMETER The generator is invalid.
168 @retval EFI_NOT_FOUND The requested generator is not found
169 in the list of registered generators.
170 **/
171 EFI_STATUS
172 EFIAPI
173 DeregisterDtTableGenerator (
174 IN CONST DT_TABLE_GENERATOR *CONST Generator
175 )
176 {
177 UINT16 TableId;
178
179 if (Generator == NULL) {
180 DEBUG ((DEBUG_ERROR, "ERROR: DT deregister - Invalid Generator\n"));
181 return EFI_INVALID_PARAMETER;
182 }
183
184 if (!IS_GENERATOR_TYPE_DT (Generator->GeneratorID)) {
185 DEBUG ((
186 DEBUG_ERROR,
187 "ERROR: DT deregister - Generator" \
188 " Type is not DT\n"
189 ));
190 return EFI_INVALID_PARAMETER;
191 }
192
193 TableId = GET_TABLE_ID (Generator->GeneratorID);
194 if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) {
195 if (TableId >= EStdDtTableIdMax) {
196 ASSERT (TableId < EStdDtTableIdMax);
197 return EFI_INVALID_PARAMETER;
198 }
199
200 if (TableFactoryInfo.StdDtTableGeneratorList[TableId] != NULL) {
201 if (Generator != TableFactoryInfo.StdDtTableGeneratorList[TableId]) {
202 return EFI_INVALID_PARAMETER;
203 }
204
205 TableFactoryInfo.StdDtTableGeneratorList[TableId] = NULL;
206 } else {
207 return EFI_NOT_FOUND;
208 }
209 } else {
210 if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) {
211 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators));
212 return EFI_INVALID_PARAMETER;
213 }
214
215 if (TableFactoryInfo.CustomDtTableGeneratorList[TableId] != NULL) {
216 if (Generator !=
217 TableFactoryInfo.CustomDtTableGeneratorList[TableId])
218 {
219 return EFI_INVALID_PARAMETER;
220 }
221
222 TableFactoryInfo.CustomDtTableGeneratorList[TableId] = NULL;
223 } else {
224 return EFI_NOT_FOUND;
225 }
226 }
227
228 DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description));
229 return EFI_SUCCESS;
230 }