genirq/irqdomain: Allow irq domain aliasing

It is not uncommon (at least with the ARM stuff) to have a piece
of hardware that implements different flavours of "interrupts".
A typical example of this is the GICv3 ITS, which implements
standard PCI/MSI support, but also some form of "generic MSI".

So far, the PCI/MSI domain is registered using the ITS device_node,
so that irq_find_host can return it. On the contrary, the raw MSI
domain is not registered with an device_node, making it impossible
to be looked up by another subsystem (obviously, using the same
device_node twice would only result in confusion, as it is not
defined which one irq_find_host would return).

A solution to this is to "type" domains that may be aliasing, and
to be able to lookup an device_node that matches a given type.
For this, we introduce irq_find_matching_host() as a superset
of irq_find_host:

struct irq_domain *irq_find_matching_host(struct device_node *node,
                                enum irq_domain_bus_token bus_token);

where bus_token is the "type" we want to match the domain against
(so far, only DOMAIN_BUS_ANY is defined). This result in some
moderately invasive changes on the PPC side (which is the only
user of the .match method).

This has otherwise no functionnal change.

Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: Yijing Wang <wangyijing@huawei.com>
Cc: Ma Jun <majun258@huawei.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Duc Dang <dhdang@apm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Jason Cooper <jason@lakedaemon.net>
Link: http://lkml.kernel.org/r/1438091186-10244-2-git-send-email-marc.zyngier@arm.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
Marc Zyngier 2015-07-28 14:46:08 +01:00 committed by Thomas Gleixner
parent 8505a81bb0
commit ad3aedfbb0
14 changed files with 58 additions and 19 deletions

View File

@ -123,7 +123,8 @@ cpld_pic_cascade(unsigned int irq, struct irq_desc *desc)
} }
static int static int
cpld_pic_host_match(struct irq_domain *h, struct device_node *node) cpld_pic_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
return cpld_pic_node == node; return cpld_pic_node == node;
} }

View File

@ -222,7 +222,8 @@ void iic_request_IPIs(void)
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
static int iic_host_match(struct irq_domain *h, struct device_node *node) static int iic_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
return of_device_is_compatible(node, return of_device_is_compatible(node,
"IBM,CBEA-Internal-Interrupt-Controller"); "IBM,CBEA-Internal-Interrupt-Controller");

View File

@ -108,7 +108,8 @@ static int flipper_pic_map(struct irq_domain *h, unsigned int virq,
return 0; return 0;
} }
static int flipper_pic_match(struct irq_domain *h, struct device_node *np) static int flipper_pic_match(struct irq_domain *h, struct device_node *np,
enum irq_domain_bus_token bus_token)
{ {
return 1; return 1;
} }

View File

@ -268,7 +268,8 @@ static struct irqaction gatwick_cascade_action = {
.name = "cascade", .name = "cascade",
}; };
static int pmac_pic_host_match(struct irq_domain *h, struct device_node *node) static int pmac_pic_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
/* We match all, we don't always have a node anyway */ /* We match all, we don't always have a node anyway */
return 1; return 1;

View File

@ -134,7 +134,8 @@ static void opal_handle_irq_work(struct irq_work *work)
opal_handle_events(be64_to_cpu(last_outstanding_events)); opal_handle_events(be64_to_cpu(last_outstanding_events));
} }
static int opal_event_match(struct irq_domain *h, struct device_node *node) static int opal_event_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
return h->of_node == node; return h->of_node == node;
} }

View File

@ -678,7 +678,8 @@ static int ps3_host_map(struct irq_domain *h, unsigned int virq,
return 0; return 0;
} }
static int ps3_host_match(struct irq_domain *h, struct device_node *np) static int ps3_host_match(struct irq_domain *h, struct device_node *np,
enum irq_domain_bus_token bus_token)
{ {
/* Match all */ /* Match all */
return 1; return 1;

View File

@ -177,7 +177,8 @@ unsigned int ehv_pic_get_irq(void)
return irq_linear_revmap(global_ehv_pic->irqhost, irq); return irq_linear_revmap(global_ehv_pic->irqhost, irq);
} }
static int ehv_pic_host_match(struct irq_domain *h, struct device_node *node) static int ehv_pic_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
/* Exact match, unless ehv_pic node is NULL */ /* Exact match, unless ehv_pic node is NULL */
return h->of_node == NULL || h->of_node == node; return h->of_node == NULL || h->of_node == node;

View File

@ -162,7 +162,8 @@ static struct resource pic_edgectrl_iores = {
.flags = IORESOURCE_BUSY, .flags = IORESOURCE_BUSY,
}; };
static int i8259_host_match(struct irq_domain *h, struct device_node *node) static int i8259_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
return h->of_node == NULL || h->of_node == node; return h->of_node == NULL || h->of_node == node;
} }

View File

@ -671,7 +671,8 @@ static struct irq_chip ipic_edge_irq_chip = {
.irq_set_type = ipic_set_irq_type, .irq_set_type = ipic_set_irq_type,
}; };
static int ipic_host_match(struct irq_domain *h, struct device_node *node) static int ipic_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
/* Exact match, unless ipic node is NULL */ /* Exact match, unless ipic node is NULL */
return h->of_node == NULL || h->of_node == node; return h->of_node == NULL || h->of_node == node;

View File

@ -1007,7 +1007,8 @@ static struct irq_chip mpic_irq_ht_chip = {
#endif /* CONFIG_MPIC_U3_HT_IRQS */ #endif /* CONFIG_MPIC_U3_HT_IRQS */
static int mpic_host_match(struct irq_domain *h, struct device_node *node) static int mpic_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
/* Exact match, unless mpic node is NULL */ /* Exact match, unless mpic node is NULL */
return h->of_node == NULL || h->of_node == node; return h->of_node == NULL || h->of_node == node;

View File

@ -244,7 +244,8 @@ static struct irq_chip qe_ic_irq_chip = {
.irq_mask_ack = qe_ic_mask_irq, .irq_mask_ack = qe_ic_mask_irq,
}; };
static int qe_ic_host_match(struct irq_domain *h, struct device_node *node) static int qe_ic_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
/* Exact match, unless qe_ic node is NULL */ /* Exact match, unless qe_ic node is NULL */
return h->of_node == NULL || h->of_node == node; return h->of_node == NULL || h->of_node == node;

View File

@ -298,7 +298,8 @@ int xics_get_irq_server(unsigned int virq, const struct cpumask *cpumask,
} }
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
static int xics_host_match(struct irq_domain *h, struct device_node *node) static int xics_host_match(struct irq_domain *h, struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
struct ics *ics; struct ics *ics;

View File

@ -45,6 +45,17 @@ struct irq_data;
/* Number of irqs reserved for a legacy isa controller */ /* Number of irqs reserved for a legacy isa controller */
#define NUM_ISA_INTERRUPTS 16 #define NUM_ISA_INTERRUPTS 16
/*
* Should several domains have the same device node, but serve
* different purposes (for example one domain is for PCI/MSI, and the
* other for wired IRQs), they can be distinguished using a
* bus-specific token. Most domains are expected to only carry
* DOMAIN_BUS_ANY.
*/
enum irq_domain_bus_token {
DOMAIN_BUS_ANY = 0,
};
/** /**
* struct irq_domain_ops - Methods for irq_domain objects * struct irq_domain_ops - Methods for irq_domain objects
* @match: Match an interrupt controller device node to a host, returns * @match: Match an interrupt controller device node to a host, returns
@ -61,7 +72,8 @@ struct irq_data;
* to setup the irq_desc when returning from map(). * to setup the irq_desc when returning from map().
*/ */
struct irq_domain_ops { struct irq_domain_ops {
int (*match)(struct irq_domain *d, struct device_node *node); int (*match)(struct irq_domain *d, struct device_node *node,
enum irq_domain_bus_token bus_token);
int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw); int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw);
void (*unmap)(struct irq_domain *d, unsigned int virq); void (*unmap)(struct irq_domain *d, unsigned int virq);
int (*xlate)(struct irq_domain *d, struct device_node *node, int (*xlate)(struct irq_domain *d, struct device_node *node,
@ -116,6 +128,7 @@ struct irq_domain {
/* Optional data */ /* Optional data */
struct device_node *of_node; struct device_node *of_node;
enum irq_domain_bus_token bus_token;
struct irq_domain_chip_generic *gc; struct irq_domain_chip_generic *gc;
#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
struct irq_domain *parent; struct irq_domain *parent;
@ -161,9 +174,15 @@ struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
irq_hw_number_t first_hwirq, irq_hw_number_t first_hwirq,
const struct irq_domain_ops *ops, const struct irq_domain_ops *ops,
void *host_data); void *host_data);
extern struct irq_domain *irq_find_host(struct device_node *node); extern struct irq_domain *irq_find_matching_host(struct device_node *node,
enum irq_domain_bus_token bus_token);
extern void irq_set_default_host(struct irq_domain *host); extern void irq_set_default_host(struct irq_domain *host);
static inline struct irq_domain *irq_find_host(struct device_node *node)
{
return irq_find_matching_host(node, DOMAIN_BUS_ANY);
}
/** /**
* irq_domain_add_linear() - Allocate and register a linear revmap irq_domain. * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
* @of_node: pointer to interrupt controller's device tree node. * @of_node: pointer to interrupt controller's device tree node.

View File

@ -187,10 +187,12 @@ struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
EXPORT_SYMBOL_GPL(irq_domain_add_legacy); EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
/** /**
* irq_find_host() - Locates a domain for a given device node * irq_find_matching_host() - Locates a domain for a given device node
* @node: device-tree node of the interrupt controller * @node: device-tree node of the interrupt controller
* @bus_token: domain-specific data
*/ */
struct irq_domain *irq_find_host(struct device_node *node) struct irq_domain *irq_find_matching_host(struct device_node *node,
enum irq_domain_bus_token bus_token)
{ {
struct irq_domain *h, *found = NULL; struct irq_domain *h, *found = NULL;
int rc; int rc;
@ -199,13 +201,19 @@ struct irq_domain *irq_find_host(struct device_node *node)
* it might potentially be set to match all interrupts in * it might potentially be set to match all interrupts in
* the absence of a device node. This isn't a problem so far * the absence of a device node. This isn't a problem so far
* yet though... * yet though...
*
* bus_token == DOMAIN_BUS_ANY matches any domain, any other
* values must generate an exact match for the domain to be
* selected.
*/ */
mutex_lock(&irq_domain_mutex); mutex_lock(&irq_domain_mutex);
list_for_each_entry(h, &irq_domain_list, link) { list_for_each_entry(h, &irq_domain_list, link) {
if (h->ops->match) if (h->ops->match)
rc = h->ops->match(h, node); rc = h->ops->match(h, node, bus_token);
else else
rc = (h->of_node != NULL) && (h->of_node == node); rc = ((h->of_node != NULL) && (h->of_node == node) &&
((bus_token == DOMAIN_BUS_ANY) ||
(h->bus_token == bus_token)));
if (rc) { if (rc) {
found = h; found = h;
@ -215,7 +223,7 @@ struct irq_domain *irq_find_host(struct device_node *node)
mutex_unlock(&irq_domain_mutex); mutex_unlock(&irq_domain_mutex);
return found; return found;
} }
EXPORT_SYMBOL_GPL(irq_find_host); EXPORT_SYMBOL_GPL(irq_find_matching_host);
/** /**
* irq_set_default_host() - Set a "default" irq domain * irq_set_default_host() - Set a "default" irq domain