Skip to contentSkip to conversation

msi: Small cleanups and fixes

PATCH In review Jan Kiszka 3 participants 30 messages Jun 8, 2011

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

v2 cover msi: Small cleanups and fixes

A few patches to the MSI and MSI-X layer that clean up the interfaces and fix reset issues. They are from my MSI rework to prepare it for KVM's requirements (in-kernel irqchip).

In contrast to the previous version, this one moves msi[x]_reset, msi[x]_write_config and msi[x]_uninit into the PCI core, avoiding related bugs and reducing boilerplate code on device side.

CC Alexander Graf <[email protected]>
CC Gerd Hoffmann <[email protected]>
CC Isaku Yamahata <[email protected]>

Jan Kiszka (9):
msi: Fix copy&paste mistake in msi_uninit
msi: Guard msi/msix_write_config with msi_present
msi: Guard msi_reset with msi_present
msi: Use msi/msix_present more consistently
msi: Invoke msi/msix_reset from PCI core
msi: Invoke msi/msix_write_config from PCI core
msi: Invoke msi/msix_uninit from PCI core
msix: Align MSI-X constants to libpci definitions and extend them
msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

 hw/ide/ich.c            |    9 ---------
 hw/intel-hda.c          |   13 -------------
 hw/ioh3420.c            |    8 ++------
 hw/msi.c                |   17 +++++++++--------
 hw/msix.c               |   39 ++++++++++++++++++++-------------------
 hw/pci.c                |   10 ++++++++++
 hw/pci_bridge.c         |    4 ++++
 hw/pci_regs.h           |   16 ++++++++++------
 hw/virtio-pci.c         |   14 +++-----------
 hw/xio3130_downstream.c |    8 ++------
 hw/xio3130_upstream.c   |    7 +------
 11 files changed, 61 insertions(+), 84 deletions(-)
author
#1 lore raw

PATCH v2 1/9 msi: Fix copy&paste mistake in msi_uninit

---
 hw/msi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/msi.c +1 -1
index b087fe5..e8c5607 100644
@@ -172,7 +172,7 @@ void msi_uninit(struct PCIDevice *dev)
     }
     flags = pci_get_word(dev->config + msi_flags_off(dev));
     cap_size = msi_cap_sizeof(flags);
-    pci_del_capability(dev, PCI_CAP_ID_MSIX, cap_size);
+    pci_del_capability(dev, PCI_CAP_ID_MSI, cap_size);
     dev->cap_present &= ~QEMU_PCI_CAP_MSI;
 
     MSI_DEV_PRINTF(dev, "uninit\n");
Signature · 1 line
1.7.1
author
#2 lore raw

PATCH v2 2/9 msi: Guard msi/msix_write_config with msi_present

In reply to Jan Kiszka

Terminate msi/msix_write_config early if support is not enabled. This allows to remove checks at the caller site if MSI is optional.

---
 hw/msi.c  |    3 ++-
 hw/msix.c |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
hw/msi.c +2 -1
index e8c5607..b7a92c9 100644
@@ -264,7 +264,8 @@ void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len)
     unsigned int vector;
     uint32_t pending;
 
-    if (!ranges_overlap(addr, len, dev->msi_cap, msi_cap_sizeof(flags))) {
+    if (!msi_present(dev) ||
+        !ranges_overlap(addr, len, dev->msi_cap, msi_cap_sizeof(flags))) {
         return;
     }
 
hw/msix.c +1 -1
index af40e26..703f082 100644
@@ -160,7 +160,7 @@ void msix_write_config(PCIDevice *dev, uint32_t addr,
     unsigned enable_pos = dev->msix_cap + MSIX_CONTROL_OFFSET;
     int vector;
 
-    if (!range_covers_byte(addr, len, enable_pos)) {
+    if (!msix_present(dev) || !range_covers_byte(addr, len, enable_pos)) {
         return;
     }
 
Signature · 1 line
1.7.1
author
#3 lore raw

PATCH v2 3/9 msi: Guard msi_reset with msi_present

In reply to Jan Kiszka
---
 hw/msi.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
hw/msi.c +4 -0
index b7a92c9..b039893 100644
@@ -183,6 +183,10 @@ void msi_reset(PCIDevice *dev)
     uint16_t flags;
     bool msi64bit;
 
+    if (!msi_present(dev)) {
+        return;
+    }
+
     flags = pci_get_word(dev->config + msi_flags_off(dev));
     flags &= ~(PCI_MSI_FLAGS_QSIZE | PCI_MSI_FLAGS_ENABLE);
     msi64bit = flags & PCI_MSI_FLAGS_64BIT;
Signature · 1 line
1.7.1
author
#4 lore raw

PATCH v2 4/9 msi: Use msi/msix_present more consistently

In reply to Jan Kiszka

Replace some open-coded msi/msix_present checks and drop redundant msix_supported tests (present implies supported).

---
 hw/msi.c  |    2 +-
 hw/msix.c |   13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
hw/msi.c +1 -1
index b039893..09bcdd1 100644
@@ -167,7 +167,7 @@ void msi_uninit(struct PCIDevice *dev)
     uint16_t flags;
     uint8_t cap_size;
 
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSI)) {
+    if (!msi_present(dev)) {
         return;
     }
     flags = pci_get_word(dev->config + msi_flags_off(dev));
hw/msix.c +8 -5
index 703f082..600f5fb 100644
@@ -290,8 +290,9 @@ static void msix_free_irq_entries(PCIDevice *dev)
 /* Clean up resources for the device. */
 int msix_uninit(PCIDevice *dev)
 {
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+    if (!msix_present(dev)) {
         return 0;
+    }
     pci_del_capability(dev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
     dev->msix_cap = 0;
     msix_free_irq_entries(dev);
@@ -309,7 +310,7 @@ void msix_save(PCIDevice *dev, QEMUFile *f)
 {
     unsigned n = dev->msix_entries_nr;
 
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) {
+    if (!msix_present(dev)) {
         return;
     }
 
@@ -322,7 +323,7 @@ void msix_load(PCIDevice *dev, QEMUFile *f)
 {
     unsigned n = dev->msix_entries_nr;
 
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) {
+    if (!msix_present(dev)) {
         return;
     }
 
@@ -374,8 +375,9 @@ void msix_notify(PCIDevice *dev, unsigned vector)
 
 void msix_reset(PCIDevice *dev)
 {
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+    if (!msix_present(dev)) {
         return;
+    }
     msix_free_irq_entries(dev);
     dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] &=
 	    ~dev->wmask[dev->msix_cap + MSIX_CONTROL_OFFSET];
@@ -414,7 +416,8 @@ void msix_vector_unuse(PCIDevice *dev, unsigned vector)
 
 void msix_unuse_all_vectors(PCIDevice *dev)
 {
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+    if (!msix_present(dev)) {
         return;
+    }
     msix_free_irq_entries(dev);
 }
Signature · 1 line
1.7.1
author
#5 lore raw

PATCH v2 5/9 msi: Invoke msi/msix_reset from PCI core

In reply to Jan Kiszka

There is no point in pushing this burden to the devices, they may rather forget to call them (like intel-hda and ahci ATM). Instead, reset functions are now called from pci_device_reset and pci_bridge_reset. They do nothing if the MSI/MSI-X is not in use.

CC Alexander Graf <[email protected]>
CC Gerd Hoffmann <[email protected]>
CC Isaku Yamahata <[email protected]>
---
 hw/ioh3420.c            |    2 +-
 hw/pci.c                |    5 +++++
 hw/pci_bridge.c         |    4 ++++
 hw/virtio-pci.c         |    1 -
 hw/xio3130_downstream.c |    2 +-
 hw/xio3130_upstream.c   |    1 -
 6 files changed, 11 insertions(+), 4 deletions(-)
hw/ioh3420.c +1 -1
index 95adf09..73bc55f 100644
@@ -81,7 +81,7 @@ static void ioh3420_write_config(PCIDevice *d,
 static void ioh3420_reset(DeviceState *qdev)
 {
     PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
-    msi_reset(d);
+
     ioh3420_aer_vector_update(d);
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
hw/pci.c +5 -0
index 1d297d6..967f812 100644
@@ -31,6 +31,8 @@
 #include "loader.h"
 #include "qemu-objects.h"
 #include "range.h"
+#include "msi.h"
+#include "msix.h"
 
 //#define DEBUG_PCI
 #ifdef DEBUG_PCI
@@ -191,6 +193,9 @@ void pci_device_reset(PCIDevice *dev)
         }
     }
     pci_update_mappings(dev);
+
+    msi_reset(dev);
+    msix_reset(dev);
 }
 
 /*
hw/pci_bridge.c +4 -0
index 464d897..3951252 100644
@@ -32,6 +32,8 @@
 #include "pci_bridge.h"
 #include "pci_internals.h"
 #include "range.h"
+#include "msi.h"
+#include "msix.h"
 
 /* PCI bridge subsystem vendor ID helper functions */
 #define PCI_SSVID_SIZEOF        8
@@ -224,6 +226,8 @@ void pci_bridge_reset(DeviceState *qdev)
 {
     PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
     pci_bridge_reset_reg(dev);
+    msi_reset(dev);
+    msix_reset(dev);
 }
 
 /* default qdev initialization function for PCI-to-PCI bridge */
hw/virtio-pci.c +0 -1
index c19629d..075d657 100644
@@ -310,7 +310,6 @@ static void virtio_pci_reset(DeviceState *d)
     VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
     virtio_pci_stop_ioeventfd(proxy);
     virtio_reset(proxy->vdev);
-    msix_reset(&proxy->pci_dev);
     proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
 }
 
hw/xio3130_downstream.c +1 -1
index 5aa6a6b..a587c3e 100644
@@ -48,7 +48,7 @@ static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,
 static void xio3130_downstream_reset(DeviceState *qdev)
 {
     PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
-    msi_reset(d);
+
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
     pcie_cap_ari_reset(d);
hw/xio3130_upstream.c +0 -1
index a7640f5..9d75449 100644
@@ -47,7 +47,6 @@ static void xio3130_upstream_write_config(PCIDevice *d, uint32_t address,
 static void xio3130_upstream_reset(DeviceState *qdev)
 {
     PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
-    msi_reset(d);
     pci_bridge_reset(qdev);
     pcie_cap_deverr_reset(d);
 }
Signature · 1 line
1.7.1
#6 lore raw

Re: [Qemu-devel] [PATCH v2 5/9] msi: Invoke msi/msix_reset from PCI core

Quoted 45 lines · Jan Kiszka

There is no point in pushing this burden to the devices, they may rather forget to call them (like intel-hda and ahci ATM). Instead, reset functions are now called from pci_device_reset and pci_bridge_reset. They do nothing if the MSI/MSI-X is not in use.

CC Alexander Graf <[email protected]>
CC Gerd Hoffmann <[email protected]>
CC Isaku Yamahata <[email protected]>
---
 hw/ioh3420.c            |    2 +-
 hw/pci.c                |    5 +++++
 hw/pci_bridge.c         |    4 ++++
 hw/virtio-pci.c         |    1 -
 hw/xio3130_downstream.c |    2 +-
 hw/xio3130_upstream.c   |    1 -
 6 files changed, 11 insertions(+), 4 deletions(-)
hw/ioh3420.c +1 -1
index 95adf09..73bc55f 100644
@@ -81,7 +81,7 @@ static void ioh3420_write_config(PCIDevice *d,
 static void ioh3420_reset(DeviceState *qdev)
 {
     PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
-    msi_reset(d);
+
     ioh3420_aer_vector_update(d);
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
hw/pci.c +2 -0
index 1d297d6..967f812 100644
@@ -31,6 +31,8 @@
 #include "loader.h"
 #include "qemu-objects.h"
 #include "range.h"
+#include "msi.h"
+#include "msix.h"
 
 //#define DEBUG_PCI
 #ifdef DEBUG_PCI

hw/pci.c void pci_device_reset(PCIDevice *dev) · line 201

Quoted 9 lines
hw/pci.c +3 -0
@@ -191,6 +193,9 @@ void pci_device_reset(PCIDevice *dev)
         }
     }
     pci_update_mappings(dev);
+
+    msi_reset(dev);
+    msix_reset(dev);
 }
 
 /*

I am reluctant to add this dependency in pci.c:
this goes against the efforts to modularise the
pci subsystem. As I see it, pci.c should really only handle the common header. Instead I would like to add pci_caps.c and have that call out to all the capabilities (not just reset, same applies to other caps really).

I started doing that, if no one beats me to it, I'll try to dust off that patch and post it next week.

Quoted 61 lines
hw/pci_bridge.c +4 -0
index 464d897..3951252 100644
@@ -32,6 +32,8 @@
 #include "pci_bridge.h"
 #include "pci_internals.h"
 #include "range.h"
+#include "msi.h"
+#include "msix.h"
 
 /* PCI bridge subsystem vendor ID helper functions */
 #define PCI_SSVID_SIZEOF        8
@@ -224,6 +226,8 @@ void pci_bridge_reset(DeviceState *qdev)
 {
     PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
     pci_bridge_reset_reg(dev);
+    msi_reset(dev);
+    msix_reset(dev);
 }
 
 /* default qdev initialization function for PCI-to-PCI bridge */
hw/virtio-pci.c +0 -1
index c19629d..075d657 100644
@@ -310,7 +310,6 @@ static void virtio_pci_reset(DeviceState *d)
     VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
     virtio_pci_stop_ioeventfd(proxy);
     virtio_reset(proxy->vdev);
-    msix_reset(&proxy->pci_dev);
     proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
 }
 
hw/xio3130_downstream.c +1 -1
index 5aa6a6b..a587c3e 100644
@@ -48,7 +48,7 @@ static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,
 static void xio3130_downstream_reset(DeviceState *qdev)
 {
     PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
-    msi_reset(d);
+
     pcie_cap_deverr_reset(d);
     pcie_cap_slot_reset(d);
     pcie_cap_ari_reset(d);
hw/xio3130_upstream.c +0 -1
index a7640f5..9d75449 100644
@@ -47,7 +47,6 @@ static void xio3130_upstream_write_config(PCIDevice *d, uint32_t address,
 static void xio3130_upstream_reset(DeviceState *qdev)
 {
     PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
-    msi_reset(d);
     pci_bridge_reset(qdev);
     pcie_cap_deverr_reset(d);
 }
Signature · 1 line
1.7.1
#7 lore raw

Re: [Qemu-devel] [PATCH v2 5/9] msi: Invoke msi/msix_reset from PCI core

Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Jan Kiszka

There is no point in pushing this burden to the devices, they may rather forget to call them (like intel-hda and ahci ATM). Instead, reset functions are now called from pci_device_reset and pci_bridge_reset. They do nothing if the MSI/MSI-X is not in use.

CC Alexander Graf <[email protected]>
CC Gerd Hoffmann <[email protected]>
CC Isaku Yamahata <[email protected]>
---
 hw/ioh3420.c            |    2 +-
 hw/pci.c                |    5 +++++
 hw/pci_bridge.c         |    4 ++++
 hw/virtio-pci.c         |    1 -
 hw/xio3130_downstream.c |    2 +-
 hw/xio3130_upstream.c   |    1 -
 6 files changed, 11 insertions(+), 4 deletions(-)
hw/ioh3420.c +1 -1
index 95adf09..73bc55f 100644
@@ -81,7 +81,7 @@ static void ioh3420_write_config(PCIDevice *d,
 static void ioh3420_reset(DeviceState *qdev)
 {
     PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
-    msi_reset(d);
+
     ioh3420_aer_vector_update(d);
     pcie_cap_root_reset(d);
     pcie_cap_deverr_reset(d);
hw/pci.c +5 -0
index 1d297d6..967f812 100644
@@ -31,6 +31,8 @@
 #include "loader.h"
 #include "qemu-objects.h"
 #include "range.h"
+#include "msi.h"
+#include "msix.h"
 
 //#define DEBUG_PCI
 #ifdef DEBUG_PCI
@@ -191,6 +193,9 @@ void pci_device_reset(PCIDevice *dev)
         }
     }
     pci_update_mappings(dev);
+
+    msi_reset(dev);
+    msix_reset(dev);
 }
 
Quoted 8 lines

hw/pci.c void pci_device_reset(PCIDevice *dev) · line 201

Quoted 1 line
hw/pci.c +0 -0
 /*

I am reluctant to add this dependency in pci.c:
this goes against the efforts to modularise the
pci subsystem. As I see it, pci.c should really only handle the common header. Instead I would like to add pci_caps.c and have that call out to all the capabilities (not just reset, same applies to other caps really).

Yeah, true. The result should just remain that devices no longer need to worry about this.

Quoted 3 lines

I started doing that, if no one beats me to it, I'll try to dust off that patch and post it next week.

Would be welcome.

Jan

author
#8 lore raw

PATCH v2 6/9 msi: Invoke msi/msix_write_config from PCI core

In reply to Jan Kiszka

Also this functions is better invoked by the core than by each and every device. This allows to drop the config_write callbacks from ich and intel-hda.

CC Alexander Graf <[email protected]>
CC Gerd Hoffmann <[email protected]>
CC Isaku Yamahata <[email protected]>
---
 hw/ide/ich.c            |    8 --------
 hw/intel-hda.c          |   12 ------------
 hw/ioh3420.c            |    1 -
 hw/msi.c                |    2 +-
 hw/pci.c                |    3 +++
 hw/virtio-pci.c         |    1 -
 hw/xio3130_downstream.c |    1 -
 hw/xio3130_upstream.c   |    1 -
 8 files changed, 4 insertions(+), 25 deletions(-)
hw/ide/ich.c +0 -8
index 6150ce3..2aaef10 100644
@@ -116,13 +116,6 @@ static int pci_ich9_uninit(PCIDevice *dev)
     return 0;
 }
 
-static void pci_ich9_write_config(PCIDevice *pci, uint32_t addr,
-                                  uint32_t val, int len)
-{
-    pci_default_write_config(pci, addr, val, len);
-    msi_write_config(pci, addr, val, len);
-}
-
 static PCIDeviceInfo ich_ahci_info[] = {
     {
         .qdev.name    = "ich9-ahci",
@@ -130,7 +123,6 @@ static PCIDeviceInfo ich_ahci_info[] = {
         .qdev.size    = sizeof(AHCIPCIState),
         .init         = pci_ich9_ahci_init,
         .exit         = pci_ich9_uninit,
-        .config_write = pci_ich9_write_config,
     },{
         /* end of list */
     }
hw/intel-hda.c +0 -12
index 5485745..99d9b98 100644
@@ -1170,17 +1170,6 @@ static int intel_hda_exit(PCIDevice *pci)
     return 0;
 }
 
-static void intel_hda_write_config(PCIDevice *pci, uint32_t addr,
-                                   uint32_t val, int len)
-{
-    IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci);
-
-    pci_default_write_config(pci, addr, val, len);
-    if (d->msi) {
-        msi_write_config(pci, addr, val, len);
-    }
-}
-
 static int intel_hda_post_load(void *opaque, int version)
 {
     IntelHDAState* d = opaque;
@@ -1264,7 +1253,6 @@ static PCIDeviceInfo intel_hda_info = {
     .qdev.reset   = intel_hda_reset,
     .init         = intel_hda_init,
     .exit         = intel_hda_exit,
-    .config_write = intel_hda_write_config,
     .qdev.props   = (Property[]) {
         DEFINE_PROP_UINT32("debug", IntelHDAState, debug, 0),
         DEFINE_PROP_UINT32("msi", IntelHDAState, msi, 1),
hw/ioh3420.c +0 -1
index 73bc55f..3c28648 100644
@@ -71,7 +71,6 @@ static void ioh3420_write_config(PCIDevice *d,
         pci_get_long(d->config + d->exp.aer_cap + PCI_ERR_ROOT_COMMAND);
 
     pci_bridge_write_config(d, address, val, len);
-    msi_write_config(d, address, val, len);
     ioh3420_aer_vector_update(d);
     pcie_cap_slot_write_config(d, address, val, len);
     pcie_aer_write_config(d, address, val, len);
hw/msi.c +1 -1
index 09bcdd1..e23f5df 100644
@@ -256,7 +256,7 @@ void msi_notify(PCIDevice *dev, unsigned int vector)
     stl_phys(address, data);
 }
 
-/* call this function after updating configs by pci_default_write_config(). */
+/* Normally called by pci_default_write_config(). */
 void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len)
 {
     uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
hw/pci.c +3 -0
index 967f812..fc2b555 100644
@@ -1119,6 +1119,9 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
 
     if (range_covers_byte(addr, l, PCI_COMMAND))
         pci_update_irq_disabled(d, was_irq_disabled);
+
+    msi_write_config(d, addr, val, l);
+    msix_write_config(d, addr, val, l);
 }
 
 /***********************************************************/
hw/virtio-pci.c +0 -1
index 075d657..a181291 100644
@@ -547,7 +547,6 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
     }
 
     pci_default_write_config(pci_dev, address, val, len);
-    msix_write_config(pci_dev, address, val, len);
 }
 
 static unsigned virtio_pci_get_features(void *opaque)
hw/xio3130_downstream.c +0 -1
index a587c3e..933a1ee 100644
@@ -41,7 +41,6 @@ static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,
     pci_bridge_write_config(d, address, val, len);
     pcie_cap_flr_write_config(d, address, val, len);
     pcie_cap_slot_write_config(d, address, val, len);
-    msi_write_config(d, address, val, len);
     pcie_aer_write_config(d, address, val, len);
 }
 
hw/xio3130_upstream.c +0 -1
index 9d75449..584ffa2 100644
@@ -40,7 +40,6 @@ static void xio3130_upstream_write_config(PCIDevice *d, uint32_t address,
 {
     pci_bridge_write_config(d, address, val, len);
     pcie_cap_flr_write_config(d, address, val, len);
-    msi_write_config(d, address, val, len);
     pcie_aer_write_config(d, address, val, len);
 }
 
Signature · 1 line
1.7.1
author
#9 lore raw

PATCH v2 7/9 msi: Invoke msi/msix_uninit from PCI core

In reply to Jan Kiszka

Again less boilerplate: Clean up MSI/MSI-X unconditionally from the PCI PCI core. Both services do nothing if there was no support registered. Eliminates virtio_exit_pci among other things.

CC Alexander Graf <[email protected]>
CC Gerd Hoffmann <[email protected]>
CC Isaku Yamahata <[email protected]>
---
 hw/ide/ich.c            |    1 -
 hw/intel-hda.c          |    1 -
 hw/ioh3420.c            |    5 +----
 hw/pci.c                |    2 ++
 hw/virtio-pci.c         |   12 +++---------
 hw/xio3130_downstream.c |    5 +----
 hw/xio3130_upstream.c   |    5 +----
 7 files changed, 8 insertions(+), 23 deletions(-)
hw/ide/ich.c +0 -1
index 2aaef10..016bca0 100644
@@ -109,7 +109,6 @@ static int pci_ich9_uninit(PCIDevice *dev)
     struct AHCIPCIState *d;
     d = DO_UPCAST(struct AHCIPCIState, card, dev);
 
-    msi_uninit(dev);
     qemu_unregister_reset(ahci_reset, d);
     ahci_uninit(&d->ahci);
 
hw/intel-hda.c +0 -1
index 99d9b98..174f201 100644
@@ -1165,7 +1165,6 @@ static int intel_hda_exit(PCIDevice *pci)
 {
     IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci);
 
-    msi_uninit(&d->pci);
     cpu_unregister_io_memory(d->mmio_addr);
     return 0;
 }
hw/ioh3420.c +1 -4
index 3c28648..1667e66 100644
@@ -122,7 +122,7 @@ static int ioh3420_initfn(PCIDevice *d)
     }
     rc = pcie_cap_init(d, IOH_EP_EXP_OFFSET, PCI_EXP_TYPE_ROOT_PORT, p->port);
     if (rc < 0) {
-        goto err_msi;
+        goto err_bridge;
     }
     pcie_cap_deverr_init(d);
     pcie_cap_slot_init(d, s->slot);
@@ -145,8 +145,6 @@ err:
     pcie_chassis_del_slot(s);
 err_pcie_cap:
     pcie_cap_exit(d);
-err_msi:
-    msi_uninit(d);
 err_bridge:
     tmp = pci_bridge_exitfn(d);
     assert(!tmp);
@@ -162,7 +160,6 @@ static int ioh3420_exitfn(PCIDevice *d)
     pcie_aer_exit(d);
     pcie_chassis_del_slot(s);
     pcie_cap_exit(d);
-    msi_uninit(d);
     return pci_bridge_exitfn(d);
 }
 
hw/pci.c +2 -0
index fc2b555..f77ae26 100644
@@ -783,6 +783,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
 
 static void do_pci_unregister_device(PCIDevice *pci_dev)
 {
+    msi_uninit(pci_dev);
+    msix_uninit(pci_dev);
     qemu_free_irqs(pci_dev->irq);
     pci_dev->bus->devices[pci_dev->devfn] = NULL;
     pci_config_free(pci_dev);
hw/virtio-pci.c +3 -9
index a181291..1044fce 100644
@@ -742,11 +742,6 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
-static int virtio_exit_pci(PCIDevice *pci_dev)
-{
-    return msix_uninit(pci_dev);
-}
-
 static int virtio_blk_exit_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -754,7 +749,7 @@ static int virtio_blk_exit_pci(PCIDevice *pci_dev)
     virtio_pci_stop_ioeventfd(proxy);
     virtio_blk_exit(proxy->vdev);
     blockdev_mark_auto_del(proxy->block.bs);
-    return virtio_exit_pci(pci_dev);
+    return 0;
 }
 
 static int virtio_serial_init_pci(PCIDevice *pci_dev)
@@ -788,7 +783,7 @@ static int virtio_serial_exit_pci(PCIDevice *pci_dev)
 
     virtio_pci_stop_ioeventfd(proxy);
     virtio_serial_exit(proxy->vdev);
-    return virtio_exit_pci(pci_dev);
+    return 0;
 }
 
 static int virtio_net_init_pci(PCIDevice *pci_dev)
@@ -816,7 +811,7 @@ static int virtio_net_exit_pci(PCIDevice *pci_dev)
 
     virtio_pci_stop_ioeventfd(proxy);
     virtio_net_exit(proxy->vdev);
-    return virtio_exit_pci(pci_dev);
+    return 0;
 }
 
 static int virtio_balloon_init_pci(PCIDevice *pci_dev)
@@ -913,7 +908,6 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.alias = "virtio-balloon",
         .qdev.size = sizeof(VirtIOPCIProxy),
         .init      = virtio_balloon_init_pci,
-        .exit      = virtio_exit_pci,
         .qdev.props = (Property[]) {
             DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
             DEFINE_PROP_END_OF_LIST(),
hw/xio3130_downstream.c +1 -4
index 933a1ee..62bc7db 100644
@@ -86,7 +86,7 @@ static int xio3130_downstream_initfn(PCIDevice *d)
     rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_DOWNSTREAM,
                        p->port);
     if (rc < 0) {
-        goto err_msi;
+        goto err_bridge;
     }
     pcie_cap_flr_init(d);
     pcie_cap_deverr_init(d);
@@ -108,8 +108,6 @@ err:
     pcie_chassis_del_slot(s);
 err_pcie_cap:
     pcie_cap_exit(d);
-err_msi:
-    msi_uninit(d);
 err_bridge:
     tmp = pci_bridge_exitfn(d);
     assert(!tmp);
@@ -125,7 +123,6 @@ static int xio3130_downstream_exitfn(PCIDevice *d)
     pcie_aer_exit(d);
     pcie_chassis_del_slot(s);
     pcie_cap_exit(d);
-    msi_uninit(d);
     return pci_bridge_exitfn(d);
 }
 
hw/xio3130_upstream.c +1 -4
index 584ffa2..3587aa6 100644
@@ -81,7 +81,7 @@ static int xio3130_upstream_initfn(PCIDevice *d)
     rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_UPSTREAM,
                        p->port);
     if (rc < 0) {
-        goto err_msi;
+        goto err_bridge;
     }
     pcie_cap_flr_init(d);
     pcie_cap_deverr_init(d);
@@ -94,8 +94,6 @@ static int xio3130_upstream_initfn(PCIDevice *d)
 
 err:
     pcie_cap_exit(d);
-err_msi:
-    msi_uninit(d);
 err_bridge:
     tmp =  pci_bridge_exitfn(d);
     assert(!tmp);
@@ -106,7 +104,6 @@ static int xio3130_upstream_exitfn(PCIDevice *d)
 {
     pcie_aer_exit(d);
     pcie_cap_exit(d);
-    msi_uninit(d);
     return pci_bridge_exitfn(d);
 }
 
Signature · 1 line
1.7.1
author
#10 lore raw

PATCH v2 8/9 msix: Align MSI-X constants to libpci definitions and extend them

In reply to Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

---
 hw/msix.c     |   24 +++++++++++-------------
 hw/pci_regs.h |   14 ++++++++------
 2 files changed, 19 insertions(+), 19 deletions(-)
hw/msix.c +11 -13
index 600f5fb..b20cf7c 100644
@@ -16,15 +16,12 @@
 #include "pci.h"
 #include "range.h"
 
-/* MSI-X capability structure */
-#define MSIX_TABLE_OFFSET 4
-#define MSIX_PBA_OFFSET 8
 #define MSIX_CAP_LENGTH 12
 
-/* MSI enable bit and maskall bit are in byte 1 in FLAGS register */
-#define MSIX_CONTROL_OFFSET (PCI_MSIX_FLAGS + 1)
-#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
-#define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8)
+/* MSI enable bit and maskall bit are in byte 1 in control register */
+#define MSIX_CONTROL_OFFSET (PCI_MSIX_CTRL + 1)
+#define MSIX_ENABLE_MASK (PCI_MSIX_ENABLE >> 8)
+#define MSIX_MASKALL_MASK (PCI_MSIX_MASK >> 8)
 
 /* MSI-X table format */
 #define MSIX_MSG_ADDR 0
@@ -58,8 +55,9 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
     uint8_t *config;
     uint32_t new_size;
 
-    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
+    if (nentries < 1 || nentries > PCI_MSIX_TABSIZE + 1) {
         return -EINVAL;
+    }
     if (bar_size > 0x80000000)
         return -ENOSPC;
 
@@ -80,11 +78,11 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
         return config_offset;
     config = pdev->config + config_offset;
 
-    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    pci_set_word(config + PCI_MSIX_CTRL, nentries - 1);
     /* Table on top of BAR */
-    pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
+    pci_set_long(config + PCI_MSIX_TABLE, bar_size | bar_nr);
     /* Pending bits on top of that */
-    pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+    pci_set_long(config + PCI_MSIX_PBA, (bar_size + MSIX_PAGE_PENDING) |
                  bar_nr);
     pdev->msix_cap = config_offset;
     /* Make flags bit writable. */
@@ -208,11 +206,11 @@ void msix_mmio_map(PCIDevice *d, int region_num,
                    pcibus_t addr, pcibus_t size, int type)
 {
     uint8_t *config = d->config + d->msix_cap;
-    uint32_t table = pci_get_long(config + MSIX_TABLE_OFFSET);
+    uint32_t table = pci_get_long(config + PCI_MSIX_TABLE);
     uint32_t offset = table & ~(MSIX_PAGE_SIZE - 1);
     /* TODO: for assigned devices, we'll want to make it possible to map
      * pending bits separately in case they are in a separate bar. */
-    int table_bir = table & PCI_MSIX_FLAGS_BIRMASK;
+    int table_bir = table & PCI_MSIX_BIR;
 
     if (table_bir != region_num)
         return;
hw/pci_regs.h +8 -6
index 5a5ab89..c17c22f 100644
@@ -300,12 +300,14 @@
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
 #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
 
-/* MSI-X registers (these are at offset PCI_MSIX_FLAGS) */
-#define PCI_MSIX_FLAGS		2
-#define  PCI_MSIX_FLAGS_QSIZE	0x7FF
-#define  PCI_MSIX_FLAGS_ENABLE	(1 << 15)
-#define  PCI_MSIX_FLAGS_MASKALL	(1 << 14)
-#define PCI_MSIX_FLAGS_BIRMASK	(7 << 0)
+/* MSI-X registers */
+#define PCI_MSIX_CTRL           2       /* Message control */
+#define  PCI_MSIX_TABSIZE       0x7FF   /* Table size - 1 */
+#define  PCI_MSIX_MASK          0x4000  /* Mask all vectors */
+#define  PCI_MSIX_ENABLE        0x8000  /* Enable MSI-X */
+#define PCI_MSIX_TABLE          4       /* MSI-X table */
+#define PCI_MSIX_PBA            8       /* Pending bit array */
+#define  PCI_MSIX_BIR           0x7     /* BAR indication register */
 
 /* CompactPCI Hotswap Register */
 
Signature · 1 line
1.7.1
#11 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

Quoted 88 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

---
 hw/msix.c     |   24 +++++++++++-------------
 hw/pci_regs.h |   14 ++++++++------
 2 files changed, 19 insertions(+), 19 deletions(-)
hw/msix.c +11 -13
index 600f5fb..b20cf7c 100644
@@ -16,15 +16,12 @@
 #include "pci.h"
 #include "range.h"
 
-/* MSI-X capability structure */
-#define MSIX_TABLE_OFFSET 4
-#define MSIX_PBA_OFFSET 8
 #define MSIX_CAP_LENGTH 12
 
-/* MSI enable bit and maskall bit are in byte 1 in FLAGS register */
-#define MSIX_CONTROL_OFFSET (PCI_MSIX_FLAGS + 1)
-#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
-#define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8)
+/* MSI enable bit and maskall bit are in byte 1 in control register */
+#define MSIX_CONTROL_OFFSET (PCI_MSIX_CTRL + 1)
+#define MSIX_ENABLE_MASK (PCI_MSIX_ENABLE >> 8)
+#define MSIX_MASKALL_MASK (PCI_MSIX_MASK >> 8)
 
 /* MSI-X table format */
 #define MSIX_MSG_ADDR 0
@@ -58,8 +55,9 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
     uint8_t *config;
     uint32_t new_size;
 
-    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
+    if (nentries < 1 || nentries > PCI_MSIX_TABSIZE + 1) {
         return -EINVAL;
+    }
     if (bar_size > 0x80000000)
         return -ENOSPC;
 
@@ -80,11 +78,11 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
         return config_offset;
     config = pdev->config + config_offset;
 
-    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    pci_set_word(config + PCI_MSIX_CTRL, nentries - 1);
     /* Table on top of BAR */
-    pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
+    pci_set_long(config + PCI_MSIX_TABLE, bar_size | bar_nr);
     /* Pending bits on top of that */
-    pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+    pci_set_long(config + PCI_MSIX_PBA, (bar_size + MSIX_PAGE_PENDING) |
                  bar_nr);
     pdev->msix_cap = config_offset;
     /* Make flags bit writable. */
@@ -208,11 +206,11 @@ void msix_mmio_map(PCIDevice *d, int region_num,
                    pcibus_t addr, pcibus_t size, int type)
 {
     uint8_t *config = d->config + d->msix_cap;
-    uint32_t table = pci_get_long(config + MSIX_TABLE_OFFSET);
+    uint32_t table = pci_get_long(config + PCI_MSIX_TABLE);
     uint32_t offset = table & ~(MSIX_PAGE_SIZE - 1);
     /* TODO: for assigned devices, we'll want to make it possible to map
      * pending bits separately in case they are in a separate bar. */
-    int table_bir = table & PCI_MSIX_FLAGS_BIRMASK;
+    int table_bir = table & PCI_MSIX_BIR;
 
     if (table_bir != region_num)
         return;
hw/pci_regs.h +0 -6
index 5a5ab89..c17c22f 100644
@@ -300,12 +300,14 @@
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
 #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
 
-/* MSI-X registers (these are at offset PCI_MSIX_FLAGS) */
-#define PCI_MSIX_FLAGS		2
-#define  PCI_MSIX_FLAGS_QSIZE	0x7FF
-#define  PCI_MSIX_FLAGS_ENABLE	(1 << 15)
-#define  PCI_MSIX_FLAGS_MASKALL	(1 << 14)
-#define PCI_MSIX_FLAGS_BIRMASK	(7 << 0)

hw/pci_regs.h line 312

Quoted 10 lines
hw/pci_regs.h +8 -0
+/* MSI-X registers */
+#define PCI_MSIX_CTRL           2       /* Message control */
+#define  PCI_MSIX_TABSIZE       0x7FF   /* Table size - 1 */
+#define  PCI_MSIX_MASK          0x4000  /* Mask all vectors */
+#define  PCI_MSIX_ENABLE        0x8000  /* Enable MSI-X */
+#define PCI_MSIX_TABLE          4       /* MSI-X table */
+#define PCI_MSIX_PBA            8       /* Pending bit array */
+#define  PCI_MSIX_BIR           0x7     /* BAR indication register */
 
 /* CompactPCI Hotswap Register */

We are using pci_regs.h from Linux, not libpci, as the base. What I see there is:

#define PCI_MSIX_FLAGS          2
#define  PCI_MSIX_FLAGS_QSIZE   0x7FF
#define  PCI_MSIX_FLAGS_ENABLE  (1 << 15)

#define PCI_MSIX_FLAGS_MASKALL (1 << 14)
#define PCI_MSIX_TABLE 4
#define PCI_MSIX_PBA 8
#define PCI_MSIX_FLAGS_BIRMASK (7 << 0)

#define PCI_MSIX_ENTRY_SIZE             16
#define  PCI_MSIX_ENTRY_LOWER_ADDR      0
#define  PCI_MSIX_ENTRY_UPPER_ADDR      4
#define  PCI_MSIX_ENTRY_DATA            8
#define  PCI_MSIX_ENTRY_VECTOR_CTRL     12
#define   PCI_MSIX_ENTRY_CTRL_MASKBIT   1

Let's stick to that please.

Quoted 3 lines
Signature · 2 lines
-- 
1.7.1
#12 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

In reply to Jan Kiszka
Quoted 5 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

Besides keeping pci_regs.h aligned with the original, I also think ideally pci register banging should stay within the pci subsystem.

Could we add high-level APIs to help with that, instead of having kvm look at config space directly?

Quoted 96 lines
---
 hw/msix.c     |   24 +++++++++++-------------
 hw/pci_regs.h |   14 ++++++++------
 2 files changed, 19 insertions(+), 19 deletions(-)
hw/msix.c +11 -13
index 600f5fb..b20cf7c 100644
@@ -16,15 +16,12 @@
 #include "pci.h"
 #include "range.h"
 
-/* MSI-X capability structure */
-#define MSIX_TABLE_OFFSET 4
-#define MSIX_PBA_OFFSET 8
 #define MSIX_CAP_LENGTH 12
 
-/* MSI enable bit and maskall bit are in byte 1 in FLAGS register */
-#define MSIX_CONTROL_OFFSET (PCI_MSIX_FLAGS + 1)
-#define MSIX_ENABLE_MASK (PCI_MSIX_FLAGS_ENABLE >> 8)
-#define MSIX_MASKALL_MASK (PCI_MSIX_FLAGS_MASKALL >> 8)
+/* MSI enable bit and maskall bit are in byte 1 in control register */
+#define MSIX_CONTROL_OFFSET (PCI_MSIX_CTRL + 1)
+#define MSIX_ENABLE_MASK (PCI_MSIX_ENABLE >> 8)
+#define MSIX_MASKALL_MASK (PCI_MSIX_MASK >> 8)
 
 /* MSI-X table format */
 #define MSIX_MSG_ADDR 0
@@ -58,8 +55,9 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
     uint8_t *config;
     uint32_t new_size;
 
-    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
+    if (nentries < 1 || nentries > PCI_MSIX_TABSIZE + 1) {
         return -EINVAL;
+    }
     if (bar_size > 0x80000000)
         return -ENOSPC;
 
@@ -80,11 +78,11 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
         return config_offset;
     config = pdev->config + config_offset;
 
-    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    pci_set_word(config + PCI_MSIX_CTRL, nentries - 1);
     /* Table on top of BAR */
-    pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
+    pci_set_long(config + PCI_MSIX_TABLE, bar_size | bar_nr);
     /* Pending bits on top of that */
-    pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+    pci_set_long(config + PCI_MSIX_PBA, (bar_size + MSIX_PAGE_PENDING) |
                  bar_nr);
     pdev->msix_cap = config_offset;
     /* Make flags bit writable. */
@@ -208,11 +206,11 @@ void msix_mmio_map(PCIDevice *d, int region_num,
                    pcibus_t addr, pcibus_t size, int type)
 {
     uint8_t *config = d->config + d->msix_cap;
-    uint32_t table = pci_get_long(config + MSIX_TABLE_OFFSET);
+    uint32_t table = pci_get_long(config + PCI_MSIX_TABLE);
     uint32_t offset = table & ~(MSIX_PAGE_SIZE - 1);
     /* TODO: for assigned devices, we'll want to make it possible to map
      * pending bits separately in case they are in a separate bar. */
-    int table_bir = table & PCI_MSIX_FLAGS_BIRMASK;
+    int table_bir = table & PCI_MSIX_BIR;
 
     if (table_bir != region_num)
         return;
hw/pci_regs.h +8 -6
index 5a5ab89..c17c22f 100644
@@ -300,12 +300,14 @@
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
 #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
 
-/* MSI-X registers (these are at offset PCI_MSIX_FLAGS) */
-#define PCI_MSIX_FLAGS		2
-#define  PCI_MSIX_FLAGS_QSIZE	0x7FF
-#define  PCI_MSIX_FLAGS_ENABLE	(1 << 15)
-#define  PCI_MSIX_FLAGS_MASKALL	(1 << 14)
-#define PCI_MSIX_FLAGS_BIRMASK	(7 << 0)
+/* MSI-X registers */
+#define PCI_MSIX_CTRL           2       /* Message control */
+#define  PCI_MSIX_TABSIZE       0x7FF   /* Table size - 1 */
+#define  PCI_MSIX_MASK          0x4000  /* Mask all vectors */
+#define  PCI_MSIX_ENABLE        0x8000  /* Enable MSI-X */
+#define PCI_MSIX_TABLE          4       /* MSI-X table */
+#define PCI_MSIX_PBA            8       /* Pending bit array */
+#define  PCI_MSIX_BIR           0x7     /* BAR indication register */
 
 /* CompactPCI Hotswap Register */
 
Signature · 1 line
1.7.1
#13 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

Quoted 8 lines
Quoted 1 line

Besides keeping pci_regs.h aligned with the original, I also think ideally pci register banging should stay within the pci subsystem.

Could we add high-level APIs to help with that, instead of having kvm look at config space directly?

We could move the related static inlines from msi/msix.c to the headers in order to test for bits etc. Still, kvm needs to interpret the config space of the assigned device, so the abstraction will remain rather low.

Jan

#14 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Michael S. Tsirkin
Quoted 5 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

Besides keeping pci_regs.h aligned with the original, I also think ideally pci register banging should stay within the pci subsystem.

Quoted 9 lines
Quoted 2 lines

Could we add high-level APIs to help with that, instead of having kvm look at config space directly?

We could move the related static inlines from msi/msix.c to the headers in order to test for bits etc. Still, kvm needs to interpret the config space of the assigned device, so the abstraction will remain rather low.

Jan

Hmm, at least for MSI/MSIX I thought this is done by kvm in kernel?

Signature · 1 line
MST
#15 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Michael S. Tsirkin
Quoted 5 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

Besides keeping pci_regs.h aligned with the original, I also think ideally pci register banging should stay within the pci subsystem.

Could we add high-level APIs to help with that, instead of having kvm look at config space directly?

Quoted 9 lines
Quoted 6 lines

We could move the related static inlines from msi/msix.c to the headers in order to test for bits etc. Still, kvm needs to interpret the config space of the assigned device, so the abstraction will remain rather low.

Jan

Hmm, at least for MSI/MSIX I thought this is done by kvm in kernel?

At least for the "traditional" assignment interface (VFIO may offload something), no. User space does the cap analysis, filtering, and in the MSI/MSI-X case the translation to QEMU msi/msix services. The latter is even WIP in my tree. Surrent assignment open-codes this, missing many corner cases.

Jan

#16 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

Quoted 27 lines · Jan Kiszka
Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Michael S. Tsirkin
Quoted 5 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

Besides keeping pci_regs.h aligned with the original, I also think ideally pci register banging should stay within the pci subsystem.

Could we add high-level APIs to help with that, instead of having kvm look at config space directly?

Quoted 9 lines
Quoted 6 lines

We could move the related static inlines from msi/msix.c to the headers in order to test for bits etc. Still, kvm needs to interpret the config space of the assigned device, so the abstraction will remain rather low.

Jan

Hmm, at least for MSI/MSIX I thought this is done by kvm in kernel?

Quoted 8 lines

At least for the "traditional" assignment interface (VFIO may offload something), no. User space does the cap analysis, filtering, and in the MSI/MSI-X case the translation to QEMU msi/msix services. The latter is even WIP in my tree. Surrent assignment open-codes this, missing many corner cases.

Jan

Anyway, if some defines need to be in a header, and aren't upstream yet, let's create pci_ext_regs.h and add a comment there that we should work on upstreaming them.

Signature · 1 line
MST
#17 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Jan Kiszka
Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Michael S. Tsirkin
Quoted 5 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

Besides keeping pci_regs.h aligned with the original, I also think ideally pci register banging should stay within the pci subsystem.

Could we add high-level APIs to help with that, instead of having kvm look at config space directly?

Quoted 9 lines
Quoted 6 lines

We could move the related static inlines from msi/msix.c to the headers in order to test for bits etc. Still, kvm needs to interpret the config space of the assigned device, so the abstraction will remain rather low.

Jan

Hmm, at least for MSI/MSIX I thought this is done by kvm in kernel?

At least for the "traditional" assignment interface (VFIO may offload something), no. User space does the cap analysis, filtering, and in the MSI/MSI-X case the translation to QEMU msi/msix services. The latter is even WIP in my tree. Surrent assignment open-codes this, missing many corner cases.

Quoted 6 lines
Quoted 2 lines

Jan

Anyway, if some defines need to be in a header, and aren't upstream yet, let's create pci_ext_regs.h and add a comment there that we should work on upstreaming them.

Sounds good. But what is supposed to be upstream for us, the kernel or pci-utils/libpci?

Jan

#18 lore raw

Re: [Qemu-devel] [PATCH v2 8/9] msix: Align MSI-X constants to libpci definitions and extend them

Quoted 38 lines · Jan Kiszka
Quoted 37 lines · Michael S. Tsirkin
Quoted 35 lines · Jan Kiszka
Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · Jan Kiszka
Quoted 13 lines · Michael S. Tsirkin
Quoted 5 lines · Jan Kiszka

Add PCI_MSIX_TABLE and PCI_MSIX_PBA, align other MSIX related constant names to libpci style. Will be used for device assignment code in qemu-kvm.

Besides keeping pci_regs.h aligned with the original, I also think ideally pci register banging should stay within the pci subsystem.

Could we add high-level APIs to help with that, instead of having kvm look at config space directly?

Quoted 9 lines
Quoted 6 lines

We could move the related static inlines from msi/msix.c to the headers in order to test for bits etc. Still, kvm needs to interpret the config space of the assigned device, so the abstraction will remain rather low.

Jan

Hmm, at least for MSI/MSIX I thought this is done by kvm in kernel?

At least for the "traditional" assignment interface (VFIO may offload something), no. User space does the cap analysis, filtering, and in the MSI/MSI-X case the translation to QEMU msi/msix services. The latter is even WIP in my tree. Surrent assignment open-codes this, missing many corner cases.

Jan

Quoted 9 lines
Quoted 3 lines

Anyway, if some defines need to be in a header, and aren't upstream yet, let's create pci_ext_regs.h and add a comment there that we should work on upstreaming them.

Sounds good. But what is supposed to be upstream for us, the kernel or pci-utils/libpci?

Jan

It's currently the kernel, I don't really see a reason to change that.

Signature · 1 line
MST
author
#19 lore raw

PATCH v2 9/9 msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

In reply to Jan Kiszka
---
 hw/msi.c      |    4 ----
 hw/pci_regs.h |    2 ++
 2 files changed, 2 insertions(+), 4 deletions(-)
hw/msi.c +0 -4
index e23f5df..d548939 100644
@@ -21,10 +21,6 @@
 #include "msi.h"
 #include "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_regs.h +2 -0
index c17c22f..002ed2e 100644
@@ -297,8 +297,10 @@
 #define PCI_MSI_ADDRESS_HI	8	/* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
 #define PCI_MSI_DATA_32		8	/* 16 bits of data for 32-bit devices */
 #define PCI_MSI_MASK_32		12	/* Mask bits register for 32-bit devices */
+#define PCI_MSI_PENDING_32      16      /* Pending bits register for 32-bit devices */
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
 #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
+#define PCI_MSI_PENDING_64      20      /* Pending bits register for 64-bit devices */
 
 /* MSI-X registers */
 #define PCI_MSIX_CTRL           2       /* Message control */
Signature · 1 line
1.7.1
#20 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

If you want to move them, please send them upstream we'll merge when they are there.

Quoted 37 lines
---
 hw/msi.c      |    4 ----
 hw/pci_regs.h |    2 ++
 2 files changed, 2 insertions(+), 4 deletions(-)
hw/msi.c +0 -4
index e23f5df..d548939 100644
@@ -21,10 +21,6 @@
 #include "msi.h"
 #include "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_regs.h +2 -0
index c17c22f..002ed2e 100644
@@ -297,8 +297,10 @@
 #define PCI_MSI_ADDRESS_HI	8	/* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
 #define PCI_MSI_DATA_32		8	/* 16 bits of data for 32-bit devices */
 #define PCI_MSI_MASK_32		12	/* Mask bits register for 32-bit devices */
+#define PCI_MSI_PENDING_32      16      /* Pending bits register for 32-bit devices */
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
 #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
+#define PCI_MSI_PENDING_64      20      /* Pending bits register for 64-bit devices */
 
 /* MSI-X registers */
 #define PCI_MSIX_CTRL           2       /* Message control */
Signature · 1 line
1.7.1
#21 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 29 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

Quoted 2 lines

If you want to move them, please send them upstream we'll merge when they are there.

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

Jan

#22 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

Quoted 8 lines
Quoted 2 lines

If you want to move them, please send them upstream we'll merge when they are there.

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

PCI_MSIX_FLAGS is the same.

Quoted 3 lines

Jan

#23 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Jan Kiszka
Quoted 31 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

If you want to move them, please send them upstream we'll merge when they are there.

Quoted 7 lines
Quoted 5 lines

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

PCI_MSIX_FLAGS is the same.

That does not exist in libpci's header.

Jan

#24 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 39 lines · Jan Kiszka
Quoted 38 lines · Michael S. Tsirkin
Quoted 37 lines · Jan Kiszka
Quoted 29 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

Quoted 2 lines

If you want to move them, please send them upstream we'll merge when they are there.

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

PCI_MSIX_FLAGS is the same.

That does not exist in libpci's header.

Jan

The upstream I meant is pci_Regs.h in Linux.

Signature · 1 line
MST
#25 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 42 lines · Michael S. Tsirkin
Quoted 41 lines · Jan Kiszka
Quoted 40 lines · Michael S. Tsirkin
Quoted 38 lines · Jan Kiszka
Quoted 29 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

Quoted 2 lines

If you want to move them, please send them upstream we'll merge when they are there.

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

PCI_MSIX_FLAGS is the same.

That does not exist in libpci's header.

Jan

The upstream I meant is pci_Regs.h in Linux.

Why not sync against
git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git? Sounds more appropriate.

Jan

#26 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 50 lines · Jan Kiszka
Quoted 49 lines · Michael S. Tsirkin
Quoted 47 lines · Jan Kiszka
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Jan Kiszka
Quoted 31 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

If you want to move them, please send them upstream we'll merge when they are there.

Quoted 7 lines
Quoted 5 lines

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

PCI_MSIX_FLAGS is the same.

That does not exist in libpci's header.

Jan

Quoted 9 lines
Quoted 2 lines

The upstream I meant is pci_Regs.h in Linux.

Why not sync against
git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git? Sounds more appropriate.

Jan

We are 100% aligned with Linux changing that seems pointless. I think Linux gets new hardware features faster and has a better chance to be correct.
We already pull headers from Linux so that's one dependency less.

Signature · 1 line
MST
#27 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 58 lines · Michael S. Tsirkin
Quoted 57 lines · Jan Kiszka
Quoted 42 lines · Michael S. Tsirkin
Quoted 41 lines · Jan Kiszka
Quoted 40 lines · Michael S. Tsirkin
Quoted 38 lines · Jan Kiszka
Quoted 29 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

Quoted 2 lines

If you want to move them, please send them upstream we'll merge when they are there.

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

PCI_MSIX_FLAGS is the same.

That does not exist in libpci's header.

Jan

The upstream I meant is pci_Regs.h in Linux.

Why not sync against
git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git? Sounds more appropriate.

Quoted 8 lines
Quoted 2 lines

Jan

We are 100% aligned with Linux changing that seems pointless. I think Linux gets new hardware features faster and has a better chance to be correct.
We already pull headers from Linux so that's one dependency less.

The kernel appears to gain defines based on what it uses. The libpci headers seem to serve more use cases, at least it had the missing fields for several years and is a few hundred lines longer.

Jan

#28 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

Quoted 68 lines · Jan Kiszka
Quoted 58 lines · Michael S. Tsirkin
Quoted 57 lines · Jan Kiszka
Quoted 42 lines · Michael S. Tsirkin
Quoted 41 lines · Jan Kiszka
Quoted 40 lines · Michael S. Tsirkin
Quoted 38 lines · Jan Kiszka
Quoted 29 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

Quoted 2 lines

If you want to move them, please send them upstream we'll merge when they are there.

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

PCI_MSIX_FLAGS is the same.

That does not exist in libpci's header.

Jan

The upstream I meant is pci_Regs.h in Linux.

Why not sync against
git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git? Sounds more appropriate.

Quoted 8 lines
Quoted 2 lines

Jan

We are 100% aligned with Linux changing that seems pointless. I think Linux gets new hardware features faster and has a better chance to be correct.
We already pull headers from Linux so that's one dependency less.

Quoted 3 lines

The kernel appears to gain defines based on what it uses. The libpci headers seem to serve more use cases, at least it had the missing fields for several years and is a few hundred lines longer.

OK, looks like that "added value" comes from merging pci_regs.h with pci_ids.h. Never mind, will work against the kernel.

Jan

#29 lore raw

Re: [Qemu-devel] [PATCH v2 9/9] msi: Move PCI_MSI_PENDING_32/64 into pci_regs.h

In reply to Jan Kiszka
Quoted 62 lines · Jan Kiszka
Quoted 61 lines · Michael S. Tsirkin
Quoted 59 lines · Jan Kiszka
Quoted 42 lines · Michael S. Tsirkin
Quoted 41 lines · Jan Kiszka
Quoted 40 lines · Michael S. Tsirkin
Quoted 38 lines · Jan Kiszka
Quoted 29 lines · Michael S. Tsirkin
Quoted 1 line · Jan Kiszka

pci_regs.h from linux does not have these
this is why we keep them in msi.c

[mst@tuck linux-2.6]$ grep PCI_MSI_ include/linux/pci_regs.h

#define PCI_MSI_FLAGS           2       /* Various flags */
#define  PCI_MSI_FLAGS_64BIT    0x80    /* 64-bit addresses allowed */
#define  PCI_MSI_FLAGS_QSIZE    0x70    /* Message queue size configured
*/
#define  PCI_MSI_FLAGS_QMASK    0x0e    /* Maximum queue size available
*/
#define  PCI_MSI_FLAGS_ENABLE   0x01    /* MSI feature enabled */
#define  PCI_MSI_FLAGS_MASKBIT  0x100   /* 64-bit mask bits allowed */
#define PCI_MSI_RFU             3       /* Rest of capability flags */
#define PCI_MSI_ADDRESS_LO      4       /* Lower 32 bits */
#define PCI_MSI_ADDRESS_HI      8       /* Upper 32 bits (if

PCI_MSI_FLAGS_64BIT set) */
#define PCI_MSI_DATA_32 8 /* 16 bits of data for 32-bit
devices */
#define PCI_MSI_MASK_32 12 /* Mask bits register for 32-bit
devices */
#define PCI_MSI_DATA_64 12 /* 16 bits of data for 64-bit
devices */
#define PCI_MSI_MASK_64 16 /* Mask bits register for 64-bit
devices */

Quoted 2 lines

If you want to move them, please send them upstream we'll merge when they are there.

In fact, both defines are already in libpci. Since 3.0.0. Released 5 years ago. OK, I'll send a header resync patch against a more recent release.

Then we should just lack something like PCI_MSIX_CTRL. I will have a look.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

PCI_MSIX_FLAGS is the same.

That does not exist in libpci's header.

Jan

The upstream I meant is pci_Regs.h in Linux.

Why not sync against
git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git? Sounds more appropriate.

Jan

Quoted 7 lines
Quoted 5 lines

We are 100% aligned with Linux changing that seems pointless. I think Linux gets new hardware features faster and has a better chance to be correct.
We already pull headers from Linux so that's one dependency less.

The kernel appears to gain defines based on what it uses.

I don't expect trouble adding stuff we might need though.

Quoted 6 lines

The libpci
headers seem to serve more use cases, at least it had the missing fields for several years and is a few hundred lines longer.

Jan

Some defines got into Linux already, specifically
MSIX_TABLE_OFFSET, MSIX_PBA_OFFSET
(with different names)

Signature · 1 line
MST