]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c
Add SMBIOS 2.7.1 support to SmbiosView command.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / SmbiosView.c
1 /** @file
2 Tools of clarify the content of the smbios table.
3
4 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "../UefiShellDebug1CommandsLib.h"
16 #include "LibSmbiosView.h"
17 #include "SmbiosView.h"
18 #include "PrintInfo.h"
19 #include "QueryTable.h"
20
21 UINT8 gShowType = SHOW_DETAIL;
22 STATIC STRUCTURE_STATISTICS *mStatisticsTable = NULL;
23
24 UINT8 SmbiosMajorVersion;
25 UINT8 SmbiosMinorVersion;
26
27 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
28 {L"-t", TypeValue},
29 {L"-h", TypeValue},
30 {L"-s", TypeFlag},
31 {L"-a", TypeFlag},
32 {NULL, TypeMax}
33 };
34
35 /**
36 Function for 'smbiosview' command.
37
38 @param[in] ImageHandle Handle to the Image (NULL if Internal).
39 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
40 **/
41 SHELL_STATUS
42 EFIAPI
43 ShellCommandRunSmbiosView (
44 IN EFI_HANDLE ImageHandle,
45 IN EFI_SYSTEM_TABLE *SystemTable
46 )
47 {
48 UINT8 StructType;
49 UINT16 StructHandle;
50 EFI_STATUS Status;
51 BOOLEAN RandomView;
52 LIST_ENTRY *Package;
53 CHAR16 *ProblemParam;
54 SHELL_STATUS ShellStatus;
55 CONST CHAR16 *Temp;
56
57 mStatisticsTable = NULL;
58 Package = NULL;
59 ShellStatus = SHELL_SUCCESS;
60
61 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
62 if (EFI_ERROR(Status)) {
63 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
64 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
65 FreePool(ProblemParam);
66 ShellStatus = SHELL_INVALID_PARAMETER;
67 } else {
68 ASSERT(FALSE);
69 }
70 } else {
71 if (ShellCommandLineGetCount(Package) > 1) {
72 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
73 ShellStatus = SHELL_INVALID_PARAMETER;
74 } else if (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetValue(Package, L"-t") == NULL) {
75 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-t");
76 ShellStatus = SHELL_INVALID_PARAMETER;
77 } else if (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetValue(Package, L"-h") == NULL) {
78 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-h");
79 ShellStatus = SHELL_INVALID_PARAMETER;
80 } else if (
81 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-h")) ||
82 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-s")) ||
83 (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-a")) ||
84 (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-s")) ||
85 (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-a")) ||
86 (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-a"))
87 ) {
88 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
89 ShellStatus = SHELL_INVALID_PARAMETER;
90 } else {
91
92 //
93 // Init Lib
94
95 Status = LibSmbiosInit ();
96 if (EFI_ERROR (Status)) {
97 ShellStatus = SHELL_NOT_FOUND;
98 goto Done;
99 }
100 //
101 // build statistics table
102 //
103 Status = InitSmbiosTableStatistics ();
104 if (EFI_ERROR (Status)) {
105 ShellStatus = SHELL_NOT_FOUND;
106 goto Done;
107 }
108
109 StructType = STRUCTURE_TYPE_RANDOM;
110 RandomView = TRUE;
111 //
112 // Initialize the StructHandle to be the first handle
113 //
114 StructHandle = INVALID_HANDLE;
115 LibGetSmbiosStructure (&StructHandle, NULL, NULL);
116
117 Temp = ShellCommandLineGetValue(Package, L"-t");
118 if (Temp != NULL) {
119 StructType = (UINT8) ShellStrToUintn (Temp);
120 }
121
122 Temp = ShellCommandLineGetValue(Package, L"-h");
123 if (Temp != NULL) {
124 RandomView = FALSE;
125 StructHandle = (UINT16) ShellStrToUintn(Temp);
126 }
127
128 if (ShellCommandLineGetFlag(Package, L"-s")) {
129 Status = DisplayStatisticsTable (SHOW_DETAIL);
130 if (EFI_ERROR(Status)) {
131 ShellStatus = SHELL_NOT_FOUND;
132 }
133 goto Done;
134 }
135
136 if (ShellCommandLineGetFlag(Package, L"-a")) {
137 gShowType = SHOW_ALL;
138 }
139 //
140 // Show SMBIOS structure information
141 //
142 Status = SMBiosView (StructType, StructHandle, gShowType, RandomView);
143 if (EFI_ERROR(Status)) {
144 ShellStatus = SHELL_NOT_FOUND;
145 }
146 }
147 }
148 Done:
149 //
150 // Release resources
151 //
152 if (mStatisticsTable != NULL) {
153 //
154 // Release statistics table
155 //
156 FreePool (mStatisticsTable);
157 mStatisticsTable = NULL;
158 }
159
160 if (Package != NULL) {
161 ShellCommandLineFreeVarList (Package);
162 }
163
164 LibSmbiosCleanup ();
165
166 return ShellStatus;
167 }
168
169 /**
170 Query all structures Data from SMBIOS table and Display
171 the information to users as required display option.
172
173 @param[in] QueryType Structure type to view.
174 @param[in] QueryHandle Structure handle to view.
175 @param[in] Option Display option: none,outline,normal,detail.
176 @param[in] RandomView Support for -h parameter.
177
178 @retval EFI_SUCCESS print is successful.
179 @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table.
180 **/
181 EFI_STATUS
182 EFIAPI
183 SMBiosView (
184 IN UINT8 QueryType,
185 IN UINT16 QueryHandle,
186 IN UINT8 Option,
187 IN BOOLEAN RandomView
188 )
189 {
190 UINT16 Handle;
191 UINT8 *Buffer;
192 UINT16 Length;
193 UINTN Index;
194
195 SMBIOS_STRUCTURE_POINTER SmbiosStruct;
196 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
197
198 SMBiosTable = NULL;
199 LibSmbiosGetEPS (&SMBiosTable);
200 if (SMBiosTable == NULL) {
201 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
202 return EFI_BAD_BUFFER_SIZE;
203 }
204
205 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) == 0) {
206 //
207 // Have got SMBIOS table
208 //
209 SmbiosPrintEPSInfo (SMBiosTable, Option);
210
211 SmbiosMajorVersion = SMBiosTable->MajorVersion;
212 SmbiosMinorVersion = SMBiosTable->MinorVersion;
213
214 ShellPrintEx(-1,-1,L"=========================================================\n");
215 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);
216
217 if (QueryType == STRUCTURE_TYPE_RANDOM) {
218 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);
219 } else {
220 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);
221 }
222
223 if (RandomView) {
224 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);
225 } else {
226 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);
227 }
228
229 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle);
230 ShellPrintEx(-1,-1,GetShowTypeString (gShowType));
231 ShellPrintEx(-1,-1,L"\n\n");
232
233 /*
234 //
235 // Get internal commands, such as change options.
236 //
237 Status = WaitEnter ();
238 if (EFI_ERROR (Status)) {
239 if (Status == EFI_ABORTED) {
240 return EFI_SUCCESS;
241 }
242
243 return Status;
244 }
245 */
246
247 //
248 // Searching and display structure info
249 //
250 Handle = QueryHandle;
251 for (Index = 0; Index < SMBiosTable->NumberOfSmbiosStructures; Index++) {
252 //
253 // if reach the end of table, break..
254 //
255 if (Handle == INVALID_HANDLE) {
256 break;
257 }
258 //
259 // handle then point to the next!
260 //
261 if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
262 break;
263 }
264
265 SmbiosStruct.Raw = Buffer;
266
267 //
268 // if QueryType==Random, print this structure.
269 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
270 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
271 //
272 if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) {
273 continue;
274 }
275
276 ShellPrintEx(-1,-1,L"\n=========================================================\n");
277 ShellPrintHiiEx(-1,-1,NULL,
278 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),
279 gShellDebug1HiiHandle,
280 SmbiosStruct.Hdr->Type,
281 SmbiosStruct.Hdr->Handle
282 );
283 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);
284 //
285 // Addr of structure in structure in table
286 //
287 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer);
288 DumpHex (0, 0, Length, Buffer);
289
290 /*
291 //
292 // Get internal commands, such as change options.
293 //
294 Status = WaitEnter ();
295 if (EFI_ERROR (Status)) {
296 if (Status == EFI_ABORTED) {
297 return EFI_SUCCESS;
298 }
299
300 return Status;
301 }
302 */
303
304 if (gShowType != SHOW_NONE) {
305 //
306 // Print structure information
307 //
308 SmbiosPrintStructure (&SmbiosStruct, gShowType);
309 ShellPrintEx(-1,-1,L"\n");
310
311 /*
312 //
313 // Get internal commands, such as change options.
314 //
315 Status = WaitEnter ();
316 if (EFI_ERROR (Status)) {
317 if (Status == EFI_ABORTED) {
318 return EFI_SUCCESS;
319 }
320
321 return Status;
322 }
323 */
324 }
325 if (!RandomView) {
326 break;
327 }
328 }
329
330 ShellPrintEx(-1,-1,L"\n=========================================================\n");
331 return EFI_SUCCESS;
332 }
333
334 return EFI_BAD_BUFFER_SIZE;
335 }
336
337 /**
338 Function to initialize the global mStatisticsTable object.
339
340 @retval EFI_SUCCESS print is successful.
341 **/
342 EFI_STATUS
343 EFIAPI
344 InitSmbiosTableStatistics (
345 VOID
346 )
347 {
348 UINT16 Handle;
349 UINT8 *Buffer;
350 UINT16 Length;
351 UINT16 Offset;
352 UINT16 Index;
353
354 SMBIOS_STRUCTURE_POINTER SmbiosStruct;
355 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
356 STRUCTURE_STATISTICS *StatisticsPointer;
357
358 SMBiosTable = NULL;
359 LibSmbiosGetEPS (&SMBiosTable);
360 if (SMBiosTable == NULL) {
361 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
362 return EFI_NOT_FOUND;
363 }
364
365 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) != 0) {
366 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE), gShellDebug1HiiHandle);
367 return EFI_INVALID_PARAMETER;
368 }
369 //
370 // Allocate memory to mStatisticsTable
371 //
372 if (mStatisticsTable != NULL) {
373 FreePool (mStatisticsTable);
374 mStatisticsTable = NULL;
375 }
376
377 mStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));
378
379 if (mStatisticsTable == NULL) {
380 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);
381 return EFI_OUT_OF_RESOURCES;
382 }
383
384 Offset = 0;
385 StatisticsPointer = mStatisticsTable;
386
387 //
388 // search from the first one
389 //
390 Handle = INVALID_HANDLE;
391 LibGetSmbiosStructure (&Handle, NULL, NULL);
392 for (Index = 1; Index <= SMBiosTable->NumberOfSmbiosStructures; Index++) {
393 //
394 // If reach the end of table, break..
395 //
396 if (Handle == INVALID_HANDLE) {
397 break;
398 }
399 //
400 // After LibGetSmbiosStructure(), handle then point to the next!
401 //
402 if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
403 break;
404 }
405
406 SmbiosStruct.Raw = Buffer;
407
408 //
409 // general statistics
410 //
411 StatisticsPointer->Index = Index;
412 StatisticsPointer->Type = SmbiosStruct.Hdr->Type;
413 StatisticsPointer->Handle = SmbiosStruct.Hdr->Handle;
414 StatisticsPointer->Length = Length;
415 StatisticsPointer->Addr = Offset;
416
417 Offset = (UINT16) (Offset + Length);
418
419 StatisticsPointer = &mStatisticsTable[Index];
420 }
421
422 return EFI_SUCCESS;
423 }
424
425 /**
426 Function to display the global mStatisticsTable object.
427
428 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
429
430 @retval EFI_SUCCESS print is successful.
431 **/
432 EFI_STATUS
433 EFIAPI
434 DisplayStatisticsTable (
435 IN UINT8 Option
436 )
437 {
438 UINTN Index;
439 UINTN Num;
440 STRUCTURE_STATISTICS *StatisticsPointer;
441 SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
442
443 SMBiosTable = NULL;
444 if (Option < SHOW_OUTLINE) {
445 return EFI_SUCCESS;
446 }
447 //
448 // display EPS information firstly
449 //
450 LibSmbiosGetEPS (&SMBiosTable);
451 if (SMBiosTable == NULL) {
452 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
453 return EFI_UNSUPPORTED;
454 }
455
456 ShellPrintEx(-1,-1,L"\n============================================================\n");
457 SmbiosPrintEPSInfo (SMBiosTable, Option);
458
459 if (Option < SHOW_NORMAL) {
460 return EFI_SUCCESS;
461 }
462
463 if (mStatisticsTable == NULL) {
464 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);
465 return EFI_NOT_FOUND;
466 }
467
468 ShellPrintEx(-1,-1,L"============================================================\n");
469 StatisticsPointer = &mStatisticsTable[0];
470 Num = SMBiosTable->NumberOfSmbiosStructures;
471 //
472 // display statistics table content
473 //
474 for (Index = 1; Index <= Num; Index++) {
475 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX), gShellDebug1HiiHandle, StatisticsPointer->Index);
476 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE), gShellDebug1HiiHandle, StatisticsPointer->Type);
477 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE), gShellDebug1HiiHandle, StatisticsPointer->Handle);
478 if (Option >= SHOW_DETAIL) {
479 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET), gShellDebug1HiiHandle, StatisticsPointer->Addr);
480 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH), gShellDebug1HiiHandle, StatisticsPointer->Length);
481 }
482
483 ShellPrintEx(-1,-1,L"\n");
484 StatisticsPointer = &mStatisticsTable[Index];
485 /*
486 //
487 // Display 20 lines and wait for a page break
488 //
489 if (Index % 20 == 0) {
490 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
491 Status = WaitEnter ();
492 if (EFI_ERROR (Status)) {
493 if (Status == EFI_ABORTED) {
494 return EFI_SUCCESS;
495 }
496
497 return Status;
498 }
499 }
500 */
501 }
502
503 return EFI_SUCCESS;
504 }
505
506 /**
507 function to return a string of the detail level.
508
509 @param[in] ShowType The detail level whose name is desired in clear text.
510
511 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
512 **/
513 CHAR16 *
514 EFIAPI
515 GetShowTypeString (
516 UINT8 ShowType
517 )
518 {
519 //
520 // show type
521 //
522 switch (ShowType) {
523
524 case SHOW_NONE:
525 return L"SHOW_NONE";
526
527 case SHOW_OUTLINE:
528 return L"SHOW_OUTLINE";
529
530 case SHOW_NORMAL:
531 return L"SHOW_NORMAL";
532
533 case SHOW_DETAIL:
534 return L"SHOW_DETAIL";
535
536 case SHOW_ALL:
537 return L"SHOW_ALL";
538
539 default:
540 return L"Undefined type";
541 }
542 }
543