]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DeviceTreeTableFactory/DeviceTreeTableFactory.c
98b7e70fc1557b7c8f7159bfc50c4b971f51f89a
[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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 @par Glossary:
15 - Std - Standard
16 **/
17
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/DebugLib.h>
21
22 // Module specific include files.
23 #include <DeviceTreeTableGenerator.h>
24 #include <ConfigurationManagerObject.h>
25 #include <Protocol/ConfigurationManagerProtocol.h>
26 #include <Protocol/DynamicTableFactoryProtocol.h>
27
28 #include "DynamicTableFactory.h"
29
30 extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo;
31
32 /** Return a pointer to the DT table generator.
33
34 @param [in] This Pointer to the Dynamic Table Factory Protocol.
35 @param [in] GeneratorId The DT table generator ID for the
36 requested generator.
37 @param [out] Generator Pointer to the requested DT table
38 generator.
39
40 @retval EFI_SUCCESS Success.
41 @retval EFI_INVALID_PARAMETER A parameter is invalid.
42 @retval EFI_NOT_FOUND The requested generator is not found
43 in the list of registered generators.
44 **/
45 EFI_STATUS
46 EFIAPI
47 GetDtTableGenerator (
48 IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * CONST This,
49 IN CONST DT_TABLE_GENERATOR_ID GeneratorId,
50 OUT CONST DT_TABLE_GENERATOR ** CONST Generator
51 )
52 {
53 UINT16 TableId;
54 EDKII_DYNAMIC_TABLE_FACTORY_INFO * FactoryInfo;
55
56 ASSERT (This != NULL);
57
58 FactoryInfo = This->TableFactoryInfo;
59
60 if (Generator == NULL) {
61 DEBUG ((DEBUG_ERROR, "ERROR: Invalid Generator pointer\n"));
62 return EFI_INVALID_PARAMETER;
63 }
64
65 if (!IS_GENERATOR_TYPE_DT (GeneratorId)) {
66 DEBUG ((DEBUG_ERROR, "ERROR: Generator Type is not DT\n"));
67 return EFI_INVALID_PARAMETER;
68 }
69
70 *Generator = NULL;
71 TableId = GET_TABLE_ID (GeneratorId);
72 if (IS_GENERATOR_NAMESPACE_STD (GeneratorId)) {
73 if (TableId >= EStdDtTableIdMax) {
74 ASSERT (TableId < EStdDtTableIdMax);
75 return EFI_INVALID_PARAMETER;
76 }
77 if (FactoryInfo->StdDtTableGeneratorList[TableId] != NULL) {
78 *Generator = FactoryInfo->StdDtTableGeneratorList[TableId];
79 } else {
80 return EFI_NOT_FOUND;
81 }
82 } else {
83 if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) {
84 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators));
85 return EFI_INVALID_PARAMETER;
86 }
87 if (FactoryInfo->CustomDtTableGeneratorList[TableId] != NULL) {
88 *Generator = FactoryInfo->CustomDtTableGeneratorList[TableId];
89 } else {
90 return EFI_NOT_FOUND;
91 }
92 }
93 return EFI_SUCCESS;
94 }
95
96 /** Register DT table factory generator.
97
98 The DT table factory maintains a list of the Standard and OEM DT
99 table generators.
100
101 @param [in] Generator Pointer to the DT table generator.
102
103 @retval EFI_SUCCESS The Generator was registered
104 successfully.
105 @retval EFI_INVALID_PARAMETER The Generator ID is invalid or
106 the Generator pointer is NULL.
107 @retval EFI_ALREADY_STARTED The Generator for the Table ID is
108 already registered.
109 **/
110 EFI_STATUS
111 EFIAPI
112 RegisterDtTableGenerator (
113 IN CONST DT_TABLE_GENERATOR * CONST Generator
114 )
115 {
116 UINT16 TableId;
117
118 if (Generator == NULL) {
119 DEBUG ((DEBUG_ERROR, "ERROR: DT register - Invalid Generator\n"));
120 return EFI_INVALID_PARAMETER;
121 }
122
123 if (!IS_GENERATOR_TYPE_DT (Generator->GeneratorID)) {
124 DEBUG ((
125 DEBUG_ERROR,
126 "ERROR: DT register - Generator" \
127 " Type is not DT\n"
128 ));
129 return EFI_INVALID_PARAMETER;
130 }
131
132 DEBUG ((DEBUG_INFO, "Registering %s\n", Generator->Description));
133
134 TableId = GET_TABLE_ID (Generator->GeneratorID);
135 if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) {
136 if (TableId >= EStdDtTableIdMax) {
137 ASSERT (TableId < EStdDtTableIdMax);
138 return EFI_INVALID_PARAMETER;
139 }
140 if (TableFactoryInfo.StdDtTableGeneratorList[TableId] == NULL) {
141 TableFactoryInfo.StdDtTableGeneratorList[TableId] = Generator;
142 } else {
143 return EFI_ALREADY_STARTED;
144 }
145 } else {
146 if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) {
147 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators));
148 return EFI_INVALID_PARAMETER;
149 }
150 if (TableFactoryInfo.CustomDtTableGeneratorList[TableId] == NULL) {
151 TableFactoryInfo.CustomDtTableGeneratorList[TableId] = Generator;
152 } else {
153 return EFI_ALREADY_STARTED;
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 if (TableFactoryInfo.StdDtTableGeneratorList[TableId] != NULL) {
200 if (Generator != TableFactoryInfo.StdDtTableGeneratorList[TableId]) {
201 return EFI_INVALID_PARAMETER;
202 }
203 TableFactoryInfo.StdDtTableGeneratorList[TableId] = NULL;
204 } else {
205 return EFI_NOT_FOUND;
206 }
207 } else {
208 if (TableId > FixedPcdGet16 (PcdMaxCustomDTGenerators)) {
209 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomDTGenerators));
210 return EFI_INVALID_PARAMETER;
211 }
212 if (TableFactoryInfo.CustomDtTableGeneratorList[TableId] != NULL) {
213 if (Generator !=
214 TableFactoryInfo.CustomDtTableGeneratorList[TableId]) {
215 return EFI_INVALID_PARAMETER;
216 }
217 TableFactoryInfo.CustomDtTableGeneratorList[TableId] = NULL;
218 } else {
219 return EFI_NOT_FOUND;
220 }
221 }
222
223 DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description));
224 return EFI_SUCCESS;
225 }