xref: /linux/arch/mips/sibyte/sb1250/smp.c (revision 937a801576f954bd030d7c4a5a94571710d87c0b)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (C) 2001, 2002, 2003 Broadcom Corporation
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or
51da177e4SLinus Torvalds  * modify it under the terms of the GNU General Public License
61da177e4SLinus Torvalds  * as published by the Free Software Foundation; either version 2
71da177e4SLinus Torvalds  * of the License, or (at your option) any later version.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * This program is distributed in the hope that it will be useful,
101da177e4SLinus Torvalds  * but WITHOUT ANY WARRANTY; without even the implied warranty of
111da177e4SLinus Torvalds  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
121da177e4SLinus Torvalds  * GNU General Public License for more details.
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
151da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software
161da177e4SLinus Torvalds  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
171da177e4SLinus Torvalds  */
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #include <linux/init.h>
201da177e4SLinus Torvalds #include <linux/delay.h>
211da177e4SLinus Torvalds #include <linux/interrupt.h>
221da177e4SLinus Torvalds #include <linux/smp.h>
231da177e4SLinus Torvalds #include <linux/kernel_stat.h>
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #include <asm/mmu_context.h>
261da177e4SLinus Torvalds #include <asm/io.h>
271da177e4SLinus Torvalds #include <asm/sibyte/sb1250.h>
281da177e4SLinus Torvalds #include <asm/sibyte/sb1250_regs.h>
291da177e4SLinus Torvalds #include <asm/sibyte/sb1250_int.h>
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds static void *mailbox_set_regs[] = {
3265bda1a9SMaciej W. Rozycki 	IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_SET_CPU),
3365bda1a9SMaciej W. Rozycki 	IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_SET_CPU)
341da177e4SLinus Torvalds };
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds static void *mailbox_clear_regs[] = {
3765bda1a9SMaciej W. Rozycki 	IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CLR_CPU),
3865bda1a9SMaciej W. Rozycki 	IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CLR_CPU)
391da177e4SLinus Torvalds };
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds static void *mailbox_regs[] = {
4265bda1a9SMaciej W. Rozycki 	IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CPU),
4365bda1a9SMaciej W. Rozycki 	IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CPU)
441da177e4SLinus Torvalds };
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds /*
471da177e4SLinus Torvalds  * SMP init and finish on secondary CPUs
481da177e4SLinus Torvalds  */
491da177e4SLinus Torvalds void sb1250_smp_init(void)
501da177e4SLinus Torvalds {
511da177e4SLinus Torvalds 	unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
521da177e4SLinus Torvalds 		STATUSF_IP1 | STATUSF_IP0;
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds 	/* Set interrupt mask, but don't enable */
551da177e4SLinus Torvalds 	change_c0_status(ST0_IM, imask);
561da177e4SLinus Torvalds }
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds void sb1250_smp_finish(void)
591da177e4SLinus Torvalds {
601da177e4SLinus Torvalds 	extern void sb1250_time_init(void);
611da177e4SLinus Torvalds 	sb1250_time_init();
621da177e4SLinus Torvalds 	local_irq_enable();
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds /*
661da177e4SLinus Torvalds  * These are routines for dealing with the sb1250 smp capabilities
671da177e4SLinus Torvalds  * independent of board/firmware
681da177e4SLinus Torvalds  */
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /*
711da177e4SLinus Torvalds  * Simple enough; everything is set up, so just poke the appropriate mailbox
721da177e4SLinus Torvalds  * register, and we should be set
731da177e4SLinus Torvalds  */
741da177e4SLinus Torvalds void core_send_ipi(int cpu, unsigned int action)
751da177e4SLinus Torvalds {
7665bda1a9SMaciej W. Rozycki 	__raw_writeq((((u64)action) << 48), mailbox_set_regs[cpu]);
771da177e4SLinus Torvalds }
781da177e4SLinus Torvalds 
79*937a8015SRalf Baechle void sb1250_mailbox_interrupt(void)
801da177e4SLinus Torvalds {
811da177e4SLinus Torvalds 	int cpu = smp_processor_id();
821da177e4SLinus Torvalds 	unsigned int action;
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds 	kstat_this_cpu.irqs[K_INT_MBOX_0]++;
851da177e4SLinus Torvalds 	/* Load the mailbox register to figure out what we're supposed to do */
8665bda1a9SMaciej W. Rozycki 	action = (____raw_readq(mailbox_regs[cpu]) >> 48) & 0xffff;
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds 	/* Clear the mailbox to clear the interrupt */
8965bda1a9SMaciej W. Rozycki 	____raw_writeq(((u64)action) << 48, mailbox_clear_regs[cpu]);
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds 	/*
921da177e4SLinus Torvalds 	 * Nothing to do for SMP_RESCHEDULE_YOURSELF; returning from the
931da177e4SLinus Torvalds 	 * interrupt will do the reschedule for us
941da177e4SLinus Torvalds 	 */
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds 	if (action & SMP_CALL_FUNCTION)
971da177e4SLinus Torvalds 		smp_call_function_interrupt();
981da177e4SLinus Torvalds }
99