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