Skip to content

Commit 2206d5d

Browse files
jcmvbkbcczankel
authored andcommitted
xtensa: add IRQ domains support
IRQ domains provide a mechanism for conversion of linux IRQ numbers to hardware IRQ numbers and vice versus. It is used by OpenFirmware for linking device tree objects to their respective interrupt controllers. Signed-off-by: Max Filippov <[email protected]> Signed-off-by: Chris Zankel <[email protected]>
1 parent 0322cab commit 2206d5d

File tree

3 files changed

+94
-34
lines changed

3 files changed

+94
-34
lines changed

arch/xtensa/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config XTENSA
1717
select GENERIC_KERNEL_EXECVE
1818
select ARCH_WANT_OPTIONAL_GPIOLIB
1919
select CLONE_BACKWARDS
20+
select IRQ_DOMAIN
2021
help
2122
Xtensa processors are 32-bit RISC machines designed by Tensilica
2223
primarily for embedded systems. These processors are both

arch/xtensa/kernel/irq.c

+89-33
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/interrupt.h>
1919
#include <linux/irq.h>
2020
#include <linux/kernel_stat.h>
21+
#include <linux/irqdomain.h>
2122

2223
#include <asm/uaccess.h>
2324
#include <asm/platform.h>
@@ -26,19 +27,22 @@ static unsigned int cached_irq_mask;
2627

2728
atomic_t irq_err_count;
2829

30+
static struct irq_domain *root_domain;
31+
2932
/*
3033
* do_IRQ handles all normal device IRQ's (the special
3134
* SMP cross-CPU interrupts have their own specific
3235
* handlers).
3336
*/
3437

35-
asmlinkage void do_IRQ(int irq, struct pt_regs *regs)
38+
asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
3639
{
3740
struct pt_regs *old_regs = set_irq_regs(regs);
41+
int irq = irq_find_mapping(root_domain, hwirq);
3842

39-
if (irq >= NR_IRQS) {
43+
if (hwirq >= NR_IRQS) {
4044
printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
41-
__func__, irq);
45+
__func__, hwirq);
4246
}
4347

4448
irq_enter();
@@ -71,40 +75,39 @@ int arch_show_interrupts(struct seq_file *p, int prec)
7175

7276
static void xtensa_irq_mask(struct irq_data *d)
7377
{
74-
cached_irq_mask &= ~(1 << d->irq);
78+
cached_irq_mask &= ~(1 << d->hwirq);
7579
set_sr (cached_irq_mask, intenable);
7680
}
7781

7882
static void xtensa_irq_unmask(struct irq_data *d)
7983
{
80-
cached_irq_mask |= 1 << d->irq;
84+
cached_irq_mask |= 1 << d->hwirq;
8185
set_sr (cached_irq_mask, intenable);
8286
}
8387

8488
static void xtensa_irq_enable(struct irq_data *d)
8589
{
86-
variant_irq_enable(d->irq);
90+
variant_irq_enable(d->hwirq);
8791
xtensa_irq_unmask(d);
8892
}
8993

9094
static void xtensa_irq_disable(struct irq_data *d)
9195
{
9296
xtensa_irq_mask(d);
93-
variant_irq_disable(d->irq);
97+
variant_irq_disable(d->hwirq);
9498
}
9599

96100
static void xtensa_irq_ack(struct irq_data *d)
97101
{
98-
set_sr(1 << d->irq, intclear);
102+
set_sr(1 << d->hwirq, intclear);
99103
}
100104

101105
static int xtensa_irq_retrigger(struct irq_data *d)
102106
{
103-
set_sr (1 << d->irq, INTSET);
107+
set_sr(1 << d->hwirq, intset);
104108
return 1;
105109
}
106110

107-
108111
static struct irq_chip xtensa_irq_chip = {
109112
.name = "xtensa",
110113
.irq_enable = xtensa_irq_enable,
@@ -115,37 +118,90 @@ static struct irq_chip xtensa_irq_chip = {
115118
.irq_retrigger = xtensa_irq_retrigger,
116119
};
117120

118-
void __init init_IRQ(void)
121+
static int xtensa_irq_map(struct irq_domain *d, unsigned int irq,
122+
irq_hw_number_t hw)
119123
{
120-
int index;
121-
122-
for (index = 0; index < XTENSA_NR_IRQS; index++) {
123-
int mask = 1 << index;
124-
125-
if (mask & XCHAL_INTTYPE_MASK_SOFTWARE)
126-
irq_set_chip_and_handler(index, &xtensa_irq_chip,
127-
handle_simple_irq);
124+
u32 mask = 1 << hw;
125+
126+
if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) {
127+
irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
128+
handle_simple_irq, "level");
129+
irq_set_status_flags(irq, IRQ_LEVEL);
130+
} else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) {
131+
irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
132+
handle_edge_irq, "edge");
133+
irq_clear_status_flags(irq, IRQ_LEVEL);
134+
} else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) {
135+
irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
136+
handle_level_irq, "level");
137+
irq_set_status_flags(irq, IRQ_LEVEL);
138+
} else if (mask & XCHAL_INTTYPE_MASK_TIMER) {
139+
irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
140+
handle_edge_irq, "edge");
141+
irq_clear_status_flags(irq, IRQ_LEVEL);
142+
} else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */
143+
/* XCHAL_INTTYPE_MASK_NMI */
144+
145+
irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
146+
handle_level_irq, "level");
147+
irq_set_status_flags(irq, IRQ_LEVEL);
148+
}
149+
return 0;
150+
}
128151

129-
else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE)
130-
irq_set_chip_and_handler(index, &xtensa_irq_chip,
131-
handle_edge_irq);
152+
static unsigned map_ext_irq(unsigned ext_irq)
153+
{
154+
unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE |
155+
XCHAL_INTTYPE_MASK_EXTERN_LEVEL;
156+
unsigned i;
132157

133-
else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL)
134-
irq_set_chip_and_handler(index, &xtensa_irq_chip,
135-
handle_level_irq);
158+
for (i = 0; mask; ++i, mask >>= 1) {
159+
if ((mask & 1) && ext_irq-- == 0)
160+
return i;
161+
}
162+
return XCHAL_NUM_INTERRUPTS;
163+
}
136164

137-
else if (mask & XCHAL_INTTYPE_MASK_TIMER)
138-
irq_set_chip_and_handler(index, &xtensa_irq_chip,
139-
handle_edge_irq);
165+
/*
166+
* Device Tree IRQ specifier translation function which works with one or
167+
* two cell bindings. First cell value maps directly to the hwirq number.
168+
* Second cell if present specifies whether hwirq number is external (1) or
169+
* internal (0).
170+
*/
171+
int xtensa_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
172+
const u32 *intspec, unsigned int intsize,
173+
unsigned long *out_hwirq, unsigned int *out_type)
174+
{
175+
if (WARN_ON(intsize < 1 || intsize > 2))
176+
return -EINVAL;
177+
if (intsize == 2 && intspec[1] == 1) {
178+
unsigned int_irq = map_ext_irq(intspec[0]);
179+
if (int_irq < XCHAL_NUM_INTERRUPTS)
180+
*out_hwirq = int_irq;
181+
else
182+
return -EINVAL;
183+
} else {
184+
*out_hwirq = intspec[0];
185+
}
186+
*out_type = IRQ_TYPE_NONE;
187+
return 0;
188+
}
140189

141-
else /* XCHAL_INTTYPE_MASK_WRITE_ERROR */
142-
/* XCHAL_INTTYPE_MASK_NMI */
190+
static const struct irq_domain_ops xtensa_irq_domain_ops = {
191+
.xlate = xtensa_irq_domain_xlate,
192+
.map = xtensa_irq_map,
193+
};
143194

144-
irq_set_chip_and_handler(index, &xtensa_irq_chip,
145-
handle_level_irq);
146-
}
195+
void __init init_IRQ(void)
196+
{
197+
struct device_node *intc = NULL;
147198

148199
cached_irq_mask = 0;
200+
set_sr(~0, intclear);
201+
202+
root_domain = irq_domain_add_legacy(intc, NR_IRQS, 0, 0,
203+
&xtensa_irq_domain_ops, NULL);
204+
irq_set_default_host(root_domain);
149205

150206
variant_init_irq();
151207
}

arch/xtensa/kernel/time.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/irq.h>
2323
#include <linux/profile.h>
2424
#include <linux/delay.h>
25+
#include <linux/irqdomain.h>
2526

2627
#include <asm/timex.h>
2728
#include <asm/platform.h>
@@ -52,6 +53,7 @@ static struct irqaction timer_irqaction = {
5253

5354
void __init time_init(void)
5455
{
56+
unsigned int irq;
5557
#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
5658
printk("Calibrating CPU frequency ");
5759
platform_calibrate_ccount();
@@ -62,7 +64,8 @@ void __init time_init(void)
6264

6365
/* Initialize the linux timer interrupt. */
6466

65-
setup_irq(LINUX_TIMER_INT, &timer_irqaction);
67+
irq = irq_create_mapping(NULL, LINUX_TIMER_INT);
68+
setup_irq(irq, &timer_irqaction);
6669
set_linux_timer(get_ccount() + CCOUNT_PER_JIFFY);
6770
}
6871

0 commit comments

Comments
 (0)