Skip to content

Commit

Permalink
Merge branch 'cpu_of_node' of git://linux-arm.org/linux-skn into pm-c…
Browse files Browse the repository at this point in the history
…pufreq-next

Pull DT/core/cpufreq cpu_ofnode updates for v3.12 from Sudeep KarkadaNagesha.

* 'cpu_of_node' of git://linux-arm.org/linux-skn:
  cpufreq: pmac32-cpufreq: remove device tree parsing for cpu nodes
  cpufreq: pmac64-cpufreq: remove device tree parsing for cpu nodes
  cpufreq: maple-cpufreq: remove device tree parsing for cpu nodes
  cpufreq: arm_big_little: remove device tree parsing for cpu nodes
  cpufreq: kirkwood-cpufreq: remove device tree parsing for cpu nodes
  cpufreq: spear-cpufreq: remove device tree parsing for cpu nodes
  cpufreq: highbank-cpufreq: remove device tree parsing for cpu nodes
  cpufreq: cpufreq-cpu0: remove device tree parsing for cpu nodes
  cpufreq: imx6q-cpufreq: remove device tree parsing for cpu nodes
  drivers/bus: arm-cci: avoid parsing DT for cpu device nodes
  ARM: mvebu: remove device tree parsing for cpu nodes
  ARM: topology: remove hwid/MPIDR dependency from cpu_capacity
  of/device: add helper to get cpu device node from logical cpu index
  driver/core: cpu: initialize of_node in cpu's device struture
  ARM: DT/kernel: define ARM specific arch_match_cpu_phys_id
  of: move of_get_cpu_node implementation to DT core library
  powerpc: refactor of_get_cpu_node to support other architectures
  openrisc: remove undefined of_get_cpu_node declaration
  microblaze: remove undefined of_get_cpu_node declaration
  • Loading branch information
Rafael J. Wysocki committed Aug 22, 2013
2 parents 4eb5178 + 1037b27 commit 09198f8
Show file tree
Hide file tree
Showing 23 changed files with 226 additions and 266 deletions.
5 changes: 5 additions & 0 deletions arch/arm/kernel/devtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ void __init arm_dt_init_cpu_maps(void)
}
}

bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
{
return (phys_id & MPIDR_HWID_BITMASK) == cpu_logical_map(cpu);
}

/**
* setup_machine_fdt - Machine setup when an dtb was passed to the kernel
* @dt_phys: physical address of dt blob
Expand Down
61 changes: 19 additions & 42 deletions arch/arm/kernel/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ struct cpu_efficiency table_efficiency[] = {
{NULL, },
};

struct cpu_capacity {
unsigned long hwid;
unsigned long capacity;
};

struct cpu_capacity *cpu_capacity;
unsigned long *__cpu_capacity;
#define cpu_capacity(cpu) __cpu_capacity[cpu]

unsigned long middle_capacity = 1;

Expand All @@ -100,15 +96,19 @@ static void __init parse_dt_topology(void)
unsigned long capacity = 0;
int alloc_size, cpu = 0;

alloc_size = nr_cpu_ids * sizeof(struct cpu_capacity);
cpu_capacity = kzalloc(alloc_size, GFP_NOWAIT);
alloc_size = nr_cpu_ids * sizeof(*__cpu_capacity);
__cpu_capacity = kzalloc(alloc_size, GFP_NOWAIT);

while ((cn = of_find_node_by_type(cn, "cpu"))) {
const u32 *rate, *reg;
for_each_possible_cpu(cpu) {
const u32 *rate;
int len;

if (cpu >= num_possible_cpus())
break;
/* too early to use cpu->of_node */
cn = of_get_cpu_node(cpu, NULL);
if (!cn) {
pr_err("missing device node for CPU %d\n", cpu);
continue;
}

for (cpu_eff = table_efficiency; cpu_eff->compatible; cpu_eff++)
if (of_device_is_compatible(cn, cpu_eff->compatible))
Expand All @@ -124,12 +124,6 @@ static void __init parse_dt_topology(void)
continue;
}

reg = of_get_property(cn, "reg", &len);
if (!reg || len != 4) {
pr_err("%s missing reg property\n", cn->full_name);
continue;
}

capacity = ((be32_to_cpup(rate)) >> 20) * cpu_eff->efficiency;

/* Save min capacity of the system */
Expand All @@ -140,23 +134,17 @@ static void __init parse_dt_topology(void)
if (capacity > max_capacity)
max_capacity = capacity;

cpu_capacity[cpu].capacity = capacity;
cpu_capacity[cpu++].hwid = be32_to_cpup(reg);
cpu_capacity(cpu) = capacity;
}

if (cpu < num_possible_cpus())
cpu_capacity[cpu].hwid = (unsigned long)(-1);

/* If min and max capacities are equals, we bypass the update of the
* cpu_scale because all CPUs have the same capacity. Otherwise, we
* compute a middle_capacity factor that will ensure that the capacity
* of an 'average' CPU of the system will be as close as possible to
* SCHED_POWER_SCALE, which is the default value, but with the
* constraint explained near table_efficiency[].
*/
if (min_capacity == max_capacity)
cpu_capacity[0].hwid = (unsigned long)(-1);
else if (4*max_capacity < (3*(max_capacity + min_capacity)))
if (4*max_capacity < (3*(max_capacity + min_capacity)))
middle_capacity = (min_capacity + max_capacity)
>> (SCHED_POWER_SHIFT+1);
else
Expand All @@ -170,31 +158,20 @@ static void __init parse_dt_topology(void)
* boot. The update of all CPUs is in O(n^2) for heteregeneous system but the
* function returns directly for SMP system.
*/
void update_cpu_power(unsigned int cpu, unsigned long hwid)
void update_cpu_power(unsigned int cpu)
{
unsigned int idx = 0;

/* look for the cpu's hwid in the cpu capacity table */
for (idx = 0; idx < num_possible_cpus(); idx++) {
if (cpu_capacity[idx].hwid == hwid)
break;

if (cpu_capacity[idx].hwid == -1)
return;
}

if (idx == num_possible_cpus())
if (!cpu_capacity(cpu))
return;

set_power_scale(cpu, cpu_capacity[idx].capacity / middle_capacity);
set_power_scale(cpu, cpu_capacity(cpu) / middle_capacity);

printk(KERN_INFO "CPU%u: update cpu_power %lu\n",
cpu, arch_scale_freq_power(NULL, cpu));
}

#else
static inline void parse_dt_topology(void) {}
static inline void update_cpu_power(unsigned int cpuid, unsigned int mpidr) {}
static inline void update_cpu_power(unsigned int cpuid) {}
#endif

/*
Expand Down Expand Up @@ -281,7 +258,7 @@ void store_cpu_topology(unsigned int cpuid)

update_siblings_masks(cpuid);

update_cpu_power(cpuid, mpidr & MPIDR_HWID_BITMASK);
update_cpu_power(cpuid);

printk(KERN_INFO "CPU%u: thread %d, cpu %d, socket %d, mpidr %x\n",
cpuid, cpu_topology[cpuid].thread_id,
Expand Down
3 changes: 1 addition & 2 deletions arch/arm/mach-imx/mach-imx6q.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,12 @@ static void __init imx6q_opp_init(struct device *cpu_dev)
{
struct device_node *np;

np = of_find_node_by_path("/cpus/cpu@0");
np = of_node_get(cpu_dev->of_node);
if (!np) {
pr_warn("failed to find cpu0 node\n");
return;
}

cpu_dev->of_node = np;
if (of_init_opp_table(cpu_dev)) {
pr_warn("failed to init OPP table\n");
goto put_node;
Expand Down
51 changes: 23 additions & 28 deletions arch/arm/mach-mvebu/platsmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,40 @@
#include "pmsu.h"
#include "coherency.h"

static struct clk *__init get_cpu_clk(int cpu)
{
struct clk *cpu_clk;
struct device_node *np = of_get_cpu_node(cpu, NULL);

if (WARN(!np, "missing cpu node\n"))
return NULL;
cpu_clk = of_clk_get(np, 0);
if (WARN_ON(IS_ERR(cpu_clk)))
return NULL;
return cpu_clk;
}

void __init set_secondary_cpus_clock(void)
{
int thiscpu;
int thiscpu, cpu;
unsigned long rate;
struct clk *cpu_clk = NULL;
struct device_node *np = NULL;
struct clk *cpu_clk;

thiscpu = smp_processor_id();
for_each_node_by_type(np, "cpu") {
int err;
int cpu;

err = of_property_read_u32(np, "reg", &cpu);
if (WARN_ON(err))
return;

if (cpu == thiscpu) {
cpu_clk = of_clk_get(np, 0);
break;
}
}
if (WARN_ON(IS_ERR(cpu_clk)))
cpu_clk = get_cpu_clk(thiscpu);
if (!cpu_clk)
return;
clk_prepare_enable(cpu_clk);
rate = clk_get_rate(cpu_clk);

/* set all the other CPU clk to the same rate than the boot CPU */
for_each_node_by_type(np, "cpu") {
int err;
int cpu;

err = of_property_read_u32(np, "reg", &cpu);
if (WARN_ON(err))
for_each_possible_cpu(cpu) {
if (cpu == thiscpu)
continue;
cpu_clk = get_cpu_clk(cpu);
if (!cpu_clk)
return;

if (cpu != thiscpu) {
cpu_clk = of_clk_get(np, 0);
clk_set_rate(cpu_clk, rate);
}
clk_set_rate(cpu_clk, rate);
}
}

Expand Down
3 changes: 0 additions & 3 deletions arch/microblaze/include/asm/prom.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,

extern void kdump_move_device_tree(void);

/* CPU OF node matching */
struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);

#endif /* __ASSEMBLY__ */
#endif /* __KERNEL__ */

Expand Down
3 changes: 0 additions & 3 deletions arch/openrisc/include/asm/prom.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,

extern void kdump_move_device_tree(void);

/* CPU OF node matching */
struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);

/* Get the MAC address */
extern const void *of_get_mac_address(struct device_node *np);

Expand Down
3 changes: 0 additions & 3 deletions arch/powerpc/include/asm/prom.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,

extern void kdump_move_device_tree(void);

/* CPU OF node matching */
struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);

/* cache lookup */
struct device_node *of_find_next_cache_node(struct device_node *np);

Expand Down
43 changes: 2 additions & 41 deletions arch/powerpc/kernel/prom.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,49 +865,10 @@ static int __init prom_reconfig_setup(void)
__initcall(prom_reconfig_setup);
#endif

/* Find the device node for a given logical cpu number, also returns the cpu
* local thread number (index in ibm,interrupt-server#s) if relevant and
* asked for (non NULL)
*/
struct device_node *of_get_cpu_node(int cpu, unsigned int *thread)
bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
{
int hardid;
struct device_node *np;

hardid = get_hard_smp_processor_id(cpu);

for_each_node_by_type(np, "cpu") {
const u32 *intserv;
unsigned int plen, t;

/* Check for ibm,ppc-interrupt-server#s. If it doesn't exist
* fallback to "reg" property and assume no threads
*/
intserv = of_get_property(np, "ibm,ppc-interrupt-server#s",
&plen);
if (intserv == NULL) {
const u32 *reg = of_get_property(np, "reg", NULL);
if (reg == NULL)
continue;
if (*reg == hardid) {
if (thread)
*thread = 0;
return np;
}
} else {
plen /= sizeof(u32);
for (t = 0; t < plen; t++) {
if (hardid == intserv[t]) {
if (thread)
*thread = t;
return np;
}
}
}
}
return NULL;
return (int)phys_id == get_hard_smp_processor_id(cpu);
}
EXPORT_SYMBOL(of_get_cpu_node);

#if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
static struct debugfs_blob_wrapper flat_dt_blob;
Expand Down
2 changes: 2 additions & 0 deletions drivers/base/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/slab.h>
#include <linux/percpu.h>
#include <linux/acpi.h>
#include <linux/of.h>

#include "base.h"

Expand Down Expand Up @@ -289,6 +290,7 @@ int register_cpu(struct cpu *cpu, int num)
cpu->dev.release = cpu_device_release;
cpu->dev.offline_disabled = !cpu->hotpluggable;
cpu->dev.offline = !cpu_online(num);
cpu->dev.of_node = of_get_cpu_node(num, NULL);
#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
cpu->dev.bus->uevent = arch_cpu_uevent;
#endif
Expand Down
28 changes: 7 additions & 21 deletions drivers/bus/arm-cci.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,8 @@ EXPORT_SYMBOL_GPL(cci_ace_get_port);

static void __init cci_ace_init_ports(void)
{
int port, ac, cpu;
u64 hwid;
const u32 *cell;
struct device_node *cpun, *cpus;

cpus = of_find_node_by_path("/cpus");
if (WARN(!cpus, "Missing cpus node, bailing out\n"))
return;

if (WARN_ON(of_property_read_u32(cpus, "#address-cells", &ac)))
ac = of_n_addr_cells(cpus);
int port, cpu;
struct device_node *cpun;

/*
* Port index look-up speeds up the function disabling ports by CPU,
Expand All @@ -141,18 +132,13 @@ static void __init cci_ace_init_ports(void)
* The stashed index array is initialized for all possible CPUs
* at probe time.
*/
for_each_child_of_node(cpus, cpun) {
if (of_node_cmp(cpun->type, "cpu"))
continue;
cell = of_get_property(cpun, "reg", NULL);
if (WARN(!cell, "%s: missing reg property\n", cpun->full_name))
continue;

hwid = of_read_number(cell, ac);
cpu = get_logical_index(hwid & MPIDR_HWID_BITMASK);
for_each_possible_cpu(cpu) {
/* too early to use cpu->of_node */
cpun = of_get_cpu_node(cpu, NULL);

if (cpu < 0 || !cpu_possible(cpu))
if (WARN(!cpun, "Missing cpu device node\n"))
continue;

port = __cci_ace_get_port(cpun, ACE_PORT);
if (port < 0)
continue;
Expand Down
Loading

0 comments on commit 09198f8

Please sign in to comment.