xref: /openbmc/linux/arch/mips/kernel/smp-bmips.c (revision 4f62d0a2)
1df0ac8a4SKevin Cernekee /*
2df0ac8a4SKevin Cernekee  * This file is subject to the terms and conditions of the GNU General Public
3df0ac8a4SKevin Cernekee  * License.  See the file "COPYING" in the main directory of this archive
4df0ac8a4SKevin Cernekee  * for more details.
5df0ac8a4SKevin Cernekee  *
6df0ac8a4SKevin Cernekee  * Copyright (C) 2011 by Kevin Cernekee (cernekee@gmail.com)
7df0ac8a4SKevin Cernekee  *
8df0ac8a4SKevin Cernekee  * SMP support for BMIPS
9df0ac8a4SKevin Cernekee  */
10df0ac8a4SKevin Cernekee 
11df0ac8a4SKevin Cernekee #include <linux/init.h>
12df0ac8a4SKevin Cernekee #include <linux/sched.h>
13ef8bd77fSIngo Molnar #include <linux/sched/hotplug.h>
14fc69910fSArnd Bergmann #include <linux/sched/task_stack.h>
15df0ac8a4SKevin Cernekee #include <linux/mm.h>
16df0ac8a4SKevin Cernekee #include <linux/delay.h>
17df0ac8a4SKevin Cernekee #include <linux/smp.h>
18df0ac8a4SKevin Cernekee #include <linux/interrupt.h>
19df0ac8a4SKevin Cernekee #include <linux/spinlock.h>
20df0ac8a4SKevin Cernekee #include <linux/cpu.h>
21df0ac8a4SKevin Cernekee #include <linux/cpumask.h>
22df0ac8a4SKevin Cernekee #include <linux/reboot.h>
23df0ac8a4SKevin Cernekee #include <linux/io.h>
24df0ac8a4SKevin Cernekee #include <linux/compiler.h>
25df0ac8a4SKevin Cernekee #include <linux/linkage.h>
26df0ac8a4SKevin Cernekee #include <linux/bug.h>
27df0ac8a4SKevin Cernekee #include <linux/kernel.h>
2862cac480SDengcheng Zhu #include <linux/kexec.h>
29df0ac8a4SKevin Cernekee 
30df0ac8a4SKevin Cernekee #include <asm/time.h>
31df0ac8a4SKevin Cernekee #include <asm/processor.h>
32df0ac8a4SKevin Cernekee #include <asm/bootinfo.h>
33df0ac8a4SKevin Cernekee #include <asm/cacheflush.h>
34df0ac8a4SKevin Cernekee #include <asm/tlbflush.h>
35df0ac8a4SKevin Cernekee #include <asm/mipsregs.h>
36df0ac8a4SKevin Cernekee #include <asm/bmips.h>
37df0ac8a4SKevin Cernekee #include <asm/traps.h>
38df0ac8a4SKevin Cernekee #include <asm/barrier.h>
39fc455787SKevin Cernekee #include <asm/cpu-features.h>
40df0ac8a4SKevin Cernekee 
41df0ac8a4SKevin Cernekee static int __maybe_unused max_cpus = 1;
42df0ac8a4SKevin Cernekee 
43df0ac8a4SKevin Cernekee /* these may be configured by the platform code */
44df0ac8a4SKevin Cernekee int bmips_smp_enabled = 1;
45df0ac8a4SKevin Cernekee int bmips_cpu_offset;
46df0ac8a4SKevin Cernekee cpumask_t bmips_booted_mask;
47d8010cebSKevin Cernekee unsigned long bmips_tp1_irqs = IE_IRQ1;
48df0ac8a4SKevin Cernekee 
49fc455787SKevin Cernekee #define RESET_FROM_KSEG0		0x80080800
50fc455787SKevin Cernekee #define RESET_FROM_KSEG1		0xa0080800
51fc455787SKevin Cernekee 
523677a283SKevin Cernekee static void bmips_set_reset_vec(int cpu, u32 val);
533677a283SKevin Cernekee 
54df0ac8a4SKevin Cernekee #ifdef CONFIG_SMP
55df0ac8a4SKevin Cernekee 
56df0ac8a4SKevin Cernekee /* initial $sp, $gp - used by arch/mips/kernel/bmips_vec.S */
57df0ac8a4SKevin Cernekee unsigned long bmips_smp_boot_sp;
58df0ac8a4SKevin Cernekee unsigned long bmips_smp_boot_gp;
59df0ac8a4SKevin Cernekee 
606465460cSJonas Gorski static void bmips43xx_send_ipi_single(int cpu, unsigned int action);
616465460cSJonas Gorski static void bmips5000_send_ipi_single(int cpu, unsigned int action);
626465460cSJonas Gorski static irqreturn_t bmips43xx_ipi_interrupt(int irq, void *dev_id);
636465460cSJonas Gorski static irqreturn_t bmips5000_ipi_interrupt(int irq, void *dev_id);
64df0ac8a4SKevin Cernekee 
65df0ac8a4SKevin Cernekee /* SW interrupts 0,1 are used for interprocessor signaling */
66df0ac8a4SKevin Cernekee #define IPI0_IRQ			(MIPS_CPU_IRQ_BASE + 0)
67df0ac8a4SKevin Cernekee #define IPI1_IRQ			(MIPS_CPU_IRQ_BASE + 1)
68df0ac8a4SKevin Cernekee 
69df0ac8a4SKevin Cernekee #define CPUNUM(cpu, shift)		(((cpu) + bmips_cpu_offset) << (shift))
70df0ac8a4SKevin Cernekee #define ACTION_CLR_IPI(cpu, ipi)	(0x2000 | CPUNUM(cpu, 9) | ((ipi) << 8))
71df0ac8a4SKevin Cernekee #define ACTION_SET_IPI(cpu, ipi)	(0x3000 | CPUNUM(cpu, 9) | ((ipi) << 8))
72df0ac8a4SKevin Cernekee #define ACTION_BOOT_THREAD(cpu)		(0x08 | CPUNUM(cpu, 0))
73df0ac8a4SKevin Cernekee 
74df0ac8a4SKevin Cernekee static void __init bmips_smp_setup(void)
75df0ac8a4SKevin Cernekee {
764df715aaSFlorian Fainelli 	int i, cpu = 1, boot_cpu = 0;
77fcfa66deSFlorian Fainelli 	int cpu_hw_intr;
78fcfa66deSFlorian Fainelli 
796465460cSJonas Gorski 	switch (current_cpu_type()) {
806465460cSJonas Gorski 	case CPU_BMIPS4350:
816465460cSJonas Gorski 	case CPU_BMIPS4380:
82df0ac8a4SKevin Cernekee 		/* arbitration priority */
83df0ac8a4SKevin Cernekee 		clear_c0_brcm_cmt_ctrl(0x30);
84df0ac8a4SKevin Cernekee 
85df0ac8a4SKevin Cernekee 		/* NBK and weak order flags */
86df0ac8a4SKevin Cernekee 		set_c0_brcm_config_0(0x30000);
87df0ac8a4SKevin Cernekee 
884df715aaSFlorian Fainelli 		/* Find out if we are running on TP0 or TP1 */
894df715aaSFlorian Fainelli 		boot_cpu = !!(read_c0_brcm_cmt_local() & (1 << 31));
904df715aaSFlorian Fainelli 
91df0ac8a4SKevin Cernekee 		/*
926465460cSJonas Gorski 		 * MIPS interrupts 0,1 (SW INT 0,1) cross over to the other
936465460cSJonas Gorski 		 * thread
94df0ac8a4SKevin Cernekee 		 * MIPS interrupt 2 (HW INT 0) is the CPU0 L1 controller output
95df0ac8a4SKevin Cernekee 		 * MIPS interrupt 3 (HW INT 1) is the CPU1 L1 controller output
96df0ac8a4SKevin Cernekee 		 */
97fcfa66deSFlorian Fainelli 		if (boot_cpu == 0)
98fcfa66deSFlorian Fainelli 			cpu_hw_intr = 0x02;
99fcfa66deSFlorian Fainelli 		else
100fcfa66deSFlorian Fainelli 			cpu_hw_intr = 0x1d;
101fcfa66deSFlorian Fainelli 
1026465460cSJonas Gorski 		change_c0_brcm_cmt_intr(0xf8018000,
1036465460cSJonas Gorski 					(cpu_hw_intr << 27) | (0x03 << 15));
104df0ac8a4SKevin Cernekee 
105df0ac8a4SKevin Cernekee 		/* single core, 2 threads (2 pipelines) */
106df0ac8a4SKevin Cernekee 		max_cpus = 2;
1076465460cSJonas Gorski 
1086465460cSJonas Gorski 		break;
1096465460cSJonas Gorski 	case CPU_BMIPS5000:
110df0ac8a4SKevin Cernekee 		/* enable raceless SW interrupts */
111df0ac8a4SKevin Cernekee 		set_c0_brcm_config(0x03 << 22);
112df0ac8a4SKevin Cernekee 
113df0ac8a4SKevin Cernekee 		/* route HW interrupt 0 to CPU0, HW interrupt 1 to CPU1 */
114df0ac8a4SKevin Cernekee 		change_c0_brcm_mode(0x1f << 27, 0x02 << 27);
115df0ac8a4SKevin Cernekee 
116df0ac8a4SKevin Cernekee 		/* N cores, 2 threads per core */
117df0ac8a4SKevin Cernekee 		max_cpus = (((read_c0_brcm_config() >> 6) & 0x03) + 1) << 1;
118df0ac8a4SKevin Cernekee 
119df0ac8a4SKevin Cernekee 		/* clear any pending SW interrupts */
120df0ac8a4SKevin Cernekee 		for (i = 0; i < max_cpus; i++) {
121df0ac8a4SKevin Cernekee 			write_c0_brcm_action(ACTION_CLR_IPI(i, 0));
122df0ac8a4SKevin Cernekee 			write_c0_brcm_action(ACTION_CLR_IPI(i, 1));
123df0ac8a4SKevin Cernekee 		}
1246465460cSJonas Gorski 
1256465460cSJonas Gorski 		break;
1266465460cSJonas Gorski 	default:
1276465460cSJonas Gorski 		max_cpus = 1;
1286465460cSJonas Gorski 	}
129df0ac8a4SKevin Cernekee 
130df0ac8a4SKevin Cernekee 	if (!bmips_smp_enabled)
131df0ac8a4SKevin Cernekee 		max_cpus = 1;
132df0ac8a4SKevin Cernekee 
133df0ac8a4SKevin Cernekee 	/* this can be overridden by the BSP */
134df0ac8a4SKevin Cernekee 	if (!board_ebase_setup)
135df0ac8a4SKevin Cernekee 		board_ebase_setup = &bmips_ebase_setup;
136df0ac8a4SKevin Cernekee 
137*4f62d0a2SÁlvaro Fernández Rojas 	if (max_cpus > 1) {
1384df715aaSFlorian Fainelli 		__cpu_number_map[boot_cpu] = 0;
1394df715aaSFlorian Fainelli 		__cpu_logical_map[0] = boot_cpu;
1404df715aaSFlorian Fainelli 
141df0ac8a4SKevin Cernekee 		for (i = 0; i < max_cpus; i++) {
1424df715aaSFlorian Fainelli 			if (i != boot_cpu) {
1434df715aaSFlorian Fainelli 				__cpu_number_map[i] = cpu;
1444df715aaSFlorian Fainelli 				__cpu_logical_map[cpu] = i;
1454df715aaSFlorian Fainelli 				cpu++;
1464df715aaSFlorian Fainelli 			}
147df0ac8a4SKevin Cernekee 			set_cpu_possible(i, 1);
148df0ac8a4SKevin Cernekee 			set_cpu_present(i, 1);
149df0ac8a4SKevin Cernekee 		}
150*4f62d0a2SÁlvaro Fernández Rojas 	} else {
151*4f62d0a2SÁlvaro Fernández Rojas 		__cpu_number_map[0] = boot_cpu;
152*4f62d0a2SÁlvaro Fernández Rojas 		__cpu_logical_map[0] = 0;
153*4f62d0a2SÁlvaro Fernández Rojas 		set_cpu_possible(0, 1);
154*4f62d0a2SÁlvaro Fernández Rojas 		set_cpu_present(0, 1);
155*4f62d0a2SÁlvaro Fernández Rojas 	}
156df0ac8a4SKevin Cernekee }
157df0ac8a4SKevin Cernekee 
158df0ac8a4SKevin Cernekee /*
159df0ac8a4SKevin Cernekee  * IPI IRQ setup - runs on CPU0
160df0ac8a4SKevin Cernekee  */
161df0ac8a4SKevin Cernekee static void bmips_prepare_cpus(unsigned int max_cpus)
162df0ac8a4SKevin Cernekee {
1636465460cSJonas Gorski 	irqreturn_t (*bmips_ipi_interrupt)(int irq, void *dev_id);
1646465460cSJonas Gorski 
1656465460cSJonas Gorski 	switch (current_cpu_type()) {
1666465460cSJonas Gorski 	case CPU_BMIPS4350:
1676465460cSJonas Gorski 	case CPU_BMIPS4380:
1686465460cSJonas Gorski 		bmips_ipi_interrupt = bmips43xx_ipi_interrupt;
1696465460cSJonas Gorski 		break;
1706465460cSJonas Gorski 	case CPU_BMIPS5000:
1716465460cSJonas Gorski 		bmips_ipi_interrupt = bmips5000_ipi_interrupt;
1726465460cSJonas Gorski 		break;
1736465460cSJonas Gorski 	default:
1746465460cSJonas Gorski 		return;
1756465460cSJonas Gorski 	}
1766465460cSJonas Gorski 
17706a3f0c9SJustin Chen 	if (request_irq(IPI0_IRQ, bmips_ipi_interrupt,
17806a3f0c9SJustin Chen 			IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi0", NULL))
179f7777dccSRalf Baechle 		panic("Can't request IPI0 interrupt");
18006a3f0c9SJustin Chen 	if (request_irq(IPI1_IRQ, bmips_ipi_interrupt,
18106a3f0c9SJustin Chen 			IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi1", NULL))
182f7777dccSRalf Baechle 		panic("Can't request IPI1 interrupt");
183df0ac8a4SKevin Cernekee }
184df0ac8a4SKevin Cernekee 
185df0ac8a4SKevin Cernekee /*
186df0ac8a4SKevin Cernekee  * Tell the hardware to boot CPUx - runs on CPU0
187df0ac8a4SKevin Cernekee  */
188d595d423SPaul Burton static int bmips_boot_secondary(int cpu, struct task_struct *idle)
189df0ac8a4SKevin Cernekee {
190df0ac8a4SKevin Cernekee 	bmips_smp_boot_sp = __KSTK_TOS(idle);
191df0ac8a4SKevin Cernekee 	bmips_smp_boot_gp = (unsigned long)task_thread_info(idle);
192df0ac8a4SKevin Cernekee 	mb();
193df0ac8a4SKevin Cernekee 
194df0ac8a4SKevin Cernekee 	/*
195df0ac8a4SKevin Cernekee 	 * Initial boot sequence for secondary CPU:
196df0ac8a4SKevin Cernekee 	 *   bmips_reset_nmi_vec @ a000_0000 ->
197df0ac8a4SKevin Cernekee 	 *   bmips_smp_entry ->
198df0ac8a4SKevin Cernekee 	 *   plat_wired_tlb_setup (cached function call; optional) ->
199df0ac8a4SKevin Cernekee 	 *   start_secondary (cached jump)
200df0ac8a4SKevin Cernekee 	 *
201df0ac8a4SKevin Cernekee 	 * Warm restart sequence:
202df0ac8a4SKevin Cernekee 	 *   play_dead WAIT loop ->
203df0ac8a4SKevin Cernekee 	 *   bmips_smp_int_vec @ BMIPS_WARM_RESTART_VEC ->
204df0ac8a4SKevin Cernekee 	 *   eret to play_dead ->
205df0ac8a4SKevin Cernekee 	 *   bmips_secondary_reentry ->
206df0ac8a4SKevin Cernekee 	 *   start_secondary
207df0ac8a4SKevin Cernekee 	 */
208df0ac8a4SKevin Cernekee 
209df0ac8a4SKevin Cernekee 	pr_info("SMP: Booting CPU%d...\n", cpu);
210df0ac8a4SKevin Cernekee 
2116465460cSJonas Gorski 	if (cpumask_test_cpu(cpu, &bmips_booted_mask)) {
2123677a283SKevin Cernekee 		/* kseg1 might not exist if this CPU enabled XKS01 */
2133677a283SKevin Cernekee 		bmips_set_reset_vec(cpu, RESET_FROM_KSEG0);
2143677a283SKevin Cernekee 
2156465460cSJonas Gorski 		switch (current_cpu_type()) {
2166465460cSJonas Gorski 		case CPU_BMIPS4350:
2176465460cSJonas Gorski 		case CPU_BMIPS4380:
2186465460cSJonas Gorski 			bmips43xx_send_ipi_single(cpu, 0);
2196465460cSJonas Gorski 			break;
2206465460cSJonas Gorski 		case CPU_BMIPS5000:
2216465460cSJonas Gorski 			bmips5000_send_ipi_single(cpu, 0);
2226465460cSJonas Gorski 			break;
2236465460cSJonas Gorski 		}
2243677a283SKevin Cernekee 	} else {
2253677a283SKevin Cernekee 		bmips_set_reset_vec(cpu, RESET_FROM_KSEG1);
2263677a283SKevin Cernekee 
2276465460cSJonas Gorski 		switch (current_cpu_type()) {
2286465460cSJonas Gorski 		case CPU_BMIPS4350:
2296465460cSJonas Gorski 		case CPU_BMIPS4380:
2304df715aaSFlorian Fainelli 			/* Reset slave TP1 if booting from TP0 */
231976f39b1SFlorian Fainelli 			if (cpu_logical_map(cpu) == 1)
232df0ac8a4SKevin Cernekee 				set_c0_brcm_cmt_ctrl(0x01);
2336465460cSJonas Gorski 			break;
2346465460cSJonas Gorski 		case CPU_BMIPS5000:
235df0ac8a4SKevin Cernekee 			write_c0_brcm_action(ACTION_BOOT_THREAD(cpu));
2366465460cSJonas Gorski 			break;
2376465460cSJonas Gorski 		}
238df0ac8a4SKevin Cernekee 		cpumask_set_cpu(cpu, &bmips_booted_mask);
239df0ac8a4SKevin Cernekee 	}
240d595d423SPaul Burton 
241d595d423SPaul Burton 	return 0;
242df0ac8a4SKevin Cernekee }
243df0ac8a4SKevin Cernekee 
244df0ac8a4SKevin Cernekee /*
245df0ac8a4SKevin Cernekee  * Early setup - runs on secondary CPU after cache probe
246df0ac8a4SKevin Cernekee  */
247df0ac8a4SKevin Cernekee static void bmips_init_secondary(void)
248df0ac8a4SKevin Cernekee {
249e14f633bSFlorian Fainelli 	bmips_cpu_setup();
250e14f633bSFlorian Fainelli 
2516465460cSJonas Gorski 	switch (current_cpu_type()) {
2526465460cSJonas Gorski 	case CPU_BMIPS4350:
2536465460cSJonas Gorski 	case CPU_BMIPS4380:
254df0ac8a4SKevin Cernekee 		clear_c0_cause(smp_processor_id() ? C_SW1 : C_SW0);
2556465460cSJonas Gorski 		break;
2566465460cSJonas Gorski 	case CPU_BMIPS5000:
257df0ac8a4SKevin Cernekee 		write_c0_brcm_action(ACTION_CLR_IPI(smp_processor_id(), 0));
258f875a832SPaul Burton 		cpu_set_core(&current_cpu_data, (read_c0_brcm_config() >> 25) & 3);
2596465460cSJonas Gorski 		break;
2606465460cSJonas Gorski 	}
261df0ac8a4SKevin Cernekee }
262df0ac8a4SKevin Cernekee 
263df0ac8a4SKevin Cernekee /*
264df0ac8a4SKevin Cernekee  * Late setup - runs on secondary CPU before entering the idle loop
265df0ac8a4SKevin Cernekee  */
266df0ac8a4SKevin Cernekee static void bmips_smp_finish(void)
267df0ac8a4SKevin Cernekee {
268df0ac8a4SKevin Cernekee 	pr_info("SMP: CPU%d is running\n", smp_processor_id());
269856ac3c6SYong Zhang 
270856ac3c6SYong Zhang 	/* make sure there won't be a timer interrupt for a little while */
271856ac3c6SYong Zhang 	write_c0_compare(read_c0_count() + mips_hpt_frequency / HZ);
272856ac3c6SYong Zhang 
273856ac3c6SYong Zhang 	irq_enable_hazard();
274d8010cebSKevin Cernekee 	set_c0_status(IE_SW0 | IE_SW1 | bmips_tp1_irqs | IE_IRQ5 | ST0_IE);
275856ac3c6SYong Zhang 	irq_enable_hazard();
276df0ac8a4SKevin Cernekee }
277df0ac8a4SKevin Cernekee 
278df0ac8a4SKevin Cernekee /*
279df0ac8a4SKevin Cernekee  * BMIPS5000 raceless IPIs
280df0ac8a4SKevin Cernekee  *
281df0ac8a4SKevin Cernekee  * Each CPU has two inbound SW IRQs which are independent of all other CPUs.
282df0ac8a4SKevin Cernekee  * IPI0 is used for SMP_RESCHEDULE_YOURSELF
283df0ac8a4SKevin Cernekee  * IPI1 is used for SMP_CALL_FUNCTION
284df0ac8a4SKevin Cernekee  */
285df0ac8a4SKevin Cernekee 
2866465460cSJonas Gorski static void bmips5000_send_ipi_single(int cpu, unsigned int action)
287df0ac8a4SKevin Cernekee {
288df0ac8a4SKevin Cernekee 	write_c0_brcm_action(ACTION_SET_IPI(cpu, action == SMP_CALL_FUNCTION));
289df0ac8a4SKevin Cernekee }
290df0ac8a4SKevin Cernekee 
2916465460cSJonas Gorski static irqreturn_t bmips5000_ipi_interrupt(int irq, void *dev_id)
292df0ac8a4SKevin Cernekee {
293df0ac8a4SKevin Cernekee 	int action = irq - IPI0_IRQ;
294df0ac8a4SKevin Cernekee 
295df0ac8a4SKevin Cernekee 	write_c0_brcm_action(ACTION_CLR_IPI(smp_processor_id(), action));
296df0ac8a4SKevin Cernekee 
297df0ac8a4SKevin Cernekee 	if (action == 0)
298df0ac8a4SKevin Cernekee 		scheduler_ipi();
299df0ac8a4SKevin Cernekee 	else
3004ace6139SAlex Smith 		generic_smp_call_function_interrupt();
301df0ac8a4SKevin Cernekee 
302df0ac8a4SKevin Cernekee 	return IRQ_HANDLED;
303df0ac8a4SKevin Cernekee }
304df0ac8a4SKevin Cernekee 
3056465460cSJonas Gorski static void bmips5000_send_ipi_mask(const struct cpumask *mask,
3066465460cSJonas Gorski 	unsigned int action)
3076465460cSJonas Gorski {
3086465460cSJonas Gorski 	unsigned int i;
3096465460cSJonas Gorski 
3106465460cSJonas Gorski 	for_each_cpu(i, mask)
3116465460cSJonas Gorski 		bmips5000_send_ipi_single(i, action);
3126465460cSJonas Gorski }
313df0ac8a4SKevin Cernekee 
314df0ac8a4SKevin Cernekee /*
315df0ac8a4SKevin Cernekee  * BMIPS43xx racey IPIs
316df0ac8a4SKevin Cernekee  *
317df0ac8a4SKevin Cernekee  * We use one inbound SW IRQ for each CPU.
318df0ac8a4SKevin Cernekee  *
319df0ac8a4SKevin Cernekee  * A spinlock must be held in order to keep CPUx from accidentally clearing
320df0ac8a4SKevin Cernekee  * an incoming IPI when it writes CP0 CAUSE to raise an IPI on CPUy.  The
321df0ac8a4SKevin Cernekee  * same spinlock is used to protect the action masks.
322df0ac8a4SKevin Cernekee  */
323df0ac8a4SKevin Cernekee 
324df0ac8a4SKevin Cernekee static DEFINE_SPINLOCK(ipi_lock);
325df0ac8a4SKevin Cernekee static DEFINE_PER_CPU(int, ipi_action_mask);
326df0ac8a4SKevin Cernekee 
3276465460cSJonas Gorski static void bmips43xx_send_ipi_single(int cpu, unsigned int action)
328df0ac8a4SKevin Cernekee {
329df0ac8a4SKevin Cernekee 	unsigned long flags;
330df0ac8a4SKevin Cernekee 
331df0ac8a4SKevin Cernekee 	spin_lock_irqsave(&ipi_lock, flags);
332df0ac8a4SKevin Cernekee 	set_c0_cause(cpu ? C_SW1 : C_SW0);
333df0ac8a4SKevin Cernekee 	per_cpu(ipi_action_mask, cpu) |= action;
334df0ac8a4SKevin Cernekee 	irq_enable_hazard();
335df0ac8a4SKevin Cernekee 	spin_unlock_irqrestore(&ipi_lock, flags);
336df0ac8a4SKevin Cernekee }
337df0ac8a4SKevin Cernekee 
3386465460cSJonas Gorski static irqreturn_t bmips43xx_ipi_interrupt(int irq, void *dev_id)
339df0ac8a4SKevin Cernekee {
340df0ac8a4SKevin Cernekee 	unsigned long flags;
341df0ac8a4SKevin Cernekee 	int action, cpu = irq - IPI0_IRQ;
342df0ac8a4SKevin Cernekee 
343df0ac8a4SKevin Cernekee 	spin_lock_irqsave(&ipi_lock, flags);
34435898716SChristoph Lameter 	action = __this_cpu_read(ipi_action_mask);
345df0ac8a4SKevin Cernekee 	per_cpu(ipi_action_mask, cpu) = 0;
346df0ac8a4SKevin Cernekee 	clear_c0_cause(cpu ? C_SW1 : C_SW0);
347df0ac8a4SKevin Cernekee 	spin_unlock_irqrestore(&ipi_lock, flags);
348df0ac8a4SKevin Cernekee 
349df0ac8a4SKevin Cernekee 	if (action & SMP_RESCHEDULE_YOURSELF)
350df0ac8a4SKevin Cernekee 		scheduler_ipi();
351df0ac8a4SKevin Cernekee 	if (action & SMP_CALL_FUNCTION)
3524ace6139SAlex Smith 		generic_smp_call_function_interrupt();
353df0ac8a4SKevin Cernekee 
354df0ac8a4SKevin Cernekee 	return IRQ_HANDLED;
355df0ac8a4SKevin Cernekee }
356df0ac8a4SKevin Cernekee 
3576465460cSJonas Gorski static void bmips43xx_send_ipi_mask(const struct cpumask *mask,
358df0ac8a4SKevin Cernekee 	unsigned int action)
359df0ac8a4SKevin Cernekee {
360df0ac8a4SKevin Cernekee 	unsigned int i;
361df0ac8a4SKevin Cernekee 
362df0ac8a4SKevin Cernekee 	for_each_cpu(i, mask)
3636465460cSJonas Gorski 		bmips43xx_send_ipi_single(i, action);
364df0ac8a4SKevin Cernekee }
365df0ac8a4SKevin Cernekee 
366df0ac8a4SKevin Cernekee #ifdef CONFIG_HOTPLUG_CPU
367df0ac8a4SKevin Cernekee 
368df0ac8a4SKevin Cernekee static int bmips_cpu_disable(void)
369df0ac8a4SKevin Cernekee {
370df0ac8a4SKevin Cernekee 	unsigned int cpu = smp_processor_id();
371df0ac8a4SKevin Cernekee 
372df0ac8a4SKevin Cernekee 	pr_info("SMP: CPU%d is offline\n", cpu);
373df0ac8a4SKevin Cernekee 
3740b5f9c00SRusty Russell 	set_cpu_online(cpu, false);
375826e99beSJames Hogan 	calculate_cpu_foreign_map();
37651ad4aceSFlorian Fainelli 	irq_cpu_offline();
377230b6ff5SJon Fraser 	clear_c0_status(IE_IRQ5);
378df0ac8a4SKevin Cernekee 
379df0ac8a4SKevin Cernekee 	local_flush_tlb_all();
380df0ac8a4SKevin Cernekee 	local_flush_icache_range(0, ~0);
381df0ac8a4SKevin Cernekee 
382df0ac8a4SKevin Cernekee 	return 0;
383df0ac8a4SKevin Cernekee }
384df0ac8a4SKevin Cernekee 
385df0ac8a4SKevin Cernekee static void bmips_cpu_die(unsigned int cpu)
386df0ac8a4SKevin Cernekee {
387df0ac8a4SKevin Cernekee }
388df0ac8a4SKevin Cernekee 
389df0ac8a4SKevin Cernekee void __ref play_dead(void)
390df0ac8a4SKevin Cernekee {
391df0ac8a4SKevin Cernekee 	idle_task_exit();
392df0ac8a4SKevin Cernekee 
393df0ac8a4SKevin Cernekee 	/* flush data cache */
394df0ac8a4SKevin Cernekee 	_dma_cache_wback_inv(0, ~0);
395df0ac8a4SKevin Cernekee 
396df0ac8a4SKevin Cernekee 	/*
397df0ac8a4SKevin Cernekee 	 * Wakeup is on SW0 or SW1; disable everything else
398df0ac8a4SKevin Cernekee 	 * Use BEV !IV (BMIPS_WARM_RESTART_VEC) to avoid the regular Linux
399df0ac8a4SKevin Cernekee 	 * IRQ handlers; this clears ST0_IE and returns immediately.
400df0ac8a4SKevin Cernekee 	 */
401df0ac8a4SKevin Cernekee 	clear_c0_cause(CAUSEF_IV | C_SW0 | C_SW1);
402d8010cebSKevin Cernekee 	change_c0_status(
403d8010cebSKevin Cernekee 		IE_IRQ5 | bmips_tp1_irqs | IE_SW0 | IE_SW1 | ST0_IE | ST0_BEV,
404df0ac8a4SKevin Cernekee 		IE_SW0 | IE_SW1 | ST0_IE | ST0_BEV);
405df0ac8a4SKevin Cernekee 	irq_disable_hazard();
406df0ac8a4SKevin Cernekee 
407df0ac8a4SKevin Cernekee 	/*
408df0ac8a4SKevin Cernekee 	 * wait for SW interrupt from bmips_boot_secondary(), then jump
409df0ac8a4SKevin Cernekee 	 * back to start_secondary()
410df0ac8a4SKevin Cernekee 	 */
411df0ac8a4SKevin Cernekee 	__asm__ __volatile__(
412df0ac8a4SKevin Cernekee 	"	wait\n"
413df0ac8a4SKevin Cernekee 	"	j	bmips_secondary_reentry\n"
414df0ac8a4SKevin Cernekee 	: : : "memory");
415df0ac8a4SKevin Cernekee }
416df0ac8a4SKevin Cernekee 
417df0ac8a4SKevin Cernekee #endif /* CONFIG_HOTPLUG_CPU */
418df0ac8a4SKevin Cernekee 
419ff2c8252SMatt Redfearn const struct plat_smp_ops bmips43xx_smp_ops = {
420df0ac8a4SKevin Cernekee 	.smp_setup		= bmips_smp_setup,
421df0ac8a4SKevin Cernekee 	.prepare_cpus		= bmips_prepare_cpus,
422df0ac8a4SKevin Cernekee 	.boot_secondary		= bmips_boot_secondary,
423df0ac8a4SKevin Cernekee 	.smp_finish		= bmips_smp_finish,
424df0ac8a4SKevin Cernekee 	.init_secondary		= bmips_init_secondary,
4256465460cSJonas Gorski 	.send_ipi_single	= bmips43xx_send_ipi_single,
4266465460cSJonas Gorski 	.send_ipi_mask		= bmips43xx_send_ipi_mask,
4276465460cSJonas Gorski #ifdef CONFIG_HOTPLUG_CPU
4286465460cSJonas Gorski 	.cpu_disable		= bmips_cpu_disable,
4296465460cSJonas Gorski 	.cpu_die		= bmips_cpu_die,
4306465460cSJonas Gorski #endif
43162cac480SDengcheng Zhu #ifdef CONFIG_KEXEC
43262cac480SDengcheng Zhu 	.kexec_nonboot_cpu	= kexec_nonboot_cpu_jump,
43362cac480SDengcheng Zhu #endif
4346465460cSJonas Gorski };
4356465460cSJonas Gorski 
436ff2c8252SMatt Redfearn const struct plat_smp_ops bmips5000_smp_ops = {
4376465460cSJonas Gorski 	.smp_setup		= bmips_smp_setup,
4386465460cSJonas Gorski 	.prepare_cpus		= bmips_prepare_cpus,
4396465460cSJonas Gorski 	.boot_secondary		= bmips_boot_secondary,
4406465460cSJonas Gorski 	.smp_finish		= bmips_smp_finish,
4416465460cSJonas Gorski 	.init_secondary		= bmips_init_secondary,
4426465460cSJonas Gorski 	.send_ipi_single	= bmips5000_send_ipi_single,
4436465460cSJonas Gorski 	.send_ipi_mask		= bmips5000_send_ipi_mask,
444df0ac8a4SKevin Cernekee #ifdef CONFIG_HOTPLUG_CPU
445df0ac8a4SKevin Cernekee 	.cpu_disable		= bmips_cpu_disable,
446df0ac8a4SKevin Cernekee 	.cpu_die		= bmips_cpu_die,
447df0ac8a4SKevin Cernekee #endif
44862cac480SDengcheng Zhu #ifdef CONFIG_KEXEC
44962cac480SDengcheng Zhu 	.kexec_nonboot_cpu	= kexec_nonboot_cpu_jump,
45062cac480SDengcheng Zhu #endif
451df0ac8a4SKevin Cernekee };
452df0ac8a4SKevin Cernekee 
453df0ac8a4SKevin Cernekee #endif /* CONFIG_SMP */
454df0ac8a4SKevin Cernekee 
455df0ac8a4SKevin Cernekee /***********************************************************************
456df0ac8a4SKevin Cernekee  * BMIPS vector relocation
457df0ac8a4SKevin Cernekee  * This is primarily used for SMP boot, but it is applicable to some
458df0ac8a4SKevin Cernekee  * UP BMIPS systems as well.
459df0ac8a4SKevin Cernekee  ***********************************************************************/
460df0ac8a4SKevin Cernekee 
461078a55fcSPaul Gortmaker static void bmips_wr_vec(unsigned long dst, char *start, char *end)
462df0ac8a4SKevin Cernekee {
463df0ac8a4SKevin Cernekee 	memcpy((void *)dst, start, end - start);
46457b41758SPetri Gynther 	dma_cache_wback(dst, end - start);
465df0ac8a4SKevin Cernekee 	local_flush_icache_range(dst, dst + (end - start));
466df0ac8a4SKevin Cernekee 	instruction_hazard();
467df0ac8a4SKevin Cernekee }
468df0ac8a4SKevin Cernekee 
469078a55fcSPaul Gortmaker static inline void bmips_nmi_handler_setup(void)
470df0ac8a4SKevin Cernekee {
471e4f5cb1aSJonas Gorski 	bmips_wr_vec(BMIPS_NMI_RESET_VEC, bmips_reset_nmi_vec,
472e4f5cb1aSJonas Gorski 		bmips_reset_nmi_vec_end);
473e4f5cb1aSJonas Gorski 	bmips_wr_vec(BMIPS_WARM_RESTART_VEC, bmips_smp_int_vec,
474e4f5cb1aSJonas Gorski 		bmips_smp_int_vec_end);
475df0ac8a4SKevin Cernekee }
476df0ac8a4SKevin Cernekee 
477fc455787SKevin Cernekee struct reset_vec_info {
478fc455787SKevin Cernekee 	int cpu;
479fc455787SKevin Cernekee 	u32 val;
480fc455787SKevin Cernekee };
481fc455787SKevin Cernekee 
482fc455787SKevin Cernekee static void bmips_set_reset_vec_remote(void *vinfo)
483fc455787SKevin Cernekee {
484fc455787SKevin Cernekee 	struct reset_vec_info *info = vinfo;
485fc455787SKevin Cernekee 	int shift = info->cpu & 0x01 ? 16 : 0;
486fc455787SKevin Cernekee 	u32 mask = ~(0xffff << shift), val = info->val >> 16;
487fc455787SKevin Cernekee 
488fc455787SKevin Cernekee 	preempt_disable();
489fc455787SKevin Cernekee 	if (smp_processor_id() > 0) {
490fc455787SKevin Cernekee 		smp_call_function_single(0, &bmips_set_reset_vec_remote,
491fc455787SKevin Cernekee 					 info, 1);
492fc455787SKevin Cernekee 	} else {
493fc455787SKevin Cernekee 		if (info->cpu & 0x02) {
494fc455787SKevin Cernekee 			/* BMIPS5200 "should" use mask/shift, but it's buggy */
495fc455787SKevin Cernekee 			bmips_write_zscm_reg(0xa0, (val << 16) | val);
496fc455787SKevin Cernekee 			bmips_read_zscm_reg(0xa0);
497fc455787SKevin Cernekee 		} else {
498fc455787SKevin Cernekee 			write_c0_brcm_bootvec((read_c0_brcm_bootvec() & mask) |
499fc455787SKevin Cernekee 					      (val << shift));
500fc455787SKevin Cernekee 		}
501fc455787SKevin Cernekee 	}
502fc455787SKevin Cernekee 	preempt_enable();
503fc455787SKevin Cernekee }
504fc455787SKevin Cernekee 
505fc455787SKevin Cernekee static void bmips_set_reset_vec(int cpu, u32 val)
506fc455787SKevin Cernekee {
507fc455787SKevin Cernekee 	struct reset_vec_info info;
508fc455787SKevin Cernekee 
509fc455787SKevin Cernekee 	if (current_cpu_type() == CPU_BMIPS5000) {
510fc455787SKevin Cernekee 		/* this needs to run from CPU0 (which is always online) */
511fc455787SKevin Cernekee 		info.cpu = cpu;
512fc455787SKevin Cernekee 		info.val = val;
513fc455787SKevin Cernekee 		bmips_set_reset_vec_remote(&info);
514fc455787SKevin Cernekee 	} else {
515fc455787SKevin Cernekee 		void __iomem *cbr = BMIPS_GET_CBR();
516fc455787SKevin Cernekee 
517fc455787SKevin Cernekee 		if (cpu == 0)
518fc455787SKevin Cernekee 			__raw_writel(val, cbr + BMIPS_RELO_VECTOR_CONTROL_0);
519fc455787SKevin Cernekee 		else {
520fc455787SKevin Cernekee 			if (current_cpu_type() != CPU_BMIPS4380)
521fc455787SKevin Cernekee 				return;
522fc455787SKevin Cernekee 			__raw_writel(val, cbr + BMIPS_RELO_VECTOR_CONTROL_1);
523fc455787SKevin Cernekee 		}
524fc455787SKevin Cernekee 	}
525fc455787SKevin Cernekee 	__sync();
526fc455787SKevin Cernekee 	back_to_back_c0_hazard();
527fc455787SKevin Cernekee }
528fc455787SKevin Cernekee 
529078a55fcSPaul Gortmaker void bmips_ebase_setup(void)
530df0ac8a4SKevin Cernekee {
531df0ac8a4SKevin Cernekee 	unsigned long new_ebase = ebase;
532df0ac8a4SKevin Cernekee 
533df0ac8a4SKevin Cernekee 	BUG_ON(ebase != CKSEG0);
534df0ac8a4SKevin Cernekee 
5356465460cSJonas Gorski 	switch (current_cpu_type()) {
5366465460cSJonas Gorski 	case CPU_BMIPS4350:
537df0ac8a4SKevin Cernekee 		/*
538df0ac8a4SKevin Cernekee 		 * BMIPS4350 cannot relocate the normal vectors, but it
539df0ac8a4SKevin Cernekee 		 * can relocate the BEV=1 vectors.  So CPU1 starts up at
540df0ac8a4SKevin Cernekee 		 * the relocated BEV=1, IV=0 general exception vector @
541df0ac8a4SKevin Cernekee 		 * 0xa000_0380.
542df0ac8a4SKevin Cernekee 		 *
543df0ac8a4SKevin Cernekee 		 * set_uncached_handler() is used here because:
544df0ac8a4SKevin Cernekee 		 *  - CPU1 will run this from uncached space
545df0ac8a4SKevin Cernekee 		 *  - None of the cacheflush functions are set up yet
546df0ac8a4SKevin Cernekee 		 */
547df0ac8a4SKevin Cernekee 		set_uncached_handler(BMIPS_WARM_RESTART_VEC - CKSEG0,
548df0ac8a4SKevin Cernekee 			&bmips_smp_int_vec, 0x80);
549df0ac8a4SKevin Cernekee 		__sync();
550df0ac8a4SKevin Cernekee 		return;
551fa010672SJon Fraser 	case CPU_BMIPS3300:
5526465460cSJonas Gorski 	case CPU_BMIPS4380:
553df0ac8a4SKevin Cernekee 		/*
554df0ac8a4SKevin Cernekee 		 * 0x8000_0000: reset/NMI (initially in kseg1)
555df0ac8a4SKevin Cernekee 		 * 0x8000_0400: normal vectors
556df0ac8a4SKevin Cernekee 		 */
557df0ac8a4SKevin Cernekee 		new_ebase = 0x80000400;
558fc455787SKevin Cernekee 		bmips_set_reset_vec(0, RESET_FROM_KSEG0);
5596465460cSJonas Gorski 		break;
5606465460cSJonas Gorski 	case CPU_BMIPS5000:
561df0ac8a4SKevin Cernekee 		/*
562df0ac8a4SKevin Cernekee 		 * 0x8000_0000: reset/NMI (initially in kseg1)
563df0ac8a4SKevin Cernekee 		 * 0x8000_1000: normal vectors
564df0ac8a4SKevin Cernekee 		 */
565df0ac8a4SKevin Cernekee 		new_ebase = 0x80001000;
566fc455787SKevin Cernekee 		bmips_set_reset_vec(0, RESET_FROM_KSEG0);
567df0ac8a4SKevin Cernekee 		write_c0_ebase(new_ebase);
5686465460cSJonas Gorski 		break;
5696465460cSJonas Gorski 	default:
570df0ac8a4SKevin Cernekee 		return;
5716465460cSJonas Gorski 	}
5726465460cSJonas Gorski 
573df0ac8a4SKevin Cernekee 	board_nmi_handler_setup = &bmips_nmi_handler_setup;
574df0ac8a4SKevin Cernekee 	ebase = new_ebase;
575df0ac8a4SKevin Cernekee }
576df0ac8a4SKevin Cernekee 
577df0ac8a4SKevin Cernekee asmlinkage void __weak plat_wired_tlb_setup(void)
578df0ac8a4SKevin Cernekee {
579df0ac8a4SKevin Cernekee 	/*
580df0ac8a4SKevin Cernekee 	 * Called when starting/restarting a secondary CPU.
581df0ac8a4SKevin Cernekee 	 * Kernel stacks and other important data might only be accessible
582df0ac8a4SKevin Cernekee 	 * once the wired entries are present.
583df0ac8a4SKevin Cernekee 	 */
584df0ac8a4SKevin Cernekee }
585738a3f79SFlorian Fainelli 
586627f4a2bSJaedon Shin void bmips_cpu_setup(void)
587738a3f79SFlorian Fainelli {
588738a3f79SFlorian Fainelli 	void __iomem __maybe_unused *cbr = BMIPS_GET_CBR();
589738a3f79SFlorian Fainelli 	u32 __maybe_unused cfg;
590738a3f79SFlorian Fainelli 
591738a3f79SFlorian Fainelli 	switch (current_cpu_type()) {
592738a3f79SFlorian Fainelli 	case CPU_BMIPS3300:
593738a3f79SFlorian Fainelli 		/* Set BIU to async mode */
594738a3f79SFlorian Fainelli 		set_c0_brcm_bus_pll(BIT(22));
595738a3f79SFlorian Fainelli 		__sync();
596738a3f79SFlorian Fainelli 
597738a3f79SFlorian Fainelli 		/* put the BIU back in sync mode */
598738a3f79SFlorian Fainelli 		clear_c0_brcm_bus_pll(BIT(22));
599738a3f79SFlorian Fainelli 
600738a3f79SFlorian Fainelli 		/* clear BHTD to enable branch history table */
601738a3f79SFlorian Fainelli 		clear_c0_brcm_reset(BIT(16));
602738a3f79SFlorian Fainelli 
603738a3f79SFlorian Fainelli 		/* Flush and enable RAC */
604738a3f79SFlorian Fainelli 		cfg = __raw_readl(cbr + BMIPS_RAC_CONFIG);
605ea4b3afeSJaedon Shin 		__raw_writel(cfg | 0x100, cbr + BMIPS_RAC_CONFIG);
606738a3f79SFlorian Fainelli 		__raw_readl(cbr + BMIPS_RAC_CONFIG);
607738a3f79SFlorian Fainelli 
608738a3f79SFlorian Fainelli 		cfg = __raw_readl(cbr + BMIPS_RAC_CONFIG);
609ea4b3afeSJaedon Shin 		__raw_writel(cfg | 0xf, cbr + BMIPS_RAC_CONFIG);
610738a3f79SFlorian Fainelli 		__raw_readl(cbr + BMIPS_RAC_CONFIG);
611738a3f79SFlorian Fainelli 
612738a3f79SFlorian Fainelli 		cfg = __raw_readl(cbr + BMIPS_RAC_ADDRESS_RANGE);
613738a3f79SFlorian Fainelli 		__raw_writel(cfg | 0x0fff0000, cbr + BMIPS_RAC_ADDRESS_RANGE);
614738a3f79SFlorian Fainelli 		__raw_readl(cbr + BMIPS_RAC_ADDRESS_RANGE);
615738a3f79SFlorian Fainelli 		break;
616738a3f79SFlorian Fainelli 
617738a3f79SFlorian Fainelli 	case CPU_BMIPS4380:
618738a3f79SFlorian Fainelli 		/* CBG workaround for early BMIPS4380 CPUs */
619738a3f79SFlorian Fainelli 		switch (read_c0_prid()) {
620738a3f79SFlorian Fainelli 		case 0x2a040:
621738a3f79SFlorian Fainelli 		case 0x2a042:
622738a3f79SFlorian Fainelli 		case 0x2a044:
623738a3f79SFlorian Fainelli 		case 0x2a060:
624738a3f79SFlorian Fainelli 			cfg = __raw_readl(cbr + BMIPS_L2_CONFIG);
625738a3f79SFlorian Fainelli 			__raw_writel(cfg & ~0x07000000, cbr + BMIPS_L2_CONFIG);
626738a3f79SFlorian Fainelli 			__raw_readl(cbr + BMIPS_L2_CONFIG);
627738a3f79SFlorian Fainelli 		}
628738a3f79SFlorian Fainelli 
629738a3f79SFlorian Fainelli 		/* clear BHTD to enable branch history table */
630738a3f79SFlorian Fainelli 		clear_c0_brcm_config_0(BIT(21));
631738a3f79SFlorian Fainelli 
632738a3f79SFlorian Fainelli 		/* XI/ROTR enable */
633738a3f79SFlorian Fainelli 		set_c0_brcm_config_0(BIT(23));
634738a3f79SFlorian Fainelli 		set_c0_brcm_cmt_ctrl(BIT(15));
635738a3f79SFlorian Fainelli 		break;
636738a3f79SFlorian Fainelli 
637738a3f79SFlorian Fainelli 	case CPU_BMIPS5000:
638738a3f79SFlorian Fainelli 		/* enable RDHWR, BRDHWR */
639738a3f79SFlorian Fainelli 		set_c0_brcm_config(BIT(17) | BIT(21));
640738a3f79SFlorian Fainelli 
641738a3f79SFlorian Fainelli 		/* Disable JTB */
642738a3f79SFlorian Fainelli 		__asm__ __volatile__(
643738a3f79SFlorian Fainelli 		"	.set	noreorder\n"
644738a3f79SFlorian Fainelli 		"	li	$8, 0x5a455048\n"
645738a3f79SFlorian Fainelli 		"	.word	0x4088b00f\n"	/* mtc0	t0, $22, 15 */
646738a3f79SFlorian Fainelli 		"	.word	0x4008b008\n"	/* mfc0	t0, $22, 8 */
647738a3f79SFlorian Fainelli 		"	li	$9, 0x00008000\n"
648738a3f79SFlorian Fainelli 		"	or	$8, $8, $9\n"
649738a3f79SFlorian Fainelli 		"	.word	0x4088b008\n"	/* mtc0	t0, $22, 8 */
650738a3f79SFlorian Fainelli 		"	sync\n"
651738a3f79SFlorian Fainelli 		"	li	$8, 0x0\n"
652738a3f79SFlorian Fainelli 		"	.word	0x4088b00f\n"	/* mtc0	t0, $22, 15 */
653738a3f79SFlorian Fainelli 		"	.set	reorder\n"
654738a3f79SFlorian Fainelli 		: : : "$8", "$9");
655738a3f79SFlorian Fainelli 
656738a3f79SFlorian Fainelli 		/* XI enable */
657738a3f79SFlorian Fainelli 		set_c0_brcm_config(BIT(27));
658738a3f79SFlorian Fainelli 
659738a3f79SFlorian Fainelli 		/* enable MIPS32R2 ROR instruction for XI TLB handlers */
660738a3f79SFlorian Fainelli 		__asm__ __volatile__(
661738a3f79SFlorian Fainelli 		"	li	$8, 0x5a455048\n"
662738a3f79SFlorian Fainelli 		"	.word	0x4088b00f\n"	/* mtc0 $8, $22, 15 */
663738a3f79SFlorian Fainelli 		"	nop; nop; nop\n"
664738a3f79SFlorian Fainelli 		"	.word	0x4008b008\n"	/* mfc0 $8, $22, 8 */
665738a3f79SFlorian Fainelli 		"	lui	$9, 0x0100\n"
666738a3f79SFlorian Fainelli 		"	or	$8, $9\n"
667738a3f79SFlorian Fainelli 		"	.word	0x4088b008\n"	/* mtc0 $8, $22, 8 */
668738a3f79SFlorian Fainelli 		: : : "$8", "$9");
669738a3f79SFlorian Fainelli 		break;
670738a3f79SFlorian Fainelli 	}
671738a3f79SFlorian Fainelli }
672