All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Will Deacon <will@kernel.org>,
	Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: Alexandru Elisei <alexandru.elisei@arm.com>,
	kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu
Subject: [PATCH kvmtool v4 6/5] pci: Move legacy IRQ assignment into devices
Date: Fri, 24 Apr 2020 16:17:02 +0100	[thread overview]
Message-ID: <20200424151702.4750-1-andre.przywara@arm.com> (raw)

So far the (legacy) IRQ line for a PCI device is allocated in devices.c,
which should actually not take care of that. Since we allocate all other
device specific resources in the actual device emulation code, the IRQ
should not be something special.

Remove the PCI specific code from devices.c, and move the IRQ line
allocation to the PCI code.
This drops the IRQ line from the VESA device, since it does not use one.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Hi Will,

this is the patch I mentioned earlier today. Briefly tested on x86 with
the VESA device and on a Juno.

Cheers,
Andre

 devices.c         | 9 ---------
 include/kvm/pci.h | 2 +-
 pci.c             | 6 +++---
 vfio/pci.c        | 2 ++
 virtio/pci.c      | 5 ++---
 5 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/devices.c b/devices.c
index 2c8b2665..41cffdd7 100644
--- a/devices.c
+++ b/devices.c
@@ -1,6 +1,5 @@
 #include "kvm/devices.h"
 #include "kvm/kvm.h"
-#include "kvm/pci.h"
 
 #include <linux/err.h>
 #include <linux/rbtree.h>
@@ -28,14 +27,6 @@ int device__register(struct device_header *dev)
 	bus = &device_trees[dev->bus_type];
 	dev->dev_num = bus->dev_num++;
 
-	switch (dev->bus_type) {
-	case DEVICE_BUS_PCI:
-		pci__assign_irq(dev);
-		break;
-	default:
-		break;
-	}
-
 	node = &bus->root.rb_node;
 	while (*node) {
 		int num = rb_entry(*node, struct device_header, node)->dev_num;
diff --git a/include/kvm/pci.h b/include/kvm/pci.h
index ccb155e3..2c29c094 100644
--- a/include/kvm/pci.h
+++ b/include/kvm/pci.h
@@ -155,7 +155,7 @@ int pci__exit(struct kvm *kvm);
 struct pci_device_header *pci__find_dev(u8 dev_num);
 u32 pci_get_mmio_block(u32 size);
 u16 pci_get_io_port_block(u32 size);
-void pci__assign_irq(struct device_header *dev_hdr);
+int pci__assign_irq(struct pci_device_header *pci_hdr);
 void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, int size);
 void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data, int size);
 
diff --git a/pci.c b/pci.c
index b6892d97..3ecdd0f9 100644
--- a/pci.c
+++ b/pci.c
@@ -49,10 +49,8 @@ void *pci_find_cap(struct pci_device_header *hdr, u8 cap_type)
 	return NULL;
 }
 
-void pci__assign_irq(struct device_header *dev_hdr)
+int pci__assign_irq(struct pci_device_header *pci_hdr)
 {
-	struct pci_device_header *pci_hdr = dev_hdr->data;
-
 	/*
 	 * PCI supports only INTA#,B#,C#,D# per device.
 	 *
@@ -64,6 +62,8 @@ void pci__assign_irq(struct device_header *dev_hdr)
 
 	if (!pci_hdr->irq_type)
 		pci_hdr->irq_type = IRQ_TYPE_EDGE_RISING;
+
+	return pci_hdr->irq_line;
 }
 
 static void *pci_config_address_ptr(u16 port)
diff --git a/vfio/pci.c b/vfio/pci.c
index 4412c6d7..7c2ea10c 100644
--- a/vfio/pci.c
+++ b/vfio/pci.c
@@ -1212,6 +1212,8 @@ static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev
 	}
 
 	if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) {
+		pci__assign_irq(&vdev->pci.hdr);
+
 		ret = vfio_pci_init_intx(kvm, vdev);
 		if (ret)
 			return ret;
diff --git a/virtio/pci.c b/virtio/pci.c
index 281c3181..c6529493 100644
--- a/virtio/pci.c
+++ b/virtio/pci.c
@@ -524,13 +524,12 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
 	if (irq__can_signal_msi(kvm))
 		vpci->features |= VIRTIO_PCI_F_SIGNAL_MSI;
 
+	vpci->legacy_irq_line = pci__assign_irq(&vpci->pci_hdr);
+
 	r = device__register(&vpci->dev_hdr);
 	if (r < 0)
 		goto free_msix_mmio;
 
-	/* save the IRQ that device__register() has allocated */
-	vpci->legacy_irq_line = vpci->pci_hdr.irq_line;
-
 	return 0;
 
 free_msix_mmio:
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: Andre Przywara <andre.przywara@arm.com>
To: Will Deacon <will@kernel.org>,
	Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Subject: [PATCH kvmtool v4 6/5] pci: Move legacy IRQ assignment into devices
Date: Fri, 24 Apr 2020 16:17:02 +0100	[thread overview]
Message-ID: <20200424151702.4750-1-andre.przywara@arm.com> (raw)

So far the (legacy) IRQ line for a PCI device is allocated in devices.c,
which should actually not take care of that. Since we allocate all other
device specific resources in the actual device emulation code, the IRQ
should not be something special.

Remove the PCI specific code from devices.c, and move the IRQ line
allocation to the PCI code.
This drops the IRQ line from the VESA device, since it does not use one.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Hi Will,

this is the patch I mentioned earlier today. Briefly tested on x86 with
the VESA device and on a Juno.

Cheers,
Andre

 devices.c         | 9 ---------
 include/kvm/pci.h | 2 +-
 pci.c             | 6 +++---
 vfio/pci.c        | 2 ++
 virtio/pci.c      | 5 ++---
 5 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/devices.c b/devices.c
index 2c8b2665..41cffdd7 100644
--- a/devices.c
+++ b/devices.c
@@ -1,6 +1,5 @@
 #include "kvm/devices.h"
 #include "kvm/kvm.h"
-#include "kvm/pci.h"
 
 #include <linux/err.h>
 #include <linux/rbtree.h>
@@ -28,14 +27,6 @@ int device__register(struct device_header *dev)
 	bus = &device_trees[dev->bus_type];
 	dev->dev_num = bus->dev_num++;
 
-	switch (dev->bus_type) {
-	case DEVICE_BUS_PCI:
-		pci__assign_irq(dev);
-		break;
-	default:
-		break;
-	}
-
 	node = &bus->root.rb_node;
 	while (*node) {
 		int num = rb_entry(*node, struct device_header, node)->dev_num;
diff --git a/include/kvm/pci.h b/include/kvm/pci.h
index ccb155e3..2c29c094 100644
--- a/include/kvm/pci.h
+++ b/include/kvm/pci.h
@@ -155,7 +155,7 @@ int pci__exit(struct kvm *kvm);
 struct pci_device_header *pci__find_dev(u8 dev_num);
 u32 pci_get_mmio_block(u32 size);
 u16 pci_get_io_port_block(u32 size);
-void pci__assign_irq(struct device_header *dev_hdr);
+int pci__assign_irq(struct pci_device_header *pci_hdr);
 void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, int size);
 void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data, int size);
 
diff --git a/pci.c b/pci.c
index b6892d97..3ecdd0f9 100644
--- a/pci.c
+++ b/pci.c
@@ -49,10 +49,8 @@ void *pci_find_cap(struct pci_device_header *hdr, u8 cap_type)
 	return NULL;
 }
 
-void pci__assign_irq(struct device_header *dev_hdr)
+int pci__assign_irq(struct pci_device_header *pci_hdr)
 {
-	struct pci_device_header *pci_hdr = dev_hdr->data;
-
 	/*
 	 * PCI supports only INTA#,B#,C#,D# per device.
 	 *
@@ -64,6 +62,8 @@ void pci__assign_irq(struct device_header *dev_hdr)
 
 	if (!pci_hdr->irq_type)
 		pci_hdr->irq_type = IRQ_TYPE_EDGE_RISING;
+
+	return pci_hdr->irq_line;
 }
 
 static void *pci_config_address_ptr(u16 port)
diff --git a/vfio/pci.c b/vfio/pci.c
index 4412c6d7..7c2ea10c 100644
--- a/vfio/pci.c
+++ b/vfio/pci.c
@@ -1212,6 +1212,8 @@ static int vfio_pci_configure_dev_irqs(struct kvm *kvm, struct vfio_device *vdev
 	}
 
 	if (pdev->irq_modes & VFIO_PCI_IRQ_MODE_INTX) {
+		pci__assign_irq(&vdev->pci.hdr);
+
 		ret = vfio_pci_init_intx(kvm, vdev);
 		if (ret)
 			return ret;
diff --git a/virtio/pci.c b/virtio/pci.c
index 281c3181..c6529493 100644
--- a/virtio/pci.c
+++ b/virtio/pci.c
@@ -524,13 +524,12 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
 	if (irq__can_signal_msi(kvm))
 		vpci->features |= VIRTIO_PCI_F_SIGNAL_MSI;
 
+	vpci->legacy_irq_line = pci__assign_irq(&vpci->pci_hdr);
+
 	r = device__register(&vpci->dev_hdr);
 	if (r < 0)
 		goto free_msix_mmio;
 
-	/* save the IRQ that device__register() has allocated */
-	vpci->legacy_irq_line = vpci->pci_hdr.irq_line;
-
 	return 0;
 
 free_msix_mmio:
-- 
2.17.1

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

             reply	other threads:[~2020-04-24 15:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24 15:17 Andre Przywara [this message]
2020-04-24 15:17 ` [PATCH kvmtool v4 6/5] pci: Move legacy IRQ assignment into devices Andre Przywara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200424151702.4750-1-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.