diff options
Diffstat (limited to 'arch/sparc64/kernel/devices.c')
-rw-r--r-- | arch/sparc64/kernel/devices.c | 189 |
1 files changed, 179 insertions, 10 deletions
diff --git a/arch/sparc64/kernel/devices.c b/arch/sparc64/kernel/devices.c index df9a1ca8fd77..007e8922cd16 100644 --- a/arch/sparc64/kernel/devices.c +++ b/arch/sparc64/kernel/devices.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/string.h> | 12 | #include <linux/string.h> |
13 | #include <linux/spinlock.h> | 13 | #include <linux/spinlock.h> |
14 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
15 | #include <linux/bootmem.h> | ||
15 | 16 | ||
16 | #include <asm/page.h> | 17 | #include <asm/page.h> |
17 | #include <asm/oplib.h> | 18 | #include <asm/oplib.h> |
@@ -20,6 +21,8 @@ | |||
20 | #include <asm/spitfire.h> | 21 | #include <asm/spitfire.h> |
21 | #include <asm/timer.h> | 22 | #include <asm/timer.h> |
22 | #include <asm/cpudata.h> | 23 | #include <asm/cpudata.h> |
24 | #include <asm/vdev.h> | ||
25 | #include <asm/irq.h> | ||
23 | 26 | ||
24 | /* Used to synchronize acceses to NatSemi SUPER I/O chip configure | 27 | /* Used to synchronize acceses to NatSemi SUPER I/O chip configure |
25 | * operations in asm/ns87303.h | 28 | * operations in asm/ns87303.h |
@@ -29,13 +32,158 @@ DEFINE_SPINLOCK(ns87303_lock); | |||
29 | extern void cpu_probe(void); | 32 | extern void cpu_probe(void); |
30 | extern void central_probe(void); | 33 | extern void central_probe(void); |
31 | 34 | ||
32 | static char *cpu_mid_prop(void) | 35 | u32 sun4v_vdev_devhandle; |
36 | int sun4v_vdev_root; | ||
37 | |||
38 | struct vdev_intmap { | ||
39 | unsigned int phys; | ||
40 | unsigned int irq; | ||
41 | unsigned int cnode; | ||
42 | unsigned int cinterrupt; | ||
43 | }; | ||
44 | |||
45 | struct vdev_intmask { | ||
46 | unsigned int phys; | ||
47 | unsigned int interrupt; | ||
48 | unsigned int __unused; | ||
49 | }; | ||
50 | |||
51 | static struct vdev_intmap *vdev_intmap; | ||
52 | static int vdev_num_intmap; | ||
53 | static struct vdev_intmask vdev_intmask; | ||
54 | |||
55 | static void __init sun4v_virtual_device_probe(void) | ||
56 | { | ||
57 | struct linux_prom64_registers regs; | ||
58 | struct vdev_intmap *ip; | ||
59 | int node, sz, err; | ||
60 | |||
61 | if (tlb_type != hypervisor) | ||
62 | return; | ||
63 | |||
64 | node = prom_getchild(prom_root_node); | ||
65 | node = prom_searchsiblings(node, "virtual-devices"); | ||
66 | if (!node) { | ||
67 | prom_printf("SUN4V: Fatal error, no virtual-devices node.\n"); | ||
68 | prom_halt(); | ||
69 | } | ||
70 | |||
71 | sun4v_vdev_root = node; | ||
72 | |||
73 | prom_getproperty(node, "reg", (char *)®s, sizeof(regs)); | ||
74 | sun4v_vdev_devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff; | ||
75 | |||
76 | sz = prom_getproplen(node, "interrupt-map"); | ||
77 | if (sz <= 0) { | ||
78 | prom_printf("SUN4V: Error, no vdev interrupt-map.\n"); | ||
79 | prom_halt(); | ||
80 | } | ||
81 | |||
82 | if ((sz % sizeof(*ip)) != 0) { | ||
83 | prom_printf("SUN4V: Bogus interrupt-map property size %d\n", | ||
84 | sz); | ||
85 | prom_halt(); | ||
86 | } | ||
87 | |||
88 | vdev_intmap = ip = alloc_bootmem_low_pages(sz); | ||
89 | if (!vdev_intmap) { | ||
90 | prom_printf("SUN4V: Error, cannot allocate vdev_intmap.\n"); | ||
91 | prom_halt(); | ||
92 | } | ||
93 | |||
94 | err = prom_getproperty(node, "interrupt-map", (char *) ip, sz); | ||
95 | if (err == -1) { | ||
96 | prom_printf("SUN4V: Fatal error, no vdev interrupt-map.\n"); | ||
97 | prom_halt(); | ||
98 | } | ||
99 | if (err != sz) { | ||
100 | prom_printf("SUN4V: Inconsistent interrupt-map size, " | ||
101 | "proplen(%d) vs getprop(%d).\n", sz,err); | ||
102 | prom_halt(); | ||
103 | } | ||
104 | |||
105 | vdev_num_intmap = err / sizeof(*ip); | ||
106 | |||
107 | err = prom_getproperty(node, "interrupt-map-mask", | ||
108 | (char *) &vdev_intmask, | ||
109 | sizeof(vdev_intmask)); | ||
110 | if (err <= 0) { | ||
111 | prom_printf("SUN4V: Fatal error, no vdev " | ||
112 | "interrupt-map-mask.\n"); | ||
113 | prom_halt(); | ||
114 | } | ||
115 | if (err % sizeof(vdev_intmask)) { | ||
116 | prom_printf("SUN4V: Bogus interrupt-map-mask " | ||
117 | "property size %d\n", err); | ||
118 | prom_halt(); | ||
119 | } | ||
120 | |||
121 | printk("SUN4V: virtual-devices devhandle[%x]\n", | ||
122 | sun4v_vdev_devhandle); | ||
123 | } | ||
124 | |||
125 | unsigned int sun4v_vdev_device_interrupt(unsigned int dev_node) | ||
126 | { | ||
127 | unsigned int irq, reg; | ||
128 | int err, i; | ||
129 | |||
130 | err = prom_getproperty(dev_node, "interrupts", | ||
131 | (char *) &irq, sizeof(irq)); | ||
132 | if (err <= 0) { | ||
133 | printk("VDEV: Cannot get \"interrupts\" " | ||
134 | "property for OBP node %x\n", dev_node); | ||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | err = prom_getproperty(dev_node, "reg", | ||
139 | (char *) ®, sizeof(reg)); | ||
140 | if (err <= 0) { | ||
141 | printk("VDEV: Cannot get \"reg\" " | ||
142 | "property for OBP node %x\n", dev_node); | ||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | for (i = 0; i < vdev_num_intmap; i++) { | ||
147 | if (vdev_intmap[i].phys == (reg & vdev_intmask.phys) && | ||
148 | vdev_intmap[i].irq == (irq & vdev_intmask.interrupt)) { | ||
149 | irq = vdev_intmap[i].cinterrupt; | ||
150 | break; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | if (i == vdev_num_intmap) { | ||
155 | printk("VDEV: No matching interrupt map entry " | ||
156 | "for OBP node %x\n", dev_node); | ||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | return sun4v_build_irq(sun4v_vdev_devhandle, irq, 5, 0); | ||
161 | } | ||
162 | |||
163 | static const char *cpu_mid_prop(void) | ||
33 | { | 164 | { |
34 | if (tlb_type == spitfire) | 165 | if (tlb_type == spitfire) |
35 | return "upa-portid"; | 166 | return "upa-portid"; |
36 | return "portid"; | 167 | return "portid"; |
37 | } | 168 | } |
38 | 169 | ||
170 | static int get_cpu_mid(int prom_node) | ||
171 | { | ||
172 | if (tlb_type == hypervisor) { | ||
173 | struct linux_prom64_registers reg; | ||
174 | |||
175 | if (prom_getproplen(prom_node, "cpuid") == 4) | ||
176 | return prom_getintdefault(prom_node, "cpuid", 0); | ||
177 | |||
178 | prom_getproperty(prom_node, "reg", (char *) ®, sizeof(reg)); | ||
179 | return (reg.phys_addr >> 32) & 0x0fffffffUL; | ||
180 | } else { | ||
181 | const char *prop_name = cpu_mid_prop(); | ||
182 | |||
183 | return prom_getintdefault(prom_node, prop_name, 0); | ||
184 | } | ||
185 | } | ||
186 | |||
39 | static int check_cpu_node(int nd, int *cur_inst, | 187 | static int check_cpu_node(int nd, int *cur_inst, |
40 | int (*compare)(int, int, void *), void *compare_arg, | 188 | int (*compare)(int, int, void *), void *compare_arg, |
41 | int *prom_node, int *mid) | 189 | int *prom_node, int *mid) |
@@ -50,7 +198,7 @@ static int check_cpu_node(int nd, int *cur_inst, | |||
50 | if (prom_node) | 198 | if (prom_node) |
51 | *prom_node = nd; | 199 | *prom_node = nd; |
52 | if (mid) | 200 | if (mid) |
53 | *mid = prom_getintdefault(nd, cpu_mid_prop(), 0); | 201 | *mid = get_cpu_mid(nd); |
54 | return 0; | 202 | return 0; |
55 | } | 203 | } |
56 | 204 | ||
@@ -105,7 +253,7 @@ static int cpu_mid_compare(int nd, int instance, void *_arg) | |||
105 | int desired_mid = (int) (long) _arg; | 253 | int desired_mid = (int) (long) _arg; |
106 | int this_mid; | 254 | int this_mid; |
107 | 255 | ||
108 | this_mid = prom_getintdefault(nd, cpu_mid_prop(), 0); | 256 | this_mid = get_cpu_mid(nd); |
109 | if (this_mid == desired_mid) | 257 | if (this_mid == desired_mid) |
110 | return 0; | 258 | return 0; |
111 | return -ENODEV; | 259 | return -ENODEV; |
@@ -126,7 +274,8 @@ void __init device_scan(void) | |||
126 | 274 | ||
127 | #ifndef CONFIG_SMP | 275 | #ifndef CONFIG_SMP |
128 | { | 276 | { |
129 | int err, cpu_node; | 277 | int err, cpu_node, def; |
278 | |||
130 | err = cpu_find_by_instance(0, &cpu_node, NULL); | 279 | err = cpu_find_by_instance(0, &cpu_node, NULL); |
131 | if (err) { | 280 | if (err) { |
132 | prom_printf("No cpu nodes, cannot continue\n"); | 281 | prom_printf("No cpu nodes, cannot continue\n"); |
@@ -135,21 +284,40 @@ void __init device_scan(void) | |||
135 | cpu_data(0).clock_tick = prom_getintdefault(cpu_node, | 284 | cpu_data(0).clock_tick = prom_getintdefault(cpu_node, |
136 | "clock-frequency", | 285 | "clock-frequency", |
137 | 0); | 286 | 0); |
287 | |||
288 | def = ((tlb_type == hypervisor) ? | ||
289 | (8 * 1024) : | ||
290 | (16 * 1024)); | ||
138 | cpu_data(0).dcache_size = prom_getintdefault(cpu_node, | 291 | cpu_data(0).dcache_size = prom_getintdefault(cpu_node, |
139 | "dcache-size", | 292 | "dcache-size", |
140 | 16 * 1024); | 293 | def); |
294 | |||
295 | def = 32; | ||
141 | cpu_data(0).dcache_line_size = | 296 | cpu_data(0).dcache_line_size = |
142 | prom_getintdefault(cpu_node, "dcache-line-size", 32); | 297 | prom_getintdefault(cpu_node, "dcache-line-size", |
298 | def); | ||
299 | |||
300 | def = 16 * 1024; | ||
143 | cpu_data(0).icache_size = prom_getintdefault(cpu_node, | 301 | cpu_data(0).icache_size = prom_getintdefault(cpu_node, |
144 | "icache-size", | 302 | "icache-size", |
145 | 16 * 1024); | 303 | def); |
304 | |||
305 | def = 32; | ||
146 | cpu_data(0).icache_line_size = | 306 | cpu_data(0).icache_line_size = |
147 | prom_getintdefault(cpu_node, "icache-line-size", 32); | 307 | prom_getintdefault(cpu_node, "icache-line-size", |
308 | def); | ||
309 | |||
310 | def = ((tlb_type == hypervisor) ? | ||
311 | (3 * 1024 * 1024) : | ||
312 | (4 * 1024 * 1024)); | ||
148 | cpu_data(0).ecache_size = prom_getintdefault(cpu_node, | 313 | cpu_data(0).ecache_size = prom_getintdefault(cpu_node, |
149 | "ecache-size", | 314 | "ecache-size", |
150 | 4 * 1024 * 1024); | 315 | def); |
316 | |||
317 | def = 64; | ||
151 | cpu_data(0).ecache_line_size = | 318 | cpu_data(0).ecache_line_size = |
152 | prom_getintdefault(cpu_node, "ecache-line-size", 64); | 319 | prom_getintdefault(cpu_node, "ecache-line-size", |
320 | def); | ||
153 | printk("CPU[0]: Caches " | 321 | printk("CPU[0]: Caches " |
154 | "D[sz(%d):line_sz(%d)] " | 322 | "D[sz(%d):line_sz(%d)] " |
155 | "I[sz(%d):line_sz(%d)] " | 323 | "I[sz(%d):line_sz(%d)] " |
@@ -160,6 +328,7 @@ void __init device_scan(void) | |||
160 | } | 328 | } |
161 | #endif | 329 | #endif |
162 | 330 | ||
331 | sun4v_virtual_device_probe(); | ||
163 | central_probe(); | 332 | central_probe(); |
164 | 333 | ||
165 | cpu_probe(); | 334 | cpu_probe(); |