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>
26 /* Used to synchronize acceses to NatSemi SUPER I/O chip configure
27 * operations in asm/ns87303.h
29 DEFINE_SPINLOCK(ns87303_lock);
31 extern void cpu_probe(void);
32 extern void central_probe(void);
34 u32 sun4v_vdev_devhandle;
36 struct linux_prom_pci_intmap *sun4v_vdev_intmap;
37 int sun4v_vdev_num_intmap;
38 struct linux_prom_pci_intmap sun4v_vdev_intmask;
40 static void __init sun4v_virtual_device_probe(void)
42 struct linux_prom64_registers regs;
43 struct linux_prom_pci_intmap *ip;
46 if (tlb_type != hypervisor)
49 node = prom_getchild(prom_root_node);
50 node = prom_searchsiblings(node, "virtual-devices");
52 prom_printf("SUN4V: Fatal error, no virtual-devices node.\n");
56 sun4v_vdev_root = node;
58 prom_getproperty(node, "reg", (char *)®s, sizeof(regs));
59 sun4v_vdev_devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff;
61 sz = sizeof(*ip) * 64;
62 sun4v_vdev_intmap = ip = alloc_bootmem_low_pages(sz);
63 if (!sun4v_vdev_intmap) {
64 prom_printf("SUN4V: Error, cannot allocate vdev intmap.\n");
68 err = prom_getproperty(node, "interrupt-map", (char *) ip, sz);
70 prom_printf("SUN4V: Fatal error, no vdev interrupt-map.\n");
74 sun4v_vdev_num_intmap = err / sizeof(*ip);
76 err = prom_getproperty(node, "interrupt-map-mask",
77 (char *) &sun4v_vdev_intmask,
78 sizeof(sun4v_vdev_intmask));
80 prom_printf("SUN4V: Fatal error, no vdev "
81 "interrupt-map-mask.\n");
85 printk("SUN4V: virtual-devices devhandle[%x]\n",
86 sun4v_vdev_devhandle);
89 static const char *cpu_mid_prop(void)
91 if (tlb_type == spitfire)
96 static int get_cpu_mid(int prom_node)
98 if (tlb_type == hypervisor) {
99 struct linux_prom64_registers reg;
101 if (prom_getproplen(prom_node, "cpuid") == 4)
102 return prom_getintdefault(prom_node, "cpuid", 0);
104 prom_getproperty(prom_node, "reg", (char *) ®, sizeof(reg));
105 return (reg.phys_addr >> 32) & 0x0fffffffUL;
107 const char *prop_name = cpu_mid_prop();
109 return prom_getintdefault(prom_node, prop_name, 0);
113 static int check_cpu_node(int nd, int *cur_inst,
114 int (*compare)(int, int, void *), void *compare_arg,
115 int *prom_node, int *mid)
119 prom_getstring(nd, "device_type", node_str, sizeof(node_str));
120 if (strcmp(node_str, "cpu"))
123 if (!compare(nd, *cur_inst, compare_arg)) {
127 *mid = get_cpu_mid(nd);
136 static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
137 int *prom_node, int *mid)
139 int nd, cur_inst, err;
144 err = check_cpu_node(nd, &cur_inst,
145 compare, compare_arg,
150 nd = prom_getchild(nd);
151 while ((nd = prom_getsibling(nd)) != 0) {
152 err = check_cpu_node(nd, &cur_inst,
153 compare, compare_arg,
162 static int cpu_instance_compare(int nd, int instance, void *_arg)
164 int desired_instance = (int) (long) _arg;
166 if (instance == desired_instance)
171 int cpu_find_by_instance(int instance, int *prom_node, int *mid)
173 return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
177 static int cpu_mid_compare(int nd, int instance, void *_arg)
179 int desired_mid = (int) (long) _arg;
182 this_mid = get_cpu_mid(nd);
183 if (this_mid == desired_mid)
188 int cpu_find_by_mid(int mid, int *prom_node)
190 return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
194 void __init device_scan(void)
196 /* FIX ME FAST... -DaveM */
197 ioport_resource.end = 0xffffffffffffffffUL;
199 prom_printf("Booting Linux...\n");
203 int err, cpu_node, def;
205 err = cpu_find_by_instance(0, &cpu_node, NULL);
207 prom_printf("No cpu nodes, cannot continue\n");
210 cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
214 def = ((tlb_type == hypervisor) ?
217 cpu_data(0).dcache_size = prom_getintdefault(cpu_node,
222 cpu_data(0).dcache_line_size =
223 prom_getintdefault(cpu_node, "dcache-line-size",
227 cpu_data(0).icache_size = prom_getintdefault(cpu_node,
232 cpu_data(0).icache_line_size =
233 prom_getintdefault(cpu_node, "icache-line-size",
236 def = ((tlb_type == hypervisor) ?
239 cpu_data(0).ecache_size = prom_getintdefault(cpu_node,
244 cpu_data(0).ecache_line_size =
245 prom_getintdefault(cpu_node, "ecache-line-size",
247 printk("CPU[0]: Caches "
248 "D[sz(%d):line_sz(%d)] "
249 "I[sz(%d):line_sz(%d)] "
250 "E[sz(%d):line_sz(%d)]\n",
251 cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
252 cpu_data(0).icache_size, cpu_data(0).icache_line_size,
253 cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
257 sun4v_virtual_device_probe();