Skip to content

Commit 1aa0dd9

Browse files
committed
irqdomain: Eliminate revmap type
The NOMAP irq_domain type is only used by a handful of interrupt controllers and it unnecessarily complicates the code by adding special cases on how to look up mappings and different revmap functions are used for each type which need to validate the correct type is passed to it before performing the reverse map. Eliminating the revmap_type and making a single reverse mapping function simplifies the code. It also shouldn't be any slower than having separate revmap functions because the type of the revmap needed to be checked anyway. The linear and tree revmap types were already merged in a previous patch. This patch rolls the NOMAP or direct mapping behaviour into the same domain code making is possible for an irq domain to do any mapping type; linear, tree or direct; and that the mapping will be transparent to the interrupt controller driver. With this change, direct mappings will get stored in the linear or tree mapping for consistency. Reverse mapping from the hwirq to virq will go through the normal lookup process. However, any controller using a direct mapping can take advantage of knowing that hwirq==virq for any mapped interrupts skip doing a revmap lookup when handling IRQs. Signed-off-by: Grant Likely <grant.likely@linaro.org>
1 parent cef5075 commit 1aa0dd9

3 files changed

Lines changed: 43 additions & 65 deletions

File tree

‎include/linux/irqdomain.h‎

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,50 +73,42 @@ struct irq_domain_chip_generic;
7373
/**
7474
* struct irq_domain - Hardware interrupt number translation object
7575
* @link: Element in global irq_domain list.
76-
* @revmap_type: Method used for reverse mapping hwirq numbers to linux irq. This
77-
* will be one of the IRQ_DOMAIN_MAP_* values.
76+
* @name: Name of interrupt domain
7877
* @ops: pointer to irq_domain methods
7978
* @host_data: private data pointer for use by owner. Not touched by irq_domain
8079
* core code.
81-
* @irq_base: Start of irq_desc range assigned to the irq_domain. The creator
82-
* of the irq_domain is responsible for allocating the array of
83-
* irq_desc structures.
84-
* @nr_irq: Number of irqs managed by the irq domain
85-
* @hwirq_base: Starting number for hwirqs managed by the irq domain
86-
* @of_node: (optional) Pointer to device tree nodes associated with the
87-
* irq_domain. Used when decoding device tree interrupt specifiers.
80+
*
81+
* Optional elements
82+
* @of_node: Pointer to device tree nodes associated with the irq_domain. Used
83+
* when decoding device tree interrupt specifiers.
84+
* @gc: Pointer to a list of generic chips. There is a helper function for
85+
* setting up one or more generic chips for interrupt controllers
86+
* drivers using the generic chip library which uses this pointer.
87+
*
88+
* Revmap data, used internally by irq_domain
89+
* @revmap_direct_max_irq: The largest hwirq that can be set for controllers that
90+
* support direct mapping
91+
* @revmap_size: Size of the linear map table @linear_revmap[]
92+
* @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map
93+
* @linear_revmap: Linear table of hwirq->virq reverse mappings
8894
*/
8995
struct irq_domain {
9096
struct list_head link;
9197
const char *name;
92-
93-
/* type of reverse mapping_technique */
94-
unsigned int revmap_type;
95-
struct {
96-
struct {
97-
unsigned int size;
98-
} linear;
99-
struct {
100-
unsigned int max_irq;
101-
} nomap;
102-
struct radix_tree_root tree;
103-
} revmap_data;
10498
const struct irq_domain_ops *ops;
10599
void *host_data;
106-
irq_hw_number_t inval_irq;
107100

108-
/* Optional device node pointer */
101+
/* Optional data */
109102
struct device_node *of_node;
110-
/* Optional pointer to generic interrupt chips */
111103
struct irq_domain_chip_generic *gc;
112104

113-
/* Linear reverse map */
105+
/* reverse map data. The linear map gets appended to the irq_domain */
106+
unsigned int revmap_direct_max_irq;
107+
unsigned int revmap_size;
108+
struct radix_tree_root revmap_tree;
114109
unsigned int linear_revmap[];
115110
};
116111

117-
#define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */
118-
#define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */
119-
120112
#ifdef CONFIG_IRQ_DOMAIN
121113
struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
122114
unsigned int size,

‎kernel/irq/generic-chip.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,7 @@ int irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
270270
if (d->gc)
271271
return -EBUSY;
272272

273-
if (d->revmap_type != IRQ_DOMAIN_MAP_LINEAR)
274-
return -EINVAL;
275-
276-
numchips = d->revmap_data.linear.size / irqs_per_chip;
273+
numchips = d->revmap_size / irqs_per_chip;
277274
if (!numchips)
278275
return -EINVAL;
279276

‎kernel/irq/irqdomain.c‎

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ static struct irq_domain *irq_default_domain;
2525
/**
2626
* irq_domain_alloc() - Allocate a new irq_domain data structure
2727
* @of_node: optional device-tree node of the interrupt controller
28-
* @revmap_type: type of reverse mapping to use
2928
* @ops: map/unmap domain callbacks
3029
* @host_data: Controller private data pointer
3130
*
@@ -34,7 +33,7 @@ static struct irq_domain *irq_default_domain;
3433
* to IRQ domain, or NULL on failure.
3534
*/
3635
static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
37-
unsigned int revmap_type, int size,
36+
int size,
3837
const struct irq_domain_ops *ops,
3938
void *host_data)
4039
{
@@ -46,12 +45,11 @@ static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
4645
return NULL;
4746

4847
/* Fill structure */
49-
INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
50-
domain->revmap_type = revmap_type;
48+
INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
5149
domain->ops = ops;
5250
domain->host_data = host_data;
5351
domain->of_node = of_node_get(of_node);
54-
domain->revmap_data.linear.size = size;
52+
domain->revmap_size = size;
5553

5654
return domain;
5755
}
@@ -67,8 +65,7 @@ static void irq_domain_add(struct irq_domain *domain)
6765
mutex_lock(&irq_domain_mutex);
6866
list_add(&domain->link, &irq_domain_list);
6967
mutex_unlock(&irq_domain_mutex);
70-
pr_debug("Allocated domain of type %d @0x%p\n",
71-
domain->revmap_type, domain);
68+
pr_debug("Added domain %s\n", domain->name);
7269
}
7370

7471
/**
@@ -88,7 +85,7 @@ void irq_domain_remove(struct irq_domain *domain)
8885
* node when all entries are removed. Shout if there are
8986
* any mappings left.
9087
*/
91-
WARN_ON(domain->revmap_data.tree.height);
88+
WARN_ON(domain->revmap_tree.height);
9289

9390
list_del(&domain->link);
9491

@@ -100,8 +97,7 @@ void irq_domain_remove(struct irq_domain *domain)
10097

10198
mutex_unlock(&irq_domain_mutex);
10299

103-
pr_debug("Removed domain of type %d @0x%p\n",
104-
domain->revmap_type, domain);
100+
pr_debug("Removed domain %s\n", domain->name);
105101

106102
irq_domain_free(domain);
107103
}
@@ -216,7 +212,7 @@ struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
216212
{
217213
struct irq_domain *domain;
218214

219-
domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, size, ops, host_data);
215+
domain = irq_domain_alloc(of_node, size, ops, host_data);
220216
if (!domain)
221217
return NULL;
222218

@@ -230,10 +226,9 @@ struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
230226
const struct irq_domain_ops *ops,
231227
void *host_data)
232228
{
233-
struct irq_domain *domain = irq_domain_alloc(of_node,
234-
IRQ_DOMAIN_MAP_NOMAP, 0, ops, host_data);
229+
struct irq_domain *domain = irq_domain_alloc(of_node, 0, ops, host_data);
235230
if (domain) {
236-
domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
231+
domain->revmap_direct_max_irq = max_irq ? max_irq : ~0;
237232
irq_domain_add(domain);
238233
}
239234
return domain;
@@ -321,11 +316,11 @@ static void irq_domain_disassociate_many(struct irq_domain *domain,
321316
irq_data->hwirq = 0;
322317

323318
/* Clear reverse map for this hwirq */
324-
if (hwirq < domain->revmap_data.linear.size) {
319+
if (hwirq < domain->revmap_size) {
325320
domain->linear_revmap[hwirq] = 0;
326321
} else {
327322
mutex_lock(&revmap_trees_mutex);
328-
radix_tree_delete(&domain->revmap_data.tree, hwirq);
323+
radix_tree_delete(&domain->revmap_tree, hwirq);
329324
mutex_unlock(&revmap_trees_mutex);
330325
}
331326
}
@@ -378,11 +373,11 @@ int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
378373
domain->name = irq_data->chip->name;
379374
}
380375

381-
if (hwirq < domain->revmap_data.linear.size) {
376+
if (hwirq < domain->revmap_size) {
382377
domain->linear_revmap[hwirq] = virq;
383378
} else {
384379
mutex_lock(&revmap_trees_mutex);
385-
radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
380+
radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
386381
mutex_unlock(&revmap_trees_mutex);
387382
}
388383

@@ -399,7 +394,9 @@ EXPORT_SYMBOL_GPL(irq_domain_associate_many);
399394
*
400395
* This routine is used for irq controllers which can choose the hardware
401396
* interrupt numbers they generate. In such a case it's simplest to use
402-
* the linux irq as the hardware interrupt number.
397+
* the linux irq as the hardware interrupt number. It still uses the linear
398+
* or radix tree to store the mapping, but the irq controller can optimize
399+
* the revmap path by using the hwirq directly.
403400
*/
404401
unsigned int irq_create_direct_mapping(struct irq_domain *domain)
405402
{
@@ -408,17 +405,14 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
408405
if (domain == NULL)
409406
domain = irq_default_domain;
410407

411-
if (WARN_ON(!domain || domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP))
412-
return 0;
413-
414408
virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
415409
if (!virq) {
416410
pr_debug("create_direct virq allocation failed\n");
417411
return 0;
418412
}
419-
if (virq >= domain->revmap_data.nomap.max_irq) {
413+
if (virq >= domain->revmap_direct_max_irq) {
420414
pr_err("ERROR: no free irqs available below %i maximum\n",
421-
domain->revmap_data.nomap.max_irq);
415+
domain->revmap_direct_max_irq);
422416
irq_free_desc(virq);
423417
return 0;
424418
}
@@ -617,17 +611,13 @@ unsigned int irq_find_mapping(struct irq_domain *domain,
617611
if (domain == NULL)
618612
return 0;
619613

620-
switch (domain->revmap_type) {
621-
case IRQ_DOMAIN_MAP_LINEAR:
622-
return irq_linear_revmap(domain, hwirq);
623-
case IRQ_DOMAIN_MAP_NOMAP:
614+
if (hwirq < domain->revmap_direct_max_irq) {
624615
data = irq_get_irq_data(hwirq);
625616
if (data && (data->domain == domain) && (data->hwirq == hwirq))
626617
return hwirq;
627-
break;
628618
}
629619

630-
return 0;
620+
return irq_linear_revmap(domain, hwirq);
631621
}
632622
EXPORT_SYMBOL_GPL(irq_find_mapping);
633623

@@ -643,12 +633,11 @@ unsigned int irq_linear_revmap(struct irq_domain *domain,
643633
irq_hw_number_t hwirq)
644634
{
645635
struct irq_data *data;
646-
BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
647636

648637
/* Check revmap bounds; complain if exceeded */
649-
if (hwirq >= domain->revmap_data.linear.size) {
638+
if (hwirq >= domain->revmap_size) {
650639
rcu_read_lock();
651-
data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
640+
data = radix_tree_lookup(&domain->revmap_tree, hwirq);
652641
rcu_read_unlock();
653642
return data ? data->irq : 0;
654643
}

0 commit comments

Comments
 (0)