Skip to content

Commit 1bc04f2

Browse files
committed
irq_domain: Add support for base irq and hwirq in legacy mappings
Add support for a legacy mapping where irq = (hwirq - first_hwirq + first_irq) so that a controller driver can allocate a fixed range of irq_descs and use a simple calculation to translate back and forth between linux and hw irq numbers. This is needed to use an irq_domain with many of the ARM interrupt controller drivers that manage their own irq_desc allocations. Ultimately the goal is to migrate those drivers to use the linear revmap, but doing it this way allows each driver to be converted separately which makes the migration path easier. This patch generalizes the IRQ_DOMAIN_MAP_LEGACY method to use (first_irq-first_hwirq) as the offset between hwirq and linux irq number, and adds checks to make sure that the hwirq number does not exceed range assigned to the controller. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Rob Herring <rob.herring@calxeda.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Milton Miller <miltonm@bga.com> Tested-by: Olof Johansson <olof@lixom.net>
1 parent a8db8cf commit 1bc04f2

5 files changed

Lines changed: 85 additions & 38 deletions

File tree

‎arch/powerpc/include/asm/irq.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ extern atomic_t ppc_n_lost_interrupts;
3636
/* Total number of virq in the platform */
3737
#define NR_IRQS CONFIG_NR_IRQS
3838

39-
/* Number of irqs reserved for the legacy controller */
40-
#define NUM_ISA_INTERRUPTS 16
41-
4239
/* Same thing, used by the generic IRQ code */
4340
#define NR_IRQS_LEGACY NUM_ISA_INTERRUPTS
4441

‎arch/powerpc/sysdev/i8259.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void i8259_init(struct device_node *node, unsigned long intack_addr)
263263
raw_spin_unlock_irqrestore(&i8259_lock, flags);
264264

265265
/* create a legacy host */
266-
i8259_host = irq_domain_add_legacy(node, &i8259_host_ops, NULL);
266+
i8259_host = irq_domain_add_legacy_isa(node, &i8259_host_ops, NULL);
267267
if (i8259_host == NULL) {
268268
printk(KERN_ERR "i8259: failed to allocate irq host !\n");
269269
return;

‎arch/powerpc/sysdev/tsi108_pci.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void __init tsi108_pci_int_init(struct device_node *node)
419419
{
420420
DBG("Tsi108_pci_int_init: initializing PCI interrupts\n");
421421

422-
pci_irq_host = irq_domain_add_legacy(node, &pci_irq_domain_ops, NULL);
422+
pci_irq_host = irq_domain_add_legacy_isa(node, &pci_irq_domain_ops, NULL);
423423
if (pci_irq_host == NULL) {
424424
printk(KERN_ERR "pci_irq_host: failed to allocate irq domain!\n");
425425
return;

‎include/linux/irqdomain.h‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct device_node;
3939
struct irq_domain;
4040
struct of_device_id;
4141

42+
/* Number of irqs reserved for a legacy isa controller */
43+
#define NUM_ISA_INTERRUPTS 16
44+
4245
/* This type is the placeholder for a hardware interrupt number. It has to
4346
* be big enough to enclose whatever representation is used by a given
4447
* platform.
@@ -96,6 +99,11 @@ struct irq_domain {
9699
/* type of reverse mapping_technique */
97100
unsigned int revmap_type;
98101
union {
102+
struct {
103+
unsigned int size;
104+
unsigned int first_irq;
105+
irq_hw_number_t first_hwirq;
106+
} legacy;
99107
struct {
100108
unsigned int size;
101109
unsigned int *revmap;
@@ -117,6 +125,9 @@ struct irq_domain {
117125
#ifdef CONFIG_IRQ_DOMAIN
118126
#ifdef CONFIG_PPC
119127
struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
128+
unsigned int size,
129+
unsigned int first_irq,
130+
irq_hw_number_t first_hwirq,
120131
struct irq_domain_ops *ops,
121132
void *host_data);
122133
struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
@@ -130,11 +141,18 @@ struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
130141
struct irq_domain_ops *ops,
131142
void *host_data);
132143

133-
134144
extern struct irq_domain *irq_find_host(struct device_node *node);
135145
extern void irq_set_default_host(struct irq_domain *host);
136146
extern void irq_set_virq_count(unsigned int count);
137147

148+
static inline struct irq_domain *irq_domain_add_legacy_isa(
149+
struct device_node *of_node,
150+
struct irq_domain_ops *ops,
151+
void *host_data)
152+
{
153+
return irq_domain_add_legacy(of_node, NUM_ISA_INTERRUPTS, 0, 0, ops,
154+
host_data);
155+
}
138156

139157
extern unsigned int irq_create_mapping(struct irq_domain *host,
140158
irq_hw_number_t hwirq);

‎kernel/irq/irqdomain.c‎

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <linux/smp.h>
1414
#include <linux/fs.h>
1515

16-
#define IRQ_DOMAIN_MAP_LEGACY 0 /* legacy 8259, gets irqs 1..15 */
16+
#define IRQ_DOMAIN_MAP_LEGACY 0 /* driver allocated fixed range of irqs.
17+
* ie. legacy 8259, gets irqs 1..15 */
1718
#define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */
1819
#define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */
1920
#define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */
@@ -74,9 +75,25 @@ static void irq_domain_add(struct irq_domain *domain)
7475
domain->revmap_type, domain);
7576
}
7677

78+
static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
79+
irq_hw_number_t hwirq)
80+
{
81+
irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq;
82+
int size = domain->revmap_data.legacy.size;
83+
84+
if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
85+
return 0;
86+
return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq;
87+
}
88+
7789
/**
7890
* irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
7991
* @of_node: pointer to interrupt controller's device tree node.
92+
* @size: total number of irqs in legacy mapping
93+
* @first_irq: first number of irq block assigned to the domain
94+
* @first_hwirq: first hwirq number to use for the translation. Should normally
95+
* be '0', but a positive integer can be used if the effective
96+
* hwirqs numbering does not begin at zero.
8097
* @ops: map/unmap domain callbacks
8198
* @host_data: Controller private data pointer
8299
*
@@ -85,44 +102,64 @@ static void irq_domain_add(struct irq_domain *domain)
85102
* a legacy controller).
86103
*/
87104
struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
105+
unsigned int size,
106+
unsigned int first_irq,
107+
irq_hw_number_t first_hwirq,
88108
struct irq_domain_ops *ops,
89109
void *host_data)
90110
{
91-
struct irq_domain *domain, *h;
111+
struct irq_domain *domain;
92112
unsigned int i;
93113

94114
domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
95115
if (!domain)
96116
return NULL;
97117

118+
domain->revmap_data.legacy.first_irq = first_irq;
119+
domain->revmap_data.legacy.first_hwirq = first_hwirq;
120+
domain->revmap_data.legacy.size = size;
121+
98122
mutex_lock(&irq_domain_mutex);
99-
/* Make sure only one legacy controller can be created */
100-
list_for_each_entry(h, &irq_domain_list, link) {
101-
if (WARN_ON(h->revmap_type == IRQ_DOMAIN_MAP_LEGACY)) {
123+
/* Verify that all the irqs are available */
124+
for (i = 0; i < size; i++) {
125+
int irq = first_irq + i;
126+
struct irq_data *irq_data = irq_get_irq_data(irq);
127+
128+
if (WARN_ON(!irq_data || irq_data->domain)) {
102129
mutex_unlock(&irq_domain_mutex);
103130
of_node_put(domain->of_node);
104131
kfree(domain);
105132
return NULL;
106133
}
107134
}
108-
list_add(&domain->link, &irq_domain_list);
109-
mutex_unlock(&irq_domain_mutex);
110135

111-
/* setup us as the domain for all legacy interrupts */
112-
for (i = 1; i < NUM_ISA_INTERRUPTS; i++) {
113-
struct irq_data *irq_data = irq_get_irq_data(i);
114-
irq_data->hwirq = i;
136+
/* Claim all of the irqs before registering a legacy domain */
137+
for (i = 0; i < size; i++) {
138+
struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
139+
irq_data->hwirq = first_hwirq + i;
115140
irq_data->domain = domain;
141+
}
142+
mutex_unlock(&irq_domain_mutex);
143+
144+
for (i = 0; i < size; i++) {
145+
int irq = first_irq + i;
146+
int hwirq = first_hwirq + i;
147+
148+
/* IRQ0 gets ignored */
149+
if (!irq)
150+
continue;
116151

117152
/* Legacy flags are left to default at this point,
118153
* one can then use irq_create_mapping() to
119154
* explicitly change them
120155
*/
121-
ops->map(domain, i, i);
156+
ops->map(domain, irq, hwirq);
122157

123158
/* Clear norequest flags */
124-
irq_clear_status_flags(i, IRQ_NOREQUEST);
159+
irq_clear_status_flags(irq, IRQ_NOREQUEST);
125160
}
161+
162+
irq_domain_add(domain);
126163
return domain;
127164
}
128165

@@ -338,24 +375,19 @@ unsigned int irq_create_mapping(struct irq_domain *domain,
338375
}
339376

340377
/* Get a virtual interrupt number */
341-
if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY) {
342-
/* Handle legacy */
343-
virq = (unsigned int)hwirq;
344-
if (virq == 0 || virq >= NUM_ISA_INTERRUPTS)
345-
return 0;
346-
return virq;
347-
} else {
348-
/* Allocate a virtual interrupt number */
349-
hint = hwirq % irq_virq_count;
350-
if (hint == 0)
351-
hint++;
352-
virq = irq_alloc_desc_from(hint, 0);
353-
if (!virq)
354-
virq = irq_alloc_desc_from(1, 0);
355-
if (!virq) {
356-
pr_debug("irq: -> virq allocation failed\n");
357-
return 0;
358-
}
378+
if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
379+
return irq_domain_legacy_revmap(domain, hwirq);
380+
381+
/* Allocate a virtual interrupt number */
382+
hint = hwirq % irq_virq_count;
383+
if (hint == 0)
384+
hint++;
385+
virq = irq_alloc_desc_from(hint, 0);
386+
if (!virq)
387+
virq = irq_alloc_desc_from(1, 0);
388+
if (!virq) {
389+
pr_debug("irq: -> virq allocation failed\n");
390+
return 0;
359391
}
360392

361393
if (irq_setup_virq(domain, virq, hwirq)) {
@@ -483,7 +515,7 @@ unsigned int irq_find_mapping(struct irq_domain *domain,
483515

484516
/* legacy -> bail early */
485517
if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
486-
return hwirq;
518+
return irq_domain_legacy_revmap(domain, hwirq);
487519

488520
/* Slow path does a linear search of the map */
489521
if (hint == 0)

0 commit comments

Comments
 (0)