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