Move away from the legacy MSI domain setup, switch to use
msi_create_parent_irq_domain().

Signed-off-by: Nam Cao <nam...@linutronix.de>
---
 arch/powerpc/include/asm/pci-bridge.h  |   2 -
 arch/powerpc/platforms/pseries/Kconfig |   1 +
 arch/powerpc/platforms/pseries/msi.c   | 106 ++++++++++---------------
 3 files changed, 45 insertions(+), 64 deletions(-)

diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index 2aa3a091ef20e..1dae53130782a 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -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;
diff --git a/arch/powerpc/platforms/pseries/Kconfig 
b/arch/powerpc/platforms/pseries/Kconfig
index fa3c2fff082a8..3e042218d6cd8 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -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
diff --git a/arch/powerpc/platforms/pseries/msi.c 
b/arch/powerpc/platforms/pseries/msi.c
index 10712477938e4..70be6e24427da 100644
--- a/arch/powerpc/platforms/pseries/msi.c
+++ b/arch/powerpc/platforms/pseries/msi.c
@@ -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 @@ static int rtas_prepare_msi_irqs(struct pci_dev *pdev, int 
nvec_in, int type,
 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);
 }
@@ -447,11 +449,6 @@ static void pseries_msi_post_free(struct irq_domain 
*domain, struct device *dev)
        rtas_disable_msi(to_pci_dev(dev));
 }
 
-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_post_free = pseries_msi_post_free;
+
+       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)
-- 
2.39.5


Reply via email to