1f137e463SAndrew Isaacson /* 2f137e463SAndrew Isaacson * Copyright (C) 2001,2002,2004 Broadcom Corporation 3f137e463SAndrew Isaacson * 4f137e463SAndrew Isaacson * This program is free software; you can redistribute it and/or 5f137e463SAndrew Isaacson * modify it under the terms of the GNU General Public License 6f137e463SAndrew Isaacson * as published by the Free Software Foundation; either version 2 7f137e463SAndrew Isaacson * of the License, or (at your option) any later version. 8f137e463SAndrew Isaacson * 9f137e463SAndrew Isaacson * This program is distributed in the hope that it will be useful, 10f137e463SAndrew Isaacson * but WITHOUT ANY WARRANTY; without even the implied warranty of 11f137e463SAndrew Isaacson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12f137e463SAndrew Isaacson * GNU General Public License for more details. 13f137e463SAndrew Isaacson * 14f137e463SAndrew Isaacson * You should have received a copy of the GNU General Public License 15f137e463SAndrew Isaacson * along with this program; if not, write to the Free Software 16f137e463SAndrew Isaacson * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17f137e463SAndrew Isaacson */ 18f137e463SAndrew Isaacson 19f137e463SAndrew Isaacson #include <linux/init.h> 20f137e463SAndrew Isaacson #include <linux/delay.h> 21f137e463SAndrew Isaacson #include <linux/smp.h> 22f137e463SAndrew Isaacson #include <linux/kernel_stat.h> 23f137e463SAndrew Isaacson 24f137e463SAndrew Isaacson #include <asm/mmu_context.h> 25f137e463SAndrew Isaacson #include <asm/io.h> 26*87353d8aSRalf Baechle #include <asm/fw/cfe/cfe_api.h> 27f137e463SAndrew Isaacson #include <asm/sibyte/sb1250.h> 28f137e463SAndrew Isaacson #include <asm/sibyte/bcm1480_regs.h> 29f137e463SAndrew Isaacson #include <asm/sibyte/bcm1480_int.h> 30f137e463SAndrew Isaacson 31f137e463SAndrew Isaacson extern void smp_call_function_interrupt(void); 32f137e463SAndrew Isaacson 33f137e463SAndrew Isaacson /* 34f137e463SAndrew Isaacson * These are routines for dealing with the bcm1480 smp capabilities 35f137e463SAndrew Isaacson * independent of board/firmware 36f137e463SAndrew Isaacson */ 37f137e463SAndrew Isaacson 388fb303c7SRalf Baechle static void *mailbox_0_set_regs[] = { 39f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU0_BASE + R_BCM1480_IMR_MAILBOX_0_SET_CPU), 40f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU1_BASE + R_BCM1480_IMR_MAILBOX_0_SET_CPU), 41f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU2_BASE + R_BCM1480_IMR_MAILBOX_0_SET_CPU), 42f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU3_BASE + R_BCM1480_IMR_MAILBOX_0_SET_CPU), 43f137e463SAndrew Isaacson }; 44f137e463SAndrew Isaacson 458fb303c7SRalf Baechle static void *mailbox_0_clear_regs[] = { 46f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU0_BASE + R_BCM1480_IMR_MAILBOX_0_CLR_CPU), 47f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU1_BASE + R_BCM1480_IMR_MAILBOX_0_CLR_CPU), 48f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU2_BASE + R_BCM1480_IMR_MAILBOX_0_CLR_CPU), 49f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU3_BASE + R_BCM1480_IMR_MAILBOX_0_CLR_CPU), 50f137e463SAndrew Isaacson }; 51f137e463SAndrew Isaacson 528fb303c7SRalf Baechle static void *mailbox_0_regs[] = { 53f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU0_BASE + R_BCM1480_IMR_MAILBOX_0_CPU), 54f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU1_BASE + R_BCM1480_IMR_MAILBOX_0_CPU), 55f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU2_BASE + R_BCM1480_IMR_MAILBOX_0_CPU), 56f137e463SAndrew Isaacson IOADDR(A_BCM1480_IMR_CPU3_BASE + R_BCM1480_IMR_MAILBOX_0_CPU), 57f137e463SAndrew Isaacson }; 58f137e463SAndrew Isaacson 59f137e463SAndrew Isaacson /* 60f137e463SAndrew Isaacson * SMP init and finish on secondary CPUs 61f137e463SAndrew Isaacson */ 62d0453365SRalf Baechle void __cpuinit bcm1480_smp_init(void) 63f137e463SAndrew Isaacson { 64f137e463SAndrew Isaacson unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 | 65f137e463SAndrew Isaacson STATUSF_IP1 | STATUSF_IP0; 66f137e463SAndrew Isaacson 67f137e463SAndrew Isaacson /* Set interrupt mask, but don't enable */ 68f137e463SAndrew Isaacson change_c0_status(ST0_IM, imask); 69f137e463SAndrew Isaacson } 70f137e463SAndrew Isaacson 71f137e463SAndrew Isaacson /* 72f137e463SAndrew Isaacson * These are routines for dealing with the sb1250 smp capabilities 73f137e463SAndrew Isaacson * independent of board/firmware 74f137e463SAndrew Isaacson */ 75f137e463SAndrew Isaacson 76f137e463SAndrew Isaacson /* 77f137e463SAndrew Isaacson * Simple enough; everything is set up, so just poke the appropriate mailbox 78f137e463SAndrew Isaacson * register, and we should be set 79f137e463SAndrew Isaacson */ 80*87353d8aSRalf Baechle static void bcm1480_send_ipi_single(int cpu, unsigned int action) 81f137e463SAndrew Isaacson { 82f137e463SAndrew Isaacson __raw_writeq((((u64)action)<< 48), mailbox_0_set_regs[cpu]); 83f137e463SAndrew Isaacson } 84f137e463SAndrew Isaacson 85*87353d8aSRalf Baechle static void bcm1480_send_ipi_mask(cpumask_t mask, unsigned int action) 86*87353d8aSRalf Baechle { 87*87353d8aSRalf Baechle unsigned int i; 88*87353d8aSRalf Baechle 89*87353d8aSRalf Baechle for_each_cpu_mask(i, mask) 90*87353d8aSRalf Baechle bcm1480_send_ipi_single(i, action); 91*87353d8aSRalf Baechle } 92*87353d8aSRalf Baechle 93*87353d8aSRalf Baechle /* 94*87353d8aSRalf Baechle * Code to run on secondary just after probing the CPU 95*87353d8aSRalf Baechle */ 96*87353d8aSRalf Baechle static void __cpuinit bcm1480_init_secondary(void) 97*87353d8aSRalf Baechle { 98*87353d8aSRalf Baechle extern void bcm1480_smp_init(void); 99*87353d8aSRalf Baechle 100*87353d8aSRalf Baechle bcm1480_smp_init(); 101*87353d8aSRalf Baechle } 102*87353d8aSRalf Baechle 103*87353d8aSRalf Baechle /* 104*87353d8aSRalf Baechle * Do any tidying up before marking online and running the idle 105*87353d8aSRalf Baechle * loop 106*87353d8aSRalf Baechle */ 107*87353d8aSRalf Baechle static void __cpuinit bcm1480_smp_finish(void) 108*87353d8aSRalf Baechle { 109*87353d8aSRalf Baechle extern void sb1480_clockevent_init(void); 110*87353d8aSRalf Baechle 111*87353d8aSRalf Baechle sb1480_clockevent_init(); 112*87353d8aSRalf Baechle local_irq_enable(); 113*87353d8aSRalf Baechle bcm1480_smp_finish(); 114*87353d8aSRalf Baechle } 115*87353d8aSRalf Baechle 116*87353d8aSRalf Baechle /* 117*87353d8aSRalf Baechle * Final cleanup after all secondaries booted 118*87353d8aSRalf Baechle */ 119*87353d8aSRalf Baechle static void bcm1480_cpus_done(void) 120*87353d8aSRalf Baechle { 121*87353d8aSRalf Baechle } 122*87353d8aSRalf Baechle 123*87353d8aSRalf Baechle /* 124*87353d8aSRalf Baechle * Setup the PC, SP, and GP of a secondary processor and start it 125*87353d8aSRalf Baechle * running! 126*87353d8aSRalf Baechle */ 127*87353d8aSRalf Baechle static void __cpuinit bcm1480_boot_secondary(int cpu, struct task_struct *idle) 128*87353d8aSRalf Baechle { 129*87353d8aSRalf Baechle int retval; 130*87353d8aSRalf Baechle 131*87353d8aSRalf Baechle retval = cfe_cpu_start(cpu_logical_map(cpu), &smp_bootstrap, 132*87353d8aSRalf Baechle __KSTK_TOS(idle), 133*87353d8aSRalf Baechle (unsigned long)task_thread_info(idle), 0); 134*87353d8aSRalf Baechle if (retval != 0) 135*87353d8aSRalf Baechle printk("cfe_start_cpu(%i) returned %i\n" , cpu, retval); 136*87353d8aSRalf Baechle } 137*87353d8aSRalf Baechle 138*87353d8aSRalf Baechle /* 139*87353d8aSRalf Baechle * Use CFE to find out how many CPUs are available, setting up 140*87353d8aSRalf Baechle * phys_cpu_present_map and the logical/physical mappings. 141*87353d8aSRalf Baechle * XXXKW will the boot CPU ever not be physical 0? 142*87353d8aSRalf Baechle * 143*87353d8aSRalf Baechle * Common setup before any secondaries are started 144*87353d8aSRalf Baechle */ 145*87353d8aSRalf Baechle static void __init bcm1480_smp_setup(void) 146*87353d8aSRalf Baechle { 147*87353d8aSRalf Baechle int i, num; 148*87353d8aSRalf Baechle 149*87353d8aSRalf Baechle cpus_clear(phys_cpu_present_map); 150*87353d8aSRalf Baechle cpu_set(0, phys_cpu_present_map); 151*87353d8aSRalf Baechle __cpu_number_map[0] = 0; 152*87353d8aSRalf Baechle __cpu_logical_map[0] = 0; 153*87353d8aSRalf Baechle 154*87353d8aSRalf Baechle for (i = 1, num = 0; i < NR_CPUS; i++) { 155*87353d8aSRalf Baechle if (cfe_cpu_stop(i) == 0) { 156*87353d8aSRalf Baechle cpu_set(i, phys_cpu_present_map); 157*87353d8aSRalf Baechle __cpu_number_map[i] = ++num; 158*87353d8aSRalf Baechle __cpu_logical_map[num] = i; 159*87353d8aSRalf Baechle } 160*87353d8aSRalf Baechle } 161*87353d8aSRalf Baechle printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num); 162*87353d8aSRalf Baechle } 163*87353d8aSRalf Baechle 164*87353d8aSRalf Baechle static void __init bcm1480_prepare_cpus(unsigned int max_cpus) 165*87353d8aSRalf Baechle { 166*87353d8aSRalf Baechle } 167*87353d8aSRalf Baechle 168*87353d8aSRalf Baechle struct plat_smp_ops bcm1480_smp_ops = { 169*87353d8aSRalf Baechle .send_ipi_single = bcm1480_send_ipi_single, 170*87353d8aSRalf Baechle .send_ipi_mask = bcm1480_send_ipi_mask, 171*87353d8aSRalf Baechle .init_secondary = bcm1480_init_secondary, 172*87353d8aSRalf Baechle .smp_finish = bcm1480_smp_finish, 173*87353d8aSRalf Baechle .cpus_done = bcm1480_cpus_done, 174*87353d8aSRalf Baechle .boot_secondary = bcm1480_boot_secondary, 175*87353d8aSRalf Baechle .smp_setup = bcm1480_smp_setup, 176*87353d8aSRalf Baechle .prepare_cpus = bcm1480_prepare_cpus, 177*87353d8aSRalf Baechle }; 178*87353d8aSRalf Baechle 179937a8015SRalf Baechle void bcm1480_mailbox_interrupt(void) 180f137e463SAndrew Isaacson { 181f137e463SAndrew Isaacson int cpu = smp_processor_id(); 182f137e463SAndrew Isaacson unsigned int action; 183f137e463SAndrew Isaacson 184f137e463SAndrew Isaacson kstat_this_cpu.irqs[K_BCM1480_INT_MBOX_0_0]++; 185f137e463SAndrew Isaacson /* Load the mailbox register to figure out what we're supposed to do */ 186f137e463SAndrew Isaacson action = (__raw_readq(mailbox_0_regs[cpu]) >> 48) & 0xffff; 187f137e463SAndrew Isaacson 188f137e463SAndrew Isaacson /* Clear the mailbox to clear the interrupt */ 189f137e463SAndrew Isaacson __raw_writeq(((u64)action)<<48, mailbox_0_clear_regs[cpu]); 190f137e463SAndrew Isaacson 191f137e463SAndrew Isaacson /* 192f137e463SAndrew Isaacson * Nothing to do for SMP_RESCHEDULE_YOURSELF; returning from the 193f137e463SAndrew Isaacson * interrupt will do the reschedule for us 194f137e463SAndrew Isaacson */ 195f137e463SAndrew Isaacson 196f137e463SAndrew Isaacson if (action & SMP_CALL_FUNCTION) 197f137e463SAndrew Isaacson smp_call_function_interrupt(); 198f137e463SAndrew Isaacson } 199