1/* devices.c: Initial scan of the prom device tree for important
2 *            Sparc device nodes which we need to find.
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
6
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
14#include <asm/page.h>
15#include <asm/oplib.h>
16#include <asm/system.h>
17#include <asm/smp.h>
18#include <asm/spitfire.h>
19
20struct prom_cpuinfo linux_cpus[64] __initdata = { { 0 } };
21unsigned prom_cpu_nodes[64];
22int linux_num_cpus = 0;
23
24extern void cpu_probe(void);
25extern void central_probe(void);
26
27void __init device_scan(void)
28{
29	char node_str[128];
30	int nd, prom_node_cpu, thismid;
31	int cpu_nds[64];  /* One node for each cpu */
32	int cpu_ctr = 0;
33
34	/* FIX ME FAST... -DaveM */
35	ioport_resource.end = 0xffffffffffffffffUL;
36	iomem_resource.end = 0xffffffffffffffffUL;
37
38	prom_getstring(prom_root_node, "device_type", node_str, sizeof(node_str));
39
40	prom_printf("Booting Linux...\n");
41	if(strcmp(node_str, "cpu") == 0) {
42		cpu_nds[0] = prom_root_node;
43		linux_cpus[0].prom_node = prom_root_node;
44		linux_cpus[0].mid = 0;
45		cpu_ctr++;
46	} else {
47		int scan;
48		scan = prom_getchild(prom_root_node);
49		/* prom_printf("root child is %08x\n", (unsigned) scan); */
50		nd = 0;
51		while((scan = prom_getsibling(scan)) != 0) {
52			prom_getstring(scan, "device_type", node_str, sizeof(node_str));
53			if(strcmp(node_str, "cpu") == 0) {
54				cpu_nds[cpu_ctr] = scan;
55				linux_cpus[cpu_ctr].prom_node = scan;
56				thismid = 0;
57				if (tlb_type == spitfire) {
58					prom_getproperty(scan, "upa-portid",
59							 (char *) &thismid, sizeof(thismid));
60				} else if (tlb_type == cheetah ||
61					   tlb_type == cheetah_plus) {
62					prom_getproperty(scan, "portid",
63							 (char *) &thismid, sizeof(thismid));
64				}
65				linux_cpus[cpu_ctr].mid = thismid;
66				printk("Found CPU %d (node=%08x,mid=%d)\n",
67				       cpu_ctr, (unsigned) scan, thismid);
68				cpu_ctr++;
69			}
70		};
71		if(cpu_ctr == 0) {
72			prom_printf("No CPU nodes found, cannot continue.\n");
73			prom_halt();
74		}
75		printk("Found %d CPU prom device tree node(s).\n", cpu_ctr);
76	}
77	prom_node_cpu = cpu_nds[0];
78
79	linux_num_cpus = cpu_ctr;
80
81	prom_cpu_nodes[0] = prom_node_cpu;
82
83#ifndef CONFIG_SMP
84	{
85		extern unsigned long up_clock_tick;
86		up_clock_tick = prom_getintdefault(prom_node_cpu,
87						   "clock-frequency",
88						   0);
89	}
90#endif
91
92	central_probe();
93
94	cpu_probe();
95}
96