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>
27 /* Used to synchronize acceses to NatSemi SUPER I/O chip configure
28 * operations in asm/ns87303.h
30 DEFINE_SPINLOCK(ns87303_lock);
32 extern void cpu_probe(void);
33 extern void central_probe(void);
35 u32 sun4v_vdev_devhandle;
42 unsigned int cinterrupt;
47 unsigned int interrupt;
48 unsigned int __unused;
51 static struct vdev_intmap *vdev_intmap;
52 static int vdev_num_intmap;
53 static struct vdev_intmask vdev_intmask;
55 static void __init sun4v_virtual_device_probe(void)
57 struct linux_prom64_registers regs;
58 struct vdev_intmap *ip;
61 if (tlb_type != hypervisor)
64 node = prom_getchild(prom_root_node);
65 node = prom_searchsiblings(node, "virtual-devices");
67 prom_printf("SUN4V: Fatal error, no virtual-devices node.\n");
71 sun4v_vdev_root = node;
73 prom_getproperty(node, "reg", (char *)®s, sizeof(regs));
74 sun4v_vdev_devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff;
76 sz = prom_getproplen(node, "interrupt-map");
78 prom_printf("SUN4V: Error, no vdev interrupt-map.\n");
82 if ((sz % sizeof(*ip)) != 0) {
83 prom_printf("SUN4V: Bogus interrupt-map property size %d\n",
88 vdev_intmap = ip = alloc_bootmem_low_pages(sz);
90 prom_printf("SUN4V: Error, cannot allocate vdev_intmap.\n");
94 err = prom_getproperty(node, "interrupt-map", (char *) ip, sz);
96 prom_printf("SUN4V: Fatal error, no vdev interrupt-map.\n");
100 prom_printf("SUN4V: Inconsistent interrupt-map size, "
101 "proplen(%d) vs getprop(%d).\n", sz,err);
105 vdev_num_intmap = err / sizeof(*ip);
107 err = prom_getproperty(node, "interrupt-map-mask",
108 (char *) &vdev_intmask,
109 sizeof(vdev_intmask));
111 prom_printf("SUN4V: Fatal error, no vdev "
112 "interrupt-map-mask.\n");
115 if (err % sizeof(vdev_intmask)) {
116 prom_printf("SUN4V: Bogus interrupt-map-mask "
117 "property size %d\n", err);
121 printk("SUN4V: virtual-devices devhandle[%x]\n",
122 sun4v_vdev_devhandle);
125 unsigned int sun4v_vdev_device_interrupt(unsigned int dev_node)
127 unsigned int irq, reg;
130 err = prom_getproperty(dev_node, "interrupts",
131 (char *) &irq, sizeof(irq));
133 printk("VDEV: Cannot get \"interrupts\" "
134 "property for OBP node %x\n", dev_node);
138 err = prom_getproperty(dev_node, "reg",
139 (char *) ®, sizeof(reg));
141 printk("VDEV: Cannot get \"reg\" "
142 "property for OBP node %x\n", dev_node);
146 for (i = 0; i < vdev_num_intmap; i++) {
147 if (vdev_intmap[i].phys == (reg & vdev_intmask.phys) &&
148 vdev_intmap[i].irq == (irq & vdev_intmask.interrupt)) {
149 irq = vdev_intmap[i].cinterrupt;
154 if (i == vdev_num_intmap) {
155 printk("VDEV: No matching interrupt map entry "
156 "for OBP node %x\n", dev_node);
160 return sun4v_build_irq(sun4v_vdev_devhandle, irq, 5, 0);
163 static const char *cpu_mid_prop(void)
165 if (tlb_type == spitfire)
170 static int get_cpu_mid(int prom_node)
172 if (tlb_type == hypervisor) {
173 struct linux_prom64_registers reg;
175 if (prom_getproplen(prom_node, "cpuid") == 4)
176 return prom_getintdefault(prom_node, "cpuid", 0);
178 prom_getproperty(prom_node, "reg", (char *) ®, sizeof(reg));
179 return (reg.phys_addr >> 32) & 0x0fffffffUL;
181 const char *prop_name = cpu_mid_prop();
183 return prom_getintdefault(prom_node, prop_name, 0);
187 static int check_cpu_node(int nd, int *cur_inst,
188 int (*compare)(int, int, void *), void *compare_arg,
189 int *prom_node, int *mid)
193 prom_getstring(nd, "device_type", node_str, sizeof(node_str));
194 if (strcmp(node_str, "cpu"))
197 if (!compare(nd, *cur_inst, compare_arg)) {
201 *mid = get_cpu_mid(nd);
210 static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
211 int *prom_node, int *mid)
213 int nd, cur_inst, err;
218 err = check_cpu_node(nd, &cur_inst,
219 compare, compare_arg,
224 nd = prom_getchild(nd);
225 while ((nd = prom_getsibling(nd)) != 0) {
226 err = check_cpu_node(nd, &cur_inst,
227 compare, compare_arg,
236 static int cpu_instance_compare(int nd, int instance, void *_arg)
238 int desired_instance = (int) (long) _arg;
240 if (instance == desired_instance)
245 int cpu_find_by_instance(int instance, int *prom_node, int *mid)
247 return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
251 static int cpu_mid_compare(int nd, int instance, void *_arg)
253 int desired_mid = (int) (long) _arg;
256 this_mid = get_cpu_mid(nd);
257 if (this_mid == desired_mid)
262 int cpu_find_by_mid(int mid, int *prom_node)
264 return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
268 void __init device_scan(void)
270 /* FIX ME FAST... -DaveM */
271 ioport_resource.end = 0xffffffffffffffffUL;
273 prom_printf("Booting Linux...\n");
277 int err, cpu_node, def;
279 err = cpu_find_by_instance(0, &cpu_node, NULL);
281 prom_printf("No cpu nodes, cannot continue\n");
284 cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
288 def = ((tlb_type == hypervisor) ?
291 cpu_data(0).dcache_size = prom_getintdefault(cpu_node,
296 cpu_data(0).dcache_line_size =
297 prom_getintdefault(cpu_node, "dcache-line-size",
301 cpu_data(0).icache_size = prom_getintdefault(cpu_node,
306 cpu_data(0).icache_line_size =
307 prom_getintdefault(cpu_node, "icache-line-size",
310 def = ((tlb_type == hypervisor) ?
313 cpu_data(0).ecache_size = prom_getintdefault(cpu_node,
318 cpu_data(0).ecache_line_size =
319 prom_getintdefault(cpu_node, "ecache-line-size",
321 printk("CPU[0]: Caches "
322 "D[sz(%d):line_sz(%d)] "
323 "I[sz(%d):line_sz(%d)] "
324 "E[sz(%d):line_sz(%d)]\n",
325 cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
326 cpu_data(0).icache_size, cpu_data(0).icache_line_size,
327 cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
331 sun4v_virtual_device_probe();