18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General
38c2ecf20Sopenharmony_ci * Public License.  See the file "COPYING" in the main directory of this
48c2ecf20Sopenharmony_ci * archive for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com)
78c2ecf20Sopenharmony_ci * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc.
88c2ecf20Sopenharmony_ci * Copyright (C) 2000, 2001, 2002 Ralf Baechle
98c2ecf20Sopenharmony_ci * Copyright (C) 2000, 2001 Broadcom Corporation
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#ifndef __ASM_SMP_H
128c2ecf20Sopenharmony_ci#define __ASM_SMP_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/bitops.h>
158c2ecf20Sopenharmony_ci#include <linux/linkage.h>
168c2ecf20Sopenharmony_ci#include <linux/smp.h>
178c2ecf20Sopenharmony_ci#include <linux/threads.h>
188c2ecf20Sopenharmony_ci#include <linux/cpumask.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <linux/atomic.h>
218c2ecf20Sopenharmony_ci#include <asm/smp-ops.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciextern int smp_num_siblings;
248c2ecf20Sopenharmony_ciextern cpumask_t cpu_sibling_map[];
258c2ecf20Sopenharmony_ciextern cpumask_t cpu_core_map[];
268c2ecf20Sopenharmony_ciextern cpumask_t cpu_foreign_map[];
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic inline int raw_smp_processor_id(void)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci#if defined(__VDSO__)
318c2ecf20Sopenharmony_ci	extern int vdso_smp_processor_id(void)
328c2ecf20Sopenharmony_ci		__compiletime_error("VDSO should not call smp_processor_id()");
338c2ecf20Sopenharmony_ci	return vdso_smp_processor_id();
348c2ecf20Sopenharmony_ci#else
358c2ecf20Sopenharmony_ci	return current_thread_info()->cpu;
368c2ecf20Sopenharmony_ci#endif
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci#define raw_smp_processor_id raw_smp_processor_id
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* Map from cpu id to sequential logical cpu number.  This will only
418c2ecf20Sopenharmony_ci   not be idempotent when cpus failed to come on-line.	*/
428c2ecf20Sopenharmony_ciextern int __cpu_number_map[CONFIG_MIPS_NR_CPU_NR_MAP];
438c2ecf20Sopenharmony_ci#define cpu_number_map(cpu)  __cpu_number_map[cpu]
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* The reverse map from sequential logical cpu number to cpu id.  */
468c2ecf20Sopenharmony_ciextern int __cpu_logical_map[NR_CPUS];
478c2ecf20Sopenharmony_ci#define cpu_logical_map(cpu)  __cpu_logical_map[cpu]
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define NO_PROC_ID	(-1)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define SMP_RESCHEDULE_YOURSELF 0x1	/* XXX braindead */
528c2ecf20Sopenharmony_ci#define SMP_CALL_FUNCTION	0x2
538c2ecf20Sopenharmony_ci/* Octeon - Tell another core to flush its icache */
548c2ecf20Sopenharmony_ci#define SMP_ICACHE_FLUSH	0x4
558c2ecf20Sopenharmony_ci#define SMP_ASK_C0COUNT		0x8
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Mask of CPUs which are currently definitely operating coherently */
588c2ecf20Sopenharmony_ciextern cpumask_t cpu_coherent_mask;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciextern asmlinkage void smp_bootstrap(void);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciextern void calculate_cpu_foreign_map(void);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/*
658c2ecf20Sopenharmony_ci * this function sends a 'reschedule' IPI to another CPU.
668c2ecf20Sopenharmony_ci * it goes straight through and wastes no time serializing
678c2ecf20Sopenharmony_ci * anything. Worst case is that we lose a reschedule ...
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_cistatic inline void smp_send_reschedule(int cpu)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	extern const struct plat_smp_ops *mp_ops;	/* private */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	mp_ops->send_ipi_single(cpu, SMP_RESCHEDULE_YOURSELF);
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#ifdef CONFIG_HOTPLUG_CPU
778c2ecf20Sopenharmony_cistatic inline int __cpu_disable(void)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	extern const struct plat_smp_ops *mp_ops;	/* private */
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	return mp_ops->cpu_disable();
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic inline void __cpu_die(unsigned int cpu)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	extern const struct plat_smp_ops *mp_ops;	/* private */
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	mp_ops->cpu_die(cpu);
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciextern void play_dead(void);
928c2ecf20Sopenharmony_ci#endif
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#ifdef CONFIG_KEXEC
958c2ecf20Sopenharmony_cistatic inline void kexec_nonboot_cpu(void)
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	extern const struct plat_smp_ops *mp_ops;	/* private */
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	return mp_ops->kexec_nonboot_cpu();
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic inline void *kexec_nonboot_cpu_func(void)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	extern const struct plat_smp_ops *mp_ops;	/* private */
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	return mp_ops->kexec_nonboot_cpu;
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci#endif
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/*
1118c2ecf20Sopenharmony_ci * This function will set up the necessary IPIs for Linux to communicate
1128c2ecf20Sopenharmony_ci * with the CPUs in mask.
1138c2ecf20Sopenharmony_ci * Return 0 on success.
1148c2ecf20Sopenharmony_ci */
1158c2ecf20Sopenharmony_ciint mips_smp_ipi_allocate(const struct cpumask *mask);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/*
1188c2ecf20Sopenharmony_ci * This function will free up IPIs allocated with mips_smp_ipi_allocate to the
1198c2ecf20Sopenharmony_ci * CPUs in mask, which must be a subset of the IPIs that have been configured.
1208c2ecf20Sopenharmony_ci * Return 0 on success.
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ciint mips_smp_ipi_free(const struct cpumask *mask);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic inline void arch_send_call_function_single_ipi(int cpu)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci	extern const struct plat_smp_ops *mp_ops;	/* private */
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	mp_ops->send_ipi_single(cpu, SMP_CALL_FUNCTION);
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistatic inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
1328c2ecf20Sopenharmony_ci{
1338c2ecf20Sopenharmony_ci	extern const struct plat_smp_ops *mp_ops;	/* private */
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	mp_ops->send_ipi_mask(mask, SMP_CALL_FUNCTION);
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#endif /* __ASM_SMP_H */
139