]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/LibSmbiosView.c
rename a file.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / LibSmbiosView.c
CommitLineData
5d73d92f 1/** @file\r
2 API for SMBIOS table.\r
3\r
4 Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14 \r
15\r
16#include "../UefiShellDebug1CommandsLib.h"\r
17#include <Guid/Smbios.h>\r
18#include "LIbSmbios.h"\r
19#include "LibSmbiosView.h"\r
20#include "smbiosview.h"\r
21\r
22STATIC UINT8 mInit = 0;\r
23STATIC SMBIOS_STRUCTURE_TABLE *mSmbiosTable = NULL;\r
24STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;\r
25STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;\r
26\r
27EFI_STATUS\r
28LibSmbiosInit (\r
29 VOID\r
30 )\r
31/*++\r
32\r
33Routine Description:\r
34 Init the SMBIOS VIEW API's environment.\r
35\r
36 Arguments:\r
37 None\r
38\r
39Returns:\r
40 EFI_SUCCESS - Successful to init the SMBIOS VIEW Lib\r
41 Others - Cannot get SMBIOS Table\r
42\r
43**/\r
44{\r
45 EFI_STATUS Status;\r
46\r
47 //\r
48 // Init only once\r
49 //\r
50 if (mInit == 1) {\r
51 return EFI_SUCCESS;\r
52 }\r
53 //\r
54 // Get SMBIOS table from System Configure table\r
55 //\r
56 Status = GetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID**)&mSmbiosTable);\r
57\r
58 if (mSmbiosTable == NULL) {\r
59 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle);\r
60 return EFI_NOT_FOUND;\r
61 }\r
62\r
63 if (EFI_ERROR (Status)) {\r
64 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), gShellDebug1HiiHandle, Status);\r
65 return Status;\r
66 }\r
67 //\r
68 // Init SMBIOS structure table address\r
69 //\r
70 mSmbiosStruct->Raw = (UINT8 *) (UINTN) (mSmbiosTable->TableAddress);\r
71\r
72 mInit = 1;\r
73 return EFI_SUCCESS;\r
74}\r
75\r
76VOID\r
77LibSmbiosCleanup (\r
78 VOID\r
79 )\r
80{\r
81 //\r
82 // Release resources\r
83 //\r
84 if (mSmbiosTable != NULL) {\r
85 mSmbiosTable = NULL;\r
86 }\r
87\r
88 mInit = 0;\r
89}\r
90\r
91VOID\r
92LibSmbiosGetEPS (\r
93 SMBIOS_STRUCTURE_TABLE **pEntryPointStructure\r
94 )\r
95{\r
96 //\r
97 // return SMBIOS Table address\r
98 //\r
99 *pEntryPointStructure = mSmbiosTable;\r
100}\r
101\r
102VOID\r
103LibSmbiosGetStructHead (\r
104 SMBIOS_STRUCTURE_POINTER *pHead\r
105 )\r
106{\r
107 //\r
108 // return SMBIOS structure table address\r
109 //\r
110 pHead = mSmbiosStruct;\r
111}\r
112\r
113EFI_STATUS\r
114LibGetSmbiosInfo (\r
115 OUT CHAR8 *dmiBIOSRevision,\r
116 OUT UINT16 *NumStructures,\r
117 OUT UINT16 *StructureSize,\r
118 OUT UINT32 *dmiStorageBase,\r
119 OUT UINT16 *dmiStorageSize\r
120 )\r
121/*++\r
122\r
123Routine Description:\r
124 Get SMBIOS Information.\r
125\r
126 Arguments:\r
127 dmiBIOSRevision - Revision of the SMBIOS Extensions.\r
128 NumStructures - Max. Number of Structures the BIOS will return.\r
129 StructureSize - Size of largest SMBIOS Structure.\r
130 dmiStorageBase - 32-bit physical base address for memory mapped SMBIOS data.\r
131 dmiStorageSize - Size of the memory-mapped SMBIOS data.\r
132\r
133 Returns:\r
134 DMI_SUCCESS - successful.\r
135 DMI_FUNCTION_NOT_SUPPORTED - Does not support SMBIOS calling interface capability.\r
136\r
137**/\r
138{\r
139 //\r
140 // If no SMIBOS table, unsupported.\r
141 //\r
142 if (mSmbiosTable == NULL) {\r
143 return DMI_FUNCTION_NOT_SUPPORTED;\r
144 }\r
145\r
146 *dmiBIOSRevision = mSmbiosTable->SmbiosBcdRevision;\r
147 *NumStructures = mSmbiosTable->NumberOfSmbiosStructures;\r
148 *StructureSize = mSmbiosTable->MaxStructureSize;\r
149 *dmiStorageBase = mSmbiosTable->TableAddress;\r
150 *dmiStorageSize = mSmbiosTable->TableLength;\r
151\r
152 return DMI_SUCCESS;\r
153}\r
154\r
155EFI_STATUS\r
156LibGetSmbiosStructure (\r
157 IN OUT UINT16 *Handle,\r
158 IN OUT UINT8 *Buffer,\r
159 OUT UINT16 *Length\r
160 )\r
161/*++\r
162\r
163 Routine Description:\r
164 Get SMBIOS structure given the Handle,copy data to the Buffer,\r
165 Handle is changed to the next handle or 0xFFFF when the end is\r
166 reached or the handle is not found.\r
167\r
168 Arguments:\r
169 Handle: - 0xFFFF: get the first structure\r
170 - Others: get a structure according to this value.\r
171 Buffter: - The pointer to the caller's memory buffer.\r
172 Length: - Length of return buffer in bytes.\r
173\r
174 Returns:\r
175 DMI_SUCCESS - Buffer contains the required structure data\r
176 - Handle is updated with next structure handle or\r
177 0xFFFF(end-of-list).\r
178\r
179 DMI_INVALID_HANDLE - Buffer not contain the requiring structure data\r
180 - Handle is updated with next structure handle or\r
181 0xFFFF(end-of-list).\r
182**/\r
183{\r
184 SMBIOS_STRUCTURE_POINTER Smbios;\r
185 SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r
186 UINT8 *Raw;\r
187\r
188 if (*Handle == INVALIDE_HANDLE) {\r
189 *Handle = mSmbiosStruct->Hdr->Handle;\r
190 return DMI_INVALID_HANDLE;\r
191 }\r
192\r
193 if (Buffer == NULL) {\r
194 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_SPEC), gShellDebug1HiiHandle);\r
195 return DMI_INVALID_HANDLE;\r
196 }\r
197\r
198 *Length = 0;\r
199 Smbios.Hdr = mSmbiosStruct->Hdr;\r
200 SmbiosEnd.Raw = Smbios.Raw + mSmbiosTable->TableLength;\r
201 while (Smbios.Raw < SmbiosEnd.Raw) {\r
202 if (Smbios.Hdr->Handle == *Handle) {\r
203 Raw = Smbios.Raw;\r
204 //\r
205 // Walk to next structure\r
206 //\r
207 LibGetSmbiosString (&Smbios, (UINT16) (-1));\r
208 //\r
209 // Length = Next structure head - this structure head\r
210 //\r
211 *Length = (UINT16) (Smbios.Raw - Raw);\r
212 CopyMem (Buffer, Raw, *Length);\r
213 //\r
214 // update with the next structure handle.\r
215 //\r
216 if (Smbios.Raw < SmbiosEnd.Raw) {\r
217 *Handle = Smbios.Hdr->Handle;\r
218 } else {\r
219 *Handle = INVALIDE_HANDLE;\r
220 }\r
221 return DMI_SUCCESS;\r
222 }\r
223 //\r
224 // Walk to next structure\r
225 //\r
226 LibGetSmbiosString (&Smbios, (UINT16) (-1));\r
227 }\r
228\r
229 *Handle = INVALIDE_HANDLE;\r
230 return DMI_INVALID_HANDLE;\r
231}\r
232\r
233EFI_STATUS\r
234SmbiosCheckStructure (\r
235 IN SMBIOS_STRUCTURE_POINTER *Smbios\r
236 )\r
237/*++\r
238\r
239 Routine Description:\r
240 Check the structure to see if it is legal.\r
241\r
242 Arguments:\r
243 Smbios - Pointer to the structure that will be checked.\r
244\r
245 Returns:\r
246 DMI_SUCCESS - Structure data is legal.\r
247 DMI_BAD_PARAMETER - Structure data contains bad parameter\r
248\r
249**/\r
250{\r
251 //\r
252 // If key != value, then error.\r
253 //\r
254#define CHECK_VALUE(key, value) (((key) == (value)) ? EFI_SUCCESS : DMI_BAD_PARAMETER)\r
255\r
256 EFI_STATUS Status;\r
257 //\r
258 // Assume staus is EFI_SUCCESS,\r
259 // but if check is error, then EFI_ERROR.\r
260 //\r
261 Status = EFI_SUCCESS;\r
262\r
263 switch (Smbios->Hdr->Type) {\r
264 case 0:\r
265 break;\r
266\r
267 case 1:\r
268 if (Smbios->Type1->Hdr.Length == 0x08 || Smbios->Type0->Hdr.Length == 0x19) {\r
269 Status = EFI_SUCCESS;\r
270 } else {\r
271 Status = DMI_BAD_PARAMETER;\r
272 }\r
273 break;\r
274\r
275 case 2:\r
276 Status = CHECK_VALUE (Smbios->Type2->Hdr.Length, 0x08);\r
277 break;\r
278\r
279 case 6:\r
280 Status = CHECK_VALUE (Smbios->Type6->Hdr.Length, 0x0C);\r
281 break;\r
282\r
283 case 11:\r
284 Status = CHECK_VALUE (Smbios->Type11->Hdr.Length, 0x05);\r
285 break;\r
286\r
287 case 12:\r
288 Status = CHECK_VALUE (Smbios->Type12->Hdr.Length, 0x05);\r
289 break;\r
290\r
291 case 13:\r
292 Status = CHECK_VALUE (Smbios->Type13->Hdr.Length, 0x16);\r
293 break;\r
294\r
295 case 16:\r
296 Status = CHECK_VALUE (Smbios->Type16->Hdr.Length, 0x0F);\r
297 break;\r
298\r
299 case 19:\r
300 Status = CHECK_VALUE (Smbios->Type19->Hdr.Length, 0x0F);\r
301 break;\r
302\r
303 case 20:\r
304 Status = CHECK_VALUE (Smbios->Type20->Hdr.Length, 0x13);\r
305 break;\r
306\r
307 case 32:\r
308 //\r
309 // Because EFI_SUCCESS == 0,\r
310 // So errors added up is also error.\r
311 //\r
312 Status = CHECK_VALUE (Smbios->Type32->Reserved[0], 0x00) +\r
313 CHECK_VALUE (Smbios->Type32->Reserved[1], 0x00) +\r
314 CHECK_VALUE (Smbios->Type32->Reserved[2], 0x00) +\r
315 CHECK_VALUE (Smbios->Type32->Reserved[3], 0x00) +\r
316 CHECK_VALUE (Smbios->Type32->Reserved[4], 0x00) +\r
317 CHECK_VALUE (Smbios->Type32->Reserved[5], 0x00);\r
318 break;\r
319\r
320 default:\r
321 Status = DMI_BAD_PARAMETER;\r
322 }\r
323\r
324 return Status;\r
325}\r
326\r
327VOID\r
328SmbiosGetPendingString (\r
329 IN SMBIOS_STRUCTURE_POINTER *Smbios,\r
330 IN UINT16 StringNumber,\r
331 OUT CHAR8 *Buffer\r
332 )\r
333{\r
334 CHAR8 *String;\r
335 if (Buffer == NULL) {\r
336 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUF_SPEC_WHEN_STRUCT), gShellDebug1HiiHandle);\r
337 return ;\r
338 }\r
339 //\r
340 // Get string and copy to buffer.\r
341 // Caller should provide the buffer.\r
342 //\r
343 String = LibGetSmbiosString (Smbios, StringNumber);\r
344 if (String != NULL) {\r
345 CopyMem (Buffer, String, AsciiStrLen(String));\r
346 } else {\r
347 Buffer = NULL;\r
348 }\r
349}\r