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