]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
ShellPkg/[hex]edit: use SimpleTextInEx to read console
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Mm.c
index 3f08cc84dc244f4c70a974eae94b8b56a0e1f9e9..9f97f1d345f7e6df2609e434599970c86e132115 100644 (file)
@@ -2,7 +2,7 @@
   Main file for Mm shell Debug1 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -58,10 +58,10 @@ CONST EFI_CPU_IO_PROTOCOL_WIDTH mShellMmCpuIoWidth[] = {
 \r
 /**\r
   Extract the PCI segment, bus, device, function, register from\r
-  from a SHELL_MM_PCI or SHELL_MM_PCIE format of address..\r
+  from a PCI or PCIE format of address..\r
 \r
   @param[in]  PciFormat      Whether the address is of PCI format of PCIE format.\r
-  @param[in]  Address        SHELL_MM_PCI or SHELL_MM_PCIE address.\r
+  @param[in]  Address        PCI or PCIE address.\r
   @param[out] Segment        PCI segment number.\r
   @param[out] Bus            PCI bus number.\r
   @param[out] Device         PCI device number.\r
@@ -69,7 +69,6 @@ CONST EFI_CPU_IO_PROTOCOL_WIDTH mShellMmCpuIoWidth[] = {
   @param[out] Register       PCI register offset.\r
 **/\r
 VOID\r
-EFIAPI\r
 ShellMmDecodePciAddress (\r
   IN BOOLEAN                PciFormat,\r
   IN UINT64                 Address,\r
@@ -82,10 +81,10 @@ ShellMmDecodePciAddress (
 {\r
   if (PciFormat) {\r
     //\r
-    // PCI Configuration Space.The address will have the format 0x000000ssbbddffrr,\r
-    // where ss = Segment, bb = Bus, dd = Device, ff = Function and rr = Register.\r
+    // PCI Configuration Space.The address will have the format ssssbbddffrr,\r
+    // where ssss = Segment, bb = Bus, dd = Device, ff = Function and rr = Register.\r
     //\r
-    *Segment = (UINT32) (RShiftU64 (Address, 32) & 0xFF);\r
+    *Segment = (UINT32) (RShiftU64 (Address, 32) & 0xFFFF);\r
     *Bus = (UINT8) (((UINT32) Address) >> 24);\r
 \r
     if (Device != NULL) {\r
@@ -99,10 +98,10 @@ ShellMmDecodePciAddress (
     }\r
   } else {\r
     //\r
-    // PCI Express Configuration Space.The address will have the format 0x0000000ssbbddffrrr,\r
-    // where ss = Segment, bb = Bus, dd = Device, ff = Function and rrr = Register.\r
+    // PCI Express Configuration Space.The address will have the format ssssssbbddffrrr,\r
+    // where ssss = Segment, bb = Bus, dd = Device, ff = Function and rrr = Register.\r
     //\r
-    *Segment = (UINT32) (RShiftU64 (Address, 36) & 0xFF);\r
+    *Segment = (UINT32) (RShiftU64 (Address, 36) & 0xFFFF);\r
     *Bus = (UINT8) RShiftU64 (Address, 28);\r
     if (Device != NULL) {\r
       *Device = (UINT8) (((UINT32) Address) >> 20);\r
@@ -317,6 +316,7 @@ ShellMmLocateIoProtocol (
   }\r
 \r
   *PciRootBridgeIo = NULL;\r
+  HandleBuffer     = NULL;\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
                   &gEfiPciRootBridgeIoProtocolGuid,\r
@@ -324,10 +324,12 @@ ShellMmLocateIoProtocol (
                   &HandleCount,\r
                   &HandleBuffer\r
                   );\r
-  if (EFI_ERROR (Status) || (HandleCount == 0)) {\r
+  if (EFI_ERROR (Status) || (HandleCount == 0) || (HandleBuffer == NULL)) {\r
     return FALSE;\r
   }\r
 \r
+  Segment = 0;\r
+  Bus     = 0;\r
   if ((AccessType == ShellMmPci) || (AccessType == ShellMmPciExpress)) {\r
     ShellMmDecodePciAddress ((BOOLEAN) (AccessType == ShellMmPci), Address, &Segment, &Bus, NULL, NULL, NULL);\r
   }\r
@@ -614,18 +616,18 @@ ShellCommandRunMm (
         // skip space characters\r
         //\r
         for (Index = 0; InputStr[Index] == ' '; Index++);\r
-      }\r
 \r
-      if ((InputStr != NULL) && (InputStr[Index] != CHAR_NULL)) {\r
-        if ((InputStr[Index] == '.') || (InputStr[Index] == 'q') || (InputStr[Index] == 'Q')) {\r
-          Complete = TRUE;\r
-        } else if (!EFI_ERROR (ShellConvertStringToUint64 (InputStr + Index, &Buffer, TRUE, TRUE)) &&\r
-                   (Buffer <= mShellMmMaxNumber[Size])\r
-                   ) {\r
-          ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, FALSE, Address, Size, &Buffer);\r
-        } else {\r
-          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle, L"mm");\r
-          continue;\r
+        if (InputStr[Index] != CHAR_NULL) {\r
+          if ((InputStr[Index] == '.') || (InputStr[Index] == 'q') || (InputStr[Index] == 'Q')) {\r
+            Complete = TRUE;\r
+          } else if (!EFI_ERROR (ShellConvertStringToUint64 (InputStr + Index, &Buffer, TRUE, TRUE)) &&\r
+                     (Buffer <= mShellMmMaxNumber[Size])\r
+                     ) {\r
+            ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, FALSE, Address, Size, &Buffer);\r
+          } else {\r
+            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle, L"mm");\r
+            continue;\r
+          }\r
         }\r
       }\r
 \r