4 Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
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
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.
18 #include <IndustryStandard/SmBios.h>
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/DebugLib.h>
23 // Module specific include files.
24 #include <SmbiosTableGenerator.h>
25 #include <ConfigurationManagerObject.h>
26 #include <Protocol/ConfigurationManagerProtocol.h>
27 #include <Protocol/DynamicTableFactoryProtocol.h>
29 #include "DynamicTableFactory.h"
31 extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo
;
33 /** Return a pointer to the SMBIOS table generator.
35 @param [in] This Pointer to the Dynamic Table Factory Protocol.
36 @param [in] GeneratorId The SMBIOS table generator ID for the
38 @param [out] Generator Pointer to the requested SMBIOS table
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.
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
55 EDKII_DYNAMIC_TABLE_FACTORY_INFO
* FactoryInfo
;
57 ASSERT (This
!= NULL
);
59 FactoryInfo
= This
->TableFactoryInfo
;
61 if (Generator
== NULL
) {
62 DEBUG ((DEBUG_ERROR
, "ERROR: Invalid Generator pointer\n"));
63 return EFI_INVALID_PARAMETER
;
66 if (!IS_GENERATOR_TYPE_SMBIOS (GeneratorId
)) {
67 DEBUG ((DEBUG_ERROR
, "ERROR: Generator Type is not SMBIOS\n"));
68 return EFI_INVALID_PARAMETER
;
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
;
78 if (FactoryInfo
->StdSmbiosTableGeneratorList
[TableId
] != NULL
) {
79 *Generator
= FactoryInfo
->StdSmbiosTableGeneratorList
[TableId
];
84 if (TableId
> FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators
)) {
85 ASSERT (TableId
<= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators
));
86 return EFI_INVALID_PARAMETER
;
88 if (FactoryInfo
->CustomSmbiosTableGeneratorList
[TableId
] != NULL
) {
89 *Generator
= FactoryInfo
->CustomSmbiosTableGeneratorList
[TableId
];
97 /** Register SMBIOS table factory generator.
99 The SMBIOS table factory maintains a list of the Standard and OEM SMBIOS
102 @param [in] Generator Pointer to the SMBIOS table generator.
104 @retval EFI_SUCCESS The Generator was registered
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
113 RegisterSmbiosTableGenerator (
114 IN CONST SMBIOS_TABLE_GENERATOR
* CONST Generator
119 if (Generator
== NULL
) {
120 DEBUG ((DEBUG_ERROR
, "ERROR: SMBIOS register - Invalid Generator\n"));
121 return EFI_INVALID_PARAMETER
;
124 if (!IS_GENERATOR_TYPE_SMBIOS (Generator
->GeneratorID
)) {
127 "ERROR: SMBIOS register - Generator" \
128 " Type is not SMBIOS\n"
130 return EFI_INVALID_PARAMETER
;
133 DEBUG ((DEBUG_INFO
, "Registering %s\n", Generator
->Description
));
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
;
141 if (TableFactoryInfo
.StdSmbiosTableGeneratorList
[TableId
] == NULL
) {
142 TableFactoryInfo
.StdSmbiosTableGeneratorList
[TableId
] = Generator
;
144 return EFI_ALREADY_STARTED
;
147 if (TableId
> FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators
)) {
148 ASSERT (TableId
<= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators
));
149 return EFI_INVALID_PARAMETER
;
151 if (TableFactoryInfo
.CustomSmbiosTableGeneratorList
[TableId
] == NULL
) {
152 TableFactoryInfo
.CustomSmbiosTableGeneratorList
[TableId
] = Generator
;
154 return EFI_ALREADY_STARTED
;
160 /** Deregister SMBIOS generator.
162 This function is called by the SMBIOS table generator to deregister itself
163 from the SMBIOS table factory.
165 @param [in] Generator Pointer to the SMBIOS table generator.
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.
174 DeregisterSmbiosTableGenerator (
175 IN CONST SMBIOS_TABLE_GENERATOR
* CONST Generator
180 if (Generator
== NULL
) {
181 DEBUG ((DEBUG_ERROR
, "ERROR: SMBIOS deregister - Invalid Generator\n"));
182 return EFI_INVALID_PARAMETER
;
185 if (!IS_GENERATOR_TYPE_SMBIOS (Generator
->GeneratorID
)) {
188 "ERROR: SMBIOS deregister - Generator" \
189 " Type is not SMBIOS\n"
191 return EFI_INVALID_PARAMETER
;
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
;
200 if (TableFactoryInfo
.StdSmbiosTableGeneratorList
[TableId
] != NULL
) {
201 if (Generator
!= TableFactoryInfo
.StdSmbiosTableGeneratorList
[TableId
]) {
202 return EFI_INVALID_PARAMETER
;
204 TableFactoryInfo
.StdSmbiosTableGeneratorList
[TableId
] = NULL
;
206 return EFI_NOT_FOUND
;
209 if (TableId
> FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators
)) {
210 ASSERT (TableId
<= FixedPcdGet16 (PcdMaxCustomSMBIOSGenerators
));
211 return EFI_INVALID_PARAMETER
;
213 if (TableFactoryInfo
.CustomSmbiosTableGeneratorList
[TableId
] != NULL
) {
215 TableFactoryInfo
.CustomSmbiosTableGeneratorList
[TableId
]) {
216 return EFI_INVALID_PARAMETER
;
218 TableFactoryInfo
.CustomSmbiosTableGeneratorList
[TableId
] = NULL
;
220 return EFI_NOT_FOUND
;
224 DEBUG ((DEBUG_INFO
, "Deregistering %s\n", Generator
->Description
));