1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_CPUTHREADS_H 3b8b572e1SStephen Rothwell #define _ASM_POWERPC_CPUTHREADS_H 4b8b572e1SStephen Rothwell 56becef7eSchenhui zhao #ifndef __ASSEMBLY__ 6b8b572e1SStephen Rothwell #include <linux/cpumask.h> 7e340eca9SGuenter Roeck #include <asm/cpu_has_feature.h> 8b8b572e1SStephen Rothwell 9b8b572e1SStephen Rothwell /* 10b8b572e1SStephen Rothwell * Mapping of threads to cores 11fcce8109SBenjamin Herrenschmidt * 12fcce8109SBenjamin Herrenschmidt * Note: This implementation is limited to a power of 2 number of 13fcce8109SBenjamin Herrenschmidt * threads per core and the same number for each core in the system 14fcce8109SBenjamin Herrenschmidt * (though it would work if some processors had less threads as long 15933b90a9SAnshuman Khandual * as the CPU numbers are still allocated, just not brought online). 16fcce8109SBenjamin Herrenschmidt * 17fcce8109SBenjamin Herrenschmidt * However, the API allows for a different implementation in the future 18fcce8109SBenjamin Herrenschmidt * if needed, as long as you only use the functions and not the variables 19fcce8109SBenjamin Herrenschmidt * directly. 20b8b572e1SStephen Rothwell */ 21b8b572e1SStephen Rothwell 22b8b572e1SStephen Rothwell #ifdef CONFIG_SMP 23b8b572e1SStephen Rothwell extern int threads_per_core; 245853aef1SMichael Ellerman extern int threads_per_subcore; 25b8b572e1SStephen Rothwell extern int threads_shift; 26b8b572e1SStephen Rothwell extern cpumask_t threads_core_mask; 27b8b572e1SStephen Rothwell #else 28b8b572e1SStephen Rothwell #define threads_per_core 1 295853aef1SMichael Ellerman #define threads_per_subcore 1 30b8b572e1SStephen Rothwell #define threads_shift 0 31425752c6SGautham R. Shenoy #define has_big_cores 0 3287313df7SRusty Russell #define threads_core_mask (*get_cpu_mask(0)) 33b8b572e1SStephen Rothwell #endif 34b8b572e1SStephen Rothwell cpu_nr_cores(void)35b8b572e1SStephen Rothwellstatic inline int cpu_nr_cores(void) 36b8b572e1SStephen Rothwell { 37d52356e7SJan Stancek return nr_cpu_ids >> threads_shift; 38b8b572e1SStephen Rothwell } 39b8b572e1SStephen Rothwell 4099d86705SVaidyanathan Srinivasan #ifdef CONFIG_SMP 4199d86705SVaidyanathan Srinivasan int cpu_core_index_of_thread(int cpu); 4299d86705SVaidyanathan Srinivasan int cpu_first_thread_of_core(int core); 4399d86705SVaidyanathan Srinivasan #else cpu_core_index_of_thread(int cpu)4499d86705SVaidyanathan Srinivasanstatic inline int cpu_core_index_of_thread(int cpu) { return cpu; } cpu_first_thread_of_core(int core)4599d86705SVaidyanathan Srinivasanstatic inline int cpu_first_thread_of_core(int core) { return core; } 4699d86705SVaidyanathan Srinivasan #endif 47b8b572e1SStephen Rothwell cpu_thread_in_core(int cpu)48b8b572e1SStephen Rothwellstatic inline int cpu_thread_in_core(int cpu) 49b8b572e1SStephen Rothwell { 50b8b572e1SStephen Rothwell return cpu & (threads_per_core - 1); 51b8b572e1SStephen Rothwell } 52b8b572e1SStephen Rothwell cpu_thread_in_subcore(int cpu)535853aef1SMichael Ellermanstatic inline int cpu_thread_in_subcore(int cpu) 545853aef1SMichael Ellerman { 555853aef1SMichael Ellerman return cpu & (threads_per_subcore - 1); 565853aef1SMichael Ellerman } 575853aef1SMichael Ellerman cpu_first_thread_sibling(int cpu)5899d86705SVaidyanathan Srinivasanstatic inline int cpu_first_thread_sibling(int cpu) 59b8b572e1SStephen Rothwell { 60b8b572e1SStephen Rothwell return cpu & ~(threads_per_core - 1); 61b8b572e1SStephen Rothwell } 62b8b572e1SStephen Rothwell cpu_last_thread_sibling(int cpu)6399d86705SVaidyanathan Srinivasanstatic inline int cpu_last_thread_sibling(int cpu) 64fcce8109SBenjamin Herrenschmidt { 65fcce8109SBenjamin Herrenschmidt return cpu | (threads_per_core - 1); 66fcce8109SBenjamin Herrenschmidt } 67fcce8109SBenjamin Herrenschmidt 68*77bbbc0cSSuraj Jitindar Singh /* 69*77bbbc0cSSuraj Jitindar Singh * tlb_thread_siblings are siblings which share a TLB. This is not 70*77bbbc0cSSuraj Jitindar Singh * architected, is not something a hypervisor could emulate and a future 71*77bbbc0cSSuraj Jitindar Singh * CPU may change behaviour even in compat mode, so this should only be 72*77bbbc0cSSuraj Jitindar Singh * used on PowerNV, and only with care. 73*77bbbc0cSSuraj Jitindar Singh */ cpu_first_tlb_thread_sibling(int cpu)74*77bbbc0cSSuraj Jitindar Singhstatic inline int cpu_first_tlb_thread_sibling(int cpu) 75*77bbbc0cSSuraj Jitindar Singh { 76*77bbbc0cSSuraj Jitindar Singh if (cpu_has_feature(CPU_FTR_ARCH_300) && (threads_per_core == 8)) 77*77bbbc0cSSuraj Jitindar Singh return cpu & ~0x6; /* Big Core */ 78*77bbbc0cSSuraj Jitindar Singh else 79*77bbbc0cSSuraj Jitindar Singh return cpu_first_thread_sibling(cpu); 80*77bbbc0cSSuraj Jitindar Singh } 81*77bbbc0cSSuraj Jitindar Singh cpu_last_tlb_thread_sibling(int cpu)82*77bbbc0cSSuraj Jitindar Singhstatic inline int cpu_last_tlb_thread_sibling(int cpu) 83*77bbbc0cSSuraj Jitindar Singh { 84*77bbbc0cSSuraj Jitindar Singh if (cpu_has_feature(CPU_FTR_ARCH_300) && (threads_per_core == 8)) 85*77bbbc0cSSuraj Jitindar Singh return cpu | 0x6; /* Big Core */ 86*77bbbc0cSSuraj Jitindar Singh else 87*77bbbc0cSSuraj Jitindar Singh return cpu_last_thread_sibling(cpu); 88*77bbbc0cSSuraj Jitindar Singh } 89*77bbbc0cSSuraj Jitindar Singh cpu_tlb_thread_sibling_step(void)90*77bbbc0cSSuraj Jitindar Singhstatic inline int cpu_tlb_thread_sibling_step(void) 91*77bbbc0cSSuraj Jitindar Singh { 92*77bbbc0cSSuraj Jitindar Singh if (cpu_has_feature(CPU_FTR_ARCH_300) && (threads_per_core == 8)) 93*77bbbc0cSSuraj Jitindar Singh return 2; /* Big Core */ 94*77bbbc0cSSuraj Jitindar Singh else 95*77bbbc0cSSuraj Jitindar Singh return 1; 96*77bbbc0cSSuraj Jitindar Singh } 97*77bbbc0cSSuraj Jitindar Singh get_tensr(void)98ebb9d30aSchenhui zhaostatic inline u32 get_tensr(void) 99ebb9d30aSchenhui zhao { 100ebb9d30aSchenhui zhao #ifdef CONFIG_BOOKE 101ebb9d30aSchenhui zhao if (cpu_has_feature(CPU_FTR_SMT)) 102ebb9d30aSchenhui zhao return mfspr(SPRN_TENSR); 103ebb9d30aSchenhui zhao #endif 104ebb9d30aSchenhui zhao return 1; 105ebb9d30aSchenhui zhao } 106fcce8109SBenjamin Herrenschmidt 1076becef7eSchenhui zhao void book3e_start_thread(int thread, unsigned long addr); 108d17799f9Schenhui zhao void book3e_stop_thread(int thread); 109fcce8109SBenjamin Herrenschmidt 1106becef7eSchenhui zhao #endif /* __ASSEMBLY__ */ 1116becef7eSchenhui zhao 1126becef7eSchenhui zhao #define INVALID_THREAD_HWID 0x0fff 1136becef7eSchenhui zhao 114b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_CPUTHREADS_H */ 115b8b572e1SStephen Rothwell 116