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