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 char *cpu_mid_prop(void)
34 if (tlb_type == spitfire)
39 static int check_cpu_node(int nd, int *cur_inst,
40 int (*compare)(int, int, void *), void *compare_arg,
41 int *prom_node, int *mid)
45 prom_getstring(nd, "device_type", node_str, sizeof(node_str));
46 if (strcmp(node_str, "cpu"))
49 if (!compare(nd, *cur_inst, compare_arg)) {
53 *mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
62 static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
63 int *prom_node, int *mid)
65 int nd, cur_inst, err;
70 err = check_cpu_node(nd, &cur_inst,
76 nd = prom_getchild(nd);
77 while ((nd = prom_getsibling(nd)) != 0) {
78 err = check_cpu_node(nd, &cur_inst,
88 static int cpu_instance_compare(int nd, int instance, void *_arg)
90 int desired_instance = (int) (long) _arg;
92 if (instance == desired_instance)
97 int cpu_find_by_instance(int instance, int *prom_node, int *mid)
99 return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
103 static int cpu_mid_compare(int nd, int instance, void *_arg)
105 int desired_mid = (int) (long) _arg;
108 this_mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
109 if (this_mid == desired_mid)
114 int cpu_find_by_mid(int mid, int *prom_node)
116 return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
120 void __init device_scan(void)
122 /* FIX ME FAST... -DaveM */
123 ioport_resource.end = 0xffffffffffffffffUL;
125 prom_printf("Booting Linux...\n");
130 err = cpu_find_by_instance(0, &cpu_node, NULL);
132 prom_printf("No cpu nodes, cannot continue\n");
135 cpu_data(0).clock_tick = prom_getintdefault(cpu_node,