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