| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General |
| 3 | * Public License. See the file "COPYING" in the main directory of this |
| 4 | * archive for more details. |
| 5 | * |
| 6 | * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com) |
| 7 | * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc. |
| 8 | * Copyright (C) 2000, 2001, 2002 Ralf Baechle |
| 9 | * Copyright (C) 2000, 2001 Broadcom Corporation |
| 10 | */ |
| 11 | #ifndef __ASM_SMP_H |
| 12 | #define __ASM_SMP_H |
| 13 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/bitops.h> |
| 15 | #include <linux/linkage.h> |
| Ralf Baechle | 631330f | 2009-06-19 14:05:26 +0100 | [diff] [blame] | 16 | #include <linux/smp.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/threads.h> |
| 18 | #include <linux/cpumask.h> |
| Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 19 | |
| Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 20 | #include <linux/atomic.h> |
| Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 21 | #include <asm/smp-ops.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| Ralf Baechle | 0ab7aef | 2007-03-02 20:42:04 +0000 | [diff] [blame] | 23 | extern int smp_num_siblings; |
| 24 | extern cpumask_t cpu_sibling_map[]; |
| Huacai Chen | bda4584 | 2014-06-26 11:41:26 +0800 | [diff] [blame] | 25 | extern cpumask_t cpu_core_map[]; |
| James Hogan | 640511a | 2016-07-13 14:12:52 +0100 | [diff] [blame] | 26 | extern cpumask_t cpu_foreign_map[]; |
| Ralf Baechle | 0ab7aef | 2007-03-02 20:42:04 +0000 | [diff] [blame] | 27 | |
| Paul Burton | 351fddd | 2017-12-12 09:57:47 +0000 | [diff] [blame] | 28 | static inline int raw_smp_processor_id(void) |
| 29 | { |
| 30 | #if defined(__VDSO__) |
| 31 | extern int vdso_smp_processor_id(void) |
| 32 | __compiletime_error("VDSO should not call smp_processor_id()"); |
| 33 | return vdso_smp_processor_id(); |
| 34 | #else |
| 35 | return current_thread_info()->cpu; |
| 36 | #endif |
| 37 | } |
| 38 | #define raw_smp_processor_id raw_smp_processor_id |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* Map from cpu id to sequential logical cpu number. This will only |
| Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 41 | not be idempotent when cpus failed to come on-line. */ |
| David Daney | 7820b84 | 2017-09-28 12:34:04 -0500 | [diff] [blame] | 42 | extern int __cpu_number_map[CONFIG_MIPS_NR_CPU_NR_MAP]; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define cpu_number_map(cpu) __cpu_number_map[cpu] |
| 44 | |
| 45 | /* The reverse map from sequential logical cpu number to cpu id. */ |
| 46 | extern int __cpu_logical_map[NR_CPUS]; |
| 47 | #define cpu_logical_map(cpu) __cpu_logical_map[cpu] |
| 48 | |
| 49 | #define NO_PROC_ID (-1) |
| 50 | |
| Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 51 | #define SMP_RESCHEDULE_YOURSELF 0x1 /* XXX braindead */ |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define SMP_CALL_FUNCTION 0x2 |
| David Daney | ddcdb1b | 2008-12-11 15:33:32 -0800 | [diff] [blame] | 53 | /* Octeon - Tell another core to flush its icache */ |
| 54 | #define SMP_ICACHE_FLUSH 0x4 |
| Marcin Nowakowski | c83c2ee | 2016-12-02 09:58:28 +0100 | [diff] [blame] | 55 | #define SMP_ASK_C0COUNT 0x8 |
| David Daney | ddcdb1b | 2008-12-11 15:33:32 -0800 | [diff] [blame] | 56 | |
| Paul Burton | 76306f4 | 2014-02-14 16:30:52 +0000 | [diff] [blame] | 57 | /* Mask of CPUs which are currently definitely operating coherently */ |
| 58 | extern cpumask_t cpu_coherent_mask; |
| 59 | |
| Joe Perches | b745fcb | 2017-07-12 14:37:25 -0700 | [diff] [blame] | 60 | extern asmlinkage void smp_bootstrap(void); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| James Hogan | 826e99b | 2016-07-13 14:12:45 +0100 | [diff] [blame] | 62 | extern void calculate_cpu_foreign_map(void); |
| 63 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* |
| 65 | * this function sends a 'reschedule' IPI to another CPU. |
| 66 | * it goes straight through and wastes no time serializing |
| 67 | * anything. Worst case is that we lose a reschedule ... |
| 68 | */ |
| 69 | static inline void smp_send_reschedule(int cpu) |
| 70 | { |
| Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 71 | extern const struct plat_smp_ops *mp_ops; /* private */ |
| Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 72 | |
| 73 | mp_ops->send_ipi_single(cpu, SMP_RESCHEDULE_YOURSELF); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| Ralf Baechle | 1b2bc75 | 2009-06-23 10:00:31 +0100 | [diff] [blame] | 76 | #ifdef CONFIG_HOTPLUG_CPU |
| 77 | static inline int __cpu_disable(void) |
| 78 | { |
| Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 79 | extern const struct plat_smp_ops *mp_ops; /* private */ |
| Ralf Baechle | 1b2bc75 | 2009-06-23 10:00:31 +0100 | [diff] [blame] | 80 | |
| 81 | return mp_ops->cpu_disable(); |
| 82 | } |
| 83 | |
| 84 | static inline void __cpu_die(unsigned int cpu) |
| 85 | { |
| Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 86 | extern const struct plat_smp_ops *mp_ops; /* private */ |
| Ralf Baechle | 1b2bc75 | 2009-06-23 10:00:31 +0100 | [diff] [blame] | 87 | |
| 88 | mp_ops->cpu_die(cpu); |
| 89 | } |
| 90 | |
| 91 | extern void play_dead(void); |
| 92 | #endif |
| 93 | |
| Dengcheng Zhu | 62cac48 | 2018-09-11 14:49:21 -0700 | [diff] [blame] | 94 | #ifdef CONFIG_KEXEC |
| 95 | static inline void kexec_nonboot_cpu(void) |
| 96 | { |
| 97 | extern const struct plat_smp_ops *mp_ops; /* private */ |
| 98 | |
| 99 | return mp_ops->kexec_nonboot_cpu(); |
| 100 | } |
| 101 | |
| 102 | static inline void *kexec_nonboot_cpu_func(void) |
| 103 | { |
| 104 | extern const struct plat_smp_ops *mp_ops; /* private */ |
| 105 | |
| 106 | return mp_ops->kexec_nonboot_cpu; |
| 107 | } |
| 108 | #endif |
| 109 | |
| Matt Redfearn | 7688c53 | 2016-09-20 09:47:26 +0100 | [diff] [blame] | 110 | /* |
| 111 | * This function will set up the necessary IPIs for Linux to communicate |
| 112 | * with the CPUs in mask. |
| 113 | * Return 0 on success. |
| 114 | */ |
| 115 | int mips_smp_ipi_allocate(const struct cpumask *mask); |
| 116 | |
| 117 | /* |
| 118 | * This function will free up IPIs allocated with mips_smp_ipi_allocate to the |
| 119 | * CPUs in mask, which must be a subset of the IPIs that have been configured. |
| 120 | * Return 0 on success. |
| 121 | */ |
| 122 | int mips_smp_ipi_free(const struct cpumask *mask); |
| 123 | |
| Ralf Baechle | eef34ec | 2009-09-25 15:35:28 +0100 | [diff] [blame] | 124 | static inline void arch_send_call_function_single_ipi(int cpu) |
| 125 | { |
| Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 126 | extern const struct plat_smp_ops *mp_ops; /* private */ |
| Ralf Baechle | eef34ec | 2009-09-25 15:35:28 +0100 | [diff] [blame] | 127 | |
| Rusty Russell | 1ed1835 | 2015-03-10 13:00:43 +1030 | [diff] [blame] | 128 | mp_ops->send_ipi_mask(cpumask_of(cpu), SMP_CALL_FUNCTION); |
| Ralf Baechle | eef34ec | 2009-09-25 15:35:28 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask) |
| 132 | { |
| Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 133 | extern const struct plat_smp_ops *mp_ops; /* private */ |
| Ralf Baechle | eef34ec | 2009-09-25 15:35:28 +0100 | [diff] [blame] | 134 | |
| 135 | mp_ops->send_ipi_mask(mask, SMP_CALL_FUNCTION); |
| 136 | } |
| Jens Axboe | 2f304c0 | 2008-06-17 10:45:23 +0200 | [diff] [blame] | 137 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #endif /* __ASM_SMP_H */ |