blob: d2eddd6647cd2d1debfb79d11a9bce1cc87e8c74 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* devices.c: Initial scan of the prom device tree for important
2 * Sparc device nodes which we need to find.
3 *
4 * This is based on the sparc64 version, but sun4m doesn't always use
5 * the hardware MIDs, so be careful.
6 *
7 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/threads.h>
12#include <linux/string.h>
13#include <linux/init.h>
14#include <linux/errno.h>
15
16#include <asm/page.h>
17#include <asm/oplib.h>
David S. Millerc2d3bff2006-07-17 21:49:58 -070018#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/smp.h>
20#include <asm/system.h>
21#include <asm/cpudata.h>
22
23extern void cpu_probe(void);
24extern void clock_stop_probe(void); /* tadpole.c */
25extern void sun4c_probe_memerr_reg(void);
26
27static char *cpu_mid_prop(void)
28{
29 if (sparc_cpu_model == sun4d)
30 return "cpu-id";
31 return "mid";
32}
33
Andres Salomon8d125562010-10-08 14:18:11 -070034static int check_cpu_node(phandle nd, int *cur_inst,
35 int (*compare)(phandle, int, void *), void *compare_arg,
36 phandle *prom_node, int *mid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 if (!compare(nd, *cur_inst, compare_arg)) {
39 if (prom_node)
40 *prom_node = nd;
41 if (mid) {
42 *mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
43 if (sparc_cpu_model == sun4m)
44 *mid &= 3;
45 }
46 return 0;
47 }
48
49 (*cur_inst)++;
50
51 return -ENODEV;
52}
53
Andres Salomon8d125562010-10-08 14:18:11 -070054static int __cpu_find_by(int (*compare)(phandle, int, void *),
55 void *compare_arg, phandle *prom_node, int *mid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
David S. Millerc2d3bff2006-07-17 21:49:58 -070057 struct device_node *dp;
58 int cur_inst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 cur_inst = 0;
David S. Millerc2d3bff2006-07-17 21:49:58 -070061 for_each_node_by_type(dp, "cpu") {
Grant Likely6016a362010-01-28 14:06:53 -070062 int err = check_cpu_node(dp->phandle, &cur_inst,
David S. Millerc2d3bff2006-07-17 21:49:58 -070063 compare, compare_arg,
64 prom_node, mid);
Julia Lawallb127aa82007-12-04 00:33:07 -080065 if (!err) {
66 of_node_put(dp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 return 0;
Julia Lawallb127aa82007-12-04 00:33:07 -080068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70
71 return -ENODEV;
72}
73
Andres Salomon8d125562010-10-08 14:18:11 -070074static int cpu_instance_compare(phandle nd, int instance, void *_arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 int desired_instance = (int) _arg;
77
78 if (instance == desired_instance)
79 return 0;
80 return -ENODEV;
81}
82
Andres Salomon8d125562010-10-08 14:18:11 -070083int cpu_find_by_instance(int instance, phandle *prom_node, int *mid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 return __cpu_find_by(cpu_instance_compare, (void *)instance,
86 prom_node, mid);
87}
88
Andres Salomon8d125562010-10-08 14:18:11 -070089static int cpu_mid_compare(phandle nd, int instance, void *_arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 int desired_mid = (int) _arg;
92 int this_mid;
93
94 this_mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
95 if (this_mid == desired_mid
96 || (sparc_cpu_model == sun4m && (this_mid & 3) == desired_mid))
97 return 0;
98 return -ENODEV;
99}
100
Andres Salomon8d125562010-10-08 14:18:11 -0700101int cpu_find_by_mid(int mid, phandle *prom_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103 return __cpu_find_by(cpu_mid_compare, (void *)mid,
104 prom_node, NULL);
105}
106
107/* sun4m uses truncated mids since we base the cpuid on the ttable/irqset
108 * address (0-3). This gives us the true hardware mid, which might have
109 * some other bits set. On 4d hardware and software mids are the same.
110 */
Andres Salomon8d125562010-10-08 14:18:11 -0700111int cpu_get_hwmid(phandle prom_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 return prom_getintdefault(prom_node, cpu_mid_prop(), -ENODEV);
114}
115
116void __init device_scan(void)
117{
118 prom_printf("Booting Linux...\n");
119
120#ifndef CONFIG_SMP
121 {
Andres Salomon8d125562010-10-08 14:18:11 -0700122 phandle cpu_node;
123 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 err = cpu_find_by_instance(0, &cpu_node, NULL);
125 if (err) {
126 /* Probably a sun4e, Sun is trying to trick us ;-) */
127 prom_printf("No cpu nodes, cannot continue\n");
128 prom_halt();
129 }
130 cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
131 "clock-frequency",
132 0);
133 }
134#endif /* !CONFIG_SMP */
135
136 cpu_probe();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 {
138 extern void auxio_probe(void);
139 extern void auxio_power_probe(void);
140 auxio_probe();
141 auxio_power_probe();
142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 clock_stop_probe();
144
Adrian Bunk5110bd22008-08-31 20:59:37 -0700145 if (ARCH_SUN4C)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 sun4c_probe_memerr_reg();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}