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