blob: 15c5ea3e98d4e7d65c064c3d4ab104606411e4c4 [file] [log] [blame]
Jonas Bonn816ebaa2011-06-04 22:18:56 +03001/*
2 * OpenRISC irq.c
3 *
4 * Linux architectural port borrowing liberally from similar works of
5 * others. All original copyrights apply as per the original source
6 * declaration.
7 *
8 * Modifications for the OpenRISC architecture:
9 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 */
16
17#include <linux/ptrace.h>
18#include <linux/errno.h>
19#include <linux/interrupt.h>
20#include <linux/init.h>
21#include <linux/of.h>
22#include <linux/ftrace.h>
23#include <linux/irq.h>
24#include <linux/seq_file.h>
25#include <linux/kernel_stat.h>
Jonas Bonnabdf8b52012-02-15 15:00:32 +010026#include <linux/export.h>
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +020027#include <linux/irqdomain.h>
Jonas Bonn816ebaa2011-06-04 22:18:56 +030028#include <linux/irqflags.h>
29
30/* read interrupt enabled status */
31unsigned long arch_local_save_flags(void)
32{
33 return mfspr(SPR_SR) & (SPR_SR_IEE|SPR_SR_TEE);
34}
35EXPORT_SYMBOL(arch_local_save_flags);
36
37/* set interrupt enabled status */
38void arch_local_irq_restore(unsigned long flags)
39{
40 mtspr(SPR_SR, ((mfspr(SPR_SR) & ~(SPR_SR_IEE|SPR_SR_TEE)) | flags));
41}
42EXPORT_SYMBOL(arch_local_irq_restore);
43
44
45/* OR1K PIC implementation */
46
47/* We're a couple of cycles faster than the generic implementations with
48 * these 'fast' versions.
49 */
50
51static void or1k_pic_mask(struct irq_data *data)
52{
53 mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1UL << data->irq));
54}
55
56static void or1k_pic_unmask(struct irq_data *data)
57{
58 mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (1UL << data->irq));
59}
60
61static void or1k_pic_ack(struct irq_data *data)
62{
63 /* EDGE-triggered interrupts need to be ack'ed in order to clear
64 * the latch.
65 * LEVER-triggered interrupts do not need to be ack'ed; however,
66 * ack'ing the interrupt has no ill-effect and is quicker than
67 * trying to figure out what type it is...
68 */
69
70 /* The OpenRISC 1000 spec says to write a 1 to the bit to ack the
71 * interrupt, but the OR1200 does this backwards and requires a 0
72 * to be written...
73 */
74
75#ifdef CONFIG_OR1K_1200
76 /* There are two oddities with the OR1200 PIC implementation:
77 * i) LEVEL-triggered interrupts are latched and need to be cleared
78 * ii) the interrupt latch is cleared by writing a 0 to the bit,
79 * as opposed to a 1 as mandated by the spec
80 */
81
82 mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
83#else
84 WARN(1, "Interrupt handling possibily broken\n");
85 mtspr(SPR_PICSR, (1UL << irq));
86#endif
87}
88
89static void or1k_pic_mask_ack(struct irq_data *data)
90{
91 /* Comments for pic_ack apply here, too */
92
93#ifdef CONFIG_OR1K_1200
94 mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
95#else
96 WARN(1, "Interrupt handling possibily broken\n");
97 mtspr(SPR_PICSR, (1UL << irq));
98#endif
99}
100
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200101#if 0
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300102static int or1k_pic_set_type(struct irq_data *data, unsigned int flow_type)
103{
104 /* There's nothing to do in the PIC configuration when changing
105 * flow type. Level and edge-triggered interrupts are both
106 * supported, but it's PIC-implementation specific which type
107 * is handled. */
108
109 return irq_setup_alt_chip(data, flow_type);
110}
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200111#endif
112
113static struct irq_chip or1k_dev = {
114 .name = "or1k-PIC",
115 .irq_unmask = or1k_pic_unmask,
116 .irq_mask = or1k_pic_mask,
117 .irq_ack = or1k_pic_ack,
118 .irq_mask_ack = or1k_pic_mask_ack,
119};
120
121static struct irq_domain *root_domain;
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300122
123static inline int pic_get_irq(int first)
124{
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200125 int hwirq;
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300126
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200127 hwirq = ffs(mfspr(SPR_PICSR) >> first);
128 if (!hwirq)
129 return NO_IRQ;
130 else
131 hwirq = hwirq + first -1;
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300132
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200133 return irq_find_mapping(root_domain, hwirq);
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300134}
135
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200136
137static int or1k_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
138{
139 irq_set_chip_and_handler_name(irq, &or1k_dev,
140 handle_level_irq, "level");
141 irq_set_status_flags(irq, IRQ_LEVEL | IRQ_NOPROBE);
142
143 return 0;
144}
145
146static const struct irq_domain_ops or1k_irq_domain_ops = {
147 .xlate = irq_domain_xlate_onecell,
148 .map = or1k_map,
149};
150
151/*
152 * This sets up the IRQ domain for the PIC built in to the OpenRISC
153 * 1000 CPU. This is the "root" domain as these are the interrupts
154 * that directly trigger an exception in the CPU.
155 */
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300156static void __init or1k_irq_init(void)
157{
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200158 struct device_node *intc = NULL;
159
160 /* The interrupt controller device node is mandatory */
161 intc = of_find_compatible_node(NULL, NULL, "opencores,or1k-pic");
162 BUG_ON(!intc);
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300163
164 /* Disable all interrupts until explicitly requested */
165 mtspr(SPR_PICMR, (0UL));
166
Jonas Bonnb4c4c6e2012-04-06 12:52:54 +0200167 root_domain = irq_domain_add_linear(intc, 32,
168 &or1k_irq_domain_ops, NULL);
Jonas Bonn816ebaa2011-06-04 22:18:56 +0300169}
170
171void __init init_IRQ(void)
172{
173 or1k_irq_init();
174}
175
176void __irq_entry do_IRQ(struct pt_regs *regs)
177{
178 int irq = -1;
179 struct pt_regs *old_regs = set_irq_regs(regs);
180
181 irq_enter();
182
183 while ((irq = pic_get_irq(irq + 1)) != NO_IRQ)
184 generic_handle_irq(irq);
185
186 irq_exit();
187 set_irq_regs(old_regs);
188}