4 Copyright (c) 2005 - 2011, 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 "LIbSmbios.h"
19 #include "LibSmbiosView.h"
20 #include "SmbiosView.h"
22 STATIC UINT8 mInit
= 0;
23 STATIC SMBIOS_STRUCTURE_TABLE
*mSmbiosTable
= NULL
;
24 STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct
;
25 STATIC SMBIOS_STRUCTURE_POINTER
*mSmbiosStruct
= &m_SmbiosStruct
;
28 Init the SMBIOS VIEW API's environment.
30 @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
46 // Get SMBIOS table from System Configure table
48 Status
= GetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**)&mSmbiosTable
);
50 if (mSmbiosTable
== NULL
) {
51 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE
), gShellDebug1HiiHandle
);
55 if (EFI_ERROR (Status
)) {
56 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR
), gShellDebug1HiiHandle
, Status
);
60 // Init SMBIOS structure table address
62 mSmbiosStruct
->Raw
= (UINT8
*) (UINTN
) (mSmbiosTable
->TableAddress
);
69 Cleanup the Smbios information.
79 if (mSmbiosTable
!= NULL
) {
87 Get the entry point structure for the table.
89 @param[out] EntryPointStructure The pointer to populate.
93 OUT SMBIOS_STRUCTURE_TABLE
**EntryPointStructure
97 // return SMBIOS Table address
99 *EntryPointStructure
= mSmbiosTable
;
103 Get SMBIOS structure given the Handle,copy data to the Buffer,
104 Handle is changed to the next handle or 0xFFFF when the end is
105 reached or the handle is not found.
107 @param[in,out] Handle 0xFFFF: get the first structure
108 Others: get a structure according to this value.
109 @param[in,out] Buffer The pointer to the caller's memory buffer.
110 @param[out] Length Length of return buffer in bytes.
112 @retval DMI_SUCCESS Buffer contains the required structure data
113 Handle is updated with next structure handle or
116 @retval DMI_INVALID_HANDLE Buffer not contain the requiring structure data.
117 Handle is updated with next structure handle or
121 LibGetSmbiosStructure (
122 IN OUT UINT16
*Handle
,
123 IN OUT UINT8
*Buffer
,
127 SMBIOS_STRUCTURE_POINTER Smbios
;
128 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
131 if (*Handle
== INVALIDE_HANDLE
) {
132 *Handle
= mSmbiosStruct
->Hdr
->Handle
;
133 return DMI_INVALID_HANDLE
;
136 if (Buffer
== NULL
) {
137 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_SPEC
), gShellDebug1HiiHandle
);
138 return DMI_INVALID_HANDLE
;
142 Smbios
.Hdr
= mSmbiosStruct
->Hdr
;
143 SmbiosEnd
.Raw
= Smbios
.Raw
+ mSmbiosTable
->TableLength
;
144 while (Smbios
.Raw
< SmbiosEnd
.Raw
) {
145 if (Smbios
.Hdr
->Handle
== *Handle
) {
148 // Walk to next structure
150 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
152 // Length = Next structure head - this structure head
154 *Length
= (UINT16
) (Smbios
.Raw
- Raw
);
155 CopyMem (Buffer
, Raw
, *Length
);
157 // update with the next structure handle.
159 if (Smbios
.Raw
< SmbiosEnd
.Raw
) {
160 *Handle
= Smbios
.Hdr
->Handle
;
162 *Handle
= INVALIDE_HANDLE
;
167 // Walk to next structure
169 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
172 *Handle
= INVALIDE_HANDLE
;
173 return DMI_INVALID_HANDLE
;
177 Check the structure to see if it is legal.
179 @param[in] Smbios - Pointer to the structure that will be checked.
181 @retval DMI_SUCCESS Structure data is legal.
182 @retval DMI_BAD_PARAMETER Structure data contains bad parameter.
185 SmbiosCheckStructure (
186 IN SMBIOS_STRUCTURE_POINTER
*Smbios
190 // If key != value, then error.
192 #define CHECK_VALUE(key, value) (((key) == (value)) ? EFI_SUCCESS : DMI_BAD_PARAMETER)
196 // Assume staus is EFI_SUCCESS,
197 // but if check is error, then EFI_ERROR.
199 Status
= EFI_SUCCESS
;
201 switch (Smbios
->Hdr
->Type
) {
206 if (Smbios
->Type1
->Hdr
.Length
== 0x08 || Smbios
->Type0
->Hdr
.Length
== 0x19) {
207 Status
= EFI_SUCCESS
;
209 Status
= DMI_BAD_PARAMETER
;
214 Status
= CHECK_VALUE (Smbios
->Type2
->Hdr
.Length
, 0x08);
218 Status
= CHECK_VALUE (Smbios
->Type6
->Hdr
.Length
, 0x0C);
222 Status
= CHECK_VALUE (Smbios
->Type11
->Hdr
.Length
, 0x05);
226 Status
= CHECK_VALUE (Smbios
->Type12
->Hdr
.Length
, 0x05);
230 Status
= CHECK_VALUE (Smbios
->Type13
->Hdr
.Length
, 0x16);
234 Status
= CHECK_VALUE (Smbios
->Type16
->Hdr
.Length
, 0x0F);
238 Status
= CHECK_VALUE (Smbios
->Type19
->Hdr
.Length
, 0x0F);
242 Status
= CHECK_VALUE (Smbios
->Type20
->Hdr
.Length
, 0x13);
247 // Because EFI_SUCCESS == 0,
248 // So errors added up is also error.
250 Status
= CHECK_VALUE (Smbios
->Type32
->Reserved
[0], 0x00) +
251 CHECK_VALUE (Smbios
->Type32
->Reserved
[1], 0x00) +
252 CHECK_VALUE (Smbios
->Type32
->Reserved
[2], 0x00) +
253 CHECK_VALUE (Smbios
->Type32
->Reserved
[3], 0x00) +
254 CHECK_VALUE (Smbios
->Type32
->Reserved
[4], 0x00) +
255 CHECK_VALUE (Smbios
->Type32
->Reserved
[5], 0x00);
259 Status
= DMI_BAD_PARAMETER
;
266 Get a string from the smbios information.
268 @param[in] Smbios The pointer to the smbios information.
269 @param[in] StringNumber The index to the string to get.
270 @param[out] Buffer The buffer to fill with the string when retrieved.
273 SmbiosGetPendingString (
274 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
275 IN UINT16 StringNumber
,
280 if (Buffer
== NULL
) {
281 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUF_SPEC_WHEN_STRUCT
), gShellDebug1HiiHandle
);
285 // Get string and copy to buffer.
286 // Caller should provide the buffer.
288 String
= LibGetSmbiosString (Smbios
, StringNumber
);
289 if (String
!= NULL
) {
290 CopyMem (Buffer
, String
, AsciiStrLen(String
));