From 957d8d1d06fa15e1db50166d17a4fe9094f7fec3 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 23 Oct 2019 11:04:21 +0100 Subject: libqos: add MSI-X callbacks to QVirtioPCIDevice The MSI-X vectors are programmed differently in the VIRTIO 1.0 and Legacy interfaces. Introduce callbacks so different implementations can be used depending on the interface version. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth Message-Id: <20191023100425.12168-13-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/libqos/virtio-pci.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/libqos/virtio-pci.h') diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 728b4715f1..4299efc023 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -14,16 +14,28 @@ #include "libqos/pci.h" #include "libqos/qgraph.h" +typedef struct QVirtioPCIMSIXOps QVirtioPCIMSIXOps; + typedef struct QVirtioPCIDevice { QOSGraphObject obj; QVirtioDevice vdev; QPCIDevice *pdev; QPCIBar bar; + const QVirtioPCIMSIXOps *msix_ops; uint16_t config_msix_entry; uint64_t config_msix_addr; uint32_t config_msix_data; } QVirtioPCIDevice; +struct QVirtioPCIMSIXOps { + /* Set the Configuration Vector for MSI-X */ + void (*set_config_vector)(QVirtioPCIDevice *d, uint16_t entry); + + /* Set the Queue Vector for MSI-X */ + void (*set_queue_vector)(QVirtioPCIDevice *d, uint16_t vq_idx, + uint16_t entry); +}; + typedef struct QVirtQueuePCI { QVirtQueue vq; uint16_t msix_entry; -- cgit v1.2.3 From e56536bc8b897efdf069c25e68202e521cdcbb49 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 23 Oct 2019 11:04:22 +0100 Subject: libqos: expose common virtqueue setup/cleanup functions The VIRTIO 1.0 code will need to perform additional steps but it will reuse the common virtqueue setup/cleanup code. Make these functions public. Make sure to invoke callbacks via QVirtioBus instead of directly calling the virtio-pci Legacy versions of these functions. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth Message-Id: <20191023100425.12168-14-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/libqos/virtio-pci.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/libqos/virtio-pci.h') diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 4299efc023..0e4a8b7b00 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -65,4 +65,12 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d, QGuestAllocator *alloc, uint16_t entry); void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci, QGuestAllocator *alloc, uint16_t entry); + +/* Used by Legacy and Modern virtio-pci code */ +QVirtQueue *qvirtio_pci_virtqueue_setup_common(QVirtioDevice *d, + QGuestAllocator *alloc, + uint16_t index); +void qvirtio_pci_virtqueue_cleanup_common(QVirtQueue *vq, + QGuestAllocator *alloc); + #endif -- cgit v1.2.3 From f17429e545dae46fbe85eebd89fec4e720a1e241 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 23 Oct 2019 11:04:23 +0100 Subject: libqos: make the virtio-pci BAR index configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Legacy virtio-pci interface always uses BAR 0. VIRTIO 1.0 may need to use a different BAR index, so make it configurable. Signed-off-by: Stefan Hajnoczi Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20191023100425.12168-15-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/libqos/virtio-pci.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/libqos/virtio-pci.h') diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 0e4a8b7b00..78a1c15c2a 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -25,6 +25,8 @@ typedef struct QVirtioPCIDevice { uint16_t config_msix_entry; uint64_t config_msix_addr; uint32_t config_msix_data; + + int bar_idx; } QVirtioPCIDevice; struct QVirtioPCIMSIXOps { -- cgit v1.2.3 From 9598f9e4023cc4b0f1f4c4964e4d0debc30cc77c Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 23 Oct 2019 11:04:24 +0100 Subject: libqos: extract Legacy virtio-pci.c code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current libqos virtio-pci.c code implements the VIRTIO Legacy interface. Extract existing code in preparation for VIRTIO 1.0 support. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20191023100425.12168-16-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/libqos/virtio-pci.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/libqos/virtio-pci.h') diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 78a1c15c2a..6b3a385b06 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -45,8 +45,6 @@ typedef struct QVirtQueuePCI { uint32_t msix_data; } QVirtQueuePCI; -extern const QVirtioBus qvirtio_pci; - void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * addr); QVirtioPCIDevice *virtio_pci_new(QPCIBus *bus, QPCIAddress * addr); -- cgit v1.2.3 From d08f68b8e858fc761e88ae66349b6eab1235e3fe Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 23 Oct 2019 11:04:25 +0100 Subject: libqos: add VIRTIO PCI 1.0 support Implement the VIRTIO 1.0 virtio-pci interface. The main change here is that the register layout is no longer a fixed layout in BAR 0. Instead we have to iterate of PCI Capabilities to find descriptions of where various registers are located. The vring registers are also more fine-grained, allowing for more flexible vring layouts, but we don't take advantage of that. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Message-Id: <20191023100425.12168-17-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Thomas Huth --- tests/libqos/virtio-pci.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/libqos/virtio-pci.h') diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 6b3a385b06..294d5567ee 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -27,6 +27,13 @@ typedef struct QVirtioPCIDevice { uint32_t config_msix_data; int bar_idx; + + /* VIRTIO 1.0 */ + uint32_t common_cfg_offset; + uint32_t notify_cfg_offset; + uint32_t notify_off_multiplier; + uint32_t isr_cfg_offset; + uint32_t device_cfg_offset; } QVirtioPCIDevice; struct QVirtioPCIMSIXOps { @@ -43,6 +50,9 @@ typedef struct QVirtQueuePCI { uint16_t msix_entry; uint64_t msix_addr; uint32_t msix_data; + + /* VIRTIO 1.0 */ + uint64_t notify_offset; } QVirtQueuePCI; void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * addr); -- cgit v1.2.3