blob: 05dc0d56d599fd0da4d7ef93a27fb75172de9927 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @file
2 Main file for Dmem shell Debug1 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2011, 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 <Protocol/PciRootBridgeIo.h>
18#include <Guid/Acpi.h>
19#include <Guid/Mps.h>
20#include <Guid/SmBios.h>
21#include <Guid/SalSystemTable.h>
22
23/**
24 Make a printable character.
25
26 If Char is printable then return it, otherwise return a question mark.
27
28 @param[in] Char The character to make printable.
29
30 @return A printable character representing Char.
31**/
32CHAR16
33EFIAPI
34MakePrintable(
35 IN CONST CHAR16 Char
36 )
37{
38 if ((Char < 0x20 && Char > 0)||(Char > 126)) {
39 return (L'?');
40 }
41 return (Char);
42}
43
44/**
45 Display some Memory-Mapped-IO memory.
46
47 @param[in] Address The starting address to display.
48 @param[in] Size The length of memory to display.
49**/
50SHELL_STATUS
51EFIAPI
52DisplayMmioMemory(
53 IN CONST VOID *Address,
54 IN CONST UINTN Size
55 )
56{
57 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRbIo;
58 EFI_STATUS Status;
59 VOID *Buffer;
60 SHELL_STATUS ShellStatus;
61
62 ShellStatus = SHELL_SUCCESS;
63
64 Status = gBS->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid, NULL, (VOID**)&PciRbIo);
65 if (EFI_ERROR(Status)) {
66 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"dmem");
67 return (SHELL_NOT_FOUND);
68 }
69 Buffer = AllocateZeroPool(Size);
70 ASSERT(Buffer != NULL);
71
72 Status = PciRbIo->Mem.Read(PciRbIo, EfiPciWidthUint8, (UINT64)(UINTN)Address, Size, Buffer);
73 if (EFI_ERROR(Status)) {
74 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_ER), gShellDebug1HiiHandle, L"dmem");
75 ShellStatus = SHELL_NOT_FOUND;
76 } else {
77 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);
78 DumpHex(2, (UINTN)Address, Size, Buffer);
79 }
80
81 FreePool(Buffer);
82 return (ShellStatus);
83}
84
85STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
86 {L"-mmio", TypeFlag},
87 {NULL, TypeMax}
88 };
89
90/**
91 Function for 'dmem' command.
92
93 @param[in] ImageHandle Handle to the Image (NULL if Internal).
94 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
95**/
96SHELL_STATUS
97EFIAPI
98ShellCommandRunDmem (
99 IN EFI_HANDLE ImageHandle,
100 IN EFI_SYSTEM_TABLE *SystemTable
101 )
102{
103 EFI_STATUS Status;
104 LIST_ENTRY *Package;
105 CHAR16 *ProblemParam;
106 SHELL_STATUS ShellStatus;
107 VOID *Address;
108 UINT64 Size;
109 CONST CHAR16 *Temp1;
110 UINT64 AcpiTableAddress;
111 UINT64 Acpi20TableAddress;
112 UINT64 SalTableAddress;
113 UINT64 SmbiosTableAddress;
114 UINT64 MpsTableAddress;
115 UINTN TableWalker;
116
117 ShellStatus = SHELL_SUCCESS;
118 Status = EFI_SUCCESS;
119 Address = NULL;
120 Size = 0;
121
122 //
123 // initialize the shell lib (we must be in non-auto-init...)
124 //
125 Status = ShellInitialize();
126 ASSERT_EFI_ERROR(Status);
127
128 Status = CommandInit();
129 ASSERT_EFI_ERROR(Status);
130
131 //
132 // parse the command line
133 //
134 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
135 if (EFI_ERROR(Status)) {
136 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
137 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmem", ProblemParam);
138 FreePool(ProblemParam);
139 ShellStatus = SHELL_INVALID_PARAMETER;
140 } else {
141 ASSERT(FALSE);
142 }
143 } else {
144 if (ShellCommandLineGetCount(Package) > 3) {
145 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem");
146 ShellStatus = SHELL_INVALID_PARAMETER;
147 } else {
148 Temp1 = ShellCommandLineGetRawValue(Package, 1);
149 if (Temp1 == NULL) {
150 Address = gST;
151 Size = 512;
152 } else {
153 if (!ShellIsHexOrDecimalNumber(Temp1, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, (UINT64*)&Address, TRUE, FALSE))) {
154 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1);
155 ShellStatus = SHELL_INVALID_PARAMETER;
156 }
157 Temp1 = ShellCommandLineGetRawValue(Package, 2);
158 if (Temp1 == NULL) {
159 Size = 512;
160 } else {
161 if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, &Size, TRUE, FALSE))) {
162 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1);
163 ShellStatus = SHELL_INVALID_PARAMETER;
164 }
165 }
166 }
167 }
168
169 if (ShellStatus == SHELL_SUCCESS) {
170 if (!ShellCommandLineGetFlag(Package, L"-mmio")) {
171 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);
172 DumpHex(2, (UINTN)Address, (UINTN)Size, Address);
173 if (Address == (VOID*)gST) {
174 Acpi20TableAddress = 0;
175 AcpiTableAddress = 0;
176 SalTableAddress = 0;
177 SmbiosTableAddress = 0;
178 MpsTableAddress = 0;
179 for (TableWalker = 0 ; TableWalker < gST->NumberOfTableEntries ; TableWalker++) {
180 if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi20TableGuid)) {
181 Acpi20TableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
182 continue;
183 }
184 if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi10TableGuid)) {
185 AcpiTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
186 continue;
187 }
188 if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSalSystemTableGuid)) {
189 SalTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
190 continue;
191 }
192 if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSmbiosTableGuid)) {
193 SmbiosTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
194 continue;
195 }
196 if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMpsTableGuid)) {
197 MpsTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
198 continue;
199 }
200 }
201
202 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE), gShellDebug1HiiHandle,
203 (UINT64)(UINTN)Address,
204 gST->Hdr.HeaderSize,
205 gST->Hdr.Revision,
206 (UINT64)(UINTN)gST->ConIn,
207 (UINT64)(UINTN)gST->ConOut,
208 (UINT64)(UINTN)gST->StdErr,
209 (UINT64)(UINTN)gST->RuntimeServices,
210 (UINT64)(UINTN)gST->BootServices,
211 SalTableAddress,
212 AcpiTableAddress,
213 Acpi20TableAddress,
214 MpsTableAddress,
215 SmbiosTableAddress
216 );
217 }
218 } else {
219 ShellStatus = DisplayMmioMemory(Address, (UINTN)Size);
220 }
221 }
222
223
224 ShellCommandLineFreeVarList (Package);
225 }
226
227 return (ShellStatus);
228}