]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c
DynamicTablesPkg: Replace BSD License with BSD+Patent License
[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 if (FactoryInfo->StdSmbiosTableGeneratorList[TableId] != NULL) {
73 *Generator = FactoryInfo->StdSmbiosTableGeneratorList[TableId];
74 } else {
75 return EFI_NOT_FOUND;
76 }
77 } else {
78 if (TableId > FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)) {
79 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators));
80 return EFI_INVALID_PARAMETER;
81 }
82 if (FactoryInfo->CustomSmbiosTableGeneratorList[TableId] != NULL) {
83 *Generator = FactoryInfo->CustomSmbiosTableGeneratorList[TableId];
84 } else {
85 return EFI_NOT_FOUND;
86 }
87 }
88 return EFI_SUCCESS;
89 }
90
91 /** Register SMBIOS table factory generator.
92
93 The SMBIOS table factory maintains a list of the Standard and OEM SMBIOS
94 table generators.
95
96 @param [in] Generator Pointer to the SMBIOS table generator.
97
98 @retval EFI_SUCCESS The Generator was registered
99 successfully.
100 @retval EFI_INVALID_PARAMETER The Generator ID is invalid or
101 the Generator pointer is NULL.
102 @retval EFI_ALREADY_STARTED The Generator for the Table ID is
103 already registered.
104 **/
105 EFI_STATUS
106 EFIAPI
107 RegisterSmbiosTableGenerator (
108 IN CONST SMBIOS_TABLE_GENERATOR * CONST Generator
109 )
110 {
111 UINT16 TableId;
112
113 if (Generator == NULL) {
114 DEBUG ((DEBUG_ERROR, "ERROR: SMBIOS register - Invalid Generator\n"));
115 return EFI_INVALID_PARAMETER;
116 }
117
118 if (!IS_GENERATOR_TYPE_SMBIOS (Generator->GeneratorID)) {
119 DEBUG ((
120 DEBUG_ERROR,
121 "ERROR: SMBIOS register - Generator" \
122 " Type is not SMBIOS\n"
123 ));
124 return EFI_INVALID_PARAMETER;
125 }
126
127 DEBUG ((DEBUG_INFO, "Registering %s\n", Generator->Description));
128
129 TableId = GET_TABLE_ID (Generator->GeneratorID);
130 if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) {
131 if (TableId >= EStdSmbiosTableIdMax) {
132 ASSERT (TableId < EStdSmbiosTableIdMax);
133 return EFI_INVALID_PARAMETER;
134 }
135 if (TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] == NULL) {
136 TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] = Generator;
137 } else {
138 return EFI_ALREADY_STARTED;
139 }
140 } else {
141 if (TableId > FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)) {
142 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators));
143 return EFI_INVALID_PARAMETER;
144 }
145 if (TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] == NULL) {
146 TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] = Generator;
147 } else {
148 return EFI_ALREADY_STARTED;
149 }
150 }
151 return EFI_SUCCESS;
152 }
153
154 /** Deregister SMBIOS generator.
155
156 This function is called by the SMBIOS table generator to deregister itself
157 from the SMBIOS table factory.
158
159 @param [in] Generator Pointer to the SMBIOS table generator.
160
161 @retval EFI_SUCCESS Success.
162 @retval EFI_INVALID_PARAMETER The generator is invalid.
163 @retval EFI_NOT_FOUND The requested generator is not found
164 in the list of registered generators.
165 **/
166 EFI_STATUS
167 EFIAPI
168 DeregisterSmbiosTableGenerator (
169 IN CONST SMBIOS_TABLE_GENERATOR * CONST Generator
170 )
171 {
172 UINT16 TableId;
173
174 if (Generator == NULL) {
175 DEBUG ((DEBUG_ERROR, "ERROR: SMBIOS deregister - Invalid Generator\n"));
176 return EFI_INVALID_PARAMETER;
177 }
178
179 if (!IS_GENERATOR_TYPE_SMBIOS (Generator->GeneratorID)) {
180 DEBUG ((
181 DEBUG_ERROR,
182 "ERROR: SMBIOS deregister - Generator" \
183 " Type is not SMBIOS\n"
184 ));
185 return EFI_INVALID_PARAMETER;
186 }
187
188 TableId = GET_TABLE_ID (Generator->GeneratorID);
189 if (IS_GENERATOR_NAMESPACE_STD (Generator->GeneratorID)) {
190 if (TableId >= EStdSmbiosTableIdMax) {
191 ASSERT (TableId < EStdSmbiosTableIdMax);
192 return EFI_INVALID_PARAMETER;
193 }
194 if (TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] != NULL) {
195 if (Generator != TableFactoryInfo.StdSmbiosTableGeneratorList[TableId]) {
196 return EFI_INVALID_PARAMETER;
197 }
198 TableFactoryInfo.StdSmbiosTableGeneratorList[TableId] = NULL;
199 } else {
200 return EFI_NOT_FOUND;
201 }
202 } else {
203 if (TableId > FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators)) {
204 ASSERT (TableId <= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators));
205 return EFI_INVALID_PARAMETER;
206 }
207 if (TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] != NULL) {
208 if (Generator !=
209 TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId]) {
210 return EFI_INVALID_PARAMETER;
211 }
212 TableFactoryInfo.CustomSmbiosTableGeneratorList[TableId] = NULL;
213 } else {
214 return EFI_NOT_FOUND;
215 }
216 }
217
218 DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description));
219 return EFI_SUCCESS;
220 }