[SPARC64]: Use different cache sizing defaults on SUN4V.
[pandora-kernel.git] / 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/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>
16
17 #include <asm/page.h>
18 #include <asm/oplib.h>
19 #include <asm/system.h>
20 #include <asm/smp.h>
21 #include <asm/spitfire.h>
22 #include <asm/timer.h>
23 #include <asm/cpudata.h>
24 #include <asm/vdev.h>
25
26 /* Used to synchronize acceses to NatSemi SUPER I/O chip configure
27  * operations in asm/ns87303.h
28  */
29 DEFINE_SPINLOCK(ns87303_lock);
30
31 extern void cpu_probe(void);
32 extern void central_probe(void);
33
34 u32 sun4v_vdev_devhandle;
35 int sun4v_vdev_root;
36 struct linux_prom_pci_intmap *sun4v_vdev_intmap;
37 int sun4v_vdev_num_intmap;
38 struct linux_prom_pci_intmap sun4v_vdev_intmask;
39
40 static void __init sun4v_virtual_device_probe(void)
41 {
42         struct linux_prom64_registers regs;
43         struct linux_prom_pci_intmap *ip;
44         int node, sz, err;
45
46         if (tlb_type != hypervisor)
47                 return;
48
49         node = prom_getchild(prom_root_node);
50         node = prom_searchsiblings(node, "virtual-devices");
51         if (!node) {
52                 prom_printf("SUN4V: Fatal error, no virtual-devices node.\n");
53                 prom_halt();
54         }
55
56         sun4v_vdev_root = node;
57
58         prom_getproperty(node, "reg", (char *)&regs, sizeof(regs));
59         sun4v_vdev_devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff;
60
61         sz = sizeof(*ip) * 64;
62         sun4v_vdev_intmap = ip = alloc_bootmem_low_pages(sz);
63         if (!sun4v_vdev_intmap) {
64                 prom_printf("SUN4V: Error, cannot allocate vdev intmap.\n");
65                 prom_halt();
66         }
67
68         err = prom_getproperty(node, "interrupt-map", (char *) ip, sz);
69         if (err == -1) {
70                 prom_printf("SUN4V: Fatal error, no vdev interrupt-map.\n");
71                 prom_halt();
72         }
73
74         sun4v_vdev_num_intmap = err / sizeof(*ip);
75
76         err = prom_getproperty(node, "interrupt-map-mask",
77                                (char *) &sun4v_vdev_intmask,
78                                sizeof(sun4v_vdev_intmask));
79         if (err == -1) {
80                 prom_printf("SUN4V: Fatal error, no vdev "
81                             "interrupt-map-mask.\n");
82                 prom_halt();
83         }
84
85         printk("SUN4V: virtual-devices devhandle[%x]\n",
86                sun4v_vdev_devhandle);
87 }
88
89 static const char *cpu_mid_prop(void)
90 {
91         if (tlb_type == spitfire)
92                 return "upa-portid";
93         return "portid";
94 }
95
96 static int get_cpu_mid(int prom_node)
97 {
98         if (tlb_type == hypervisor) {
99                 struct linux_prom64_registers reg;
100
101                 if (prom_getproplen(prom_node, "cpuid") == 4)
102                         return prom_getintdefault(prom_node, "cpuid", 0);
103
104                 prom_getproperty(prom_node, "reg", (char *) &reg, sizeof(reg));
105                 return (reg.phys_addr >> 32) & 0x0fffffffUL;
106         } else {
107                 const char *prop_name = cpu_mid_prop();
108
109                 return prom_getintdefault(prom_node, prop_name, 0);
110         }
111 }
112
113 static int check_cpu_node(int nd, int *cur_inst,
114                           int (*compare)(int, int, void *), void *compare_arg,
115                           int *prom_node, int *mid)
116 {
117         char node_str[128];
118
119         prom_getstring(nd, "device_type", node_str, sizeof(node_str));
120         if (strcmp(node_str, "cpu"))
121                 return -ENODEV;
122
123         if (!compare(nd, *cur_inst, compare_arg)) {
124                 if (prom_node)
125                         *prom_node = nd;
126                 if (mid)
127                         *mid = get_cpu_mid(nd);
128                 return 0;
129         }
130
131         (*cur_inst)++;
132
133         return -ENODEV;
134 }
135
136 static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
137                          int *prom_node, int *mid)
138 {
139         int nd, cur_inst, err;
140
141         nd = prom_root_node;
142         cur_inst = 0;
143
144         err = check_cpu_node(nd, &cur_inst,
145                              compare, compare_arg,
146                              prom_node, mid);
147         if (err == 0)
148                 return 0;
149
150         nd = prom_getchild(nd);
151         while ((nd = prom_getsibling(nd)) != 0) {
152                 err = check_cpu_node(nd, &cur_inst,
153                                      compare, compare_arg,
154                                      prom_node, mid);
155                 if (err == 0)
156                         return 0;
157         }
158
159         return -ENODEV;
160 }
161
162 static int cpu_instance_compare(int nd, int instance, void *_arg)
163 {
164         int desired_instance = (int) (long) _arg;
165
166         if (instance == desired_instance)
167                 return 0;
168         return -ENODEV;
169 }
170
171 int cpu_find_by_instance(int instance, int *prom_node, int *mid)
172 {
173         return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
174                              prom_node, mid);
175 }
176
177 static int cpu_mid_compare(int nd, int instance, void *_arg)
178 {
179         int desired_mid = (int) (long) _arg;
180         int this_mid;
181
182         this_mid = get_cpu_mid(nd);
183         if (this_mid == desired_mid)
184                 return 0;
185         return -ENODEV;
186 }
187
188 int cpu_find_by_mid(int mid, int *prom_node)
189 {
190         return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
191                              prom_node, NULL);
192 }
193
194 void __init device_scan(void)
195 {
196         /* FIX ME FAST... -DaveM */
197         ioport_resource.end = 0xffffffffffffffffUL;
198
199         prom_printf("Booting Linux...\n");
200
201 #ifndef CONFIG_SMP
202         {
203                 int err, cpu_node, def;
204
205                 err = cpu_find_by_instance(0, &cpu_node, NULL);
206                 if (err) {
207                         prom_printf("No cpu nodes, cannot continue\n");
208                         prom_halt();
209                 }
210                 cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
211                                                             "clock-frequency",
212                                                             0);
213
214                 def = ((tlb_type == hypervisor) ?
215                        (8 * 1024) :
216                        (16 * 1024));
217                 cpu_data(0).dcache_size = prom_getintdefault(cpu_node,
218                                                              "dcache-size",
219                                                              def);
220
221                 def = 32;
222                 cpu_data(0).dcache_line_size =
223                         prom_getintdefault(cpu_node, "dcache-line-size",
224                                            def);
225
226                 def = 16 * 1024;
227                 cpu_data(0).icache_size = prom_getintdefault(cpu_node,
228                                                              "icache-size",
229                                                              def);
230
231                 def = 32;
232                 cpu_data(0).icache_line_size =
233                         prom_getintdefault(cpu_node, "icache-line-size",
234                                            def);
235
236                 def = ((tlb_type == hypervisor) ?
237                        (3 * 1024 * 1024) :
238                        (4 * 1024 * 1024));
239                 cpu_data(0).ecache_size = prom_getintdefault(cpu_node,
240                                                              "ecache-size",
241                                                              def);
242
243                 def = 64;
244                 cpu_data(0).ecache_line_size =
245                         prom_getintdefault(cpu_node, "ecache-line-size",
246                                            def);
247                 printk("CPU[0]: Caches "
248                        "D[sz(%d):line_sz(%d)] "
249                        "I[sz(%d):line_sz(%d)] "
250                        "E[sz(%d):line_sz(%d)]\n",
251                        cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
252                        cpu_data(0).icache_size, cpu_data(0).icache_line_size,
253                        cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
254         }
255 #endif
256
257         sun4v_virtual_device_probe();
258         central_probe();
259
260         cpu_probe();
261 }