]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/powerpc/include/asm/cputhreads.h
powerpc/mpc85xx: Add hotplug support on E5500 and E500MC cores
[mirror_ubuntu-focal-kernel.git] / arch / powerpc / include / asm / cputhreads.h
CommitLineData
8d089085
BH
1#ifndef _ASM_POWERPC_CPUTHREADS_H
2#define _ASM_POWERPC_CPUTHREADS_H
3
4#include <linux/cpumask.h>
5
6/*
7 * Mapping of threads to cores
fcce8109
BH
8 *
9 * Note: This implementation is limited to a power of 2 number of
10 * threads per core and the same number for each core in the system
11 * (though it would work if some processors had less threads as long
933b90a9 12 * as the CPU numbers are still allocated, just not brought online).
fcce8109
BH
13 *
14 * However, the API allows for a different implementation in the future
15 * if needed, as long as you only use the functions and not the variables
16 * directly.
8d089085
BH
17 */
18
19#ifdef CONFIG_SMP
20extern int threads_per_core;
5853aef1 21extern int threads_per_subcore;
8d089085
BH
22extern int threads_shift;
23extern cpumask_t threads_core_mask;
24#else
25#define threads_per_core 1
5853aef1 26#define threads_per_subcore 1
8d089085 27#define threads_shift 0
87313df7 28#define threads_core_mask (*get_cpu_mask(0))
8d089085
BH
29#endif
30
31/* cpu_thread_mask_to_cores - Return a cpumask of one per cores
32 * hit by the argument
33 *
e602ffb2 34 * @threads: a cpumask of online threads
8d089085 35 *
e602ffb2 36 * This function returns a cpumask which will have one online cpu's
8d089085
BH
37 * bit set for each core that has at least one thread set in the argument.
38 *
39 * This can typically be used for things like IPI for tlb invalidations
40 * since those need to be done only once per core/TLB
41 */
104699c0 42static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads)
8d089085
BH
43{
44 cpumask_t tmp, res;
e602ffb2 45 int i, cpu;
8d089085 46
104699c0 47 cpumask_clear(&res);
8d089085 48 for (i = 0; i < NR_CPUS; i += threads_per_core) {
104699c0 49 cpumask_shift_left(&tmp, &threads_core_mask, i);
e602ffb2
SP
50 if (cpumask_intersects(threads, &tmp)) {
51 cpu = cpumask_next_and(-1, &tmp, cpu_online_mask);
52 if (cpu < nr_cpu_ids)
53 cpumask_set_cpu(cpu, &res);
54 }
8d089085
BH
55 }
56 return res;
57}
58
59static inline int cpu_nr_cores(void)
60{
d52356e7 61 return nr_cpu_ids >> threads_shift;
8d089085
BH
62}
63
64static inline cpumask_t cpu_online_cores_map(void)
65{
104699c0 66 return cpu_thread_mask_to_cores(cpu_online_mask);
8d089085
BH
67}
68
99d86705
VS
69#ifdef CONFIG_SMP
70int cpu_core_index_of_thread(int cpu);
71int cpu_first_thread_of_core(int core);
72#else
73static inline int cpu_core_index_of_thread(int cpu) { return cpu; }
74static inline int cpu_first_thread_of_core(int core) { return core; }
75#endif
8d089085
BH
76
77static inline int cpu_thread_in_core(int cpu)
78{
79 return cpu & (threads_per_core - 1);
80}
81
5853aef1
ME
82static inline int cpu_thread_in_subcore(int cpu)
83{
84 return cpu & (threads_per_subcore - 1);
85}
86
99d86705 87static inline int cpu_first_thread_sibling(int cpu)
8d089085
BH
88{
89 return cpu & ~(threads_per_core - 1);
90}
91
99d86705 92static inline int cpu_last_thread_sibling(int cpu)
fcce8109
BH
93{
94 return cpu | (threads_per_core - 1);
95}
96
ebb9d30a 97static inline u32 get_tensr(void)
98{
99#ifdef CONFIG_BOOKE
100 if (cpu_has_feature(CPU_FTR_SMT))
101 return mfspr(SPRN_TENSR);
102#endif
103 return 1;
104}
fcce8109 105
d17799f9 106void book3e_stop_thread(int thread);
fcce8109 107
8d089085
BH
108#endif /* _ASM_POWERPC_CPUTHREADS_H */
109