Skip to contentSkip to conversation

PCI/MSI: pci-xgene-msi: Enable MSI support in ACPI boot for X-Gene v1

PATCH In review Duc Dang 6 participants 16 messages Feb 10, 2016 – Apr 26, 2017 PCI

lore
Share & tools
lore

Duc Dang

author
#0 lore raw

PATCH 1/1 PCI/MSI: pci-xgene-msi: Enable MSI support in ACPI boot for X-Gene v1

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +32 -3
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0			0x000000
 #define MSI_INT0		0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-	struct device_node	*node;
+	struct fwnode_handle	*fwnode;
 	struct irq_domain	*inner_domain;
 	struct irq_domain	*msi_domain;
 	u64			msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
 	.free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+	return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
 	msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
 	if (!msi->inner_domain)
 		return -ENOMEM;
 
-	msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+	msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
 						    &xgene_msi_domain_info,
 						    msi->inner_domain);
 
@@ -265,6 +273,9 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
 		return -ENOMEM;
 	}
 
+#ifdef CONFIG_ACPI
+	pci_msi_register_fwnode_provider(&xgene_msi_get_fwnode);
+#endif
 	return 0;
 }
 
@@ -473,6 +484,13 @@ static const struct of_device_id xgene_msi_match_table[] = {
 	{},
 };
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id xgene_msi_acpi_ids[] = {
+	{"APMC0D0E", 0},
+	{ },
+};
+#endif
+
 static int xgene_msi_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -494,7 +512,17 @@ static int xgene_msi_probe(struct platform_device *pdev)
 		goto error;
 	}
 	xgene_msi->msi_addr = res->start;
-	xgene_msi->node = pdev->dev.of_node;
+
+	xgene_msi->fwnode = of_node_to_fwnode(pdev->dev.of_node);
+	if (!xgene_msi->fwnode) {
+		xgene_msi->fwnode = irq_domain_alloc_fwnode(NULL);
+		if (!xgene_msi->fwnode) {
+			dev_err(&pdev->dev, "Failed to create fwnode\n");
+			rc = ENOMEM;
+			goto error;
+		}
+	}
+
 	xgene_msi->num_cpus = num_possible_cpus();
 
 	rc = xgene_msi_init_allocator(xgene_msi);
@@ -571,6 +599,7 @@ static struct platform_driver xgene_msi_driver = {
 	.driver = {
 		.name = "xgene-msi",
 		.of_match_table = xgene_msi_match_table,
+		.acpi_match_table = ACPI_PTR(xgene_msi_acpi_ids),
 	},
 	.probe = xgene_msi_probe,
 	.remove = xgene_msi_remove,
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

Another nail on the ACPI "standardization" coffin, I suppose... Oh well.

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
author
#2 lore raw
Quoted 9 lines · Marc Zyngier
Quoted 4 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

Another nail on the ACPI "standardization" coffin, I suppose... Oh well.

Thanks, Marc.

Regards,
Duc Dang.

Quoted 4 lines
        M.

--
Jazz is not dead. It just smells funny...

author
#3 lore raw
In reply to Duc Dang
Quoted 2 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

Hi Bjorn,

Are you planning to take this patch into your tree?

Regards,
Duc Dang.

Quoted 104 lines
---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +32 -4
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                        0x000000
 #define MSI_INT0               0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-       struct device_node      *node;
+       struct fwnode_handle    *fwnode;
        struct irq_domain       *inner_domain;
        struct irq_domain       *msi_domain;
        u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
        .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+       return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
        msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
        if (!msi->inner_domain)
                return -ENOMEM;
 
-       msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+       msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                    &xgene_msi_domain_info,
                                                    msi->inner_domain);
 
@@ -265,6 +273,9 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
                return -ENOMEM;
        }
 
+#ifdef CONFIG_ACPI
+       pci_msi_register_fwnode_provider(&xgene_msi_get_fwnode);
+#endif
        return 0;
 }
 
@@ -473,6 +484,13 @@ static const struct of_device_id xgene_msi_match_table[] = {
        {},
 };
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id xgene_msi_acpi_ids[] = {
+       {"APMC0D0E", 0},
+       { },
+};
+#endif
+
 static int xgene_msi_probe(struct platform_device *pdev)
 {
        struct resource *res;
@@ -494,7 +512,17 @@ static int xgene_msi_probe(struct platform_device *pdev)
                goto error;
        }
        xgene_msi->msi_addr = res->start;
-       xgene_msi->node = pdev->dev.of_node;
+
+       xgene_msi->fwnode = of_node_to_fwnode(pdev->dev.of_node);
+       if (!xgene_msi->fwnode) {
+               xgene_msi->fwnode = irq_domain_alloc_fwnode(NULL);
+               if (!xgene_msi->fwnode) {
+                       dev_err(&pdev->dev, "Failed to create fwnode\n");
+                       rc = ENOMEM;
+                       goto error;
+               }
+       }
+
        xgene_msi->num_cpus = num_possible_cpus();
 
        rc = xgene_msi_init_allocator(xgene_msi);
@@ -571,6 +599,7 @@ static struct platform_driver xgene_msi_driver = {
        .driver = {
                .name = "xgene-msi",
                .of_match_table = xgene_msi_match_table,
+               .acpi_match_table = ACPI_PTR(xgene_msi_acpi_ids),
        },
        .probe = xgene_msi_probe,
        .remove = xgene_msi_remove,
--

1.9.1

maintainer
#4 lore raw
Quoted 7 lines · Duc Dang
Quoted 2 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

Hi Bjorn,

Are you planning to take this patch into your tree?

Sorry, I haven't had a chance to look at this yet. I had a sick daughter last week, so I'm even farther behind than usual.

When I get to it, I'll be asking questions like:

- Does this correspond to some analogous x86 code?
- Is there something unique about arm64 or X-Gene that means it
needs special code?

I don't really understand the arm64/ACPI strategy yet, so I'll be looking first for generic solutions that work across x86/ia64/arm64, and justifications for the inevitable exceptions.

Quoted 103 lines
Quoted 103 lines
---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +32 -4
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                        0x000000
 #define MSI_INT0               0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-       struct device_node      *node;
+       struct fwnode_handle    *fwnode;
        struct irq_domain       *inner_domain;
        struct irq_domain       *msi_domain;
        u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
        .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+       return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
        msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
        if (!msi->inner_domain)
                return -ENOMEM;
 
-       msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+       msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                    &xgene_msi_domain_info,
                                                    msi->inner_domain);
 
@@ -265,6 +273,9 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
                return -ENOMEM;
        }
 
+#ifdef CONFIG_ACPI
+       pci_msi_register_fwnode_provider(&xgene_msi_get_fwnode);
+#endif
        return 0;
 }
 
@@ -473,6 +484,13 @@ static const struct of_device_id xgene_msi_match_table[] = {
        {},
 };
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id xgene_msi_acpi_ids[] = {
+       {"APMC0D0E", 0},
+       { },
+};
+#endif
+
 static int xgene_msi_probe(struct platform_device *pdev)
 {
        struct resource *res;
@@ -494,7 +512,17 @@ static int xgene_msi_probe(struct platform_device *pdev)
                goto error;
        }
        xgene_msi->msi_addr = res->start;
-       xgene_msi->node = pdev->dev.of_node;
+
+       xgene_msi->fwnode = of_node_to_fwnode(pdev->dev.of_node);
+       if (!xgene_msi->fwnode) {
+               xgene_msi->fwnode = irq_domain_alloc_fwnode(NULL);
+               if (!xgene_msi->fwnode) {
+                       dev_err(&pdev->dev, "Failed to create fwnode\n");
+                       rc = ENOMEM;
+                       goto error;
+               }
+       }
+
        xgene_msi->num_cpus = num_possible_cpus();
 
        rc = xgene_msi_init_allocator(xgene_msi);
@@ -571,6 +599,7 @@ static struct platform_driver xgene_msi_driver = {
        .driver = {
                .name = "xgene-msi",
                .of_match_table = xgene_msi_match_table,
+               .acpi_match_table = ACPI_PTR(xgene_msi_acpi_ids),
        },
        .probe = xgene_msi_probe,
        .remove = xgene_msi_remove,
--

1.9.1

author
#5 lore raw
Quoted 6 lines · Bjorn Helgaas
Quoted 4 lines · Duc Dang
Quoted 2 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

Quoted 7 lines
Quoted 3 lines

Hi Bjorn,

Are you planning to take this patch into your tree?

Sorry, I haven't had a chance to look at this yet. I had a sick daughter last week, so I'm even farther behind than usual.

Hi Bjorn,

I hope your daughter is doing well.

Quoted 3 lines

When I get to it, I'll be asking questions like:

- Does this correspond to some analogous x86 code?

I am not aware of any x86 code similar to this.

Quoted 2 lines

- Is there something unique about arm64 or X-Gene that means it
needs special code?

The MSI controller on X-Gene v1 is a separate IP block. pci-xgene-msi is a separate X-Gene v1 specific driver that provides MSI capability for X-Gene v1 PCIe controllers. We already have device-tree version of this driver. So the purpose of this patch is to make the driver can be discovered and loaded when booting with ACPI mode.

Regards,
Duc Dang.

Quoted 108 lines

I don't really understand the arm64/ACPI strategy yet, so I'll be looking first for generic solutions that work across x86/ia64/arm64, and justifications for the inevitable exceptions.

Quoted 103 lines
Quoted 103 lines
---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +32 -4
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                        0x000000
 #define MSI_INT0               0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-       struct device_node      *node;
+       struct fwnode_handle    *fwnode;
        struct irq_domain       *inner_domain;
        struct irq_domain       *msi_domain;
        u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
        .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+       return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
        msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
        if (!msi->inner_domain)
                return -ENOMEM;
 
-       msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+       msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                    &xgene_msi_domain_info,
                                                    msi->inner_domain);
 
@@ -265,6 +273,9 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
                return -ENOMEM;
        }
 
+#ifdef CONFIG_ACPI
+       pci_msi_register_fwnode_provider(&xgene_msi_get_fwnode);
+#endif
        return 0;
 }
 
@@ -473,6 +484,13 @@ static const struct of_device_id xgene_msi_match_table[] = {
        {},
 };
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id xgene_msi_acpi_ids[] = {
+       {"APMC0D0E", 0},
+       { },
+};
+#endif
+
 static int xgene_msi_probe(struct platform_device *pdev)
 {
        struct resource *res;
@@ -494,7 +512,17 @@ static int xgene_msi_probe(struct platform_device *pdev)
                goto error;
        }
        xgene_msi->msi_addr = res->start;
-       xgene_msi->node = pdev->dev.of_node;
+
+       xgene_msi->fwnode = of_node_to_fwnode(pdev->dev.of_node);
+       if (!xgene_msi->fwnode) {
+               xgene_msi->fwnode = irq_domain_alloc_fwnode(NULL);
+               if (!xgene_msi->fwnode) {
+                       dev_err(&pdev->dev, "Failed to create fwnode\n");
+                       rc = ENOMEM;
+                       goto error;
+               }
+       }
+
        xgene_msi->num_cpus = num_possible_cpus();
 
        rc = xgene_msi_init_allocator(xgene_msi);
@@ -571,6 +599,7 @@ static struct platform_driver xgene_msi_driver = {
        .driver = {
                .name = "xgene-msi",
                .of_match_table = xgene_msi_match_table,
+               .acpi_match_table = ACPI_PTR(xgene_msi_acpi_ids),
        },
        .probe = xgene_msi_probe,
        .remove = xgene_msi_remove,
--

1.9.1

#6 lore raw
In reply to Duc Dang
Quoted 49 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
?drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++--- ?1 file changed, 32 insertions(+), 3 deletions(-)

drivers/pci/host/pci-xgene-msi.c +0 -0
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@

?#include <linux/pci.h>
?#include <linux/platform_device.h>
?#include <linux/of_pci.h>
+#include <linux/acpi.h>
?
?#define MSI_IR0 0x000000
?#define MSI_INT0 0x800000

drivers/pci/host/pci-xgene-msi.c +0 -0
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 ?};

?
?struct xgene_msi {

drivers/pci/host/pci-xgene-msi.c +1 -1
-	struct device_node	*node;
+	struct fwnode_handle	*fwnode;

? struct irq_domain *inner_domain;
? struct irq_domain *msi_domain;
? u64 msi_addr;

drivers/pci/host/pci-xgene-msi.c +0 -0
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
 ?	.free???= xgene_irq_domain_free,
 ?};

?

drivers/pci/host/pci-xgene-msi.c +7 -0
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+	return xgene_msi_ctrl.fwnode;
+}
+#endif
+

?static int xgene_allocate_domains(struct xgene_msi *msi) ?{
? msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,

drivers/pci/host/pci-xgene-msi.c +0 -0
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
 ?	if (!msi->inner_domain)
 ?		return -ENOMEM;

?

drivers/pci/host/pci-xgene-msi.c +1 -1
-	msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+	msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
Quoted 2 lines

? ????&xgene_msi_domain_info,
? ????msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be?pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 52 lines

?

drivers/pci/host/pci-xgene-msi.c +0 -0
@@ -265,6 +273,9 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
 ?		return -ENOMEM;
 ?	}

?

drivers/pci/host/pci-xgene-msi.c +3 -0
+#ifdef CONFIG_ACPI
+	pci_msi_register_fwnode_provider(&xgene_msi_get_fwnode);
+#endif

? return 0;
?}
?

drivers/pci/host/pci-xgene-msi.c +0 -0
@@ -473,6 +484,13 @@ static const struct of_device_id xgene_msi_match_table[] = {
 ?	{},
 ?};

?

drivers/pci/host/pci-xgene-msi.c +7 -0
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id xgene_msi_acpi_ids[] = {
+	{"APMC0D0E", 0},
+	{ },
+};
+#endif
+

?static int xgene_msi_probe(struct platform_device *pdev) ?{
? struct resource *res;

drivers/pci/host/pci-xgene-msi.c +11 -1
@@ -494,7 +512,17 @@ static int xgene_msi_probe(struct platform_device *pdev)
 ?		goto error;
 ?	}
 ?	xgene_msi->msi_addr = res->start;
-	xgene_msi->node = pdev->dev.of_node;
+
+	xgene_msi->fwnode = of_node_to_fwnode(pdev->dev.of_node);
+	if (!xgene_msi->fwnode) {
+		xgene_msi->fwnode = irq_domain_alloc_fwnode(NULL);
+		if (!xgene_msi->fwnode) {
+			dev_err(&pdev->dev, "Failed to create fwnode\n");
+			rc = ENOMEM;
+			goto error;
+		}
+	}
+
 ?	xgene_msi->num_cpus = num_possible_cpus();

?
? rc = xgene_msi_init_allocator(xgene_msi);

drivers/pci/host/pci-xgene-msi.c +1 -0
@@ -571,6 +599,7 @@ static struct platform_driver xgene_msi_driver = {
 ?	.driver = {
 ?		.name = "xgene-msi",
 ?		.of_match_table = xgene_msi_match_table,
+		.acpi_match_table = ACPI_PTR(xgene_msi_acpi_ids),
 ?	},
 ?	.probe = xgene_msi_probe,
 ?	.remove = xgene_msi_remove,
#7 lore raw
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0			0x000000
 #define MSI_INT0		0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-	struct device_node	*node;
+	struct fwnode_handle	*fwnode;
 	struct irq_domain	*inner_domain;
 	struct irq_domain	*msi_domain;
 	u64			msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
 	.free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+	return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
 	msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
 	if (!msi->inner_domain)
 		return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-	msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+	msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
 						    &xgene_msi_domain_info,
 						    msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
author
#8 lore raw
Quoted 59 lines · Marc Zyngier
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                     0x000000
 #define MSI_INT0            0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-    struct device_node      *node;
+    struct fwnode_handle    *fwnode;
     struct irq_domain       *inner_domain;
     struct irq_domain       *msi_domain;
     u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
     .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+    return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
     msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
     if (!msi->inner_domain)
             return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-    msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+    msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                 &xgene_msi_domain_info,
                                                 msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 6 lines

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

Hi Mark and Marc,

I have modified Tianocore firmware to have MSI node declared before PCIe node in Dsdt table. With this modification, the MSI driver will be loaded before PCIe driver and MSI domain is available at the time PCIe root is initialized.

So we will need a UEFI firmware update to work with this patch.

Regards,
Duc Dang.

Quoted 4 lines
        M.

--
Jazz is not dead. It just smells funny...

#9 lore raw
Quoted 67 lines · Duc Dang
Quoted 59 lines · Marc Zyngier
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                     0x000000
 #define MSI_INT0            0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-    struct device_node      *node;
+    struct fwnode_handle    *fwnode;
     struct irq_domain       *inner_domain;
     struct irq_domain       *msi_domain;
     u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
     .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+    return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
     msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
     if (!msi->inner_domain)
             return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-    msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+    msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                 &xgene_msi_domain_info,
                                                 msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 6 lines

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

Quoted 6 lines

Hi Mark and Marc,

I have modified Tianocore firmware to have MSI node declared before PCIe node in Dsdt table. With this modification, the MSI driver will be loaded before PCIe driver and MSI domain is available at the time PCIe root is initialized.

I am totally against this. We should not hack ACPI tables to make the kernel work (on top of that with unwritten ordering rules that may well require changes as kernel evolves), we should have a standard set of bindings that people use to describe HW in the DSDT and the kernel(s) has to cope with that. If there is a dependency problem in the description we may solve it at bindings level, but I absolutely do not want to rely on DSDT nodes ordering for things to work, that's fragile, no shortcuts please.

Thanks,
Lorenzo

author
#10 lore raw
Quoted 75 lines · Lorenzo Pieralisi
Quoted 67 lines · Duc Dang
Quoted 59 lines · Marc Zyngier
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                     0x000000
 #define MSI_INT0            0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-    struct device_node      *node;
+    struct fwnode_handle    *fwnode;
     struct irq_domain       *inner_domain;
     struct irq_domain       *msi_domain;
     u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
     .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+    return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
     msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
     if (!msi->inner_domain)
             return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-    msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+    msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                 &xgene_msi_domain_info,
                                                 msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 6 lines

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

Quoted 6 lines

Hi Mark and Marc,

I have modified Tianocore firmware to have MSI node declared before PCIe node in Dsdt table. With this modification, the MSI driver will be loaded before PCIe driver and MSI domain is available at the time PCIe root is initialized.

Quoted 8 lines

I am totally against this. We should not hack ACPI tables to make the kernel work (on top of that with unwritten ordering rules that may well require changes as kernel evolves), we should have a standard set of bindings that people use to describe HW in the DSDT and the kernel(s) has to cope with that. If there is a dependency problem in the description we may solve it at bindings level, but I absolutely do not want to rely on DSDT nodes ordering for things to work, that's fragile, no shortcuts please.

Hi Lorenzo, Bjorn,

(Refresh this thread on this merge cycle)

I tried to use _DEP method to describe the dependency of PCIe node to MSI node but it turns out that PCIe driver does not check for the dependency (only EC (ec.c) and I2C core (i2c-core.c) use acpi_walk_dep_device_list to check for dependency before loading dependent drivers)

Do you have other suggestion/example about how to ensure strict ordering on driver loading in ACPI boot mode without changing the order of ACPI nodes in DSDT?

Regards,
Duc Dang.

Quoted 3 lines

Thanks,
Lorenzo

#11 lore raw

Hi Duc,

Quoted 96 lines · Duc Dang
Quoted 75 lines · Lorenzo Pieralisi
Quoted 67 lines · Duc Dang
Quoted 59 lines · Marc Zyngier
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                     0x000000
 #define MSI_INT0            0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-    struct device_node      *node;
+    struct fwnode_handle    *fwnode;
     struct irq_domain       *inner_domain;
     struct irq_domain       *msi_domain;
     u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
     .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+    return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
     msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
     if (!msi->inner_domain)
             return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-    msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+    msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                 &xgene_msi_domain_info,
                                                 msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 6 lines

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

Quoted 6 lines

Hi Mark and Marc,

I have modified Tianocore firmware to have MSI node declared before PCIe node in Dsdt table. With this modification, the MSI driver will be loaded before PCIe driver and MSI domain is available at the time PCIe root is initialized.

Quoted 8 lines

I am totally against this. We should not hack ACPI tables to make the kernel work (on top of that with unwritten ordering rules that may well require changes as kernel evolves), we should have a standard set of bindings that people use to describe HW in the DSDT and the kernel(s) has to cope with that. If there is a dependency problem in the description we may solve it at bindings level, but I absolutely do not want to rely on DSDT nodes ordering for things to work, that's fragile, no shortcuts please.

Hi Lorenzo, Bjorn,

(Refresh this thread on this merge cycle)

I tried to use _DEP method to describe the dependency of PCIe node to MSI node but it turns out that PCIe driver does not check for the dependency (only EC (ec.c) and I2C core (i2c-core.c) use acpi_walk_dep_device_list to check for dependency before loading dependent drivers)

Quoted 3 lines

Do you have other suggestion/example about how to ensure strict ordering on driver loading in ACPI boot mode without changing the order of ACPI nodes in DSDT?

Before doing anything else, I would like to ask you to report the code paths leading to failures (what fails actually ?) please, and I want to understand what "this does not work" means.

In particular:

- Why using pci_msi_create_default_irq_domain() works
- Why, if you change the DSDT nodes ordering, things work (please add some debugging to MSI allocation functions to detect the code paths leading to correct MSI allocation)
- What's the difference wrt the DT probe path

When we have a detailed view of MSI allocation code paths and failures we can see what we can do to fix it in ACPI.

Thanks,
Lorenzo

author
#12 lore raw

Hi Lorenzo,

Quoted 107 lines · Lorenzo Pieralisi

Hi Duc,

Quoted 96 lines · Duc Dang
Quoted 75 lines · Lorenzo Pieralisi
Quoted 67 lines · Duc Dang
Quoted 59 lines · Marc Zyngier
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                     0x000000
 #define MSI_INT0            0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-    struct device_node      *node;
+    struct fwnode_handle    *fwnode;
     struct irq_domain       *inner_domain;
     struct irq_domain       *msi_domain;
     u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
     .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+    return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
     msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
     if (!msi->inner_domain)
             return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-    msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+    msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                 &xgene_msi_domain_info,
                                                 msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 6 lines

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

Quoted 6 lines

Hi Mark and Marc,

I have modified Tianocore firmware to have MSI node declared before PCIe node in Dsdt table. With this modification, the MSI driver will be loaded before PCIe driver and MSI domain is available at the time PCIe root is initialized.

Quoted 8 lines

I am totally against this. We should not hack ACPI tables to make the kernel work (on top of that with unwritten ordering rules that may well require changes as kernel evolves), we should have a standard set of bindings that people use to describe HW in the DSDT and the kernel(s) has to cope with that. If there is a dependency problem in the description we may solve it at bindings level, but I absolutely do not want to rely on DSDT nodes ordering for things to work, that's fragile, no shortcuts please.

Hi Lorenzo, Bjorn,

(Refresh this thread on this merge cycle)

I tried to use _DEP method to describe the dependency of PCIe node to MSI node but it turns out that PCIe driver does not check for the dependency (only EC (ec.c) and I2C core (i2c-core.c) use acpi_walk_dep_device_list to check for dependency before loading dependent drivers)

Quoted 3 lines

Do you have other suggestion/example about how to ensure strict ordering on driver loading in ACPI boot mode without changing the order of ACPI nodes in DSDT?

Before doing anything else, I would like to ask you to report the code paths leading to failures (what fails actually ?) please, and I want to understand what "this does not work" means.

Quoted 7 lines

In particular:

- Why using pci_msi_create_default_irq_domain() works
- Why, if you change the DSDT nodes ordering, things work (please add some debugging to MSI allocation functions to detect the code paths leading to correct MSI allocation)
- What's the difference wrt the DT probe path

The MSI allocation happens with following code path (I use PMC pm80xx SAS driver as an example (drivers/scsi/pm8001/pm8001_init.c)):
pci_enable_msix_exact

    pci_enable_msix_range
        pci_enable_msix
            msix_capbility_init
                pci_msi_setup_msi_irqs
                    pci_msi_get_domain
                        dev_get_msi_domain
                        arch_get_pci_msi_domain
                            return pci_msi_default_domain;

In my failing case: pci_msi_get_domain return NULL, so MSI allocation function (pci_enable_msix_exact) fails.

The expected MSI domain is registered when X-Gene MSI driver is initialized and is attached to each PCI bus by calling pci_set_bus_msi_domain during PCIe bus-scan:
pci_scan_root_bus
pci_scan_root_bus_msi
pci_scan_child_bus
pci_scan_bridge
pci_add_new_bus
pci_alloc_child_bus
pci_set_bus_msi_domain
pci_host_bridge_msi_domain
pci_host_bridge_of_msi_domain pci_host_bridge_acpi_msi_domain

+ When booting with DT: X-Gene MSI driver is initialized early (subsys_initcall level); X-Gene PCIe driver is initialized later at device_initcall level (using module_platform_driver). Because of that when PCIe enumeration happens, the X-Gene MSI domain was already registered and available. So when the driver of PCIe Endpoint devices gets loaded, the call to pci_enable_msix_exact (to allocate MSI) succeeds.

+ When booting with ACPI: acpi_scan_init is called at subsys_initcall level (the same level with X-Gene MSI driver):
acpi_init
acpi_bus_init (GIC is initialized here)
acpi_scan_init
acpi_pci_root_init
acpi_pci_link_init
...
acpi_bus_scan
acpi_bus_check_add
...

Currently, in DSDT table, X-Gene MSI node is defined right after X-Gene PCIe nodes. So PCIe driver initialization and PCIe enumeration happens before MSI driver is initialized. During PCIe bus scan, the pci_set_bus_msi_domain gets a NULL irq_domain value from pci_host_bridge_msi_domain (as MSI driver is not initialized), so there is no MSI support for PCIe bus.

+ Using pci_msi_create_default_irq_domain() helps MSI allocation succeed as pci_msi_get_domain (in the code path of pci_enable_msix_exact above) can fall back to get a valid domain from arch_get_pci_msi_domain (please note that PCIe endpoint driver gets called later (at device_initcall level (using module_init)), so at the time PCIe endpoint driver probe function executes, the MSI driver already register the global MSI domain with pci_msi_create_default_irq_domain)

+ If changing DSDT node ordering, to define MSI node before PCIe nodes, then X-Gene MSI driver will be loaded before PCIe host driver. At the time PCIe enumeration happens, X-Gene MSI driver already registered a valid MSI domain (by calling pci_msi_register_fwnode_provider to register the fwnode provider function), so all the detected PCIe buses (and PCIe endpoint devices) will have a valid MSI domain attached to them (as a result of function pci_set_bus_msi_domain)

Regards,
Duc Dang.

Quoted 6 lines

When we have a detailed view of MSI allocation code paths and failures we can see what we can do to fix it in ACPI.

Thanks,
Lorenzo

#13 lore raw

[+ Rafael]

Quoted 184 lines · Duc Dang

Hi Lorenzo,

Quoted 107 lines · Lorenzo Pieralisi

Hi Duc,

Quoted 96 lines · Duc Dang
Quoted 75 lines · Lorenzo Pieralisi
Quoted 67 lines · Duc Dang
Quoted 59 lines · Marc Zyngier
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                     0x000000
 #define MSI_INT0            0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-    struct device_node      *node;
+    struct fwnode_handle    *fwnode;
     struct irq_domain       *inner_domain;
     struct irq_domain       *msi_domain;
     u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
     .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+    return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
     msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
     if (!msi->inner_domain)
             return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-    msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+    msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                 &xgene_msi_domain_info,
                                                 msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 6 lines

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

Quoted 6 lines

Hi Mark and Marc,

I have modified Tianocore firmware to have MSI node declared before PCIe node in Dsdt table. With this modification, the MSI driver will be loaded before PCIe driver and MSI domain is available at the time PCIe root is initialized.

Quoted 8 lines

I am totally against this. We should not hack ACPI tables to make the kernel work (on top of that with unwritten ordering rules that may well require changes as kernel evolves), we should have a standard set of bindings that people use to describe HW in the DSDT and the kernel(s) has to cope with that. If there is a dependency problem in the description we may solve it at bindings level, but I absolutely do not want to rely on DSDT nodes ordering for things to work, that's fragile, no shortcuts please.

Hi Lorenzo, Bjorn,

(Refresh this thread on this merge cycle)

I tried to use _DEP method to describe the dependency of PCIe node to MSI node but it turns out that PCIe driver does not check for the dependency (only EC (ec.c) and I2C core (i2c-core.c) use acpi_walk_dep_device_list to check for dependency before loading dependent drivers)

Quoted 3 lines

Do you have other suggestion/example about how to ensure strict ordering on driver loading in ACPI boot mode without changing the order of ACPI nodes in DSDT?

Before doing anything else, I would like to ask you to report the code paths leading to failures (what fails actually ?) please, and I want to understand what "this does not work" means.

Quoted 7 lines

In particular:

- Why using pci_msi_create_default_irq_domain() works
- Why, if you change the DSDT nodes ordering, things work (please add some debugging to MSI allocation functions to detect the code paths leading to correct MSI allocation)
- What's the difference wrt the DT probe path

The MSI allocation happens with following code path (I use PMC pm80xx SAS driver as an example (drivers/scsi/pm8001/pm8001_init.c)):
pci_enable_msix_exact

    pci_enable_msix_range
        pci_enable_msix
            msix_capbility_init
                pci_msi_setup_msi_irqs
                    pci_msi_get_domain
                        dev_get_msi_domain
                        arch_get_pci_msi_domain
                            return pci_msi_default_domain;

In my failing case: pci_msi_get_domain return NULL, so MSI allocation function (pci_enable_msix_exact) fails.

The expected MSI domain is registered when X-Gene MSI driver is initialized and is attached to each PCI bus by calling pci_set_bus_msi_domain during PCIe bus-scan:
pci_scan_root_bus
pci_scan_root_bus_msi
pci_scan_child_bus
pci_scan_bridge
pci_add_new_bus
pci_alloc_child_bus
pci_set_bus_msi_domain
pci_host_bridge_msi_domain
pci_host_bridge_of_msi_domain pci_host_bridge_acpi_msi_domain

+ When booting with DT: X-Gene MSI driver is initialized early (subsys_initcall level); X-Gene PCIe driver is initialized later at device_initcall level (using module_platform_driver). Because of that when PCIe enumeration happens, the X-Gene MSI domain was already registered and available. So when the driver of PCIe Endpoint devices gets loaded, the call to pci_enable_msix_exact (to allocate MSI) succeeds.

+ When booting with ACPI: acpi_scan_init is called at subsys_initcall level (the same level with X-Gene MSI driver):
acpi_init
acpi_bus_init (GIC is initialized here)
acpi_scan_init
acpi_pci_root_init
acpi_pci_link_init
...
acpi_bus_scan
acpi_bus_check_add
...

Currently, in DSDT table, X-Gene MSI node is defined right after X-Gene PCIe nodes. So PCIe driver initialization and PCIe enumeration happens before MSI driver is initialized. During PCIe bus scan, the pci_set_bus_msi_domain gets a NULL irq_domain value from pci_host_bridge_msi_domain (as MSI driver is not initialized), so there is no MSI support for PCIe bus.

+ Using pci_msi_create_default_irq_domain() helps MSI allocation succeed as pci_msi_get_domain (in the code path of pci_enable_msix_exact above) can fall back to get a valid domain from arch_get_pci_msi_domain (please note that PCIe endpoint driver gets called later (at device_initcall level (using module_init)), so at the time PCIe endpoint driver probe function executes, the MSI driver already register the global MSI domain with pci_msi_create_default_irq_domain)

Quoted 8 lines

+ If changing DSDT node ordering, to define MSI node before PCIe nodes, then X-Gene MSI driver will be loaded before PCIe host driver. At the time PCIe enumeration happens, X-Gene MSI driver already registered a valid MSI domain (by calling pci_msi_register_fwnode_provider to register the fwnode provider function), so all the detected PCIe buses (and PCIe endpoint devices) will have a valid MSI domain attached to them (as a result of function pci_set_bus_msi_domain)

This still works out of sheer luck, given that relying on initcall ordering at same init level is undefined (ie it works if your msi driver registration call is executed before acpi_init() is called).

I though about using a scan handler like:

See arch/ia64/hp/common/sba_iommu.c acpi_sba_ioc_handler

but that won't solve your problem either since, given that PNP0A03 (ie PCI host bridge) is handled through a scan handler too, IIUC you will still have issues related to namespace device nodes ordering.

I suspect we will have to add a hook walking the ACPI namespace before acpi_bus_scan() is called in acpi_scan_init() (aka MSI controllers must be probed before any other device is, that's the gist), I CC'ed Rafael to see if there is any other suitable way to sort out this issue.

Thanks,
Lorenzo

author
#14 lore raw
Quoted 205 lines · Lorenzo Pieralisi

[+ Rafael]

Quoted 184 lines · Duc Dang

Hi Lorenzo,

Quoted 107 lines · Lorenzo Pieralisi

Hi Duc,

Quoted 96 lines · Duc Dang
Quoted 75 lines · Lorenzo Pieralisi
Quoted 67 lines · Duc Dang
Quoted 59 lines · Marc Zyngier
Quoted 48 lines · Mark Salter
Quoted 47 lines · Duc Dang

This patch makes pci-xgene-msi driver ACPI-aware and provides MSI capability for X-Gene v1 PCIe controllers in ACPI boot mode.

---
 drivers/pci/host/pci-xgene-msi.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/pci/host/pci-xgene-msi.c +9 -1
index a6456b5..466aa93 100644
@@ -24,6 +24,7 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/of_pci.h>
+#include <linux/acpi.h>
 
 #define MSI_IR0                     0x000000
 #define MSI_INT0            0x800000
@@ -39,7 +40,7 @@ struct xgene_msi_group {
 };
 
 struct xgene_msi {
-    struct device_node      *node;
+    struct fwnode_handle    *fwnode;
     struct irq_domain       *inner_domain;
     struct irq_domain       *msi_domain;
     u64                     msi_addr;
@@ -249,6 +250,13 @@ static const struct irq_domain_ops msi_domain_ops = {
     .free   = xgene_irq_domain_free,
 };
 
+#ifdef CONFIG_ACPI
+static struct fwnode_handle *xgene_msi_get_fwnode(struct device *dev)
+{
+    return xgene_msi_ctrl.fwnode;
+}
+#endif
+
 static int xgene_allocate_domains(struct xgene_msi *msi)
 {
     msi->inner_domain = irq_domain_add_linear(NULL, NR_MSI_VEC,
@@ -256,7 +264,7 @@ static int xgene_allocate_domains(struct xgene_msi *msi)
     if (!msi->inner_domain)
             return -ENOMEM;
 
Quoted 9 lines

drivers/pci/host/pci-xgene-msi.c static int xgene_allocate_domains(struct xgene_msi *msi) · line 269

Quoted 4 lines
drivers/pci/host/pci-xgene-msi.c +1 -1
-    msi->msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(msi->node),
+    msi->msi_domain = pci_msi_create_irq_domain(msi->fwnode,
                                                 &xgene_msi_domain_info,
                                                 msi->inner_domain);

This doesn't work for me (ACPI probing on Mustang) unless I change this to be pci_msi_create_default_irq_domain(). The problem seems to be that the MSI probe happens after the PCIe RC is probed so there is no MSI domain at the time the PCIe root is initialized by ACPI.

Quoted 6 lines

pci_msi_create_default_irq_domain is the wrong thing do use, specially if you have multiple MSI controllers in the system. I certainly wouldn't want to see it being used on arm64.

This is the usual dependency hell. You try moving the probing earlier, but that may break something else in the process.

Quoted 6 lines

Hi Mark and Marc,

I have modified Tianocore firmware to have MSI node declared before PCIe node in Dsdt table. With this modification, the MSI driver will be loaded before PCIe driver and MSI domain is available at the time PCIe root is initialized.

Quoted 8 lines

I am totally against this. We should not hack ACPI tables to make the kernel work (on top of that with unwritten ordering rules that may well require changes as kernel evolves), we should have a standard set of bindings that people use to describe HW in the DSDT and the kernel(s) has to cope with that. If there is a dependency problem in the description we may solve it at bindings level, but I absolutely do not want to rely on DSDT nodes ordering for things to work, that's fragile, no shortcuts please.

Hi Lorenzo, Bjorn,

(Refresh this thread on this merge cycle)

I tried to use _DEP method to describe the dependency of PCIe node to MSI node but it turns out that PCIe driver does not check for the dependency (only EC (ec.c) and I2C core (i2c-core.c) use acpi_walk_dep_device_list to check for dependency before loading dependent drivers)

Quoted 3 lines

Do you have other suggestion/example about how to ensure strict ordering on driver loading in ACPI boot mode without changing the order of ACPI nodes in DSDT?

Before doing anything else, I would like to ask you to report the code paths leading to failures (what fails actually ?) please, and I want to understand what "this does not work" means.

Quoted 7 lines

In particular:

- Why using pci_msi_create_default_irq_domain() works
- Why, if you change the DSDT nodes ordering, things work (please add some debugging to MSI allocation functions to detect the code paths leading to correct MSI allocation)
- What's the difference wrt the DT probe path

The MSI allocation happens with following code path (I use PMC pm80xx SAS driver as an example (drivers/scsi/pm8001/pm8001_init.c)):
pci_enable_msix_exact

    pci_enable_msix_range
        pci_enable_msix
            msix_capbility_init
                pci_msi_setup_msi_irqs
                    pci_msi_get_domain
                        dev_get_msi_domain
                        arch_get_pci_msi_domain
                            return pci_msi_default_domain;

In my failing case: pci_msi_get_domain return NULL, so MSI allocation function (pci_enable_msix_exact) fails.

The expected MSI domain is registered when X-Gene MSI driver is initialized and is attached to each PCI bus by calling pci_set_bus_msi_domain during PCIe bus-scan:
pci_scan_root_bus
pci_scan_root_bus_msi
pci_scan_child_bus
pci_scan_bridge
pci_add_new_bus
pci_alloc_child_bus
pci_set_bus_msi_domain
pci_host_bridge_msi_domain
pci_host_bridge_of_msi_domain pci_host_bridge_acpi_msi_domain

+ When booting with DT: X-Gene MSI driver is initialized early (subsys_initcall level); X-Gene PCIe driver is initialized later at device_initcall level (using module_platform_driver). Because of that when PCIe enumeration happens, the X-Gene MSI domain was already registered and available. So when the driver of PCIe Endpoint devices gets loaded, the call to pci_enable_msix_exact (to allocate MSI) succeeds.

+ When booting with ACPI: acpi_scan_init is called at subsys_initcall level (the same level with X-Gene MSI driver):
acpi_init
acpi_bus_init (GIC is initialized here)
acpi_scan_init
acpi_pci_root_init
acpi_pci_link_init
...
acpi_bus_scan
acpi_bus_check_add
...

Currently, in DSDT table, X-Gene MSI node is defined right after X-Gene PCIe nodes. So PCIe driver initialization and PCIe enumeration happens before MSI driver is initialized. During PCIe bus scan, the pci_set_bus_msi_domain gets a NULL irq_domain value from pci_host_bridge_msi_domain (as MSI driver is not initialized), so there is no MSI support for PCIe bus.

+ Using pci_msi_create_default_irq_domain() helps MSI allocation succeed as pci_msi_get_domain (in the code path of pci_enable_msix_exact above) can fall back to get a valid domain from arch_get_pci_msi_domain (please note that PCIe endpoint driver gets called later (at device_initcall level (using module_init)), so at the time PCIe endpoint driver probe function executes, the MSI driver already register the global MSI domain with pci_msi_create_default_irq_domain)

Quoted 8 lines

+ If changing DSDT node ordering, to define MSI node before PCIe nodes, then X-Gene MSI driver will be loaded before PCIe host driver. At the time PCIe enumeration happens, X-Gene MSI driver already registered a valid MSI domain (by calling pci_msi_register_fwnode_provider to register the fwnode provider function), so all the detected PCIe buses (and PCIe endpoint devices) will have a valid MSI domain attached to them (as a result of function pci_set_bus_msi_domain)

This still works out of sheer luck, given that relying on initcall ordering at same init level is undefined (ie it works if your msi driver registration call is executed before acpi_init() is called).

I though about using a scan handler like:

See arch/ia64/hp/common/sba_iommu.c acpi_sba_ioc_handler

Quoted 8 lines

but that won't solve your problem either since, given that PNP0A03 (ie PCI host bridge) is handled through a scan handler too, IIUC you will still have issues related to namespace device nodes ordering.

I suspect we will have to add a hook walking the ACPI namespace before acpi_bus_scan() is called in acpi_scan_init() (aka MSI controllers must be probed before any other device is, that's the gist), I CC'ed Rafael to see if there is any other suitable way to sort out this issue.

Thanks for your input, Lorenzo.

Hi Rafael,

Do you have other suggestions? Otherwise, I will prepare a patch following Lorenzo's approach.

Regards,
Duc Dang.

Quoted 3 lines

Thanks,
Lorenzo

#15 lore raw
Quoted 2 lines · Duc Dang

Do you have other suggestions? Otherwise, I will prepare a patch following Lorenzo's approach.

Duc has since left Applied for other pastures. I miss him, he's a great guy. He laid all the right groundwork for this, but the ACPI binding still needs to be upstreamed. It's a few lines of code matching on APMC0D0E but without it, upstream kernels wont have working MSI on X-Gene with ACPI. I need this to be upstreamed soon please :) Can someone at APM followup with an updated patch, and get it in?

Here's the rub. The average person booting a Linux box (even a good kernel person) isn't going to say "hey, MSIs aren't setup right on this ARM server because it's compliant with 1 out of 3 possible ways MSIs might be done at a high level [let's forget the many others] and all it needs is this...". What they're going to say is "huh, PCIe card doesn't work, might be an MSI problem". Which is the email I have after someone tried using an IB card in an X-Gene box and spent a few hours poking.

We're so close to having "ACPI all the things" but the latest development builds of RHEL don't do MSI on X-Gene because of the Red Hat "upstream first" rules. So let's get that fixed.

Thanks,

Jon.

Signature · 1 line
Computer Architect | Sent from my Fedora powered laptop