ShellPkg: Update header file including style
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / SmbiosView.c
CommitLineData
5d73d92f 1/** @file\r
2 Tools of clarify the content of the smbios table.\r
3\r
c011b6c9 4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
810c635d 5 Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
5d73d92f 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
8a765da2 16#include "UefiShellDebug1CommandsLib.h"\r
5d73d92f 17#include "LibSmbiosView.h"\r
a1d4bfcc 18#include "SmbiosView.h"\r
5d73d92f 19#include "PrintInfo.h"\r
20#include "QueryTable.h"\r
21\r
22UINT8 gShowType = SHOW_DETAIL;\r
23STATIC STRUCTURE_STATISTICS *mStatisticsTable = NULL;\r
ec8a502e 24STATIC STRUCTURE_STATISTICS *mSmbios64BitStatisticsTable = NULL;\r
5d73d92f 25\r
26UINT8 SmbiosMajorVersion;\r
27UINT8 SmbiosMinorVersion;\r
28\r
ec8a502e
EL
29UINTN mNumberOfSmbios64BitStructures;\r
30UINTN mSmbios64BitTableLength;\r
31\r
5d73d92f 32STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
33 {L"-t", TypeValue},\r
34 {L"-h", TypeValue},\r
35 {L"-s", TypeFlag},\r
36 {L"-a", TypeFlag},\r
37 {NULL, TypeMax}\r
38 };\r
39\r
a1d4bfcc 40/**\r
41 Function for 'smbiosview' command.\r
42\r
43 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
44 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
45**/\r
5d73d92f 46SHELL_STATUS\r
47EFIAPI\r
48ShellCommandRunSmbiosView (\r
49 IN EFI_HANDLE ImageHandle,\r
50 IN EFI_SYSTEM_TABLE *SystemTable\r
51 )\r
52{\r
53 UINT8 StructType;\r
54 UINT16 StructHandle;\r
55 EFI_STATUS Status;\r
ec8a502e
EL
56 EFI_STATUS Status1;\r
57 EFI_STATUS Status2;\r
5d73d92f 58 BOOLEAN RandomView;\r
59 LIST_ENTRY *Package;\r
60 CHAR16 *ProblemParam;\r
61 SHELL_STATUS ShellStatus;\r
62 CONST CHAR16 *Temp;\r
63\r
ec8a502e
EL
64 mStatisticsTable = NULL;\r
65 mSmbios64BitStatisticsTable = NULL;\r
66 Package = NULL;\r
67 ShellStatus = SHELL_SUCCESS;\r
5d73d92f 68\r
3737ac2b 69 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
5d73d92f 70 if (EFI_ERROR(Status)) {\r
71 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
4092a8f6 72 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"smbiosview", ProblemParam); \r
5d73d92f 73 FreePool(ProblemParam);\r
74 ShellStatus = SHELL_INVALID_PARAMETER;\r
75 } else {\r
76 ASSERT(FALSE);\r
77 }\r
78 } else {\r
79 if (ShellCommandLineGetCount(Package) > 1) {\r
4092a8f6 80 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); \r
5d73d92f 81 ShellStatus = SHELL_INVALID_PARAMETER;\r
980d554e 82 } else if (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetValue(Package, L"-t") == NULL) {\r
4092a8f6 83 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-t"); \r
980d554e 84 ShellStatus = SHELL_INVALID_PARAMETER;\r
85 } else if (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetValue(Package, L"-h") == NULL) {\r
4092a8f6 86 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-h"); \r
980d554e 87 ShellStatus = SHELL_INVALID_PARAMETER;\r
3737ac2b 88 } else if (\r
89 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-h")) ||\r
90 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-s")) ||\r
91 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-a")) ||\r
92 (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-s")) ||\r
93 (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-a")) ||\r
94 (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-a"))\r
95 ) {\r
4092a8f6 96 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); \r
3737ac2b 97 ShellStatus = SHELL_INVALID_PARAMETER;\r
5d73d92f 98 } else {\r
99\r
100 //\r
101 // Init Lib\r
5d73d92f 102 //\r
ec8a502e
EL
103 Status1 = LibSmbiosInit ();\r
104 Status2 = LibSmbios64BitInit ();\r
105 if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) {\r
106 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle);\r
5d73d92f 107 ShellStatus = SHELL_NOT_FOUND;\r
108 goto Done;\r
109 }\r
ec8a502e 110 \r
5d73d92f 111 StructType = STRUCTURE_TYPE_RANDOM;\r
112 RandomView = TRUE;\r
ec8a502e 113 \r
5d73d92f 114 Temp = ShellCommandLineGetValue(Package, L"-t");\r
115 if (Temp != NULL) {\r
116 StructType = (UINT8) ShellStrToUintn (Temp);\r
117 }\r
ec8a502e
EL
118 \r
119 if (ShellCommandLineGetFlag(Package, L"-a")) {\r
120 gShowType = SHOW_ALL;\r
5d73d92f 121 }\r
ec8a502e
EL
122 \r
123 if (!EFI_ERROR (Status1)) {\r
124 //\r
125 // Initialize the StructHandle to be the first handle\r
126 //\r
127 StructHandle = INVALID_HANDLE;\r
128 LibGetSmbiosStructure (&StructHandle, NULL, NULL);\r
129 \r
130 Temp = ShellCommandLineGetValue(Package, L"-h");\r
131 if (Temp != NULL) {\r
132 RandomView = FALSE;\r
133 StructHandle = (UINT16) ShellStrToUintn(Temp);\r
134 }\r
135 //\r
136 // build statistics table\r
137 //\r
138 Status = InitSmbiosTableStatistics ();\r
139 if (EFI_ERROR (Status)) {\r
140 ShellStatus = SHELL_NOT_FOUND;\r
141 goto Done;\r
142 }\r
143 \r
144 if (ShellCommandLineGetFlag(Package, L"-s")) {\r
145 Status = DisplayStatisticsTable (SHOW_DETAIL);\r
146 if (EFI_ERROR(Status)) {\r
147 ShellStatus = SHELL_NOT_FOUND;\r
148 }\r
149 goto Show64Bit;\r
150 }\r
151 \r
152 //\r
153 // Show SMBIOS structure information\r
154 //\r
155 Status = SMBiosView (StructType, StructHandle, gShowType, RandomView);\r
5d73d92f 156 if (EFI_ERROR(Status)) {\r
157 ShellStatus = SHELL_NOT_FOUND;\r
ec8a502e 158 goto Done;\r
5d73d92f 159 }\r
5d73d92f 160 }\r
161\r
ec8a502e
EL
162Show64Bit:\r
163 if (!EFI_ERROR (Status2)) {\r
164 //\r
165 // build statistics table\r
166 //\r
167 Status = InitSmbios64BitTableStatistics ();\r
168 if (EFI_ERROR (Status)) {\r
169 ShellStatus = SHELL_NOT_FOUND;\r
170 goto Done;\r
171 }\r
172 //\r
173 // Initialize the StructHandle to be the first handle\r
174 //\r
175 StructHandle = INVALID_HANDLE;\r
176 LibGetSmbios64BitStructure (&StructHandle, NULL, NULL);\r
177 \r
178 Temp = ShellCommandLineGetValue(Package, L"-h");\r
179 if (Temp != NULL) {\r
180 RandomView = FALSE;\r
181 StructHandle = (UINT16) ShellStrToUintn(Temp);\r
182 }\r
183 \r
184 if (ShellCommandLineGetFlag(Package, L"-s")) {\r
185 Status = DisplaySmbios64BitStatisticsTable (SHOW_DETAIL);\r
186 if (EFI_ERROR(Status)) {\r
187 ShellStatus = SHELL_NOT_FOUND;\r
188 }\r
189 goto Done;\r
190 }\r
191 \r
192 //\r
193 // Show SMBIOS structure information\r
194 //\r
195 Status = SMBios64View (StructType, StructHandle, gShowType, RandomView);\r
196 if (EFI_ERROR(Status)) {\r
197 ShellStatus = SHELL_NOT_FOUND;\r
198 }\r
5d73d92f 199 }\r
200 }\r
201 }\r
202Done:\r
203 //\r
204 // Release resources\r
205 //\r
206 if (mStatisticsTable != NULL) {\r
207 //\r
208 // Release statistics table\r
209 //\r
210 FreePool (mStatisticsTable);\r
211 mStatisticsTable = NULL;\r
212 }\r
213\r
ec8a502e
EL
214 if (mSmbios64BitStatisticsTable != NULL) {\r
215 //\r
216 // Release statistics table\r
217 //\r
218 FreePool (mSmbios64BitStatisticsTable);\r
219 mSmbios64BitStatisticsTable = NULL;\r
220 }\r
221\r
5d73d92f 222 if (Package != NULL) {\r
223 ShellCommandLineFreeVarList (Package);\r
224 }\r
225\r
226 LibSmbiosCleanup ();\r
ec8a502e 227 LibSmbios64BitCleanup ();\r
5d73d92f 228\r
229 return ShellStatus;\r
230}\r
231\r
232/**\r
233 Query all structures Data from SMBIOS table and Display\r
234 the information to users as required display option.\r
235\r
236 @param[in] QueryType Structure type to view.\r
237 @param[in] QueryHandle Structure handle to view.\r
238 @param[in] Option Display option: none,outline,normal,detail.\r
239 @param[in] RandomView Support for -h parameter.\r
240\r
241 @retval EFI_SUCCESS print is successful.\r
242 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.\r
243**/\r
244EFI_STATUS\r
5d73d92f 245SMBiosView (\r
246 IN UINT8 QueryType,\r
247 IN UINT16 QueryHandle,\r
248 IN UINT8 Option,\r
249 IN BOOLEAN RandomView\r
250 )\r
251{\r
252 UINT16 Handle;\r
187cb3dd 253 UINT8 *Buffer;\r
5d73d92f 254 UINT16 Length;\r
255 UINTN Index;\r
5d73d92f 256\r
a1d4bfcc 257 SMBIOS_STRUCTURE_POINTER SmbiosStruct;\r
187cb3dd 258 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;\r
5d73d92f 259\r
260 SMBiosTable = NULL;\r
261 LibSmbiosGetEPS (&SMBiosTable);\r
262 if (SMBiosTable == NULL) {\r
263 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);\r
264 return EFI_BAD_BUFFER_SIZE;\r
265 }\r
266\r
267 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) == 0) {\r
268 //\r
187cb3dd 269 // Have got SMBIOS table\r
5d73d92f 270 //\r
271 SmbiosPrintEPSInfo (SMBiosTable, Option);\r
272\r
273 SmbiosMajorVersion = SMBiosTable->MajorVersion;\r
274 SmbiosMinorVersion = SMBiosTable->MinorVersion;\r
275\r
276 ShellPrintEx(-1,-1,L"=========================================================\n");\r
277 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);\r
278\r
279 if (QueryType == STRUCTURE_TYPE_RANDOM) {\r
280 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);\r
281 } else {\r
282 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);\r
283 }\r
284\r
285 if (RandomView) {\r
286 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);\r
287 } else {\r
288 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);\r
289 }\r
290\r
291 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle);\r
292 ShellPrintEx(-1,-1,GetShowTypeString (gShowType));\r
293 ShellPrintEx(-1,-1,L"\n\n");\r
294\r
295/*\r
296 //\r
297 // Get internal commands, such as change options.\r
298 //\r
299 Status = WaitEnter ();\r
300 if (EFI_ERROR (Status)) {\r
301 if (Status == EFI_ABORTED) {\r
302 return EFI_SUCCESS;\r
303 }\r
304\r
305 return Status;\r
306 }\r
307*/\r
308\r
309 //\r
310 // Searching and display structure info\r
311 //\r
312 Handle = QueryHandle;\r
5d73d92f 313 for (Index = 0; Index < SMBiosTable->NumberOfSmbiosStructures; Index++) {\r
314 //\r
315 // if reach the end of table, break..\r
316 //\r
187cb3dd 317 if (Handle == INVALID_HANDLE) {\r
5d73d92f 318 break;\r
319 }\r
320 //\r
321 // handle then point to the next!\r
322 //\r
187cb3dd 323 if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {\r
5d73d92f 324 break;\r
325 }\r
187cb3dd 326\r
a1d4bfcc 327 SmbiosStruct.Raw = Buffer;\r
5d73d92f 328\r
329 //\r
330 // if QueryType==Random, print this structure.\r
331 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.\r
332 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.\r
333 //\r
a1d4bfcc 334 if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) {\r
5d73d92f 335 continue;\r
336 }\r
337\r
338 ShellPrintEx(-1,-1,L"\n=========================================================\n");\r
339 ShellPrintHiiEx(-1,-1,NULL,\r
340 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),\r
341 gShellDebug1HiiHandle,\r
a1d4bfcc 342 SmbiosStruct.Hdr->Type,\r
343 SmbiosStruct.Hdr->Handle\r
5d73d92f 344 );\r
345 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);\r
346 //\r
347 // Addr of structure in structure in table\r
348 //\r
187cb3dd 349 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer);\r
5d73d92f 350 DumpHex (0, 0, Length, Buffer);\r
351\r
352/*\r
353 //\r
354 // Get internal commands, such as change options.\r
355 //\r
356 Status = WaitEnter ();\r
357 if (EFI_ERROR (Status)) {\r
358 if (Status == EFI_ABORTED) {\r
359 return EFI_SUCCESS;\r
360 }\r
361\r
362 return Status;\r
363 }\r
364*/\r
365\r
366 if (gShowType != SHOW_NONE) {\r
5d73d92f 367 //\r
368 // Print structure information\r
369 //\r
a1d4bfcc 370 SmbiosPrintStructure (&SmbiosStruct, gShowType);\r
5d73d92f 371 ShellPrintEx(-1,-1,L"\n");\r
372\r
373/*\r
374 //\r
375 // Get internal commands, such as change options.\r
376 //\r
377 Status = WaitEnter ();\r
378 if (EFI_ERROR (Status)) {\r
379 if (Status == EFI_ABORTED) {\r
380 return EFI_SUCCESS;\r
381 }\r
382\r
383 return Status;\r
384 }\r
385*/\r
386 }\r
387 if (!RandomView) {\r
388 break;\r
389 }\r
7ac133d0 390 //\r
391 // Support Execution Interrupt.\r
392 //\r
393 if (ShellGetExecutionBreakFlag ()) {\r
394 return EFI_ABORTED;\r
395 }\r
5d73d92f 396 }\r
397\r
398 ShellPrintEx(-1,-1,L"\n=========================================================\n");\r
399 return EFI_SUCCESS;\r
400 }\r
401\r
402 return EFI_BAD_BUFFER_SIZE;\r
403}\r
404\r
ec8a502e
EL
405/**\r
406 Query all structures Data from SMBIOS table and Display\r
407 the information to users as required display option.\r
408\r
409 @param[in] QueryType Structure type to view.\r
410 @param[in] QueryHandle Structure handle to view.\r
411 @param[in] Option Display option: none,outline,normal,detail.\r
412 @param[in] RandomView Support for -h parameter.\r
413\r
414 @retval EFI_SUCCESS print is successful.\r
415 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.\r
416**/\r
417EFI_STATUS\r
ec8a502e
EL
418SMBios64View (\r
419 IN UINT8 QueryType,\r
420 IN UINT16 QueryHandle,\r
421 IN UINT8 Option,\r
422 IN BOOLEAN RandomView\r
423 )\r
424{\r
425 UINT16 Handle;\r
426 UINT8 *Buffer;\r
427 UINT16 Length;\r
428 UINTN Index;\r
429 SMBIOS_STRUCTURE_POINTER SmbiosStruct;\r
430 SMBIOS_TABLE_3_0_ENTRY_POINT *SMBiosTable;\r
431\r
432 SMBiosTable = NULL;\r
433 LibSmbios64BitGetEPS (&SMBiosTable);\r
434 if (SMBiosTable == NULL) {\r
435 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);\r
436 return EFI_BAD_BUFFER_SIZE;\r
437 }\r
438\r
439 if (CompareMem (SMBiosTable->AnchorString, "_SM3_", 5) == 0) {\r
440 //\r
441 // Have got SMBIOS table\r
442 //\r
443 Smbios64BitPrintEPSInfo (SMBiosTable, Option);\r
444\r
445 SmbiosMajorVersion = SMBiosTable->MajorVersion;\r
446 SmbiosMinorVersion = SMBiosTable->MinorVersion;\r
447\r
448 ShellPrintEx(-1,-1,L"=========================================================\n");\r
449 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);\r
450\r
451 if (QueryType == STRUCTURE_TYPE_RANDOM) {\r
452 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);\r
453 } else {\r
454 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);\r
455 }\r
456\r
457 if (RandomView) {\r
458 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);\r
459 } else {\r
460 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);\r
461 }\r
462\r
463 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle);\r
464 ShellPrintEx(-1,-1,GetShowTypeString (gShowType));\r
465 ShellPrintEx(-1,-1,L"\n\n");\r
466\r
467/*\r
468 //\r
469 // Get internal commands, such as change options.\r
470 //\r
471 Status = WaitEnter ();\r
472 if (EFI_ERROR (Status)) {\r
473 if (Status == EFI_ABORTED) {\r
474 return EFI_SUCCESS;\r
475 }\r
476\r
477 return Status;\r
478 }\r
479*/\r
480\r
481 //\r
482 // Searching and display structure info\r
483 //\r
484 Handle = QueryHandle;\r
485 for (Index = 0; Index < mNumberOfSmbios64BitStructures; Index++) {\r
486 //\r
487 // if reach the end of table, break..\r
488 //\r
489 if (Handle == INVALID_HANDLE) {\r
490 break;\r
491 }\r
492 //\r
493 // handle then point to the next!\r
494 //\r
495 if (LibGetSmbios64BitStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {\r
496 break;\r
497 }\r
498\r
499 SmbiosStruct.Raw = Buffer;\r
500\r
501 //\r
502 // if QueryType==Random, print this structure.\r
503 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.\r
504 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.\r
505 //\r
506 if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) {\r
507 continue;\r
508 }\r
509\r
510 ShellPrintEx(-1,-1,L"\n=========================================================\n");\r
511 ShellPrintHiiEx(-1,-1,NULL,\r
512 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),\r
513 gShellDebug1HiiHandle,\r
514 SmbiosStruct.Hdr->Type,\r
515 SmbiosStruct.Hdr->Handle\r
516 );\r
517 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);\r
518 //\r
519 // Addr of structure in structure in table\r
520 //\r
521 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer);\r
522 DumpHex (0, 0, Length, Buffer);\r
523\r
524/*\r
525 //\r
526 // Get internal commands, such as change options.\r
527 //\r
528 Status = WaitEnter ();\r
529 if (EFI_ERROR (Status)) {\r
530 if (Status == EFI_ABORTED) {\r
531 return EFI_SUCCESS;\r
532 }\r
533\r
534 return Status;\r
535 }\r
536*/\r
537\r
538 if (gShowType != SHOW_NONE) {\r
539 //\r
540 // Print structure information\r
541 //\r
542 SmbiosPrintStructure (&SmbiosStruct, gShowType);\r
543 ShellPrintEx(-1,-1,L"\n");\r
544\r
545/*\r
546 //\r
547 // Get internal commands, such as change options.\r
548 //\r
549 Status = WaitEnter ();\r
550 if (EFI_ERROR (Status)) {\r
551 if (Status == EFI_ABORTED) {\r
552 return EFI_SUCCESS;\r
553 }\r
554\r
555 return Status;\r
556 }\r
557*/\r
558 }\r
559 if (!RandomView) {\r
560 break;\r
561 }\r
562 //\r
563 // Support Execution Interrupt.\r
564 //\r
565 if (ShellGetExecutionBreakFlag ()) {\r
566 return EFI_ABORTED;\r
567 }\r
568 }\r
569\r
570 ShellPrintEx(-1,-1,L"\n=========================================================\n");\r
571 return EFI_SUCCESS;\r
572 }\r
573\r
574 return EFI_BAD_BUFFER_SIZE;\r
575}\r
576\r
5d73d92f 577/**\r
578 Function to initialize the global mStatisticsTable object.\r
579\r
580 @retval EFI_SUCCESS print is successful.\r
581**/\r
582EFI_STATUS\r
5d73d92f 583InitSmbiosTableStatistics (\r
584 VOID\r
585 )\r
586{\r
587 UINT16 Handle;\r
187cb3dd 588 UINT8 *Buffer;\r
5d73d92f 589 UINT16 Length;\r
590 UINT16 Offset;\r
591 UINT16 Index;\r
592\r
a1d4bfcc 593 SMBIOS_STRUCTURE_POINTER SmbiosStruct;\r
187cb3dd 594 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;\r
a1d4bfcc 595 STRUCTURE_STATISTICS *StatisticsPointer;\r
5d73d92f 596\r
597 SMBiosTable = NULL;\r
598 LibSmbiosGetEPS (&SMBiosTable);\r
599 if (SMBiosTable == NULL) {\r
600 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);\r
601 return EFI_NOT_FOUND;\r
602 }\r
603\r
604 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) != 0) {\r
605 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE), gShellDebug1HiiHandle);\r
606 return EFI_INVALID_PARAMETER;\r
607 }\r
608 //\r
609 // Allocate memory to mStatisticsTable\r
610 //\r
611 if (mStatisticsTable != NULL) {\r
612 FreePool (mStatisticsTable);\r
613 mStatisticsTable = NULL;\r
614 }\r
615\r
3737ac2b 616 mStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));\r
5d73d92f 617\r
618 if (mStatisticsTable == NULL) {\r
619 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);\r
620 return EFI_OUT_OF_RESOURCES;\r
621 }\r
622\r
623 Offset = 0;\r
a1d4bfcc 624 StatisticsPointer = mStatisticsTable;\r
5d73d92f 625\r
626 //\r
627 // search from the first one\r
628 //\r
187cb3dd 629 Handle = INVALID_HANDLE;\r
5d73d92f 630 LibGetSmbiosStructure (&Handle, NULL, NULL);\r
631 for (Index = 1; Index <= SMBiosTable->NumberOfSmbiosStructures; Index++) {\r
632 //\r
633 // If reach the end of table, break..\r
634 //\r
187cb3dd 635 if (Handle == INVALID_HANDLE) {\r
5d73d92f 636 break;\r
637 }\r
638 //\r
639 // After LibGetSmbiosStructure(), handle then point to the next!\r
640 //\r
187cb3dd 641 if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {\r
5d73d92f 642 break;\r
643 }\r
644\r
a1d4bfcc 645 SmbiosStruct.Raw = Buffer;\r
5d73d92f 646\r
647 //\r
648 // general statistics\r
649 //\r
a1d4bfcc 650 StatisticsPointer->Index = Index;\r
651 StatisticsPointer->Type = SmbiosStruct.Hdr->Type;\r
652 StatisticsPointer->Handle = SmbiosStruct.Hdr->Handle;\r
653 StatisticsPointer->Length = Length;\r
654 StatisticsPointer->Addr = Offset;\r
5d73d92f 655\r
187cb3dd
SZ
656 Offset = (UINT16) (Offset + Length);\r
657\r
a1d4bfcc 658 StatisticsPointer = &mStatisticsTable[Index];\r
5d73d92f 659 }\r
660\r
661 return EFI_SUCCESS;\r
662}\r
663\r
ec8a502e
EL
664/**\r
665 @param[in] Smbios64EntryPoint SMBIOS 64-bit entry point.\r
666 @param[out] NumberOfSmbios64Structures The number of structures in 64-bit SMBIOS table.\r
667 @param[out] Smbios64TableLength The total length of 64-bit SMBIOS table.\r
668\r
669 @retval EFI_SUCCESS Calculation was successful.\r
670**/\r
671EFI_STATUS\r
ec8a502e
EL
672CalculateSmbios64BitStructureCountAndLength (\r
673 SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios64EntryPoint,\r
674 UINTN *NumberOfSmbios64Structures,\r
675 UINTN *Smbios64TableLength\r
676)\r
677{\r
678 SMBIOS_STRUCTURE_POINTER Smbios;\r
679 UINT8 *Raw;\r
680 \r
681 *Smbios64TableLength = 0;\r
682 *NumberOfSmbios64Structures = 0;\r
683 \r
684 Smbios.Raw = (UINT8 *)(UINTN)(Smbios64EntryPoint->TableAddress);\r
685 while (TRUE) {\r
686 if (Smbios.Hdr->Type == 127) {\r
687 //\r
688 // Reach the end of table type 127\r
689 //\r
690 (*NumberOfSmbios64Structures)++;\r
691 (*Smbios64TableLength) += sizeof (SMBIOS_STRUCTURE);\r
692 return EFI_SUCCESS;\r
693 }\r
694\r
695 Raw = Smbios.Raw;\r
696 //\r
697 // Walk to next structure\r
698 //\r
699 LibGetSmbiosString (&Smbios, (UINT16) (-1));\r
700 //\r
701 // Length = Next structure head - this structure head\r
702 //\r
810c635d 703 (*Smbios64TableLength) += ((UINTN) Smbios.Raw - (UINTN) Raw);\r
ec8a502e
EL
704 if ((*Smbios64TableLength) > Smbios64EntryPoint->TableMaximumSize) {\r
705 //\r
706 // The actual table length exceeds maximum table size,\r
707 // There should be something wrong with SMBIOS table.\r
708 //\r
709 return EFI_INVALID_PARAMETER;\r
710 }\r
711 (*NumberOfSmbios64Structures)++;\r
712 }\r
713}\r
714\r
715/**\r
716 Function to initialize the global mSmbios64BitStatisticsTable object.\r
717\r
718 @retval EFI_SUCCESS print is successful.\r
719**/\r
720EFI_STATUS\r
ec8a502e
EL
721InitSmbios64BitTableStatistics (\r
722 VOID\r
723 )\r
724{\r
725 UINT16 Handle;\r
726 UINT8 *Buffer;\r
727 UINT16 Length;\r
728 UINT16 Offset;\r
729 UINT16 Index;\r
730 EFI_STATUS Status;\r
731 SMBIOS_STRUCTURE_POINTER SmbiosStruct;\r
732 SMBIOS_TABLE_3_0_ENTRY_POINT *SMBiosTable;\r
733 STRUCTURE_STATISTICS *StatisticsPointer;\r
734\r
735 SMBiosTable = NULL;\r
736 LibSmbios64BitGetEPS (&SMBiosTable);\r
737 if (SMBiosTable == NULL) {\r
738 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);\r
739 return EFI_NOT_FOUND;\r
740 }\r
741\r
742 if (CompareMem (SMBiosTable->AnchorString, "_SM3_", 5) != 0) {\r
743 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE), gShellDebug1HiiHandle);\r
744 return EFI_INVALID_PARAMETER;\r
745 }\r
746 //\r
747 // Allocate memory to mSmbios64BitStatisticsTable\r
748 //\r
749 if (mSmbios64BitStatisticsTable != NULL) {\r
750 FreePool (mSmbios64BitStatisticsTable);\r
751 mSmbios64BitStatisticsTable = NULL;\r
752 }\r
753 //\r
754 // Calculate number of smbios structures\r
755 //\r
756 Status = CalculateSmbios64BitStructureCountAndLength (SMBiosTable, &mNumberOfSmbios64BitStructures, &mSmbios64BitTableLength);\r
757 if ((EFI_ERROR (Status)) || (mSmbios64BitTableLength > SMBiosTable->TableMaximumSize)) {\r
758 return EFI_INVALID_PARAMETER;\r
759 }\r
760 \r
761 mSmbios64BitStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (mNumberOfSmbios64BitStructures * sizeof (STRUCTURE_STATISTICS));\r
762\r
763 if (mSmbios64BitStatisticsTable == NULL) {\r
764 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);\r
765 return EFI_OUT_OF_RESOURCES;\r
766 }\r
767\r
768 Offset = 0;\r
769 StatisticsPointer = mSmbios64BitStatisticsTable;\r
770\r
771 //\r
772 // search from the first one\r
773 //\r
774 Handle = INVALID_HANDLE;\r
775 LibGetSmbios64BitStructure (&Handle, NULL, NULL);\r
776 for (Index = 1; Index <= mNumberOfSmbios64BitStructures; Index++) {\r
777 //\r
778 // If reach the end of table, break..\r
779 //\r
780 if (Handle == INVALID_HANDLE) {\r
781 break;\r
782 }\r
783 //\r
784 // After LibGetSmbios64BitStructure(), handle then point to the next!\r
785 //\r
786 if (LibGetSmbios64BitStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {\r
787 break;\r
788 }\r
789\r
790 SmbiosStruct.Raw = Buffer;\r
791\r
792 //\r
793 // general statistics\r
794 //\r
795 StatisticsPointer->Index = Index;\r
796 StatisticsPointer->Type = SmbiosStruct.Hdr->Type;\r
797 StatisticsPointer->Handle = SmbiosStruct.Hdr->Handle;\r
798 StatisticsPointer->Length = Length;\r
799 StatisticsPointer->Addr = Offset;\r
800\r
801 Offset = (UINT16) (Offset + Length);\r
802\r
803 StatisticsPointer = &mSmbios64BitStatisticsTable[Index];\r
804 }\r
805\r
806 return EFI_SUCCESS;\r
807}\r
808\r
5d73d92f 809/**\r
810 Function to display the global mStatisticsTable object.\r
811\r
812 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.\r
813\r
814 @retval EFI_SUCCESS print is successful.\r
815**/\r
816EFI_STATUS\r
5d73d92f 817DisplayStatisticsTable (\r
818 IN UINT8 Option\r
819 )\r
820{\r
187cb3dd
SZ
821 UINTN Index;\r
822 UINTN Num;\r
823 STRUCTURE_STATISTICS *StatisticsPointer;\r
824 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;\r
5d73d92f 825\r
826 SMBiosTable = NULL;\r
827 if (Option < SHOW_OUTLINE) {\r
828 return EFI_SUCCESS;\r
829 }\r
830 //\r
831 // display EPS information firstly\r
832 //\r
833 LibSmbiosGetEPS (&SMBiosTable);\r
834 if (SMBiosTable == NULL) {\r
835 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);\r
836 return EFI_UNSUPPORTED;\r
837 }\r
838\r
839 ShellPrintEx(-1,-1,L"\n============================================================\n");\r
840 SmbiosPrintEPSInfo (SMBiosTable, Option);\r
841\r
842 if (Option < SHOW_NORMAL) {\r
843 return EFI_SUCCESS;\r
844 }\r
845\r
846 if (mStatisticsTable == NULL) {\r
847 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);\r
848 return EFI_NOT_FOUND;\r
849 }\r
850\r
851 ShellPrintEx(-1,-1,L"============================================================\n");\r
a1d4bfcc 852 StatisticsPointer = &mStatisticsTable[0];\r
5d73d92f 853 Num = SMBiosTable->NumberOfSmbiosStructures;\r
854 //\r
855 // display statistics table content\r
856 //\r
857 for (Index = 1; Index <= Num; Index++) {\r
a1d4bfcc 858 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX), gShellDebug1HiiHandle, StatisticsPointer->Index);\r
859 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE), gShellDebug1HiiHandle, StatisticsPointer->Type);\r
860 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE), gShellDebug1HiiHandle, StatisticsPointer->Handle);\r
5d73d92f 861 if (Option >= SHOW_DETAIL) {\r
a1d4bfcc 862 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET), gShellDebug1HiiHandle, StatisticsPointer->Addr);\r
863 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH), gShellDebug1HiiHandle, StatisticsPointer->Length);\r
5d73d92f 864 }\r
865\r
866 ShellPrintEx(-1,-1,L"\n");\r
a1d4bfcc 867 StatisticsPointer = &mStatisticsTable[Index];\r
ec8a502e
EL
868/*\r
869 //\r
870 // Display 20 lines and wait for a page break\r
871 //\r
872 if (Index % 20 == 0) {\r
873 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);\r
874 Status = WaitEnter ();\r
875 if (EFI_ERROR (Status)) {\r
876 if (Status == EFI_ABORTED) {\r
877 return EFI_SUCCESS;\r
878 }\r
879\r
880 return Status;\r
881 }\r
882 }\r
883*/\r
884 }\r
885\r
886 return EFI_SUCCESS;\r
887}\r
888\r
889/**\r
890 Function to display the global mSmbios64BitStatisticsTable object.\r
891\r
892 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.\r
893\r
894 @retval EFI_SUCCESS print is successful.\r
895**/\r
896EFI_STATUS\r
ec8a502e
EL
897DisplaySmbios64BitStatisticsTable (\r
898 IN UINT8 Option\r
899 )\r
900{\r
901 UINTN Index;\r
902 UINTN Num;\r
903 STRUCTURE_STATISTICS *StatisticsPointer;\r
904 SMBIOS_TABLE_3_0_ENTRY_POINT *SMBiosTable;\r
905\r
906 SMBiosTable = NULL;\r
907 if (Option < SHOW_OUTLINE) {\r
908 return EFI_SUCCESS;\r
909 }\r
910 //\r
911 // display EPS information firstly\r
912 //\r
913 LibSmbios64BitGetEPS (&SMBiosTable);\r
914 if (SMBiosTable == NULL) {\r
915 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);\r
916 return EFI_UNSUPPORTED;\r
917 }\r
918\r
919 ShellPrintEx(-1,-1,L"\n============================================================\n");\r
920 Smbios64BitPrintEPSInfo (SMBiosTable, Option);\r
921\r
922 if (Option < SHOW_NORMAL) {\r
923 return EFI_SUCCESS;\r
924 }\r
925\r
926 if (mSmbios64BitStatisticsTable == NULL) {\r
927 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);\r
928 return EFI_NOT_FOUND;\r
929 }\r
930\r
931 ShellPrintEx(-1,-1,L"============================================================\n");\r
932 StatisticsPointer = &mSmbios64BitStatisticsTable[0];\r
933 Num = mNumberOfSmbios64BitStructures;\r
934 //\r
935 // display statistics table content\r
936 //\r
937 for (Index = 1; Index <= Num; Index++) {\r
938 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX), gShellDebug1HiiHandle, StatisticsPointer->Index);\r
939 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE), gShellDebug1HiiHandle, StatisticsPointer->Type);\r
940 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE), gShellDebug1HiiHandle, StatisticsPointer->Handle);\r
941 if (Option >= SHOW_DETAIL) {\r
942 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET), gShellDebug1HiiHandle, StatisticsPointer->Addr);\r
943 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH), gShellDebug1HiiHandle, StatisticsPointer->Length);\r
944 }\r
945\r
946 ShellPrintEx(-1,-1,L"\n");\r
947 StatisticsPointer = &mSmbios64BitStatisticsTable[Index];\r
5d73d92f 948/*\r
949 //\r
950 // Display 20 lines and wait for a page break\r
951 //\r
952 if (Index % 20 == 0) {\r
953 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);\r
954 Status = WaitEnter ();\r
955 if (EFI_ERROR (Status)) {\r
956 if (Status == EFI_ABORTED) {\r
957 return EFI_SUCCESS;\r
958 }\r
959\r
960 return Status;\r
961 }\r
962 }\r
963*/\r
964 }\r
965\r
966 return EFI_SUCCESS;\r
967}\r
968\r
969/**\r
970 function to return a string of the detail level.\r
971\r
972 @param[in] ShowType The detail level whose name is desired in clear text.\r
973\r
974 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).\r
975**/\r
976CHAR16 *\r
5d73d92f 977GetShowTypeString (\r
978 UINT8 ShowType\r
979 )\r
980{\r
981 //\r
982 // show type\r
983 //\r
984 switch (ShowType) {\r
985\r
986 case SHOW_NONE:\r
987 return L"SHOW_NONE";\r
988\r
989 case SHOW_OUTLINE:\r
990 return L"SHOW_OUTLINE";\r
991\r
992 case SHOW_NORMAL:\r
993 return L"SHOW_NORMAL";\r
994\r
995 case SHOW_DETAIL:\r
996 return L"SHOW_DETAIL";\r
997\r
998 case SHOW_ALL:\r
999 return L"SHOW_ALL";\r
1000\r
1001 default:\r
1002 return L"Undefined type";\r
1003 }\r
1004}\r
1005\r