4 Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellDebug1CommandsLib.h"
17 #include <Guid/SmBios.h>
18 #include "LibSmbiosView.h"
19 #include "SmbiosView.h"
21 STATIC UINT8 mInit
= 0;
22 STATIC UINT8 m64Init
= 0;
23 STATIC SMBIOS_TABLE_ENTRY_POINT
*mSmbiosTable
= NULL
;
24 STATIC SMBIOS_TABLE_3_0_ENTRY_POINT
*mSmbios64BitTable
= NULL
;
25 STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct
;
26 STATIC SMBIOS_STRUCTURE_POINTER
*mSmbiosStruct
= &m_SmbiosStruct
;
27 STATIC SMBIOS_STRUCTURE_POINTER m_Smbios64BitStruct
;
28 STATIC SMBIOS_STRUCTURE_POINTER
*mSmbios64BitStruct
= &m_Smbios64BitStruct
;
31 Init the SMBIOS VIEW API's environment.
33 @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
49 // Get SMBIOS table from System Configure table
51 Status
= GetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**)&mSmbiosTable
);
53 if (mSmbiosTable
== NULL
) {
57 if (EFI_ERROR (Status
)) {
58 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR
), gShellDebug1HiiHandle
, Status
);
62 // Init SMBIOS structure table address
64 mSmbiosStruct
->Raw
= (UINT8
*) (UINTN
) (mSmbiosTable
->TableAddress
);
71 Init the SMBIOS VIEW API's environment.
73 @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
89 // Get SMBIOS table from System Configure table
91 Status
= GetSystemConfigurationTable (&gEfiSmbios3TableGuid
, (VOID
**)&mSmbios64BitTable
);
93 if (mSmbios64BitTable
== NULL
) {
97 if (EFI_ERROR (Status
)) {
98 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR
), gShellDebug1HiiHandle
, Status
);
102 // Init SMBIOS structure table address
104 mSmbios64BitStruct
->Raw
= (UINT8
*) (UINTN
) (mSmbios64BitTable
->TableAddress
);
111 Cleanup the Smbios information.
121 if (mSmbiosTable
!= NULL
) {
129 Cleanup the Smbios information.
132 LibSmbios64BitCleanup (
139 if (mSmbios64BitTable
!= NULL
) {
140 mSmbios64BitTable
= NULL
;
147 Get the entry point structure for the table.
149 @param[out] EntryPointStructure The pointer to populate.
153 OUT SMBIOS_TABLE_ENTRY_POINT
**EntryPointStructure
157 // return SMBIOS Table address
159 *EntryPointStructure
= mSmbiosTable
;
163 Get the entry point structure for the table.
165 @param[out] EntryPointStructure The pointer to populate.
168 LibSmbios64BitGetEPS (
169 OUT SMBIOS_TABLE_3_0_ENTRY_POINT
**EntryPointStructure
173 // return SMBIOS Table address
175 *EntryPointStructure
= mSmbios64BitTable
;
179 Return SMBIOS string for the given string number.
181 @param[in] Smbios Pointer to SMBIOS structure.
182 @param[in] StringNumber String number to return. -1 is used to skip all strings and
183 point to the next SMBIOS structure.
185 @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
189 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
190 IN UINT16 StringNumber
196 ASSERT (Smbios
!= NULL
);
199 // Skip over formatted section
201 String
= (CHAR8
*) (Smbios
->Raw
+ Smbios
->Hdr
->Length
);
204 // Look through unformated section
206 for (Index
= 1; Index
<= StringNumber
; Index
++) {
207 if (StringNumber
== Index
) {
213 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
;
293 // Walk to next structure
295 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
298 *Handle
= INVALID_HANDLE
;
299 return DMI_INVALID_HANDLE
;
303 Get SMBIOS structure for the given Handle,
304 Handle is changed to the next handle or 0xFFFF when the end is
305 reached or the handle is not found.
307 @param[in, out] Handle 0xFFFF: get the first structure
308 Others: get a structure according to this value.
309 @param[out] Buffer The pointer to the pointer to the structure.
310 @param[out] Length Length of the structure.
312 @retval DMI_SUCCESS Handle is updated with next structure handle or
315 @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or
319 LibGetSmbios64BitStructure (
320 IN OUT UINT16
*Handle
,
325 SMBIOS_STRUCTURE_POINTER Smbios
;
326 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
329 if (*Handle
== INVALID_HANDLE
) {
330 *Handle
= mSmbios64BitStruct
->Hdr
->Handle
;
331 return DMI_INVALID_HANDLE
;
334 if ((Buffer
== NULL
) || (Length
== NULL
)) {
335 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC
), gShellDebug1HiiHandle
);
336 return DMI_INVALID_HANDLE
;
340 Smbios
.Hdr
= mSmbios64BitStruct
->Hdr
;
342 SmbiosEnd
.Raw
= Smbios
.Raw
+ mSmbios64BitTableLength
;
343 while (Smbios
.Raw
< SmbiosEnd
.Raw
) {
344 if (Smbios
.Hdr
->Handle
== *Handle
) {
347 // Walk to next structure
349 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
351 // Length = Next structure head - this structure head
353 *Length
= (UINT16
) (Smbios
.Raw
- Raw
);
356 // update with the next structure handle.
358 if (Smbios
.Raw
< SmbiosEnd
.Raw
) {
359 *Handle
= Smbios
.Hdr
->Handle
;
361 *Handle
= INVALID_HANDLE
;
366 // Walk to next structure
368 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
371 *Handle
= INVALID_HANDLE
;
372 return DMI_INVALID_HANDLE
;