4 Copyright (c) 2005 - 2010, 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
;
34 Init the SMBIOS VIEW API's environment.
40 EFI_SUCCESS - Successful to init the SMBIOS VIEW Lib
41 Others - Cannot get SMBIOS Table
54 // Get SMBIOS table from System Configure table
56 Status
= GetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**)&mSmbiosTable
);
58 if (mSmbiosTable
== NULL
) {
59 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE
), gShellDebug1HiiHandle
);
63 if (EFI_ERROR (Status
)) {
64 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR
), gShellDebug1HiiHandle
, Status
);
68 // Init SMBIOS structure table address
70 mSmbiosStruct
->Raw
= (UINT8
*) (UINTN
) (mSmbiosTable
->TableAddress
);
84 if (mSmbiosTable
!= NULL
) {
93 SMBIOS_STRUCTURE_TABLE
**pEntryPointStructure
97 // return SMBIOS Table address
99 *pEntryPointStructure
= mSmbiosTable
;
103 LibSmbiosGetStructHead (
104 SMBIOS_STRUCTURE_POINTER
*pHead
108 // return SMBIOS structure table address
110 pHead
= mSmbiosStruct
;
115 OUT CHAR8
*dmiBIOSRevision
,
116 OUT UINT16
*NumStructures
,
117 OUT UINT16
*StructureSize
,
118 OUT UINT32
*dmiStorageBase
,
119 OUT UINT16
*dmiStorageSize
124 Get SMBIOS Information.
127 dmiBIOSRevision - Revision of the SMBIOS Extensions.
128 NumStructures - Max. Number of Structures the BIOS will return.
129 StructureSize - Size of largest SMBIOS Structure.
130 dmiStorageBase - 32-bit physical base address for memory mapped SMBIOS data.
131 dmiStorageSize - Size of the memory-mapped SMBIOS data.
134 DMI_SUCCESS - successful.
135 DMI_FUNCTION_NOT_SUPPORTED - Does not support SMBIOS calling interface capability.
140 // If no SMIBOS table, unsupported.
142 if (mSmbiosTable
== NULL
) {
143 return DMI_FUNCTION_NOT_SUPPORTED
;
146 *dmiBIOSRevision
= mSmbiosTable
->SmbiosBcdRevision
;
147 *NumStructures
= mSmbiosTable
->NumberOfSmbiosStructures
;
148 *StructureSize
= mSmbiosTable
->MaxStructureSize
;
149 *dmiStorageBase
= mSmbiosTable
->TableAddress
;
150 *dmiStorageSize
= mSmbiosTable
->TableLength
;
156 LibGetSmbiosStructure (
157 IN OUT UINT16
*Handle
,
158 IN OUT UINT8
*Buffer
,
164 Get SMBIOS structure given the Handle,copy data to the Buffer,
165 Handle is changed to the next handle or 0xFFFF when the end is
166 reached or the handle is not found.
169 Handle: - 0xFFFF: get the first structure
170 - Others: get a structure according to this value.
171 Buffter: - The pointer to the caller's memory buffer.
172 Length: - Length of return buffer in bytes.
175 DMI_SUCCESS - Buffer contains the required structure data
176 - Handle is updated with next structure handle or
179 DMI_INVALID_HANDLE - Buffer not contain the requiring structure data
180 - Handle is updated with next structure handle or
184 SMBIOS_STRUCTURE_POINTER Smbios
;
185 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
188 if (*Handle
== INVALIDE_HANDLE
) {
189 *Handle
= mSmbiosStruct
->Hdr
->Handle
;
190 return DMI_INVALID_HANDLE
;
193 if (Buffer
== NULL
) {
194 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_SPEC
), gShellDebug1HiiHandle
);
195 return DMI_INVALID_HANDLE
;
199 Smbios
.Hdr
= mSmbiosStruct
->Hdr
;
200 SmbiosEnd
.Raw
= Smbios
.Raw
+ mSmbiosTable
->TableLength
;
201 while (Smbios
.Raw
< SmbiosEnd
.Raw
) {
202 if (Smbios
.Hdr
->Handle
== *Handle
) {
205 // Walk to next structure
207 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
209 // Length = Next structure head - this structure head
211 *Length
= (UINT16
) (Smbios
.Raw
- Raw
);
212 CopyMem (Buffer
, Raw
, *Length
);
214 // update with the next structure handle.
216 if (Smbios
.Raw
< SmbiosEnd
.Raw
) {
217 *Handle
= Smbios
.Hdr
->Handle
;
219 *Handle
= INVALIDE_HANDLE
;
224 // Walk to next structure
226 LibGetSmbiosString (&Smbios
, (UINT16
) (-1));
229 *Handle
= INVALIDE_HANDLE
;
230 return DMI_INVALID_HANDLE
;
234 SmbiosCheckStructure (
235 IN SMBIOS_STRUCTURE_POINTER
*Smbios
240 Check the structure to see if it is legal.
243 Smbios - Pointer to the structure that will be checked.
246 DMI_SUCCESS - Structure data is legal.
247 DMI_BAD_PARAMETER - Structure data contains bad parameter
252 // If key != value, then error.
254 #define CHECK_VALUE(key, value) (((key) == (value)) ? EFI_SUCCESS : DMI_BAD_PARAMETER)
258 // Assume staus is EFI_SUCCESS,
259 // but if check is error, then EFI_ERROR.
261 Status
= EFI_SUCCESS
;
263 switch (Smbios
->Hdr
->Type
) {
268 if (Smbios
->Type1
->Hdr
.Length
== 0x08 || Smbios
->Type0
->Hdr
.Length
== 0x19) {
269 Status
= EFI_SUCCESS
;
271 Status
= DMI_BAD_PARAMETER
;
276 Status
= CHECK_VALUE (Smbios
->Type2
->Hdr
.Length
, 0x08);
280 Status
= CHECK_VALUE (Smbios
->Type6
->Hdr
.Length
, 0x0C);
284 Status
= CHECK_VALUE (Smbios
->Type11
->Hdr
.Length
, 0x05);
288 Status
= CHECK_VALUE (Smbios
->Type12
->Hdr
.Length
, 0x05);
292 Status
= CHECK_VALUE (Smbios
->Type13
->Hdr
.Length
, 0x16);
296 Status
= CHECK_VALUE (Smbios
->Type16
->Hdr
.Length
, 0x0F);
300 Status
= CHECK_VALUE (Smbios
->Type19
->Hdr
.Length
, 0x0F);
304 Status
= CHECK_VALUE (Smbios
->Type20
->Hdr
.Length
, 0x13);
309 // Because EFI_SUCCESS == 0,
310 // So errors added up is also error.
312 Status
= CHECK_VALUE (Smbios
->Type32
->Reserved
[0], 0x00) +
313 CHECK_VALUE (Smbios
->Type32
->Reserved
[1], 0x00) +
314 CHECK_VALUE (Smbios
->Type32
->Reserved
[2], 0x00) +
315 CHECK_VALUE (Smbios
->Type32
->Reserved
[3], 0x00) +
316 CHECK_VALUE (Smbios
->Type32
->Reserved
[4], 0x00) +
317 CHECK_VALUE (Smbios
->Type32
->Reserved
[5], 0x00);
321 Status
= DMI_BAD_PARAMETER
;
328 SmbiosGetPendingString (
329 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
330 IN UINT16 StringNumber
,
335 if (Buffer
== NULL
) {
336 ShellPrintHiiEx(-1,-1,NULL
,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUF_SPEC_WHEN_STRUCT
), gShellDebug1HiiHandle
);
340 // Get string and copy to buffer.
341 // Caller should provide the buffer.
343 String
= LibGetSmbiosString (Smbios
, StringNumber
);
344 if (String
!= NULL
) {
345 CopyMem (Buffer
, String
, AsciiStrLen(String
));