]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c
add comments to function declarations and definitions and updated to match coding...
[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 - 2011, 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 = STRUCTURE_HANDLE_INVALID;
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[1024];
192 //
193 // bigger than SMBIOS_STRUCTURE_TABLE.MaxStructureSize
194 //
195 UINT16 Length;
196 UINTN Index;
197 UINT16 Offset;
198 //
199 // address offset from structure table head.
200 //
201 UINT32 TableHead;
202 //
203 // structure table head.
204 //
205
206 SMBIOS_STRUCTURE_POINTER SmbiosStruct;
207 SMBIOS_STRUCTURE_TABLE *SMBiosTable;
208
209 SMBiosTable = NULL;
210 LibSmbiosGetEPS (&SMBiosTable);
211 if (SMBiosTable == NULL) {
212 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
213 return EFI_BAD_BUFFER_SIZE;
214 }
215
216 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) == 0) {
217 //
218 // Have get SMBIOS table
219 //
220 SmbiosPrintEPSInfo (SMBiosTable, Option);
221
222 SmbiosMajorVersion = SMBiosTable->MajorVersion;
223 SmbiosMinorVersion = SMBiosTable->MinorVersion;
224
225 ShellPrintEx(-1,-1,L"=========================================================\n");
226 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle);
227
228 if (QueryType == STRUCTURE_TYPE_RANDOM) {
229 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle);
230 } else {
231 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType);
232 }
233
234 if (RandomView) {
235 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle);
236 } else {
237 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle);
238 }
239
240 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle);
241 ShellPrintEx(-1,-1,GetShowTypeString (gShowType));
242 ShellPrintEx(-1,-1,L"\n\n");
243
244 /*
245 //
246 // Get internal commands, such as change options.
247 //
248 Status = WaitEnter ();
249 if (EFI_ERROR (Status)) {
250 if (Status == EFI_ABORTED) {
251 return EFI_SUCCESS;
252 }
253
254 return Status;
255 }
256 */
257
258 //
259 // Searching and display structure info
260 //
261 Handle = QueryHandle;
262 TableHead = SMBiosTable->TableAddress;
263 Offset = 0;
264 for (Index = 0; Index < SMBiosTable->NumberOfSmbiosStructures; Index++) {
265 //
266 // if reach the end of table, break..
267 //
268 if (Handle == STRUCTURE_HANDLE_INVALID) {
269 break;
270 }
271 //
272 // handle then point to the next!
273 //
274 if (LibGetSmbiosStructure (&Handle, Buffer, &Length) != DMI_SUCCESS) {
275 break;
276 }
277 Offset = (UINT16) (Offset + Length);
278 SmbiosStruct.Raw = Buffer;
279
280 //
281 // if QueryType==Random, print this structure.
282 // if QueryType!=Random, but Hdr->Type==QueryType, also print it.
283 // only if QueryType != Random and Hdr->Type != QueryType, skiped it.
284 //
285 if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) {
286 continue;
287 }
288
289 ShellPrintEx(-1,-1,L"\n=========================================================\n");
290 ShellPrintHiiEx(-1,-1,NULL,
291 STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT),
292 gShellDebug1HiiHandle,
293 SmbiosStruct.Hdr->Type,
294 SmbiosStruct.Hdr->Handle
295 );
296 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length);
297 //
298 // Addr of structure in structure in table
299 //
300 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, TableHead + Offset);
301 DumpHex (0, 0, Length, Buffer);
302
303 /*
304 //
305 // Get internal commands, such as change options.
306 //
307 Status = WaitEnter ();
308 if (EFI_ERROR (Status)) {
309 if (Status == EFI_ABORTED) {
310 return EFI_SUCCESS;
311 }
312
313 return Status;
314 }
315 */
316
317 if (gShowType != SHOW_NONE) {
318 //
319 // check structure legality
320 //
321 SmbiosCheckStructure (&SmbiosStruct);
322
323 //
324 // Print structure information
325 //
326 SmbiosPrintStructure (&SmbiosStruct, gShowType);
327 ShellPrintEx(-1,-1,L"\n");
328
329 /*
330 //
331 // Get internal commands, such as change options.
332 //
333 Status = WaitEnter ();
334 if (EFI_ERROR (Status)) {
335 if (Status == EFI_ABORTED) {
336 return EFI_SUCCESS;
337 }
338
339 return Status;
340 }
341 */
342 }
343 if (!RandomView) {
344 break;
345 }
346 }
347
348 ShellPrintEx(-1,-1,L"\n=========================================================\n");
349 return EFI_SUCCESS;
350 }
351
352 return EFI_BAD_BUFFER_SIZE;
353 }
354
355 /**
356 Function to initialize the global mStatisticsTable object.
357
358 @retval EFI_SUCCESS print is successful.
359 **/
360 EFI_STATUS
361 EFIAPI
362 InitSmbiosTableStatistics (
363 VOID
364 )
365 {
366 UINT16 Handle;
367 UINT8 Buffer[1024];
368 UINT16 Length;
369 UINT16 Offset;
370 UINT16 Index;
371
372 SMBIOS_STRUCTURE_POINTER SmbiosStruct;
373 SMBIOS_STRUCTURE_TABLE *SMBiosTable;
374 STRUCTURE_STATISTICS *StatisticsPointer;
375
376 SMBiosTable = NULL;
377 LibSmbiosGetEPS (&SMBiosTable);
378 if (SMBiosTable == NULL) {
379 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
380 return EFI_NOT_FOUND;
381 }
382
383 if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) != 0) {
384 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SMBIOS_TABLE), gShellDebug1HiiHandle);
385 return EFI_INVALID_PARAMETER;
386 }
387 //
388 // Allocate memory to mStatisticsTable
389 //
390 if (mStatisticsTable != NULL) {
391 FreePool (mStatisticsTable);
392 mStatisticsTable = NULL;
393 }
394
395 mStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));
396
397 if (mStatisticsTable == NULL) {
398 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);
399 return EFI_OUT_OF_RESOURCES;
400 }
401
402 Offset = 0;
403 StatisticsPointer = mStatisticsTable;
404
405 //
406 // search from the first one
407 //
408 Handle = STRUCTURE_HANDLE_INVALID;
409 LibGetSmbiosStructure (&Handle, NULL, NULL);
410 for (Index = 1; Index <= SMBiosTable->NumberOfSmbiosStructures; Index++) {
411 //
412 // If reach the end of table, break..
413 //
414 if (Handle == STRUCTURE_HANDLE_INVALID) {
415 break;
416 }
417 //
418 // After LibGetSmbiosStructure(), handle then point to the next!
419 //
420 if (LibGetSmbiosStructure (&Handle, Buffer, &Length) != DMI_SUCCESS) {
421 break;
422 }
423
424 SmbiosStruct.Raw = Buffer;
425 Offset = (UINT16) (Offset + Length);
426
427 //
428 // general statistics
429 //
430 StatisticsPointer->Index = Index;
431 StatisticsPointer->Type = SmbiosStruct.Hdr->Type;
432 StatisticsPointer->Handle = SmbiosStruct.Hdr->Handle;
433 StatisticsPointer->Length = Length;
434 StatisticsPointer->Addr = Offset;
435
436 StatisticsPointer = &mStatisticsTable[Index];
437 }
438
439 return EFI_SUCCESS;
440 }
441
442 /**
443 Function to display the global mStatisticsTable object.
444
445 @param[in] Option ECHO, NORMAL, or DETAIL control the amount of detail displayed.
446
447 @retval EFI_SUCCESS print is successful.
448 **/
449 EFI_STATUS
450 EFIAPI
451 DisplayStatisticsTable (
452 IN UINT8 Option
453 )
454 {
455 UINTN Index;
456 UINTN Num;
457 STRUCTURE_STATISTICS *StatisticsPointer;
458 SMBIOS_STRUCTURE_TABLE *SMBiosTable;
459
460 SMBiosTable = NULL;
461 if (Option < SHOW_OUTLINE) {
462 return EFI_SUCCESS;
463 }
464 //
465 // display EPS information firstly
466 //
467 LibSmbiosGetEPS (&SMBiosTable);
468 if (SMBiosTable == NULL) {
469 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle);
470 return EFI_UNSUPPORTED;
471 }
472
473 ShellPrintEx(-1,-1,L"\n============================================================\n");
474 SmbiosPrintEPSInfo (SMBiosTable, Option);
475
476 if (Option < SHOW_NORMAL) {
477 return EFI_SUCCESS;
478 }
479
480 if (mStatisticsTable == NULL) {
481 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_STATS), gShellDebug1HiiHandle);
482 return EFI_NOT_FOUND;
483 }
484
485 ShellPrintEx(-1,-1,L"============================================================\n");
486 StatisticsPointer = &mStatisticsTable[0];
487 Num = SMBiosTable->NumberOfSmbiosStructures;
488 //
489 // display statistics table content
490 //
491 for (Index = 1; Index <= Num; Index++) {
492 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX), gShellDebug1HiiHandle, StatisticsPointer->Index);
493 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE), gShellDebug1HiiHandle, StatisticsPointer->Type);
494 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_HANDLE), gShellDebug1HiiHandle, StatisticsPointer->Handle);
495 if (Option >= SHOW_DETAIL) {
496 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OFFSET), gShellDebug1HiiHandle, StatisticsPointer->Addr);
497 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_LENGTH), gShellDebug1HiiHandle, StatisticsPointer->Length);
498 }
499
500 ShellPrintEx(-1,-1,L"\n");
501 StatisticsPointer = &mStatisticsTable[Index];
502 /*
503 //
504 // Display 20 lines and wait for a page break
505 //
506 if (Index % 20 == 0) {
507 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ENTER_CONTINUE), gShellDebug1HiiHandle);
508 Status = WaitEnter ();
509 if (EFI_ERROR (Status)) {
510 if (Status == EFI_ABORTED) {
511 return EFI_SUCCESS;
512 }
513
514 return Status;
515 }
516 }
517 */
518 }
519
520 return EFI_SUCCESS;
521 }
522
523 /**
524 function to return a string of the detail level.
525
526 @param[in] ShowType The detail level whose name is desired in clear text.
527
528 @return A pointer to a string representing the ShowType (or 'undefined type' if not known).
529 **/
530 CHAR16 *
531 EFIAPI
532 GetShowTypeString (
533 UINT8 ShowType
534 )
535 {
536 //
537 // show type
538 //
539 switch (ShowType) {
540
541 case SHOW_NONE:
542 return L"SHOW_NONE";
543
544 case SHOW_OUTLINE:
545 return L"SHOW_OUTLINE";
546
547 case SHOW_NORMAL:
548 return L"SHOW_NORMAL";
549
550 case SHOW_DETAIL:
551 return L"SHOW_DETAIL";
552
553 case SHOW_ALL:
554 return L"SHOW_ALL";
555
556 default:
557 return L"Undefined type";
558 }
559 }
560
561 /*
562 EFI_STATUS
563 InitializeSmbiosViewApplicationGetLineHelp (
564 OUT CHAR16 **Str
565 )
566 {
567 return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiSmbiosViewGuid, STRING_TOKEN (STR_SMBIOSVIEW_LINE_HELP), Str);
568 }
569 */