4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "UefiShellDebug1CommandsLib.h"
10 #include <Guid/SmBios.h>
11 #include "LibSmbiosView.h"
12 #include "SmbiosView.h"
14 STATIC UINT8 mInit
= 0;
15 STATIC UINT8 m64Init
= 0;
16 STATIC SMBIOS_TABLE_ENTRY_POINT
*mSmbiosTable
= NULL
;
17 STATIC SMBIOS_TABLE_3_0_ENTRY_POINT
*mSmbios64BitTable
= NULL
;
18 STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct
;
19 STATIC SMBIOS_STRUCTURE_POINTER
*mSmbiosStruct
= &m_SmbiosStruct
;
20 STATIC SMBIOS_STRUCTURE_POINTER m_Smbios64BitStruct
;
21 STATIC SMBIOS_STRUCTURE_POINTER
*mSmbios64BitStruct
= &m_Smbios64BitStruct
;
24 Init the SMBIOS VIEW API's environment.
26 @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
43 // Get SMBIOS table from System Configure table
45 Status
= GetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**)&mSmbiosTable
);
47 if (mSmbiosTable
== NULL
) {
51 if (EFI_ERROR (Status
)) {
52 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR
), gShellDebug1HiiHandle
, Status
);
57 // Init SMBIOS structure table address
59 mSmbiosStruct
->Raw
= (UINT8
*)(UINTN
)(mSmbiosTable
->TableAddress
);
66 Init the SMBIOS VIEW API's environment.
68 @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
85 // Get SMBIOS table from System Configure table
87 Status
= GetSystemConfigurationTable (&gEfiSmbios3TableGuid
, (VOID
**)&mSmbios64BitTable
);
89 if (mSmbios64BitTable
== NULL
) {
93 if (EFI_ERROR (Status
)) {
94 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR
), gShellDebug1HiiHandle
, Status
);
99 // Init SMBIOS structure table address
101 mSmbios64BitStruct
->Raw
= (UINT8
*)(UINTN
)(mSmbios64BitTable
->TableAddress
);
108 Cleanup the Smbios information.
118 if (mSmbiosTable
!= NULL
) {
126 Cleanup the Smbios information.
129 LibSmbios64BitCleanup (
136 if (mSmbios64BitTable
!= NULL
) {
137 mSmbios64BitTable
= NULL
;
144 Get the entry point structure for the table.
146 @param[out] EntryPointStructure The pointer to populate.
150 OUT SMBIOS_TABLE_ENTRY_POINT
**EntryPointStructure
154 // return SMBIOS Table address
156 *EntryPointStructure
= mSmbiosTable
;
160 Get the entry point structure for the table.
162 @param[out] EntryPointStructure The pointer to populate.
165 LibSmbios64BitGetEPS (
166 OUT SMBIOS_TABLE_3_0_ENTRY_POINT
**EntryPointStructure
170 // return SMBIOS Table address
172 *EntryPointStructure
= mSmbios64BitTable
;
176 Return SMBIOS string for the given string number.
178 @param[in] Smbios Pointer to SMBIOS structure.
179 @param[in] StringNumber String number to return. -1 is used to skip all strings and
180 point to the next SMBIOS structure.
182 @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
186 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
187 IN UINT16 StringNumber
193 ASSERT (Smbios
!= NULL
);
196 // Skip over formatted section
198 String
= (CHAR8
*)(Smbios
->Raw
+ Smbios
->Hdr
->Length
);
201 // Look through unformated section
203 for (Index
= 1; Index
<= StringNumber
; Index
++) {
204 if (StringNumber
== Index
) {
211 for ( ; *String
!= 0; String
++) {
218 // If double NULL then we are done.
219 // Return pointer to next structure in Smbios.
220 // if you pass in a -1 you will always get here
222 Smbios
->Raw
= (UINT8
*)++String
;
231 Get SMBIOS structure for the given Handle,
232 Handle is changed to the next handle or 0xFFFF when the end is
233 reached or the handle is not found.
235 @param[in, out] Handle 0xFFFF: get the first structure
236 Others: get a structure according to this value.
237 @param[out] Buffer The pointer to the pointer to the structure.
238 @param[out] Length Length of the structure.
240 @retval DMI_SUCCESS Handle is updated with next structure handle or
243 @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or
247 LibGetSmbiosStructure (
248 IN OUT UINT16
*Handle
,
253 SMBIOS_STRUCTURE_POINTER Smbios
;
254 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
257 if (*Handle
== INVALID_HANDLE
) {
258 *Handle
= mSmbiosStruct
->Hdr
->Handle
;
259 return DMI_INVALID_HANDLE
;
262 if ((Buffer
== NULL
) || (Length
== NULL
)) {
263 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC
), gShellDebug1HiiHandle
);
264 return DMI_INVALID_HANDLE
;
268 Smbios
.Hdr
= mSmbiosStruct
->Hdr
;
269 SmbiosEnd
.Raw
= Smbios
.Raw
+ mSmbiosTable
->TableLength
;
270 while (Smbios
.Raw
< SmbiosEnd
.Raw
) {
271 if (Smbios
.Hdr
->Handle
== *Handle
) {
274 // Walk to next structure
276 LibGetSmbiosString (&Smbios
, (UINT16
)(-1));
278 // Length = Next structure head - this structure head
280 *Length
= (UINT16
)(Smbios
.Raw
- Raw
);
283 // update with the next structure handle.
285 if (Smbios
.Raw
< SmbiosEnd
.Raw
) {
286 *Handle
= Smbios
.Hdr
->Handle
;
288 *Handle
= INVALID_HANDLE
;
295 // Walk to next structure
297 LibGetSmbiosString (&Smbios
, (UINT16
)(-1));
300 *Handle
= INVALID_HANDLE
;
301 return DMI_INVALID_HANDLE
;
305 Get SMBIOS structure for the given Handle,
306 Handle is changed to the next handle or 0xFFFF when the end is
307 reached or the handle is not found.
309 @param[in, out] Handle 0xFFFF: get the first structure
310 Others: get a structure according to this value.
311 @param[out] Buffer The pointer to the pointer to the structure.
312 @param[out] Length Length of the structure.
314 @retval DMI_SUCCESS Handle is updated with next structure handle or
317 @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or
321 LibGetSmbios64BitStructure (
322 IN OUT UINT16
*Handle
,
327 SMBIOS_STRUCTURE_POINTER Smbios
;
328 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
331 if (*Handle
== INVALID_HANDLE
) {
332 *Handle
= mSmbios64BitStruct
->Hdr
->Handle
;
333 return DMI_INVALID_HANDLE
;
336 if ((Buffer
== NULL
) || (Length
== NULL
)) {
337 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC
), gShellDebug1HiiHandle
);
338 return DMI_INVALID_HANDLE
;
342 Smbios
.Hdr
= mSmbios64BitStruct
->Hdr
;
344 SmbiosEnd
.Raw
= Smbios
.Raw
+ mSmbios64BitTableLength
;
345 while (Smbios
.Raw
< SmbiosEnd
.Raw
) {
346 if (Smbios
.Hdr
->Handle
== *Handle
) {
349 // Walk to next structure
351 LibGetSmbiosString (&Smbios
, (UINT16
)(-1));
353 // Length = Next structure head - this structure head
355 *Length
= (UINT16
)(Smbios
.Raw
- Raw
);
358 // update with the next structure handle.
360 if (Smbios
.Raw
< SmbiosEnd
.Raw
) {
361 *Handle
= Smbios
.Hdr
->Handle
;
363 *Handle
= INVALID_HANDLE
;
370 // Walk to next structure
372 LibGetSmbiosString (&Smbios
, (UINT16
)(-1));
375 *Handle
= INVALID_HANDLE
;
376 return DMI_INVALID_HANDLE
;