Skip to contentSkip to conversation

of: property: Add fw_devlink support for interrupt-map property

PATCH Superseded Anup Patel 3 participants 3 messages Apr 30, 2024 – May 9, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH v3 1/1 of: property: Add fw_devlink support for interrupt-map property

Some of the PCI controllers (such as generic PCI host controller) use "interrupt-map" DT property to describe the mapping between PCI endpoints and PCI interrupt pins. This the only case where the interrupts are not described in DT.

Currently, there is no fw_devlink created based on "interrupt-map" DT property so interrupt controller is not guaranteed to be probed before PCI host controller. This affects every platform where both PCI host controller and interrupt controllers are probed as regular platform devices.

This creates fw_devlink between consumers (PCI host controller) and supplier (interrupt controller) based on "interrupt-map" DT property.

---
Changes since v2:
- No need for a loop to find #interrupt-cells property value
- Fix node de-reference leak when index is greater than number of entries in interrupt-map property
Changes since v1:
- Updated commit description based on Rob's suggestion
- Use of_irq_parse_raw() for parsing interrupt-map DT property

---
 drivers/of/property.c | 50 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
drivers/of/property.c +50 -0
index a6358ee99b74..7326ca07adfe 100644
@@ -1311,6 +1311,55 @@ static struct device_node *parse_interrupts(struct device_node *np,
 	return of_irq_parse_one(np, index, &sup_args) ? NULL : sup_args.np;
 }
 
+static struct device_node *parse_interrupt_map(struct device_node *np,
+					       const char *prop_name, int index)
+{
+	const __be32 *imap, *imap_end, *addr;
+	struct of_phandle_args sup_args;
+	u32 addrcells, intcells;
+	int i, imaplen;
+
+	if (!IS_ENABLED(CONFIG_OF_IRQ))
+		return NULL;
+
+	if (strcmp(prop_name, "interrupt-map"))
+		return NULL;
+
+	if (of_property_read_u32(np, "#interrupt-cells", &intcells))
+		return NULL;
+	addrcells = of_bus_n_addr_cells(np);
+
+	imap = of_get_property(np, "interrupt-map", &imaplen);
+	if (!imap || imaplen <= (addrcells + intcells))
+		return NULL;
+	imap_end = imap + imaplen;
+
+	sup_args.np = NULL;
+	while (imap < imap_end) {
+		addr = imap;
+		imap += addrcells;
+
+		sup_args.np = np;
+		sup_args.args_count = intcells;
+		for (i = 0; i < intcells; i++)
+			sup_args.args[i] = be32_to_cpu(imap[i]);
+		imap += intcells;
+
+		if (of_irq_parse_raw(addr, &sup_args))
+			return NULL;
+
+		if (!index)
+			return sup_args.np;
+
+		of_node_put(sup_args.np);
+		sup_args.np = NULL;
+		imap += sup_args.args_count + 1;
+		index--;
+	}
+
+	return NULL;
+}
+
 static struct device_node *parse_remote_endpoint(struct device_node *np,
 						 const char *prop_name,
 						 int index)
@@ -1359,6 +1408,7 @@ static const struct supplier_bindings of_supplier_bindings[] = {
 	{ .parse_prop = parse_msi_parent, },
 	{ .parse_prop = parse_gpio_compat, },
 	{ .parse_prop = parse_interrupts, },
+	{ .parse_prop = parse_interrupt_map, },
 	{ .parse_prop = parse_regulators, },
 	{ .parse_prop = parse_gpio, },
 	{ .parse_prop = parse_gpios, },
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 61 lines · Anup Patel

Some of the PCI controllers (such as generic PCI host controller) use "interrupt-map" DT property to describe the mapping between PCI endpoints and PCI interrupt pins. This the only case where the interrupts are not described in DT.

Currently, there is no fw_devlink created based on "interrupt-map" DT property so interrupt controller is not guaranteed to be probed before PCI host controller. This affects every platform where both PCI host controller and interrupt controllers are probed as regular platform devices.

This creates fw_devlink between consumers (PCI host controller) and supplier (interrupt controller) based on "interrupt-map" DT property.

---
Changes since v2:
- No need for a loop to find #interrupt-cells property value
- Fix node de-reference leak when index is greater than number of entries in interrupt-map property
Changes since v1:
- Updated commit description based on Rob's suggestion
- Use of_irq_parse_raw() for parsing interrupt-map DT property

---
 drivers/of/property.c | 50 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
drivers/of/property.c +25 -0
index a6358ee99b74..7326ca07adfe 100644
@@ -1311,6 +1311,55 @@ static struct device_node *parse_interrupts(struct device_node *np,
        return of_irq_parse_one(np, index, &sup_args) ? NULL : sup_args.np;
 }
 
+static struct device_node *parse_interrupt_map(struct device_node *np,
+                                              const char *prop_name, int index)
+{
+       const __be32 *imap, *imap_end, *addr;
+       struct of_phandle_args sup_args;
+       u32 addrcells, intcells;
+       int i, imaplen;
+
+       if (!IS_ENABLED(CONFIG_OF_IRQ))
+               return NULL;
+
+       if (strcmp(prop_name, "interrupt-map"))
+               return NULL;
+
+       if (of_property_read_u32(np, "#interrupt-cells", &intcells))
+               return NULL;
+       addrcells = of_bus_n_addr_cells(np);
+
+       imap = of_get_property(np, "interrupt-map", &imaplen);
+       if (!imap || imaplen <= (addrcells + intcells))
+               return NULL;
+       imap_end = imap + imaplen;
+
+       sup_args.np = NULL;
+       while (imap < imap_end) {

drivers/of/property.c static struct device_node *parse_interrupts(struct device_node *np, · line 1348

Quoted 10 lines
drivers/of/property.c +10 -0
+               addr = imap;
+               imap += addrcells;
+
+               sup_args.np = np;
+               sup_args.args_count = intcells;
+               for (i = 0; i < intcells; i++)
+                       sup_args.args[i] = be32_to_cpu(imap[i]);
+               imap += intcells;
+
+               if (of_irq_parse_raw(addr, &sup_args))

Can you leave a comment above this call saying of_irq_parse_raw() updates sup_args.np? It's really a problem with the function IMO, but a comment here would be helpful.

drivers/of/property.c static struct device_node *parse_interrupts(struct device_node *np, · line 1355

Quoted 7 lines
drivers/of/property.c +7 -0
+                       return NULL;
+
+               if (!index)
+                       return sup_args.np;
+
+               of_node_put(sup_args.np);
+               sup_args.np = NULL;

Why do you need to set it to NULL? Can we just delete this line?

If you take care of these minor comments, then

-Saravana

Quoted 21 lines
drivers/of/property.c +8 -1
+               imap += sup_args.args_count + 1;
+               index--;
+       }
+
+       return NULL;
+}
+
 static struct device_node *parse_remote_endpoint(struct device_node *np,
                                                 const char *prop_name,
                                                 int index)
@@ -1359,6 +1408,7 @@ static const struct supplier_bindings of_supplier_bindings[] = {
        { .parse_prop = parse_msi_parent, },
        { .parse_prop = parse_gpio_compat, },
        { .parse_prop = parse_interrupts, },
+       { .parse_prop = parse_interrupt_map, },
        { .parse_prop = parse_regulators, },
        { .parse_prop = parse_gpio, },
        { .parse_prop = parse_gpios, },
--

2.34.1

#2 lore raw
Quoted 68 lines · Saravana Kannan
Quoted 66 lines · Anup Patel

Some of the PCI controllers (such as generic PCI host controller) use "interrupt-map" DT property to describe the mapping between PCI endpoints and PCI interrupt pins. This the only case where the interrupts are not described in DT.

Currently, there is no fw_devlink created based on "interrupt-map" DT property so interrupt controller is not guaranteed to be probed before PCI host controller. This affects every platform where both PCI host controller and interrupt controllers are probed as regular platform devices.

This creates fw_devlink between consumers (PCI host controller) and supplier (interrupt controller) based on "interrupt-map" DT property.

---
Changes since v2:
- No need for a loop to find #interrupt-cells property value
- Fix node de-reference leak when index is greater than number of entries in interrupt-map property
Changes since v1:
- Updated commit description based on Rob's suggestion
- Use of_irq_parse_raw() for parsing interrupt-map DT property

---
 drivers/of/property.c | 50 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
drivers/of/property.c +30 -0
index a6358ee99b74..7326ca07adfe 100644
@@ -1311,6 +1311,55 @@ static struct device_node *parse_interrupts(struct device_node *np,
        return of_irq_parse_one(np, index, &sup_args) ? NULL : sup_args.np;
 }
 
+static struct device_node *parse_interrupt_map(struct device_node *np,
+                                              const char *prop_name, int index)
+{
+       const __be32 *imap, *imap_end, *addr;
+       struct of_phandle_args sup_args;
+       u32 addrcells, intcells;
+       int i, imaplen;
+
+       if (!IS_ENABLED(CONFIG_OF_IRQ))
+               return NULL;
+
+       if (strcmp(prop_name, "interrupt-map"))
+               return NULL;
+
+       if (of_property_read_u32(np, "#interrupt-cells", &intcells))
+               return NULL;
+       addrcells = of_bus_n_addr_cells(np);
+
+       imap = of_get_property(np, "interrupt-map", &imaplen);
+       if (!imap || imaplen <= (addrcells + intcells))
+               return NULL;
+       imap_end = imap + imaplen;
+
+       sup_args.np = NULL;
+       while (imap < imap_end) {
+               addr = imap;
+               imap += addrcells;
+
+               sup_args.np = np;
+               sup_args.args_count = intcells;
Quoted 8 lines

drivers/of/property.c static struct device_node *parse_interrupts(struct device_node *np, · line 1348

Quoted 5 lines
drivers/of/property.c +5 -0
+               for (i = 0; i < intcells; i++)
+                       sup_args.args[i] = be32_to_cpu(imap[i]);
+               imap += intcells;
+
+               if (of_irq_parse_raw(addr, &sup_args))

Can you leave a comment above this call saying of_irq_parse_raw() updates sup_args.np? It's really a problem with the function IMO, but a comment here would be helpful.

Sure, I will add a comment about this.

Quoted 10 lines

drivers/of/property.c static struct device_node *parse_interrupts(struct device_node *np, · line 1355

Quoted 8 lines
drivers/of/property.c +7 -0
+                       return NULL;
+
+               if (!index)
+                       return sup_args.np;
+
+               of_node_put(sup_args.np);
+               sup_args.np = NULL;

Why do you need to set it to NULL? Can we just delete this line?

These NULL assignments are residue from previous revision. I will remove these assignments.

Quoted 20 lines

If you take care of these minor comments, then

-Saravana

Quoted 13 lines
drivers/of/property.c +7 -0
+               imap += sup_args.args_count + 1;
+               index--;
+       }
+
+       return NULL;
+}
+
 static struct device_node *parse_remote_endpoint(struct device_node *np,
                                                 const char *prop_name,
                                                 int index)
@@ -1359,6 +1408,7 @@ static const struct supplier_bindings of_supplier_bindings[] = {
        { .parse_prop = parse_msi_parent, },
        { .parse_prop = parse_gpio_compat, },
Quoted 8 lines
Quoted 8 lines
drivers/of/property.c +1 -1
        { .parse_prop = parse_interrupts, },
+       { .parse_prop = parse_interrupt_map, },
        { .parse_prop = parse_regulators, },
        { .parse_prop = parse_gpio, },
        { .parse_prop = parse_gpios, },
--

2.34.1

Thanks,
Anup