Commit 07f8e5f3 authored by David S. Miller's avatar David S. Miller

[SPARC64]: Convert cpu_find_by_*() interface to in-kernel PROM device tree.

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6d307724
...@@ -133,38 +133,44 @@ static const char *cpu_mid_prop(void) ...@@ -133,38 +133,44 @@ static const char *cpu_mid_prop(void)
return "portid"; return "portid";
} }
static int get_cpu_mid(int prom_node) static int get_cpu_mid(struct device_node *dp)
{ {
struct property *prop;
if (tlb_type == hypervisor) { if (tlb_type == hypervisor) {
struct linux_prom64_registers reg; struct linux_prom64_registers *reg;
int len;
if (prom_getproplen(prom_node, "cpuid") == 4) prop = of_find_property(dp, "cpuid", &len);
return prom_getintdefault(prom_node, "cpuid", 0); if (prop && len == 4)
return *(int *) prop->value;
prom_getproperty(prom_node, "reg", (char *) &reg, sizeof(reg)); prop = of_find_property(dp, "reg", NULL);
return (reg.phys_addr >> 32) & 0x0fffffffUL; reg = prop->value;
return (reg[0].phys_addr >> 32) & 0x0fffffffUL;
} else { } else {
const char *prop_name = cpu_mid_prop(); const char *prop_name = cpu_mid_prop();
return prom_getintdefault(prom_node, prop_name, 0); prop = of_find_property(dp, prop_name, NULL);
if (prop)
return *(int *) prop->value;
return 0;
} }
} }
static int check_cpu_node(int nd, int *cur_inst, static int check_cpu_node(struct device_node *dp, int *cur_inst,
int (*compare)(int, int, void *), void *compare_arg, int (*compare)(struct device_node *, int, void *),
int *prom_node, int *mid) void *compare_arg,
struct device_node **dev_node, int *mid)
{ {
char node_str[128]; if (strcmp(dp->type, "cpu"))
prom_getstring(nd, "device_type", node_str, sizeof(node_str));
if (strcmp(node_str, "cpu"))
return -ENODEV; return -ENODEV;
if (!compare(nd, *cur_inst, compare_arg)) { if (!compare(dp, *cur_inst, compare_arg)) {
if (prom_node) if (dev_node)
*prom_node = nd; *dev_node = dp;
if (mid) if (mid)
*mid = get_cpu_mid(nd); *mid = get_cpu_mid(dp);
return 0; return 0;
} }
...@@ -173,25 +179,18 @@ static int check_cpu_node(int nd, int *cur_inst, ...@@ -173,25 +179,18 @@ static int check_cpu_node(int nd, int *cur_inst,
return -ENODEV; return -ENODEV;
} }
static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg, static int __cpu_find_by(int (*compare)(struct device_node *, int, void *),
int *prom_node, int *mid) void *compare_arg,
struct device_node **dev_node, int *mid)
{ {
int nd, cur_inst, err; struct device_node *dp;
int cur_inst;
nd = prom_root_node;
cur_inst = 0; cur_inst = 0;
for_each_node_by_type(dp, "cpu") {
err = check_cpu_node(nd, &cur_inst, int err = check_cpu_node(dp, &cur_inst,
compare, compare_arg, compare, compare_arg,
prom_node, mid); dev_node, mid);
if (err == 0)
return 0;
nd = prom_getchild(nd);
while ((nd = prom_getsibling(nd)) != 0) {
err = check_cpu_node(nd, &cur_inst,
compare, compare_arg,
prom_node, mid);
if (err == 0) if (err == 0)
return 0; return 0;
} }
...@@ -199,7 +198,7 @@ static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg, ...@@ -199,7 +198,7 @@ static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
return -ENODEV; return -ENODEV;
} }
static int cpu_instance_compare(int nd, int instance, void *_arg) static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg)
{ {
int desired_instance = (int) (long) _arg; int desired_instance = (int) (long) _arg;
...@@ -208,27 +207,27 @@ static int cpu_instance_compare(int nd, int instance, void *_arg) ...@@ -208,27 +207,27 @@ static int cpu_instance_compare(int nd, int instance, void *_arg)
return -ENODEV; return -ENODEV;
} }
int cpu_find_by_instance(int instance, int *prom_node, int *mid) int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid)
{ {
return __cpu_find_by(cpu_instance_compare, (void *)(long)instance, return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
prom_node, mid); dev_node, mid);
} }
static int cpu_mid_compare(int nd, int instance, void *_arg) static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg)
{ {
int desired_mid = (int) (long) _arg; int desired_mid = (int) (long) _arg;
int this_mid; int this_mid;
this_mid = get_cpu_mid(nd); this_mid = get_cpu_mid(dp);
if (this_mid == desired_mid) if (this_mid == desired_mid)
return 0; return 0;
return -ENODEV; return -ENODEV;
} }
int cpu_find_by_mid(int mid, int *prom_node) int cpu_find_by_mid(int mid, struct device_node **dev_node)
{ {
return __cpu_find_by(cpu_mid_compare, (void *)(long)mid, return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
prom_node, NULL); dev_node, NULL);
} }
void __init device_scan(void) void __init device_scan(void)
...@@ -240,50 +239,47 @@ void __init device_scan(void) ...@@ -240,50 +239,47 @@ void __init device_scan(void)
#ifndef CONFIG_SMP #ifndef CONFIG_SMP
{ {
int err, cpu_node, def; struct device_node *dp;
int err, def;
err = cpu_find_by_instance(0, &cpu_node, NULL); err = cpu_find_by_instance(0, &dp, NULL);
if (err) { if (err) {
prom_printf("No cpu nodes, cannot continue\n"); prom_printf("No cpu nodes, cannot continue\n");
prom_halt(); prom_halt();
} }
cpu_data(0).clock_tick = prom_getintdefault(cpu_node, cpu_data(0).clock_tick =
"clock-frequency", of_getintprop_default(dp, "clock-frequency", 0);
0);
def = ((tlb_type == hypervisor) ? def = ((tlb_type == hypervisor) ?
(8 * 1024) : (8 * 1024) :
(16 * 1024)); (16 * 1024));
cpu_data(0).dcache_size = prom_getintdefault(cpu_node, cpu_data(0).dcache_size = of_getintprop_default(dp,
"dcache-size", "dcache-size",
def); def);
def = 32; def = 32;
cpu_data(0).dcache_line_size = cpu_data(0).dcache_line_size =
prom_getintdefault(cpu_node, "dcache-line-size", of_getintprop_default(dp, "dcache-line-size", def);
def);
def = 16 * 1024; def = 16 * 1024;
cpu_data(0).icache_size = prom_getintdefault(cpu_node, cpu_data(0).icache_size = of_getintprop_default(dp,
"icache-size", "icache-size",
def); def);
def = 32; def = 32;
cpu_data(0).icache_line_size = cpu_data(0).icache_line_size =
prom_getintdefault(cpu_node, "icache-line-size", of_getintprop_default(dp, "icache-line-size", def);
def);
def = ((tlb_type == hypervisor) ? def = ((tlb_type == hypervisor) ?
(3 * 1024 * 1024) : (3 * 1024 * 1024) :
(4 * 1024 * 1024)); (4 * 1024 * 1024));
cpu_data(0).ecache_size = prom_getintdefault(cpu_node, cpu_data(0).ecache_size = of_getintprop_default(dp,
"ecache-size", "ecache-size",
def); def);
def = 64; def = 64;
cpu_data(0).ecache_line_size = cpu_data(0).ecache_line_size =
prom_getintdefault(cpu_node, "ecache-line-size", of_getintprop_default(dp, "ecache-line-size", def);
def);
printk("CPU[0]: Caches " printk("CPU[0]: Caches "
"D[sz(%d):line_sz(%d)] " "D[sz(%d):line_sz(%d)] "
"I[sz(%d):line_sz(%d)] " "I[sz(%d):line_sz(%d)] "
......
...@@ -1455,16 +1455,13 @@ void sabre_init(struct device_node *dp, char *model_name) ...@@ -1455,16 +1455,13 @@ void sabre_init(struct device_node *dp, char *model_name)
hummingbird_p = 1; hummingbird_p = 1;
} }
if (!hummingbird_p) { if (!hummingbird_p) {
char compat[64]; struct device_node *dp;
int cpu_node;
/* Of course, Sun has to encode things a thousand /* Of course, Sun has to encode things a thousand
* different ways, inconsistently. * different ways, inconsistently.
*/ */
cpu_find_by_instance(0, &cpu_node, NULL); cpu_find_by_instance(0, &dp, NULL);
if (prom_getproperty(cpu_node, "name", if (!strcmp(dp->name, "SUNW,UltraSPARC-IIe"))
compat, sizeof(compat)) > 0 &&
!strcmp(compat, "SUNW,UltraSPARC-IIe"))
hummingbird_p = 1; hummingbird_p = 1;
} }
} }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <asm/starfire.h> #include <asm/starfire.h>
#include <asm/tlb.h> #include <asm/tlb.h>
#include <asm/sections.h> #include <asm/sections.h>
#include <asm/prom.h>
extern void calibrate_delay(void); extern void calibrate_delay(void);
...@@ -76,41 +77,42 @@ void smp_bogo(struct seq_file *m) ...@@ -76,41 +77,42 @@ void smp_bogo(struct seq_file *m)
void __init smp_store_cpu_info(int id) void __init smp_store_cpu_info(int id)
{ {
int cpu_node, def; struct device_node *dp;
int def;
/* multiplier and counter set by /* multiplier and counter set by
smp_setup_percpu_timer() */ smp_setup_percpu_timer() */
cpu_data(id).udelay_val = loops_per_jiffy; cpu_data(id).udelay_val = loops_per_jiffy;
cpu_find_by_mid(id, &cpu_node); cpu_find_by_mid(id, &dp);
cpu_data(id).clock_tick = prom_getintdefault(cpu_node, cpu_data(id).clock_tick =
"clock-frequency", 0); of_getintprop_default(dp, "clock-frequency", 0);
def = ((tlb_type == hypervisor) ? (8 * 1024) : (16 * 1024)); def = ((tlb_type == hypervisor) ? (8 * 1024) : (16 * 1024));
cpu_data(id).dcache_size = prom_getintdefault(cpu_node, "dcache-size", cpu_data(id).dcache_size =
def); of_getintprop_default(dp, "dcache-size", def);
def = 32; def = 32;
cpu_data(id).dcache_line_size = cpu_data(id).dcache_line_size =
prom_getintdefault(cpu_node, "dcache-line-size", def); of_getintprop_default(dp, "dcache-line-size", def);
def = 16 * 1024; def = 16 * 1024;
cpu_data(id).icache_size = prom_getintdefault(cpu_node, "icache-size", cpu_data(id).icache_size =
def); of_getintprop_default(dp, "icache-size", def);
def = 32; def = 32;
cpu_data(id).icache_line_size = cpu_data(id).icache_line_size =
prom_getintdefault(cpu_node, "icache-line-size", def); of_getintprop_default(dp, "icache-line-size", def);
def = ((tlb_type == hypervisor) ? def = ((tlb_type == hypervisor) ?
(3 * 1024 * 1024) : (3 * 1024 * 1024) :
(4 * 1024 * 1024)); (4 * 1024 * 1024));
cpu_data(id).ecache_size = prom_getintdefault(cpu_node, "ecache-size", cpu_data(id).ecache_size =
def); of_getintprop_default(dp, "ecache-size", def);
def = 64; def = 64;
cpu_data(id).ecache_line_size = cpu_data(id).ecache_line_size =
prom_getintdefault(cpu_node, "ecache-line-size", def); of_getintprop_default(dp, "ecache-line-size", def);
printk("CPU[%d]: Caches " printk("CPU[%d]: Caches "
"D[sz(%d):line_sz(%d)] " "D[sz(%d):line_sz(%d)] "
...@@ -342,10 +344,10 @@ static int __devinit smp_boot_one_cpu(unsigned int cpu) ...@@ -342,10 +344,10 @@ static int __devinit smp_boot_one_cpu(unsigned int cpu)
prom_startcpu_cpuid(cpu, entry, cookie); prom_startcpu_cpuid(cpu, entry, cookie);
} else { } else {
int cpu_node; struct device_node *dp;
cpu_find_by_mid(cpu, &cpu_node); cpu_find_by_mid(cpu, &dp);
prom_startcpu(cpu_node, entry, cookie); prom_startcpu(dp->node, entry, cookie);
} }
for (timeout = 0; timeout < 5000000; timeout++) { for (timeout = 0; timeout < 5000000; timeout++) {
...@@ -1289,7 +1291,8 @@ int setup_profiling_timer(unsigned int multiplier) ...@@ -1289,7 +1291,8 @@ int setup_profiling_timer(unsigned int multiplier)
static void __init smp_tune_scheduling(void) static void __init smp_tune_scheduling(void)
{ {
int instance, node; struct device_node *dp;
int instance;
unsigned int def, smallest = ~0U; unsigned int def, smallest = ~0U;
def = ((tlb_type == hypervisor) ? def = ((tlb_type == hypervisor) ?
...@@ -1297,10 +1300,10 @@ static void __init smp_tune_scheduling(void) ...@@ -1297,10 +1300,10 @@ static void __init smp_tune_scheduling(void)
(4 * 1024 * 1024)); (4 * 1024 * 1024));
instance = 0; instance = 0;
while (!cpu_find_by_instance(instance, &node, NULL)) { while (!cpu_find_by_instance(instance, &dp, NULL)) {
unsigned int val; unsigned int val;
val = prom_getintdefault(node, "ecache-size", def); val = of_getintprop_default(dp, "ecache-size", def);
if (val < smallest) if (val < smallest)
smallest = val; smallest = val;
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include <asm/sections.h> #include <asm/sections.h>
#include <asm/cpudata.h> #include <asm/cpudata.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/prom.h>
DEFINE_SPINLOCK(mostek_lock); DEFINE_SPINLOCK(mostek_lock);
DEFINE_SPINLOCK(rtc_lock); DEFINE_SPINLOCK(rtc_lock);
...@@ -983,12 +984,14 @@ void __init clock_probe(void) ...@@ -983,12 +984,14 @@ void __init clock_probe(void)
/* This is gets the master TICK_INT timer going. */ /* This is gets the master TICK_INT timer going. */
static unsigned long sparc64_init_timers(void) static unsigned long sparc64_init_timers(void)
{ {
struct device_node *dp;
struct property *prop;
unsigned long clock; unsigned long clock;
int node;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
extern void smp_tick_init(void); extern void smp_tick_init(void);
#endif #endif
dp = of_find_node_by_path("/");
if (tlb_type == spitfire) { if (tlb_type == spitfire) {
unsigned long ver, manuf, impl; unsigned long ver, manuf, impl;
...@@ -999,18 +1002,17 @@ static unsigned long sparc64_init_timers(void) ...@@ -999,18 +1002,17 @@ static unsigned long sparc64_init_timers(void)
if (manuf == 0x17 && impl == 0x13) { if (manuf == 0x17 && impl == 0x13) {
/* Hummingbird, aka Ultra-IIe */ /* Hummingbird, aka Ultra-IIe */
tick_ops = &hbtick_operations; tick_ops = &hbtick_operations;
node = prom_root_node; prop = of_find_property(dp, "stick-frequency", NULL);
clock = prom_getint(node, "stick-frequency");
} else { } else {
tick_ops = &tick_operations; tick_ops = &tick_operations;
cpu_find_by_instance(0, &node, NULL); cpu_find_by_instance(0, &dp, NULL);
clock = prom_getint(node, "clock-frequency"); prop = of_find_property(dp, "clock-frequency", NULL);
} }
} else { } else {
tick_ops = &stick_operations; tick_ops = &stick_operations;
node = prom_root_node; prop = of_find_property(dp, "stick-frequency", NULL);
clock = prom_getint(node, "stick-frequency");
} }
clock = *(unsigned int *) prop->value;
timer_tick_offset = clock / HZ; timer_tick_offset = clock / HZ;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#ifdef CONFIG_KMOD #ifdef CONFIG_KMOD
#include <linux/kmod.h> #include <linux/kmod.h>
#endif #endif
#include <asm/prom.h>
ATOMIC_NOTIFIER_HEAD(sparc64die_chain); ATOMIC_NOTIFIER_HEAD(sparc64die_chain);
...@@ -807,7 +808,8 @@ extern unsigned int cheetah_deferred_trap_vector[], cheetah_deferred_trap_vector ...@@ -807,7 +808,8 @@ extern unsigned int cheetah_deferred_trap_vector[], cheetah_deferred_trap_vector
void __init cheetah_ecache_flush_init(void) void __init cheetah_ecache_flush_init(void)
{ {
unsigned long largest_size, smallest_linesize, order, ver; unsigned long largest_size, smallest_linesize, order, ver;
int node, i, instance; struct device_node *dp;
int i, instance, sz;
/* Scan all cpu device tree nodes, note two values: /* Scan all cpu device tree nodes, note two values:
* 1) largest E-cache size * 1) largest E-cache size
...@@ -817,14 +819,14 @@ void __init cheetah_ecache_flush_init(void) ...@@ -817,14 +819,14 @@ void __init cheetah_ecache_flush_init(void)
smallest_linesize = ~0UL; smallest_linesize = ~0UL;
instance = 0; instance = 0;
while (!cpu_find_by_instance(instance, &node, NULL)) { while (!cpu_find_by_instance(instance, &dp, NULL)) {
unsigned long val; unsigned long val;
val = prom_getintdefault(node, "ecache-size", val = of_getintprop_default(dp, "ecache-size",
(2 * 1024 * 1024)); (2 * 1024 * 1024));
if (val > largest_size) if (val > largest_size)
largest_size = val; largest_size = val;
val = prom_getintdefault(node, "ecache-line-size", 64); val = of_getintprop_default(dp, "ecache-line-size", 64);
if (val < smallest_linesize) if (val < smallest_linesize)
smallest_linesize = val; smallest_linesize = val;
instance++; instance++;
...@@ -849,16 +851,16 @@ void __init cheetah_ecache_flush_init(void) ...@@ -849,16 +851,16 @@ void __init cheetah_ecache_flush_init(void)
} }
/* Now allocate error trap reporting scoreboard. */ /* Now allocate error trap reporting scoreboard. */
node = NR_CPUS * (2 * sizeof(struct cheetah_err_info)); sz = NR_CPUS * (2 * sizeof(struct cheetah_err_info));
for (order = 0; order < MAX_ORDER; order++) { for (order = 0; order < MAX_ORDER; order++) {
if ((PAGE_SIZE << order) >= node) if ((PAGE_SIZE << order) >= sz)
break; break;
} }
cheetah_error_log = (struct cheetah_err_info *) cheetah_error_log = (struct cheetah_err_info *)
__get_free_pages(GFP_KERNEL, order); __get_free_pages(GFP_KERNEL, order);
if (!cheetah_error_log) { if (!cheetah_error_log) {
prom_printf("cheetah_ecache_flush_init: Failed to allocate " prom_printf("cheetah_ecache_flush_init: Failed to allocate "
"error logging scoreboard (%d bytes).\n", node); "error logging scoreboard (%d bytes).\n", sz);
prom_halt(); prom_halt();
} }
memset(cheetah_error_log, 0, PAGE_SIZE << order); memset(cheetah_error_log, 0, PAGE_SIZE << order);
......
...@@ -323,8 +323,9 @@ extern int prom_pathtoinode(const char *path); ...@@ -323,8 +323,9 @@ extern int prom_pathtoinode(const char *path);
extern int prom_inst2pkg(int); extern int prom_inst2pkg(int);
/* CPU probing helpers. */ /* CPU probing helpers. */
int cpu_find_by_instance(int instance, int *prom_node, int *mid); struct device_node;
int cpu_find_by_mid(int mid, int *prom_node); int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid);
int cpu_find_by_mid(int mid, struct device_node **prom_node);
/* Client interface level routines. */ /* Client interface level routines. */
extern void prom_set_trap_table(unsigned long tba); extern void prom_set_trap_table(unsigned long tba);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment