12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
24ca4b627SJon Loeliger /*
34ca4b627SJon Loeliger * Author: Xianghua Xiao <x.xiao@freescale.com>
44ca4b627SJon Loeliger * Zhang Wei <wei.zhang@freescale.com>
54ca4b627SJon Loeliger *
64ca4b627SJon Loeliger * Copyright 2006 Freescale Semiconductor Inc.
74ca4b627SJon Loeliger */
84ca4b627SJon Loeliger
94ca4b627SJon Loeliger #include <linux/stddef.h>
104ca4b627SJon Loeliger #include <linux/kernel.h>
114ca4b627SJon Loeliger #include <linux/init.h>
124ca4b627SJon Loeliger #include <linux/delay.h>
1365fddcfcSMike Rapoport #include <linux/pgtable.h>
144ca4b627SJon Loeliger
15aaddd3eaSMichael Ellerman #include <asm/code-patching.h>
164ca4b627SJon Loeliger #include <asm/page.h>
174ca4b627SJon Loeliger #include <asm/pci-bridge.h>
18b8b572e1SStephen Rothwell #include <asm/mpic.h>
194ca4b627SJon Loeliger #include <asm/cacheflush.h>
2075346251SJordan Niethe #include <asm/inst.h>
214ca4b627SJon Loeliger
224ca4b627SJon Loeliger #include <sysdev/fsl_soc.h>
234ca4b627SJon Loeliger
244ca4b627SJon Loeliger #include "mpc86xx.h"
254ca4b627SJon Loeliger
264ca4b627SJon Loeliger extern void __secondary_start_mpc86xx(void);
274ca4b627SJon Loeliger
281e76dff2SKumar Gala #define MCM_PORT_CONFIG_OFFSET 0x10
291e76dff2SKumar Gala
301e76dff2SKumar Gala /* Offset from CCSRBAR */
311e76dff2SKumar Gala #define MPC86xx_MCM_OFFSET (0x1000)
321e76dff2SKumar Gala #define MPC86xx_MCM_SIZE (0x1000)
334ca4b627SJon Loeliger
344ca4b627SJon Loeliger static void __init
smp_86xx_release_core(int nr)354ca4b627SJon Loeliger smp_86xx_release_core(int nr)
364ca4b627SJon Loeliger {
379ad494f6SKumar Gala __be32 __iomem *mcm_vaddr;
389ad494f6SKumar Gala unsigned long pcr;
394ca4b627SJon Loeliger
404ca4b627SJon Loeliger if (nr < 0 || nr >= NR_CPUS)
414ca4b627SJon Loeliger return;
424ca4b627SJon Loeliger
434ca4b627SJon Loeliger /*
444ca4b627SJon Loeliger * Startup Core #nr.
454ca4b627SJon Loeliger */
464ca4b627SJon Loeliger mcm_vaddr = ioremap(get_immrbase() + MPC86xx_MCM_OFFSET,
474ca4b627SJon Loeliger MPC86xx_MCM_SIZE);
489ad494f6SKumar Gala pcr = in_be32(mcm_vaddr + (MCM_PORT_CONFIG_OFFSET >> 2));
494ca4b627SJon Loeliger pcr |= 1 << (nr + 24);
509ad494f6SKumar Gala out_be32(mcm_vaddr + (MCM_PORT_CONFIG_OFFSET >> 2), pcr);
511e76dff2SKumar Gala
521e76dff2SKumar Gala iounmap(mcm_vaddr);
534ca4b627SJon Loeliger }
544ca4b627SJon Loeliger
554ca4b627SJon Loeliger
56de300974SMichael Ellerman static int __init
smp_86xx_kick_cpu(int nr)574ca4b627SJon Loeliger smp_86xx_kick_cpu(int nr)
584ca4b627SJon Loeliger {
594ca4b627SJon Loeliger unsigned int save_vector;
604ca4b627SJon Loeliger unsigned long target, flags;
614ca4b627SJon Loeliger int n = 0;
62e7a57273SMichael Ellerman unsigned int *vector = (unsigned int *)(KERNELBASE + 0x100);
634ca4b627SJon Loeliger
644ca4b627SJon Loeliger if (nr < 0 || nr >= NR_CPUS)
65de300974SMichael Ellerman return -ENOENT;
664ca4b627SJon Loeliger
674ca4b627SJon Loeliger pr_debug("smp_86xx_kick_cpu: kick CPU #%d\n", nr);
684ca4b627SJon Loeliger
694ca4b627SJon Loeliger local_irq_save(flags);
704ca4b627SJon Loeliger
714ca4b627SJon Loeliger /* Save reset vector */
724ca4b627SJon Loeliger save_vector = *vector;
734ca4b627SJon Loeliger
744ca4b627SJon Loeliger /* Setup fake reset vector to call __secondary_start_mpc86xx. */
754ca4b627SJon Loeliger target = (unsigned long) __secondary_start_mpc86xx;
76*69d4d6e5SChristophe Leroy patch_branch(vector, target, BRANCH_SET_LINK);
774ca4b627SJon Loeliger
784ca4b627SJon Loeliger /* Kick that CPU */
794ca4b627SJon Loeliger smp_86xx_release_core(nr);
804ca4b627SJon Loeliger
814ca4b627SJon Loeliger /* Wait a bit for the CPU to take the exception. */
824ca4b627SJon Loeliger while ((__secondary_hold_acknowledge != nr) && (n++, n < 1000))
834ca4b627SJon Loeliger mdelay(1);
844ca4b627SJon Loeliger
854ca4b627SJon Loeliger /* Restore the exception vector */
86*69d4d6e5SChristophe Leroy patch_instruction(vector, ppc_inst(save_vector));
874ca4b627SJon Loeliger
884ca4b627SJon Loeliger local_irq_restore(flags);
894ca4b627SJon Loeliger
904ca4b627SJon Loeliger pr_debug("wait CPU #%d for %d msecs.\n", nr, n);
91de300974SMichael Ellerman
92de300974SMichael Ellerman return 0;
934ca4b627SJon Loeliger }
944ca4b627SJon Loeliger
954ca4b627SJon Loeliger
964ca4b627SJon Loeliger static void __init
smp_86xx_setup_cpu(int cpu_nr)974ca4b627SJon Loeliger smp_86xx_setup_cpu(int cpu_nr)
984ca4b627SJon Loeliger {
994ca4b627SJon Loeliger mpic_setup_this_cpu();
1004ca4b627SJon Loeliger }
1014ca4b627SJon Loeliger
1024ca4b627SJon Loeliger
1034ca4b627SJon Loeliger struct smp_ops_t smp_86xx_ops = {
104c64af645SNicholas Piggin .cause_nmi_ipi = NULL,
1054ca4b627SJon Loeliger .message_pass = smp_mpic_message_pass,
1064ca4b627SJon Loeliger .probe = smp_mpic_probe,
1074ca4b627SJon Loeliger .kick_cpu = smp_86xx_kick_cpu,
1084ca4b627SJon Loeliger .setup_cpu = smp_86xx_setup_cpu,
1094ca4b627SJon Loeliger .take_timebase = smp_generic_take_timebase,
1104ca4b627SJon Loeliger .give_timebase = smp_generic_give_timebase,
1114ca4b627SJon Loeliger };
1124ca4b627SJon Loeliger
1134ca4b627SJon Loeliger
1144ca4b627SJon Loeliger void __init
mpc86xx_smp_init(void)1154ca4b627SJon Loeliger mpc86xx_smp_init(void)
1164ca4b627SJon Loeliger {
1174ca4b627SJon Loeliger smp_ops = &smp_86xx_ops;
1184ca4b627SJon Loeliger }
119