[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v4 34/47] acpi: pcihp: pcie: set power on cap on parent slot
From: |
Michael S. Tsirkin |
Subject: |
[PULL v4 34/47] acpi: pcihp: pcie: set power on cap on parent slot |
Date: |
Mon, 7 Mar 2022 17:46:18 -0500 |
From: Igor Mammedov <imammedo@redhat.com>
on creation a PCIDevice has power turned on at the end of pci_qdev_realize()
however later on if PCIe slot isn't populated with any children
it's power is turned off. It's fine if native hotplug is used
as plug callback will power slot on among other things.
However when ACPI hotplug is enabled it replaces native PCIe plug
callbacks with ACPI specific ones (acpi_pcihp_device_*plug_cb) and
as result slot stays powered off. It works fine as ACPI hotplug
on guest side takes care of enumerating/initializing hotplugged
device. But when later guest is migrated, call chain introduced by]
commit d5daff7d312 (pcie: implement slot power control for pcie root ports)
pcie_cap_slot_post_load()
-> pcie_cap_update_power()
-> pcie_set_power_device()
-> pci_set_power()
-> pci_update_mappings()
will disable earlier initialized BARs for the hotplugged device
in powered off slot due to commit 23786d13441 (pci: implement power state)
which disables BARs if power is off.
Fix it by setting PCI_EXP_SLTCTL_PCC to PCI_EXP_SLTCTL_PWR_ON
on slot (root port/downstream port) at the time a device
hotplugged into it. As result PCI_EXP_SLTCTL_PWR_ON is migrated
to target and above call chain keeps device plugged into it
powered on.
Fixes: d5daff7d312 ("pcie: implement slot power control for pcie root ports")
Fixes: 23786d13441 ("pci: implement power state")
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2053584
Suggested-by: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Message-Id: <20220301151200.3507298-3-imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/pci/pcie.h | 1 +
hw/acpi/pcihp.c | 12 +++++++++++-
hw/pci/pcie.c | 11 +++++++++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index 168950a83b..798a262a0a 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -118,6 +118,7 @@ void pcie_cap_slot_write_config(PCIDevice *dev,
uint32_t addr, uint32_t val, int len);
int pcie_cap_slot_post_load(void *opaque, int version_id);
void pcie_cap_slot_push_attention_button(PCIDevice *dev);
+void pcie_cap_slot_enable_power(PCIDevice *dev);
void pcie_cap_root_init(PCIDevice *dev);
void pcie_cap_root_reset(PCIDevice *dev);
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 6befd23e16..6351bd3424 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -32,6 +32,7 @@
#include "hw/pci/pci_bridge.h"
#include "hw/pci/pci_host.h"
#include "hw/pci/pcie_port.h"
+#include "hw/pci-bridge/xio3130_downstream.h"
#include "hw/i386/acpi-build.h"
#include "hw/acpi/acpi.h"
#include "hw/pci/pci_bus.h"
@@ -336,6 +337,8 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev,
AcpiPciHpState *s,
{
PCIDevice *pdev = PCI_DEVICE(dev);
int slot = PCI_SLOT(pdev->devfn);
+ PCIDevice *bridge;
+ PCIBus *bus;
int bsel;
/* Don't send event when device is enabled during qemu machine creation:
@@ -365,7 +368,14 @@ void acpi_pcihp_device_plug_cb(HotplugHandler
*hotplug_dev, AcpiPciHpState *s,
return;
}
- bsel = acpi_pcihp_get_bsel(pci_get_bus(pdev));
+ bus = pci_get_bus(pdev);
+ bridge = pci_bridge_get_device(bus);
+ if (object_dynamic_cast(OBJECT(bridge), TYPE_PCIE_ROOT_PORT) ||
+ object_dynamic_cast(OBJECT(bridge), TYPE_XIO3130_DOWNSTREAM)) {
+ pcie_cap_slot_enable_power(bridge);
+ }
+
+ bsel = acpi_pcihp_get_bsel(bus);
g_assert(bsel >= 0);
s->acpi_pcihp_pci_status[bsel].up |= (1U << slot);
acpi_send_event(DEVICE(hotplug_dev), ACPI_PCI_HOTPLUG_STATUS);
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 3c44204cf3..67a5d67372 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -366,6 +366,17 @@ static void hotplug_event_clear(PCIDevice *dev)
}
}
+void pcie_cap_slot_enable_power(PCIDevice *dev)
+{
+ uint8_t *exp_cap = dev->config + dev->exp.exp_cap;
+ uint32_t sltcap = pci_get_long(exp_cap + PCI_EXP_SLTCAP);
+
+ if (sltcap & PCI_EXP_SLTCAP_PCP) {
+ pci_set_word_by_mask(exp_cap + PCI_EXP_SLTCTL,
+ PCI_EXP_SLTCTL_PCC, PCI_EXP_SLTCTL_PWR_ON);
+ }
+}
+
static void pcie_set_power_device(PCIBus *bus, PCIDevice *dev, void *opaque)
{
bool *power = opaque;
--
MST
- [PULL v4 23/47] virtio-net: Unlimit tx queue size if peer is vdpa, (continued)
- [PULL v4 23/47] virtio-net: Unlimit tx queue size if peer is vdpa, Michael S. Tsirkin, 2022/03/07
- [PULL v4 24/47] pcie: Add support for Single Root I/O Virtualization (SR/IOV), Michael S. Tsirkin, 2022/03/07
- [PULL v4 26/47] pcie: Add a helper to the SR/IOV API, Michael S. Tsirkin, 2022/03/07
- [PULL v4 27/47] pcie: Add 1.2 version token for the Power Management Capability, Michael S. Tsirkin, 2022/03/07
- [PULL v4 28/47] pci-bridge/xio3130_upstream: Fix error handling, Michael S. Tsirkin, 2022/03/07
- [PULL v4 29/47] pci-bridge/xio3130_downstream: Fix error handling, Michael S. Tsirkin, 2022/03/07
- [PULL v4 30/47] headers: Add pvpanic.h, Michael S. Tsirkin, 2022/03/07
- [PULL v4 31/47] hw/misc/pvpanic: Use standard headers instead, Michael S. Tsirkin, 2022/03/07
- [PULL v4 33/47] pci: expose TYPE_XIO3130_DOWNSTREAM name, Michael S. Tsirkin, 2022/03/07
- [PULL v4 35/47] pc: add option to disable PS/2 mouse/keyboard, Michael S. Tsirkin, 2022/03/07
- [PULL v4 34/47] acpi: pcihp: pcie: set power on cap on parent slot,
Michael S. Tsirkin <=
- [PULL v4 32/47] pci: show id info when pci BDF conflict, Michael S. Tsirkin, 2022/03/07
- [PULL v4 36/47] vhost-vsock: detach the virqueue element in case of error, Michael S. Tsirkin, 2022/03/07
- [PULL v4 37/47] x86: cleanup unused compat_apic_id_mode, Michael S. Tsirkin, 2022/03/07
- [PULL v4 38/47] hw/smbios: Add table 4 parameter, "processor-id", Michael S. Tsirkin, 2022/03/07
- [PULL v4 39/47] pci: drop COMPAT_PROP_PCP for 2.0 machine types, Michael S. Tsirkin, 2022/03/07
- [PULL v4 40/47] event_notifier: add event_notifier_get_wfd(), Michael S. Tsirkin, 2022/03/07
- [PULL v4 41/47] vhost: use wfd on functions setting vring call fd, Michael S. Tsirkin, 2022/03/07
- [PULL v4 42/47] configure, meson: allow enabling vhost-user on all POSIX systems, Michael S. Tsirkin, 2022/03/07
- [PULL v4 43/47] docs: vhost-user: add subsection for non-Linux platforms, Michael S. Tsirkin, 2022/03/07
- [PULL v4 44/47] tests/acpi: i386: allow FACP acpi table changes, Michael S. Tsirkin, 2022/03/07