• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
ShellCommandRunSmbiosView(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)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
SMBiosView(IN UINT8 QueryType,IN UINT16 QueryHandle,IN UINT8 Option,IN BOOLEAN RandomView)245 SMBiosView (
246   IN  UINT8   QueryType,
247   IN  UINT16  QueryHandle,
248   IN  UINT8   Option,
249   IN  BOOLEAN RandomView
250   )
251 {
252   UINT16                    Handle;
253   UINT8                     *Buffer;
254   UINT16                    Length;
255   UINTN                     Index;
256 
257   SMBIOS_STRUCTURE_POINTER  SmbiosStruct;
258   SMBIOS_TABLE_ENTRY_POINT  *SMBiosTable;
259 
260   SMBiosTable = NULL;
261   LibSmbiosGetEPS (&SMBiosTable);
262   if (SMBiosTable == NULL) {
263     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
264     return EFI_BAD_BUFFER_SIZE;
265   }
266 
267   if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) == 0) {
268     //
269     // Have got SMBIOS table
270     //
271     SmbiosPrintEPSInfo (SMBiosTable, Option);
272 
273     SmbiosMajorVersion = SMBiosTable->MajorVersion;
274     SmbiosMinorVersion = SMBiosTable->MinorVersion;
275 
276     ShellPrintEx(-1,-1,L"=========================================================\n");
277     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);
278 
279     if (QueryType == STRUCTURE_TYPE_RANDOM) {
280       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);
281     } else {
282       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);
283     }
284 
285     if (RandomView) {
286       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);
287     } else {
288       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);
289     }
290 
291     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle);
292     ShellPrintEx(-1,-1,GetShowTypeString (gShowType));
293     ShellPrintEx(-1,-1,L"\n\n");
294 
295 /*
296     //
297     // Get internal commands, such as change options.
298     //
299     Status = WaitEnter ();
300     if (EFI_ERROR (Status)) {
301       if (Status == EFI_ABORTED) {
302         return EFI_SUCCESS;
303       }
304 
305       return Status;
306     }
307 */
308 
309     //
310     // Searching and display structure info
311     //
312     Handle    = QueryHandle;
313     for (Index = 0; Index < SMBiosTable->NumberOfSmbiosStructures; Index++) {
314       //
315       // if reach the end of table, break..
316       //
317       if (Handle == INVALID_HANDLE) {
318         break;
319       }
320       //
321       // handle then point to the next!
322       //
323       if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
324         break;
325       }
326 
327       SmbiosStruct.Raw = Buffer;
328 
329       //
330       // if QueryType==Random, print this structure.
331       // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
332       // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
333       //
334       if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) {
335         continue;
336       }
337 
338       ShellPrintEx(-1,-1,L"\n=========================================================\n");
339       ShellPrintHiiEx(-1,-1,NULL,
340         STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),
341         gShellDebug1HiiHandle,
342         SmbiosStruct.Hdr->Type,
343         SmbiosStruct.Hdr->Handle
344        );
345       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);
346       //
347       // Addr of structure in structure in table
348       //
349       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer);
350       DumpHex (0, 0, Length, Buffer);
351 
352 /*
353       //
354       // Get internal commands, such as change options.
355       //
356       Status = WaitEnter ();
357       if (EFI_ERROR (Status)) {
358         if (Status == EFI_ABORTED) {
359           return EFI_SUCCESS;
360         }
361 
362         return Status;
363       }
364 */
365 
366       if (gShowType != SHOW_NONE) {
367         //
368         // Print structure information
369         //
370         SmbiosPrintStructure (&SmbiosStruct, gShowType);
371         ShellPrintEx(-1,-1,L"\n");
372 
373 /*
374         //
375         // Get internal commands, such as change options.
376         //
377         Status = WaitEnter ();
378         if (EFI_ERROR (Status)) {
379           if (Status == EFI_ABORTED) {
380             return EFI_SUCCESS;
381           }
382 
383           return Status;
384         }
385 */
386       }
387       if (!RandomView) {
388         break;
389       }
390       //
391       // Support Execution Interrupt.
392       //
393       if (ShellGetExecutionBreakFlag ()) {
394         return EFI_ABORTED;
395       }
396     }
397 
398     ShellPrintEx(-1,-1,L"\n=========================================================\n");
399     return EFI_SUCCESS;
400   }
401 
402   return EFI_BAD_BUFFER_SIZE;
403 }
404 
405 /**
406   Query all structures Data from SMBIOS table and Display
407   the information to users as required display option.
408 
409   @param[in] QueryType      Structure type to view.
410   @param[in] QueryHandle    Structure handle to view.
411   @param[in] Option         Display option: none,outline,normal,detail.
412   @param[in] RandomView     Support for -h parameter.
413 
414   @retval EFI_SUCCESS           print is successful.
415   @retval EFI_BAD_BUFFER_SIZE   structure is out of the range of SMBIOS table.
416 **/
417 EFI_STATUS
SMBios64View(IN UINT8 QueryType,IN UINT16 QueryHandle,IN UINT8 Option,IN BOOLEAN RandomView)418 SMBios64View (
419   IN  UINT8   QueryType,
420   IN  UINT16  QueryHandle,
421   IN  UINT8   Option,
422   IN  BOOLEAN RandomView
423   )
424 {
425   UINT16                        Handle;
426   UINT8                         *Buffer;
427   UINT16                        Length;
428   UINTN                         Index;
429   SMBIOS_STRUCTURE_POINTER      SmbiosStruct;
430   SMBIOS_TABLE_3_0_ENTRY_POINT  *SMBiosTable;
431 
432   SMBiosTable = NULL;
433   LibSmbios64BitGetEPS (&SMBiosTable);
434   if (SMBiosTable == NULL) {
435     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
436     return EFI_BAD_BUFFER_SIZE;
437   }
438 
439   if (CompareMem (SMBiosTable->AnchorString, "_SM3_", 5) == 0) {
440     //
441     // Have got SMBIOS table
442     //
443     Smbios64BitPrintEPSInfo (SMBiosTable, Option);
444 
445     SmbiosMajorVersion = SMBiosTable->MajorVersion;
446     SmbiosMinorVersion = SMBiosTable->MinorVersion;
447 
448     ShellPrintEx(-1,-1,L"=========================================================\n");
449     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);
450 
451     if (QueryType == STRUCTURE_TYPE_RANDOM) {
452       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);
453     } else {
454       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);
455     }
456 
457     if (RandomView) {
458       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);
459     } else {
460       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);
461     }
462 
463     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle);
464     ShellPrintEx(-1,-1,GetShowTypeString (gShowType));
465     ShellPrintEx(-1,-1,L"\n\n");
466 
467 /*
468     //
469     // Get internal commands, such as change options.
470     //
471     Status = WaitEnter ();
472     if (EFI_ERROR (Status)) {
473       if (Status == EFI_ABORTED) {
474         return EFI_SUCCESS;
475       }
476 
477       return Status;
478     }
479 */
480 
481     //
482     // Searching and display structure info
483     //
484     Handle    = QueryHandle;
485     for (Index = 0; Index < mNumberOfSmbios64BitStructures; Index++) {
486       //
487       // if reach the end of table, break..
488       //
489       if (Handle == INVALID_HANDLE) {
490         break;
491       }
492       //
493       // handle then point to the next!
494       //
495       if (LibGetSmbios64BitStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
496         break;
497       }
498 
499       SmbiosStruct.Raw = Buffer;
500 
501       //
502       // if QueryType==Random, print this structure.
503       // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
504       // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
505       //
506       if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) {
507         continue;
508       }
509 
510       ShellPrintEx(-1,-1,L"\n=========================================================\n");
511       ShellPrintHiiEx(-1,-1,NULL,
512         STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),
513         gShellDebug1HiiHandle,
514         SmbiosStruct.Hdr->Type,
515         SmbiosStruct.Hdr->Handle
516        );
517       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);
518       //
519       // Addr of structure in structure in table
520       //
521       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer);
522       DumpHex (0, 0, Length, Buffer);
523 
524 /*
525       //
526       // Get internal commands, such as change options.
527       //
528       Status = WaitEnter ();
529       if (EFI_ERROR (Status)) {
530         if (Status == EFI_ABORTED) {
531           return EFI_SUCCESS;
532         }
533 
534         return Status;
535       }
536 */
537 
538       if (gShowType != SHOW_NONE) {
539         //
540         // Print structure information
541         //
542         SmbiosPrintStructure (&SmbiosStruct, gShowType);
543         ShellPrintEx(-1,-1,L"\n");
544 
545 /*
546         //
547         // Get internal commands, such as change options.
548         //
549         Status = WaitEnter ();
550         if (EFI_ERROR (Status)) {
551           if (Status == EFI_ABORTED) {
552             return EFI_SUCCESS;
553           }
554 
555           return Status;
556         }
557 */
558       }
559       if (!RandomView) {
560         break;
561       }
562       //
563       // Support Execution Interrupt.
564       //
565       if (ShellGetExecutionBreakFlag ()) {
566         return EFI_ABORTED;
567       }
568     }
569 
570     ShellPrintEx(-1,-1,L"\n=========================================================\n");
571     return EFI_SUCCESS;
572   }
573 
574   return EFI_BAD_BUFFER_SIZE;
575 }
576 
577 /**
578   Function to initialize the global mStatisticsTable object.
579 
580   @retval EFI_SUCCESS           print is successful.
581 **/
582 EFI_STATUS
InitSmbiosTableStatistics(VOID)583 InitSmbiosTableStatistics (
584   VOID
585   )
586 {
587   UINT16                    Handle;
588   UINT8                     *Buffer;
589   UINT16                    Length;
590   UINT16                    Offset;
591   UINT16                    Index;
592 
593   SMBIOS_STRUCTURE_POINTER  SmbiosStruct;
594   SMBIOS_TABLE_ENTRY_POINT  *SMBiosTable;
595   STRUCTURE_STATISTICS      *StatisticsPointer;
596 
597   SMBiosTable = NULL;
598   LibSmbiosGetEPS (&SMBiosTable);
599   if (SMBiosTable == NULL) {
600     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
601     return EFI_NOT_FOUND;
602   }
603 
604   if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) != 0) {
605     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE), gShellDebug1HiiHandle);
606     return EFI_INVALID_PARAMETER;
607   }
608   //
609   // Allocate memory to mStatisticsTable
610   //
611   if (mStatisticsTable != NULL) {
612     FreePool (mStatisticsTable);
613     mStatisticsTable = NULL;
614   }
615 
616   mStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));
617 
618   if (mStatisticsTable == NULL) {
619     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);
620     return EFI_OUT_OF_RESOURCES;
621   }
622 
623   Offset      = 0;
624   StatisticsPointer = mStatisticsTable;
625 
626   //
627   // search from the first one
628   //
629   Handle = INVALID_HANDLE;
630   LibGetSmbiosStructure (&Handle, NULL, NULL);
631   for (Index = 1; Index <= SMBiosTable->NumberOfSmbiosStructures; Index++) {
632     //
633     // If reach the end of table, break..
634     //
635     if (Handle == INVALID_HANDLE) {
636       break;
637     }
638     //
639     // After LibGetSmbiosStructure(), handle then point to the next!
640     //
641     if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
642       break;
643     }
644 
645     SmbiosStruct.Raw = Buffer;
646 
647     //
648     // general statistics
649     //
650     StatisticsPointer->Index  = Index;
651     StatisticsPointer->Type   = SmbiosStruct.Hdr->Type;
652     StatisticsPointer->Handle = SmbiosStruct.Hdr->Handle;
653     StatisticsPointer->Length = Length;
654     StatisticsPointer->Addr   = Offset;
655 
656     Offset = (UINT16) (Offset + Length);
657 
658     StatisticsPointer         = &mStatisticsTable[Index];
659   }
660 
661   return EFI_SUCCESS;
662 }
663 
664 /**
665   @param[in]  Smbios64EntryPoint          SMBIOS 64-bit entry point.
666   @param[out] NumberOfSmbios64Structures  The number of structures in 64-bit SMBIOS table.
667   @param[out] Smbios64TableLength         The total length of 64-bit SMBIOS table.
668 
669   @retval EFI_SUCCESS           					Calculation was successful.
670 **/
671 EFI_STATUS
CalculateSmbios64BitStructureCountAndLength(SMBIOS_TABLE_3_0_ENTRY_POINT * Smbios64EntryPoint,UINTN * NumberOfSmbios64Structures,UINTN * Smbios64TableLength)672 CalculateSmbios64BitStructureCountAndLength (
673   SMBIOS_TABLE_3_0_ENTRY_POINT    *Smbios64EntryPoint,
674   UINTN                           *NumberOfSmbios64Structures,
675   UINTN                           *Smbios64TableLength
676 )
677 {
678   SMBIOS_STRUCTURE_POINTER        Smbios;
679   UINT8                           *Raw;
680 
681   *Smbios64TableLength = 0;
682   *NumberOfSmbios64Structures = 0;
683 
684   Smbios.Raw = (UINT8 *)(UINTN)(Smbios64EntryPoint->TableAddress);
685   while (TRUE) {
686     if (Smbios.Hdr->Type == 127) {
687       //
688       // Reach the end of table type 127
689       //
690       (*NumberOfSmbios64Structures)++;
691       (*Smbios64TableLength) += sizeof (SMBIOS_STRUCTURE);
692       return EFI_SUCCESS;
693     }
694 
695     Raw = Smbios.Raw;
696     //
697     // Walk to next structure
698     //
699     LibGetSmbiosString (&Smbios, (UINT16) (-1));
700     //
701     // Length = Next structure head - this structure head
702     //
703     (*Smbios64TableLength) += (UINTN) (Smbios.Raw - Raw);
704     if ((*Smbios64TableLength) > Smbios64EntryPoint->TableMaximumSize) {
705     	//
706     	// The actual table length exceeds maximum table size,
707     	// There should be something wrong with SMBIOS table.
708     	//
709     	return EFI_INVALID_PARAMETER;
710     }
711     (*NumberOfSmbios64Structures)++;
712   }
713 }
714 
715 /**
716   Function to initialize the global mSmbios64BitStatisticsTable object.
717 
718   @retval EFI_SUCCESS           print is successful.
719 **/
720 EFI_STATUS
InitSmbios64BitTableStatistics(VOID)721 InitSmbios64BitTableStatistics (
722   VOID
723   )
724 {
725   UINT16                    Handle;
726   UINT8                     *Buffer;
727   UINT16                    Length;
728   UINT16                    Offset;
729   UINT16                    Index;
730 	EFI_STATUS								Status;
731   SMBIOS_STRUCTURE_POINTER      SmbiosStruct;
732   SMBIOS_TABLE_3_0_ENTRY_POINT  *SMBiosTable;
733   STRUCTURE_STATISTICS          *StatisticsPointer;
734 
735   SMBiosTable = NULL;
736   LibSmbios64BitGetEPS (&SMBiosTable);
737   if (SMBiosTable == NULL) {
738     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
739     return EFI_NOT_FOUND;
740   }
741 
742   if (CompareMem (SMBiosTable->AnchorString, "_SM3_", 5) != 0) {
743     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE), gShellDebug1HiiHandle);
744     return EFI_INVALID_PARAMETER;
745   }
746   //
747   // Allocate memory to mSmbios64BitStatisticsTable
748   //
749   if (mSmbios64BitStatisticsTable != NULL) {
750     FreePool (mSmbios64BitStatisticsTable);
751     mSmbios64BitStatisticsTable = NULL;
752   }
753   //
754   // Calculate number of smbios structures
755   //
756   Status = CalculateSmbios64BitStructureCountAndLength (SMBiosTable, &mNumberOfSmbios64BitStructures, &mSmbios64BitTableLength);
757   if ((EFI_ERROR (Status)) || (mSmbios64BitTableLength > SMBiosTable->TableMaximumSize)) {
758   	return EFI_INVALID_PARAMETER;
759   }
760 
761   mSmbios64BitStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (mNumberOfSmbios64BitStructures * sizeof (STRUCTURE_STATISTICS));
762 
763   if (mSmbios64BitStatisticsTable == NULL) {
764     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);
765     return EFI_OUT_OF_RESOURCES;
766   }
767 
768   Offset      = 0;
769   StatisticsPointer = mSmbios64BitStatisticsTable;
770 
771   //
772   // search from the first one
773   //
774   Handle = INVALID_HANDLE;
775   LibGetSmbios64BitStructure (&Handle, NULL, NULL);
776   for (Index = 1; Index <= mNumberOfSmbios64BitStructures; Index++) {
777     //
778     // If reach the end of table, break..
779     //
780     if (Handle == INVALID_HANDLE) {
781       break;
782     }
783     //
784     // After LibGetSmbios64BitStructure(), handle then point to the next!
785     //
786     if (LibGetSmbios64BitStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
787       break;
788     }
789 
790     SmbiosStruct.Raw = Buffer;
791 
792     //
793     // general statistics
794     //
795     StatisticsPointer->Index  = Index;
796     StatisticsPointer->Type   = SmbiosStruct.Hdr->Type;
797     StatisticsPointer->Handle = SmbiosStruct.Hdr->Handle;
798     StatisticsPointer->Length = Length;
799     StatisticsPointer->Addr   = Offset;
800 
801     Offset = (UINT16) (Offset + Length);
802 
803     StatisticsPointer         = &mSmbios64BitStatisticsTable[Index];
804   }
805 
806   return EFI_SUCCESS;
807 }
808 
809 /**
810   Function to display the global mStatisticsTable object.
811 
812   @param[in] Option             ECHO, NORMAL, or DETAIL control the amount of detail displayed.
813 
814   @retval EFI_SUCCESS           print is successful.
815 **/
816 EFI_STATUS
DisplayStatisticsTable(IN UINT8 Option)817 DisplayStatisticsTable (
818   IN   UINT8   Option
819   )
820 {
821   UINTN                    Index;
822   UINTN                    Num;
823   STRUCTURE_STATISTICS     *StatisticsPointer;
824   SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
825 
826   SMBiosTable = NULL;
827   if (Option < SHOW_OUTLINE) {
828     return EFI_SUCCESS;
829   }
830   //
831   // display EPS information firstly
832   //
833   LibSmbiosGetEPS (&SMBiosTable);
834   if (SMBiosTable == NULL) {
835     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
836     return EFI_UNSUPPORTED;
837   }
838 
839   ShellPrintEx(-1,-1,L"\n============================================================\n");
840   SmbiosPrintEPSInfo (SMBiosTable, Option);
841 
842   if (Option < SHOW_NORMAL) {
843     return EFI_SUCCESS;
844   }
845 
846   if (mStatisticsTable == NULL) {
847     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);
848     return EFI_NOT_FOUND;
849   }
850 
851   ShellPrintEx(-1,-1,L"============================================================\n");
852   StatisticsPointer = &mStatisticsTable[0];
853   Num         = SMBiosTable->NumberOfSmbiosStructures;
854   //
855   // display statistics table content
856   //
857   for (Index = 1; Index <= Num; Index++) {
858     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX), gShellDebug1HiiHandle, StatisticsPointer->Index);
859     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE), gShellDebug1HiiHandle, StatisticsPointer->Type);
860     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE), gShellDebug1HiiHandle, StatisticsPointer->Handle);
861     if (Option >= SHOW_DETAIL) {
862       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET), gShellDebug1HiiHandle, StatisticsPointer->Addr);
863       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH), gShellDebug1HiiHandle, StatisticsPointer->Length);
864     }
865 
866     ShellPrintEx(-1,-1,L"\n");
867     StatisticsPointer = &mStatisticsTable[Index];
868 /*
869     //
870     // Display 20 lines and wait for a page break
871     //
872     if (Index % 20 == 0) {
873       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
874       Status = WaitEnter ();
875       if (EFI_ERROR (Status)) {
876         if (Status == EFI_ABORTED) {
877           return EFI_SUCCESS;
878         }
879 
880         return Status;
881       }
882     }
883 */
884   }
885 
886   return EFI_SUCCESS;
887 }
888 
889 /**
890   Function to display the global mSmbios64BitStatisticsTable object.
891 
892   @param[in] Option             ECHO, NORMAL, or DETAIL control the amount of detail displayed.
893 
894   @retval EFI_SUCCESS           print is successful.
895 **/
896 EFI_STATUS
DisplaySmbios64BitStatisticsTable(IN UINT8 Option)897 DisplaySmbios64BitStatisticsTable (
898   IN   UINT8   Option
899   )
900 {
901   UINTN                    Index;
902   UINTN                    Num;
903   STRUCTURE_STATISTICS     *StatisticsPointer;
904   SMBIOS_TABLE_3_0_ENTRY_POINT *SMBiosTable;
905 
906   SMBiosTable = NULL;
907   if (Option < SHOW_OUTLINE) {
908     return EFI_SUCCESS;
909   }
910   //
911   // display EPS information firstly
912   //
913   LibSmbios64BitGetEPS (&SMBiosTable);
914   if (SMBiosTable == NULL) {
915     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
916     return EFI_UNSUPPORTED;
917   }
918 
919   ShellPrintEx(-1,-1,L"\n============================================================\n");
920   Smbios64BitPrintEPSInfo (SMBiosTable, Option);
921 
922   if (Option < SHOW_NORMAL) {
923     return EFI_SUCCESS;
924   }
925 
926   if (mSmbios64BitStatisticsTable == NULL) {
927     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);
928     return EFI_NOT_FOUND;
929   }
930 
931   ShellPrintEx(-1,-1,L"============================================================\n");
932   StatisticsPointer = &mSmbios64BitStatisticsTable[0];
933   Num         = mNumberOfSmbios64BitStructures;
934   //
935   // display statistics table content
936   //
937   for (Index = 1; Index <= Num; Index++) {
938     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX), gShellDebug1HiiHandle, StatisticsPointer->Index);
939     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE), gShellDebug1HiiHandle, StatisticsPointer->Type);
940     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE), gShellDebug1HiiHandle, StatisticsPointer->Handle);
941     if (Option >= SHOW_DETAIL) {
942       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET), gShellDebug1HiiHandle, StatisticsPointer->Addr);
943       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH), gShellDebug1HiiHandle, StatisticsPointer->Length);
944     }
945 
946     ShellPrintEx(-1,-1,L"\n");
947     StatisticsPointer = &mSmbios64BitStatisticsTable[Index];
948 /*
949     //
950     // Display 20 lines and wait for a page break
951     //
952     if (Index % 20 == 0) {
953       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
954       Status = WaitEnter ();
955       if (EFI_ERROR (Status)) {
956         if (Status == EFI_ABORTED) {
957           return EFI_SUCCESS;
958         }
959 
960         return Status;
961       }
962     }
963 */
964   }
965 
966   return EFI_SUCCESS;
967 }
968 
969 /**
970   function to return a string of the detail level.
971 
972   @param[in] ShowType         The detail level whose name is desired in clear text.
973 
974   @return   A pointer to a string representing the ShowType (or 'undefined type' if not known).
975 **/
976 CHAR16 *
GetShowTypeString(UINT8 ShowType)977 GetShowTypeString (
978   UINT8 ShowType
979   )
980 {
981   //
982   // show type
983   //
984   switch (ShowType) {
985 
986   case SHOW_NONE:
987     return L"SHOW_NONE";
988 
989   case SHOW_OUTLINE:
990     return L"SHOW_OUTLINE";
991 
992   case SHOW_NORMAL:
993     return L"SHOW_NORMAL";
994 
995   case SHOW_DETAIL:
996     return L"SHOW_DETAIL";
997 
998   case SHOW_ALL:
999     return L"SHOW_ALL";
1000 
1001   default:
1002     return L"Undefined type";
1003   }
1004 }
1005 
1006