blob: 8033132eda8c6f4d5082b04e4a4bc31ad1fe5f53 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* sun4c_irq.c
2 * arch/sparc/kernel/sun4c_irq.c:
3 *
4 * djhr: Hacked out of irq.c into a CPU dependent version.
5 *
6 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
8 * Copyright (C) 1995 Pete A. Zaitcev (zaitcev@yahoo.com)
9 * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/errno.h>
13#include <linux/linkage.h>
14#include <linux/kernel_stat.h>
15#include <linux/signal.h>
16#include <linux/sched.h>
17#include <linux/ptrace.h>
18#include <linux/interrupt.h>
19#include <linux/slab.h>
20#include <linux/init.h>
David S. Miller454eeb22008-08-27 04:05:35 -070021#include <linux/of.h>
22#include <linux/of_device.h>
Al Viro32231a62007-07-21 19:18:57 -070023#include "irq.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include <asm/ptrace.h>
26#include <asm/processor.h>
27#include <asm/system.h>
28#include <asm/psr.h>
29#include <asm/vaddrs.h>
30#include <asm/timer.h>
31#include <asm/openprom.h>
32#include <asm/oplib.h>
33#include <asm/traps.h>
34#include <asm/irq.h>
35#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/idprom.h>
37#include <asm/machines.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Al Viro32231a62007-07-21 19:18:57 -070039/*
40 * Bit field defines for the interrupt registers on various
41 * Sparc machines.
42 */
43
44/* The sun4c interrupt register. */
45#define SUN4C_INT_ENABLE 0x01 /* Allow interrupts. */
46#define SUN4C_INT_E14 0x80 /* Enable level 14 IRQ. */
47#define SUN4C_INT_E10 0x20 /* Enable level 10 IRQ. */
48#define SUN4C_INT_E8 0x10 /* Enable level 8 IRQ. */
49#define SUN4C_INT_E6 0x08 /* Enable level 6 IRQ. */
50#define SUN4C_INT_E4 0x04 /* Enable level 4 IRQ. */
51#define SUN4C_INT_E1 0x02 /* Enable level 1 IRQ. */
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/* Pointer to the interrupt enable byte
54 *
55 * Dave Redman (djhr@tadpole.co.uk)
56 * What you may not be aware of is that entry.S requires this variable.
57 *
58 * --- linux_trap_nmi_sun4c --
59 *
60 * so don't go making it static, like I tried. sigh.
61 */
David S. Miller45bb5a72008-09-13 22:43:48 -070062unsigned char __iomem *interrupt_enable = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void sun4c_disable_irq(unsigned int irq_nr)
65{
66 unsigned long flags;
67 unsigned char current_mask, new_mask;
68
69 local_irq_save(flags);
70 irq_nr &= (NR_IRQS - 1);
David S. Miller45bb5a72008-09-13 22:43:48 -070071 current_mask = sbus_readb(interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 switch(irq_nr) {
73 case 1:
74 new_mask = ((current_mask) & (~(SUN4C_INT_E1)));
75 break;
76 case 8:
77 new_mask = ((current_mask) & (~(SUN4C_INT_E8)));
78 break;
79 case 10:
80 new_mask = ((current_mask) & (~(SUN4C_INT_E10)));
81 break;
82 case 14:
83 new_mask = ((current_mask) & (~(SUN4C_INT_E14)));
84 break;
85 default:
86 local_irq_restore(flags);
87 return;
88 }
David S. Miller45bb5a72008-09-13 22:43:48 -070089 sbus_writeb(new_mask, interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 local_irq_restore(flags);
91}
92
93static void sun4c_enable_irq(unsigned int irq_nr)
94{
95 unsigned long flags;
96 unsigned char current_mask, new_mask;
97
98 local_irq_save(flags);
99 irq_nr &= (NR_IRQS - 1);
David S. Miller45bb5a72008-09-13 22:43:48 -0700100 current_mask = sbus_readb(interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 switch(irq_nr) {
102 case 1:
103 new_mask = ((current_mask) | SUN4C_INT_E1);
104 break;
105 case 8:
106 new_mask = ((current_mask) | SUN4C_INT_E8);
107 break;
108 case 10:
109 new_mask = ((current_mask) | SUN4C_INT_E10);
110 break;
111 case 14:
112 new_mask = ((current_mask) | SUN4C_INT_E14);
113 break;
114 default:
115 local_irq_restore(flags);
116 return;
117 }
David S. Miller45bb5a72008-09-13 22:43:48 -0700118 sbus_writeb(new_mask, interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 local_irq_restore(flags);
120}
121
122#define TIMER_IRQ 10 /* Also at level 14, but we ignore that one. */
123#define PROFILE_IRQ 14 /* Level14 ticker.. used by OBP for polling */
124
125volatile struct sun4c_timer_info *sun4c_timers;
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127static void sun4c_clear_clock_irq(void)
128{
129 volatile unsigned int clear_intr;
Adrian Bunk5110bd22008-08-31 20:59:37 -0700130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 clear_intr = sun4c_timers->timer_limit10;
132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134static void sun4c_load_profile_irq(int cpu, unsigned int limit)
135{
136 /* Errm.. not sure how to do this.. */
137}
138
David Howells40220c12006-10-09 12:19:47 +0100139static void __init sun4c_init_timers(irq_handler_t counter_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 int irq;
142
143 /* Map the Timer chip, this is implemented in hardware inside
144 * the cache chip on the sun4c.
145 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 sun4c_timers = ioremap(SUN_TIMER_PHYSADDR,
147 sizeof(struct sun4c_timer_info));
148
149 /* Have the level 10 timer tick at 100HZ. We don't touch the
150 * level 14 timer limit since we are letting the prom handle
151 * them until we have a real console driver so L1-A works.
152 */
153 sun4c_timers->timer_limit10 = (((1000000/HZ) + 1) << 10);
154 master_l10_counter = &sun4c_timers->cur_count10;
155 master_l10_limit = &sun4c_timers->timer_limit10;
156
157 irq = request_irq(TIMER_IRQ,
158 counter_fn,
Thomas Gleixner67413202006-07-01 19:29:26 -0700159 (IRQF_DISABLED | SA_STATIC_ALLOC),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 "timer", NULL);
161 if (irq) {
162 prom_printf("time_init: unable to attach IRQ%d\n",TIMER_IRQ);
163 prom_halt();
164 }
165
David S. Millerb218fa02008-09-13 22:08:26 -0700166 sun4c_disable_irq(PROFILE_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
169#ifdef CONFIG_SMP
170static void sun4c_nop(void) {}
171#endif
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173void __init sun4c_init_IRQ(void)
174{
David S. Miller45bb5a72008-09-13 22:43:48 -0700175 struct device_node *dp;
176 const u32 *addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
David S. Miller45bb5a72008-09-13 22:43:48 -0700178 dp = of_find_node_by_name(NULL, "interrupt-enable");
179 if (!dp) {
180 prom_printf("sun4c_init_IRQ: Unable to find interrupt-enable\n");
181 prom_halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
David S. Miller45bb5a72008-09-13 22:43:48 -0700183
184 addr = of_get_property(dp, "address", NULL);
185 if (!addr) {
186 prom_printf("sun4c_init_IRQ: No address property\n");
187 prom_halt();
188 }
189
190 interrupt_enable = (void __iomem *) (unsigned long) addr[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 BTFIXUPSET_CALL(enable_irq, sun4c_enable_irq, BTFIXUPCALL_NORM);
193 BTFIXUPSET_CALL(disable_irq, sun4c_disable_irq, BTFIXUPCALL_NORM);
194 BTFIXUPSET_CALL(enable_pil_irq, sun4c_enable_irq, BTFIXUPCALL_NORM);
195 BTFIXUPSET_CALL(disable_pil_irq, sun4c_disable_irq, BTFIXUPCALL_NORM);
196 BTFIXUPSET_CALL(clear_clock_irq, sun4c_clear_clock_irq, BTFIXUPCALL_NORM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 BTFIXUPSET_CALL(load_profile_irq, sun4c_load_profile_irq, BTFIXUPCALL_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 sparc_init_timers = sun4c_init_timers;
199#ifdef CONFIG_SMP
200 BTFIXUPSET_CALL(set_cpu_int, sun4c_nop, BTFIXUPCALL_NOP);
201 BTFIXUPSET_CALL(clear_cpu_int, sun4c_nop, BTFIXUPCALL_NOP);
202 BTFIXUPSET_CALL(set_irq_udt, sun4c_nop, BTFIXUPCALL_NOP);
203#endif
David S. Miller45bb5a72008-09-13 22:43:48 -0700204 sbus_writeb(SUN4C_INT_ENABLE, interrupt_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 /* Cannot enable interrupts until OBP ticker is disabled. */
206}