2 Provides library functions for common SMBIOS operations. Only available to DXE
6 Copyright (c) 2012, Apple Inc. All rights reserved.
7 Portitions Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available under
9 the terms and conditions of the BSD License that accompanies this distribution.
10 The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php.
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/SmbiosLib.h>
28 EFI_SMBIOS_PROTOCOL
*gSmbios
= NULL
;
33 InitializeSmbiosTableFromTemplate (
34 IN SMBIOS_TEMPLATE_ENTRY
*Template
40 if (Template
== NULL
) {
41 return EFI_INVALID_PARAMETER
;
44 for (Index
= 0; Template
[Index
].Entry
!= NULL
; Index
++) {
45 Status
= CreateSmbiosEntry (Template
[Index
].Entry
, Template
[Index
].StringArray
);
56 Converts a fixed SMBIOS structure and an array of pointers to strings into
57 an SMBIOS record where the strings are cat'ed on the end of the fixed record
58 and terminated via a double NULL and add to SMBIOS table.
60 SMBIOS_TABLE_TYPE32 gSmbiosType12 = {
61 { EFI_SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS, sizeof (SMBIOS_TABLE_TYPE12), 0 },
64 CHAR8 *gSmbiosType12Strings[] = {
71 (EFI_SMBIOS_TABLE_HEADER*)&gSmbiosType12,
75 @param SmbiosEntry Fixed SMBIOS structure
76 @param StringArray Array of strings to convert to an SMBIOS string pack.
83 IN SMBIOS_STRUCTURE
*SmbiosEntry
,
84 IN CHAR8
**StringArray
88 EFI_SMBIOS_HANDLE SmbiosHandle
;
89 EFI_SMBIOS_TABLE_HEADER
*Record
;
95 // Calculate the size of the fixed record and optional string pack
96 Size
= SmbiosEntry
->Length
;
97 if (StringArray
== NULL
) {
98 Size
+= 2; // Min string section is double null
99 } else if (StringArray
[0] == NULL
) {
100 Size
+= 2; // Min string section is double null
102 for (Index
= 0; StringArray
[Index
] != NULL
; Index
++) {
103 StringSize
= AsciiStrSize (StringArray
[Index
]);
106 // Don't forget the terminating double null
110 // Copy over Template
111 Record
= (EFI_SMBIOS_TABLE_HEADER
*)AllocateZeroPool (Size
);
112 if (Record
== NULL
) {
113 return EFI_OUT_OF_RESOURCES
;
115 CopyMem (Record
, SmbiosEntry
, SmbiosEntry
->Length
);
117 if (StringArray
!= NULL
) {
118 // Append string pack
119 Str
= ((CHAR8
*)Record
) + Record
->Length
;
120 for (Index
= 0; StringArray
[Index
] != NULL
; Index
++) {
121 StringSize
= AsciiStrSize (StringArray
[Index
]);
122 CopyMem (Str
, StringArray
[Index
], StringSize
);
128 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
129 Status
= gSmbios
->Add (
143 Update the string associated with an existing SMBIOS record.
145 This function allows the update of specific SMBIOS strings. The number of valid strings for any
146 SMBIOS record is defined by how many strings were present when Add() was called.
148 @param[in] SmbiosHandle SMBIOS Handle of structure that will have its string updated.
149 @param[in] StringNumber The non-zero string number of the string to update.
150 @param[in] String Update the StringNumber string with String.
152 @retval EFI_SUCCESS SmbiosHandle had its StringNumber String updated.
153 @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist. Or String is invalid.
154 @retval EFI_UNSUPPORTED String was not added because it is longer than the SMBIOS Table supports.
155 @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMBIOS record.
160 IN EFI_SMBIOS_HANDLE SmbiosHandle
,
161 IN SMBIOS_TABLE_STRING StringNumber
,
167 if (String
== NULL
) {
168 return EFI_INVALID_PARAMETER
;
171 if (*String
== '\0') {
172 // A string with no data is not legal in SMBIOS
173 return EFI_INVALID_PARAMETER
;
176 StringIndex
= StringNumber
;
177 return gSmbios
->UpdateString (gSmbios
, &SmbiosHandle
, &StringIndex
, String
);
182 Update the string associated with an existing SMBIOS record.
184 This function allows the update of specific SMBIOS strings. The number of valid strings for any
185 SMBIOS record is defined by how many strings were present when Add() was called.
187 @param[in] SmbiosHandle SMBIOS Handle of structure that will have its string updated.
188 @param[in] StringNumber The non-zero string number of the string to update.
189 @param[in] String Update the StringNumber string with String.
191 @retval EFI_SUCCESS SmbiosHandle had its StringNumber String updated.
192 @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist. Or String is invalid.
193 @retval EFI_UNSUPPORTED String was not added because it is longer than the SMBIOS Table supports.
194 @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMBIOS record.
198 SmbiosUpdateUnicodeString (
199 IN EFI_SMBIOS_HANDLE SmbiosHandle
,
200 IN SMBIOS_TABLE_STRING StringNumber
,
208 if (String
== NULL
) {
209 return EFI_INVALID_PARAMETER
;
212 if (*String
== '\0') {
213 // A string with no data is not legal in SMBIOS
214 return EFI_INVALID_PARAMETER
;
217 Ascii
= AllocateZeroPool (StrSize (String
));
219 return EFI_OUT_OF_RESOURCES
;
221 UnicodeStrToAsciiStr (String
, Ascii
);
223 StringIndex
= StringNumber
;
224 Status
= gSmbios
->UpdateString (gSmbios
, &SmbiosHandle
, &StringIndex
, Ascii
);
232 Allow caller to read a specific SMBIOS string
234 @param[in] Header SMBIOS record that contains the string.
235 @param[in[ Intance Instance of SMBIOS string 0 - N-1.
237 @retval NULL Instance of Type SMBIOS string was not found.
238 @retval Other Pointer to matching SMBIOS string.
242 IN SMBIOS_STRUCTURE
*Header
,
249 Data
= (CHAR8
*)Header
+ Header
->Length
;
250 for (NullCount
= 0;!(*Data
== 0 && *(Data
+1) == 0); ) {
251 if (Instance
== NullCount
) {
255 if (*(Data
- 1) == '\0') {
265 Allow the caller to discover a specific SMBIOS entry, and patch it if necissary.
267 @param[in] Type Type of the next SMBIOS record to return.
268 @param[in[ Instance Instance of SMBIOS record 0 - N-1.
269 @param[out] SmbiosHandle Returns SMBIOS handle for the matching record.
271 @retval NULL Instance of Type SMBIOS record was not found.
272 @retval Other Pointer to matching SMBIOS record.
277 IN EFI_SMBIOS_TYPE Type
,
279 OUT EFI_SMBIOS_HANDLE
*SmbiosHandle
283 EFI_SMBIOS_TABLE_HEADER
*Record
;
287 *SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
289 Status
= gSmbios
->GetNext (gSmbios
, SmbiosHandle
, &Type
, &Record
, NULL
);
290 if (!EFI_ERROR (Status
)) {
291 if (Match
== Instance
) {
292 return (SMBIOS_STRUCTURE
*)Record
;
296 } while (!EFI_ERROR (Status
));
303 Remove an SMBIOS record.
305 This function removes an SMBIOS record using the handle specified by SmbiosHandle.
307 @param[in] SmbiosHandle The handle of the SMBIOS record to remove.
309 @retval EFI_SUCCESS SMBIOS record was removed.
310 @retval EFI_INVALID_PARAMETER SmbiosHandle does not specify a valid SMBIOS record.
315 OUT EFI_SMBIOS_HANDLE SmbiosHandle
318 return gSmbios
->Remove (gSmbios
, SmbiosHandle
);
325 OUT UINT8
*SmbiosMajorVersion
,
326 OUT UINT8
*SmbiosMinorVersion
329 if (SmbiosMajorVersion
!= NULL
) {
330 *SmbiosMajorVersion
= gSmbios
->MajorVersion
;
332 if (SmbiosMinorVersion
!= NULL
) {
333 *SmbiosMinorVersion
= gSmbios
->MinorVersion
;
342 @param ImageHandle ImageHandle of the loaded driver.
343 @param SystemTable Pointer to the EFI System Table.
345 @retval EFI_SUCCESS Register successfully.
346 @retval EFI_OUT_OF_RESOURCES No enough memory to register this handler.
350 SmbiosLibConstructor (
351 IN EFI_HANDLE ImageHandle
,
352 IN EFI_SYSTEM_TABLE
*SystemTable
355 return gBS
->LocateProtocol (&gEfiSmbiosProtocolGuid
, NULL
, (VOID
**)&gSmbios
);