Pull kmalloc into release branch
[linux-2.6] / arch / sparc64 / kernel / devices.c
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/kernel.h>
8 #include <linux/threads.h>
9 #include <linux/init.h>
10 #include <linux/ioport.h>
11 #include <linux/string.h>
12 #include <linux/spinlock.h>
13 #include <linux/errno.h>
14 #include <linux/bootmem.h>
15
16 #include <asm/page.h>
17 #include <asm/oplib.h>
18 #include <asm/system.h>
19 #include <asm/smp.h>
20 #include <asm/spitfire.h>
21 #include <asm/timer.h>
22 #include <asm/cpudata.h>
23
24 /* Used to synchronize acceses to NatSemi SUPER I/O chip configure
25  * operations in asm/ns87303.h
26  */
27 DEFINE_SPINLOCK(ns87303_lock);
28
29 extern void cpu_probe(void);
30 extern void central_probe(void);
31
32 static const char *cpu_mid_prop(void)
33 {
34         if (tlb_type == spitfire)
35                 return "upa-portid";
36         return "portid";
37 }
38
39 static int get_cpu_mid(struct device_node *dp)
40 {
41         struct property *prop;
42
43         if (tlb_type == hypervisor) {
44                 struct linux_prom64_registers *reg;
45                 int len;
46
47                 prop = of_find_property(dp, "cpuid", &len);
48                 if (prop && len == 4)
49                         return *(int *) prop->value;
50
51                 prop = of_find_property(dp, "reg", NULL);
52                 reg = prop->value;
53                 return (reg[0].phys_addr >> 32) & 0x0fffffffUL;
54         } else {
55                 const char *prop_name = cpu_mid_prop();
56
57                 prop = of_find_property(dp, prop_name, NULL);
58                 if (prop)
59                         return *(int *) prop->value;
60                 return 0;
61         }
62 }
63
64 static int check_cpu_node(struct device_node *dp, int *cur_inst,
65                           int (*compare)(struct device_node *, int, void *),
66                           void *compare_arg,
67                           struct device_node **dev_node, int *mid)
68 {
69         if (strcmp(dp->type, "cpu"))
70                 return -ENODEV;
71
72         if (!compare(dp, *cur_inst, compare_arg)) {
73                 if (dev_node)
74                         *dev_node = dp;
75                 if (mid)
76                         *mid = get_cpu_mid(dp);
77                 return 0;
78         }
79
80         (*cur_inst)++;
81
82         return -ENODEV;
83 }
84
85 static int __cpu_find_by(int (*compare)(struct device_node *, int, void *),
86                          void *compare_arg,
87                          struct device_node **dev_node, int *mid)
88 {
89         struct device_node *dp;
90         int cur_inst;
91
92         cur_inst = 0;
93         for_each_node_by_type(dp, "cpu") {
94                 int err = check_cpu_node(dp, &cur_inst,
95                                          compare, compare_arg,
96                                          dev_node, mid);
97                 if (err == 0)
98                         return 0;
99         }
100
101         return -ENODEV;
102 }
103
104 static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg)
105 {
106         int desired_instance = (int) (long) _arg;
107
108         if (instance == desired_instance)
109                 return 0;
110         return -ENODEV;
111 }
112
113 int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid)
114 {
115         return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
116                              dev_node, mid);
117 }
118
119 static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg)
120 {
121         int desired_mid = (int) (long) _arg;
122         int this_mid;
123
124         this_mid = get_cpu_mid(dp);
125         if (this_mid == desired_mid)
126                 return 0;
127         return -ENODEV;
128 }
129
130 int cpu_find_by_mid(int mid, struct device_node **dev_node)
131 {
132         return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
133                              dev_node, NULL);
134 }
135
136 void __init device_scan(void)
137 {
138         /* FIX ME FAST... -DaveM */
139         ioport_resource.end = 0xffffffffffffffffUL;
140
141         prom_printf("Booting Linux...\n");
142
143 #ifndef CONFIG_SMP
144         {
145                 struct device_node *dp;
146                 int err, def;
147
148                 err = cpu_find_by_instance(0, &dp, NULL);
149                 if (err) {
150                         prom_printf("No cpu nodes, cannot continue\n");
151                         prom_halt();
152                 }
153                 cpu_data(0).clock_tick =
154                         of_getintprop_default(dp, "clock-frequency", 0);
155
156                 def = ((tlb_type == hypervisor) ?
157                        (8 * 1024) :
158                        (16 * 1024));
159                 cpu_data(0).dcache_size = of_getintprop_default(dp,
160                                                                 "dcache-size",
161                                                                 def);
162
163                 def = 32;
164                 cpu_data(0).dcache_line_size =
165                         of_getintprop_default(dp, "dcache-line-size", def);
166
167                 def = 16 * 1024;
168                 cpu_data(0).icache_size = of_getintprop_default(dp,
169                                                                 "icache-size",
170                                                                 def);
171
172                 def = 32;
173                 cpu_data(0).icache_line_size =
174                         of_getintprop_default(dp, "icache-line-size", def);
175
176                 def = ((tlb_type == hypervisor) ?
177                        (3 * 1024 * 1024) :
178                        (4 * 1024 * 1024));
179                 cpu_data(0).ecache_size = of_getintprop_default(dp,
180                                                                 "ecache-size",
181                                                                 def);
182
183                 def = 64;
184                 cpu_data(0).ecache_line_size =
185                         of_getintprop_default(dp, "ecache-line-size", def);
186                 printk("CPU[0]: Caches "
187                        "D[sz(%d):line_sz(%d)] "
188                        "I[sz(%d):line_sz(%d)] "
189                        "E[sz(%d):line_sz(%d)]\n",
190                        cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
191                        cpu_data(0).icache_size, cpu_data(0).icache_line_size,
192                        cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
193         }
194 #endif
195
196         central_probe();
197
198         cpu_probe();
199 }