xref: /openbmc/linux/arch/sparc/kernel/sun4m_irq.c (revision c2e27c359ab76fecbbd292dbfc0bcfa8399afdd9)
11da177e4SLinus Torvalds /*  sun4m_irq.c
21da177e4SLinus Torvalds  *  arch/sparc/kernel/sun4m_irq.c:
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  djhr: Hacked out of irq.c into a CPU dependent version.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
71da177e4SLinus Torvalds  *  Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
81da177e4SLinus Torvalds  *  Copyright (C) 1995 Pete A. Zaitcev (zaitcev@yahoo.com)
91da177e4SLinus Torvalds  *  Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #include <linux/errno.h>
131da177e4SLinus Torvalds #include <linux/linkage.h>
141da177e4SLinus Torvalds #include <linux/kernel_stat.h>
151da177e4SLinus Torvalds #include <linux/signal.h>
161da177e4SLinus Torvalds #include <linux/sched.h>
171da177e4SLinus Torvalds #include <linux/ptrace.h>
181da177e4SLinus Torvalds #include <linux/smp.h>
191da177e4SLinus Torvalds #include <linux/interrupt.h>
201da177e4SLinus Torvalds #include <linux/slab.h>
211da177e4SLinus Torvalds #include <linux/init.h>
221da177e4SLinus Torvalds #include <linux/ioport.h>
23454eeb2dSDavid S. Miller #include <linux/of.h>
24454eeb2dSDavid S. Miller #include <linux/of_device.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include <asm/ptrace.h>
271da177e4SLinus Torvalds #include <asm/processor.h>
281da177e4SLinus Torvalds #include <asm/system.h>
291da177e4SLinus Torvalds #include <asm/psr.h>
301da177e4SLinus Torvalds #include <asm/vaddrs.h>
311da177e4SLinus Torvalds #include <asm/timer.h>
321da177e4SLinus Torvalds #include <asm/openprom.h>
331da177e4SLinus Torvalds #include <asm/oplib.h>
341da177e4SLinus Torvalds #include <asm/traps.h>
351da177e4SLinus Torvalds #include <asm/pgalloc.h>
361da177e4SLinus Torvalds #include <asm/pgtable.h>
371da177e4SLinus Torvalds #include <asm/smp.h>
381da177e4SLinus Torvalds #include <asm/irq.h>
391da177e4SLinus Torvalds #include <asm/io.h>
401da177e4SLinus Torvalds #include <asm/cacheflush.h>
411da177e4SLinus Torvalds 
4232231a66SAl Viro #include "irq.h"
4332231a66SAl Viro 
4469c010b2SDavid S. Miller struct sun4m_irq_percpu {
4569c010b2SDavid S. Miller 	u32		pending;
4669c010b2SDavid S. Miller 	u32		clear;
4769c010b2SDavid S. Miller 	u32		set;
4832231a66SAl Viro };
4932231a66SAl Viro 
5069c010b2SDavid S. Miller struct sun4m_irq_global {
5169c010b2SDavid S. Miller 	u32		pending;
5269c010b2SDavid S. Miller 	u32		mask;
5369c010b2SDavid S. Miller 	u32		mask_clear;
5469c010b2SDavid S. Miller 	u32		mask_set;
5569c010b2SDavid S. Miller 	u32		interrupt_target;
5632231a66SAl Viro };
5732231a66SAl Viro 
5869c010b2SDavid S. Miller /* Code in entry.S needs to get at these register mappings.  */
5969c010b2SDavid S. Miller struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS];
6069c010b2SDavid S. Miller struct sun4m_irq_global __iomem *sun4m_irq_global;
6169c010b2SDavid S. Miller 
6232231a66SAl Viro /* Dave Redman (djhr@tadpole.co.uk)
6332231a66SAl Viro  * The sun4m interrupt registers.
6432231a66SAl Viro  */
6532231a66SAl Viro #define SUN4M_INT_ENABLE  	0x80000000
6632231a66SAl Viro #define SUN4M_INT_E14     	0x00000080
6732231a66SAl Viro #define SUN4M_INT_E10     	0x00080000
6832231a66SAl Viro 
6932231a66SAl Viro #define SUN4M_HARD_INT(x)	(0x000000001 << (x))
7032231a66SAl Viro #define SUN4M_SOFT_INT(x)	(0x000010000 << (x))
7132231a66SAl Viro 
7232231a66SAl Viro #define	SUN4M_INT_MASKALL	0x80000000	  /* mask all interrupts */
7332231a66SAl Viro #define	SUN4M_INT_MODULE_ERR	0x40000000	  /* module error */
746cf4a924SRobert Reif #define	SUN4M_INT_M2S_WRITE_ERR	0x20000000	  /* write buffer error */
756cf4a924SRobert Reif #define	SUN4M_INT_ECC_ERR	0x10000000	  /* ecc memory error */
766cf4a924SRobert Reif #define	SUN4M_INT_VME_ERR	0x08000000	  /* vme async error */
7732231a66SAl Viro #define	SUN4M_INT_FLOPPY	0x00400000	  /* floppy disk */
7832231a66SAl Viro #define	SUN4M_INT_MODULE	0x00200000	  /* module interrupt */
7932231a66SAl Viro #define	SUN4M_INT_VIDEO		0x00100000	  /* onboard video */
8032231a66SAl Viro #define	SUN4M_INT_REALTIME	0x00080000	  /* system timer */
8132231a66SAl Viro #define	SUN4M_INT_SCSI		0x00040000	  /* onboard scsi */
8232231a66SAl Viro #define	SUN4M_INT_AUDIO		0x00020000	  /* audio/isdn */
8332231a66SAl Viro #define	SUN4M_INT_ETHERNET	0x00010000	  /* onboard ethernet */
8432231a66SAl Viro #define	SUN4M_INT_SERIAL	0x00008000	  /* serial ports */
8532231a66SAl Viro #define	SUN4M_INT_KBDMS		0x00004000	  /* keyboard/mouse */
8632231a66SAl Viro #define	SUN4M_INT_SBUSBITS	0x00003F80	  /* sbus int bits */
876cf4a924SRobert Reif #define	SUN4M_INT_VMEBITS	0x0000007F	  /* vme int bits */
886cf4a924SRobert Reif 
896cf4a924SRobert Reif #define	SUN4M_INT_ERROR		(SUN4M_INT_MODULE_ERR |    \
906cf4a924SRobert Reif 				 SUN4M_INT_M2S_WRITE_ERR | \
916cf4a924SRobert Reif 				 SUN4M_INT_ECC_ERR |       \
926cf4a924SRobert Reif 				 SUN4M_INT_VME_ERR)
9332231a66SAl Viro 
9432231a66SAl Viro #define SUN4M_INT_SBUS(x)	(1 << (x+7))
9532231a66SAl Viro #define SUN4M_INT_VME(x)	(1 << (x))
9632231a66SAl Viro 
976cf4a924SRobert Reif /* Interrupt levels used by OBP */
986cf4a924SRobert Reif #define	OBP_INT_LEVEL_SOFT	0x10
996cf4a924SRobert Reif #define	OBP_INT_LEVEL_ONBOARD	0x20
1006cf4a924SRobert Reif #define	OBP_INT_LEVEL_SBUS	0x30
1016cf4a924SRobert Reif #define	OBP_INT_LEVEL_VME	0x40
1026cf4a924SRobert Reif 
103778b1c65SDavid S. Miller /* Interrupt level assignment on sun4m:
104778b1c65SDavid S. Miller  *
105778b1c65SDavid S. Miller  *	level		source
106778b1c65SDavid S. Miller  * ------------------------------------------------------------
107778b1c65SDavid S. Miller  *        1		softint-1
108778b1c65SDavid S. Miller  *	  2		softint-2, VME/SBUS level 1
109778b1c65SDavid S. Miller  *	  3		softint-3, VME/SBUS level 2
110778b1c65SDavid S. Miller  *	  4		softint-4, onboard SCSI
111778b1c65SDavid S. Miller  *	  5		softint-5, VME/SBUS level 3
112778b1c65SDavid S. Miller  *	  6		softint-6, onboard ETHERNET
113778b1c65SDavid S. Miller  *	  7		softint-7, VME/SBUS level 4
114778b1c65SDavid S. Miller  *	  8		softint-8, onboard VIDEO
115778b1c65SDavid S. Miller  *	  9		softint-9, VME/SBUS level 5, Module Interrupt
116778b1c65SDavid S. Miller  *	 10		softint-10, system counter/timer
117778b1c65SDavid S. Miller  *	 11		softint-11, VME/SBUS level 6, Floppy
118778b1c65SDavid S. Miller  *	 12		softint-12, Keyboard/Mouse, Serial
119778b1c65SDavid S. Miller  *	 13		softint-13, VME/SBUS level 7, ISDN Audio
120778b1c65SDavid S. Miller  *	 14		softint-14, per-processor counter/timer
121778b1c65SDavid S. Miller  *	 15		softint-15, Asynchronous Errors (broadcast)
122778b1c65SDavid S. Miller  *
123778b1c65SDavid S. Miller  * Each interrupt source is masked distinctly in the sun4m interrupt
124778b1c65SDavid S. Miller  * registers.  The PIL level alone is therefore ambiguous, since multiple
125778b1c65SDavid S. Miller  * interrupt sources map to a single PIL.
126778b1c65SDavid S. Miller  *
127778b1c65SDavid S. Miller  * This ambiguity is resolved in the 'intr' property for device nodes
128778b1c65SDavid S. Miller  * in the OF device tree.  Each 'intr' property entry is composed of
129778b1c65SDavid S. Miller  * two 32-bit words.  The first word is the IRQ priority value, which
130778b1c65SDavid S. Miller  * is what we're intersted in.  The second word is the IRQ vector, which
131778b1c65SDavid S. Miller  * is unused.
132778b1c65SDavid S. Miller  *
133778b1c65SDavid S. Miller  * The low 4 bits of the IRQ priority indicate the PIL, and the upper
134778b1c65SDavid S. Miller  * 4 bits indicate onboard vs. SBUS leveled vs. VME leveled.  0x20
135778b1c65SDavid S. Miller  * means onboard, 0x30 means SBUS leveled, and 0x40 means VME leveled.
136778b1c65SDavid S. Miller  *
137778b1c65SDavid S. Miller  * For example, an 'intr' IRQ priority value of 0x24 is onboard SCSI
138778b1c65SDavid S. Miller  * whereas a value of 0x33 is SBUS level 2.  Here are some sample
139778b1c65SDavid S. Miller  * 'intr' property IRQ priority values from ss4, ss5, ss10, ss20, and
140778b1c65SDavid S. Miller  * Tadpole S3 GX systems.
141778b1c65SDavid S. Miller  *
142778b1c65SDavid S. Miller  * esp: 	0x24	onboard ESP SCSI
143778b1c65SDavid S. Miller  * le:  	0x26	onboard Lance ETHERNET
144778b1c65SDavid S. Miller  * p9100:	0x32	SBUS level 1 P9100 video
145778b1c65SDavid S. Miller  * bpp:  	0x33	SBUS level 2 BPP parallel port device
146778b1c65SDavid S. Miller  * DBRI:	0x39	SBUS level 5 DBRI ISDN audio
147778b1c65SDavid S. Miller  * SUNW,leo:	0x39	SBUS level 5 LEO video
148778b1c65SDavid S. Miller  * pcmcia:	0x3b	SBUS level 6 PCMCIA controller
149778b1c65SDavid S. Miller  * uctrl:	0x3b	SBUS level 6 UCTRL device
150778b1c65SDavid S. Miller  * modem:	0x3d	SBUS level 7 MODEM
151778b1c65SDavid S. Miller  * zs:		0x2c	onboard keyboard/mouse/serial
152778b1c65SDavid S. Miller  * floppy:	0x2b	onboard Floppy
153778b1c65SDavid S. Miller  * power:	0x22	onboard power device (XXX unknown mask bit XXX)
154778b1c65SDavid S. Miller  */
155778b1c65SDavid S. Miller 
1566cf4a924SRobert Reif static unsigned long irq_mask[0x50] = {
1576cf4a924SRobert Reif 	/* SMP */
1586cf4a924SRobert Reif 	0,  SUN4M_SOFT_INT(1),
1596cf4a924SRobert Reif 	SUN4M_SOFT_INT(2),  SUN4M_SOFT_INT(3),
1606cf4a924SRobert Reif 	SUN4M_SOFT_INT(4),  SUN4M_SOFT_INT(5),
1616cf4a924SRobert Reif 	SUN4M_SOFT_INT(6),  SUN4M_SOFT_INT(7),
1626cf4a924SRobert Reif 	SUN4M_SOFT_INT(8),  SUN4M_SOFT_INT(9),
1636cf4a924SRobert Reif 	SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
1646cf4a924SRobert Reif 	SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
1656cf4a924SRobert Reif 	SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
1666cf4a924SRobert Reif 	/* soft */
1676cf4a924SRobert Reif 	0,  SUN4M_SOFT_INT(1),
1686cf4a924SRobert Reif 	SUN4M_SOFT_INT(2),  SUN4M_SOFT_INT(3),
1696cf4a924SRobert Reif 	SUN4M_SOFT_INT(4),  SUN4M_SOFT_INT(5),
1706cf4a924SRobert Reif 	SUN4M_SOFT_INT(6),  SUN4M_SOFT_INT(7),
1716cf4a924SRobert Reif 	SUN4M_SOFT_INT(8),  SUN4M_SOFT_INT(9),
1726cf4a924SRobert Reif 	SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
1736cf4a924SRobert Reif 	SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
1746cf4a924SRobert Reif 	SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
1756cf4a924SRobert Reif 	/* onboard */
1766cf4a924SRobert Reif 	0, 0, 0, 0,
1776cf4a924SRobert Reif 	SUN4M_INT_SCSI,  0, SUN4M_INT_ETHERNET, 0,
1786cf4a924SRobert Reif 	SUN4M_INT_VIDEO, SUN4M_INT_MODULE,
1796cf4a924SRobert Reif 	SUN4M_INT_REALTIME, SUN4M_INT_FLOPPY,
1806cf4a924SRobert Reif 	(SUN4M_INT_SERIAL | SUN4M_INT_KBDMS),
1816cf4a924SRobert Reif 	SUN4M_INT_AUDIO, 0, SUN4M_INT_MODULE_ERR,
1826cf4a924SRobert Reif 	/* sbus */
1836cf4a924SRobert Reif 	0, 0, SUN4M_INT_SBUS(0), SUN4M_INT_SBUS(1),
1846cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(2), 0, SUN4M_INT_SBUS(3),
1856cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(4), 0, SUN4M_INT_SBUS(5),
1866cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(6), 0, 0,
1876cf4a924SRobert Reif 	/* vme */
1886cf4a924SRobert Reif 	0, 0, SUN4M_INT_VME(0), SUN4M_INT_VME(1),
1896cf4a924SRobert Reif 	0, SUN4M_INT_VME(2), 0, SUN4M_INT_VME(3),
1906cf4a924SRobert Reif 	0, SUN4M_INT_VME(4), 0, SUN4M_INT_VME(5),
1916cf4a924SRobert Reif 	0, SUN4M_INT_VME(6), 0, 0
1921da177e4SLinus Torvalds };
1931da177e4SLinus Torvalds 
194c61c65cdSAdrian Bunk static unsigned long sun4m_get_irqmask(unsigned int irq)
1951da177e4SLinus Torvalds {
1961da177e4SLinus Torvalds 	unsigned long mask;
1971da177e4SLinus Torvalds 
1986cf4a924SRobert Reif 	if (irq < 0x50)
1996cf4a924SRobert Reif 		mask = irq_mask[irq];
2006cf4a924SRobert Reif 	else
2016cf4a924SRobert Reif 		mask = 0;
2026cf4a924SRobert Reif 
2031da177e4SLinus Torvalds 	if (!mask)
2046cf4a924SRobert Reif 		printk(KERN_ERR "sun4m_get_irqmask: IRQ%d has no valid mask!\n",
2056cf4a924SRobert Reif 		       irq);
2066cf4a924SRobert Reif 
2071da177e4SLinus Torvalds 	return mask;
2081da177e4SLinus Torvalds }
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds static void sun4m_disable_irq(unsigned int irq_nr)
2111da177e4SLinus Torvalds {
2121da177e4SLinus Torvalds 	unsigned long mask, flags;
2131da177e4SLinus Torvalds 	int cpu = smp_processor_id();
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 	mask = sun4m_get_irqmask(irq_nr);
2161da177e4SLinus Torvalds 	local_irq_save(flags);
2171da177e4SLinus Torvalds 	if (irq_nr > 15)
21869c010b2SDavid S. Miller 		sbus_writel(mask, &sun4m_irq_global->mask_set);
2191da177e4SLinus Torvalds 	else
22069c010b2SDavid S. Miller 		sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
2211da177e4SLinus Torvalds 	local_irq_restore(flags);
2221da177e4SLinus Torvalds }
2231da177e4SLinus Torvalds 
2241da177e4SLinus Torvalds static void sun4m_enable_irq(unsigned int irq_nr)
2251da177e4SLinus Torvalds {
2261da177e4SLinus Torvalds 	unsigned long mask, flags;
2271da177e4SLinus Torvalds 	int cpu = smp_processor_id();
2281da177e4SLinus Torvalds 
2291da177e4SLinus Torvalds 	/* Dreadful floppy hack. When we use 0x2b instead of
2301da177e4SLinus Torvalds          * 0x0b the system blows (it starts to whistle!).
2311da177e4SLinus Torvalds          * So we continue to use 0x0b. Fixme ASAP. --P3
2321da177e4SLinus Torvalds          */
2331da177e4SLinus Torvalds         if (irq_nr != 0x0b) {
2341da177e4SLinus Torvalds 		mask = sun4m_get_irqmask(irq_nr);
2351da177e4SLinus Torvalds 		local_irq_save(flags);
2361da177e4SLinus Torvalds 		if (irq_nr > 15)
23769c010b2SDavid S. Miller 			sbus_writel(mask, &sun4m_irq_global->mask_clear);
2381da177e4SLinus Torvalds 		else
23969c010b2SDavid S. Miller 			sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
2401da177e4SLinus Torvalds 		local_irq_restore(flags);
2411da177e4SLinus Torvalds 	} else {
2421da177e4SLinus Torvalds 		local_irq_save(flags);
24369c010b2SDavid S. Miller 		sbus_writel(SUN4M_INT_FLOPPY, &sun4m_irq_global->mask_clear);
2441da177e4SLinus Torvalds 		local_irq_restore(flags);
2451da177e4SLinus Torvalds 	}
2461da177e4SLinus Torvalds }
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds static unsigned long cpu_pil_to_imask[16] = {
2491da177e4SLinus Torvalds /*0*/	0x00000000,
2501da177e4SLinus Torvalds /*1*/	0x00000000,
2511da177e4SLinus Torvalds /*2*/	SUN4M_INT_SBUS(0) | SUN4M_INT_VME(0),
2521da177e4SLinus Torvalds /*3*/	SUN4M_INT_SBUS(1) | SUN4M_INT_VME(1),
2531da177e4SLinus Torvalds /*4*/	SUN4M_INT_SCSI,
2541da177e4SLinus Torvalds /*5*/	SUN4M_INT_SBUS(2) | SUN4M_INT_VME(2),
2551da177e4SLinus Torvalds /*6*/	SUN4M_INT_ETHERNET,
2561da177e4SLinus Torvalds /*7*/	SUN4M_INT_SBUS(3) | SUN4M_INT_VME(3),
2571da177e4SLinus Torvalds /*8*/	SUN4M_INT_VIDEO,
2581da177e4SLinus Torvalds /*9*/	SUN4M_INT_SBUS(4) | SUN4M_INT_VME(4) | SUN4M_INT_MODULE_ERR,
2591da177e4SLinus Torvalds /*10*/	SUN4M_INT_REALTIME,
2601da177e4SLinus Torvalds /*11*/	SUN4M_INT_SBUS(5) | SUN4M_INT_VME(5) | SUN4M_INT_FLOPPY,
2611da177e4SLinus Torvalds /*12*/	SUN4M_INT_SERIAL  | SUN4M_INT_KBDMS,
2626cf4a924SRobert Reif /*13*/	SUN4M_INT_SBUS(6) | SUN4M_INT_VME(6) | SUN4M_INT_AUDIO,
2631da177e4SLinus Torvalds /*14*/	SUN4M_INT_E14,
2646cf4a924SRobert Reif /*15*/	SUN4M_INT_ERROR
2651da177e4SLinus Torvalds };
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds /* We assume the caller has disabled local interrupts when these are called,
2681da177e4SLinus Torvalds  * or else very bizarre behavior will result.
2691da177e4SLinus Torvalds  */
2701da177e4SLinus Torvalds static void sun4m_disable_pil_irq(unsigned int pil)
2711da177e4SLinus Torvalds {
27269c010b2SDavid S. Miller 	sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_set);
2731da177e4SLinus Torvalds }
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds static void sun4m_enable_pil_irq(unsigned int pil)
2761da177e4SLinus Torvalds {
27769c010b2SDavid S. Miller 	sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_clear);
2781da177e4SLinus Torvalds }
2791da177e4SLinus Torvalds 
2801da177e4SLinus Torvalds #ifdef CONFIG_SMP
2811da177e4SLinus Torvalds static void sun4m_send_ipi(int cpu, int level)
2821da177e4SLinus Torvalds {
28369c010b2SDavid S. Miller 	unsigned long mask = sun4m_get_irqmask(level);
28469c010b2SDavid S. Miller 	sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
2851da177e4SLinus Torvalds }
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds static void sun4m_clear_ipi(int cpu, int level)
2881da177e4SLinus Torvalds {
28969c010b2SDavid S. Miller 	unsigned long mask = sun4m_get_irqmask(level);
29069c010b2SDavid S. Miller 	sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds 
2931da177e4SLinus Torvalds static void sun4m_set_udt(int cpu)
2941da177e4SLinus Torvalds {
29569c010b2SDavid S. Miller 	sbus_writel(cpu, &sun4m_irq_global->interrupt_target);
2961da177e4SLinus Torvalds }
2971da177e4SLinus Torvalds #endif
2981da177e4SLinus Torvalds 
2999b2e43aeSDavid S. Miller struct sun4m_timer_percpu {
3009b2e43aeSDavid S. Miller 	u32		l14_limit;
3019b2e43aeSDavid S. Miller 	u32		l14_count;
3029b2e43aeSDavid S. Miller 	u32		l14_limit_noclear;
3039b2e43aeSDavid S. Miller 	u32		user_timer_start_stop;
3049b2e43aeSDavid S. Miller };
3059b2e43aeSDavid S. Miller 
3069b2e43aeSDavid S. Miller static struct sun4m_timer_percpu __iomem *timers_percpu[SUN4M_NCPUS];
3079b2e43aeSDavid S. Miller 
3089b2e43aeSDavid S. Miller struct sun4m_timer_global {
3099b2e43aeSDavid S. Miller 	u32		l10_limit;
3109b2e43aeSDavid S. Miller 	u32		l10_count;
3119b2e43aeSDavid S. Miller 	u32		l10_limit_noclear;
3129b2e43aeSDavid S. Miller 	u32		reserved;
3139b2e43aeSDavid S. Miller 	u32		timer_config;
3149b2e43aeSDavid S. Miller };
3159b2e43aeSDavid S. Miller 
3169b2e43aeSDavid S. Miller static struct sun4m_timer_global __iomem *timers_global;
3179b2e43aeSDavid S. Miller 
3186cf4a924SRobert Reif #define TIMER_IRQ  	(OBP_INT_LEVEL_ONBOARD | 10)
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10);
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds static void sun4m_clear_clock_irq(void)
3231da177e4SLinus Torvalds {
3249b2e43aeSDavid S. Miller 	sbus_readl(&timers_global->l10_limit);
3251da177e4SLinus Torvalds }
3261da177e4SLinus Torvalds 
3276cf4a924SRobert Reif void sun4m_nmi(struct pt_regs *regs)
3286cf4a924SRobert Reif {
3296cf4a924SRobert Reif 	unsigned long afsr, afar, si;
3306cf4a924SRobert Reif 
3316cf4a924SRobert Reif 	printk(KERN_ERR "Aieee: sun4m NMI received!\n");
3326cf4a924SRobert Reif 	/* XXX HyperSparc hack XXX */
3336cf4a924SRobert Reif 	__asm__ __volatile__("mov 0x500, %%g1\n\t"
3346cf4a924SRobert Reif 			     "lda [%%g1] 0x4, %0\n\t"
3356cf4a924SRobert Reif 			     "mov 0x600, %%g1\n\t"
3366cf4a924SRobert Reif 			     "lda [%%g1] 0x4, %1\n\t" :
3376cf4a924SRobert Reif 			     "=r" (afsr), "=r" (afar));
3386cf4a924SRobert Reif 	printk(KERN_ERR "afsr=%08lx afar=%08lx\n", afsr, afar);
3396cf4a924SRobert Reif 	si = sbus_readl(&sun4m_irq_global->pending);
3406cf4a924SRobert Reif 	printk(KERN_ERR "si=%08lx\n", si);
3416cf4a924SRobert Reif 	if (si & SUN4M_INT_MODULE_ERR)
3426cf4a924SRobert Reif 		printk(KERN_ERR "Module async error\n");
3436cf4a924SRobert Reif 	if (si & SUN4M_INT_M2S_WRITE_ERR)
3446cf4a924SRobert Reif 		printk(KERN_ERR "MBus/SBus async error\n");
3456cf4a924SRobert Reif 	if (si & SUN4M_INT_ECC_ERR)
3466cf4a924SRobert Reif 		printk(KERN_ERR "ECC memory error\n");
3476cf4a924SRobert Reif 	if (si & SUN4M_INT_VME_ERR)
3486cf4a924SRobert Reif 		printk(KERN_ERR "VME async error\n");
3496cf4a924SRobert Reif 	printk(KERN_ERR "you lose buddy boy...\n");
3506cf4a924SRobert Reif 	show_regs(regs);
3516cf4a924SRobert Reif 	prom_halt();
3526cf4a924SRobert Reif }
3536cf4a924SRobert Reif 
3541de937a5SDavid S. Miller /* Exported for sun4m_smp.c */
3551de937a5SDavid S. Miller void sun4m_clear_profile_irq(int cpu)
3561da177e4SLinus Torvalds {
3579b2e43aeSDavid S. Miller 	sbus_readl(&timers_percpu[cpu]->l14_limit);
3581da177e4SLinus Torvalds }
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds static void sun4m_load_profile_irq(int cpu, unsigned int limit)
3611da177e4SLinus Torvalds {
3629b2e43aeSDavid S. Miller 	sbus_writel(limit, &timers_percpu[cpu]->l14_limit);
3631da177e4SLinus Torvalds }
3641da177e4SLinus Torvalds 
36540220c1aSDavid Howells static void __init sun4m_init_timers(irq_handler_t counter_fn)
3661da177e4SLinus Torvalds {
3679b2e43aeSDavid S. Miller 	struct device_node *dp = of_find_node_by_name(NULL, "counter");
3689b2e43aeSDavid S. Miller 	int i, err, len, num_cpu_timers;
3699b2e43aeSDavid S. Miller 	const u32 *addr;
3701da177e4SLinus Torvalds 
3719b2e43aeSDavid S. Miller 	if (!dp) {
3729b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: No 'counter' node.\n");
3739b2e43aeSDavid S. Miller 		return;
3741da177e4SLinus Torvalds 	}
3751da177e4SLinus Torvalds 
3769b2e43aeSDavid S. Miller 	addr = of_get_property(dp, "address", &len);
377*c2e27c35SNicolas Palix 	of_node_put(dp);
3789b2e43aeSDavid S. Miller 	if (!addr) {
3799b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: No 'address' prop.\n");
3809b2e43aeSDavid S. Miller 		return;
3811da177e4SLinus Torvalds 	}
3821da177e4SLinus Torvalds 
3839b2e43aeSDavid S. Miller 	num_cpu_timers = (len / sizeof(u32)) - 1;
3849b2e43aeSDavid S. Miller 	for (i = 0; i < num_cpu_timers; i++) {
3859b2e43aeSDavid S. Miller 		timers_percpu[i] = (void __iomem *)
3869b2e43aeSDavid S. Miller 			(unsigned long) addr[i];
3871da177e4SLinus Torvalds 	}
3889b2e43aeSDavid S. Miller 	timers_global = (void __iomem *)
3899b2e43aeSDavid S. Miller 		(unsigned long) addr[num_cpu_timers];
3909b2e43aeSDavid S. Miller 
3919b2e43aeSDavid S. Miller 	sbus_writel((((1000000/HZ) + 1) << 10), &timers_global->l10_limit);
3929b2e43aeSDavid S. Miller 
3939b2e43aeSDavid S. Miller 	master_l10_counter = &timers_global->l10_count;
3949b2e43aeSDavid S. Miller 
3959b2e43aeSDavid S. Miller 	err = request_irq(TIMER_IRQ, counter_fn,
3969b2e43aeSDavid S. Miller 			  (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
3979b2e43aeSDavid S. Miller 	if (err) {
3989b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: Register IRQ error %d.\n",
3999b2e43aeSDavid S. Miller 			err);
4009b2e43aeSDavid S. Miller 		return;
4019b2e43aeSDavid S. Miller 	}
4029b2e43aeSDavid S. Miller 
4039b2e43aeSDavid S. Miller 	for (i = 0; i < num_cpu_timers; i++)
4049b2e43aeSDavid S. Miller 		sbus_writel(0, &timers_percpu[i]->l14_limit);
4059b2e43aeSDavid S. Miller 	if (num_cpu_timers == 4)
40669c010b2SDavid S. Miller 		sbus_writel(SUN4M_INT_E14, &sun4m_irq_global->mask_set);
4079b2e43aeSDavid S. Miller 
4081da177e4SLinus Torvalds #ifdef CONFIG_SMP
4091da177e4SLinus Torvalds 	{
4101da177e4SLinus Torvalds 		unsigned long flags;
4111da177e4SLinus Torvalds 		extern unsigned long lvl14_save[4];
4121da177e4SLinus Torvalds 		struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds 		/* For SMP we use the level 14 ticker, however the bootup code
415d1a78c32SSimon Arlott 		 * has copied the firmware's level 14 vector into the boot cpu's
4161da177e4SLinus Torvalds 		 * trap table, we must fix this now or we get squashed.
4171da177e4SLinus Torvalds 		 */
4181da177e4SLinus Torvalds 		local_irq_save(flags);
4191da177e4SLinus Torvalds 		trap_table->inst_one = lvl14_save[0];
4201da177e4SLinus Torvalds 		trap_table->inst_two = lvl14_save[1];
4211da177e4SLinus Torvalds 		trap_table->inst_three = lvl14_save[2];
4221da177e4SLinus Torvalds 		trap_table->inst_four = lvl14_save[3];
4231da177e4SLinus Torvalds 		local_flush_cache_all();
4241da177e4SLinus Torvalds 		local_irq_restore(flags);
4251da177e4SLinus Torvalds 	}
4261da177e4SLinus Torvalds #endif
4271da177e4SLinus Torvalds }
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds void __init sun4m_init_IRQ(void)
4301da177e4SLinus Torvalds {
43169c010b2SDavid S. Miller 	struct device_node *dp = of_find_node_by_name(NULL, "interrupt");
43269c010b2SDavid S. Miller 	int len, i, mid, num_cpu_iregs;
43369c010b2SDavid S. Miller 	const u32 *addr;
43469c010b2SDavid S. Miller 
43569c010b2SDavid S. Miller 	if (!dp) {
43669c010b2SDavid S. Miller 		printk(KERN_ERR "sun4m_init_IRQ: No 'interrupt' node.\n");
43769c010b2SDavid S. Miller 		return;
43869c010b2SDavid S. Miller 	}
43969c010b2SDavid S. Miller 
44069c010b2SDavid S. Miller 	addr = of_get_property(dp, "address", &len);
441*c2e27c35SNicolas Palix 	of_node_put(dp);
44269c010b2SDavid S. Miller 	if (!addr) {
44369c010b2SDavid S. Miller 		printk(KERN_ERR "sun4m_init_IRQ: No 'address' prop.\n");
44469c010b2SDavid S. Miller 		return;
44569c010b2SDavid S. Miller 	}
44669c010b2SDavid S. Miller 
44769c010b2SDavid S. Miller 	num_cpu_iregs = (len / sizeof(u32)) - 1;
44869c010b2SDavid S. Miller 	for (i = 0; i < num_cpu_iregs; i++) {
44969c010b2SDavid S. Miller 		sun4m_irq_percpu[i] = (void __iomem *)
45069c010b2SDavid S. Miller 			(unsigned long) addr[i];
45169c010b2SDavid S. Miller 	}
45269c010b2SDavid S. Miller 	sun4m_irq_global = (void __iomem *)
45369c010b2SDavid S. Miller 		(unsigned long) addr[num_cpu_iregs];
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds 	local_irq_disable();
4561da177e4SLinus Torvalds 
45769c010b2SDavid S. Miller 	sbus_writel(~SUN4M_INT_MASKALL, &sun4m_irq_global->mask_set);
4581da177e4SLinus Torvalds 	for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++)
45969c010b2SDavid S. Miller 		sbus_writel(~0x17fff, &sun4m_irq_percpu[mid]->clear);
4601da177e4SLinus Torvalds 
461e7913de9SDavid S. Miller 	if (num_cpu_iregs == 4)
46269c010b2SDavid S. Miller 		sbus_writel(0, &sun4m_irq_global->interrupt_target);
463e7913de9SDavid S. Miller 
4641da177e4SLinus Torvalds 	BTFIXUPSET_CALL(enable_irq, sun4m_enable_irq, BTFIXUPCALL_NORM);
4651da177e4SLinus Torvalds 	BTFIXUPSET_CALL(disable_irq, sun4m_disable_irq, BTFIXUPCALL_NORM);
4661da177e4SLinus Torvalds 	BTFIXUPSET_CALL(enable_pil_irq, sun4m_enable_pil_irq, BTFIXUPCALL_NORM);
4671da177e4SLinus Torvalds 	BTFIXUPSET_CALL(disable_pil_irq, sun4m_disable_pil_irq, BTFIXUPCALL_NORM);
4681da177e4SLinus Torvalds 	BTFIXUPSET_CALL(clear_clock_irq, sun4m_clear_clock_irq, BTFIXUPCALL_NORM);
4691da177e4SLinus Torvalds 	BTFIXUPSET_CALL(load_profile_irq, sun4m_load_profile_irq, BTFIXUPCALL_NORM);
4701da177e4SLinus Torvalds 	sparc_init_timers = sun4m_init_timers;
4711da177e4SLinus Torvalds #ifdef CONFIG_SMP
4721da177e4SLinus Torvalds 	BTFIXUPSET_CALL(set_cpu_int, sun4m_send_ipi, BTFIXUPCALL_NORM);
4731da177e4SLinus Torvalds 	BTFIXUPSET_CALL(clear_cpu_int, sun4m_clear_ipi, BTFIXUPCALL_NORM);
4741da177e4SLinus Torvalds 	BTFIXUPSET_CALL(set_irq_udt, sun4m_set_udt, BTFIXUPCALL_NORM);
4751da177e4SLinus Torvalds #endif
47669c010b2SDavid S. Miller 
4771da177e4SLinus Torvalds 	/* Cannot enable interrupts until OBP ticker is disabled. */
4781da177e4SLinus Torvalds }
479