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