]> www.infradead.org Git - users/hch/misc.git/commitdiff
powerpc/pseries/msi: Switch to msi_create_parent_irq_domain()
authorNam Cao <namcao@linutronix.de>
Mon, 11 Aug 2025 09:28:56 +0000 (11:28 +0200)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Sat, 6 Sep 2025 12:03:19 +0000 (17:33 +0530)
Move away from the legacy MSI domain setup, switch to use
msi_create_parent_irq_domain().

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/c7a6d8f27fd217021dea4daad777e81a525ae460.1754903590.git.namcao@linutronix.de
arch/powerpc/include/asm/pci-bridge.h
arch/powerpc/platforms/pseries/Kconfig
arch/powerpc/platforms/pseries/msi.c

index 2aa3a091ef20eae7ddcc6b6bd1adec6d1d20e868..1dae53130782a0d7b886391b2cdd857f7783f808 100644 (file)
@@ -133,8 +133,6 @@ struct pci_controller {
 
        /* IRQ domain hierarchy */
        struct irq_domain       *dev_domain;
-       struct irq_domain       *msi_domain;
-       struct fwnode_handle    *fwnode;
 
        /* iommu_ops support */
        struct iommu_device     iommu;
index fa3c2fff082a878f128559f3842e6668422d5efc..3e042218d6cd8c89e282f7b673f50ee47062a0f4 100644 (file)
@@ -7,6 +7,7 @@ config PPC_PSERIES
        select OF_DYNAMIC
        select FORCE_PCI
        select PCI_MSI
+       select IRQ_MSI_LIB
        select GENERIC_ALLOCATOR
        select PPC_XICS
        select PPC_XIVE_SPAPR
index e5cf061c519ee5749d927f6a7106a1d997011619..825f9432e03d7d8612100a92a9334954d31541f8 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/crash_dump.h>
 #include <linux/device.h>
 #include <linux/irq.h>
+#include <linux/irqchip/irq-msi-lib.h>
 #include <linux/irqdomain.h>
 #include <linux/msi.h>
 #include <linux/seq_file.h>
@@ -429,8 +430,9 @@ again:
 static int pseries_msi_ops_prepare(struct irq_domain *domain, struct device *dev,
                                   int nvec, msi_alloc_info_t *arg)
 {
+       struct msi_domain_info *info = domain->host_data;
        struct pci_dev *pdev = to_pci_dev(dev);
-       int type = pdev->msix_enabled ? PCI_CAP_ID_MSIX : PCI_CAP_ID_MSI;
+       int type = (info->flags & MSI_FLAG_PCI_MSIX) ? PCI_CAP_ID_MSIX : PCI_CAP_ID_MSI;
 
        return rtas_prepare_msi_irqs(pdev, nvec, type, arg);
 }
@@ -439,19 +441,14 @@ static int pseries_msi_ops_prepare(struct irq_domain *domain, struct device *dev
  * RTAS can not disable one MSI at a time. It's all or nothing. Do it
  * at the end after all IRQs have been freed.
  */
-static void pseries_msi_post_free(struct irq_domain *domain, struct device *dev)
+static void pseries_msi_ops_teardown(struct irq_domain *domain, msi_alloc_info_t *arg)
 {
-       if (WARN_ON_ONCE(!dev_is_pci(dev)))
-               return;
+       struct msi_desc *desc = arg->desc;
+       struct pci_dev *pdev = msi_desc_to_pci_dev(desc);
 
-       rtas_disable_msi(to_pci_dev(dev));
+       rtas_disable_msi(pdev);
 }
 
-static struct msi_domain_ops pseries_pci_msi_domain_ops = {
-       .msi_prepare    = pseries_msi_ops_prepare,
-       .msi_post_free  = pseries_msi_post_free,
-};
-
 static void pseries_msi_shutdown(struct irq_data *d)
 {
        d = d->parent_data;
@@ -459,18 +456,6 @@ static void pseries_msi_shutdown(struct irq_data *d)
                d->chip->irq_shutdown(d);
 }
 
-static void pseries_msi_mask(struct irq_data *d)
-{
-       pci_msi_mask_irq(d);
-       irq_chip_mask_parent(d);
-}
-
-static void pseries_msi_unmask(struct irq_data *d)
-{
-       pci_msi_unmask_irq(d);
-       irq_chip_unmask_parent(d);
-}
-
 static void pseries_msi_write_msg(struct irq_data *data, struct msi_msg *msg)
 {
        struct msi_desc *entry = irq_data_get_msi_desc(data);
@@ -485,27 +470,39 @@ static void pseries_msi_write_msg(struct irq_data *data, struct msi_msg *msg)
        entry->msg = *msg;
 }
 
-static struct irq_chip pseries_pci_msi_irq_chip = {
-       .name           = "pSeries-PCI-MSI",
-       .irq_shutdown   = pseries_msi_shutdown,
-       .irq_mask       = pseries_msi_mask,
-       .irq_unmask     = pseries_msi_unmask,
-       .irq_eoi        = irq_chip_eoi_parent,
-       .irq_write_msi_msg      = pseries_msi_write_msg,
-};
+static bool pseries_init_dev_msi_info(struct device *dev, struct irq_domain *domain,
+                                     struct irq_domain *real_parent, struct msi_domain_info *info)
+{
+       struct irq_chip *chip = info->chip;
 
+       if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info))
+               return false;
 
-/*
- * Set MSI_FLAG_MSIX_CONTIGUOUS as there is no way to express to
- * firmware to request a discontiguous or non-zero based range of
- * MSI-X entries. Core code will reject such setup attempts.
- */
-static struct msi_domain_info pseries_msi_domain_info = {
-       .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
-                 MSI_FLAG_MULTI_PCI_MSI  | MSI_FLAG_PCI_MSIX |
-                 MSI_FLAG_MSIX_CONTIGUOUS),
-       .ops   = &pseries_pci_msi_domain_ops,
-       .chip  = &pseries_pci_msi_irq_chip,
+       chip->irq_shutdown = pseries_msi_shutdown;
+       chip->irq_write_msi_msg = pseries_msi_write_msg;
+
+       info->ops->msi_prepare = pseries_msi_ops_prepare;
+       info->ops->msi_teardown = pseries_msi_ops_teardown;
+
+       return true;
+}
+
+#define PSERIES_PCI_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS       | \
+                                       MSI_FLAG_USE_DEF_CHIP_OPS       | \
+                                       MSI_FLAG_PCI_MSI_MASK_PARENT)
+#define PSERIES_PCI_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK                | \
+                                        MSI_FLAG_PCI_MSIX              | \
+                                        MSI_FLAG_MSIX_CONTIGUOUS       | \
+                                        MSI_FLAG_MULTI_PCI_MSI)
+
+static const struct msi_parent_ops pseries_msi_parent_ops = {
+       .required_flags         = PSERIES_PCI_MSI_FLAGS_REQUIRED,
+       .supported_flags        = PSERIES_PCI_MSI_FLAGS_SUPPORTED,
+       .chip_flags             = MSI_CHIP_FLAG_SET_EOI,
+       .bus_select_token       = DOMAIN_BUS_NEXUS,
+       .bus_select_mask        = MATCH_PCI_MSI,
+       .prefix                 = "pSeries-",
+       .init_dev_msi_info      = pseries_init_dev_msi_info,
 };
 
 static void pseries_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
@@ -593,6 +590,7 @@ static void pseries_irq_domain_free(struct irq_domain *domain, unsigned int virq
 }
 
 static const struct irq_domain_ops pseries_irq_domain_ops = {
+       .select = msi_lib_irq_domain_select,
        .alloc  = pseries_irq_domain_alloc,
        .free   = pseries_irq_domain_free,
 };
@@ -601,30 +599,18 @@ static int __pseries_msi_allocate_domains(struct pci_controller *phb,
                                          unsigned int count)
 {
        struct irq_domain *parent = irq_get_default_domain();
-
-       phb->fwnode = irq_domain_alloc_named_id_fwnode("pSeries-MSI",
-                                                      phb->global_number);
-       if (!phb->fwnode)
-               return -ENOMEM;
-
-       phb->dev_domain = irq_domain_create_hierarchy(parent, 0, count,
-                                                     phb->fwnode,
-                                                     &pseries_irq_domain_ops, phb);
+       struct irq_domain_info info = {
+               .fwnode         = of_fwnode_handle(phb->dn),
+               .ops            = &pseries_irq_domain_ops,
+               .host_data      = phb,
+               .size           = count,
+               .parent         = parent,
+       };
+
+       phb->dev_domain = msi_create_parent_irq_domain(&info, &pseries_msi_parent_ops);
        if (!phb->dev_domain) {
-               pr_err("PCI: failed to create IRQ domain bridge %pOF (domain %d)\n",
-                      phb->dn, phb->global_number);
-               irq_domain_free_fwnode(phb->fwnode);
-               return -ENOMEM;
-       }
-
-       phb->msi_domain = pci_msi_create_irq_domain(of_fwnode_handle(phb->dn),
-                                                   &pseries_msi_domain_info,
-                                                   phb->dev_domain);
-       if (!phb->msi_domain) {
                pr_err("PCI: failed to create MSI IRQ domain bridge %pOF (domain %d)\n",
                       phb->dn, phb->global_number);
-               irq_domain_free_fwnode(phb->fwnode);
-               irq_domain_remove(phb->dev_domain);
                return -ENOMEM;
        }
 
@@ -646,12 +632,8 @@ int pseries_msi_allocate_domains(struct pci_controller *phb)
 
 void pseries_msi_free_domains(struct pci_controller *phb)
 {
-       if (phb->msi_domain)
-               irq_domain_remove(phb->msi_domain);
        if (phb->dev_domain)
                irq_domain_remove(phb->dev_domain);
-       if (phb->fwnode)
-               irq_domain_free_fwnode(phb->fwnode);
 }
 
 static void rtas_msi_pci_irq_fixup(struct pci_dev *pdev)