]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
ShellPkg/pci: Fix VS2012 build failure
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Pci.c
index 9cc4f5cf2ed354a32889f41e5c8deade3e4c36a4..38559571c2309e33139cd7ae14a82ba9d8364854 100644 (file)
@@ -1905,16 +1905,12 @@ PciGetNextBusRange (
   @param[in] ConfigSpace     Data in PCI configuration space.\r
   @param[in] Address         Address used to access configuration space of this PCI device.\r
   @param[in] IoDev           Handle used to access configuration space of PCI device.\r
-  @param[in] EnhancedDump    The print format for the dump data.\r
-\r
-  @retval EFI_SUCCESS     The command completed successfully.\r
 **/\r
-EFI_STATUS\r
-PciExplainData (\r
+VOID\r
+PciExplainPci (\r
   IN PCI_CONFIG_SPACE                       *ConfigSpace,\r
   IN UINT64                                 Address,\r
-  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev,\r
-  IN CONST UINT16                           EnhancedDump\r
+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev\r
   );\r
 \r
 /**\r
@@ -2030,40 +2026,31 @@ PciExplainBridgeControl (
   );\r
 \r
 /**\r
-  Print each capability structure.\r
+  Locate capability register block per capability ID.\r
 \r
-  @param[in] IoDev            The pointer to the deivce.\r
-  @param[in] Address          The address to start at.\r
-  @param[in] CapPtr           The offset from the address.\r
-  @param[in] EnhancedDump     The print format for the dump data.\r
+  @param[in] ConfigSpace       Data in PCI configuration space.\r
+  @param[in] CapabilityId      The capability ID.\r
 \r
-  @retval EFI_SUCCESS         The operation was successful.\r
+  @return   The offset of the register block per capability ID.\r
 **/\r
-EFI_STATUS\r
-PciExplainCapabilityStruct (\r
-  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,\r
-  IN UINT64                                   Address,\r
-  IN  UINT8                                   CapPtr,\r
-  IN CONST UINT16                            EnhancedDump\r
+UINT8\r
+LocatePciCapability (\r
+  IN PCI_CONFIG_SPACE   *ConfigSpace,\r
+  IN UINT8              CapabilityId\r
   );\r
 \r
 /**\r
   Display Pcie device structure.\r
 \r
-  @param[in] IoDev            The pointer to the root pci protocol.\r
-  @param[in] Address          The Address to start at.\r
-  @param[in] CapabilityPtr    The offset from the address to start.\r
-  @param[in] EnhancedDump     The print format for the dump data.\r
-  \r
-  @retval EFI_SUCCESS           The command completed successfully.\r
-  @retval @retval EFI_SUCCESS   Pci express extend space IO is not suppoted.   \r
+  @param[in] PciExpressCap       PCI Express capability buffer.\r
+  @param[in] ExtendedConfigSpace PCI Express extended configuration space.\r
+  @param[in] ExtendedCapability  PCI Express extended capability ID to explain.\r
 **/\r
-EFI_STATUS\r
+VOID\r
 PciExplainPciExpress (\r
-  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,\r
-  IN  UINT64                                  Address,\r
-  IN  UINT8                                   CapabilityPtr,\r
-  IN CONST UINT16                            EnhancedDump\r
+  IN  PCI_CAPABILITY_PCIEXP                  *PciExpressCap,\r
+  IN  UINT8                                  *ExtendedConfigSpace,\r
+  IN CONST UINT16                            ExtendedCapability\r
   );\r
 \r
 /**\r
@@ -2370,7 +2357,7 @@ PCI_CONFIG_SPACE  *mConfigSpace = NULL;
 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
   {L"-s", TypeValue},\r
   {L"-i", TypeFlag},\r
-  {L"-_e", TypeValue},\r
+  {L"-ec", TypeValue},\r
   {NULL, TypeMax}\r
   };\r
 \r
@@ -2473,7 +2460,10 @@ ShellCommandRunPci (
   SHELL_STATUS                      ShellStatus;\r
   CONST CHAR16                      *Temp;\r
   UINT64                            RetVal;\r
-  UINT16                            EnhancedDump;\r
+  UINT16                            ExtendedCapability;\r
+  UINT8                             PcieCapabilityPtr;\r
+  UINT8                             *ExtendedConfigSpace;\r
+  UINTN                             ExtendedConfigSize;\r
 \r
   ShellStatus         = SHELL_SUCCESS;\r
   Status              = EFI_SUCCESS;\r
@@ -2516,6 +2506,11 @@ ShellCommandRunPci (
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       goto Done;\r
     }\r
+    if (ShellCommandLineGetFlag(Package, L"-ec") && ShellCommandLineGetValue(Package, L"-ec") == NULL) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle,  L"pci", L"-ec");  \r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+      goto Done;\r
+    }\r
     if (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetValue(Package, L"-s") == NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle,  L"pci", L"-s");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
@@ -2721,6 +2716,7 @@ ShellCommandRunPci (
     Bus                           = 0;\r
     Device                        = 0;\r
     Func                          = 0;\r
+    ExtendedCapability          = 0xFFFF;\r
     if (ShellCommandLineGetFlag(Package, L"-i")) {\r
       ExplainData = TRUE;\r
     }\r
@@ -2802,6 +2798,20 @@ ShellCommandRunPci (
       }\r
     }\r
 \r
+    Temp = ShellCommandLineGetValue (Package, L"-ec");\r
+    if (Temp != NULL) {\r
+      //\r
+      // Input converted to hexadecimal number.\r
+      //\r
+      if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) {\r
+        ExtendedCapability = (UINT16) RetVal;\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle, L"pci", Temp);  \r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+        goto Done;\r
+      }\r
+    }\r
+\r
     //\r
     // Find the protocol interface who's in charge of current segment, and its\r
     // bus range covers the current bus\r
@@ -2874,19 +2884,52 @@ ShellCommandRunPci (
       ConfigSpace.Data\r
      );\r
 \r
+    ExtendedConfigSpace = NULL;\r
+    ExtendedConfigSize  = 0;\r
+    PcieCapabilityPtr = LocatePciCapability (&ConfigSpace, EFI_PCI_CAPABILITY_ID_PCIEXP);\r
+    if (PcieCapabilityPtr != 0) {\r
+      ExtendedConfigSize  = 0x1000 - EFI_PCIE_CAPABILITY_BASE_OFFSET;\r
+      ExtendedConfigSpace = AllocatePool (ExtendedConfigSize);\r
+      if (ExtendedConfigSpace != NULL) {\r
+        Status = IoDev->Pci.Read (\r
+                              IoDev,\r
+                              EfiPciWidthUint32,\r
+                              EFI_PCI_ADDRESS (Bus, Device, Func, EFI_PCIE_CAPABILITY_BASE_OFFSET),\r
+                              ExtendedConfigSize / sizeof (UINT32),\r
+                              ExtendedConfigSpace\r
+                              );\r
+        if (EFI_ERROR (Status)) {\r
+          SHELL_FREE_NON_NULL (ExtendedConfigSpace);\r
+        }\r
+      }\r
+    }\r
+\r
+    if ((ExtendedConfigSpace != NULL) && !ShellGetExecutionBreakFlag ()) {\r
+      //\r
+      // Print the PciEx extend space in raw bytes ( 0xFF-0xFFF)\r
+      //\r
+      ShellPrintEx (-1, -1, L"\r\n%HStart dumping PCIex extended configuration space (0x100 - 0xFFF).%N\r\n\r\n");\r
+\r
+      DumpHex (\r
+        2,\r
+        EFI_PCIE_CAPABILITY_BASE_OFFSET,\r
+        ExtendedConfigSize,\r
+        ExtendedConfigSpace\r
+        );\r
+    }\r
+\r
     //\r
     // If "-i" appears in command line, interpret data in configuration space\r
     //\r
     if (ExplainData) {\r
-      EnhancedDump = 0;\r
-      if (ShellCommandLineGetFlag(Package, L"-_e")) {\r
-        EnhancedDump = 0xFFFF;\r
-        Temp = ShellCommandLineGetValue(Package, L"-_e");\r
-        if (Temp != NULL) {\r
-          EnhancedDump = (UINT16) ShellHexStrToUintn (Temp);\r
-        }\r
+      PciExplainPci (&ConfigSpace, Address, IoDev);\r
+      if ((ExtendedConfigSpace != NULL) && !ShellGetExecutionBreakFlag ()) {\r
+        PciExplainPciExpress (\r
+          (PCI_CAPABILITY_PCIEXP *) ((UINT8 *) &ConfigSpace + PcieCapabilityPtr),\r
+          ExtendedConfigSpace,\r
+          ExtendedCapability\r
+          );\r
       }\r
-      Status = PciExplainData (&ConfigSpace, Address, IoDev, EnhancedDump);\r
     }\r
   }\r
 Done:\r
@@ -3080,22 +3123,16 @@ PciGetNextBusRange (
   @param[in] ConfigSpace     Data in PCI configuration space.\r
   @param[in] Address         Address used to access configuration space of this PCI device.\r
   @param[in] IoDev           Handle used to access configuration space of PCI device.\r
-  @param[in] EnhancedDump    The print format for the dump data.\r
-\r
-  @retval EFI_SUCCESS     The command completed successfully.\r
 **/\r
-EFI_STATUS\r
-PciExplainData (\r
+VOID\r
+PciExplainPci (\r
   IN PCI_CONFIG_SPACE                       *ConfigSpace,\r
   IN UINT64                                 Address,\r
-  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev,\r
-  IN CONST UINT16                           EnhancedDump\r
+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev\r
   )\r
 {\r
   PCI_DEVICE_INDEPENDENT_REGION *Common;\r
   PCI_HEADER_TYPE               HeaderType;\r
-  EFI_STATUS                    Status;\r
-  UINT8                         CapPtr;\r
 \r
   Common = &(ConfigSpace->Common);\r
 \r
@@ -3201,56 +3238,6 @@ PciExplainData (
   ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_CLASS), gShellDebug1HiiHandle);\r
   PciPrintClassCode ((UINT8 *) Common->ClassCode, TRUE);\r
   ShellPrintEx (-1, -1, L"\r\n");\r
-\r
-  if (ShellGetExecutionBreakFlag()) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  //\r
-  // Interpret remaining part of PCI configuration header depending on\r
-  // HeaderType\r
-  //\r
-  CapPtr  = 0;\r
-  Status  = EFI_SUCCESS;\r
-  switch (HeaderType) {\r
-  case PciDevice:\r
-    Status = PciExplainDeviceData (\r
-              &(ConfigSpace->NonCommon.Device),\r
-              Address,\r
-              IoDev\r
-             );\r
-    CapPtr = ConfigSpace->NonCommon.Device.CapabilityPtr;\r
-    break;\r
-\r
-  case PciP2pBridge:\r
-    Status = PciExplainBridgeData (\r
-              &(ConfigSpace->NonCommon.Bridge),\r
-              Address,\r
-              IoDev\r
-             );\r
-    CapPtr = ConfigSpace->NonCommon.Bridge.CapabilityPtr;\r
-    break;\r
-\r
-  case PciCardBusBridge:\r
-    Status = PciExplainCardBusData (\r
-              &(ConfigSpace->NonCommon.CardBus),\r
-              Address,\r
-              IoDev\r
-             );\r
-    CapPtr = ConfigSpace->NonCommon.CardBus.Cap_Ptr;\r
-    break;\r
-  case PciUndefined:\r
-  default:\r
-    break;\r
-  }\r
-  //\r
-  // If Status bit4 is 1, dump or explain capability structure\r
-  //\r
-  if ((Common->Status) & EFI_PCI_STATUS_CAPABILITY) {\r
-    PciExplainCapabilityStruct (IoDev, Address, CapPtr, EnhancedDump);\r
-  }\r
-\r
-  return Status;\r
 }\r
 \r
 /**\r
@@ -4209,53 +4196,62 @@ PciExplainBridgeControl (
 }\r
 \r
 /**\r
-  Print each capability structure.\r
+  Locate capability register block per capability ID.\r
 \r
-  @param[in] IoDev            The pointer to the deivce.\r
-  @param[in] Address          The address to start at.\r
-  @param[in] CapPtr           The offset from the address.\r
-  @param[in] EnhancedDump     The print format for the dump data.\r
+  @param[in] ConfigSpace       Data in PCI configuration space.\r
+  @param[in] CapabilityId      The capability ID.\r
 \r
-  @retval EFI_SUCCESS     The operation was successful.\r
+  @return   The offset of the register block per capability ID,\r
+            or 0 if the register block cannot be found.\r
 **/\r
-EFI_STATUS\r
-PciExplainCapabilityStruct (\r
-  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,\r
-  IN UINT64                                   Address,\r
-  IN  UINT8                                   CapPtr,\r
-  IN CONST UINT16                            EnhancedDump\r
+UINT8\r
+LocatePciCapability (\r
+  IN PCI_CONFIG_SPACE   *ConfigSpace,\r
+  IN UINT8              CapabilityId\r
   )\r
 {\r
-  UINT8   CapabilityPtr;\r
-  UINT16  CapabilityEntry;\r
-  UINT8   CapabilityID;\r
-  UINT64  RegAddress;\r
-\r
-  CapabilityPtr = CapPtr;\r
+  UINT8                   CapabilityPtr;\r
+  EFI_PCI_CAPABILITY_HDR  *CapabilityEntry;\r
 \r
   //\r
-  // Go through the Capability list\r
+  // To check the cpability of this device supports\r
   //\r
-  while ((CapabilityPtr >= 0x40) && ((CapabilityPtr & 0x03) == 0x00)) {\r
-    RegAddress = Address + CapabilityPtr;\r
-    IoDev->Pci.Read (IoDev, EfiPciWidthUint16, RegAddress, 1, &CapabilityEntry);\r
+  if ((ConfigSpace->Common.Status & EFI_PCI_STATUS_CAPABILITY) == 0) {\r
+    return 0;\r
+  }\r
+\r
+  switch ((PCI_HEADER_TYPE)(ConfigSpace->Common.HeaderType & 0x7f)) {\r
+    case PciDevice:\r
+      CapabilityPtr = ConfigSpace->NonCommon.Device.CapabilityPtr;\r
+      break;\r
+    case PciP2pBridge:\r
+      CapabilityPtr = ConfigSpace->NonCommon.Bridge.CapabilityPtr;\r
+      break;\r
+    case PciCardBusBridge:\r
+      CapabilityPtr = ConfigSpace->NonCommon.CardBus.Cap_Ptr;\r
+      break;\r
+    default:\r
+      return 0;\r
+  }\r
 \r
-    CapabilityID = (UINT8) CapabilityEntry;\r
+  while ((CapabilityPtr >= 0x40) && ((CapabilityPtr & 0x03) == 0x00)) {\r
+    CapabilityEntry = (EFI_PCI_CAPABILITY_HDR *) ((UINT8 *) ConfigSpace + CapabilityPtr);\r
+    if (CapabilityEntry->CapabilityID == CapabilityId) {\r
+      return CapabilityPtr;\r
+    }\r
 \r
     //\r
-    // Explain PciExpress data\r
+    // Certain PCI device may incorrectly have capability pointing to itself,\r
+    // break to avoid dead loop.\r
     //\r
-    if (EFI_PCI_CAPABILITY_ID_PCIEXP == CapabilityID) {\r
-      PciExplainPciExpress (IoDev, Address, CapabilityPtr, EnhancedDump);\r
-      return EFI_SUCCESS;\r
+    if (CapabilityPtr == CapabilityEntry->NextItemPtr) {\r
+      break;\r
     }\r
-    //\r
-    // Explain other capabilities here\r
-    //\r
-    CapabilityPtr = (UINT8) (CapabilityEntry >> 8);\r
+\r
+    CapabilityPtr = CapabilityEntry->NextItemPtr;\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return 0;\r
 }\r
 \r
 /**\r
@@ -5502,7 +5498,8 @@ PrintInterpretedExtendedCompatibilityVirtualChannel (
   DumpHex (\r
     4,\r
     EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),\r
-    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_VC) + (Header->ExtendedVcCount - 1) * sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_CAPABILITY),\r
+    sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_CAPABILITY)\r
+    + Header->ExtendedVcCount * sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_VC),\r
     (VOID *) (HeaderAddress)\r
     );\r
 \r
@@ -5693,53 +5690,32 @@ PrintPciExtendedCapabilityDetails(
 /**\r
   Display Pcie device structure.\r
 \r
-  @param[in] IoDev          The pointer to the root pci protocol.\r
-  @param[in] Address        The Address to start at.\r
-  @param[in] CapabilityPtr  The offset from the address to start.\r
-  @param[in] EnhancedDump   The print format for the dump data.\r
-  \r
+  @param[in] PciExpressCap       PCI Express capability buffer.\r
+  @param[in] ExtendedConfigSpace PCI Express extended configuration space.\r
+  @param[in] ExtendedCapability  PCI Express extended capability ID to explain.\r
 **/\r
-EFI_STATUS\r
+VOID\r
 PciExplainPciExpress (\r
-  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,\r
-  IN  UINT64                                  Address,\r
-  IN  UINT8                                   CapabilityPtr,\r
-  IN CONST UINT16                            EnhancedDump\r
+  IN  PCI_CAPABILITY_PCIEXP                  *PciExpressCap,\r
+  IN  UINT8                                  *ExtendedConfigSpace,\r
+  IN CONST UINT16                            ExtendedCapability\r
   )\r
 {\r
-  PCI_CAPABILITY_PCIEXP PciExpressCap;\r
-  EFI_STATUS            Status;\r
-  UINT64                CapRegAddress;\r
-  UINT8                 Bus;\r
-  UINT8                 Dev;\r
-  UINT8                 Func;\r
-  UINT8                 *ExRegBuffer;\r
-  UINTN                 ExtendRegSize;\r
-  UINT64                Pciex_Address;\r
   UINT8                 DevicePortType;\r
   UINTN                 Index;\r
   UINT8                 *RegAddr;\r
   UINTN                 RegValue;\r
   PCI_EXP_EXT_HDR       *ExtHdr;\r
 \r
-  CapRegAddress = Address + CapabilityPtr;\r
-  IoDev->Pci.Read (\r
-              IoDev,\r
-              EfiPciWidthUint32,\r
-              CapRegAddress,\r
-              sizeof (PciExpressCap) / sizeof (UINT32),\r
-              &PciExpressCap\r
-             );\r
-\r
-  DevicePortType = (UINT8)PciExpressCap.Capability.Bits.DevicePortType;\r
+  DevicePortType = (UINT8)PciExpressCap->Capability.Bits.DevicePortType;\r
 \r
   ShellPrintEx (-1, -1, L"\r\nPci Express device capability structure:\r\n");\r
 \r
   for (Index = 0; PcieExplainList[Index].Type < PcieExplainTypeMax; Index++) {\r
     if (ShellGetExecutionBreakFlag()) {\r
-      goto Done;\r
+      return;\r
     }\r
-    RegAddr = ((UINT8 *) &PciExpressCap) + PcieExplainList[Index].Offset;\r
+    RegAddr = (UINT8 *) PciExpressCap + PcieExplainList[Index].Offset;\r
     switch (PcieExplainList[Index].Width) {\r
       case FieldWidthUINT8:\r
         RegValue = *(UINT8 *) RegAddr;\r
@@ -5784,7 +5760,7 @@ PciExplainPciExpress (
         //\r
         if ((DevicePortType != PCIE_DEVICE_PORT_TYPE_ROOT_PORT &&\r
              DevicePortType != PCIE_DEVICE_PORT_TYPE_DOWNSTREAM_PORT) ||\r
-             !PciExpressCap.Capability.Bits.SlotImplemented) {\r
+             !PciExpressCap->Capability.Bits.SlotImplemented) {\r
           continue;\r
         }\r
         break;\r
@@ -5800,72 +5776,28 @@ PciExplainPciExpress (
       default:\r
         break;\r
     }\r
-    PcieExplainList[Index].Func (&PciExpressCap);\r
-  }\r
-\r
-  Bus           = (UINT8) (RShiftU64 (Address, 24));\r
-  Dev           = (UINT8) (RShiftU64 (Address, 16));\r
-  Func          = (UINT8) (RShiftU64 (Address, 8));\r
-\r
-  Pciex_Address = EFI_PCI_ADDRESS (Bus, Dev, Func, EFI_PCIE_CAPABILITY_BASE_OFFSET);\r
-\r
-  ExtendRegSize = 0x1000 - EFI_PCIE_CAPABILITY_BASE_OFFSET;\r
-\r
-  ExRegBuffer   = (UINT8 *) AllocateZeroPool (ExtendRegSize);\r
-\r
-  //\r
-  // PciRootBridgeIo protocol should support pci express extend space IO\r
-  // (Begins at offset EFI_PCIE_CAPABILITY_BASE_OFFSET)\r
-  //\r
-  Status = IoDev->Pci.Read (\r
-                        IoDev,\r
-                        EfiPciWidthUint32,\r
-                        Pciex_Address,\r
-                        (ExtendRegSize) / sizeof (UINT32),\r
-                        (VOID *) (ExRegBuffer)\r
-                       );\r
-  if (EFI_ERROR (Status) || ExRegBuffer == NULL) {\r
-    SHELL_FREE_NON_NULL(ExRegBuffer);\r
-    return EFI_UNSUPPORTED;\r
+    PcieExplainList[Index].Func (PciExpressCap);\r
   }\r
 \r
-  if (EnhancedDump == 0) {\r
+  ExtHdr = (PCI_EXP_EXT_HDR*)ExtendedConfigSpace;\r
+  while (ExtHdr->CapabilityId != 0 && ExtHdr->CapabilityVersion != 0) {\r
     //\r
-    // Print the PciEx extend space in raw bytes ( 0xFF-0xFFF)\r
+    // Process this item\r
     //\r
-    ShellPrintEx (-1, -1, L"\r\n%HStart dumping PCIex extended configuration space (0x100 - 0xFFF).%N\r\n\r\n");\r
-\r
-    DumpHex (\r
-      2,\r
-      EFI_PCIE_CAPABILITY_BASE_OFFSET,\r
-      ExtendRegSize,\r
-      (VOID *) (ExRegBuffer)\r
-      );\r
-  } else {\r
-    ExtHdr = (PCI_EXP_EXT_HDR*)ExRegBuffer;\r
-    while (ExtHdr->CapabilityId != 0 && ExtHdr->CapabilityVersion != 0) {\r
+    if (ExtendedCapability == 0xFFFF || ExtendedCapability == ExtHdr->CapabilityId) {\r
       //\r
-      // Process this item\r
+      // Print this item\r
       //\r
-      if (EnhancedDump == 0xFFFF || EnhancedDump == ExtHdr->CapabilityId) {\r
-        //\r
-        // Print this item\r
-        //\r
-        PrintPciExtendedCapabilityDetails((PCI_EXP_EXT_HDR*)ExRegBuffer, ExtHdr, &PciExpressCap);\r
-      }\r
+      PrintPciExtendedCapabilityDetails((PCI_EXP_EXT_HDR*)ExtendedConfigSpace, ExtHdr, PciExpressCap);\r
+    }\r
 \r
-      //\r
-      // Advance to the next item if it exists\r
-      //\r
-      if (ExtHdr->NextCapabilityOffset != 0) {\r
-        ExtHdr = (PCI_EXP_EXT_HDR*)((UINT8*)ExRegBuffer + ExtHdr->NextCapabilityOffset - EFI_PCIE_CAPABILITY_BASE_OFFSET);\r
-      } else {\r
-        break;\r
-      }\r
+    //\r
+    // Advance to the next item if it exists\r
+    //\r
+    if (ExtHdr->NextCapabilityOffset != 0) {\r
+      ExtHdr = (PCI_EXP_EXT_HDR*)(ExtendedConfigSpace + ExtHdr->NextCapabilityOffset - EFI_PCIE_CAPABILITY_BASE_OFFSET);\r
+    } else {\r
+      break;\r
     }\r
   }\r
-  SHELL_FREE_NON_NULL(ExRegBuffer);\r
-\r
-Done:\r
-  return EFI_SUCCESS;\r
 }\r