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> 2787353d8aSRalf Baechle #include <asm/fw/cfe/cfe_api.h> 281da177e4SLinus Torvalds #include <asm/sibyte/sb1250.h> 291da177e4SLinus Torvalds #include <asm/sibyte/sb1250_regs.h> 301da177e4SLinus Torvalds #include <asm/sibyte/sb1250_int.h> 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds static void *mailbox_set_regs[] = { 3365bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_SET_CPU), 3465bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_SET_CPU) 351da177e4SLinus Torvalds }; 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds static void *mailbox_clear_regs[] = { 3865bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CLR_CPU), 3965bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CLR_CPU) 401da177e4SLinus Torvalds }; 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds static void *mailbox_regs[] = { 4365bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CPU), 4465bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CPU) 451da177e4SLinus Torvalds }; 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds /* 481da177e4SLinus Torvalds * SMP init and finish on secondary CPUs 491da177e4SLinus Torvalds */ 50d0453365SRalf Baechle void __cpuinit sb1250_smp_init(void) 511da177e4SLinus Torvalds { 521da177e4SLinus Torvalds unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 | 531da177e4SLinus Torvalds STATUSF_IP1 | STATUSF_IP0; 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds /* Set interrupt mask, but don't enable */ 561da177e4SLinus Torvalds change_c0_status(ST0_IM, imask); 571da177e4SLinus Torvalds } 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds /* 601da177e4SLinus Torvalds * These are routines for dealing with the sb1250 smp capabilities 611da177e4SLinus Torvalds * independent of board/firmware 621da177e4SLinus Torvalds */ 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds /* 651da177e4SLinus Torvalds * Simple enough; everything is set up, so just poke the appropriate mailbox 661da177e4SLinus Torvalds * register, and we should be set 671da177e4SLinus Torvalds */ 6887353d8aSRalf Baechle static void sb1250_send_ipi_single(int cpu, unsigned int action) 691da177e4SLinus Torvalds { 7065bda1a9SMaciej W. Rozycki __raw_writeq((((u64)action) << 48), mailbox_set_regs[cpu]); 711da177e4SLinus Torvalds } 721da177e4SLinus Torvalds 73*48a048feSRusty Russell static inline void sb1250_send_ipi_mask(const struct cpumask *mask, 74*48a048feSRusty Russell unsigned int action) 7587353d8aSRalf Baechle { 7687353d8aSRalf Baechle unsigned int i; 7787353d8aSRalf Baechle 78*48a048feSRusty Russell for_each_cpu(i, mask) 7987353d8aSRalf Baechle sb1250_send_ipi_single(i, action); 8087353d8aSRalf Baechle } 8187353d8aSRalf Baechle 8287353d8aSRalf Baechle /* 8387353d8aSRalf Baechle * Code to run on secondary just after probing the CPU 8487353d8aSRalf Baechle */ 8587353d8aSRalf Baechle static void __cpuinit sb1250_init_secondary(void) 8687353d8aSRalf Baechle { 8787353d8aSRalf Baechle extern void sb1250_smp_init(void); 8887353d8aSRalf Baechle 8987353d8aSRalf Baechle sb1250_smp_init(); 9087353d8aSRalf Baechle } 9187353d8aSRalf Baechle 9287353d8aSRalf Baechle /* 9387353d8aSRalf Baechle * Do any tidying up before marking online and running the idle 9487353d8aSRalf Baechle * loop 9587353d8aSRalf Baechle */ 9687353d8aSRalf Baechle static void __cpuinit sb1250_smp_finish(void) 9787353d8aSRalf Baechle { 9887353d8aSRalf Baechle extern void sb1250_clockevent_init(void); 9987353d8aSRalf Baechle 10087353d8aSRalf Baechle sb1250_clockevent_init(); 10187353d8aSRalf Baechle local_irq_enable(); 10287353d8aSRalf Baechle } 10387353d8aSRalf Baechle 10487353d8aSRalf Baechle /* 10587353d8aSRalf Baechle * Final cleanup after all secondaries booted 10687353d8aSRalf Baechle */ 10787353d8aSRalf Baechle static void sb1250_cpus_done(void) 10887353d8aSRalf Baechle { 10987353d8aSRalf Baechle } 11087353d8aSRalf Baechle 11187353d8aSRalf Baechle /* 11287353d8aSRalf Baechle * Setup the PC, SP, and GP of a secondary processor and start it 11387353d8aSRalf Baechle * running! 11487353d8aSRalf Baechle */ 11587353d8aSRalf Baechle static void __cpuinit sb1250_boot_secondary(int cpu, struct task_struct *idle) 11687353d8aSRalf Baechle { 11787353d8aSRalf Baechle int retval; 11887353d8aSRalf Baechle 11987353d8aSRalf Baechle retval = cfe_cpu_start(cpu_logical_map(cpu), &smp_bootstrap, 12087353d8aSRalf Baechle __KSTK_TOS(idle), 12187353d8aSRalf Baechle (unsigned long)task_thread_info(idle), 0); 12287353d8aSRalf Baechle if (retval != 0) 12387353d8aSRalf Baechle printk("cfe_start_cpu(%i) returned %i\n" , cpu, retval); 12487353d8aSRalf Baechle } 12587353d8aSRalf Baechle 12687353d8aSRalf Baechle /* 12787353d8aSRalf Baechle * Use CFE to find out how many CPUs are available, setting up 12898a79d6aSRusty Russell * cpu_possible_map and the logical/physical mappings. 12987353d8aSRalf Baechle * XXXKW will the boot CPU ever not be physical 0? 13087353d8aSRalf Baechle * 13187353d8aSRalf Baechle * Common setup before any secondaries are started 13287353d8aSRalf Baechle */ 13387353d8aSRalf Baechle static void __init sb1250_smp_setup(void) 13487353d8aSRalf Baechle { 13587353d8aSRalf Baechle int i, num; 13687353d8aSRalf Baechle 13798a79d6aSRusty Russell cpus_clear(cpu_possible_map); 13898a79d6aSRusty Russell cpu_set(0, cpu_possible_map); 13987353d8aSRalf Baechle __cpu_number_map[0] = 0; 14087353d8aSRalf Baechle __cpu_logical_map[0] = 0; 14187353d8aSRalf Baechle 14287353d8aSRalf Baechle for (i = 1, num = 0; i < NR_CPUS; i++) { 14387353d8aSRalf Baechle if (cfe_cpu_stop(i) == 0) { 14498a79d6aSRusty Russell cpu_set(i, cpu_possible_map); 14587353d8aSRalf Baechle __cpu_number_map[i] = ++num; 14687353d8aSRalf Baechle __cpu_logical_map[num] = i; 14787353d8aSRalf Baechle } 14887353d8aSRalf Baechle } 14987353d8aSRalf Baechle printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num); 15087353d8aSRalf Baechle } 15187353d8aSRalf Baechle 15287353d8aSRalf Baechle static void __init sb1250_prepare_cpus(unsigned int max_cpus) 15387353d8aSRalf Baechle { 15487353d8aSRalf Baechle } 15587353d8aSRalf Baechle 15687353d8aSRalf Baechle struct plat_smp_ops sb_smp_ops = { 15787353d8aSRalf Baechle .send_ipi_single = sb1250_send_ipi_single, 15887353d8aSRalf Baechle .send_ipi_mask = sb1250_send_ipi_mask, 15987353d8aSRalf Baechle .init_secondary = sb1250_init_secondary, 16087353d8aSRalf Baechle .smp_finish = sb1250_smp_finish, 16187353d8aSRalf Baechle .cpus_done = sb1250_cpus_done, 16287353d8aSRalf Baechle .boot_secondary = sb1250_boot_secondary, 16387353d8aSRalf Baechle .smp_setup = sb1250_smp_setup, 16487353d8aSRalf Baechle .prepare_cpus = sb1250_prepare_cpus, 16587353d8aSRalf Baechle }; 16687353d8aSRalf Baechle 167937a8015SRalf Baechle void sb1250_mailbox_interrupt(void) 1681da177e4SLinus Torvalds { 1691da177e4SLinus Torvalds int cpu = smp_processor_id(); 170d2287f5eSMike Travis int irq = K_INT_MBOX_0; 1711da177e4SLinus Torvalds unsigned int action; 1721da177e4SLinus Torvalds 173d2287f5eSMike Travis kstat_incr_irqs_this_cpu(irq, irq_to_desc(irq)); 1741da177e4SLinus Torvalds /* Load the mailbox register to figure out what we're supposed to do */ 17565bda1a9SMaciej W. Rozycki action = (____raw_readq(mailbox_regs[cpu]) >> 48) & 0xffff; 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds /* Clear the mailbox to clear the interrupt */ 17865bda1a9SMaciej W. Rozycki ____raw_writeq(((u64)action) << 48, mailbox_clear_regs[cpu]); 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds /* 1811da177e4SLinus Torvalds * Nothing to do for SMP_RESCHEDULE_YOURSELF; returning from the 1821da177e4SLinus Torvalds * interrupt will do the reschedule for us 1831da177e4SLinus Torvalds */ 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds if (action & SMP_CALL_FUNCTION) 1861da177e4SLinus Torvalds smp_call_function_interrupt(); 1871da177e4SLinus Torvalds } 188