From: Inochi Amaoto <inochiama@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Bjorn Helgaas <bhelgaas@google.com>,
Marc Zyngier <maz@kernel.org>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
Shradha Gupta <shradhagupta@linux.microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Inochi Amaoto <inochiama@gmail.com>,
Jonathan Cameron <Jonathan.Cameron@huwei.com>,
Juergen Gross <jgross@suse.com>,
Nicolin Chen <nicolinc@nvidia.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
Chen Wang <unicorn_wang@outlook.com>
Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
Yixun Lan <dlan@gentoo.org>, Longbin Li <looong.bin@gmail.com>
Subject: [PATCH v2 2/4] PCI/MSI: Add startup/shutdown for per device domains
Date: Thu, 14 Aug 2025 07:28:32 +0800 [thread overview]
Message-ID: <20250813232835.43458-3-inochiama@gmail.com> (raw)
In-Reply-To: <20250813232835.43458-1-inochiama@gmail.com>
As the RISC-V PLIC can not apply affinity setting without calling
irq_enable(), it will make the interrupt unavailble when using as
an underlying IRQ chip for MSI controller.
Implement .irq_startup() and .irq_shutdown() for the PCI MSI and
MSI-X templates. For chips that specify MSI_FLAG_PCI_MSI_STARTUP_PARENT,
these startup and shutdown the parent as well, which allows the
irq on the parent chip to be enabled if the irq is not enabled
when allocating. This is necessary for the MSI controllers which
use PLIC as underlying IRQ chip.
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
drivers/pci/msi/irqdomain.c | 52 +++++++++++++++++++++++++++++++++++++
include/linux/msi.h | 2 ++
2 files changed, 54 insertions(+)
diff --git a/drivers/pci/msi/irqdomain.c b/drivers/pci/msi/irqdomain.c
index 0938ef7ebabf..e0a800f918e8 100644
--- a/drivers/pci/msi/irqdomain.c
+++ b/drivers/pci/msi/irqdomain.c
@@ -148,6 +148,23 @@ static void pci_device_domain_set_desc(msi_alloc_info_t *arg, struct msi_desc *d
arg->hwirq = desc->msi_index;
}
+static void cond_shutdown_parent(struct irq_data *data)
+{
+ struct msi_domain_info *info = data->domain->host_data;
+
+ if (unlikely(info->flags & MSI_FLAG_PCI_MSI_STARTUP_PARENT))
+ irq_chip_shutdown_parent(data);
+}
+
+static unsigned int cond_startup_parent(struct irq_data *data)
+{
+ struct msi_domain_info *info = data->domain->host_data;
+
+ if (unlikely(info->flags & MSI_FLAG_PCI_MSI_STARTUP_PARENT))
+ return irq_chip_startup_parent(data);
+ return 0;
+}
+
static __always_inline void cond_mask_parent(struct irq_data *data)
{
struct msi_domain_info *info = data->domain->host_data;
@@ -164,6 +181,23 @@ static __always_inline void cond_unmask_parent(struct irq_data *data)
irq_chip_unmask_parent(data);
}
+static void pci_irq_shutdown_msi(struct irq_data *data)
+{
+ struct msi_desc *desc = irq_data_get_msi_desc(data);
+
+ pci_msi_mask(desc, BIT(data->irq - desc->irq));
+ cond_shutdown_parent(data);
+}
+
+static unsigned int pci_irq_startup_msi(struct irq_data *data)
+{
+ struct msi_desc *desc = irq_data_get_msi_desc(data);
+ unsigned int ret = cond_startup_parent(data);
+
+ pci_msi_unmask(desc, BIT(data->irq - desc->irq));
+ return ret;
+}
+
static void pci_irq_mask_msi(struct irq_data *data)
{
struct msi_desc *desc = irq_data_get_msi_desc(data);
@@ -194,6 +228,8 @@ static void pci_irq_unmask_msi(struct irq_data *data)
static const struct msi_domain_template pci_msi_template = {
.chip = {
.name = "PCI-MSI",
+ .irq_startup = pci_irq_startup_msi,
+ .irq_shutdown = pci_irq_shutdown_msi,
.irq_mask = pci_irq_mask_msi,
.irq_unmask = pci_irq_unmask_msi,
.irq_write_msi_msg = pci_msi_domain_write_msg,
@@ -210,6 +246,20 @@ static const struct msi_domain_template pci_msi_template = {
},
};
+static void pci_irq_shutdown_msix(struct irq_data *data)
+{
+ pci_msix_mask(irq_data_get_msi_desc(data));
+ cond_shutdown_parent(data);
+}
+
+static unsigned int pci_irq_startup_msix(struct irq_data *data)
+{
+ unsigned int ret = cond_startup_parent(data);
+
+ pci_msix_unmask(irq_data_get_msi_desc(data));
+ return ret;
+}
+
static void pci_irq_mask_msix(struct irq_data *data)
{
pci_msix_mask(irq_data_get_msi_desc(data));
@@ -234,6 +284,8 @@ EXPORT_SYMBOL_GPL(pci_msix_prepare_desc);
static const struct msi_domain_template pci_msix_template = {
.chip = {
.name = "PCI-MSIX",
+ .irq_startup = pci_irq_startup_msix,
+ .irq_shutdown = pci_irq_shutdown_msix,
.irq_mask = pci_irq_mask_msix,
.irq_unmask = pci_irq_unmask_msix,
.irq_write_msi_msg = pci_msi_domain_write_msg,
diff --git a/include/linux/msi.h b/include/linux/msi.h
index e5e86a8529fb..3111ba95fbde 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -568,6 +568,8 @@ enum {
MSI_FLAG_PARENT_PM_DEV = (1 << 8),
/* Support for parent mask/unmask */
MSI_FLAG_PCI_MSI_MASK_PARENT = (1 << 9),
+ /* Support for parent startup/shutdown */
+ MSI_FLAG_PCI_MSI_STARTUP_PARENT = (1 << 10),
/* Mask for the generic functionality */
MSI_GENERIC_FLAGS_MASK = GENMASK(15, 0),
--
2.50.1
next prev parent reply other threads:[~2025-08-13 23:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 23:28 [PATCH v2 0/4] irqchip/sg2042-msi: Fix broken affinity setting Inochi Amaoto
2025-08-13 23:28 ` [PATCH v2 1/4] genirq: Add irq_chip_(startup/shutdown)_parent() Inochi Amaoto
2025-08-23 19:28 ` [tip: irq/core] " tip-bot2 for Inochi Amaoto
2025-08-13 23:28 ` Inochi Amaoto [this message]
2025-08-20 20:54 ` [PATCH v2 2/4] PCI/MSI: Add startup/shutdown for per device domains Bjorn Helgaas
2025-08-23 19:08 ` Thomas Gleixner
2025-08-23 19:30 ` [tip: irq/drivers] " tip-bot2 for Inochi Amaoto
2025-08-26 19:45 ` [PATCH v2 2/4] " Anders Roxell
2025-08-26 22:09 ` Nathan Chancellor
2025-08-27 10:33 ` Mark Brown
2025-08-26 22:33 ` Inochi Amaoto
2025-08-26 23:28 ` Inochi Amaoto
2025-08-27 0:47 ` Nathan Chancellor
2025-08-27 8:17 ` Naresh Kamboju
2025-08-27 9:45 ` Inochi Amaoto
2025-08-27 9:44 ` Inochi Amaoto
2025-08-27 9:39 ` Wei Fang
2025-08-27 10:14 ` Chen Wang
2025-08-27 10:14 ` Inochi Amaoto
2025-08-13 23:28 ` [PATCH v2 3/4] irqchip/sg2042-msi: Fix broken affinity setting Inochi Amaoto
2025-08-23 19:30 ` [tip: irq/drivers] " tip-bot2 for Inochi Amaoto
2025-08-13 23:28 ` [PATCH v2 4/4] irqchip/sg2042-msi: Set MSI_FLAG_MULTI_PCI_MSI flags for SG2044 Inochi Amaoto
2025-08-23 19:30 ` [tip: irq/drivers] " tip-bot2 for Inochi Amaoto
2025-08-21 6:38 ` [PATCH v2 0/4] irqchip/sg2042-msi: Fix broken affinity setting Chen 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=20250813232835.43458-3-inochiama@gmail.com \
--to=inochiama@gmail.com \
--cc=Jonathan.Cameron@huwei.com \
--cc=bhelgaas@google.com \
--cc=dlan@gentoo.org \
--cc=haiyangz@microsoft.com \
--cc=jgg@ziepe.ca \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=looong.bin@gmail.com \
--cc=lpieralisi@kernel.org \
--cc=maz@kernel.org \
--cc=nicolinc@nvidia.com \
--cc=shradhagupta@linux.microsoft.com \
--cc=tglx@linutronix.de \
--cc=unicorn_wang@outlook.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®