xref: /openbmc/linux/include/linux/arch_topology.h (revision 5b8dc787)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2615ffd63SJuri Lelli /*
3615ffd63SJuri Lelli  * include/linux/arch_topology.h - arch specific cpu topology information
4615ffd63SJuri Lelli  */
5615ffd63SJuri Lelli #ifndef _LINUX_ARCH_TOPOLOGY_H_
6615ffd63SJuri Lelli #define _LINUX_ARCH_TOPOLOGY_H_
7615ffd63SJuri Lelli 
8805df296SViresh Kumar #include <linux/types.h>
90e27c567SDietmar Eggemann #include <linux/percpu.h>
10805df296SViresh Kumar 
114ca4f26aSJuri Lelli void topology_normalize_cpu_scale(void);
12bb1fbdd3SMorten Rasmussen int topology_update_cpu_topology(void);
13615ffd63SJuri Lelli 
14*9924fbb5SIonela Voinescu #ifdef CONFIG_ACPI_CPPC_LIB
15*9924fbb5SIonela Voinescu void topology_init_cpu_capacity_cppc(void);
16*9924fbb5SIonela Voinescu #endif
17*9924fbb5SIonela Voinescu 
18615ffd63SJuri Lelli struct device_node;
19805df296SViresh Kumar bool topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu);
20615ffd63SJuri Lelli 
218216f588SDietmar Eggemann DECLARE_PER_CPU(unsigned long, cpu_scale);
228216f588SDietmar Eggemann 
topology_get_cpu_scale(int cpu)2399c73ce1SDietmar Eggemann static inline unsigned long topology_get_cpu_scale(int cpu)
248216f588SDietmar Eggemann {
258216f588SDietmar Eggemann 	return per_cpu(cpu_scale, cpu);
268216f588SDietmar Eggemann }
27615ffd63SJuri Lelli 
284ca4f26aSJuri Lelli void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
29615ffd63SJuri Lelli 
30eec73529SViresh Kumar DECLARE_PER_CPU(unsigned long, arch_freq_scale);
310e27c567SDietmar Eggemann 
topology_get_freq_scale(int cpu)3299c73ce1SDietmar Eggemann static inline unsigned long topology_get_freq_scale(int cpu)
330e27c567SDietmar Eggemann {
34eec73529SViresh Kumar 	return per_cpu(arch_freq_scale, cpu);
350e27c567SDietmar Eggemann }
360e27c567SDietmar Eggemann 
37a20b7053SIonela Voinescu void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq,
38a20b7053SIonela Voinescu 			     unsigned long max_freq);
3915e5d5b4SValentin Schneider bool topology_scale_freq_invariant(void);
4015e5d5b4SValentin Schneider 
4101e055c1SViresh Kumar enum scale_freq_source {
4201e055c1SViresh Kumar 	SCALE_FREQ_SOURCE_CPUFREQ = 0,
4301e055c1SViresh Kumar 	SCALE_FREQ_SOURCE_ARCH,
444c38f2dfSViresh Kumar 	SCALE_FREQ_SOURCE_CPPC,
4501e055c1SViresh Kumar };
4601e055c1SViresh Kumar 
4701e055c1SViresh Kumar struct scale_freq_data {
4801e055c1SViresh Kumar 	enum scale_freq_source source;
4901e055c1SViresh Kumar 	void (*set_freq_scale)(void);
5001e055c1SViresh Kumar };
5101e055c1SViresh Kumar 
5201e055c1SViresh Kumar void topology_scale_freq_tick(void);
5301e055c1SViresh Kumar void topology_set_scale_freq_source(struct scale_freq_data *data, const struct cpumask *cpus);
5401e055c1SViresh Kumar void topology_clear_scale_freq_source(enum scale_freq_source source, const struct cpumask *cpus);
55cd0ed03aSIonela Voinescu 
56ad58cc5cSThara Gopinath DECLARE_PER_CPU(unsigned long, thermal_pressure);
57ad58cc5cSThara Gopinath 
topology_get_thermal_pressure(int cpu)58ad58cc5cSThara Gopinath static inline unsigned long topology_get_thermal_pressure(int cpu)
59ad58cc5cSThara Gopinath {
60ad58cc5cSThara Gopinath 	return per_cpu(thermal_pressure, cpu);
61ad58cc5cSThara Gopinath }
62ad58cc5cSThara Gopinath 
63c214f124SLukasz Luba void topology_update_thermal_pressure(const struct cpumask *cpus,
64c214f124SLukasz Luba 				      unsigned long capped_freq);
65c214f124SLukasz Luba 
6660c1b220SAtish Patra struct cpu_topology {
6760c1b220SAtish Patra 	int thread_id;
6860c1b220SAtish Patra 	int core_id;
69c5e22fefSJonathan Cameron 	int cluster_id;
7060c1b220SAtish Patra 	int package_id;
7160c1b220SAtish Patra 	cpumask_t thread_sibling;
7260c1b220SAtish Patra 	cpumask_t core_sibling;
73c5e22fefSJonathan Cameron 	cpumask_t cluster_sibling;
7460c1b220SAtish Patra 	cpumask_t llc_sibling;
7560c1b220SAtish Patra };
7660c1b220SAtish Patra 
7760c1b220SAtish Patra #ifdef CONFIG_GENERIC_ARCH_TOPOLOGY
7860c1b220SAtish Patra extern struct cpu_topology cpu_topology[NR_CPUS];
7960c1b220SAtish Patra 
8060c1b220SAtish Patra #define topology_physical_package_id(cpu)	(cpu_topology[cpu].package_id)
81c5e22fefSJonathan Cameron #define topology_cluster_id(cpu)	(cpu_topology[cpu].cluster_id)
8260c1b220SAtish Patra #define topology_core_id(cpu)		(cpu_topology[cpu].core_id)
8360c1b220SAtish Patra #define topology_core_cpumask(cpu)	(&cpu_topology[cpu].core_sibling)
8460c1b220SAtish Patra #define topology_sibling_cpumask(cpu)	(&cpu_topology[cpu].thread_sibling)
85c5e22fefSJonathan Cameron #define topology_cluster_cpumask(cpu)	(&cpu_topology[cpu].cluster_sibling)
8660c1b220SAtish Patra #define topology_llc_cpumask(cpu)	(&cpu_topology[cpu].llc_sibling)
8760c1b220SAtish Patra void init_cpu_topology(void);
8860c1b220SAtish Patra void store_cpu_topology(unsigned int cpuid);
8960c1b220SAtish Patra const struct cpumask *cpu_coregroup_mask(int cpu);
90c5e22fefSJonathan Cameron const struct cpumask *cpu_clustergroup_mask(int cpu);
9160c1b220SAtish Patra void update_siblings_masks(unsigned int cpu);
9260c1b220SAtish Patra void remove_cpu_topology(unsigned int cpuid);
93ca74b316SAtish Patra void reset_cpu_topology(void);
94edb44e84SBen Dooks (Codethink) int parse_acpi_topology(void);
95ca74b316SAtish Patra #endif
9660c1b220SAtish Patra 
97615ffd63SJuri Lelli #endif /* _LINUX_ARCH_TOPOLOGY_H_ */
98