All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zha Bin <zhabin@linux.alibaba.com>
To: linux-kernel@vger.kernel.org
Cc: mst@redhat.com, jasowang@redhat.com, slp@redhat.com,
	virtio-dev@lists.oasis-open.org, gerry@linux.alibaba.com,
	zhabin@linux.alibaba.com, jing2.liu@intel.com,
	chao.p.peng@intel.com
Subject: [PATCH v1 1/2] x86/msi: Enhance x86 to support platform_msi
Date: Wed, 25 Dec 2019 10:50:22 +0800	[thread overview]
Message-ID: <c0919551d21bf519b05e00e6a924cbde95c5df32.1577240905.git.zhabin@linux.alibaba.com> (raw)
In-Reply-To: <cover.1577240905.git.zhabin@linux.alibaba.com>
In-Reply-To: <cover.1577240905.git.zhabin@linux.alibaba.com>

From: Liu Jiang <gerry@linux.alibaba.com>

The x86 platform currently only supports specific MSI/MSI-x for PCI
devices. To enable MSI to the platform devices such as virtio-mmio
device, this patch enhances x86 with platform MSI by leveraging the
already built-in platform-msi driver (drivers/base/platform-msi.c)
and makes it as a configurable option.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Zha Bin <zhabin@linux.alibaba.com>
Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
Signed-off-by: Jing Liu <jing2.liu@linux.intel.com>
---
 arch/x86/Kconfig                 |  6 ++++
 arch/x86/include/asm/hw_irq.h    |  5 +++
 arch/x86/include/asm/irqdomain.h |  9 +++++
 arch/x86/kernel/apic/msi.c       | 74 ++++++++++++++++++++++++++++++++++++++++
 drivers/base/platform-msi.c      |  4 +--
 include/linux/msi.h              |  1 +
 6 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 5e89499..c1178f2 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1074,6 +1074,12 @@ config X86_IO_APIC
 	def_bool y
 	depends on X86_LOCAL_APIC || X86_UP_IOAPIC
 
+config X86_PLATFORM_MSI
+	def_bool y
+	depends on X86_LOCAL_APIC && X86_64
+	select GENERIC_MSI_IRQ
+	select GENERIC_MSI_IRQ_DOMAIN
+
 config X86_REROUTE_FOR_BROKEN_BOOT_IRQS
 	bool "Reroute for broken boot IRQs"
 	depends on X86_IO_APIC
diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
index 4154bc5..5c96b49 100644
--- a/arch/x86/include/asm/hw_irq.h
+++ b/arch/x86/include/asm/hw_irq.h
@@ -113,6 +113,11 @@ struct irq_alloc_info {
 			struct msi_desc *desc;
 		};
 #endif
+#ifdef CONFIG_X86_PLATFORM_MSI
+		struct {
+			irq_hw_number_t	platform_msi_hwirq;
+		};
+#endif
 	};
 };
 
diff --git a/arch/x86/include/asm/irqdomain.h b/arch/x86/include/asm/irqdomain.h
index c066ffa..b53f51f 100644
--- a/arch/x86/include/asm/irqdomain.h
+++ b/arch/x86/include/asm/irqdomain.h
@@ -56,4 +56,13 @@ extern void mp_irqdomain_deactivate(struct irq_domain *domain,
 static inline void arch_init_msi_domain(struct irq_domain *domain) { }
 #endif
 
+#ifdef CONFIG_X86_PLATFORM_MSI
+extern struct irq_domain *platform_msi_get_def_irq_domain(void);
+#else
+static inline struct irq_domain *platform_msi_get_def_irq_domain(void)
+{
+	return NULL;
+}
+#endif
+
 #endif
diff --git a/arch/x86/kernel/apic/msi.c b/arch/x86/kernel/apic/msi.c
index 7f75334..ef558c7 100644
--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -22,6 +22,10 @@
 #include <asm/irq_remapping.h>
 
 static struct irq_domain *msi_default_domain;
+#ifdef CONFIG_X86_PLATFORM_MSI
+static struct irq_domain *platform_msi_default_domain;
+static struct msi_domain_info platform_msi_domain_info;
+#endif
 
 static void irq_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
 {
@@ -146,6 +150,17 @@ void __init arch_init_msi_domain(struct irq_domain *parent)
 	}
 	if (!msi_default_domain)
 		pr_warn("failed to initialize irqdomain for MSI/MSI-x.\n");
+#ifdef CONFIG_X86_PLATFORM_MSI
+	fn = irq_domain_alloc_named_fwnode("PLATFORM-MSI");
+	if (fn) {
+		platform_msi_default_domain =
+			platform_msi_create_irq_domain(fn,
+				&platform_msi_domain_info, parent);
+		irq_domain_free_fwnode(fn);
+	}
+	if (!platform_msi_default_domain)
+		pr_warn("failed to initialize irqdomain for PLATFORM-MSI.\n");
+#endif
 }
 
 #ifdef CONFIG_IRQ_REMAP
@@ -384,3 +399,62 @@ int hpet_assign_irq(struct irq_domain *domain, struct hpet_channel *hc,
 	return irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, &info);
 }
 #endif
+
+#ifdef CONFIG_X86_PLATFORM_MSI
+static void platform_msi_mask_irq(struct irq_data *data)
+{
+}
+
+static void platform_msi_unmask_irq(struct irq_data *data)
+{
+}
+
+static struct irq_chip platform_msi_controller = {
+	.name			= "PLATFORM-MSI",
+	.irq_mask		= platform_msi_mask_irq,
+	.irq_unmask		= platform_msi_unmask_irq,
+	.irq_ack		= irq_chip_ack_parent,
+	.irq_retrigger		= irq_chip_retrigger_hierarchy,
+	.irq_compose_msi_msg	= irq_msi_compose_msg,
+	.flags			= IRQCHIP_SKIP_SET_WAKE,
+};
+
+static int platform_msi_prepare(struct irq_domain *domain, struct device *dev,
+				int nvec, msi_alloc_info_t *arg)
+{
+	memset(arg, 0, sizeof(*arg));
+	return 0;
+}
+
+static void platform_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc)
+{
+	arg->platform_msi_hwirq = platform_msi_calc_hwirq(desc);
+}
+
+static irq_hw_number_t platform_msi_get_hwirq(struct msi_domain_info *info,
+					      msi_alloc_info_t *arg)
+{
+	return arg->platform_msi_hwirq;
+}
+
+static struct msi_domain_ops platform_msi_domain_ops = {
+	.msi_prepare	= platform_msi_prepare,
+	.set_desc	= platform_msi_set_desc,
+	.get_hwirq	= platform_msi_get_hwirq,
+};
+
+static struct msi_domain_info platform_msi_domain_info = {
+	.flags          = MSI_FLAG_USE_DEF_DOM_OPS |
+			  MSI_FLAG_USE_DEF_CHIP_OPS |
+			  MSI_FLAG_ACTIVATE_EARLY,
+	.ops            = &platform_msi_domain_ops,
+	.chip           = &platform_msi_controller,
+	.handler        = handle_edge_irq,
+	.handler_name   = "edge",
+};
+
+struct irq_domain *platform_msi_get_def_irq_domain(void)
+{
+	return platform_msi_default_domain;
+}
+#endif
diff --git a/drivers/base/platform-msi.c b/drivers/base/platform-msi.c
index 8da314b..45752f1 100644
--- a/drivers/base/platform-msi.c
+++ b/drivers/base/platform-msi.c
@@ -31,12 +31,11 @@ struct platform_msi_priv_data {
 /* The devid allocator */
 static DEFINE_IDA(platform_msi_devid_ida);
 
-#ifdef GENERIC_MSI_DOMAIN_OPS
 /*
  * Convert an msi_desc to a globaly unique identifier (per-device
  * devid + msi_desc position in the msi_list).
  */
-static irq_hw_number_t platform_msi_calc_hwirq(struct msi_desc *desc)
+irq_hw_number_t platform_msi_calc_hwirq(struct msi_desc *desc)
 {
 	u32 devid;
 
@@ -45,6 +44,7 @@ static irq_hw_number_t platform_msi_calc_hwirq(struct msi_desc *desc)
 	return (devid << (32 - DEV_ID_SHIFT)) | desc->platform.msi_index;
 }
 
+#ifdef GENERIC_MSI_DOMAIN_OPS
 static void platform_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc)
 {
 	arg->desc = desc;
diff --git a/include/linux/msi.h b/include/linux/msi.h
index 8ad679e..ee5f566 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -362,6 +362,7 @@ int platform_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
 void platform_msi_domain_free(struct irq_domain *domain, unsigned int virq,
 			      unsigned int nvec);
 void *platform_msi_get_host_data(struct irq_domain *domain);
+irq_hw_number_t platform_msi_calc_hwirq(struct msi_desc *desc);
 #endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */
 
 #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
-- 
1.8.3.1


  reply	other threads:[~2019-12-25  2:51 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-25  2:50 [PATCH v1 0/2] support virtio mmio specification Version 3 Zha Bin
2019-12-25  2:50 ` Zha Bin [this message]
2019-12-26  8:21   ` [PATCH v1 1/2] x86/msi: Enhance x86 to support platform_msi Jason Wang
2019-12-26  8:21     ` [virtio-dev] " Jason Wang
2020-01-17 13:58   ` Thomas Gleixner
2020-01-17 14:06     ` Liu, Jiang
2020-01-19  2:27     ` Liu, Jing2
2020-01-19  2:27       ` [virtio-dev] " Liu, Jing2
2020-01-19 14:57       ` Thomas Gleixner
2019-12-25  2:50 ` [PATCH v1 2/2] virtio-mmio: add features for virtio-mmio specification version 3 Zha Bin
2019-12-25 10:20   ` Jason Wang
2019-12-25 10:20     ` [virtio-dev] " Jason Wang
2019-12-25 15:20     ` Liu, Jiang
2019-12-26  8:09       ` Jason Wang
2019-12-26  8:09         ` [virtio-dev] " Jason Wang
2019-12-26 12:35         ` Liu, Jiang
2019-12-26 13:16         ` Liu, Jiang
2020-01-02  6:28           ` Jason Wang
2020-01-02  6:28             ` [virtio-dev] " Jason Wang
2020-01-03  6:50             ` Liu, Jiang
2020-01-05 10:42           ` Michael S. Tsirkin
2020-01-05 10:42             ` [virtio-dev] " Michael S. Tsirkin
2020-01-06  7:24             ` Liu, Jing2
2020-01-06  7:24               ` [virtio-dev] " Liu, Jing2
2020-01-09 16:06             ` Liu, Jiang
2020-01-09 16:47               ` Michael S. Tsirkin
2020-01-09 16:47                 ` [virtio-dev] " Michael S. Tsirkin
2019-12-25 22:28   ` kbuild test robot
2019-12-25 22:28     ` kbuild test robot
2019-12-26  1:44   ` kbuild test robot
2019-12-26  1:44     ` kbuild test robot
2019-12-26  8:40   ` Jason Wang
2019-12-26  8:40     ` [virtio-dev] " Jason Wang
2019-12-27  9:37     ` Liu, Jing2
2019-12-27  9:37       ` Liu, Jing2
2020-01-02  6:33       ` Jason Wang
2020-01-02  6:33         ` Jason Wang
2020-01-02  9:13         ` Liu, Jing2
2020-01-02  9:13           ` Liu, Jing2
2020-01-03  3:24           ` Jason Wang
2020-01-03  3:24             ` Jason Wang
2020-01-03  6:14             ` Liu, Jiang
2020-01-03  9:12               ` Jason Wang
2020-01-03  9:12                 ` Jason Wang
2020-01-05 11:25                 ` Michael S. Tsirkin
2020-01-05 11:25                   ` Michael S. Tsirkin
2020-01-06  2:51                   ` Jason Wang
2020-01-06  2:51                     ` Jason Wang
2020-01-05 11:04   ` Michael S. Tsirkin
2020-01-05 11:04     ` [virtio-dev] " Michael S. Tsirkin
2020-01-09  6:15     ` Liu, Jing2
2020-01-09  6:15       ` [virtio-dev] " Liu, Jing2
2020-01-09 13:26       ` Michael S. Tsirkin
2020-01-09 13:26         ` [virtio-dev] " Michael S. Tsirkin
2020-01-15  7:06     ` Liu, Jing2
2020-01-15  7:06       ` [virtio-dev] " Liu, Jing2
2020-01-21  5:03     ` Liu, Jing2
2020-01-21  5:03       ` Liu, Jing2
2020-01-02  6:55 ` [PATCH v1 0/2] support virtio mmio specification Version 3 Jason Wang
2020-01-02  6:55   ` [virtio-dev] " Jason Wang

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=c0919551d21bf519b05e00e6a924cbde95c5df32.1577240905.git.zhabin@linux.alibaba.com \
    --to=zhabin@linux.alibaba.com \
    --cc=chao.p.peng@intel.com \
    --cc=gerry@linux.alibaba.com \
    --cc=jasowang@redhat.com \
    --cc=jing2.liu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=slp@redhat.com \
    --cc=virtio-dev@lists.oasis-open.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.