2005-04-16 18:20:36 -04:00
|
|
|
/* devices.c: Initial scan of the prom device tree for important
|
|
|
|
* Sparc device nodes which we need to find.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/threads.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/errno.h>
|
2006-02-13 23:42:16 -05:00
|
|
|
#include <linux/bootmem.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/oplib.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/spitfire.h>
|
|
|
|
#include <asm/timer.h>
|
|
|
|
#include <asm/cpudata.h>
|
|
|
|
|
2007-05-11 16:52:08 -04:00
|
|
|
/* Used to synchronize accesses to NatSemi SUPER I/O chip configure
|
2005-04-16 18:20:36 -04:00
|
|
|
* operations in asm/ns87303.h
|
|
|
|
*/
|
|
|
|
DEFINE_SPINLOCK(ns87303_lock);
|
|
|
|
|
|
|
|
extern void cpu_probe(void);
|
|
|
|
extern void central_probe(void);
|
|
|
|
|
2006-02-09 23:46:22 -05:00
|
|
|
static const char *cpu_mid_prop(void)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
if (tlb_type == spitfire)
|
|
|
|
return "upa-portid";
|
|
|
|
return "portid";
|
|
|
|
}
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
static int get_cpu_mid(struct device_node *dp)
|
2006-02-09 23:46:22 -05:00
|
|
|
{
|
2006-06-22 02:34:02 -04:00
|
|
|
struct property *prop;
|
|
|
|
|
2006-02-09 23:46:22 -05:00
|
|
|
if (tlb_type == hypervisor) {
|
2006-06-22 02:34:02 -04:00
|
|
|
struct linux_prom64_registers *reg;
|
|
|
|
int len;
|
2006-02-09 23:46:22 -05:00
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
prop = of_find_property(dp, "cpuid", &len);
|
|
|
|
if (prop && len == 4)
|
|
|
|
return *(int *) prop->value;
|
2006-02-09 23:46:22 -05:00
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
prop = of_find_property(dp, "reg", NULL);
|
|
|
|
reg = prop->value;
|
|
|
|
return (reg[0].phys_addr >> 32) & 0x0fffffffUL;
|
2006-02-09 23:46:22 -05:00
|
|
|
} else {
|
|
|
|
const char *prop_name = cpu_mid_prop();
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
prop = of_find_property(dp, prop_name, NULL);
|
|
|
|
if (prop)
|
|
|
|
return *(int *) prop->value;
|
|
|
|
return 0;
|
2006-02-09 23:46:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
static int check_cpu_node(struct device_node *dp, int *cur_inst,
|
|
|
|
int (*compare)(struct device_node *, int, void *),
|
|
|
|
void *compare_arg,
|
|
|
|
struct device_node **dev_node, int *mid)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-06-22 02:34:02 -04:00
|
|
|
if (!compare(dp, *cur_inst, compare_arg)) {
|
|
|
|
if (dev_node)
|
|
|
|
*dev_node = dp;
|
2005-04-16 18:20:36 -04:00
|
|
|
if (mid)
|
2006-06-22 02:34:02 -04:00
|
|
|
*mid = get_cpu_mid(dp);
|
2005-04-16 18:20:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*cur_inst)++;
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
static int __cpu_find_by(int (*compare)(struct device_node *, int, void *),
|
|
|
|
void *compare_arg,
|
|
|
|
struct device_node **dev_node, int *mid)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-06-22 02:34:02 -04:00
|
|
|
struct device_node *dp;
|
|
|
|
int cur_inst;
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
cur_inst = 0;
|
2006-06-22 02:34:02 -04:00
|
|
|
for_each_node_by_type(dp, "cpu") {
|
|
|
|
int err = check_cpu_node(dp, &cur_inst,
|
|
|
|
compare, compare_arg,
|
|
|
|
dev_node, mid);
|
2005-04-16 18:20:36 -04:00
|
|
|
if (err == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
int desired_instance = (int) (long) _arg;
|
|
|
|
|
|
|
|
if (instance == desired_instance)
|
|
|
|
return 0;
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
|
2006-06-22 02:34:02 -04:00
|
|
|
dev_node, mid);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
int desired_mid = (int) (long) _arg;
|
|
|
|
int this_mid;
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
this_mid = get_cpu_mid(dp);
|
2005-04-16 18:20:36 -04:00
|
|
|
if (this_mid == desired_mid)
|
|
|
|
return 0;
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
int cpu_find_by_mid(int mid, struct device_node **dev_node)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
|
2006-06-22 02:34:02 -04:00
|
|
|
dev_node, NULL);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init device_scan(void)
|
|
|
|
{
|
|
|
|
/* FIX ME FAST... -DaveM */
|
|
|
|
ioport_resource.end = 0xffffffffffffffffUL;
|
|
|
|
|
|
|
|
prom_printf("Booting Linux...\n");
|
|
|
|
|
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
{
|
2006-06-22 02:34:02 -04:00
|
|
|
struct device_node *dp;
|
|
|
|
int err, def;
|
2006-02-15 03:35:50 -05:00
|
|
|
|
2006-06-22 02:34:02 -04:00
|
|
|
err = cpu_find_by_instance(0, &dp, NULL);
|
2005-04-16 18:20:36 -04:00
|
|
|
if (err) {
|
|
|
|
prom_printf("No cpu nodes, cannot continue\n");
|
|
|
|
prom_halt();
|
|
|
|
}
|
2006-06-22 02:34:02 -04:00
|
|
|
cpu_data(0).clock_tick =
|
|
|
|
of_getintprop_default(dp, "clock-frequency", 0);
|
2006-02-15 03:35:50 -05:00
|
|
|
|
|
|
|
def = ((tlb_type == hypervisor) ?
|
|
|
|
(8 * 1024) :
|
|
|
|
(16 * 1024));
|
2006-06-22 02:34:02 -04:00
|
|
|
cpu_data(0).dcache_size = of_getintprop_default(dp,
|
|
|
|
"dcache-size",
|
|
|
|
def);
|
2006-02-15 03:35:50 -05:00
|
|
|
|
|
|
|
def = 32;
|
2005-09-26 03:32:17 -04:00
|
|
|
cpu_data(0).dcache_line_size =
|
2006-06-22 02:34:02 -04:00
|
|
|
of_getintprop_default(dp, "dcache-line-size", def);
|
2006-02-15 03:35:50 -05:00
|
|
|
|
|
|
|
def = 16 * 1024;
|
2006-06-22 02:34:02 -04:00
|
|
|
cpu_data(0).icache_size = of_getintprop_default(dp,
|
|
|
|
"icache-size",
|
|
|
|
def);
|
2006-02-15 03:35:50 -05:00
|
|
|
|
|
|
|
def = 32;
|
2005-09-26 03:32:17 -04:00
|
|
|
cpu_data(0).icache_line_size =
|
2006-06-22 02:34:02 -04:00
|
|
|
of_getintprop_default(dp, "icache-line-size", def);
|
2006-02-15 03:35:50 -05:00
|
|
|
|
|
|
|
def = ((tlb_type == hypervisor) ?
|
|
|
|
(3 * 1024 * 1024) :
|
|
|
|
(4 * 1024 * 1024));
|
2006-06-22 02:34:02 -04:00
|
|
|
cpu_data(0).ecache_size = of_getintprop_default(dp,
|
|
|
|
"ecache-size",
|
|
|
|
def);
|
2006-02-15 03:35:50 -05:00
|
|
|
|
|
|
|
def = 64;
|
2005-09-26 03:32:17 -04:00
|
|
|
cpu_data(0).ecache_line_size =
|
2006-06-22 02:34:02 -04:00
|
|
|
of_getintprop_default(dp, "ecache-line-size", def);
|
2005-09-26 03:32:17 -04:00
|
|
|
printk("CPU[0]: Caches "
|
|
|
|
"D[sz(%d):line_sz(%d)] "
|
|
|
|
"I[sz(%d):line_sz(%d)] "
|
|
|
|
"E[sz(%d):line_sz(%d)]\n",
|
|
|
|
cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
|
|
|
|
cpu_data(0).icache_size, cpu_data(0).icache_line_size,
|
|
|
|
cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
central_probe();
|
|
|
|
|
|
|
|
cpu_probe();
|
|
|
|
}
|