diff mbox series

[1/1] pcie: Allow generic PCIE root port to enable atomic completion

Message ID 20230420153839.167418-2-robin@streamhpc.com
State New
Headers show
Series pcie: Allow atomic completion on PCIE root port | expand

Commit Message

Robin Voetter April 20, 2023, 3:38 p.m. UTC
From: Robin Voetter <robin@streamhpc.com>

Adds an experimental option to the pcie-root-port to make it report
support for the PCIe atomic completion capabilities.  This can now be
enabled by setting the x-atomic-completion option on the pcie-root-port
device.  Defaults to disabled for now.  For example:

    -device pcie-root-port,x-atomic-completion=true,id=pcie.1

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Robin Voetter <robin@streamhpc.com>
---
 hw/pci-bridge/gen_pcie_root_port.c | 2 ++
 hw/pci/pcie.c                      | 6 ++++++
 include/hw/pci/pcie_port.h         | 3 +++
 3 files changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/hw/pci-bridge/gen_pcie_root_port.c b/hw/pci-bridge/gen_pcie_root_port.c
index 1ce4e7beba..097eaecbed 100644
--- a/hw/pci-bridge/gen_pcie_root_port.c
+++ b/hw/pci-bridge/gen_pcie_root_port.c
@@ -145,6 +145,8 @@  static Property gen_rp_props[] = {
                                 speed, PCIE_LINK_SPEED_16),
     DEFINE_PROP_PCIE_LINK_WIDTH("x-width", PCIESlot,
                                 width, PCIE_LINK_WIDTH_32),
+    DEFINE_PROP_BOOL("x-atomic-completion", PCIESlot,
+                     atomic_completion, false),
     DEFINE_PROP_END_OF_LIST()
 };
 
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index b8c24cf45f..5dd61e3cdb 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -663,6 +663,12 @@  void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s)
 
     qbus_set_hotplug_handler(BUS(pci_bridge_get_sec_bus(PCI_BRIDGE(dev))),
                              OBJECT(dev));
+
+    if (s->atomic_completion) {
+        /* PCIe requires setting both comp32 and comp64 if either is supported */
+        pci_set_long(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCAP2,
+                     PCI_EXP_DEVCAP2_ATOMIC_COMP32 | PCI_EXP_DEVCAP2_ATOMIC_COMP64);
+    }
 }
 
 void pcie_cap_slot_reset(PCIDevice *dev)
diff --git a/include/hw/pci/pcie_port.h b/include/hw/pci/pcie_port.h
index 90e6cf45b8..5e85657bb0 100644
--- a/include/hw/pci/pcie_port.h
+++ b/include/hw/pci/pcie_port.h
@@ -68,6 +68,9 @@  struct PCIESlot {
     /* broken ACPI hotplug compat knob to preserve 6.1 ABI intact */
     bool        hide_native_hotplug_cap;
 
+    /* Enables PCIE Atomic completion on pcie_root_port */
+    bool atomic_completion;
+
     QLIST_ENTRY(PCIESlot) next;
 };