4 Copyright (c) 2005 - 2012, 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 SMBIOS_TABLE_ENTRY_POINT
*mSmbiosTable
= NULL
;
23 STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct
;
24 STATIC SMBIOS_STRUCTURE_POINTER
*mSmbiosStruct
= &m_SmbiosStruct
;
27 Init the SMBIOS VIEW API's environment.
29 @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
45 // Get SMBIOS table from System Configure table
47 Status
= GetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**)&mSmbiosTable
);
49 if (mSmbiosTable
== NULL
) {
50 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE
), gShellDebug1HiiHandle
);
54 if (EFI_ERROR (Status
)) {
55 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR
), gShellDebug1HiiHandle
, Status
);
59 // Init SMBIOS structure table address
61 mSmbiosStruct
->Raw
= (UINT8
*) (UINTN
) (mSmbiosTable
->TableAddress
);
68 Cleanup the Smbios information.
78 if (mSmbiosTable
!= NULL
) {
86 Get the entry point structure for the table.
88 @param[out] EntryPointStructure The pointer to populate.
92 OUT SMBIOS_TABLE_ENTRY_POINT
**EntryPointStructure
96 // return SMBIOS Table address
98 *EntryPointStructure
= mSmbiosTable
;
102 Return SMBIOS string for the given string number.
104 @param[in] Smbios Pointer to SMBIOS structure.
105 @param[in] StringNumber String number to return. -1 is used to skip all strings and
106 point to the next SMBIOS structure.
108 @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
112 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
113 IN UINT16 StringNumber
119 ASSERT (Smbios
!= NULL
);
122 // Skip over formatted section
124 String
= (CHAR8
*) (Smbios
->Raw
+ Smbios
->Hdr
->Length
);
127 // Look through unformated section
129 for (Index
= 1; Index
<= StringNumber
; Index
++) {
130 if (StringNumber
== Index
) {
136 for (; *String
!= 0; String
++);
141 // If double NULL then we are done.
142 // Return pointer to next structure in Smbios.
143 // if you pass in a -1 you will always get here
145 Smbios
->Raw
= (UINT8
*)++String
;
154 Get SMBIOS structure for the given Handle,
155 Handle is changed to the next handle or 0xFFFF when the end is
156 reached or the handle is not found.
158 @param[in, out] Handle 0xFFFF: get the first structure
159 Others: get a structure according to this value.
160 @param[out] Buffer The pointer to the pointer to the structure.
161 @param[out] Length Length of the structure.
163 @retval DMI_SUCCESS Handle is updated with next structure handle or
166 @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or
170 LibGetSmbiosStructure (
171 IN OUT UINT16
*Handle
,
176 SMBIOS_STRUCTURE_POINTER Smbios
;
177 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
180 if (*Handle
== INVALID_HANDLE
) {
181 *Handle
= mSmbiosStruct
->Hdr
->Handle
;
182 return DMI_INVALID_HANDLE
;
185 if ((Buffer
== NULL
) || (Length
== NULL
)) {
186 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC
), gShellDebug1HiiHandle
);
187 return DMI_INVALID_HANDLE
;
191 Smbios
.Hdr
= mSmbiosStruct
->Hdr
;
192 SmbiosEnd
.Raw
= Smbios
.Raw
+ mSmbiosTable
->TableLength
;
193 while (Smbios
.Raw
< SmbiosEnd
.Raw
) {
194 if (Smbios
.Hdr
->Handle
== *Handle
) {
197 // Walk to next structure
199 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
201 // Length = Next structure head - this structure head
203 *Length
= (UINT16
) (Smbios
.Raw
- Raw
);
206 // update with the next structure handle.
208 if (Smbios
.Raw
< SmbiosEnd
.Raw
) {
209 *Handle
= Smbios
.Hdr
->Handle
;
211 *Handle
= INVALID_HANDLE
;
216 // Walk to next structure
218 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
221 *Handle
= INVALID_HANDLE
;
222 return DMI_INVALID_HANDLE
;