2017-12-27 11:55:14 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2010-06-18 10:09:59 -07:00
|
|
|
/*
|
|
|
|
* Derived from arch/i386/kernel/irq.c
|
|
|
|
* Copyright (C) 1992 Linus Torvalds
|
|
|
|
* Adapted from arch/i386 by Gary Thomas
|
|
|
|
* Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
|
|
|
|
* Updated and modified by Cort Dougan <cort@fsmlabs.com>
|
|
|
|
* Copyright (C) 1996-2001 Cort Dougan
|
|
|
|
* Adapted for Power Macintosh by Paul Mackerras
|
|
|
|
* Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
|
|
|
|
*
|
|
|
|
* This file contains the code used to make IRQ descriptions in the
|
|
|
|
* device tree to actual irq numbers on an interrupt controller
|
|
|
|
* driver.
|
|
|
|
*/
|
|
|
|
|
2016-06-15 06:32:18 -07:00
|
|
|
#define pr_fmt(fmt) "OF: " fmt
|
|
|
|
|
2015-07-28 06:46:15 -07:00
|
|
|
#include <linux/device.h>
|
2010-06-18 10:09:59 -07:00
|
|
|
#include <linux/errno.h>
|
2011-09-20 13:13:50 -07:00
|
|
|
#include <linux/list.h>
|
2010-06-18 10:09:59 -07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/string.h>
|
2011-09-20 13:13:50 -07:00
|
|
|
#include <linux/slab.h>
|
2010-06-18 10:09:59 -07:00
|
|
|
|
2024-05-29 12:59:20 -07:00
|
|
|
#include "of_private.h"
|
|
|
|
|
2010-06-18 10:09:59 -07:00
|
|
|
/**
|
|
|
|
* irq_of_parse_and_map - Parse and map an interrupt into linux virq space
|
2013-08-30 18:44:10 -07:00
|
|
|
* @dev: Device node of the device whose interrupt is to be mapped
|
2010-06-18 10:09:59 -07:00
|
|
|
* @index: Index of the interrupt to map
|
|
|
|
*
|
2013-09-19 09:22:36 -07:00
|
|
|
* This function is a wrapper that chains of_irq_parse_one() and
|
2010-06-18 10:09:59 -07:00
|
|
|
* irq_create_of_mapping() to make things easier to callers
|
|
|
|
*/
|
|
|
|
unsigned int irq_of_parse_and_map(struct device_node *dev, int index)
|
|
|
|
{
|
2013-09-15 08:39:11 -07:00
|
|
|
struct of_phandle_args oirq;
|
2010-06-18 10:09:59 -07:00
|
|
|
|
2013-09-19 09:22:36 -07:00
|
|
|
if (of_irq_parse_one(dev, index, &oirq))
|
2011-12-06 16:16:26 -07:00
|
|
|
return 0;
|
2010-06-18 10:09:59 -07:00
|
|
|
|
2013-09-15 08:55:53 -07:00
|
|
|
return irq_create_of_mapping(&oirq);
|
2010-06-18 10:09:59 -07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(irq_of_parse_and_map);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* of_irq_find_parent - Given a device node, find its interrupt parent node
|
|
|
|
* @child: pointer to device node
|
|
|
|
*
|
2021-03-25 09:47:12 -07:00
|
|
|
* Return: A pointer to the interrupt parent node, or NULL if the interrupt
|
2010-06-08 06:48:06 -07:00
|
|
|
* parent could not be determined.
|
|
|
|
*/
|
2015-12-01 09:24:17 -07:00
|
|
|
struct device_node *of_irq_find_parent(struct device_node *child)
|
2010-06-08 06:48:06 -07:00
|
|
|
{
|
2011-11-22 16:09:20 -07:00
|
|
|
struct device_node *p;
|
2017-07-08 13:29:52 -07:00
|
|
|
phandle parent;
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2011-11-22 16:09:20 -07:00
|
|
|
if (!of_node_get(child))
|
2010-06-08 06:48:06 -07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
do {
|
2017-07-08 13:29:52 -07:00
|
|
|
if (of_property_read_u32(child, "interrupt-parent", &parent)) {
|
2011-11-22 16:09:20 -07:00
|
|
|
p = of_get_parent(child);
|
2017-07-08 13:29:52 -07:00
|
|
|
} else {
|
2010-06-08 06:48:06 -07:00
|
|
|
if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
|
|
|
|
p = of_node_get(of_irq_dflt_pic);
|
|
|
|
else
|
2017-07-08 13:29:52 -07:00
|
|
|
p = of_find_node_by_phandle(parent);
|
2010-06-08 06:48:06 -07:00
|
|
|
}
|
2011-11-22 16:09:20 -07:00
|
|
|
of_node_put(child);
|
|
|
|
child = p;
|
2010-06-08 06:48:06 -07:00
|
|
|
} while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL);
|
|
|
|
|
2011-11-22 16:09:20 -07:00
|
|
|
return p;
|
2010-06-08 06:48:06 -07:00
|
|
|
}
|
2015-12-01 09:24:17 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_irq_find_parent);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2021-12-01 04:41:02 -07:00
|
|
|
/*
|
|
|
|
* These interrupt controllers abuse interrupt-map for unspeakable
|
|
|
|
* reasons and rely on the core code to *ignore* it (the drivers do
|
2024-07-02 14:42:46 -07:00
|
|
|
* their own parsing of the property). The PAsemi entry covers a
|
|
|
|
* non-sensical interrupt-map that is better left ignored.
|
2021-12-01 04:41:02 -07:00
|
|
|
*
|
|
|
|
* If you think of adding to the list for something *new*, think
|
|
|
|
* again. There is a high chance that you will be sent back to the
|
|
|
|
* drawing board.
|
|
|
|
*/
|
|
|
|
static const char * const of_irq_imap_abusers[] = {
|
|
|
|
"CBEA,platform-spider-pic",
|
|
|
|
"sti,platform-spider-pic",
|
|
|
|
"realtek,rtl-intc",
|
|
|
|
"fsl,ls1021a-extirq",
|
|
|
|
"fsl,ls1043a-extirq",
|
|
|
|
"fsl,ls1088a-extirq",
|
|
|
|
"renesas,rza1-irqc",
|
2024-07-02 14:42:46 -07:00
|
|
|
"pasemi,rootbus",
|
2021-12-01 04:41:02 -07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2024-05-29 12:59:20 -07:00
|
|
|
const __be32 *of_irq_parse_imap_parent(const __be32 *imap, int len, struct of_phandle_args *out_irq)
|
|
|
|
{
|
|
|
|
u32 intsize, addrsize;
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
/* Get the interrupt parent */
|
|
|
|
if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
|
|
|
|
np = of_node_get(of_irq_dflt_pic);
|
|
|
|
else
|
|
|
|
np = of_find_node_by_phandle(be32_to_cpup(imap));
|
|
|
|
imap++;
|
|
|
|
|
|
|
|
/* Check if not found */
|
|
|
|
if (!np) {
|
|
|
|
pr_debug(" -> imap parent not found !\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get #interrupt-cells and #address-cells of new parent */
|
|
|
|
if (of_property_read_u32(np, "#interrupt-cells",
|
|
|
|
&intsize)) {
|
|
|
|
pr_debug(" -> parent lacks #interrupt-cells!\n");
|
|
|
|
of_node_put(np);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (of_property_read_u32(np, "#address-cells",
|
|
|
|
&addrsize))
|
|
|
|
addrsize = 0;
|
|
|
|
|
|
|
|
pr_debug(" -> intsize=%d, addrsize=%d\n",
|
|
|
|
intsize, addrsize);
|
|
|
|
|
|
|
|
/* Check for malformed properties */
|
|
|
|
if (WARN_ON(addrsize + intsize > MAX_PHANDLE_ARGS)
|
|
|
|
|| (len < (addrsize + intsize))) {
|
|
|
|
of_node_put(np);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug(" -> imaplen=%d\n", len);
|
|
|
|
|
|
|
|
imap += addrsize + intsize;
|
|
|
|
|
|
|
|
out_irq->np = np;
|
|
|
|
for (int i = 0; i < intsize; i++)
|
|
|
|
out_irq->args[i] = be32_to_cpup(imap - intsize + i);
|
|
|
|
out_irq->args_count = intsize;
|
|
|
|
|
|
|
|
return imap;
|
|
|
|
}
|
|
|
|
|
2010-06-08 06:48:06 -07:00
|
|
|
/**
|
2013-09-19 09:22:36 -07:00
|
|
|
* of_irq_parse_raw - Low level interrupt tree parsing
|
2013-09-15 14:32:39 -07:00
|
|
|
* @addr: address specifier (start of "reg" property of the device) in be32 format
|
2017-12-06 15:43:34 -07:00
|
|
|
* @out_irq: structure of_phandle_args updated by this function
|
2010-06-08 06:48:06 -07:00
|
|
|
*
|
|
|
|
* This function is a low-level interrupt tree walking function. It
|
|
|
|
* can be used to do a partial walk with synthetized reg and interrupts
|
|
|
|
* properties, for example when resolving PCI interrupts when no device
|
2013-09-15 14:32:39 -07:00
|
|
|
* node exist for the parent. It takes an interrupt specifier structure as
|
|
|
|
* input, walks the tree looking for any interrupt-map properties, translates
|
|
|
|
* the specifier for each map, and then returns the translated map.
|
2021-03-25 09:47:12 -07:00
|
|
|
*
|
|
|
|
* Return: 0 on success and a negative number on error
|
2010-06-08 06:48:06 -07:00
|
|
|
*/
|
2013-09-15 14:32:39 -07:00
|
|
|
int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
|
2010-06-08 06:48:06 -07:00
|
|
|
{
|
2024-05-29 12:59:20 -07:00
|
|
|
struct device_node *ipar, *tnode, *old = NULL;
|
2013-11-02 00:11:02 -07:00
|
|
|
__be32 initial_match_array[MAX_PHANDLE_ARGS];
|
2013-09-15 14:32:39 -07:00
|
|
|
const __be32 *match_array = initial_match_array;
|
2024-05-29 12:59:20 -07:00
|
|
|
const __be32 *tmp, dummy_imask[] = { [0 ... MAX_PHANDLE_ARGS] = cpu_to_be32(~0) };
|
|
|
|
u32 intsize = 1, addrsize;
|
|
|
|
int i, rc = -EINVAL;
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2013-10-11 14:05:10 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
of_print_phandle_args("of_irq_parse_raw: ", out_irq);
|
|
|
|
#endif
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2013-09-15 14:32:39 -07:00
|
|
|
ipar = of_node_get(out_irq->np);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/* First get the #interrupt-cells property of the current cursor
|
|
|
|
* that tells us how to interpret the passed-in intspec. If there
|
|
|
|
* is none, we are nice and just walk up the tree
|
|
|
|
*/
|
|
|
|
do {
|
2017-07-08 13:29:52 -07:00
|
|
|
if (!of_property_read_u32(ipar, "#interrupt-cells", &intsize))
|
2010-06-08 06:48:06 -07:00
|
|
|
break;
|
|
|
|
tnode = ipar;
|
|
|
|
ipar = of_irq_find_parent(ipar);
|
|
|
|
of_node_put(tnode);
|
|
|
|
} while (ipar);
|
|
|
|
if (ipar == NULL) {
|
|
|
|
pr_debug(" -> no parent found !\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:50:55 -07:00
|
|
|
pr_debug("of_irq_parse_raw: ipar=%pOF, size=%d\n", ipar, intsize);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2013-09-15 14:32:39 -07:00
|
|
|
if (out_irq->args_count != intsize)
|
of/irq: improve error report on irq discovery process failure
On PowerPC machines some PCI slots might not have level triggered
interrupts capability (also know as level signaled interrupts),
leading of_irq_parse_pci() to complain by presenting error messages
on the kernel log - in this case, the properties "interrupt-map" and
"interrupt-map-mask" are not present on device's node in the device
tree.
This patch introduces a different message for this specific case,
and also reduces its level from error to warning. Besides, we warn
(once) that possibly some PCI slots on the system have no level
triggered interrupts available.
We changed some error return codes too on function of_irq_parse_raw()
in order other failure's cases can be presented in a more precise way.
Before this patch, when an adapter was plugged in a slot without level
interrupts capabilitiy on PowerPC, we saw a generic error message
like this:
[54.239] pci 002d:70:00.0: of_irq_parse_pci() failed with rc=-22
Now, with this applied, we see the following specific message:
[16.154] pci 0014:60:00.1: of_irq_parse_pci: no interrupt-map found,
INTx interrupts not available
Finally, we standardize the error path in of_irq_parse_raw() by always
taking the fail path instead of returning directly from the loop.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
2016-12-05 06:59:16 -07:00
|
|
|
goto fail;
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/* Look for this #address-cells. We have to implement the old linux
|
|
|
|
* trick of looking for the parent here as some device-trees rely on it
|
|
|
|
*/
|
|
|
|
old = of_node_get(ipar);
|
|
|
|
do {
|
|
|
|
tmp = of_get_property(old, "#address-cells", NULL);
|
|
|
|
tnode = of_get_parent(old);
|
|
|
|
of_node_put(old);
|
|
|
|
old = tnode;
|
|
|
|
} while (old && tmp == NULL);
|
|
|
|
of_node_put(old);
|
|
|
|
old = NULL;
|
2010-06-08 06:48:08 -07:00
|
|
|
addrsize = (tmp == NULL) ? 2 : be32_to_cpu(*tmp);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
pr_debug(" -> addrsize=%d\n", addrsize);
|
|
|
|
|
2013-11-02 00:11:02 -07:00
|
|
|
/* Range check so that the temporary buffer doesn't overflow */
|
of/irq: improve error report on irq discovery process failure
On PowerPC machines some PCI slots might not have level triggered
interrupts capability (also know as level signaled interrupts),
leading of_irq_parse_pci() to complain by presenting error messages
on the kernel log - in this case, the properties "interrupt-map" and
"interrupt-map-mask" are not present on device's node in the device
tree.
This patch introduces a different message for this specific case,
and also reduces its level from error to warning. Besides, we warn
(once) that possibly some PCI slots on the system have no level
triggered interrupts available.
We changed some error return codes too on function of_irq_parse_raw()
in order other failure's cases can be presented in a more precise way.
Before this patch, when an adapter was plugged in a slot without level
interrupts capabilitiy on PowerPC, we saw a generic error message
like this:
[54.239] pci 002d:70:00.0: of_irq_parse_pci() failed with rc=-22
Now, with this applied, we see the following specific message:
[16.154] pci 0014:60:00.1: of_irq_parse_pci: no interrupt-map found,
INTx interrupts not available
Finally, we standardize the error path in of_irq_parse_raw() by always
taking the fail path instead of returning directly from the loop.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
2016-12-05 06:59:16 -07:00
|
|
|
if (WARN_ON(addrsize + intsize > MAX_PHANDLE_ARGS)) {
|
|
|
|
rc = -EFAULT;
|
2013-11-02 00:11:02 -07:00
|
|
|
goto fail;
|
of/irq: improve error report on irq discovery process failure
On PowerPC machines some PCI slots might not have level triggered
interrupts capability (also know as level signaled interrupts),
leading of_irq_parse_pci() to complain by presenting error messages
on the kernel log - in this case, the properties "interrupt-map" and
"interrupt-map-mask" are not present on device's node in the device
tree.
This patch introduces a different message for this specific case,
and also reduces its level from error to warning. Besides, we warn
(once) that possibly some PCI slots on the system have no level
triggered interrupts available.
We changed some error return codes too on function of_irq_parse_raw()
in order other failure's cases can be presented in a more precise way.
Before this patch, when an adapter was plugged in a slot without level
interrupts capabilitiy on PowerPC, we saw a generic error message
like this:
[54.239] pci 002d:70:00.0: of_irq_parse_pci() failed with rc=-22
Now, with this applied, we see the following specific message:
[16.154] pci 0014:60:00.1: of_irq_parse_pci: no interrupt-map found,
INTx interrupts not available
Finally, we standardize the error path in of_irq_parse_raw() by always
taking the fail path instead of returning directly from the loop.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
2016-12-05 06:59:16 -07:00
|
|
|
}
|
2013-11-02 00:11:02 -07:00
|
|
|
|
2013-09-15 14:32:39 -07:00
|
|
|
/* Precalculate the match array - this simplifies match loop */
|
|
|
|
for (i = 0; i < addrsize; i++)
|
2013-11-01 10:50:50 -07:00
|
|
|
initial_match_array[i] = addr ? addr[i] : 0;
|
2013-09-15 14:32:39 -07:00
|
|
|
for (i = 0; i < intsize; i++)
|
|
|
|
initial_match_array[addrsize + i] = cpu_to_be32(out_irq->args[i]);
|
|
|
|
|
2010-06-08 06:48:06 -07:00
|
|
|
/* Now start the actual "proper" walk of the interrupt tree */
|
|
|
|
while (ipar != NULL) {
|
2024-05-29 12:59:20 -07:00
|
|
|
int imaplen, match;
|
|
|
|
const __be32 *imap, *oldimap, *imask;
|
|
|
|
struct device_node *newpar;
|
2021-09-29 09:38:35 -07:00
|
|
|
/*
|
|
|
|
* Now check if cursor is an interrupt-controller and
|
|
|
|
* if it is then we are done, unless there is an
|
2021-12-01 04:41:02 -07:00
|
|
|
* interrupt-map which takes precedence except on one
|
|
|
|
* of these broken platforms that want to parse
|
|
|
|
* interrupt-map themselves for $reason.
|
2010-06-08 06:48:06 -07:00
|
|
|
*/
|
2021-11-12 07:10:39 -07:00
|
|
|
bool intc = of_property_read_bool(ipar, "interrupt-controller");
|
|
|
|
|
2021-09-29 09:38:35 -07:00
|
|
|
imap = of_get_property(ipar, "interrupt-map", &imaplen);
|
2021-12-01 04:41:02 -07:00
|
|
|
if (intc &&
|
|
|
|
(!imap || of_device_compatible_match(ipar, of_irq_imap_abusers))) {
|
2010-06-08 06:48:06 -07:00
|
|
|
pr_debug(" -> got it !\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-01 10:50:50 -07:00
|
|
|
/*
|
|
|
|
* interrupt-map parsing does not work without a reg
|
|
|
|
* property when #address-cells != 0
|
|
|
|
*/
|
|
|
|
if (addrsize && !addr) {
|
|
|
|
pr_debug(" -> no reg passed in when needed !\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-06-08 06:48:06 -07:00
|
|
|
/* No interrupt map, check for an interrupt parent */
|
|
|
|
if (imap == NULL) {
|
|
|
|
pr_debug(" -> no map, getting parent\n");
|
|
|
|
newpar = of_irq_find_parent(ipar);
|
|
|
|
goto skiplevel;
|
|
|
|
}
|
|
|
|
imaplen /= sizeof(u32);
|
|
|
|
|
|
|
|
/* Look for a mask */
|
|
|
|
imask = of_get_property(ipar, "interrupt-map-mask", NULL);
|
2013-09-15 14:32:39 -07:00
|
|
|
if (!imask)
|
|
|
|
imask = dummy_imask;
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/* Parse interrupt-map */
|
|
|
|
match = 0;
|
2024-05-29 12:59:20 -07:00
|
|
|
while (imaplen > (addrsize + intsize + 1)) {
|
2010-06-08 06:48:06 -07:00
|
|
|
/* Compare specifiers */
|
|
|
|
match = 1;
|
2013-09-15 14:32:39 -07:00
|
|
|
for (i = 0; i < (addrsize + intsize); i++, imaplen--)
|
2013-11-05 08:21:18 -07:00
|
|
|
match &= !((match_array[i] ^ *imap++) & imask[i]);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
pr_debug(" -> match=%d (imaplen=%d)\n", match, imaplen);
|
|
|
|
|
2024-05-29 12:59:20 -07:00
|
|
|
oldimap = imap;
|
|
|
|
imap = of_irq_parse_imap_parent(oldimap, imaplen, out_irq);
|
|
|
|
if (!imap)
|
2010-06-08 06:48:06 -07:00
|
|
|
goto fail;
|
|
|
|
|
2024-05-29 12:59:20 -07:00
|
|
|
match &= of_device_is_available(out_irq->np);
|
|
|
|
if (match)
|
|
|
|
break;
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2024-05-29 12:59:20 -07:00
|
|
|
of_node_put(out_irq->np);
|
|
|
|
imaplen -= imap - oldimap;
|
2010-06-08 06:48:06 -07:00
|
|
|
pr_debug(" -> imaplen=%d\n", imaplen);
|
|
|
|
}
|
2024-07-02 14:42:46 -07:00
|
|
|
if (!match)
|
2010-06-08 06:48:06 -07:00
|
|
|
goto fail;
|
|
|
|
|
2013-09-15 14:32:39 -07:00
|
|
|
/*
|
2022-05-21 04:11:09 -07:00
|
|
|
* Successfully parsed an interrupt-map translation; copy new
|
2013-09-15 14:32:39 -07:00
|
|
|
* interrupt specifier into the out_irq structure
|
|
|
|
*/
|
2024-05-29 12:59:20 -07:00
|
|
|
match_array = oldimap + 1;
|
|
|
|
|
|
|
|
newpar = out_irq->np;
|
|
|
|
intsize = out_irq->args_count;
|
|
|
|
addrsize = (imap - match_array) - intsize;
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2021-09-29 09:38:35 -07:00
|
|
|
if (ipar == newpar) {
|
|
|
|
pr_debug("%pOF interrupt-map entry to self\n", ipar);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-08 06:48:06 -07:00
|
|
|
skiplevel:
|
|
|
|
/* Iterate again with new parent */
|
2017-06-01 13:50:55 -07:00
|
|
|
pr_debug(" -> new parent: %pOF\n", newpar);
|
2010-06-08 06:48:06 -07:00
|
|
|
of_node_put(ipar);
|
|
|
|
ipar = newpar;
|
|
|
|
newpar = NULL;
|
|
|
|
}
|
of/irq: improve error report on irq discovery process failure
On PowerPC machines some PCI slots might not have level triggered
interrupts capability (also know as level signaled interrupts),
leading of_irq_parse_pci() to complain by presenting error messages
on the kernel log - in this case, the properties "interrupt-map" and
"interrupt-map-mask" are not present on device's node in the device
tree.
This patch introduces a different message for this specific case,
and also reduces its level from error to warning. Besides, we warn
(once) that possibly some PCI slots on the system have no level
triggered interrupts available.
We changed some error return codes too on function of_irq_parse_raw()
in order other failure's cases can be presented in a more precise way.
Before this patch, when an adapter was plugged in a slot without level
interrupts capabilitiy on PowerPC, we saw a generic error message
like this:
[54.239] pci 002d:70:00.0: of_irq_parse_pci() failed with rc=-22
Now, with this applied, we see the following specific message:
[16.154] pci 0014:60:00.1: of_irq_parse_pci: no interrupt-map found,
INTx interrupts not available
Finally, we standardize the error path in of_irq_parse_raw() by always
taking the fail path instead of returning directly from the loop.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
2016-12-05 06:59:16 -07:00
|
|
|
rc = -ENOENT; /* No interrupt-map found */
|
|
|
|
|
2010-06-08 06:48:06 -07:00
|
|
|
fail:
|
|
|
|
of_node_put(ipar);
|
|
|
|
|
of/irq: improve error report on irq discovery process failure
On PowerPC machines some PCI slots might not have level triggered
interrupts capability (also know as level signaled interrupts),
leading of_irq_parse_pci() to complain by presenting error messages
on the kernel log - in this case, the properties "interrupt-map" and
"interrupt-map-mask" are not present on device's node in the device
tree.
This patch introduces a different message for this specific case,
and also reduces its level from error to warning. Besides, we warn
(once) that possibly some PCI slots on the system have no level
triggered interrupts available.
We changed some error return codes too on function of_irq_parse_raw()
in order other failure's cases can be presented in a more precise way.
Before this patch, when an adapter was plugged in a slot without level
interrupts capabilitiy on PowerPC, we saw a generic error message
like this:
[54.239] pci 002d:70:00.0: of_irq_parse_pci() failed with rc=-22
Now, with this applied, we see the following specific message:
[16.154] pci 0014:60:00.1: of_irq_parse_pci: no interrupt-map found,
INTx interrupts not available
Finally, we standardize the error path in of_irq_parse_raw() by always
taking the fail path instead of returning directly from the loop.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Signed-off-by: Rob Herring <robh@kernel.org>
2016-12-05 06:59:16 -07:00
|
|
|
return rc;
|
2010-06-08 06:48:06 -07:00
|
|
|
}
|
2013-09-19 09:22:36 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_irq_parse_raw);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/**
|
2013-09-19 09:22:36 -07:00
|
|
|
* of_irq_parse_one - Resolve an interrupt for a device
|
2010-06-08 06:48:06 -07:00
|
|
|
* @device: the device whose interrupt is to be resolved
|
|
|
|
* @index: index of the interrupt to resolve
|
2019-08-07 06:22:31 -07:00
|
|
|
* @out_irq: structure of_phandle_args filled by this function
|
2010-06-08 06:48:06 -07:00
|
|
|
*
|
2013-09-15 14:32:39 -07:00
|
|
|
* This function resolves an interrupt for a node by walking the interrupt tree,
|
|
|
|
* finding which interrupt controller node it is attached to, and returning the
|
|
|
|
* interrupt specifier that can be used to retrieve a Linux IRQ number.
|
2010-06-08 06:48:06 -07:00
|
|
|
*/
|
2013-09-15 08:39:11 -07:00
|
|
|
int of_irq_parse_one(struct device_node *device, int index, struct of_phandle_args *out_irq)
|
2010-06-08 06:48:06 -07:00
|
|
|
{
|
|
|
|
struct device_node *p;
|
2017-07-21 14:56:12 -07:00
|
|
|
const __be32 *addr;
|
|
|
|
u32 intsize;
|
2024-08-12 03:06:51 -07:00
|
|
|
int i, res, addr_len;
|
|
|
|
__be32 addr_buf[3] = { 0 };
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2017-06-01 13:50:55 -07:00
|
|
|
pr_debug("of_irq_parse_one: dev=%pOF, index=%d\n", device, index);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/* OldWorld mac stuff is "special", handle out of line */
|
|
|
|
if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
|
2013-09-19 09:22:36 -07:00
|
|
|
return of_irq_parse_oldworld(device, index, out_irq);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2013-09-19 14:47:37 -07:00
|
|
|
/* Get the reg property (if any) */
|
2024-08-12 03:06:51 -07:00
|
|
|
addr = of_get_property(device, "reg", &addr_len);
|
|
|
|
|
|
|
|
/* Prevent out-of-bounds read in case of longer interrupt parent address size */
|
2024-08-20 05:16:53 -07:00
|
|
|
if (addr_len > sizeof(addr_buf))
|
|
|
|
addr_len = sizeof(addr_buf);
|
2024-08-12 03:06:51 -07:00
|
|
|
if (addr)
|
|
|
|
memcpy(addr_buf, addr, addr_len);
|
2013-09-19 14:47:37 -07:00
|
|
|
|
2014-08-06 13:02:27 -07:00
|
|
|
/* Try the new-style interrupts-extended first */
|
|
|
|
res = of_parse_phandle_with_args(device, "interrupts-extended",
|
|
|
|
"#interrupt-cells", index, out_irq);
|
|
|
|
if (!res)
|
2024-08-12 03:06:51 -07:00
|
|
|
return of_irq_parse_raw(addr_buf, out_irq);
|
2014-08-06 13:02:27 -07:00
|
|
|
|
2010-06-08 06:48:06 -07:00
|
|
|
/* Look for the interrupt parent. */
|
|
|
|
p = of_irq_find_parent(device);
|
|
|
|
if (p == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Get size of interrupt specifier */
|
2017-07-08 13:29:52 -07:00
|
|
|
if (of_property_read_u32(p, "#interrupt-cells", &intsize)) {
|
2015-03-17 15:21:32 -07:00
|
|
|
res = -EINVAL;
|
2010-06-08 06:48:06 -07:00
|
|
|
goto out;
|
2015-03-17 15:21:32 -07:00
|
|
|
}
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2017-07-21 14:56:12 -07:00
|
|
|
pr_debug(" parent=%pOF, intsize=%d\n", p, intsize);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
2013-09-15 14:32:39 -07:00
|
|
|
/* Copy intspec into irq structure */
|
|
|
|
out_irq->np = p;
|
|
|
|
out_irq->args_count = intsize;
|
2017-07-21 14:56:12 -07:00
|
|
|
for (i = 0; i < intsize; i++) {
|
|
|
|
res = of_property_read_u32_index(device, "interrupts",
|
|
|
|
(index * intsize) + i,
|
|
|
|
out_irq->args + i);
|
|
|
|
if (res)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug(" intspec=%d\n", *out_irq->args);
|
|
|
|
|
2013-09-15 14:32:39 -07:00
|
|
|
|
|
|
|
/* Check if there are any interrupt-map translations to process */
|
2024-08-12 03:06:51 -07:00
|
|
|
res = of_irq_parse_raw(addr_buf, out_irq);
|
2010-06-08 06:48:06 -07:00
|
|
|
out:
|
|
|
|
of_node_put(p);
|
|
|
|
return res;
|
|
|
|
}
|
2013-09-19 09:22:36 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_irq_parse_one);
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* of_irq_to_resource - Decode a node's IRQ and return it as a resource
|
|
|
|
* @dev: pointer to device tree node
|
|
|
|
* @index: zero-based index of the irq
|
|
|
|
* @r: pointer to resource structure to return result into.
|
|
|
|
*/
|
|
|
|
int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
|
|
|
|
{
|
2017-05-16 05:09:04 -07:00
|
|
|
int irq = of_irq_get(dev, index);
|
|
|
|
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
2010-06-08 06:48:06 -07:00
|
|
|
|
|
|
|
/* Only dereference the resource if both the
|
|
|
|
* resource and the irq are valid. */
|
2011-12-06 16:16:26 -07:00
|
|
|
if (r && irq) {
|
2011-12-05 07:23:56 -07:00
|
|
|
const char *name = NULL;
|
|
|
|
|
2013-07-18 03:24:10 -07:00
|
|
|
memset(r, 0, sizeof(*r));
|
2011-12-05 07:23:56 -07:00
|
|
|
/*
|
2014-04-22 11:40:25 -07:00
|
|
|
* Get optional "interrupt-names" property to add a name
|
2011-12-05 07:23:56 -07:00
|
|
|
* to the resource.
|
|
|
|
*/
|
|
|
|
of_property_read_string_index(dev, "interrupt-names", index,
|
|
|
|
&name);
|
|
|
|
|
2024-09-12 15:16:05 -07:00
|
|
|
*r = DEFINE_RES_IRQ_NAMED(irq, name ?: of_node_full_name(dev));
|
|
|
|
r->flags |= irq_get_trigger_type(irq);
|
2010-06-08 06:48:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(of_irq_to_resource);
|
2010-10-10 20:35:05 -07:00
|
|
|
|
2014-04-23 15:57:41 -07:00
|
|
|
/**
|
2016-05-28 13:02:50 -07:00
|
|
|
* of_irq_get - Decode a node's IRQ and return it as a Linux IRQ number
|
2014-04-23 15:57:41 -07:00
|
|
|
* @dev: pointer to device tree node
|
2016-05-28 13:02:50 -07:00
|
|
|
* @index: zero-based index of the IRQ
|
2014-04-23 15:57:41 -07:00
|
|
|
*
|
2021-03-25 09:47:12 -07:00
|
|
|
* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or
|
2016-05-28 13:02:50 -07:00
|
|
|
* -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case
|
|
|
|
* of any other failure.
|
2014-04-23 15:57:41 -07:00
|
|
|
*/
|
|
|
|
int of_irq_get(struct device_node *dev, int index)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct of_phandle_args oirq;
|
|
|
|
struct irq_domain *domain;
|
|
|
|
|
|
|
|
rc = of_irq_parse_one(dev, index, &oirq);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
domain = irq_find_host(oirq.np);
|
2023-01-17 07:49:29 -07:00
|
|
|
if (!domain) {
|
|
|
|
rc = -EPROBE_DEFER;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-04-23 15:57:41 -07:00
|
|
|
|
2023-01-17 07:49:29 -07:00
|
|
|
rc = irq_create_of_mapping(&oirq);
|
|
|
|
out:
|
|
|
|
of_node_put(oirq.np);
|
|
|
|
|
|
|
|
return rc;
|
2014-04-23 15:57:41 -07:00
|
|
|
}
|
2014-10-30 06:59:36 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_irq_get);
|
2014-04-23 15:57:41 -07:00
|
|
|
|
2014-05-20 03:42:02 -07:00
|
|
|
/**
|
2016-05-28 13:02:50 -07:00
|
|
|
* of_irq_get_byname - Decode a node's IRQ and return it as a Linux IRQ number
|
2014-05-20 03:42:02 -07:00
|
|
|
* @dev: pointer to device tree node
|
2016-05-28 13:02:50 -07:00
|
|
|
* @name: IRQ name
|
2014-05-20 03:42:02 -07:00
|
|
|
*
|
2021-03-25 09:47:12 -07:00
|
|
|
* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or
|
2016-05-28 13:02:50 -07:00
|
|
|
* -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case
|
|
|
|
* of any other failure.
|
2014-05-20 03:42:02 -07:00
|
|
|
*/
|
|
|
|
int of_irq_get_byname(struct device_node *dev, const char *name)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (unlikely(!name))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
index = of_property_match_string(dev, "interrupt-names", name);
|
|
|
|
if (index < 0)
|
|
|
|
return index;
|
|
|
|
|
|
|
|
return of_irq_get(dev, index);
|
|
|
|
}
|
2015-08-25 17:04:02 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_irq_get_byname);
|
2014-05-20 03:42:02 -07:00
|
|
|
|
2010-10-10 20:35:05 -07:00
|
|
|
/**
|
|
|
|
* of_irq_count - Count the number of IRQs a node uses
|
|
|
|
* @dev: pointer to device tree node
|
|
|
|
*/
|
|
|
|
int of_irq_count(struct device_node *dev)
|
|
|
|
{
|
2013-09-18 06:24:43 -07:00
|
|
|
struct of_phandle_args irq;
|
2010-10-10 20:35:05 -07:00
|
|
|
int nr = 0;
|
|
|
|
|
2013-09-18 06:24:43 -07:00
|
|
|
while (of_irq_parse_one(dev, nr, &irq) == 0)
|
2010-10-10 20:35:05 -07:00
|
|
|
nr++;
|
|
|
|
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* of_irq_to_resource_table - Fill in resource table with node's IRQ info
|
|
|
|
* @dev: pointer to device tree node
|
|
|
|
* @res: array of resources to fill in
|
|
|
|
* @nr_irqs: the number of IRQs (and upper bound for num of @res elements)
|
|
|
|
*
|
2021-03-25 09:47:12 -07:00
|
|
|
* Return: The size of the filled in table (up to @nr_irqs).
|
2010-10-10 20:35:05 -07:00
|
|
|
*/
|
|
|
|
int of_irq_to_resource_table(struct device_node *dev, struct resource *res,
|
|
|
|
int nr_irqs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_irqs; i++, res++)
|
2017-07-21 10:30:39 -07:00
|
|
|
if (of_irq_to_resource(dev, i, res) <= 0)
|
2010-10-10 20:35:05 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2012-08-26 00:13:09 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_irq_to_resource_table);
|
2011-09-20 13:13:50 -07:00
|
|
|
|
2015-06-26 05:42:45 -07:00
|
|
|
struct of_intc_desc {
|
2011-09-20 13:13:50 -07:00
|
|
|
struct list_head list;
|
2015-11-24 06:10:26 -07:00
|
|
|
of_irq_init_cb_t irq_init_cb;
|
2011-09-20 13:13:50 -07:00
|
|
|
struct device_node *dev;
|
|
|
|
struct device_node *interrupt_parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* of_irq_init - Scan and init matching interrupt controllers in DT
|
|
|
|
* @matches: 0 terminated array of nodes to match and init function to call
|
|
|
|
*
|
|
|
|
* This function scans the device tree for matching interrupt controller nodes,
|
|
|
|
* and calls their initialization functions in order with parents first.
|
|
|
|
*/
|
|
|
|
void __init of_irq_init(const struct of_device_id *matches)
|
|
|
|
{
|
2015-11-24 06:10:26 -07:00
|
|
|
const struct of_device_id *match;
|
2011-09-20 13:13:50 -07:00
|
|
|
struct device_node *np, *parent = NULL;
|
2015-06-26 05:42:45 -07:00
|
|
|
struct of_intc_desc *desc, *temp_desc;
|
2011-09-20 13:13:50 -07:00
|
|
|
struct list_head intc_desc_list, intc_parent_list;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&intc_desc_list);
|
|
|
|
INIT_LIST_HEAD(&intc_parent_list);
|
|
|
|
|
2015-11-24 06:10:26 -07:00
|
|
|
for_each_matching_node_and_match(np, matches, &match) {
|
2017-07-08 13:29:51 -07:00
|
|
|
if (!of_property_read_bool(np, "interrupt-controller") ||
|
2013-11-28 00:26:13 -07:00
|
|
|
!of_device_is_available(np))
|
2011-09-20 13:13:50 -07:00
|
|
|
continue;
|
2015-11-24 06:10:26 -07:00
|
|
|
|
|
|
|
if (WARN(!match->data, "of_irq_init: no init function for %s\n",
|
|
|
|
match->compatible))
|
|
|
|
continue;
|
|
|
|
|
2011-09-20 13:13:50 -07:00
|
|
|
/*
|
2015-06-26 05:42:45 -07:00
|
|
|
* Here, we allocate and populate an of_intc_desc with the node
|
2011-09-20 13:13:50 -07:00
|
|
|
* pointer, interrupt-parent device_node etc.
|
|
|
|
*/
|
|
|
|
desc = kzalloc(sizeof(*desc), GFP_KERNEL);
|
2019-05-02 05:40:15 -07:00
|
|
|
if (!desc) {
|
2015-10-22 02:02:51 -07:00
|
|
|
of_node_put(np);
|
2011-09-20 13:13:50 -07:00
|
|
|
goto err;
|
2015-10-22 02:02:51 -07:00
|
|
|
}
|
2011-09-20 13:13:50 -07:00
|
|
|
|
2015-11-24 06:10:26 -07:00
|
|
|
desc->irq_init_cb = match->data;
|
2015-10-22 02:02:51 -07:00
|
|
|
desc->dev = of_node_get(np);
|
of/irq: Use interrupts-extended to find parent
The RISC-V PLIC binding uses interrupts-extended to specify its parent
domain(s). That binding does not allow the interrupt-parent property to
appear in the irqchip node. This prevents of_irq_init from properly
detecting the irqchip hierarchy.
If no interrupt-parent property is present in the enclosing bus or root
node, then desc->interrupt_parent will be NULL for both the per-CPU
RISC-V INTC (the actual root domain) and the RISC-V PLIC. Similarly, if
the bus or root node specifies `interrupt-parent = <&plic>`, then
of_irq_init will hit the `desc->interrupt_parent == np` check, and again
all parents will be NULL. So things happen to work today for some boards
due to Makefile ordering.
However, things break when another irqchip ("foo") is stacked on top of
the PLIC. The bus or root node will have `interrupt-parent = <&foo>`,
since that is what all of the other peripherals need. When of_irq_init
runs, it will try to find the PLIC's parent domain. of_irq_find_parent
will fall back to using the interrupt-parent property of the PLIC's
parent node (i.e. the bus or root node), and of_irq_init will see "foo"
as the PLIC's parent domain. But this is wrong, because "foo" is
actually the PLIC's child domain!
So of_irq_init wrongly attempts to init the stacked irqchip before the
PLIC. This fails and breaks booting.
Fix this by using the first node referenced by interrupts-extended as
the parent when that property is present. This allows of_irq_init to see
the relationship between the PLIC and the per-CPU RISC-V INTC, and thus
only the RISC-V INTC is (correctly) considered a root domain.
Signed-off-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20220412051529.6293-1-samuel@sholland.org
2022-04-11 22:15:28 -07:00
|
|
|
/*
|
|
|
|
* interrupts-extended can reference multiple parent domains.
|
|
|
|
* Arbitrarily pick the first one; assume any other parents
|
|
|
|
* are the same distance away from the root irq controller.
|
|
|
|
*/
|
|
|
|
desc->interrupt_parent = of_parse_phandle(np, "interrupts-extended", 0);
|
|
|
|
if (!desc->interrupt_parent)
|
|
|
|
desc->interrupt_parent = of_irq_find_parent(np);
|
|
|
|
if (desc->interrupt_parent == np) {
|
|
|
|
of_node_put(desc->interrupt_parent);
|
2011-11-27 19:16:33 -07:00
|
|
|
desc->interrupt_parent = NULL;
|
of/irq: Use interrupts-extended to find parent
The RISC-V PLIC binding uses interrupts-extended to specify its parent
domain(s). That binding does not allow the interrupt-parent property to
appear in the irqchip node. This prevents of_irq_init from properly
detecting the irqchip hierarchy.
If no interrupt-parent property is present in the enclosing bus or root
node, then desc->interrupt_parent will be NULL for both the per-CPU
RISC-V INTC (the actual root domain) and the RISC-V PLIC. Similarly, if
the bus or root node specifies `interrupt-parent = <&plic>`, then
of_irq_init will hit the `desc->interrupt_parent == np` check, and again
all parents will be NULL. So things happen to work today for some boards
due to Makefile ordering.
However, things break when another irqchip ("foo") is stacked on top of
the PLIC. The bus or root node will have `interrupt-parent = <&foo>`,
since that is what all of the other peripherals need. When of_irq_init
runs, it will try to find the PLIC's parent domain. of_irq_find_parent
will fall back to using the interrupt-parent property of the PLIC's
parent node (i.e. the bus or root node), and of_irq_init will see "foo"
as the PLIC's parent domain. But this is wrong, because "foo" is
actually the PLIC's child domain!
So of_irq_init wrongly attempts to init the stacked irqchip before the
PLIC. This fails and breaks booting.
Fix this by using the first node referenced by interrupts-extended as
the parent when that property is present. This allows of_irq_init to see
the relationship between the PLIC and the per-CPU RISC-V INTC, and thus
only the RISC-V INTC is (correctly) considered a root domain.
Signed-off-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20220412051529.6293-1-samuel@sholland.org
2022-04-11 22:15:28 -07:00
|
|
|
}
|
2011-09-20 13:13:50 -07:00
|
|
|
list_add_tail(&desc->list, &intc_desc_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The root irq controller is the one without an interrupt-parent.
|
|
|
|
* That one goes first, followed by the controllers that reference it,
|
|
|
|
* followed by the ones that reference the 2nd level controllers, etc.
|
|
|
|
*/
|
|
|
|
while (!list_empty(&intc_desc_list)) {
|
|
|
|
/*
|
|
|
|
* Process all controllers with the current 'parent'.
|
|
|
|
* First pass will be looking for NULL as the parent.
|
|
|
|
* The assumption is that NULL parent means a root controller.
|
|
|
|
*/
|
|
|
|
list_for_each_entry_safe(desc, temp_desc, &intc_desc_list, list) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (desc->interrupt_parent != parent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_del(&desc->list);
|
|
|
|
|
2016-08-09 07:18:51 -07:00
|
|
|
of_node_set_flag(desc->dev, OF_POPULATED);
|
|
|
|
|
2017-06-01 13:50:55 -07:00
|
|
|
pr_debug("of_irq_init: init %pOF (%p), parent %p\n",
|
|
|
|
desc->dev,
|
2011-09-20 13:13:50 -07:00
|
|
|
desc->dev, desc->interrupt_parent);
|
2015-11-24 06:10:26 -07:00
|
|
|
ret = desc->irq_init_cb(desc->dev,
|
|
|
|
desc->interrupt_parent);
|
2011-09-20 13:13:50 -07:00
|
|
|
if (ret) {
|
2022-09-07 05:16:29 -07:00
|
|
|
pr_err("%s: Failed to init %pOF (%p), parent %p\n",
|
|
|
|
__func__, desc->dev, desc->dev,
|
|
|
|
desc->interrupt_parent);
|
2016-08-09 07:18:51 -07:00
|
|
|
of_node_clear_flag(desc->dev, OF_POPULATED);
|
2011-09-20 13:13:50 -07:00
|
|
|
kfree(desc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This one is now set up; add it to the parent list so
|
|
|
|
* its children can get processed in a subsequent pass.
|
|
|
|
*/
|
|
|
|
list_add_tail(&desc->list, &intc_parent_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the next pending parent that might have children */
|
2013-06-23 00:50:07 -07:00
|
|
|
desc = list_first_entry_or_null(&intc_parent_list,
|
|
|
|
typeof(*desc), list);
|
|
|
|
if (!desc) {
|
2011-09-20 13:13:50 -07:00
|
|
|
pr_err("of_irq_init: children remain, but no parents\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
list_del(&desc->list);
|
|
|
|
parent = desc->dev;
|
|
|
|
kfree(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry_safe(desc, temp_desc, &intc_parent_list, list) {
|
|
|
|
list_del(&desc->list);
|
|
|
|
kfree(desc);
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
list_for_each_entry_safe(desc, temp_desc, &intc_desc_list, list) {
|
|
|
|
list_del(&desc->list);
|
2015-10-22 02:02:51 -07:00
|
|
|
of_node_put(desc->dev);
|
2011-09-20 13:13:50 -07:00
|
|
|
kfree(desc);
|
|
|
|
}
|
|
|
|
}
|
2015-07-28 06:46:15 -07:00
|
|
|
|
2020-06-19 01:20:11 -07:00
|
|
|
static u32 __of_msi_map_id(struct device *dev, struct device_node **np,
|
|
|
|
u32 id_in)
|
2015-10-08 15:10:48 -07:00
|
|
|
{
|
|
|
|
struct device *parent_dev;
|
2020-06-19 01:20:11 -07:00
|
|
|
u32 id_out = id_in;
|
2015-10-08 15:10:48 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk up the device parent links looking for one with a
|
|
|
|
* "msi-map" property.
|
|
|
|
*/
|
2016-09-12 09:13:40 -07:00
|
|
|
for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent)
|
2020-06-19 01:20:11 -07:00
|
|
|
if (!of_map_id(parent_dev->of_node, id_in, "msi-map",
|
|
|
|
"msi-map-mask", np, &id_out))
|
2015-10-01 09:05:45 -07:00
|
|
|
break;
|
2020-06-19 01:20:11 -07:00
|
|
|
return id_out;
|
2015-10-08 15:10:48 -07:00
|
|
|
}
|
2015-09-18 06:07:40 -07:00
|
|
|
|
2015-10-01 09:05:45 -07:00
|
|
|
/**
|
2020-06-19 01:20:11 -07:00
|
|
|
* of_msi_map_id - Map a MSI ID for a device.
|
2015-10-01 09:05:45 -07:00
|
|
|
* @dev: device for which the mapping is to be done.
|
|
|
|
* @msi_np: device node of the expected msi controller.
|
2020-06-19 01:20:11 -07:00
|
|
|
* @id_in: unmapped MSI ID for the device.
|
2015-10-01 09:05:45 -07:00
|
|
|
*
|
|
|
|
* Walk up the device hierarchy looking for devices with a "msi-map"
|
2020-06-19 01:20:11 -07:00
|
|
|
* property. If found, apply the mapping to @id_in.
|
2015-10-01 09:05:45 -07:00
|
|
|
*
|
2021-03-25 09:47:12 -07:00
|
|
|
* Return: The mapped MSI ID.
|
2015-10-01 09:05:45 -07:00
|
|
|
*/
|
2020-06-19 01:20:11 -07:00
|
|
|
u32 of_msi_map_id(struct device *dev, struct device_node *msi_np, u32 id_in)
|
2015-10-01 09:05:45 -07:00
|
|
|
{
|
2020-06-19 01:20:11 -07:00
|
|
|
return __of_msi_map_id(dev, &msi_np, id_in);
|
2015-10-01 09:05:45 -07:00
|
|
|
}
|
|
|
|
|
2015-10-02 06:38:55 -07:00
|
|
|
/**
|
|
|
|
* of_msi_map_get_device_domain - Use msi-map to find the relevant MSI domain
|
|
|
|
* @dev: device for which the mapping is to be done.
|
2020-06-19 01:20:11 -07:00
|
|
|
* @id: Device ID.
|
2020-06-19 01:20:10 -07:00
|
|
|
* @bus_token: Bus token
|
2015-10-02 06:38:55 -07:00
|
|
|
*
|
|
|
|
* Walk up the device hierarchy looking for devices with a "msi-map"
|
|
|
|
* property.
|
|
|
|
*
|
|
|
|
* Returns: the MSI domain for this device (or NULL on failure)
|
|
|
|
*/
|
2020-06-19 01:20:10 -07:00
|
|
|
struct irq_domain *of_msi_map_get_device_domain(struct device *dev, u32 id,
|
|
|
|
u32 bus_token)
|
2015-10-02 06:38:55 -07:00
|
|
|
{
|
|
|
|
struct device_node *np = NULL;
|
|
|
|
|
2020-06-19 01:20:11 -07:00
|
|
|
__of_msi_map_id(dev, &np, id);
|
2020-06-19 01:20:10 -07:00
|
|
|
return irq_find_matching_host(np, bus_token);
|
2015-10-02 06:38:55 -07:00
|
|
|
}
|
|
|
|
|
2015-09-18 06:07:40 -07:00
|
|
|
/**
|
|
|
|
* of_msi_get_domain - Use msi-parent to find the relevant MSI domain
|
|
|
|
* @dev: device for which the domain is requested
|
|
|
|
* @np: device node for @dev
|
|
|
|
* @token: bus type for this domain
|
|
|
|
*
|
of/irq: Support #msi-cells=<0> in of_msi_get_domain
An 'msi-parent' property with a single entry and no accompanying
'#msi-cells' property is considered the legacy definition as opposed
to its definition after being expanded with commit 126b16e2ad98
("Docs: dt: add generic MSI bindings"). However, the legacy
definition is completely compatible with the current definition and,
since of_phandle_iterator_next() tolerates missing and present-but-
zero *cells properties since commit e42ee61017f5 ("of: Let
of_for_each_phandle fallback to non-negative cell_count"), there's no
need anymore to special case the legacy definition in
of_msi_get_domain().
Indeed, special casing has turned out to be harmful, because, as of
commit 7c025238b47a ("dt-bindings: irqchip: Describe the IMX MU block
as a MSI controller"), MSI controller DT bindings have started
specifying '#msi-cells' as a required property (even when the value
must be zero) as an effort to make the bindings more explicit. But,
since the special casing of 'msi-parent' only uses the existence of
'#msi-cells' for its heuristic, and not whether or not it's also
nonzero, the legacy path is not taken. Furthermore, the path to
support the new, broader definition isn't taken either since that
path has been restricted to the platform-msi bus.
But, neither the definition of 'msi-parent' nor the definition of
'#msi-cells' is platform-msi-specific (the platform-msi bus was just
the first bus that needed '#msi-cells'), so remove both the special
casing and the restriction. The code removal also requires changing
to of_parse_phandle_with_optional_args() in order to ensure the
legacy (but compatible) use of 'msi-parent' remains supported. This
not only simplifies the code but also resolves an issue with PCI
devices finding their MSI controllers on riscv, as the riscv,imsics
binding requires '#msi-cells=<0>'.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240817074107.31153-2-ajones@ventanamicro.com
Cc: stable@vger.kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2024-08-17 00:41:08 -07:00
|
|
|
* Parse the msi-parent property and returns the corresponding MSI domain.
|
2015-09-18 06:07:40 -07:00
|
|
|
*
|
|
|
|
* Returns: the MSI domain for this device (or NULL on failure).
|
|
|
|
*/
|
|
|
|
struct irq_domain *of_msi_get_domain(struct device *dev,
|
|
|
|
struct device_node *np,
|
|
|
|
enum irq_domain_bus_token token)
|
|
|
|
{
|
of/irq: Support #msi-cells=<0> in of_msi_get_domain
An 'msi-parent' property with a single entry and no accompanying
'#msi-cells' property is considered the legacy definition as opposed
to its definition after being expanded with commit 126b16e2ad98
("Docs: dt: add generic MSI bindings"). However, the legacy
definition is completely compatible with the current definition and,
since of_phandle_iterator_next() tolerates missing and present-but-
zero *cells properties since commit e42ee61017f5 ("of: Let
of_for_each_phandle fallback to non-negative cell_count"), there's no
need anymore to special case the legacy definition in
of_msi_get_domain().
Indeed, special casing has turned out to be harmful, because, as of
commit 7c025238b47a ("dt-bindings: irqchip: Describe the IMX MU block
as a MSI controller"), MSI controller DT bindings have started
specifying '#msi-cells' as a required property (even when the value
must be zero) as an effort to make the bindings more explicit. But,
since the special casing of 'msi-parent' only uses the existence of
'#msi-cells' for its heuristic, and not whether or not it's also
nonzero, the legacy path is not taken. Furthermore, the path to
support the new, broader definition isn't taken either since that
path has been restricted to the platform-msi bus.
But, neither the definition of 'msi-parent' nor the definition of
'#msi-cells' is platform-msi-specific (the platform-msi bus was just
the first bus that needed '#msi-cells'), so remove both the special
casing and the restriction. The code removal also requires changing
to of_parse_phandle_with_optional_args() in order to ensure the
legacy (but compatible) use of 'msi-parent' remains supported. This
not only simplifies the code but also resolves an issue with PCI
devices finding their MSI controllers on riscv, as the riscv,imsics
binding requires '#msi-cells=<0>'.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240817074107.31153-2-ajones@ventanamicro.com
Cc: stable@vger.kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2024-08-17 00:41:08 -07:00
|
|
|
struct of_phandle_iterator it;
|
2015-09-18 06:07:40 -07:00
|
|
|
struct irq_domain *d;
|
of/irq: Support #msi-cells=<0> in of_msi_get_domain
An 'msi-parent' property with a single entry and no accompanying
'#msi-cells' property is considered the legacy definition as opposed
to its definition after being expanded with commit 126b16e2ad98
("Docs: dt: add generic MSI bindings"). However, the legacy
definition is completely compatible with the current definition and,
since of_phandle_iterator_next() tolerates missing and present-but-
zero *cells properties since commit e42ee61017f5 ("of: Let
of_for_each_phandle fallback to non-negative cell_count"), there's no
need anymore to special case the legacy definition in
of_msi_get_domain().
Indeed, special casing has turned out to be harmful, because, as of
commit 7c025238b47a ("dt-bindings: irqchip: Describe the IMX MU block
as a MSI controller"), MSI controller DT bindings have started
specifying '#msi-cells' as a required property (even when the value
must be zero) as an effort to make the bindings more explicit. But,
since the special casing of 'msi-parent' only uses the existence of
'#msi-cells' for its heuristic, and not whether or not it's also
nonzero, the legacy path is not taken. Furthermore, the path to
support the new, broader definition isn't taken either since that
path has been restricted to the platform-msi bus.
But, neither the definition of 'msi-parent' nor the definition of
'#msi-cells' is platform-msi-specific (the platform-msi bus was just
the first bus that needed '#msi-cells'), so remove both the special
casing and the restriction. The code removal also requires changing
to of_parse_phandle_with_optional_args() in order to ensure the
legacy (but compatible) use of 'msi-parent' remains supported. This
not only simplifies the code but also resolves an issue with PCI
devices finding their MSI controllers on riscv, as the riscv,imsics
binding requires '#msi-cells=<0>'.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240817074107.31153-2-ajones@ventanamicro.com
Cc: stable@vger.kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2024-08-17 00:41:08 -07:00
|
|
|
int err;
|
2015-09-18 06:07:40 -07:00
|
|
|
|
of/irq: Support #msi-cells=<0> in of_msi_get_domain
An 'msi-parent' property with a single entry and no accompanying
'#msi-cells' property is considered the legacy definition as opposed
to its definition after being expanded with commit 126b16e2ad98
("Docs: dt: add generic MSI bindings"). However, the legacy
definition is completely compatible with the current definition and,
since of_phandle_iterator_next() tolerates missing and present-but-
zero *cells properties since commit e42ee61017f5 ("of: Let
of_for_each_phandle fallback to non-negative cell_count"), there's no
need anymore to special case the legacy definition in
of_msi_get_domain().
Indeed, special casing has turned out to be harmful, because, as of
commit 7c025238b47a ("dt-bindings: irqchip: Describe the IMX MU block
as a MSI controller"), MSI controller DT bindings have started
specifying '#msi-cells' as a required property (even when the value
must be zero) as an effort to make the bindings more explicit. But,
since the special casing of 'msi-parent' only uses the existence of
'#msi-cells' for its heuristic, and not whether or not it's also
nonzero, the legacy path is not taken. Furthermore, the path to
support the new, broader definition isn't taken either since that
path has been restricted to the platform-msi bus.
But, neither the definition of 'msi-parent' nor the definition of
'#msi-cells' is platform-msi-specific (the platform-msi bus was just
the first bus that needed '#msi-cells'), so remove both the special
casing and the restriction. The code removal also requires changing
to of_parse_phandle_with_optional_args() in order to ensure the
legacy (but compatible) use of 'msi-parent' remains supported. This
not only simplifies the code but also resolves an issue with PCI
devices finding their MSI controllers on riscv, as the riscv,imsics
binding requires '#msi-cells=<0>'.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240817074107.31153-2-ajones@ventanamicro.com
Cc: stable@vger.kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2024-08-17 00:41:08 -07:00
|
|
|
of_for_each_phandle(&it, err, np, "msi-parent", "#msi-cells", 0) {
|
|
|
|
d = irq_find_matching_host(it.node, token);
|
|
|
|
if (d)
|
|
|
|
return d;
|
2015-09-18 06:07:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-09-29 16:48:18 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_msi_get_domain);
|
2015-09-18 06:07:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* of_msi_configure - Set the msi_domain field of a device
|
|
|
|
* @dev: device structure to associate with an MSI irq domain
|
|
|
|
* @np: device node for that device
|
|
|
|
*/
|
|
|
|
void of_msi_configure(struct device *dev, struct device_node *np)
|
|
|
|
{
|
|
|
|
dev_set_msi_domain(dev,
|
|
|
|
of_msi_get_domain(dev, np, DOMAIN_BUS_PLATFORM_MSI));
|
|
|
|
}
|
2016-10-06 22:25:08 -07:00
|
|
|
EXPORT_SYMBOL_GPL(of_msi_configure);
|