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> 24f3ac6067SIngo Molnar #include <linux/sched/task_stack.h> 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds #include <asm/mmu_context.h> 271da177e4SLinus Torvalds #include <asm/io.h> 2887353d8aSRalf Baechle #include <asm/fw/cfe/cfe_api.h> 291da177e4SLinus Torvalds #include <asm/sibyte/sb1250.h> 301da177e4SLinus Torvalds #include <asm/sibyte/sb1250_regs.h> 311da177e4SLinus Torvalds #include <asm/sibyte/sb1250_int.h> 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds static void *mailbox_set_regs[] = { 3465bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_SET_CPU), 3565bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_SET_CPU) 361da177e4SLinus Torvalds }; 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds static void *mailbox_clear_regs[] = { 3965bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CLR_CPU), 4065bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CLR_CPU) 411da177e4SLinus Torvalds }; 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds static void *mailbox_regs[] = { 4465bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CPU), 4565bda1a9SMaciej W. Rozycki IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CPU) 461da177e4SLinus Torvalds }; 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds /* 491da177e4SLinus Torvalds * SMP init and finish on secondary CPUs 501da177e4SLinus Torvalds */ 51078a55fcSPaul Gortmaker void sb1250_smp_init(void) 521da177e4SLinus Torvalds { 531da177e4SLinus Torvalds unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 | 541da177e4SLinus Torvalds STATUSF_IP1 | STATUSF_IP0; 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /* Set interrupt mask, but don't enable */ 571da177e4SLinus Torvalds change_c0_status(ST0_IM, imask); 581da177e4SLinus Torvalds } 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds /* 611da177e4SLinus Torvalds * These are routines for dealing with the sb1250 smp capabilities 621da177e4SLinus Torvalds * independent of board/firmware 631da177e4SLinus Torvalds */ 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* 661da177e4SLinus Torvalds * Simple enough; everything is set up, so just poke the appropriate mailbox 671da177e4SLinus Torvalds * register, and we should be set 681da177e4SLinus Torvalds */ 6987353d8aSRalf Baechle static void sb1250_send_ipi_single(int cpu, unsigned int action) 701da177e4SLinus Torvalds { 7165bda1a9SMaciej W. Rozycki __raw_writeq((((u64)action) << 48), mailbox_set_regs[cpu]); 721da177e4SLinus Torvalds } 731da177e4SLinus Torvalds 7448a048feSRusty Russell static inline void sb1250_send_ipi_mask(const struct cpumask *mask, 7548a048feSRusty Russell unsigned int action) 7687353d8aSRalf Baechle { 7787353d8aSRalf Baechle unsigned int i; 7887353d8aSRalf Baechle 7948a048feSRusty Russell for_each_cpu(i, mask) 8087353d8aSRalf Baechle sb1250_send_ipi_single(i, action); 8187353d8aSRalf Baechle } 8287353d8aSRalf Baechle 8387353d8aSRalf Baechle /* 8487353d8aSRalf Baechle * Code to run on secondary just after probing the CPU 8587353d8aSRalf Baechle */ 86078a55fcSPaul Gortmaker static void sb1250_init_secondary(void) 8787353d8aSRalf Baechle { 8887353d8aSRalf Baechle extern void sb1250_smp_init(void); 8987353d8aSRalf Baechle 9087353d8aSRalf Baechle sb1250_smp_init(); 9187353d8aSRalf Baechle } 9287353d8aSRalf Baechle 9387353d8aSRalf Baechle /* 9487353d8aSRalf Baechle * Do any tidying up before marking online and running the idle 9587353d8aSRalf Baechle * loop 9687353d8aSRalf Baechle */ 97078a55fcSPaul Gortmaker static void sb1250_smp_finish(void) 9887353d8aSRalf Baechle { 9987353d8aSRalf Baechle extern void sb1250_clockevent_init(void); 10087353d8aSRalf Baechle 10187353d8aSRalf Baechle sb1250_clockevent_init(); 10287353d8aSRalf Baechle local_irq_enable(); 10387353d8aSRalf Baechle } 10487353d8aSRalf Baechle 10587353d8aSRalf Baechle /* 10687353d8aSRalf Baechle * Setup the PC, SP, and GP of a secondary processor and start it 10787353d8aSRalf Baechle * running! 10887353d8aSRalf Baechle */ 109078a55fcSPaul Gortmaker static void sb1250_boot_secondary(int cpu, struct task_struct *idle) 11087353d8aSRalf Baechle { 11187353d8aSRalf Baechle int retval; 11287353d8aSRalf Baechle 11387353d8aSRalf Baechle retval = cfe_cpu_start(cpu_logical_map(cpu), &smp_bootstrap, 11487353d8aSRalf Baechle __KSTK_TOS(idle), 11587353d8aSRalf Baechle (unsigned long)task_thread_info(idle), 0); 11687353d8aSRalf Baechle if (retval != 0) 11787353d8aSRalf Baechle printk("cfe_start_cpu(%i) returned %i\n" , cpu, retval); 11887353d8aSRalf Baechle } 11987353d8aSRalf Baechle 12087353d8aSRalf Baechle /* 12187353d8aSRalf Baechle * Use CFE to find out how many CPUs are available, setting up 1220b5f9c00SRusty Russell * cpu_possible_mask and the logical/physical mappings. 12387353d8aSRalf Baechle * XXXKW will the boot CPU ever not be physical 0? 12487353d8aSRalf Baechle * 12587353d8aSRalf Baechle * Common setup before any secondaries are started 12687353d8aSRalf Baechle */ 12787353d8aSRalf Baechle static void __init sb1250_smp_setup(void) 12887353d8aSRalf Baechle { 12987353d8aSRalf Baechle int i, num; 13087353d8aSRalf Baechle 1310b5f9c00SRusty Russell init_cpu_possible(cpumask_of(0)); 13287353d8aSRalf Baechle __cpu_number_map[0] = 0; 13387353d8aSRalf Baechle __cpu_logical_map[0] = 0; 13487353d8aSRalf Baechle 13587353d8aSRalf Baechle for (i = 1, num = 0; i < NR_CPUS; i++) { 13687353d8aSRalf Baechle if (cfe_cpu_stop(i) == 0) { 1370b5f9c00SRusty Russell set_cpu_possible(i, true); 13887353d8aSRalf Baechle __cpu_number_map[i] = ++num; 13987353d8aSRalf Baechle __cpu_logical_map[num] = i; 14087353d8aSRalf Baechle } 14187353d8aSRalf Baechle } 14287353d8aSRalf Baechle printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num); 14387353d8aSRalf Baechle } 14487353d8aSRalf Baechle 14587353d8aSRalf Baechle static void __init sb1250_prepare_cpus(unsigned int max_cpus) 14687353d8aSRalf Baechle { 14787353d8aSRalf Baechle } 14887353d8aSRalf Baechle 149*ff2c8252SMatt Redfearn const struct plat_smp_ops sb_smp_ops = { 15087353d8aSRalf Baechle .send_ipi_single = sb1250_send_ipi_single, 15187353d8aSRalf Baechle .send_ipi_mask = sb1250_send_ipi_mask, 15287353d8aSRalf Baechle .init_secondary = sb1250_init_secondary, 15387353d8aSRalf Baechle .smp_finish = sb1250_smp_finish, 15487353d8aSRalf Baechle .boot_secondary = sb1250_boot_secondary, 15587353d8aSRalf Baechle .smp_setup = sb1250_smp_setup, 15687353d8aSRalf Baechle .prepare_cpus = sb1250_prepare_cpus, 15787353d8aSRalf Baechle }; 15887353d8aSRalf Baechle 159937a8015SRalf Baechle void sb1250_mailbox_interrupt(void) 1601da177e4SLinus Torvalds { 1611da177e4SLinus Torvalds int cpu = smp_processor_id(); 162d2287f5eSMike Travis int irq = K_INT_MBOX_0; 1631da177e4SLinus Torvalds unsigned int action; 1641da177e4SLinus Torvalds 165310ff2c8SThomas Gleixner kstat_incr_irq_this_cpu(irq); 1661da177e4SLinus Torvalds /* Load the mailbox register to figure out what we're supposed to do */ 16765bda1a9SMaciej W. Rozycki action = (____raw_readq(mailbox_regs[cpu]) >> 48) & 0xffff; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds /* Clear the mailbox to clear the interrupt */ 17065bda1a9SMaciej W. Rozycki ____raw_writeq(((u64)action) << 48, mailbox_clear_regs[cpu]); 1711da177e4SLinus Torvalds 172184748ccSPeter Zijlstra if (action & SMP_RESCHEDULE_YOURSELF) 173184748ccSPeter Zijlstra scheduler_ipi(); 1741da177e4SLinus Torvalds 1754ace6139SAlex Smith if (action & SMP_CALL_FUNCTION) { 1764ace6139SAlex Smith irq_enter(); 1774ace6139SAlex Smith generic_smp_call_function_interrupt(); 1784ace6139SAlex Smith irq_exit(); 1794ace6139SAlex Smith } 1801da177e4SLinus Torvalds } 181