Skip to content

Commit cef5075

Browse files
committed
irqdomain: merge linear and tree reverse mappings.
Keeping them separate makes irq_domain more complex and adds a lot of code (as proven by the diffstat). Merging them simplifies the whole scheme. This change makes it so both the tree and linear methods can be used by the same irq_domain instance. If the hwirq is less than the ->linear_size, then the linear map is used to reverse map the hwirq. Otherwise the radix tree is used. The test for which map to use is no more expensive that the existing code, so the performance of fast path is preserved. It also means that complex interrupt controllers can use both the linear map and a tree in the same domain. This may be useful for an interrupt controller with a base set of core irqs and a large number of GPIOs which might be used as irqs. The linear map could cover the core irqs, and the tree used for thas irqs. The linear map could cover the core irqs, and the tree used for the gpios. v2: Drop reorganization of revmap data Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Rob Herring <rob.herring@calxeda.com>
1 parent 0bb4afb commit cef5075

2 files changed

Lines changed: 39 additions & 86 deletions

File tree

‎include/linux/irqdomain.h‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct irq_domain_chip_generic;
7575
* @link: Element in global irq_domain list.
7676
* @revmap_type: Method used for reverse mapping hwirq numbers to linux irq. This
7777
* will be one of the IRQ_DOMAIN_MAP_* values.
78-
* @revmap_data: Revmap method specific data.
7978
* @ops: pointer to irq_domain methods
8079
* @host_data: private data pointer for use by owner. Not touched by irq_domain
8180
* core code.
@@ -93,10 +92,9 @@ struct irq_domain {
9392

9493
/* type of reverse mapping_technique */
9594
unsigned int revmap_type;
96-
union {
95+
struct {
9796
struct {
9897
unsigned int size;
99-
unsigned int *revmap;
10098
} linear;
10199
struct {
102100
unsigned int max_irq;
@@ -111,11 +109,13 @@ struct irq_domain {
111109
struct device_node *of_node;
112110
/* Optional pointer to generic interrupt chips */
113111
struct irq_domain_chip_generic *gc;
112+
113+
/* Linear reverse map */
114+
unsigned int linear_revmap[];
114115
};
115116

116117
#define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */
117118
#define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */
118-
#define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */
119119

120120
#ifdef CONFIG_IRQ_DOMAIN
121121
struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
@@ -137,10 +137,6 @@ struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
137137
unsigned int max_irq,
138138
const struct irq_domain_ops *ops,
139139
void *host_data);
140-
struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
141-
const struct irq_domain_ops *ops,
142-
void *host_data);
143-
144140
extern struct irq_domain *irq_find_host(struct device_node *node);
145141
extern void irq_set_default_host(struct irq_domain *host);
146142

@@ -152,6 +148,12 @@ static inline struct irq_domain *irq_domain_add_legacy_isa(
152148
return irq_domain_add_legacy(of_node, NUM_ISA_INTERRUPTS, 0, 0, ops,
153149
host_data);
154150
}
151+
static inline struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
152+
const struct irq_domain_ops *ops,
153+
void *host_data)
154+
{
155+
return irq_domain_add_linear(of_node, 0, ops, host_data);
156+
}
155157

156158
extern void irq_domain_remove(struct irq_domain *host);
157159

‎kernel/irq/irqdomain.c‎

Lines changed: 29 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,24 @@ static struct irq_domain *irq_default_domain;
3434
* to IRQ domain, or NULL on failure.
3535
*/
3636
static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
37-
unsigned int revmap_type,
37+
unsigned int revmap_type, int size,
3838
const struct irq_domain_ops *ops,
3939
void *host_data)
4040
{
4141
struct irq_domain *domain;
4242

43-
domain = kzalloc_node(sizeof(*domain), GFP_KERNEL,
44-
of_node_to_nid(of_node));
43+
domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
44+
GFP_KERNEL, of_node_to_nid(of_node));
4545
if (WARN_ON(!domain))
4646
return NULL;
4747

4848
/* Fill structure */
49+
INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
4950
domain->revmap_type = revmap_type;
5051
domain->ops = ops;
5152
domain->host_data = host_data;
5253
domain->of_node = of_node_get(of_node);
54+
domain->revmap_data.linear.size = size;
5355

5456
return domain;
5557
}
@@ -81,22 +83,12 @@ void irq_domain_remove(struct irq_domain *domain)
8183
{
8284
mutex_lock(&irq_domain_mutex);
8385

84-
switch (domain->revmap_type) {
85-
case IRQ_DOMAIN_MAP_TREE:
86-
/*
87-
* radix_tree_delete() takes care of destroying the root
88-
* node when all entries are removed. Shout if there are
89-
* any mappings left.
90-
*/
91-
WARN_ON(domain->revmap_data.tree.height);
92-
break;
93-
case IRQ_DOMAIN_MAP_LINEAR:
94-
kfree(domain->revmap_data.linear.revmap);
95-
domain->revmap_data.linear.size = 0;
96-
break;
97-
case IRQ_DOMAIN_MAP_NOMAP:
98-
break;
99-
}
86+
/*
87+
* radix_tree_delete() takes care of destroying the root
88+
* node when all entries are removed. Shout if there are
89+
* any mappings left.
90+
*/
91+
WARN_ON(domain->revmap_data.tree.height);
10092

10193
list_del(&domain->link);
10294

@@ -223,20 +215,11 @@ struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
223215
void *host_data)
224216
{
225217
struct irq_domain *domain;
226-
unsigned int *revmap;
227218

228-
revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
229-
of_node_to_nid(of_node));
230-
if (WARN_ON(!revmap))
219+
domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, size, ops, host_data);
220+
if (!domain)
231221
return NULL;
232222

233-
domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
234-
if (!domain) {
235-
kfree(revmap);
236-
return NULL;
237-
}
238-
domain->revmap_data.linear.size = size;
239-
domain->revmap_data.linear.revmap = revmap;
240223
irq_domain_add(domain);
241224
return domain;
242225
}
@@ -248,7 +231,7 @@ struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
248231
void *host_data)
249232
{
250233
struct irq_domain *domain = irq_domain_alloc(of_node,
251-
IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
234+
IRQ_DOMAIN_MAP_NOMAP, 0, ops, host_data);
252235
if (domain) {
253236
domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
254237
irq_domain_add(domain);
@@ -257,28 +240,6 @@ struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
257240
}
258241
EXPORT_SYMBOL_GPL(irq_domain_add_nomap);
259242

260-
/**
261-
* irq_domain_add_tree()
262-
* @of_node: pointer to interrupt controller's device tree node.
263-
* @ops: map/unmap domain callbacks
264-
*
265-
* Note: The radix tree will be allocated later during boot automatically
266-
* (the reverse mapping will use the slow path until that happens).
267-
*/
268-
struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
269-
const struct irq_domain_ops *ops,
270-
void *host_data)
271-
{
272-
struct irq_domain *domain = irq_domain_alloc(of_node,
273-
IRQ_DOMAIN_MAP_TREE, ops, host_data);
274-
if (domain) {
275-
INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
276-
irq_domain_add(domain);
277-
}
278-
return domain;
279-
}
280-
EXPORT_SYMBOL_GPL(irq_domain_add_tree);
281-
282243
/**
283244
* irq_find_host() - Locates a domain for a given device node
284245
* @node: device-tree node of the interrupt controller
@@ -359,17 +320,13 @@ static void irq_domain_disassociate_many(struct irq_domain *domain,
359320
irq_data->domain = NULL;
360321
irq_data->hwirq = 0;
361322

362-
/* Clear reverse map */
363-
switch(domain->revmap_type) {
364-
case IRQ_DOMAIN_MAP_LINEAR:
365-
if (hwirq < domain->revmap_data.linear.size)
366-
domain->revmap_data.linear.revmap[hwirq] = 0;
367-
break;
368-
case IRQ_DOMAIN_MAP_TREE:
323+
/* Clear reverse map for this hwirq */
324+
if (hwirq < domain->revmap_data.linear.size) {
325+
domain->linear_revmap[hwirq] = 0;
326+
} else {
369327
mutex_lock(&revmap_trees_mutex);
370328
radix_tree_delete(&domain->revmap_data.tree, hwirq);
371329
mutex_unlock(&revmap_trees_mutex);
372-
break;
373330
}
374331
}
375332
}
@@ -421,16 +378,12 @@ int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
421378
domain->name = irq_data->chip->name;
422379
}
423380

424-
switch (domain->revmap_type) {
425-
case IRQ_DOMAIN_MAP_LINEAR:
426-
if (hwirq < domain->revmap_data.linear.size)
427-
domain->revmap_data.linear.revmap[hwirq] = virq;
428-
break;
429-
case IRQ_DOMAIN_MAP_TREE:
381+
if (hwirq < domain->revmap_data.linear.size) {
382+
domain->linear_revmap[hwirq] = virq;
383+
} else {
430384
mutex_lock(&revmap_trees_mutex);
431385
radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
432386
mutex_unlock(&revmap_trees_mutex);
433-
break;
434387
}
435388

436389
irq_clear_status_flags(virq, IRQ_NOREQUEST);
@@ -667,13 +620,6 @@ unsigned int irq_find_mapping(struct irq_domain *domain,
667620
switch (domain->revmap_type) {
668621
case IRQ_DOMAIN_MAP_LINEAR:
669622
return irq_linear_revmap(domain, hwirq);
670-
case IRQ_DOMAIN_MAP_TREE:
671-
rcu_read_lock();
672-
data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
673-
rcu_read_unlock();
674-
if (data)
675-
return data->irq;
676-
break;
677623
case IRQ_DOMAIN_MAP_NOMAP:
678624
data = irq_get_irq_data(hwirq);
679625
if (data && (data->domain == domain) && (data->hwirq == hwirq))
@@ -696,13 +642,18 @@ EXPORT_SYMBOL_GPL(irq_find_mapping);
696642
unsigned int irq_linear_revmap(struct irq_domain *domain,
697643
irq_hw_number_t hwirq)
698644
{
645+
struct irq_data *data;
699646
BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
700647

701648
/* Check revmap bounds; complain if exceeded */
702-
if (WARN_ON(hwirq >= domain->revmap_data.linear.size))
703-
return 0;
649+
if (hwirq >= domain->revmap_data.linear.size) {
650+
rcu_read_lock();
651+
data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
652+
rcu_read_unlock();
653+
return data ? data->irq : 0;
654+
}
704655

705-
return domain->revmap_data.linear.revmap[hwirq];
656+
return domain->linear_revmap[hwirq];
706657
}
707658
EXPORT_SYMBOL_GPL(irq_linear_revmap);
708659

0 commit comments

Comments
 (0)