summary refs log tree commit diff stats
path: root/include/hw/pci/pci_device.h
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki@daynix.com>2024-06-27 15:07:55 +0900
committerMichael S. Tsirkin <mst@redhat.com>2024-07-03 18:14:07 -0400
commit139610ae67f6ecf92127bb7bf53ac6265b459ec8 (patch)
tree776fd6f68a3bd5c92bb244b025ccb9d50078228f /include/hw/pci/pci_device.h
parent77718701157f6ca77ea7a57b536fa0a22f676082 (diff)
downloadfocaccia-qemu-139610ae67f6ecf92127bb7bf53ac6265b459ec8.tar.gz
focaccia-qemu-139610ae67f6ecf92127bb7bf53ac6265b459ec8.zip
pcie_sriov: Reuse SR-IOV VF device instances
Disable SR-IOV VF devices by reusing code to power down PCI devices
instead of removing them when the guest requests to disable VFs. This
allows to realize devices and report VF realization errors at PF
realization time.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20240627-reuse-v10-6-7ca0b8ed3d9f@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'include/hw/pci/pci_device.h')
-rw-r--r--include/hw/pci/pci_device.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h
index d57f9ce838..ca15132508 100644
--- a/include/hw/pci/pci_device.h
+++ b/include/hw/pci/pci_device.h
@@ -205,6 +205,21 @@ static inline uint16_t pci_get_bdf(PCIDevice *dev)
     return PCI_BUILD_BDF(pci_bus_num(pci_get_bus(dev)), dev->devfn);
 }
 
+static inline void pci_set_power(PCIDevice *pci_dev, bool state)
+{
+    /*
+     * Don't change the enabled state of VFs when powering on/off the device.
+     *
+     * When powering on, VFs must not be enabled immediately but they must
+     * wait until the guest configures SR-IOV.
+     * When powering off, their corresponding PFs will be reset and disable
+     * VFs.
+     */
+    if (!pci_is_vf(pci_dev)) {
+        pci_set_enabled(pci_dev, state);
+    }
+}
+
 uint16_t pci_requester_id(PCIDevice *dev);
 
 /* DMA access functions */