Skip to contentSkip to conversation

pcie: Add support for Single Root I/O Virtualization

PATCH Superseded Knut Omang 2 participants 10 messages Sep 2, 2014 – Oct 3, 2014

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Knut Omang

author
#0 lore raw

v2 cover pcie: Add support for Single Root I/O Virtualization

This patch set implements generic support for SR/IOV as an extension to the core PCIe functionality, similar to the way other capabilities such as AER is implemented.

There is no implementation of any device that provides SR/IOV support included, but I have implemented a test example which can be found together with this patch set here:

git://github.com/knuto/qemu.git sriov_patches_v2

Testing with this example device documented here:

http://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg05110.html

Changes since v1:
- Rebased on top of latest master, eliminating prereqs.
- Implement proper support for VF_STRIDE, VF_OFFSET and SUP_PGSIZE Time better spent fixing it than explaining what the previous limitations were.
- Added new first patch to fix pci bug related to this
- Split out patch to pci_default_config_write to a separate patch 2 to highlight bug fix.
- Refactored out logic into new source files hw/pci/pcie_sriov.c include/hw/pci/pcie_sriov.h similar to pcie_aer.c/h.
- Rename functions and introduce structs to better separate pf and vf functionality.
- Replaced is_vf member with pci_is_vf() function abstraction
- Fix numerous syntax, whitespace and comment issues according to Michael's review.
- Fix memory leaks.
- Removed igb example device - a rebased version available on github instead.

Knut Omang (4):
pci: Make use of the devfn property when registering new devices
pci: Avoid losing config updates to MSI/MSIX cap regs
pci: Update pci_regs header
pcie: Add support for Single Root I/O Virtualization (SR/IOV)

 hw/i386/kvm/pci-assign.c    |   4 +-
 hw/misc/vfio.c              |   8 +-
 hw/pci/Makefile.objs        |   2 +-
 hw/pci/msi.c                |   4 -
 hw/pci/msix.c               |   2 +-
 hw/pci/pci.c                | 106 +++++++++----
 hw/pci/pcie.c               |   9 +-
 hw/pci/pcie_sriov.c         | 267 +++++++++++++++++++++++++++++++
 include/hw/pci/pci.h        |  11 +-
 include/hw/pci/pci_regs.h   | 371 +++++++++++++++++++++++++++++++++-----------
 include/hw/pci/pcie.h       |   6 +
 include/hw/pci/pcie_sriov.h |  55 +++++++
 include/qemu/typedefs.h     |   2 +
 13 files changed, 708 insertions(+), 139 deletions(-)
 create mode 100644 hw/pci/pcie_sriov.c
 create mode 100644 include/hw/pci/pcie_sriov.h
Signature · 1 line
1.9.0
author
#1 lore raw

PATCH v2 1/4 pci: Make use of the devfn property when registering new devices

Without this, the devfn argument to pci_create_*() does not affect the assigned devfn.

Needed to support (VF_STRIDE,VF_OFFSET) values other than (1,1) for SR/IOV.

---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +1 -1
index daeaeac..6b21dee 100644
@@ -1757,7 +1757,7 @@ static int pci_qdev_init(DeviceState *qdev)
     bus = PCI_BUS(qdev_get_parent_bus(qdev));
     pci_dev = do_pci_register_device(pci_dev, bus,
                                      object_get_typename(OBJECT(qdev)),
-                                     pci_dev->devfn);
+                                     object_property_get_int(OBJECT(qdev), "addr", NULL));
     if (pci_dev == NULL)
         return -1;
 
Signature · 1 line
1.9.0
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/4] pci: Make use of the devfn property when registering new devices

Quoted 7 lines · Knut Omang

Without this, the devfn argument to pci_create_*() does not affect the assigned devfn.

Needed to support (VF_STRIDE,VF_OFFSET) values other than (1,1) for SR/IOV.

Sorry, I don't understand the explanation exactly. pci_dev->devfn is not set correctly? why?

Quoted 19 lines
---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +1 -1
index daeaeac..6b21dee 100644
@@ -1757,7 +1757,7 @@ static int pci_qdev_init(DeviceState *qdev)
     bus = PCI_BUS(qdev_get_parent_bus(qdev));
     pci_dev = do_pci_register_device(pci_dev, bus,
                                      object_get_typename(OBJECT(qdev)),
-                                     pci_dev->devfn);
+                                     object_property_get_int(OBJECT(qdev), "addr", NULL));
     if (pci_dev == NULL)
         return -1;
 
Signature · 1 line
1.9.0
author
#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/4] pci: Make use of the devfn property when registering new devices

Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Knut Omang

Without this, the devfn argument to pci_create_*() does not affect the assigned devfn.

Needed to support (VF_STRIDE,VF_OFFSET) values other than (1,1) for SR/IOV.

Sorry, I don't understand the explanation exactly. pci_dev->devfn is not set correctly? why?

This probably has been broken by some of the qom adaptation if I understand it right: The devfn parameter in pci_create_multifunction() is only used to set the "addr" property, which in turn is not used anywhere as far as I can see. So the pci_dev->devfn has it's default value.

What I observe is that when I enable VFs with the igb example device, now with stride = 2 and offset 0x80 (as my real lab hardware implements) and enable some VFs, this yields devfn's of 0x80, 0x82, 0x84... sent as parameters to pci_create..(), I still end up with this (eg. the "natural" next function will be selected instead of the provided devfn):

01:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01) 01:00.1 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.3 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)

With this patch applied, I get the expected:

01:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01) 01:10.0 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.6 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)

Quoted 19 lines
Quoted 19 lines
---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +1 -1
index daeaeac..6b21dee 100644
@@ -1757,7 +1757,7 @@ static int pci_qdev_init(DeviceState *qdev)
     bus = PCI_BUS(qdev_get_parent_bus(qdev));
     pci_dev = do_pci_register_device(pci_dev, bus,
                                      object_get_typename(OBJECT(qdev)),
-                                     pci_dev->devfn);
+                                     object_property_get_int(OBJECT(qdev), "addr", NULL));
     if (pci_dev == NULL)
         return -1;
 
Signature · 1 line
1.9.0
#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/4] pci: Make use of the devfn property when registering new devices

Quoted 10 lines · Knut Omang
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Knut Omang

Without this, the devfn argument to pci_create_*() does not affect the assigned devfn.

Needed to support (VF_STRIDE,VF_OFFSET) values other than (1,1) for SR/IOV.

Quoted 8 lines
Quoted 2 lines

Sorry, I don't understand the explanation exactly. pci_dev->devfn is not set correctly? why?

This probably has been broken by some of the qom adaptation if I understand it right: The devfn parameter in pci_create_multifunction() is only used to set the "addr" property, which in turn is not used anywhere as far as I can see. So the pci_dev->devfn has it's default value.

There are a bunch of places that depend on devfn being correct though so I think this needs to be fixed.

Quoted 42 lines

What I observe is that when I enable VFs with the igb example device, now with stride = 2 and offset 0x80 (as my real lab hardware implements) and enable some VFs, this yields devfn's of 0x80, 0x82, 0x84... sent as parameters to pci_create..(), I still end up with this (eg. the "natural" next function will be selected instead of the provided devfn):

01:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01) 01:00.1 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.3 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)

With this patch applied, I get the expected:

01:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01) 01:10.0 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.6 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)

Quoted 19 lines
Quoted 19 lines
---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +1 -1
index daeaeac..6b21dee 100644
@@ -1757,7 +1757,7 @@ static int pci_qdev_init(DeviceState *qdev)
     bus = PCI_BUS(qdev_get_parent_bus(qdev));
     pci_dev = do_pci_register_device(pci_dev, bus,
                                      object_get_typename(OBJECT(qdev)),
-                                     pci_dev->devfn);
+                                     object_property_get_int(OBJECT(qdev), "addr", NULL));
     if (pci_dev == NULL)
         return -1;
 
Signature · 1 line
1.9.0
author
#5 lore raw

Re: [Qemu-devel] [PATCH v2 1/4] pci: Make use of the devfn property when registering new devices

Michael,

I just realized this patch set might have got "stuck" because I did not respond to this?

Or did I miss something else?

Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Knut Omang
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Knut Omang

Without this, the devfn argument to pci_create_*() does not affect the assigned devfn.

Needed to support (VF_STRIDE,VF_OFFSET) values other than (1,1) for SR/IOV.

Sorry, I don't understand the explanation exactly. pci_dev->devfn is not set correctly? why?

Quoted 8 lines
Quoted 5 lines

This probably has been broken by some of the qom adaptation if I understand it right: The devfn parameter in pci_create_multifunction() is only used to set the "addr" property, which in turn is not used anywhere as far as I can see. So the pci_dev->devfn has it's default value.

There are a bunch of places that depend on devfn being correct though so I think this needs to be fixed.

The problem with the current code is that pci_dev->devfn is used as an argument to the function that is the one that sets pci_dev->devfn, anything that uses devfn after it has been registered (the normal case) should be fine as far as I can see?

Thanks,

Knut

Quoted 42 lines
Quoted 42 lines

What I observe is that when I enable VFs with the igb example device, now with stride = 2 and offset 0x80 (as my real lab hardware implements) and enable some VFs, this yields devfn's of 0x80, 0x82, 0x84... sent as parameters to pci_create..(), I still end up with this (eg. the "natural" next function will be selected instead of the provided devfn):

01:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01) 01:00.1 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.3 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:00.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)

With this patch applied, I get the expected:

01:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01) 01:10.0 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01) 01:10.6 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)

Quoted 19 lines
Quoted 19 lines
---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +1 -1
index daeaeac..6b21dee 100644
@@ -1757,7 +1757,7 @@ static int pci_qdev_init(DeviceState *qdev)
     bus = PCI_BUS(qdev_get_parent_bus(qdev));
     pci_dev = do_pci_register_device(pci_dev, bus,
                                      object_get_typename(OBJECT(qdev)),
-                                     pci_dev->devfn);
+                                     object_property_get_int(OBJECT(qdev), "addr", NULL));
     if (pci_dev == NULL)
         return -1;
 
Signature · 1 line
1.9.0
author
#6 lore raw

PATCH v2 2/4 pci: Avoid losing config updates to MSI/MSIX cap regs

In reply to Knut Omang

Introduce an extra local variable to avoid that the shifting in the for loop causes updates to msi/msix capability registers to get lost in pci_default_write_config.

---
 hw/pci/pci.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/pci/pci.c +4 -3
index 6b21dee..af547dc 100644
@@ -1146,9 +1146,10 @@ uint32_t pci_default_read_config(PCIDevice *d,
     return le32_to_cpu(val);
 }
 
-void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
+void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int l)
 {
     int i, was_irq_disabled = pci_irq_disabled(d);
+    uint32_t val = val_in;
 
     for (i = 0; i < l; val >>= 8, ++i) {
         uint8_t wmask = d->wmask[addr + i];
@@ -1170,8 +1171,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
                                     & PCI_COMMAND_MASTER);
     }
 
-    msi_write_config(d, addr, val, l);
-    msix_write_config(d, addr, val, l);
+    msi_write_config(d, addr, val_in, l);
+    msix_write_config(d, addr, val_in, l);
 }
 
 /***********************************************************/
Signature · 1 line
1.9.0
#7 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] pci: Avoid losing config updates to MSI/MSIX cap regs

Quoted 5 lines · Knut Omang

Introduce an extra local variable to avoid that the shifting in the for loop causes updates to msi/msix capability registers to get lost in pci_default_write_config.

OK
So this is a regression introduced by:

commit 95d658002401e2e47a5404298ebe9508846e8a39

Author: Jan Kiszka <[email protected]>
Date:   Fri May 11 11:42:40 2012 -0300

msi: Invoke msi/msix_write_config from PCI core

Will queue to qemu-stable as well.

Quoted 33 lines
---
 hw/pci/pci.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/pci/pci.c +4 -3
index 6b21dee..af547dc 100644
@@ -1146,9 +1146,10 @@ uint32_t pci_default_read_config(PCIDevice *d,
     return le32_to_cpu(val);
 }
 
-void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
+void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int l)
 {
     int i, was_irq_disabled = pci_irq_disabled(d);
+    uint32_t val = val_in;
 
     for (i = 0; i < l; val >>= 8, ++i) {
         uint8_t wmask = d->wmask[addr + i];
@@ -1170,8 +1171,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
                                     & PCI_COMMAND_MASTER);
     }
 
-    msi_write_config(d, addr, val, l);
-    msix_write_config(d, addr, val, l);
+    msi_write_config(d, addr, val_in, l);
+    msix_write_config(d, addr, val_in, l);
 }
 
 /***********************************************************/
Signature · 1 line
1.9.0
author
#8 lore raw

PATCH v2 3/4 pci: Update pci_regs header

In reply to Knut Omang

Pulls in latest version from kernel v3.16
msi: Removed local definitions now in pci_regs.h

Also replace usage of PCI_MSIX_FLAGS_BIRMASK with PCI_MSIX_TABLE_BIR to keep in sync with the kernel for future updates.

---
 hw/i386/kvm/pci-assign.c  |   4 +-
 hw/misc/vfio.c            |   8 +-
 hw/pci/msi.c              |   4 -
 hw/pci/msix.c             |   2 +-
 include/hw/pci/pci_regs.h | 371 ++++++++++++++++++++++++++++++++++------------
 5 files changed, 285 insertions(+), 104 deletions(-)
hw/i386/kvm/pci-assign.c +2 -2
index 17c7d6dc..a2285c4 100644
@@ -1321,8 +1321,8 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev, Error **errp)
                      PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL);
 
         msix_table_entry = pci_get_long(pci_dev->config + pos + PCI_MSIX_TABLE);
-        bar_nr = msix_table_entry & PCI_MSIX_FLAGS_BIRMASK;
-        msix_table_entry &= ~PCI_MSIX_FLAGS_BIRMASK;
+        bar_nr = msix_table_entry & PCI_MSIX_TABLE_BIR;
+        msix_table_entry &= ~PCI_MSIX_TABLE_BIR;
         dev->msix_table_addr = pci_region[bar_nr].base_addr + msix_table_entry;
         dev->msix_max = msix_max;
     }
hw/misc/vfio.c +4 -4
index 40dcaa6..f275084 100644
@@ -2799,10 +2799,10 @@ static int vfio_early_setup_msix(VFIODevice *vdev)
     pba = le32_to_cpu(pba);
 
     vdev->msix = g_malloc0(sizeof(*(vdev->msix)));
-    vdev->msix->table_bar = table & PCI_MSIX_FLAGS_BIRMASK;
-    vdev->msix->table_offset = table & ~PCI_MSIX_FLAGS_BIRMASK;
-    vdev->msix->pba_bar = pba & PCI_MSIX_FLAGS_BIRMASK;
-    vdev->msix->pba_offset = pba & ~PCI_MSIX_FLAGS_BIRMASK;
+    vdev->msix->table_bar = table & PCI_MSIX_TABLE_BIR;
+    vdev->msix->table_offset = table & ~PCI_MSIX_TABLE_BIR;
+    vdev->msix->pba_bar = pba & PCI_MSIX_TABLE_BIR;
+    vdev->msix->pba_offset = pba & ~PCI_MSIX_TABLE_BIR;
     vdev->msix->entries = (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
 
     DPRINTF("%04x:%02x:%02x.%x "
hw/pci/msi.c +0 -4
index 52d2313..1d25b62 100644
@@ -21,10 +21,6 @@
 #include "hw/pci/msi.h"
 #include "qemu/range.h"
 
-/* Eventually those constants should go to Linux pci_regs.h */
-#define PCI_MSI_PENDING_32      0x10
-#define PCI_MSI_PENDING_64      0x14
-
 /* PCI_MSI_ADDRESS_LO */
 #define PCI_MSI_ADDRESS_LO_MASK         (~0x3)
 
hw/pci/msix.c +1 -1
index 24de260..8206264 100644
@@ -250,7 +250,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
          ranges_overlap(table_offset, table_size, pba_offset, pba_size)) ||
         table_offset + table_size > memory_region_size(table_bar) ||
         pba_offset + pba_size > memory_region_size(pba_bar) ||
-        (table_offset | pba_offset) & PCI_MSIX_FLAGS_BIRMASK) {
+        (table_offset | pba_offset) & PCI_MSIX_TABLE_BIR) {
         return -EINVAL;
     }
 
include/hw/pci/pci_regs.h +278 -93

612 lines not on this page · raw message

Signature · 1 line
1.9.0
author
#9 lore raw

PATCH v2 4/4 pcie: Add support for Single Root I/O Virtualization (SR/IOV)

In reply to Knut Omang

This patch provides the building blocks for creating an SR/IOV PCIe Extended Capability header and register/unregister SR/IOV Virtual Functions.

---
 hw/pci/Makefile.objs        |   2 +-
 hw/pci/pci.c                |  97 ++++++++++++----
 hw/pci/pcie.c               |   9 +-
 hw/pci/pcie_sriov.c         | 267 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/pci/pci.h        |  11 +-
 include/hw/pci/pcie.h       |   6 +
 include/hw/pci/pcie_sriov.h |  55 +++++++++
 include/qemu/typedefs.h     |   2 +
 8 files changed, 418 insertions(+), 31 deletions(-)
 create mode 100644 hw/pci/pcie_sriov.c
 create mode 100644 include/hw/pci/pcie_sriov.h
hw/pci/Makefile.objs +1 -1
index 80f8aa6..4ed4205 100644
@@ -3,7 +3,7 @@ common-obj-$(CONFIG_PCI) += msix.o msi.o
 common-obj-$(CONFIG_PCI) += shpc.o
 common-obj-$(CONFIG_PCI) += slotid_cap.o
 common-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
-common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o
+common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o pcie_sriov.o
 
 common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
hw/pci/pci.c +73 -24

168 lines not on this page · raw message

hw/pci/pcie.c +5 -4
index 1babddf..a2ac110 100644
@@ -254,7 +254,7 @@ void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
      * Right now, only a device of function = 0 is allowed to be
      * hot plugged/unplugged.
      */
-    assert(PCI_FUNC(pci_dev->devfn) == 0);
+    assert(PCI_FUNC(pci_dev->devfn) == 0 || pci_is_vf(pci_dev));
 
     pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
                                PCI_EXP_SLTSTA_PDS);
@@ -266,10 +266,11 @@ void pcie_cap_slot_hot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                                  Error **errp)
 {
     uint8_t *exp_cap;
+    PCIDevice *pdev = PCI_DEVICE(hotplug_dev);
 
-    pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
+    pcie_cap_slot_hotplug_common(pdev, dev, &exp_cap, errp);
 
-    pcie_cap_slot_push_attention_button(PCI_DEVICE(hotplug_dev));
+    pcie_cap_slot_push_attention_button(pdev);
 }
 
 /* pci express slot for pci express root/downstream port
@@ -409,7 +410,7 @@ void pcie_cap_slot_write_config(PCIDevice *dev,
     }
 
     /*
-     * If the slot is polulated, power indicator is off and power
+     * If the slot is populated, power indicator is off and power
      * controller is off, it is safe to detach the devices.
      */
     if ((sltsta & PCI_EXP_SLTSTA_PDS) && (val & PCI_EXP_SLTCTL_PCC) &&
hw/pci/pcie_sriov.c new file +267 -0

267 lines not on this page · raw message

include/hw/pci/pci.h +9 -2
index c352c7b..ebda70f 100644
@@ -11,8 +11,6 @@
 /* PCI includes legacy ISA access.  */
 #include "hw/isa/isa.h"
 
-#include "hw/pci/pcie.h"
-
 /* PCI bus */
 
 #define PCI_DEVFN(slot, func)   ((((slot) & 0x1f) << 3) | ((func) & 0x07))
@@ -127,6 +125,7 @@ enum {
 #define QEMU_PCI_VGA_IO_HI_SIZE 0x20
 
 #include "hw/pci/pci_regs.h"
+#include "hw/pci/pcie.h"
 
 /* PCI HEADER_TYPE */
 #define  PCI_HEADER_TYPE_MULTI_FUNCTION 0x80
@@ -413,6 +412,9 @@ typedef AddressSpace *(*PCIIOMMUFunc)(PCIBus *, void *, int);
 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev);
 void pci_setup_iommu(PCIBus *bus, PCIIOMMUFunc fn, void *opaque);
 
+pcibus_t pci_bar_address(PCIDevice *d,
+                         int reg, uint8_t type, pcibus_t size);
+
 static inline void
 pci_set_byte(uint8_t *config, uint8_t val)
 {
@@ -664,6 +666,11 @@ static inline int pci_is_express(const PCIDevice *d)
     return d->cap_present & QEMU_PCI_CAP_EXPRESS;
 }
 
+static inline int pci_is_vf(const PCIDevice *d)
+{
+    return d->exp.sriov_vf.pf != NULL;
+}
+
 static inline uint32_t pci_config_size(const PCIDevice *d)
 {
     return pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE : PCI_CONFIG_SPACE_SIZE;
include/hw/pci/pcie.h +6 -0
index d139d58..68578e2 100644
@@ -25,6 +25,7 @@
 #include "hw/pci/pci_regs.h"
 #include "hw/pci/pcie_regs.h"
 #include "hw/pci/pcie_aer.h"
+#include "hw/pci/pcie_sriov.h"
 #include "hw/hotplug.h"
 
 typedef enum {
@@ -74,6 +75,11 @@ struct PCIExpressDevice {
     /* AER */
     uint16_t aer_cap;
     PCIEAERLog aer_log;
+
+    /* SR/IOV */
+    uint16_t sriov_cap;
+    PCIESriovPF sriov_pf;
+    PCIESriovVF sriov_vf;
 };
 
 #define COMPAT_PROP_PCP "power_controller_present"
include/hw/pci/pcie_sriov.h new file +55 -0

55 lines not on this page · raw message

include/qemu/typedefs.h +2 -0
index 5f20b0e..1954818 100644
@@ -58,6 +58,8 @@ typedef struct PCIBridge PCIBridge;
 typedef struct PCIEAERMsg PCIEAERMsg;
 typedef struct PCIEAERLog PCIEAERLog;
 typedef struct PCIEAERErr PCIEAERErr;
+typedef struct PCIESriovPF PCIESriovPF;
+typedef struct PCIESriovVF PCIESriovVF;
 typedef struct PCIEPort PCIEPort;
 typedef struct PCIESlot PCIESlot;
 typedef struct MSIMessage MSIMessage;
Signature · 1 line
1.9.0