2 Main file for Dmem shell Debug1 function.
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
11 #include "UefiShellDebug1CommandsLib.h"
12 #include <Protocol/PciRootBridgeIo.h>
13 #include <Guid/Acpi.h>
15 #include <Guid/SmBios.h>
18 Make a printable character.
20 If Char is printable then return it, otherwise return a question mark.
22 @param[in] Char The character to make printable.
24 @return A printable character representing Char.
31 if (((Char
< 0x20) && (Char
> 0)) || (Char
> 126)) {
39 Display some Memory-Mapped-IO memory.
41 @param[in] Address The starting address to display.
42 @param[in] Size The length of memory to display.
46 IN CONST VOID
*Address
,
50 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRbIo
;
53 SHELL_STATUS ShellStatus
;
55 ShellStatus
= SHELL_SUCCESS
;
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
);
63 Buffer
= AllocateZeroPool (Size
);
65 return SHELL_OUT_OF_RESOURCES
;
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
;
73 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW
), gShellDebug1HiiHandle
, (UINT64
)(UINTN
)Address
, Size
);
74 DumpHex (2, (UINTN
)Address
, Size
, Buffer
);
81 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
82 { L
"-mmio", TypeFlag
},
87 Function for 'dmem' command.
89 @param[in] ImageHandle Handle to the Image (NULL if Internal).
90 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
95 IN EFI_HANDLE ImageHandle
,
96 IN EFI_SYSTEM_TABLE
*SystemTable
101 CHAR16
*ProblemParam
;
102 SHELL_STATUS ShellStatus
;
106 UINT64 AcpiTableAddress
;
107 UINT64 Acpi20TableAddress
;
108 UINT64 SalTableAddress
;
109 UINT64 SmbiosTableAddress
;
110 UINT64 MpsTableAddress
;
113 ShellStatus
= SHELL_SUCCESS
;
114 Status
= EFI_SUCCESS
;
119 // initialize the shell lib (we must be in non-auto-init...)
121 Status
= ShellInitialize ();
122 ASSERT_EFI_ERROR (Status
);
124 Status
= CommandInit ();
125 ASSERT_EFI_ERROR (Status
);
128 // parse the command line
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
;
140 if (ShellCommandLineGetCount (Package
) > 3) {
141 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"dmem");
142 ShellStatus
= SHELL_INVALID_PARAMETER
;
144 Temp1
= ShellCommandLineGetRawValue (Package
, 1);
147 Size
= sizeof (*gST
);
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
;
154 Temp1
= ShellCommandLineGetRawValue (Package
, 2);
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
;
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;
174 SmbiosTableAddress
= 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
;
182 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiAcpi10TableGuid
)) {
183 AcpiTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
187 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbiosTableGuid
)) {
188 SmbiosTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
192 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiSmbios3TableGuid
)) {
193 SmbiosTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
197 if (CompareGuid (&gST
->ConfigurationTable
[TableWalker
].VendorGuid
, &gEfiMpsTableGuid
)) {
198 MpsTableAddress
= (UINT64
)(UINTN
)gST
->ConfigurationTable
[TableWalker
].VendorTable
;
207 STRING_TOKEN (STR_DMEM_SYSTEM_TABLE
),
208 gShellDebug1HiiHandle
,
209 (UINT64
)(UINTN
)Address
,
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
,
225 ShellStatus
= DisplayMmioMemory (Address
, (UINTN
)Size
);
229 ShellCommandLineFreeVarList (Package
);
232 return (ShellStatus
);