Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8271574ybl; Tue, 24 Dec 2019 18:52:55 -0800 (PST) X-Google-Smtp-Source: APXvYqw3iJzNiRyiizyOexfy4bA/JqRxgdGlG2bcWs1YScD34WhEbSVAjs/AlQsvUYPMC7akwkTH X-Received: by 2002:a05:6830:139a:: with SMTP id d26mr43344245otq.75.1577242375603; Tue, 24 Dec 2019 18:52:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577242375; cv=none; d=google.com; s=arc-20160816; b=UlZQX5K2ouar4p+g0wnS8HZ8ijY17ZaQbxserFaOZ63O8KsG3UXVL8QlFE6TNppRRl JXGP0IduoBuilWrQjdVAPx2EZiY619Ur2uFpMpOiF+r5nIPPhGYssILcDiDTzXrhofDu 9CVEYEIK8Wk241fMjAGd3gdVaavtQW7TQuh0Ymj2z+jMJLCREtqwVss+fk3PTyBodwNn X4Xpi5cq0+1EwqgViP1bw1c6epvz/TYMtEk0XapxGL480AL74NEQnW15030g0jt20Dk3 S70a+vnShXEjDBFo+2Yf7+4kdYKcHvS4jNCLeZAO6UxUKKplkfTA/1nyp7r9rwQC0sSh VmWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from; bh=dppGHd/r7xtdsn7fEAA2/ZeHLr3w6gYbG7ZuwImeHLQ=; b=hs5hhGzZOvhvPzikk7BuHXT5DW1Z57wjFzhm/MfPH5fvtj/MbXk7FMuVMKBMbNejAX UTre4vGIfmrBmnChvi9GVjv0QsE+6XYwszfmyvswK2rNryMqaWPLGn+mr5RAFhlR/HUu 6+AQO5LlWNWqVm1ctZnksYKN6ve+e2EoeF98OlsoTB7asGkd2Lsj3O9EzBEREFWssOkA xW6V40dKTQ1snEpiMEiEGD8qGE11pB6vtPVEehuoU9d5kEknRoozMR6eWneX9ZTNqrba sYr2/UlOJ4uli7s2EDRFq/q3aChgRsjQbh8iTiLm0bYbk0N/8KnkE2/mjwioM0q+TLT4 e3dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si12515230oia.264.2019.12.24.18.52.28; Tue, 24 Dec 2019 18:52:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726388AbfLYCvI (ORCPT + 99 others); Tue, 24 Dec 2019 21:51:08 -0500 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:55169 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726298AbfLYCvI (ORCPT ); Tue, 24 Dec 2019 21:51:08 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R751e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04446;MF=zhabin@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0Tlrvy-n_1577242264; Received: from localhost(mailfrom:zhabin@linux.alibaba.com fp:SMTPD_---0Tlrvy-n_1577242264) by smtp.aliyun-inc.com(127.0.0.1); Wed, 25 Dec 2019 10:51:04 +0800 From: Zha Bin 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 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liu Jiang 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 Signed-off-by: Zha Bin Signed-off-by: Chao Peng Signed-off-by: Jing Liu --- 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 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