21 #include <linux/sched.h>
22 #include <linux/slab.h>
24 #include <asm/cputype.h>
25 #include <asm/topology.h>
49 static void set_power_scale(
unsigned int cpu,
unsigned long power)
51 per_cpu(cpu_scale, cpu) = power;
55 struct cpu_efficiency {
57 unsigned long efficiency;
70 struct cpu_efficiency table_efficiency[] = {
71 {
"arm,cortex-a15", 3891},
72 {
"arm,cortex-a7", 2048},
81 struct cpu_capacity *cpu_capacity;
83 unsigned long middle_capacity = 1;
93 static void __init parse_dt_topology(
void)
95 struct cpu_efficiency *cpu_eff;
97 unsigned long min_capacity = (
unsigned long)(-1);
98 unsigned long max_capacity = 0;
100 int alloc_size,
cpu = 0;
102 alloc_size =
nr_cpu_ids *
sizeof(
struct cpu_capacity);
103 cpu_capacity = (
struct cpu_capacity *)kzalloc(alloc_size,
GFP_NOWAIT);
112 for (cpu_eff = table_efficiency; cpu_eff->compatible; cpu_eff++)
116 if (cpu_eff->compatible ==
NULL)
120 if (!rate || len != 4) {
121 pr_err(
"%s missing clock-frequency property\n",
127 if (!reg || len != 4) {
132 capacity = ((
be32_to_cpup(rate)) >> 20) * cpu_eff->efficiency;
135 if (capacity < min_capacity)
139 if (capacity > max_capacity)
147 cpu_capacity[
cpu].hwid = (
unsigned long)(-1);
156 if (min_capacity == max_capacity)
157 cpu_capacity[0].hwid = (
unsigned long)(-1);
158 else if (4*max_capacity < (3*(max_capacity + min_capacity)))
159 middle_capacity = (min_capacity + max_capacity)
162 middle_capacity = ((max_capacity / 3)
172 void update_cpu_power(
unsigned int cpu,
unsigned long hwid)
174 unsigned int idx = 0;
178 if (cpu_capacity[idx].hwid == hwid)
181 if (cpu_capacity[idx].hwid == -1)
188 set_power_scale(cpu, cpu_capacity[idx].capacity / middle_capacity);
195 static inline void parse_dt_topology(
void) {}
196 static inline void update_cpu_power(
unsigned int cpuid,
unsigned int mpidr) {}
204 #define MPIDR_SMP_BITMASK (0x3 << 30)
205 #define MPIDR_SMP_VALUE (0x2 << 30)
207 #define MPIDR_MT_BITMASK (0x1 << 24)
213 #define MPIDR_HWID_BITMASK 0xFFFFFF
215 #define MPIDR_LEVEL0_MASK 0x3
216 #define MPIDR_LEVEL0_SHIFT 0
218 #define MPIDR_LEVEL1_MASK 0xF
219 #define MPIDR_LEVEL1_SHIFT 8
221 #define MPIDR_LEVEL2_MASK 0xFF
222 #define MPIDR_LEVEL2_SHIFT 16
243 if (cpuid_topo->socket_id != cpu_topo->socket_id)
246 cpumask_set_cpu(cpuid, &cpu_topo->core_sibling);
248 cpumask_set_cpu(cpu, &cpuid_topo->core_sibling);
250 if (cpuid_topo->core_id != cpu_topo->core_id)
253 cpumask_set_cpu(cpuid, &cpu_topo->thread_sibling);
255 cpumask_set_cpu(cpu, &cpuid_topo->thread_sibling);
271 if (cpuid_topo->core_id != -1)
274 mpidr = read_cpuid_mpidr();
293 cpuid_topo->thread_id = -1;
305 cpuid_topo->thread_id = -1;
306 cpuid_topo->core_id = 0;
307 cpuid_topo->socket_id = -1;
332 cpu_topo->thread_id = -1;
333 cpu_topo->core_id = -1;
334 cpu_topo->socket_id = -1;
335 cpumask_clear(&cpu_topo->core_sibling);
336 cpumask_clear(&cpu_topo->thread_sibling);