xref: /openbmc/linux/arch/sparc/kernel/sun4m_irq.c (revision bbdc2661eabddd442240533a66b2290f77d89ccc)
1aba20a82SSam Ravnborg /*
2aba20a82SSam Ravnborg  * sun4m irq support
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 <asm/timer.h>
131da177e4SLinus Torvalds #include <asm/traps.h>
141da177e4SLinus Torvalds #include <asm/pgalloc.h>
151da177e4SLinus Torvalds #include <asm/pgtable.h>
161da177e4SLinus Torvalds #include <asm/irq.h>
171da177e4SLinus Torvalds #include <asm/io.h>
181da177e4SLinus Torvalds #include <asm/cacheflush.h>
191da177e4SLinus Torvalds 
2032231a66SAl Viro #include "irq.h"
21aba20a82SSam Ravnborg #include "kernel.h"
22aba20a82SSam Ravnborg 
23aba20a82SSam Ravnborg /* Sample sun4m IRQ layout:
24aba20a82SSam Ravnborg  *
25aba20a82SSam Ravnborg  * 0x22 - Power
26aba20a82SSam Ravnborg  * 0x24 - ESP SCSI
27aba20a82SSam Ravnborg  * 0x26 - Lance ethernet
28aba20a82SSam Ravnborg  * 0x2b - Floppy
29aba20a82SSam Ravnborg  * 0x2c - Zilog uart
30aba20a82SSam Ravnborg  * 0x32 - SBUS level 0
31aba20a82SSam Ravnborg  * 0x33 - Parallel port, SBUS level 1
32aba20a82SSam Ravnborg  * 0x35 - SBUS level 2
33aba20a82SSam Ravnborg  * 0x37 - SBUS level 3
34aba20a82SSam Ravnborg  * 0x39 - Audio, Graphics card, SBUS level 4
35aba20a82SSam Ravnborg  * 0x3b - SBUS level 5
36aba20a82SSam Ravnborg  * 0x3d - SBUS level 6
37aba20a82SSam Ravnborg  *
38aba20a82SSam Ravnborg  * Each interrupt source has a mask bit in the interrupt registers.
39aba20a82SSam Ravnborg  * When the mask bit is set, this blocks interrupt deliver.  So you
40aba20a82SSam Ravnborg  * clear the bit to enable the interrupt.
41aba20a82SSam Ravnborg  *
42aba20a82SSam Ravnborg  * Interrupts numbered less than 0x10 are software triggered interrupts
43aba20a82SSam Ravnborg  * and unused by Linux.
44aba20a82SSam Ravnborg  *
45aba20a82SSam Ravnborg  * Interrupt level assignment on sun4m:
46aba20a82SSam Ravnborg  *
47aba20a82SSam Ravnborg  *	level		source
48aba20a82SSam Ravnborg  * ------------------------------------------------------------
49aba20a82SSam Ravnborg  *	  1		softint-1
50aba20a82SSam Ravnborg  *	  2		softint-2, VME/SBUS level 1
51aba20a82SSam Ravnborg  *	  3		softint-3, VME/SBUS level 2
52aba20a82SSam Ravnborg  *	  4		softint-4, onboard SCSI
53aba20a82SSam Ravnborg  *	  5		softint-5, VME/SBUS level 3
54aba20a82SSam Ravnborg  *	  6		softint-6, onboard ETHERNET
55aba20a82SSam Ravnborg  *	  7		softint-7, VME/SBUS level 4
56aba20a82SSam Ravnborg  *	  8		softint-8, onboard VIDEO
57aba20a82SSam Ravnborg  *	  9		softint-9, VME/SBUS level 5, Module Interrupt
58aba20a82SSam Ravnborg  *	 10		softint-10, system counter/timer
59aba20a82SSam Ravnborg  *	 11		softint-11, VME/SBUS level 6, Floppy
60aba20a82SSam Ravnborg  *	 12		softint-12, Keyboard/Mouse, Serial
61aba20a82SSam Ravnborg  *	 13		softint-13, VME/SBUS level 7, ISDN Audio
62aba20a82SSam Ravnborg  *	 14		softint-14, per-processor counter/timer
63aba20a82SSam Ravnborg  *	 15		softint-15, Asynchronous Errors (broadcast)
64aba20a82SSam Ravnborg  *
65aba20a82SSam Ravnborg  * Each interrupt source is masked distinctly in the sun4m interrupt
66aba20a82SSam Ravnborg  * registers.  The PIL level alone is therefore ambiguous, since multiple
67aba20a82SSam Ravnborg  * interrupt sources map to a single PIL.
68aba20a82SSam Ravnborg  *
69aba20a82SSam Ravnborg  * This ambiguity is resolved in the 'intr' property for device nodes
70aba20a82SSam Ravnborg  * in the OF device tree.  Each 'intr' property entry is composed of
71aba20a82SSam Ravnborg  * two 32-bit words.  The first word is the IRQ priority value, which
72aba20a82SSam Ravnborg  * is what we're intersted in.  The second word is the IRQ vector, which
73aba20a82SSam Ravnborg  * is unused.
74aba20a82SSam Ravnborg  *
75aba20a82SSam Ravnborg  * The low 4 bits of the IRQ priority indicate the PIL, and the upper
76aba20a82SSam Ravnborg  * 4 bits indicate onboard vs. SBUS leveled vs. VME leveled.  0x20
77aba20a82SSam Ravnborg  * means onboard, 0x30 means SBUS leveled, and 0x40 means VME leveled.
78aba20a82SSam Ravnborg  *
79aba20a82SSam Ravnborg  * For example, an 'intr' IRQ priority value of 0x24 is onboard SCSI
80aba20a82SSam Ravnborg  * whereas a value of 0x33 is SBUS level 2.  Here are some sample
81aba20a82SSam Ravnborg  * 'intr' property IRQ priority values from ss4, ss5, ss10, ss20, and
82aba20a82SSam Ravnborg  * Tadpole S3 GX systems.
83aba20a82SSam Ravnborg  *
84aba20a82SSam Ravnborg  * esp:		0x24	onboard ESP SCSI
85aba20a82SSam Ravnborg  * le:		0x26	onboard Lance ETHERNET
86aba20a82SSam Ravnborg  * p9100:	0x32	SBUS level 1 P9100 video
87aba20a82SSam Ravnborg  * bpp:		0x33	SBUS level 2 BPP parallel port device
88aba20a82SSam Ravnborg  * DBRI:	0x39	SBUS level 5 DBRI ISDN audio
89aba20a82SSam Ravnborg  * SUNW,leo:	0x39	SBUS level 5 LEO video
90aba20a82SSam Ravnborg  * pcmcia:	0x3b	SBUS level 6 PCMCIA controller
91aba20a82SSam Ravnborg  * uctrl:	0x3b	SBUS level 6 UCTRL device
92aba20a82SSam Ravnborg  * modem:	0x3d	SBUS level 7 MODEM
93aba20a82SSam Ravnborg  * zs:		0x2c	onboard keyboard/mouse/serial
94aba20a82SSam Ravnborg  * floppy:	0x2b	onboard Floppy
95aba20a82SSam Ravnborg  * power:	0x22	onboard power device (XXX unknown mask bit XXX)
96aba20a82SSam Ravnborg  */
97aba20a82SSam Ravnborg 
9832231a66SAl Viro 
9969c010b2SDavid S. Miller struct sun4m_irq_percpu {
10069c010b2SDavid S. Miller 	u32		pending;
10169c010b2SDavid S. Miller 	u32		clear;
10269c010b2SDavid S. Miller 	u32		set;
10332231a66SAl Viro };
10432231a66SAl Viro 
10569c010b2SDavid S. Miller struct sun4m_irq_global {
10669c010b2SDavid S. Miller 	u32		pending;
10769c010b2SDavid S. Miller 	u32		mask;
10869c010b2SDavid S. Miller 	u32		mask_clear;
10969c010b2SDavid S. Miller 	u32		mask_set;
11069c010b2SDavid S. Miller 	u32		interrupt_target;
11132231a66SAl Viro };
11232231a66SAl Viro 
11369c010b2SDavid S. Miller /* Code in entry.S needs to get at these register mappings.  */
11469c010b2SDavid S. Miller struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS];
11569c010b2SDavid S. Miller struct sun4m_irq_global __iomem *sun4m_irq_global;
11669c010b2SDavid S. Miller 
11732231a66SAl Viro /* Dave Redman (djhr@tadpole.co.uk)
11832231a66SAl Viro  * The sun4m interrupt registers.
11932231a66SAl Viro  */
12032231a66SAl Viro #define SUN4M_INT_ENABLE	0x80000000
12132231a66SAl Viro #define SUN4M_INT_E14		0x00000080
12232231a66SAl Viro #define SUN4M_INT_E10		0x00080000
12332231a66SAl Viro 
12432231a66SAl Viro #define SUN4M_HARD_INT(x)	(0x000000001 << (x))
12532231a66SAl Viro #define SUN4M_SOFT_INT(x)	(0x000010000 << (x))
12632231a66SAl Viro 
12732231a66SAl Viro #define	SUN4M_INT_MASKALL	0x80000000	  /* mask all interrupts */
12832231a66SAl Viro #define	SUN4M_INT_MODULE_ERR	0x40000000	  /* module error */
1296cf4a924SRobert Reif #define	SUN4M_INT_M2S_WRITE_ERR	0x20000000	  /* write buffer error */
1306cf4a924SRobert Reif #define	SUN4M_INT_ECC_ERR	0x10000000	  /* ecc memory error */
1316cf4a924SRobert Reif #define	SUN4M_INT_VME_ERR	0x08000000	  /* vme async error */
13232231a66SAl Viro #define	SUN4M_INT_FLOPPY	0x00400000	  /* floppy disk */
13332231a66SAl Viro #define	SUN4M_INT_MODULE	0x00200000	  /* module interrupt */
13432231a66SAl Viro #define	SUN4M_INT_VIDEO		0x00100000	  /* onboard video */
13532231a66SAl Viro #define	SUN4M_INT_REALTIME	0x00080000	  /* system timer */
13632231a66SAl Viro #define	SUN4M_INT_SCSI		0x00040000	  /* onboard scsi */
13732231a66SAl Viro #define	SUN4M_INT_AUDIO		0x00020000	  /* audio/isdn */
13832231a66SAl Viro #define	SUN4M_INT_ETHERNET	0x00010000	  /* onboard ethernet */
13932231a66SAl Viro #define	SUN4M_INT_SERIAL	0x00008000	  /* serial ports */
14032231a66SAl Viro #define	SUN4M_INT_KBDMS		0x00004000	  /* keyboard/mouse */
14132231a66SAl Viro #define	SUN4M_INT_SBUSBITS	0x00003F80	  /* sbus int bits */
1426cf4a924SRobert Reif #define	SUN4M_INT_VMEBITS	0x0000007F	  /* vme int bits */
1436cf4a924SRobert Reif 
1446cf4a924SRobert Reif #define	SUN4M_INT_ERROR		(SUN4M_INT_MODULE_ERR |    \
1456cf4a924SRobert Reif 				 SUN4M_INT_M2S_WRITE_ERR | \
1466cf4a924SRobert Reif 				 SUN4M_INT_ECC_ERR |       \
1476cf4a924SRobert Reif 				 SUN4M_INT_VME_ERR)
14832231a66SAl Viro 
14932231a66SAl Viro #define SUN4M_INT_SBUS(x)	(1 << (x+7))
15032231a66SAl Viro #define SUN4M_INT_VME(x)	(1 << (x))
15132231a66SAl Viro 
1526cf4a924SRobert Reif /* Interrupt levels used by OBP */
1536cf4a924SRobert Reif #define	OBP_INT_LEVEL_SOFT	0x10
1546cf4a924SRobert Reif #define	OBP_INT_LEVEL_ONBOARD	0x20
1556cf4a924SRobert Reif #define	OBP_INT_LEVEL_SBUS	0x30
1566cf4a924SRobert Reif #define	OBP_INT_LEVEL_VME	0x40
1576cf4a924SRobert Reif 
1586cf4a924SRobert Reif static unsigned long irq_mask[0x50] = {
1596cf4a924SRobert Reif 	/* SMP */
1606cf4a924SRobert Reif 	0,  SUN4M_SOFT_INT(1),
1616cf4a924SRobert Reif 	SUN4M_SOFT_INT(2),  SUN4M_SOFT_INT(3),
1626cf4a924SRobert Reif 	SUN4M_SOFT_INT(4),  SUN4M_SOFT_INT(5),
1636cf4a924SRobert Reif 	SUN4M_SOFT_INT(6),  SUN4M_SOFT_INT(7),
1646cf4a924SRobert Reif 	SUN4M_SOFT_INT(8),  SUN4M_SOFT_INT(9),
1656cf4a924SRobert Reif 	SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
1666cf4a924SRobert Reif 	SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
1676cf4a924SRobert Reif 	SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
1686cf4a924SRobert Reif 	/* soft */
1696cf4a924SRobert Reif 	0,  SUN4M_SOFT_INT(1),
1706cf4a924SRobert Reif 	SUN4M_SOFT_INT(2),  SUN4M_SOFT_INT(3),
1716cf4a924SRobert Reif 	SUN4M_SOFT_INT(4),  SUN4M_SOFT_INT(5),
1726cf4a924SRobert Reif 	SUN4M_SOFT_INT(6),  SUN4M_SOFT_INT(7),
1736cf4a924SRobert Reif 	SUN4M_SOFT_INT(8),  SUN4M_SOFT_INT(9),
1746cf4a924SRobert Reif 	SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
1756cf4a924SRobert Reif 	SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
1766cf4a924SRobert Reif 	SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
1776cf4a924SRobert Reif 	/* onboard */
1786cf4a924SRobert Reif 	0, 0, 0, 0,
1796cf4a924SRobert Reif 	SUN4M_INT_SCSI,  0, SUN4M_INT_ETHERNET, 0,
1806cf4a924SRobert Reif 	SUN4M_INT_VIDEO, SUN4M_INT_MODULE,
1816cf4a924SRobert Reif 	SUN4M_INT_REALTIME, SUN4M_INT_FLOPPY,
1826cf4a924SRobert Reif 	(SUN4M_INT_SERIAL | SUN4M_INT_KBDMS),
1836cf4a924SRobert Reif 	SUN4M_INT_AUDIO, 0, SUN4M_INT_MODULE_ERR,
1846cf4a924SRobert Reif 	/* sbus */
1856cf4a924SRobert Reif 	0, 0, SUN4M_INT_SBUS(0), SUN4M_INT_SBUS(1),
1866cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(2), 0, SUN4M_INT_SBUS(3),
1876cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(4), 0, SUN4M_INT_SBUS(5),
1886cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(6), 0, 0,
1896cf4a924SRobert Reif 	/* vme */
1906cf4a924SRobert Reif 	0, 0, SUN4M_INT_VME(0), SUN4M_INT_VME(1),
1916cf4a924SRobert Reif 	0, SUN4M_INT_VME(2), 0, SUN4M_INT_VME(3),
1926cf4a924SRobert Reif 	0, SUN4M_INT_VME(4), 0, SUN4M_INT_VME(5),
1936cf4a924SRobert Reif 	0, SUN4M_INT_VME(6), 0, 0
1941da177e4SLinus Torvalds };
1951da177e4SLinus Torvalds 
196c61c65cdSAdrian Bunk static unsigned long sun4m_get_irqmask(unsigned int irq)
1971da177e4SLinus Torvalds {
1981da177e4SLinus Torvalds 	unsigned long mask;
1991da177e4SLinus Torvalds 
2006cf4a924SRobert Reif 	if (irq < 0x50)
2016cf4a924SRobert Reif 		mask = irq_mask[irq];
2026cf4a924SRobert Reif 	else
2036cf4a924SRobert Reif 		mask = 0;
2046cf4a924SRobert Reif 
2051da177e4SLinus Torvalds 	if (!mask)
2066cf4a924SRobert Reif 		printk(KERN_ERR "sun4m_get_irqmask: IRQ%d has no valid mask!\n",
2076cf4a924SRobert Reif 		       irq);
2086cf4a924SRobert Reif 
2091da177e4SLinus Torvalds 	return mask;
2101da177e4SLinus Torvalds }
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds static void sun4m_disable_irq(unsigned int irq_nr)
2131da177e4SLinus Torvalds {
2141da177e4SLinus Torvalds 	unsigned long mask, flags;
2151da177e4SLinus Torvalds 	int cpu = smp_processor_id();
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds 	mask = sun4m_get_irqmask(irq_nr);
2181da177e4SLinus Torvalds 	local_irq_save(flags);
2191da177e4SLinus Torvalds 	if (irq_nr > 15)
22069c010b2SDavid S. Miller 		sbus_writel(mask, &sun4m_irq_global->mask_set);
2211da177e4SLinus Torvalds 	else
22269c010b2SDavid S. Miller 		sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
2231da177e4SLinus Torvalds 	local_irq_restore(flags);
2241da177e4SLinus Torvalds }
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds static void sun4m_enable_irq(unsigned int irq_nr)
2271da177e4SLinus Torvalds {
2281da177e4SLinus Torvalds 	unsigned long mask, flags;
2291da177e4SLinus Torvalds 	int cpu = smp_processor_id();
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds 	/* Dreadful floppy hack. When we use 0x2b instead of
2321da177e4SLinus Torvalds 	 * 0x0b the system blows (it starts to whistle!).
2331da177e4SLinus Torvalds 	 * So we continue to use 0x0b. Fixme ASAP. --P3
2341da177e4SLinus Torvalds 	 */
2351da177e4SLinus Torvalds 	if (irq_nr != 0x0b) {
2361da177e4SLinus Torvalds 		mask = sun4m_get_irqmask(irq_nr);
2371da177e4SLinus Torvalds 		local_irq_save(flags);
2381da177e4SLinus Torvalds 		if (irq_nr > 15)
23969c010b2SDavid S. Miller 			sbus_writel(mask, &sun4m_irq_global->mask_clear);
2401da177e4SLinus Torvalds 		else
24169c010b2SDavid S. Miller 			sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
2421da177e4SLinus Torvalds 		local_irq_restore(flags);
2431da177e4SLinus Torvalds 	} else {
2441da177e4SLinus Torvalds 		local_irq_save(flags);
24569c010b2SDavid S. Miller 		sbus_writel(SUN4M_INT_FLOPPY, &sun4m_irq_global->mask_clear);
2461da177e4SLinus Torvalds 		local_irq_restore(flags);
2471da177e4SLinus Torvalds 	}
2481da177e4SLinus Torvalds }
2491da177e4SLinus Torvalds 
2501da177e4SLinus Torvalds static unsigned long cpu_pil_to_imask[16] = {
2511da177e4SLinus Torvalds /*0*/	0x00000000,
2521da177e4SLinus Torvalds /*1*/	0x00000000,
2531da177e4SLinus Torvalds /*2*/	SUN4M_INT_SBUS(0) | SUN4M_INT_VME(0),
2541da177e4SLinus Torvalds /*3*/	SUN4M_INT_SBUS(1) | SUN4M_INT_VME(1),
2551da177e4SLinus Torvalds /*4*/	SUN4M_INT_SCSI,
2561da177e4SLinus Torvalds /*5*/	SUN4M_INT_SBUS(2) | SUN4M_INT_VME(2),
2571da177e4SLinus Torvalds /*6*/	SUN4M_INT_ETHERNET,
2581da177e4SLinus Torvalds /*7*/	SUN4M_INT_SBUS(3) | SUN4M_INT_VME(3),
2591da177e4SLinus Torvalds /*8*/	SUN4M_INT_VIDEO,
2601da177e4SLinus Torvalds /*9*/	SUN4M_INT_SBUS(4) | SUN4M_INT_VME(4) | SUN4M_INT_MODULE_ERR,
2611da177e4SLinus Torvalds /*10*/	SUN4M_INT_REALTIME,
2621da177e4SLinus Torvalds /*11*/	SUN4M_INT_SBUS(5) | SUN4M_INT_VME(5) | SUN4M_INT_FLOPPY,
2631da177e4SLinus Torvalds /*12*/	SUN4M_INT_SERIAL  | SUN4M_INT_KBDMS,
2646cf4a924SRobert Reif /*13*/	SUN4M_INT_SBUS(6) | SUN4M_INT_VME(6) | SUN4M_INT_AUDIO,
2651da177e4SLinus Torvalds /*14*/	SUN4M_INT_E14,
266aba20a82SSam Ravnborg /*15*/	SUN4M_INT_ERROR,
2671da177e4SLinus Torvalds };
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds /* We assume the caller has disabled local interrupts when these are called,
2701da177e4SLinus Torvalds  * or else very bizarre behavior will result.
2711da177e4SLinus Torvalds  */
2721da177e4SLinus Torvalds static void sun4m_disable_pil_irq(unsigned int pil)
2731da177e4SLinus Torvalds {
27469c010b2SDavid S. Miller 	sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_set);
2751da177e4SLinus Torvalds }
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds static void sun4m_enable_pil_irq(unsigned int pil)
2781da177e4SLinus Torvalds {
27969c010b2SDavid S. Miller 	sbus_writel(cpu_pil_to_imask[pil], &sun4m_irq_global->mask_clear);
2801da177e4SLinus Torvalds }
2811da177e4SLinus Torvalds 
2821da177e4SLinus Torvalds #ifdef CONFIG_SMP
2831da177e4SLinus Torvalds static void sun4m_send_ipi(int cpu, int level)
2841da177e4SLinus Torvalds {
28569c010b2SDavid S. Miller 	unsigned long mask = sun4m_get_irqmask(level);
286aba20a82SSam Ravnborg 
28769c010b2SDavid S. Miller 	sbus_writel(mask, &sun4m_irq_percpu[cpu]->set);
2881da177e4SLinus Torvalds }
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds static void sun4m_clear_ipi(int cpu, int level)
2911da177e4SLinus Torvalds {
29269c010b2SDavid S. Miller 	unsigned long mask = sun4m_get_irqmask(level);
293aba20a82SSam Ravnborg 
29469c010b2SDavid S. Miller 	sbus_writel(mask, &sun4m_irq_percpu[cpu]->clear);
2951da177e4SLinus Torvalds }
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds static void sun4m_set_udt(int cpu)
2981da177e4SLinus Torvalds {
29969c010b2SDavid S. Miller 	sbus_writel(cpu, &sun4m_irq_global->interrupt_target);
3001da177e4SLinus Torvalds }
3011da177e4SLinus Torvalds #endif
3021da177e4SLinus Torvalds 
3039b2e43aeSDavid S. Miller struct sun4m_timer_percpu {
3049b2e43aeSDavid S. Miller 	u32		l14_limit;
3059b2e43aeSDavid S. Miller 	u32		l14_count;
3069b2e43aeSDavid S. Miller 	u32		l14_limit_noclear;
3079b2e43aeSDavid S. Miller 	u32		user_timer_start_stop;
3089b2e43aeSDavid S. Miller };
3099b2e43aeSDavid S. Miller 
3109b2e43aeSDavid S. Miller static struct sun4m_timer_percpu __iomem *timers_percpu[SUN4M_NCPUS];
3119b2e43aeSDavid S. Miller 
3129b2e43aeSDavid S. Miller struct sun4m_timer_global {
3139b2e43aeSDavid S. Miller 	u32		l10_limit;
3149b2e43aeSDavid S. Miller 	u32		l10_count;
3159b2e43aeSDavid S. Miller 	u32		l10_limit_noclear;
3169b2e43aeSDavid S. Miller 	u32		reserved;
3179b2e43aeSDavid S. Miller 	u32		timer_config;
3189b2e43aeSDavid S. Miller };
3199b2e43aeSDavid S. Miller 
3209b2e43aeSDavid S. Miller static struct sun4m_timer_global __iomem *timers_global;
3219b2e43aeSDavid S. Miller 
3226cf4a924SRobert Reif #define TIMER_IRQ	(OBP_INT_LEVEL_ONBOARD | 10)
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds unsigned int lvl14_resolution = (((1000000/HZ) + 1) << 10);
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds static void sun4m_clear_clock_irq(void)
3271da177e4SLinus Torvalds {
3289b2e43aeSDavid S. Miller 	sbus_readl(&timers_global->l10_limit);
3291da177e4SLinus Torvalds }
3301da177e4SLinus Torvalds 
3316cf4a924SRobert Reif void sun4m_nmi(struct pt_regs *regs)
3326cf4a924SRobert Reif {
3336cf4a924SRobert Reif 	unsigned long afsr, afar, si;
3346cf4a924SRobert Reif 
3356cf4a924SRobert Reif 	printk(KERN_ERR "Aieee: sun4m NMI received!\n");
3366cf4a924SRobert Reif 	/* XXX HyperSparc hack XXX */
3376cf4a924SRobert Reif 	__asm__ __volatile__("mov 0x500, %%g1\n\t"
3386cf4a924SRobert Reif 			     "lda [%%g1] 0x4, %0\n\t"
3396cf4a924SRobert Reif 			     "mov 0x600, %%g1\n\t"
3406cf4a924SRobert Reif 			     "lda [%%g1] 0x4, %1\n\t" :
3416cf4a924SRobert Reif 			     "=r" (afsr), "=r" (afar));
3426cf4a924SRobert Reif 	printk(KERN_ERR "afsr=%08lx afar=%08lx\n", afsr, afar);
3436cf4a924SRobert Reif 	si = sbus_readl(&sun4m_irq_global->pending);
3446cf4a924SRobert Reif 	printk(KERN_ERR "si=%08lx\n", si);
3456cf4a924SRobert Reif 	if (si & SUN4M_INT_MODULE_ERR)
3466cf4a924SRobert Reif 		printk(KERN_ERR "Module async error\n");
3476cf4a924SRobert Reif 	if (si & SUN4M_INT_M2S_WRITE_ERR)
3486cf4a924SRobert Reif 		printk(KERN_ERR "MBus/SBus async error\n");
3496cf4a924SRobert Reif 	if (si & SUN4M_INT_ECC_ERR)
3506cf4a924SRobert Reif 		printk(KERN_ERR "ECC memory error\n");
3516cf4a924SRobert Reif 	if (si & SUN4M_INT_VME_ERR)
3526cf4a924SRobert Reif 		printk(KERN_ERR "VME async error\n");
3536cf4a924SRobert Reif 	printk(KERN_ERR "you lose buddy boy...\n");
3546cf4a924SRobert Reif 	show_regs(regs);
3556cf4a924SRobert Reif 	prom_halt();
3566cf4a924SRobert Reif }
3576cf4a924SRobert Reif 
3581de937a5SDavid S. Miller /* Exported for sun4m_smp.c */
3591de937a5SDavid S. Miller void sun4m_clear_profile_irq(int cpu)
3601da177e4SLinus Torvalds {
3619b2e43aeSDavid S. Miller 	sbus_readl(&timers_percpu[cpu]->l14_limit);
3621da177e4SLinus Torvalds }
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds static void sun4m_load_profile_irq(int cpu, unsigned int limit)
3651da177e4SLinus Torvalds {
3669b2e43aeSDavid S. Miller 	sbus_writel(limit, &timers_percpu[cpu]->l14_limit);
3671da177e4SLinus Torvalds }
3681da177e4SLinus Torvalds 
36940220c1aSDavid Howells static void __init sun4m_init_timers(irq_handler_t counter_fn)
3701da177e4SLinus Torvalds {
3719b2e43aeSDavid S. Miller 	struct device_node *dp = of_find_node_by_name(NULL, "counter");
3729b2e43aeSDavid S. Miller 	int i, err, len, num_cpu_timers;
3739b2e43aeSDavid S. Miller 	const u32 *addr;
3741da177e4SLinus Torvalds 
3759b2e43aeSDavid S. Miller 	if (!dp) {
3769b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: No 'counter' node.\n");
3779b2e43aeSDavid S. Miller 		return;
3781da177e4SLinus Torvalds 	}
3791da177e4SLinus Torvalds 
3809b2e43aeSDavid S. Miller 	addr = of_get_property(dp, "address", &len);
381c2e27c35SNicolas Palix 	of_node_put(dp);
3829b2e43aeSDavid S. Miller 	if (!addr) {
3839b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: No 'address' prop.\n");
3849b2e43aeSDavid S. Miller 		return;
3851da177e4SLinus Torvalds 	}
3861da177e4SLinus Torvalds 
3879b2e43aeSDavid S. Miller 	num_cpu_timers = (len / sizeof(u32)) - 1;
3889b2e43aeSDavid S. Miller 	for (i = 0; i < num_cpu_timers; i++) {
3899b2e43aeSDavid S. Miller 		timers_percpu[i] = (void __iomem *)
3909b2e43aeSDavid S. Miller 			(unsigned long) addr[i];
3911da177e4SLinus Torvalds 	}
3929b2e43aeSDavid S. Miller 	timers_global = (void __iomem *)
3939b2e43aeSDavid S. Miller 		(unsigned long) addr[num_cpu_timers];
3949b2e43aeSDavid S. Miller 
3959b2e43aeSDavid S. Miller 	sbus_writel((((1000000/HZ) + 1) << 10), &timers_global->l10_limit);
3969b2e43aeSDavid S. Miller 
3979b2e43aeSDavid S. Miller 	master_l10_counter = &timers_global->l10_count;
3989b2e43aeSDavid S. Miller 
3999b2e43aeSDavid S. Miller 	err = request_irq(TIMER_IRQ, counter_fn,
4009b2e43aeSDavid S. Miller 			  (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
4019b2e43aeSDavid S. Miller 	if (err) {
4029b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: Register IRQ error %d.\n",
4039b2e43aeSDavid S. Miller 			err);
4049b2e43aeSDavid S. Miller 		return;
4059b2e43aeSDavid S. Miller 	}
4069b2e43aeSDavid S. Miller 
4079b2e43aeSDavid S. Miller 	for (i = 0; i < num_cpu_timers; i++)
4089b2e43aeSDavid S. Miller 		sbus_writel(0, &timers_percpu[i]->l14_limit);
4099b2e43aeSDavid S. Miller 	if (num_cpu_timers == 4)
41069c010b2SDavid S. Miller 		sbus_writel(SUN4M_INT_E14, &sun4m_irq_global->mask_set);
4119b2e43aeSDavid S. Miller 
4121da177e4SLinus Torvalds #ifdef CONFIG_SMP
4131da177e4SLinus Torvalds 	{
4141da177e4SLinus Torvalds 		unsigned long flags;
4151da177e4SLinus Torvalds 		struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
4161da177e4SLinus Torvalds 
4171da177e4SLinus Torvalds 		/* For SMP we use the level 14 ticker, however the bootup code
418d1a78c32SSimon Arlott 		 * has copied the firmware's level 14 vector into the boot cpu's
4191da177e4SLinus Torvalds 		 * trap table, we must fix this now or we get squashed.
4201da177e4SLinus Torvalds 		 */
4211da177e4SLinus Torvalds 		local_irq_save(flags);
4221da177e4SLinus Torvalds 		trap_table->inst_one = lvl14_save[0];
4231da177e4SLinus Torvalds 		trap_table->inst_two = lvl14_save[1];
4241da177e4SLinus Torvalds 		trap_table->inst_three = lvl14_save[2];
4251da177e4SLinus Torvalds 		trap_table->inst_four = lvl14_save[3];
4261da177e4SLinus Torvalds 		local_flush_cache_all();
4271da177e4SLinus Torvalds 		local_irq_restore(flags);
4281da177e4SLinus Torvalds 	}
4291da177e4SLinus Torvalds #endif
4301da177e4SLinus Torvalds }
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds void __init sun4m_init_IRQ(void)
4331da177e4SLinus Torvalds {
43469c010b2SDavid S. Miller 	struct device_node *dp = of_find_node_by_name(NULL, "interrupt");
43569c010b2SDavid S. Miller 	int len, i, mid, num_cpu_iregs;
43669c010b2SDavid S. Miller 	const u32 *addr;
43769c010b2SDavid S. Miller 
43869c010b2SDavid S. Miller 	if (!dp) {
43969c010b2SDavid S. Miller 		printk(KERN_ERR "sun4m_init_IRQ: No 'interrupt' node.\n");
44069c010b2SDavid S. Miller 		return;
44169c010b2SDavid S. Miller 	}
44269c010b2SDavid S. Miller 
44369c010b2SDavid S. Miller 	addr = of_get_property(dp, "address", &len);
444c2e27c35SNicolas Palix 	of_node_put(dp);
44569c010b2SDavid S. Miller 	if (!addr) {
44669c010b2SDavid S. Miller 		printk(KERN_ERR "sun4m_init_IRQ: No 'address' prop.\n");
44769c010b2SDavid S. Miller 		return;
44869c010b2SDavid S. Miller 	}
44969c010b2SDavid S. Miller 
45069c010b2SDavid S. Miller 	num_cpu_iregs = (len / sizeof(u32)) - 1;
45169c010b2SDavid S. Miller 	for (i = 0; i < num_cpu_iregs; i++) {
45269c010b2SDavid S. Miller 		sun4m_irq_percpu[i] = (void __iomem *)
45369c010b2SDavid S. Miller 			(unsigned long) addr[i];
45469c010b2SDavid S. Miller 	}
45569c010b2SDavid S. Miller 	sun4m_irq_global = (void __iomem *)
45669c010b2SDavid S. Miller 		(unsigned long) addr[num_cpu_iregs];
4571da177e4SLinus Torvalds 
4581da177e4SLinus Torvalds 	local_irq_disable();
4591da177e4SLinus Torvalds 
46069c010b2SDavid S. Miller 	sbus_writel(~SUN4M_INT_MASKALL, &sun4m_irq_global->mask_set);
4611da177e4SLinus Torvalds 	for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++)
46269c010b2SDavid S. Miller 		sbus_writel(~0x17fff, &sun4m_irq_percpu[mid]->clear);
4631da177e4SLinus Torvalds 
464e7913de9SDavid S. Miller 	if (num_cpu_iregs == 4)
46569c010b2SDavid S. Miller 		sbus_writel(0, &sun4m_irq_global->interrupt_target);
466e7913de9SDavid S. Miller 
4671da177e4SLinus Torvalds 	BTFIXUPSET_CALL(enable_irq, sun4m_enable_irq, BTFIXUPCALL_NORM);
4681da177e4SLinus Torvalds 	BTFIXUPSET_CALL(disable_irq, sun4m_disable_irq, BTFIXUPCALL_NORM);
4691da177e4SLinus Torvalds 	BTFIXUPSET_CALL(enable_pil_irq, sun4m_enable_pil_irq, BTFIXUPCALL_NORM);
4701da177e4SLinus Torvalds 	BTFIXUPSET_CALL(disable_pil_irq, sun4m_disable_pil_irq, BTFIXUPCALL_NORM);
4711da177e4SLinus Torvalds 	BTFIXUPSET_CALL(clear_clock_irq, sun4m_clear_clock_irq, BTFIXUPCALL_NORM);
4721da177e4SLinus Torvalds 	BTFIXUPSET_CALL(load_profile_irq, sun4m_load_profile_irq, BTFIXUPCALL_NORM);
473*bbdc2661SSam Ravnborg 
474*bbdc2661SSam Ravnborg 	sparc_irq_config.init_timers = sun4m_init_timers;
475*bbdc2661SSam Ravnborg 
4761da177e4SLinus Torvalds #ifdef CONFIG_SMP
4771da177e4SLinus Torvalds 	BTFIXUPSET_CALL(set_cpu_int, sun4m_send_ipi, BTFIXUPCALL_NORM);
4781da177e4SLinus Torvalds 	BTFIXUPSET_CALL(clear_cpu_int, sun4m_clear_ipi, BTFIXUPCALL_NORM);
4791da177e4SLinus Torvalds 	BTFIXUPSET_CALL(set_irq_udt, sun4m_set_udt, BTFIXUPCALL_NORM);
4801da177e4SLinus Torvalds #endif
48169c010b2SDavid S. Miller 
4821da177e4SLinus Torvalds 	/* Cannot enable interrupts until OBP ticker is disabled. */
4831da177e4SLinus Torvalds }
484