]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PciBusDxe: recognize hotplug-capable PCIe ports
authorLaszlo Ersek <lersek@redhat.com>
Thu, 30 Jun 2016 23:12:29 +0000 (01:12 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 13 Jul 2016 06:39:29 +0000 (08:39 +0200)
Section 7.8.2 of the PCI Express specification (r4.0 v0.3), entitled "PCI
Express Capabilities Register (Offset 02h)", and section 7.8.9 "Slot
Capabilities Register (Offset 14h)" of the same, describe the conditions
when a PCIe port should be considered "supporting hotplug":

- it should be a root complex port or a switch downstream port, and

- it should have the "Slot Implemented" bit set in the Express
  Capabilities Register, and

- it should have the "Hot-Plug Capable" bit set in the Slot Capabilities
  Register.

The first two sub-conditions are already implemented in at least two open
source projects I could find:

- in SeaBIOS by Marcel Apfelbaum: "hw/pci: reserve IO and mem for pci
  express downstream ports with no devices attached"
  <https://code.coreboot.org/p/seabios/source/commit/3aa31d7d6375>,

- in edk2 itself, in the implementation of the "PCI" UEFI Shell command:
  see the "PcieExplainTypeSlot" case label in function
  PciExplainPciExpress(), file
  "ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c".

PciBusDxe recognizes such PCIe ports as bridges, but it doesn't realize
they support hotplug. In turn PciBusDxe omits getting any resource padding
information from the platform's EFI_PCI_HOT_PLUG_INIT_PROTOCOL for these
bridges:

  GatherPpbInfo()                [PciEnumeratorSupport.c]
    GetResourcePaddingPpb()      [PciResourceSupport.c]
      GetResourcePaddingForHpb() [PciHotPlugSupport.c]
        IsPciHotPlugBus()        [PciHotPlugSupport.c]
          //
          // returns FALSE
          //
        //
        // the following is not reached:
        //
        gPciHotPlugInit->GetResourcePadding()

Implement a function called SupportsPcieHotplug() for identifying such
ports, and call it from IsPciHotPlugBus() (after the call to IsSHPC()).

Cc: "Johnson, Brian J." <bjohnson@sgi.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Marcel Apfelbaum <marcel@redhat.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ruiyu Ni <Ruiyu.ni@intel.com>
MdeModulePkg/Bus/Pci/PciBusDxe/PciHotPlugSupport.c
MdeModulePkg/Bus/Pci/PciBusDxe/PciHotPlugSupport.h

index ca8766869ae7aaf87878e9799a0c31f5e9653bb8..73bcd32788d1c2ffb5a7f540e2df7b0693df8602 100644 (file)
@@ -316,6 +316,94 @@ IsSHPC (
   return FALSE;\r
 }\r
 \r
+/**\r
+  Check whether PciIoDevice supports PCIe hotplug.\r
+\r
+  This is equivalent to the following condition:\r
+  - the device is either a PCIe switch downstream port or a root port,\r
+  - and the device has the SlotImplemented bit set in its PCIe capability\r
+    register,\r
+  - and the device has the HotPlugCapable bit set in its slot capabilities\r
+    register.\r
+\r
+  @param[in] PciIoDevice  The device being checked.\r
+\r
+  @retval TRUE   PciIoDevice is a PCIe port that accepts a hotplugged device.\r
+  @retval FALSE  Otherwise.\r
+\r
+**/\r
+BOOLEAN\r
+SupportsPcieHotplug (\r
+  IN PCI_IO_DEVICE                      *PciIoDevice\r
+  )\r
+{\r
+  UINT32                       Offset;\r
+  EFI_STATUS                   Status;\r
+  PCI_REG_PCIE_CAPABILITY      Capability;\r
+  PCI_REG_PCIE_SLOT_CAPABILITY SlotCapability;\r
+\r
+  if (PciIoDevice == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Read the PCI Express Capabilities Register\r
+  //\r
+  if (!PciIoDevice->IsPciExp) {\r
+    return FALSE;\r
+  }\r
+  Offset = PciIoDevice->PciExpressCapabilityOffset +\r
+           OFFSET_OF (PCI_CAPABILITY_PCIEXP, Capability);\r
+  Status = PciIoDevice->PciIo.Pci.Read (\r
+                                    &PciIoDevice->PciIo,\r
+                                    EfiPciIoWidthUint16,\r
+                                    Offset,\r
+                                    1,\r
+                                    &Capability\r
+                                    );\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check the contents of the register\r
+  //\r
+  switch (Capability.Bits.DevicePortType) {\r
+  case PCIE_DEVICE_PORT_TYPE_ROOT_PORT:\r
+  case PCIE_DEVICE_PORT_TYPE_DOWNSTREAM_PORT:\r
+    break;\r
+  default:\r
+    return FALSE;\r
+  }\r
+  if (!Capability.Bits.SlotImplemented) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Read the Slot Capabilities Register\r
+  //\r
+  Offset = PciIoDevice->PciExpressCapabilityOffset +\r
+           OFFSET_OF (PCI_CAPABILITY_PCIEXP, SlotCapability);\r
+  Status = PciIoDevice->PciIo.Pci.Read (\r
+                                    &PciIoDevice->PciIo,\r
+                                    EfiPciIoWidthUint32,\r
+                                    Offset,\r
+                                    1,\r
+                                    &SlotCapability\r
+                                    );\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check the contents of the register\r
+  //\r
+  if (SlotCapability.Bits.HotPlugCapable) {\r
+    return TRUE;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   Get resource padding if the specified PCI bridge is a hot plug bus.\r
 \r
@@ -382,6 +470,14 @@ IsPciHotPlugBus (
     return TRUE;\r
   }\r
 \r
+  if (SupportsPcieHotplug (PciIoDevice)) {\r
+    //\r
+    // If the PPB is a PCIe root complex port or a switch downstream port, and\r
+    // implements a hot-plug capable slot, then also return TRUE.\r
+    //\r
+    return TRUE;\r
+  }\r
+\r
   //\r
   // Otherwise, see if it is a Root HPC\r
   //\r
index 1fb9ba972091502b98160f4f3ace81fb253b3742..a285d94c93ca4827b8e519469e3e2f01a59958e2 100644 (file)
@@ -176,6 +176,27 @@ IsSHPC (
   IN PCI_IO_DEVICE                      *PciIoDevice\r
   );\r
 \r
+/**\r
+  Check whether PciIoDevice supports PCIe hotplug.\r
+\r
+  This is equivalent to the following condition:\r
+  - the device is either a PCIe switch downstream port or a root port,\r
+  - and the device has the SlotImplemented bit set in its PCIe capability\r
+    register,\r
+  - and the device has the HotPlugCapable bit set in its slot capabilities\r
+    register.\r
+\r
+  @param[in] PciIoDevice  The device being checked.\r
+\r
+  @retval TRUE   PciIoDevice is a PCIe port that accepts a hotplugged device.\r
+  @retval FALSE  Otherwise.\r
+\r
+**/\r
+BOOLEAN\r
+SupportsPcieHotplug (\r
+  IN PCI_IO_DEVICE                      *PciIoDevice\r
+  );\r
+\r
 /**\r
   Get resource padding if the specified PCI bridge is a hot plug bus.\r
 \r