1 /* devices.c: Initial scan of the prom device tree for important
2 * Sparc device nodes which we need to find.
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/threads.h>
10 #include <linux/init.h>
11 #include <linux/ioport.h>
12 #include <linux/string.h>
13 #include <linux/spinlock.h>
14 #include <linux/errno.h>
15 #include <linux/bootmem.h>
18 #include <asm/oplib.h>
19 #include <asm/system.h>
21 #include <asm/spitfire.h>
22 #include <asm/timer.h>
23 #include <asm/cpudata.h>
25 /* Used to synchronize acceses to NatSemi SUPER I/O chip configure
26 * operations in asm/ns87303.h
28 DEFINE_SPINLOCK(ns87303_lock);
30 extern void cpu_probe(void);
31 extern void central_probe(void);
33 static const char *cpu_mid_prop(void)
35 if (tlb_type == spitfire)
40 static int get_cpu_mid(struct device_node *dp)
42 struct property *prop;
44 if (tlb_type == hypervisor) {
45 struct linux_prom64_registers *reg;
48 prop = of_find_property(dp, "cpuid", &len);
50 return *(int *) prop->value;
52 prop = of_find_property(dp, "reg", NULL);
54 return (reg[0].phys_addr >> 32) & 0x0fffffffUL;
56 const char *prop_name = cpu_mid_prop();
58 prop = of_find_property(dp, prop_name, NULL);
60 return *(int *) prop->value;
65 static int check_cpu_node(struct device_node *dp, int *cur_inst,
66 int (*compare)(struct device_node *, int, void *),
68 struct device_node **dev_node, int *mid)
70 if (strcmp(dp->type, "cpu"))
73 if (!compare(dp, *cur_inst, compare_arg)) {
77 *mid = get_cpu_mid(dp);
86 static int __cpu_find_by(int (*compare)(struct device_node *, int, void *),
88 struct device_node **dev_node, int *mid)
90 struct device_node *dp;
94 for_each_node_by_type(dp, "cpu") {
95 int err = check_cpu_node(dp, &cur_inst,
105 static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg)
107 int desired_instance = (int) (long) _arg;
109 if (instance == desired_instance)
114 int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid)
116 return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
120 static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg)
122 int desired_mid = (int) (long) _arg;
125 this_mid = get_cpu_mid(dp);
126 if (this_mid == desired_mid)
131 int cpu_find_by_mid(int mid, struct device_node **dev_node)
133 return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
137 void __init device_scan(void)
139 /* FIX ME FAST... -DaveM */
140 ioport_resource.end = 0xffffffffffffffffUL;
142 prom_printf("Booting Linux...\n");
146 struct device_node *dp;
149 err = cpu_find_by_instance(0, &dp, NULL);
151 prom_printf("No cpu nodes, cannot continue\n");
154 cpu_data(0).clock_tick =
155 of_getintprop_default(dp, "clock-frequency", 0);
157 def = ((tlb_type == hypervisor) ?
160 cpu_data(0).dcache_size = of_getintprop_default(dp,
165 cpu_data(0).dcache_line_size =
166 of_getintprop_default(dp, "dcache-line-size", def);
169 cpu_data(0).icache_size = of_getintprop_default(dp,
174 cpu_data(0).icache_line_size =
175 of_getintprop_default(dp, "icache-line-size", def);
177 def = ((tlb_type == hypervisor) ?
180 cpu_data(0).ecache_size = of_getintprop_default(dp,
185 cpu_data(0).ecache_line_size =
186 of_getintprop_default(dp, "ecache-line-size", def);
187 printk("CPU[0]: Caches "
188 "D[sz(%d):line_sz(%d)] "
189 "I[sz(%d):line_sz(%d)] "
190 "E[sz(%d):line_sz(%d)]\n",
191 cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
192 cpu_data(0).icache_size, cpu_data(0).icache_line_size,
193 cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);