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>
17 #include <asm/oplib.h>
18 #include <asm/system.h>
20 #include <asm/spitfire.h>
21 #include <asm/timer.h>
22 #include <asm/cpudata.h>
24 /* Used to synchronize acceses to NatSemi SUPER I/O chip configure
25 * operations in asm/ns87303.h
27 DEFINE_SPINLOCK(ns87303_lock);
29 extern void cpu_probe(void);
30 extern void central_probe(void);
32 static const char *cpu_mid_prop(void)
34 if (tlb_type == spitfire)
39 static int get_cpu_mid(int prom_node)
41 if (tlb_type == hypervisor) {
42 struct linux_prom64_registers reg;
44 if (prom_getproplen(prom_node, "cpuid") == 4)
45 return prom_getintdefault(prom_node, "cpuid", 0);
47 prom_getproperty(prom_node, "reg", (char *) ®, sizeof(reg));
48 return (reg.phys_addr >> 32) & 0x0fffffffUL;
50 const char *prop_name = cpu_mid_prop();
52 return prom_getintdefault(prom_node, prop_name, 0);
56 static int check_cpu_node(int nd, int *cur_inst,
57 int (*compare)(int, int, void *), void *compare_arg,
58 int *prom_node, int *mid)
62 prom_getstring(nd, "device_type", node_str, sizeof(node_str));
63 if (strcmp(node_str, "cpu"))
66 if (!compare(nd, *cur_inst, compare_arg)) {
70 *mid = get_cpu_mid(nd);
79 static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
80 int *prom_node, int *mid)
82 int nd, cur_inst, err;
87 err = check_cpu_node(nd, &cur_inst,
93 nd = prom_getchild(nd);
94 while ((nd = prom_getsibling(nd)) != 0) {
95 err = check_cpu_node(nd, &cur_inst,
105 static int cpu_instance_compare(int nd, int instance, void *_arg)
107 int desired_instance = (int) (long) _arg;
109 if (instance == desired_instance)
114 int cpu_find_by_instance(int instance, int *prom_node, int *mid)
116 return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
120 static int cpu_mid_compare(int nd, int instance, void *_arg)
122 int desired_mid = (int) (long) _arg;
125 this_mid = get_cpu_mid(nd);
126 if (this_mid == desired_mid)
131 int cpu_find_by_mid(int mid, int *prom_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");
147 err = cpu_find_by_instance(0, &cpu_node, NULL);
149 prom_printf("No cpu nodes, cannot continue\n");
152 cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
155 cpu_data(0).dcache_size = prom_getintdefault(cpu_node,
158 cpu_data(0).dcache_line_size =
159 prom_getintdefault(cpu_node, "dcache-line-size", 32);
160 cpu_data(0).icache_size = prom_getintdefault(cpu_node,
163 cpu_data(0).icache_line_size =
164 prom_getintdefault(cpu_node, "icache-line-size", 32);
165 cpu_data(0).ecache_size = prom_getintdefault(cpu_node,
168 cpu_data(0).ecache_line_size =
169 prom_getintdefault(cpu_node, "ecache-line-size", 64);
170 printk("CPU[0]: Caches "
171 "D[sz(%d):line_sz(%d)] "
172 "I[sz(%d):line_sz(%d)] "
173 "E[sz(%d):line_sz(%d)]\n",
174 cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
175 cpu_data(0).icache_size, cpu_data(0).icache_line_size,
176 cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);