xref: /openbmc/linux/arch/sparc/kernel/sun4m_irq.c (revision 65fddcfca8ad14778f71a57672fd01e8112d30fa)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2aba20a82SSam Ravnborg /*
3aba20a82SSam Ravnborg  * sun4m irq support
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *  djhr: Hacked out of irq.c into a CPU dependent version.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
81da177e4SLinus Torvalds  *  Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
91da177e4SLinus Torvalds  *  Copyright (C) 1995 Pete A. Zaitcev (zaitcev@yahoo.com)
101da177e4SLinus Torvalds  *  Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
111da177e4SLinus Torvalds  */
121da177e4SLinus Torvalds 
13a755180bSStephen Rothwell #include <linux/slab.h>
14b17b0153SIngo Molnar #include <linux/sched/debug.h>
15*65fddcfcSMike Rapoport #include <linux/pgtable.h>
16a755180bSStephen Rothwell 
171da177e4SLinus Torvalds #include <asm/timer.h>
181da177e4SLinus Torvalds #include <asm/traps.h>
191da177e4SLinus Torvalds #include <asm/pgalloc.h>
201da177e4SLinus Torvalds #include <asm/irq.h>
211da177e4SLinus Torvalds #include <asm/io.h>
221da177e4SLinus Torvalds #include <asm/cacheflush.h>
231da177e4SLinus Torvalds 
2432231a66SAl Viro #include "irq.h"
25aba20a82SSam Ravnborg #include "kernel.h"
26aba20a82SSam Ravnborg 
27aba20a82SSam Ravnborg /* Sample sun4m IRQ layout:
28aba20a82SSam Ravnborg  *
29aba20a82SSam Ravnborg  * 0x22 - Power
30aba20a82SSam Ravnborg  * 0x24 - ESP SCSI
31aba20a82SSam Ravnborg  * 0x26 - Lance ethernet
32aba20a82SSam Ravnborg  * 0x2b - Floppy
33aba20a82SSam Ravnborg  * 0x2c - Zilog uart
34aba20a82SSam Ravnborg  * 0x32 - SBUS level 0
35aba20a82SSam Ravnborg  * 0x33 - Parallel port, SBUS level 1
36aba20a82SSam Ravnborg  * 0x35 - SBUS level 2
37aba20a82SSam Ravnborg  * 0x37 - SBUS level 3
38aba20a82SSam Ravnborg  * 0x39 - Audio, Graphics card, SBUS level 4
39aba20a82SSam Ravnborg  * 0x3b - SBUS level 5
40aba20a82SSam Ravnborg  * 0x3d - SBUS level 6
41aba20a82SSam Ravnborg  *
42aba20a82SSam Ravnborg  * Each interrupt source has a mask bit in the interrupt registers.
43aba20a82SSam Ravnborg  * When the mask bit is set, this blocks interrupt deliver.  So you
44aba20a82SSam Ravnborg  * clear the bit to enable the interrupt.
45aba20a82SSam Ravnborg  *
46aba20a82SSam Ravnborg  * Interrupts numbered less than 0x10 are software triggered interrupts
47aba20a82SSam Ravnborg  * and unused by Linux.
48aba20a82SSam Ravnborg  *
49aba20a82SSam Ravnborg  * Interrupt level assignment on sun4m:
50aba20a82SSam Ravnborg  *
51aba20a82SSam Ravnborg  *	level		source
52aba20a82SSam Ravnborg  * ------------------------------------------------------------
53aba20a82SSam Ravnborg  *	  1		softint-1
54aba20a82SSam Ravnborg  *	  2		softint-2, VME/SBUS level 1
55aba20a82SSam Ravnborg  *	  3		softint-3, VME/SBUS level 2
56aba20a82SSam Ravnborg  *	  4		softint-4, onboard SCSI
57aba20a82SSam Ravnborg  *	  5		softint-5, VME/SBUS level 3
58aba20a82SSam Ravnborg  *	  6		softint-6, onboard ETHERNET
59aba20a82SSam Ravnborg  *	  7		softint-7, VME/SBUS level 4
60aba20a82SSam Ravnborg  *	  8		softint-8, onboard VIDEO
61aba20a82SSam Ravnborg  *	  9		softint-9, VME/SBUS level 5, Module Interrupt
62aba20a82SSam Ravnborg  *	 10		softint-10, system counter/timer
63aba20a82SSam Ravnborg  *	 11		softint-11, VME/SBUS level 6, Floppy
64aba20a82SSam Ravnborg  *	 12		softint-12, Keyboard/Mouse, Serial
65aba20a82SSam Ravnborg  *	 13		softint-13, VME/SBUS level 7, ISDN Audio
66aba20a82SSam Ravnborg  *	 14		softint-14, per-processor counter/timer
67aba20a82SSam Ravnborg  *	 15		softint-15, Asynchronous Errors (broadcast)
68aba20a82SSam Ravnborg  *
69aba20a82SSam Ravnborg  * Each interrupt source is masked distinctly in the sun4m interrupt
70aba20a82SSam Ravnborg  * registers.  The PIL level alone is therefore ambiguous, since multiple
71aba20a82SSam Ravnborg  * interrupt sources map to a single PIL.
72aba20a82SSam Ravnborg  *
73aba20a82SSam Ravnborg  * This ambiguity is resolved in the 'intr' property for device nodes
74aba20a82SSam Ravnborg  * in the OF device tree.  Each 'intr' property entry is composed of
75aba20a82SSam Ravnborg  * two 32-bit words.  The first word is the IRQ priority value, which
76aba20a82SSam Ravnborg  * is what we're intersted in.  The second word is the IRQ vector, which
77aba20a82SSam Ravnborg  * is unused.
78aba20a82SSam Ravnborg  *
79aba20a82SSam Ravnborg  * The low 4 bits of the IRQ priority indicate the PIL, and the upper
80aba20a82SSam Ravnborg  * 4 bits indicate onboard vs. SBUS leveled vs. VME leveled.  0x20
81aba20a82SSam Ravnborg  * means onboard, 0x30 means SBUS leveled, and 0x40 means VME leveled.
82aba20a82SSam Ravnborg  *
83aba20a82SSam Ravnborg  * For example, an 'intr' IRQ priority value of 0x24 is onboard SCSI
84aba20a82SSam Ravnborg  * whereas a value of 0x33 is SBUS level 2.  Here are some sample
85aba20a82SSam Ravnborg  * 'intr' property IRQ priority values from ss4, ss5, ss10, ss20, and
86aba20a82SSam Ravnborg  * Tadpole S3 GX systems.
87aba20a82SSam Ravnborg  *
88aba20a82SSam Ravnborg  * esp:		0x24	onboard ESP SCSI
89aba20a82SSam Ravnborg  * le:		0x26	onboard Lance ETHERNET
90aba20a82SSam Ravnborg  * p9100:	0x32	SBUS level 1 P9100 video
91aba20a82SSam Ravnborg  * bpp:		0x33	SBUS level 2 BPP parallel port device
92aba20a82SSam Ravnborg  * DBRI:	0x39	SBUS level 5 DBRI ISDN audio
93aba20a82SSam Ravnborg  * SUNW,leo:	0x39	SBUS level 5 LEO video
94aba20a82SSam Ravnborg  * pcmcia:	0x3b	SBUS level 6 PCMCIA controller
95aba20a82SSam Ravnborg  * uctrl:	0x3b	SBUS level 6 UCTRL device
96aba20a82SSam Ravnborg  * modem:	0x3d	SBUS level 7 MODEM
97aba20a82SSam Ravnborg  * zs:		0x2c	onboard keyboard/mouse/serial
98aba20a82SSam Ravnborg  * floppy:	0x2b	onboard Floppy
99aba20a82SSam Ravnborg  * power:	0x22	onboard power device (XXX unknown mask bit XXX)
100aba20a82SSam Ravnborg  */
101aba20a82SSam Ravnborg 
10232231a66SAl Viro 
10369c010b2SDavid S. Miller /* Code in entry.S needs to get at these register mappings.  */
10469c010b2SDavid S. Miller struct sun4m_irq_percpu __iomem *sun4m_irq_percpu[SUN4M_NCPUS];
10569c010b2SDavid S. Miller struct sun4m_irq_global __iomem *sun4m_irq_global;
10669c010b2SDavid S. Miller 
1076baa9b20SSam Ravnborg struct sun4m_handler_data {
1086baa9b20SSam Ravnborg 	bool    percpu;
1096baa9b20SSam Ravnborg 	long    mask;
1106baa9b20SSam Ravnborg };
1116baa9b20SSam Ravnborg 
11232231a66SAl Viro /* Dave Redman (djhr@tadpole.co.uk)
11332231a66SAl Viro  * The sun4m interrupt registers.
11432231a66SAl Viro  */
11532231a66SAl Viro #define SUN4M_INT_ENABLE	0x80000000
11632231a66SAl Viro #define SUN4M_INT_E14		0x00000080
11732231a66SAl Viro #define SUN4M_INT_E10		0x00080000
11832231a66SAl Viro 
11932231a66SAl Viro #define	SUN4M_INT_MASKALL	0x80000000	  /* mask all interrupts */
12032231a66SAl Viro #define	SUN4M_INT_MODULE_ERR	0x40000000	  /* module error */
1216cf4a924SRobert Reif #define	SUN4M_INT_M2S_WRITE_ERR	0x20000000	  /* write buffer error */
1226cf4a924SRobert Reif #define	SUN4M_INT_ECC_ERR	0x10000000	  /* ecc memory error */
1236cf4a924SRobert Reif #define	SUN4M_INT_VME_ERR	0x08000000	  /* vme async error */
12432231a66SAl Viro #define	SUN4M_INT_FLOPPY	0x00400000	  /* floppy disk */
12532231a66SAl Viro #define	SUN4M_INT_MODULE	0x00200000	  /* module interrupt */
12632231a66SAl Viro #define	SUN4M_INT_VIDEO		0x00100000	  /* onboard video */
12732231a66SAl Viro #define	SUN4M_INT_REALTIME	0x00080000	  /* system timer */
12832231a66SAl Viro #define	SUN4M_INT_SCSI		0x00040000	  /* onboard scsi */
12932231a66SAl Viro #define	SUN4M_INT_AUDIO		0x00020000	  /* audio/isdn */
13032231a66SAl Viro #define	SUN4M_INT_ETHERNET	0x00010000	  /* onboard ethernet */
13132231a66SAl Viro #define	SUN4M_INT_SERIAL	0x00008000	  /* serial ports */
13232231a66SAl Viro #define	SUN4M_INT_KBDMS		0x00004000	  /* keyboard/mouse */
13332231a66SAl Viro #define	SUN4M_INT_SBUSBITS	0x00003F80	  /* sbus int bits */
1346cf4a924SRobert Reif #define	SUN4M_INT_VMEBITS	0x0000007F	  /* vme int bits */
1356cf4a924SRobert Reif 
1366cf4a924SRobert Reif #define	SUN4M_INT_ERROR		(SUN4M_INT_MODULE_ERR |    \
1376cf4a924SRobert Reif 				 SUN4M_INT_M2S_WRITE_ERR | \
1386cf4a924SRobert Reif 				 SUN4M_INT_ECC_ERR |       \
1396cf4a924SRobert Reif 				 SUN4M_INT_VME_ERR)
14032231a66SAl Viro 
14132231a66SAl Viro #define SUN4M_INT_SBUS(x)	(1 << (x+7))
14232231a66SAl Viro #define SUN4M_INT_VME(x)	(1 << (x))
14332231a66SAl Viro 
1446cf4a924SRobert Reif /* Interrupt levels used by OBP */
1456cf4a924SRobert Reif #define	OBP_INT_LEVEL_SOFT	0x10
1466cf4a924SRobert Reif #define	OBP_INT_LEVEL_ONBOARD	0x20
1476cf4a924SRobert Reif #define	OBP_INT_LEVEL_SBUS	0x30
1486cf4a924SRobert Reif #define	OBP_INT_LEVEL_VME	0x40
1496cf4a924SRobert Reif 
1500399bb5bSSam Ravnborg #define SUN4M_TIMER_IRQ         (OBP_INT_LEVEL_ONBOARD | 10)
1516baa9b20SSam Ravnborg #define SUN4M_PROFILE_IRQ       (OBP_INT_LEVEL_ONBOARD | 14)
1520399bb5bSSam Ravnborg 
1536baa9b20SSam Ravnborg static unsigned long sun4m_imask[0x50] = {
1540399bb5bSSam Ravnborg 	/* 0x00 - SMP */
1556cf4a924SRobert Reif 	0,  SUN4M_SOFT_INT(1),
1566cf4a924SRobert Reif 	SUN4M_SOFT_INT(2),  SUN4M_SOFT_INT(3),
1576cf4a924SRobert Reif 	SUN4M_SOFT_INT(4),  SUN4M_SOFT_INT(5),
1586cf4a924SRobert Reif 	SUN4M_SOFT_INT(6),  SUN4M_SOFT_INT(7),
1596cf4a924SRobert Reif 	SUN4M_SOFT_INT(8),  SUN4M_SOFT_INT(9),
1606cf4a924SRobert Reif 	SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
1616cf4a924SRobert Reif 	SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
1626cf4a924SRobert Reif 	SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
1630399bb5bSSam Ravnborg 	/* 0x10 - soft */
1646cf4a924SRobert Reif 	0,  SUN4M_SOFT_INT(1),
1656cf4a924SRobert Reif 	SUN4M_SOFT_INT(2),  SUN4M_SOFT_INT(3),
1666cf4a924SRobert Reif 	SUN4M_SOFT_INT(4),  SUN4M_SOFT_INT(5),
1676cf4a924SRobert Reif 	SUN4M_SOFT_INT(6),  SUN4M_SOFT_INT(7),
1686cf4a924SRobert Reif 	SUN4M_SOFT_INT(8),  SUN4M_SOFT_INT(9),
1696cf4a924SRobert Reif 	SUN4M_SOFT_INT(10), SUN4M_SOFT_INT(11),
1706cf4a924SRobert Reif 	SUN4M_SOFT_INT(12), SUN4M_SOFT_INT(13),
1716cf4a924SRobert Reif 	SUN4M_SOFT_INT(14), SUN4M_SOFT_INT(15),
1720399bb5bSSam Ravnborg 	/* 0x20 - onboard */
1736cf4a924SRobert Reif 	0, 0, 0, 0,
1746cf4a924SRobert Reif 	SUN4M_INT_SCSI,  0, SUN4M_INT_ETHERNET, 0,
1756cf4a924SRobert Reif 	SUN4M_INT_VIDEO, SUN4M_INT_MODULE,
1766cf4a924SRobert Reif 	SUN4M_INT_REALTIME, SUN4M_INT_FLOPPY,
1776cf4a924SRobert Reif 	(SUN4M_INT_SERIAL | SUN4M_INT_KBDMS),
1786baa9b20SSam Ravnborg 	SUN4M_INT_AUDIO, SUN4M_INT_E14, SUN4M_INT_MODULE_ERR,
1790399bb5bSSam Ravnborg 	/* 0x30 - sbus */
1806cf4a924SRobert Reif 	0, 0, SUN4M_INT_SBUS(0), SUN4M_INT_SBUS(1),
1816cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(2), 0, SUN4M_INT_SBUS(3),
1826cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(4), 0, SUN4M_INT_SBUS(5),
1836cf4a924SRobert Reif 	0, SUN4M_INT_SBUS(6), 0, 0,
1840399bb5bSSam Ravnborg 	/* 0x40 - vme */
1856cf4a924SRobert Reif 	0, 0, SUN4M_INT_VME(0), SUN4M_INT_VME(1),
1866cf4a924SRobert Reif 	0, SUN4M_INT_VME(2), 0, SUN4M_INT_VME(3),
1876cf4a924SRobert Reif 	0, SUN4M_INT_VME(4), 0, SUN4M_INT_VME(5),
1886cf4a924SRobert Reif 	0, SUN4M_INT_VME(6), 0, 0
1891da177e4SLinus Torvalds };
1901da177e4SLinus Torvalds 
1916baa9b20SSam Ravnborg static void sun4m_mask_irq(struct irq_data *data)
1921da177e4SLinus Torvalds {
1936a4a5b34SJiang Liu 	struct sun4m_handler_data *handler_data;
1941da177e4SLinus Torvalds 	int cpu = smp_processor_id();
1951da177e4SLinus Torvalds 
1966a4a5b34SJiang Liu 	handler_data = irq_data_get_irq_handler_data(data);
1976baa9b20SSam Ravnborg 	if (handler_data->mask) {
1986baa9b20SSam Ravnborg 		unsigned long flags;
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds 		local_irq_save(flags);
2016baa9b20SSam Ravnborg 		if (handler_data->percpu) {
2026baa9b20SSam Ravnborg 			sbus_writel(handler_data->mask, &sun4m_irq_percpu[cpu]->set);
2031da177e4SLinus Torvalds 		} else {
2046baa9b20SSam Ravnborg 			sbus_writel(handler_data->mask, &sun4m_irq_global->mask_set);
2056baa9b20SSam Ravnborg 		}
2061da177e4SLinus Torvalds 		local_irq_restore(flags);
2071da177e4SLinus Torvalds 	}
2081da177e4SLinus Torvalds }
2091da177e4SLinus Torvalds 
2106baa9b20SSam Ravnborg static void sun4m_unmask_irq(struct irq_data *data)
2116baa9b20SSam Ravnborg {
2126a4a5b34SJiang Liu 	struct sun4m_handler_data *handler_data;
2136baa9b20SSam Ravnborg 	int cpu = smp_processor_id();
2146baa9b20SSam Ravnborg 
2156a4a5b34SJiang Liu 	handler_data = irq_data_get_irq_handler_data(data);
2166baa9b20SSam Ravnborg 	if (handler_data->mask) {
2176baa9b20SSam Ravnborg 		unsigned long flags;
2186baa9b20SSam Ravnborg 
2196baa9b20SSam Ravnborg 		local_irq_save(flags);
2206baa9b20SSam Ravnborg 		if (handler_data->percpu) {
2216baa9b20SSam Ravnborg 			sbus_writel(handler_data->mask, &sun4m_irq_percpu[cpu]->clear);
2226baa9b20SSam Ravnborg 		} else {
2236baa9b20SSam Ravnborg 			sbus_writel(handler_data->mask, &sun4m_irq_global->mask_clear);
2246baa9b20SSam Ravnborg 		}
2256baa9b20SSam Ravnborg 		local_irq_restore(flags);
2266baa9b20SSam Ravnborg 	}
2276baa9b20SSam Ravnborg }
2286baa9b20SSam Ravnborg 
2296baa9b20SSam Ravnborg static unsigned int sun4m_startup_irq(struct irq_data *data)
2306baa9b20SSam Ravnborg {
2316baa9b20SSam Ravnborg 	irq_link(data->irq);
2326baa9b20SSam Ravnborg 	sun4m_unmask_irq(data);
2336baa9b20SSam Ravnborg 	return 0;
2346baa9b20SSam Ravnborg }
2356baa9b20SSam Ravnborg 
2366baa9b20SSam Ravnborg static void sun4m_shutdown_irq(struct irq_data *data)
2376baa9b20SSam Ravnborg {
2386baa9b20SSam Ravnborg 	sun4m_mask_irq(data);
2396baa9b20SSam Ravnborg 	irq_unlink(data->irq);
2406baa9b20SSam Ravnborg }
2416baa9b20SSam Ravnborg 
2426baa9b20SSam Ravnborg static struct irq_chip sun4m_irq = {
2436baa9b20SSam Ravnborg 	.name		= "sun4m",
2446baa9b20SSam Ravnborg 	.irq_startup	= sun4m_startup_irq,
2456baa9b20SSam Ravnborg 	.irq_shutdown	= sun4m_shutdown_irq,
2466baa9b20SSam Ravnborg 	.irq_mask	= sun4m_mask_irq,
2476baa9b20SSam Ravnborg 	.irq_unmask	= sun4m_unmask_irq,
2481da177e4SLinus Torvalds };
2491da177e4SLinus Torvalds 
2506baa9b20SSam Ravnborg 
2516baa9b20SSam Ravnborg static unsigned int sun4m_build_device_irq(struct platform_device *op,
2526baa9b20SSam Ravnborg 					   unsigned int real_irq)
2531da177e4SLinus Torvalds {
2546baa9b20SSam Ravnborg 	struct sun4m_handler_data *handler_data;
2556baa9b20SSam Ravnborg 	unsigned int irq;
2566baa9b20SSam Ravnborg 	unsigned int pil;
2576baa9b20SSam Ravnborg 
2586baa9b20SSam Ravnborg 	if (real_irq >= OBP_INT_LEVEL_VME) {
2596baa9b20SSam Ravnborg 		prom_printf("Bogus sun4m IRQ %u\n", real_irq);
2606baa9b20SSam Ravnborg 		prom_halt();
2616baa9b20SSam Ravnborg 	}
2626baa9b20SSam Ravnborg 	pil = (real_irq & 0xf);
2636baa9b20SSam Ravnborg 	irq = irq_alloc(real_irq, pil);
2646baa9b20SSam Ravnborg 
2656baa9b20SSam Ravnborg 	if (irq == 0)
2666baa9b20SSam Ravnborg 		goto out;
2676baa9b20SSam Ravnborg 
2686baa9b20SSam Ravnborg 	handler_data = irq_get_handler_data(irq);
2696baa9b20SSam Ravnborg 	if (unlikely(handler_data))
2706baa9b20SSam Ravnborg 		goto out;
2716baa9b20SSam Ravnborg 
2726baa9b20SSam Ravnborg 	handler_data = kzalloc(sizeof(struct sun4m_handler_data), GFP_ATOMIC);
2736baa9b20SSam Ravnborg 	if (unlikely(!handler_data)) {
2746baa9b20SSam Ravnborg 		prom_printf("IRQ: kzalloc(sun4m_handler_data) failed.\n");
2756baa9b20SSam Ravnborg 		prom_halt();
2761da177e4SLinus Torvalds 	}
2771da177e4SLinus Torvalds 
2786baa9b20SSam Ravnborg 	handler_data->mask = sun4m_imask[real_irq];
2796baa9b20SSam Ravnborg 	handler_data->percpu = real_irq < OBP_INT_LEVEL_ONBOARD;
2806baa9b20SSam Ravnborg 	irq_set_chip_and_handler_name(irq, &sun4m_irq,
2816baa9b20SSam Ravnborg 	                              handle_level_irq, "level");
2826baa9b20SSam Ravnborg 	irq_set_handler_data(irq, handler_data);
2836baa9b20SSam Ravnborg 
2846baa9b20SSam Ravnborg out:
2856baa9b20SSam Ravnborg 	return irq;
2861da177e4SLinus Torvalds }
2871da177e4SLinus Torvalds 
2889b2e43aeSDavid S. Miller struct sun4m_timer_percpu {
2899b2e43aeSDavid S. Miller 	u32		l14_limit;
2909b2e43aeSDavid S. Miller 	u32		l14_count;
2919b2e43aeSDavid S. Miller 	u32		l14_limit_noclear;
2929b2e43aeSDavid S. Miller 	u32		user_timer_start_stop;
2939b2e43aeSDavid S. Miller };
2949b2e43aeSDavid S. Miller 
2959b2e43aeSDavid S. Miller static struct sun4m_timer_percpu __iomem *timers_percpu[SUN4M_NCPUS];
2969b2e43aeSDavid S. Miller 
2979b2e43aeSDavid S. Miller struct sun4m_timer_global {
2989b2e43aeSDavid S. Miller 	u32		l10_limit;
2999b2e43aeSDavid S. Miller 	u32		l10_count;
3009b2e43aeSDavid S. Miller 	u32		l10_limit_noclear;
3019b2e43aeSDavid S. Miller 	u32		reserved;
3029b2e43aeSDavid S. Miller 	u32		timer_config;
3039b2e43aeSDavid S. Miller };
3049b2e43aeSDavid S. Miller 
3059b2e43aeSDavid S. Miller static struct sun4m_timer_global __iomem *timers_global;
3069b2e43aeSDavid S. Miller 
3071da177e4SLinus Torvalds static void sun4m_clear_clock_irq(void)
3081da177e4SLinus Torvalds {
3099b2e43aeSDavid S. Miller 	sbus_readl(&timers_global->l10_limit);
3101da177e4SLinus Torvalds }
3111da177e4SLinus Torvalds 
3126cf4a924SRobert Reif void sun4m_nmi(struct pt_regs *regs)
3136cf4a924SRobert Reif {
3146cf4a924SRobert Reif 	unsigned long afsr, afar, si;
3156cf4a924SRobert Reif 
3166cf4a924SRobert Reif 	printk(KERN_ERR "Aieee: sun4m NMI received!\n");
3176cf4a924SRobert Reif 	/* XXX HyperSparc hack XXX */
3186cf4a924SRobert Reif 	__asm__ __volatile__("mov 0x500, %%g1\n\t"
3196cf4a924SRobert Reif 			     "lda [%%g1] 0x4, %0\n\t"
3206cf4a924SRobert Reif 			     "mov 0x600, %%g1\n\t"
3216cf4a924SRobert Reif 			     "lda [%%g1] 0x4, %1\n\t" :
3226cf4a924SRobert Reif 			     "=r" (afsr), "=r" (afar));
3236cf4a924SRobert Reif 	printk(KERN_ERR "afsr=%08lx afar=%08lx\n", afsr, afar);
3246cf4a924SRobert Reif 	si = sbus_readl(&sun4m_irq_global->pending);
3256cf4a924SRobert Reif 	printk(KERN_ERR "si=%08lx\n", si);
3266cf4a924SRobert Reif 	if (si & SUN4M_INT_MODULE_ERR)
3276cf4a924SRobert Reif 		printk(KERN_ERR "Module async error\n");
3286cf4a924SRobert Reif 	if (si & SUN4M_INT_M2S_WRITE_ERR)
3296cf4a924SRobert Reif 		printk(KERN_ERR "MBus/SBus async error\n");
3306cf4a924SRobert Reif 	if (si & SUN4M_INT_ECC_ERR)
3316cf4a924SRobert Reif 		printk(KERN_ERR "ECC memory error\n");
3326cf4a924SRobert Reif 	if (si & SUN4M_INT_VME_ERR)
3336cf4a924SRobert Reif 		printk(KERN_ERR "VME async error\n");
3346cf4a924SRobert Reif 	printk(KERN_ERR "you lose buddy boy...\n");
3356cf4a924SRobert Reif 	show_regs(regs);
3366cf4a924SRobert Reif 	prom_halt();
3376cf4a924SRobert Reif }
3386cf4a924SRobert Reif 
3396baa9b20SSam Ravnborg void sun4m_unmask_profile_irq(void)
3406baa9b20SSam Ravnborg {
3416baa9b20SSam Ravnborg 	unsigned long flags;
3426baa9b20SSam Ravnborg 
3436baa9b20SSam Ravnborg 	local_irq_save(flags);
3446baa9b20SSam Ravnborg 	sbus_writel(sun4m_imask[SUN4M_PROFILE_IRQ], &sun4m_irq_global->mask_clear);
3456baa9b20SSam Ravnborg 	local_irq_restore(flags);
3466baa9b20SSam Ravnborg }
3476baa9b20SSam Ravnborg 
3481de937a5SDavid S. Miller void sun4m_clear_profile_irq(int cpu)
3491da177e4SLinus Torvalds {
3509b2e43aeSDavid S. Miller 	sbus_readl(&timers_percpu[cpu]->l14_limit);
3511da177e4SLinus Torvalds }
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds static void sun4m_load_profile_irq(int cpu, unsigned int limit)
3541da177e4SLinus Torvalds {
35562f08283STkhai Kirill 	unsigned int value = limit ? timer_value(limit) : 0;
35662f08283STkhai Kirill 	sbus_writel(value, &timers_percpu[cpu]->l14_limit);
3571da177e4SLinus Torvalds }
3581da177e4SLinus Torvalds 
35962f08283STkhai Kirill static void __init sun4m_init_timers(void)
3601da177e4SLinus Torvalds {
3619b2e43aeSDavid S. Miller 	struct device_node *dp = of_find_node_by_name(NULL, "counter");
3629b2e43aeSDavid S. Miller 	int i, err, len, num_cpu_timers;
3636baa9b20SSam Ravnborg 	unsigned int irq;
3649b2e43aeSDavid S. Miller 	const u32 *addr;
3651da177e4SLinus Torvalds 
3669b2e43aeSDavid S. Miller 	if (!dp) {
3679b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: No 'counter' node.\n");
3689b2e43aeSDavid S. Miller 		return;
3691da177e4SLinus Torvalds 	}
3701da177e4SLinus Torvalds 
3719b2e43aeSDavid S. Miller 	addr = of_get_property(dp, "address", &len);
372c2e27c35SNicolas Palix 	of_node_put(dp);
3739b2e43aeSDavid S. Miller 	if (!addr) {
3749b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: No 'address' prop.\n");
3759b2e43aeSDavid S. Miller 		return;
3761da177e4SLinus Torvalds 	}
3771da177e4SLinus Torvalds 
3789b2e43aeSDavid S. Miller 	num_cpu_timers = (len / sizeof(u32)) - 1;
3799b2e43aeSDavid S. Miller 	for (i = 0; i < num_cpu_timers; i++) {
3809b2e43aeSDavid S. Miller 		timers_percpu[i] = (void __iomem *)
3819b2e43aeSDavid S. Miller 			(unsigned long) addr[i];
3821da177e4SLinus Torvalds 	}
3839b2e43aeSDavid S. Miller 	timers_global = (void __iomem *)
3849b2e43aeSDavid S. Miller 		(unsigned long) addr[num_cpu_timers];
3859b2e43aeSDavid S. Miller 
386e51e07e0STkhai Kirill 	/* Every per-cpu timer works in timer mode */
387e51e07e0STkhai Kirill 	sbus_writel(0x00000000, &timers_global->timer_config);
388e51e07e0STkhai Kirill 
38962f08283STkhai Kirill #ifdef CONFIG_SMP
39062f08283STkhai Kirill 	sparc_config.cs_period = SBUS_CLOCK_RATE * 2;  /* 2 seconds */
39162f08283STkhai Kirill 	sparc_config.features |= FEAT_L14_ONESHOT;
39262f08283STkhai Kirill #else
39362f08283STkhai Kirill 	sparc_config.cs_period = SBUS_CLOCK_RATE / HZ; /* 1/HZ sec  */
39462f08283STkhai Kirill 	sparc_config.features |= FEAT_L10_CLOCKEVENT;
39562f08283STkhai Kirill #endif
39662f08283STkhai Kirill 	sparc_config.features |= FEAT_L10_CLOCKSOURCE;
39762f08283STkhai Kirill 	sbus_writel(timer_value(sparc_config.cs_period),
39862f08283STkhai Kirill 	            &timers_global->l10_limit);
3999b2e43aeSDavid S. Miller 
4009b2e43aeSDavid S. Miller 	master_l10_counter = &timers_global->l10_count;
4019b2e43aeSDavid S. Miller 
4026baa9b20SSam Ravnborg 	irq = sun4m_build_device_irq(NULL, SUN4M_TIMER_IRQ);
4036baa9b20SSam Ravnborg 
40462f08283STkhai Kirill 	err = request_irq(irq, timer_interrupt, IRQF_TIMER, "timer", NULL);
4059b2e43aeSDavid S. Miller 	if (err) {
4069b2e43aeSDavid S. Miller 		printk(KERN_ERR "sun4m_init_timers: Register IRQ error %d.\n",
4079b2e43aeSDavid S. Miller 			err);
4089b2e43aeSDavid S. Miller 		return;
4099b2e43aeSDavid S. Miller 	}
4109b2e43aeSDavid S. Miller 
4119b2e43aeSDavid S. Miller 	for (i = 0; i < num_cpu_timers; i++)
4129b2e43aeSDavid S. Miller 		sbus_writel(0, &timers_percpu[i]->l14_limit);
4139b2e43aeSDavid S. Miller 	if (num_cpu_timers == 4)
41469c010b2SDavid S. Miller 		sbus_writel(SUN4M_INT_E14, &sun4m_irq_global->mask_set);
4159b2e43aeSDavid S. Miller 
4161da177e4SLinus Torvalds #ifdef CONFIG_SMP
4171da177e4SLinus Torvalds 	{
4181da177e4SLinus Torvalds 		unsigned long flags;
4191da177e4SLinus Torvalds 		struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds 		/* For SMP we use the level 14 ticker, however the bootup code
422d1a78c32SSimon Arlott 		 * has copied the firmware's level 14 vector into the boot cpu's
4231da177e4SLinus Torvalds 		 * trap table, we must fix this now or we get squashed.
4241da177e4SLinus Torvalds 		 */
4251da177e4SLinus Torvalds 		local_irq_save(flags);
4261da177e4SLinus Torvalds 		trap_table->inst_one = lvl14_save[0];
4271da177e4SLinus Torvalds 		trap_table->inst_two = lvl14_save[1];
4281da177e4SLinus Torvalds 		trap_table->inst_three = lvl14_save[2];
4291da177e4SLinus Torvalds 		trap_table->inst_four = lvl14_save[3];
4305d83d666SDavid S. Miller 		local_ops->cache_all();
4311da177e4SLinus Torvalds 		local_irq_restore(flags);
4321da177e4SLinus Torvalds 	}
4331da177e4SLinus Torvalds #endif
4341da177e4SLinus Torvalds }
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds void __init sun4m_init_IRQ(void)
4371da177e4SLinus Torvalds {
43869c010b2SDavid S. Miller 	struct device_node *dp = of_find_node_by_name(NULL, "interrupt");
43969c010b2SDavid S. Miller 	int len, i, mid, num_cpu_iregs;
44069c010b2SDavid S. Miller 	const u32 *addr;
44169c010b2SDavid S. Miller 
44269c010b2SDavid S. Miller 	if (!dp) {
44369c010b2SDavid S. Miller 		printk(KERN_ERR "sun4m_init_IRQ: No 'interrupt' node.\n");
44469c010b2SDavid S. Miller 		return;
44569c010b2SDavid S. Miller 	}
44669c010b2SDavid S. Miller 
44769c010b2SDavid S. Miller 	addr = of_get_property(dp, "address", &len);
448c2e27c35SNicolas Palix 	of_node_put(dp);
44969c010b2SDavid S. Miller 	if (!addr) {
45069c010b2SDavid S. Miller 		printk(KERN_ERR "sun4m_init_IRQ: No 'address' prop.\n");
45169c010b2SDavid S. Miller 		return;
45269c010b2SDavid S. Miller 	}
45369c010b2SDavid S. Miller 
45469c010b2SDavid S. Miller 	num_cpu_iregs = (len / sizeof(u32)) - 1;
45569c010b2SDavid S. Miller 	for (i = 0; i < num_cpu_iregs; i++) {
45669c010b2SDavid S. Miller 		sun4m_irq_percpu[i] = (void __iomem *)
45769c010b2SDavid S. Miller 			(unsigned long) addr[i];
45869c010b2SDavid S. Miller 	}
45969c010b2SDavid S. Miller 	sun4m_irq_global = (void __iomem *)
46069c010b2SDavid S. Miller 		(unsigned long) addr[num_cpu_iregs];
4611da177e4SLinus Torvalds 
4621da177e4SLinus Torvalds 	local_irq_disable();
4631da177e4SLinus Torvalds 
46469c010b2SDavid S. Miller 	sbus_writel(~SUN4M_INT_MASKALL, &sun4m_irq_global->mask_set);
4651da177e4SLinus Torvalds 	for (i = 0; !cpu_find_by_instance(i, NULL, &mid); i++)
46669c010b2SDavid S. Miller 		sbus_writel(~0x17fff, &sun4m_irq_percpu[mid]->clear);
4671da177e4SLinus Torvalds 
468e7913de9SDavid S. Miller 	if (num_cpu_iregs == 4)
46969c010b2SDavid S. Miller 		sbus_writel(0, &sun4m_irq_global->interrupt_target);
470e7913de9SDavid S. Miller 
471472bc4f2SSam Ravnborg 	sparc_config.init_timers      = sun4m_init_timers;
472472bc4f2SSam Ravnborg 	sparc_config.build_device_irq = sun4m_build_device_irq;
47362f08283STkhai Kirill 	sparc_config.clock_rate       = SBUS_CLOCK_RATE;
47408c9388fSSam Ravnborg 	sparc_config.clear_clock_irq  = sun4m_clear_clock_irq;
47508c9388fSSam Ravnborg 	sparc_config.load_profile_irq = sun4m_load_profile_irq;
47608c9388fSSam Ravnborg 
477bbdc2661SSam Ravnborg 
4781da177e4SLinus Torvalds 	/* Cannot enable interrupts until OBP ticker is disabled. */
4791da177e4SLinus Torvalds }
480