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