2019-05-29 00:57:11 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-08-18 01:44:08 +08:00
|
|
|
/*
|
|
|
|
*
|
2006-04-05 16:45:45 +08:00
|
|
|
* Copyright (C) 2004, 05, 06 MIPS Technologies, Inc.
|
|
|
|
* Elizabeth Clarke (beth@mips.com)
|
|
|
|
* Ralf Baechle (ralf@linux-mips.org)
|
|
|
|
* Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org)
|
2005-08-18 01:44:08 +08:00
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/compiler.h>
|
2017-03-08 15:29:31 +08:00
|
|
|
#include <linux/sched/task_stack.h>
|
2007-03-03 04:42:04 +08:00
|
|
|
#include <linux/smp.h>
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2006-04-05 16:45:45 +08:00
|
|
|
#include <asm/cacheflush.h>
|
2005-08-18 01:44:08 +08:00
|
|
|
#include <asm/cpu.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/hardirq.h>
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/time.h>
|
|
|
|
#include <asm/mipsregs.h>
|
|
|
|
#include <asm/mipsmtregs.h>
|
2006-04-05 16:45:45 +08:00
|
|
|
#include <asm/mips_mt.h>
|
2017-08-13 12:36:34 +08:00
|
|
|
#include <asm/mips-cps.h>
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2008-04-29 00:14:26 +08:00
|
|
|
static void __init smvp_copy_vpe_config(void)
|
2006-11-01 02:25:10 +08:00
|
|
|
{
|
|
|
|
write_vpe_c0_status(
|
|
|
|
(read_c0_status() & ~(ST0_IM | ST0_IE | ST0_KSU)) | ST0_CU0);
|
|
|
|
|
|
|
|
/* set config to be the same as vpe0, particularly kseg0 coherency alg */
|
|
|
|
write_vpe_c0_config( read_c0_config());
|
|
|
|
|
|
|
|
/* make sure there are no software interrupts pending */
|
|
|
|
write_vpe_c0_cause(0);
|
|
|
|
|
|
|
|
/* Propagate Config7 */
|
|
|
|
write_vpe_c0_config7(read_c0_config7());
|
2006-11-01 02:33:09 +08:00
|
|
|
|
|
|
|
write_vpe_c0_count(read_c0_count());
|
2006-11-01 02:25:10 +08:00
|
|
|
}
|
|
|
|
|
2008-04-29 00:14:26 +08:00
|
|
|
static unsigned int __init smvp_vpe_init(unsigned int tc, unsigned int mvpconf0,
|
2006-11-01 02:25:10 +08:00
|
|
|
unsigned int ncpu)
|
|
|
|
{
|
|
|
|
if (tc > ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT))
|
|
|
|
return ncpu;
|
|
|
|
|
|
|
|
/* Deactivate all but VPE 0 */
|
|
|
|
if (tc != 0) {
|
|
|
|
unsigned long tmp = read_vpe_c0_vpeconf0();
|
|
|
|
|
|
|
|
tmp &= ~VPECONF0_VPA;
|
|
|
|
|
|
|
|
/* master VPE */
|
|
|
|
tmp |= VPECONF0_MVP;
|
|
|
|
write_vpe_c0_vpeconf0(tmp);
|
|
|
|
|
|
|
|
/* Record this as available CPU */
|
2009-09-24 23:34:47 +08:00
|
|
|
set_cpu_possible(tc, true);
|
2013-10-09 23:16:25 +08:00
|
|
|
set_cpu_present(tc, true);
|
2006-11-01 02:25:10 +08:00
|
|
|
__cpu_number_map[tc] = ++ncpu;
|
2013-01-22 19:59:30 +08:00
|
|
|
__cpu_logical_map[ncpu] = tc;
|
2006-11-01 02:25:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable multi-threading with TC's */
|
|
|
|
write_vpe_c0_vpecontrol(read_vpe_c0_vpecontrol() & ~VPECONTROL_TE);
|
|
|
|
|
|
|
|
if (tc != 0)
|
2008-04-29 00:14:26 +08:00
|
|
|
smvp_copy_vpe_config();
|
2006-11-01 02:25:10 +08:00
|
|
|
|
2017-08-13 10:49:35 +08:00
|
|
|
cpu_set_vpe_id(&cpu_data[ncpu], tc);
|
2017-03-31 03:06:12 +08:00
|
|
|
|
2006-11-01 02:25:10 +08:00
|
|
|
return ncpu;
|
|
|
|
}
|
|
|
|
|
2008-04-29 00:14:26 +08:00
|
|
|
static void __init smvp_tc_init(unsigned int tc, unsigned int mvpconf0)
|
2006-11-01 02:25:10 +08:00
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
if (!tc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* bind a TC to each VPE, May as well put all excess TC's
|
|
|
|
on the last VPE */
|
|
|
|
if (tc >= (((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT)+1))
|
|
|
|
write_tc_c0_tcbind(read_tc_c0_tcbind() | ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT));
|
|
|
|
else {
|
|
|
|
write_tc_c0_tcbind(read_tc_c0_tcbind() | tc);
|
|
|
|
|
|
|
|
/* and set XTC */
|
|
|
|
write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | (tc << VPECONF0_XTC_SHIFT));
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = read_tc_c0_tcstatus();
|
|
|
|
|
|
|
|
/* mark not allocated and not dynamically allocatable */
|
|
|
|
tmp &= ~(TCSTATUS_A | TCSTATUS_DA);
|
|
|
|
tmp |= TCSTATUS_IXMT; /* interrupt exempt */
|
|
|
|
write_tc_c0_tcstatus(tmp);
|
|
|
|
|
|
|
|
write_tc_c0_tchalt(TCHALT_H);
|
|
|
|
}
|
|
|
|
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 21:38:59 +08:00
|
|
|
static void vsmp_init_secondary(void)
|
2007-11-19 20:23:51 +08:00
|
|
|
{
|
2010-12-02 01:33:17 +08:00
|
|
|
/* This is Malta specific: IPI,performance and timer interrupts */
|
2017-08-13 12:36:34 +08:00
|
|
|
if (mips_gic_present())
|
2015-01-16 19:10:46 +08:00
|
|
|
change_c0_status(ST0_IM, STATUSF_IP2 | STATUSF_IP3 |
|
|
|
|
STATUSF_IP4 | STATUSF_IP5 |
|
2008-04-29 00:14:26 +08:00
|
|
|
STATUSF_IP6 | STATUSF_IP7);
|
|
|
|
else
|
|
|
|
change_c0_status(ST0_IM, STATUSF_IP0 | STATUSF_IP1 |
|
|
|
|
STATUSF_IP6 | STATUSF_IP7);
|
2006-04-05 16:45:45 +08:00
|
|
|
}
|
2005-08-18 01:44:08 +08:00
|
|
|
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 21:38:59 +08:00
|
|
|
static void vsmp_smp_finish(void)
|
2006-04-05 16:45:45 +08:00
|
|
|
{
|
2008-04-29 00:14:26 +08:00
|
|
|
/* CDFIXME: remove this? */
|
2007-11-19 20:23:51 +08:00
|
|
|
write_c0_compare(read_c0_count() + (8* mips_hpt_frequency/HZ));
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
#ifdef CONFIG_MIPS_MT_FPAFF
|
|
|
|
/* If we have an FPU, enroll ourselves in the FPU-full mask */
|
|
|
|
if (cpu_has_fpu)
|
2015-03-05 08:19:17 +08:00
|
|
|
cpumask_set_cpu(smp_processor_id(), &mt_fpu_cpumask);
|
2007-11-19 20:23:51 +08:00
|
|
|
#endif /* CONFIG_MIPS_MT_FPAFF */
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
local_irq_enable();
|
|
|
|
}
|
2005-08-18 01:44:08 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the PC, SP, and GP of a secondary processor and start it
|
|
|
|
* running!
|
|
|
|
* smp_bootstrap is the place to resume from
|
|
|
|
* __KSTK_TOS(idle) is apparently the stack pointer
|
|
|
|
* (unsigned long)idle->thread_info the gp
|
|
|
|
* assumes a 1:1 mapping of TC => VPE
|
|
|
|
*/
|
2017-08-13 10:49:40 +08:00
|
|
|
static int vsmp_boot_secondary(int cpu, struct task_struct *idle)
|
2005-08-18 01:44:08 +08:00
|
|
|
{
|
2006-01-12 17:06:07 +08:00
|
|
|
struct thread_info *gp = task_thread_info(idle);
|
2005-08-18 01:44:08 +08:00
|
|
|
dvpe();
|
|
|
|
set_c0_mvpcontrol(MVPCONTROL_VPC);
|
|
|
|
|
|
|
|
settc(cpu);
|
|
|
|
|
|
|
|
/* restart */
|
|
|
|
write_tc_c0_tcrestart((unsigned long)&smp_bootstrap);
|
|
|
|
|
|
|
|
/* enable the tc this vpe/cpu will be running */
|
|
|
|
write_tc_c0_tcstatus((read_tc_c0_tcstatus() & ~TCSTATUS_IXMT) | TCSTATUS_A);
|
|
|
|
|
|
|
|
write_tc_c0_tchalt(0);
|
|
|
|
|
|
|
|
/* enable the VPE */
|
|
|
|
write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | VPECONF0_VPA);
|
|
|
|
|
|
|
|
/* stack pointer */
|
|
|
|
write_tc_gpr_sp( __KSTK_TOS(idle));
|
|
|
|
|
|
|
|
/* global pointer */
|
2006-01-12 17:06:07 +08:00
|
|
|
write_tc_gpr_gp((unsigned long)gp);
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2006-04-05 16:45:45 +08:00
|
|
|
flush_icache_range((unsigned long)gp,
|
2013-01-22 19:59:30 +08:00
|
|
|
(unsigned long)(gp + sizeof(struct thread_info)));
|
2005-08-18 01:44:08 +08:00
|
|
|
|
|
|
|
/* finally out of configuration and into chaos */
|
|
|
|
clear_c0_mvpcontrol(MVPCONTROL_VPC);
|
|
|
|
|
|
|
|
evpe(EVPE_ENABLE);
|
2017-08-13 10:49:40 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-08-18 01:44:08 +08:00
|
|
|
}
|
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
/*
|
|
|
|
* Common setup before any secondaries are started
|
|
|
|
* Make sure all CPU's are in a sensible state before we boot any of the
|
2008-04-29 00:14:26 +08:00
|
|
|
* secondaries
|
2007-11-19 20:23:51 +08:00
|
|
|
*/
|
|
|
|
static void __init vsmp_smp_setup(void)
|
2005-08-18 01:44:08 +08:00
|
|
|
{
|
2007-11-19 20:23:51 +08:00
|
|
|
unsigned int mvpconf0, ntc, tc, ncpu = 0;
|
|
|
|
unsigned int nvpe;
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2006-04-05 16:45:47 +08:00
|
|
|
#ifdef CONFIG_MIPS_MT_FPAFF
|
|
|
|
/* If we have an FPU, enroll ourselves in the FPU-full mask */
|
|
|
|
if (cpu_has_fpu)
|
2015-03-05 08:19:17 +08:00
|
|
|
cpumask_set_cpu(0, &mt_fpu_cpumask);
|
2006-04-05 16:45:47 +08:00
|
|
|
#endif /* CONFIG_MIPS_MT_FPAFF */
|
2007-11-19 20:23:51 +08:00
|
|
|
if (!cpu_has_mipsmt)
|
|
|
|
return;
|
2006-04-05 16:45:47 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
/* disable MT so we can configure */
|
|
|
|
dvpe();
|
|
|
|
dmt();
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
/* Put MVPE's into 'configuration state' */
|
|
|
|
set_c0_mvpcontrol(MVPCONTROL_VPC);
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
mvpconf0 = read_c0_mvpconf0();
|
|
|
|
ntc = (mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT;
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
|
|
|
|
smp_num_siblings = nvpe;
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
/* we'll always have more TC's than VPE's, so loop setting everything
|
|
|
|
to a sensible state */
|
|
|
|
for (tc = 0; tc <= ntc; tc++) {
|
|
|
|
settc(tc);
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2008-04-29 00:14:26 +08:00
|
|
|
smvp_tc_init(tc, mvpconf0);
|
|
|
|
ncpu = smvp_vpe_init(tc, mvpconf0, ncpu);
|
2007-11-19 20:23:51 +08:00
|
|
|
}
|
2005-08-18 01:44:08 +08:00
|
|
|
|
2007-11-19 20:23:51 +08:00
|
|
|
/* Release config state */
|
|
|
|
clear_c0_mvpcontrol(MVPCONTROL_VPC);
|
|
|
|
|
|
|
|
/* We'll wait until starting the secondaries before starting MVPE */
|
|
|
|
|
|
|
|
printk(KERN_INFO "Detected %i available secondary CPU(s)\n", ncpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init vsmp_prepare_cpus(unsigned int max_cpus)
|
|
|
|
{
|
|
|
|
mips_mt_set_cpuoptions();
|
2005-08-18 01:44:08 +08:00
|
|
|
}
|
2007-11-19 20:23:51 +08:00
|
|
|
|
2017-07-19 16:21:03 +08:00
|
|
|
const struct plat_smp_ops vsmp_smp_ops = {
|
2017-03-31 03:06:12 +08:00
|
|
|
.send_ipi_single = mips_smp_send_ipi_single,
|
|
|
|
.send_ipi_mask = mips_smp_send_ipi_mask,
|
2007-11-19 20:23:51 +08:00
|
|
|
.init_secondary = vsmp_init_secondary,
|
|
|
|
.smp_finish = vsmp_smp_finish,
|
|
|
|
.boot_secondary = vsmp_boot_secondary,
|
|
|
|
.smp_setup = vsmp_smp_setup,
|
|
|
|
.prepare_cpus = vsmp_prepare_cpus,
|
|
|
|
};
|
2013-10-16 23:10:07 +08:00
|
|
|
|