1
2
3
4
5
6
7
8
9
10
11
12
13
14#undef DEBUG
15
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/sched.h>
19#include <linux/kernel.h>
20#include <linux/mm.h>
21#include <linux/stddef.h>
22#include <linux/unistd.h>
23#include <linux/ptrace.h>
24#include <linux/slab.h>
25#include <linux/user.h>
26#include <linux/tty.h>
27#include <linux/string.h>
28#include <linux/delay.h>
29#include <linux/ioport.h>
30#include <linux/major.h>
31#include <linux/initrd.h>
32#include <linux/vt_kern.h>
33#include <linux/console.h>
34#include <linux/pci.h>
35#include <linux/adb.h>
36#include <linux/cuda.h>
37#include <linux/pmu.h>
38#include <linux/irq.h>
39#include <linux/seq_file.h>
40#include <linux/root_dev.h>
41#include <linux/serial.h>
42#include <linux/smp.h>
43#include <linux/bitops.h>
44#include <linux/of_device.h>
45#include <linux/lmb.h>
46
47#include <asm/processor.h>
48#include <asm/sections.h>
49#include <asm/prom.h>
50#include <asm/system.h>
51#include <asm/pgtable.h>
52#include <asm/io.h>
53#include <asm/pci-bridge.h>
54#include <asm/iommu.h>
55#include <asm/machdep.h>
56#include <asm/dma.h>
57#include <asm/cputable.h>
58#include <asm/time.h>
59#include <asm/mpic.h>
60#include <asm/rtas.h>
61#include <asm/udbg.h>
62#include <asm/nvram.h>
63
64#include "maple.h"
65
66#ifdef DEBUG
67#define DBG(fmt...) udbg_printf(fmt)
68#else
69#define DBG(fmt...)
70#endif
71
72static unsigned long maple_find_nvram_base(void)
73{
74 struct device_node *rtcs;
75 unsigned long result = 0;
76
77
78 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
79 if (rtcs) {
80 struct resource r;
81 if (of_address_to_resource(rtcs, 0, &r)) {
82 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
83 " address\n");
84 goto bail;
85 }
86 if (!(r.flags & IORESOURCE_IO)) {
87 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
88 goto bail;
89 }
90 result = r.start;
91 } else
92 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
93 bail:
94 of_node_put(rtcs);
95 return result;
96}
97
98static void maple_restart(char *cmd)
99{
100 unsigned int maple_nvram_base;
101 const unsigned int *maple_nvram_offset, *maple_nvram_command;
102 struct device_node *sp;
103
104 maple_nvram_base = maple_find_nvram_base();
105 if (maple_nvram_base == 0)
106 goto fail;
107
108
109 sp = of_find_node_by_name(NULL, "service-processor");
110 if (!sp) {
111 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
112 goto fail;
113 }
114 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
115 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
116 of_node_put(sp);
117
118
119 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
120 for (;;) ;
121 fail:
122 printk(KERN_EMERG "Maple: Manual Restart Required\n");
123}
124
125static void maple_power_off(void)
126{
127 unsigned int maple_nvram_base;
128 const unsigned int *maple_nvram_offset, *maple_nvram_command;
129 struct device_node *sp;
130
131 maple_nvram_base = maple_find_nvram_base();
132 if (maple_nvram_base == 0)
133 goto fail;
134
135
136 sp = of_find_node_by_name(NULL, "service-processor");
137 if (!sp) {
138 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
139 goto fail;
140 }
141 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
142 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
143 of_node_put(sp);
144
145
146 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
147 for (;;) ;
148 fail:
149 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
150}
151
152static void maple_halt(void)
153{
154 maple_power_off();
155}
156
157#ifdef CONFIG_SMP
158struct smp_ops_t maple_smp_ops = {
159 .probe = smp_mpic_probe,
160 .message_pass = smp_mpic_message_pass,
161 .kick_cpu = smp_generic_kick_cpu,
162 .setup_cpu = smp_mpic_setup_cpu,
163 .give_timebase = smp_generic_give_timebase,
164 .take_timebase = smp_generic_take_timebase,
165};
166#endif
167
168static void __init maple_use_rtas_reboot_and_halt_if_present(void)
169{
170 if (rtas_service_present("system-reboot") &&
171 rtas_service_present("power-off")) {
172 ppc_md.restart = rtas_restart;
173 ppc_md.power_off = rtas_power_off;
174 ppc_md.halt = rtas_halt;
175 }
176}
177
178void __init maple_setup_arch(void)
179{
180
181 loops_per_jiffy = 50000000;
182
183
184#ifdef CONFIG_SMP
185 smp_ops = &maple_smp_ops;
186#endif
187
188 maple_pci_init();
189
190#ifdef CONFIG_DUMMY_CONSOLE
191 conswitchp = &dummy_con;
192#endif
193 maple_use_rtas_reboot_and_halt_if_present();
194
195 printk(KERN_DEBUG "Using native/NAP idle loop\n");
196
197 mmio_nvram_init();
198}
199
200
201
202
203static void __init maple_init_early(void)
204{
205 DBG(" -> maple_init_early\n");
206
207 iommu_init_early_dart();
208
209 DBG(" <- maple_init_early\n");
210}
211
212
213
214
215
216
217static void __init maple_init_IRQ(void)
218{
219 struct device_node *root, *np, *mpic_node = NULL;
220 const unsigned int *opprop;
221 unsigned long openpic_addr = 0;
222 int naddr, n, i, opplen, has_isus = 0;
223 struct mpic *mpic;
224 unsigned int flags = MPIC_PRIMARY;
225
226
227
228
229
230
231 for_each_node_by_type(np, "interrupt-controller")
232 if (of_device_is_compatible(np, "open-pic")) {
233 mpic_node = np;
234 break;
235 }
236 if (mpic_node == NULL)
237 for_each_node_by_type(np, "open-pic") {
238 mpic_node = np;
239 break;
240 }
241 if (mpic_node == NULL) {
242 printk(KERN_ERR
243 "Failed to locate the MPIC interrupt controller\n");
244 return;
245 }
246
247
248 root = of_find_node_by_path("/");
249 naddr = of_n_addr_cells(root);
250 opprop = of_get_property(root, "platform-open-pic", &opplen);
251 if (opprop != 0) {
252 openpic_addr = of_read_number(opprop, naddr);
253 has_isus = (opplen > naddr);
254 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
255 openpic_addr, has_isus);
256 }
257
258 BUG_ON(openpic_addr == 0);
259
260
261 if (of_get_property(np, "big-endian", NULL) != NULL)
262 flags |= MPIC_BIG_ENDIAN;
263
264
265 flags |= MPIC_U3_HT_IRQS | MPIC_WANTS_RESET;
266
267 flags |= MPIC_BIG_ENDIAN;
268
269
270
271
272
273 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
274 0, 0, " MPIC ");
275 BUG_ON(mpic == NULL);
276
277
278 opplen /= sizeof(u32);
279 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
280 unsigned long isuaddr = of_read_number(opprop + i, naddr);
281 mpic_assign_isu(mpic, n, isuaddr);
282 }
283
284
285 mpic_init(mpic);
286 ppc_md.get_irq = mpic_get_irq;
287 of_node_put(mpic_node);
288 of_node_put(root);
289}
290
291static void __init maple_progress(char *s, unsigned short hex)
292{
293 printk("*** %04x : %s\n", hex, s ? s : "");
294}
295
296
297
298
299
300static int __init maple_probe(void)
301{
302 unsigned long root = of_get_flat_dt_root();
303
304 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
305 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
306 return 0;
307
308
309
310
311
312
313 alloc_dart_table();
314
315 hpte_init_native();
316
317 return 1;
318}
319
320define_machine(maple) {
321 .name = "Maple",
322 .probe = maple_probe,
323 .setup_arch = maple_setup_arch,
324 .init_early = maple_init_early,
325 .init_IRQ = maple_init_IRQ,
326 .pci_irq_fixup = maple_pci_irq_fixup,
327 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
328 .restart = maple_restart,
329 .power_off = maple_power_off,
330 .halt = maple_halt,
331 .get_boot_time = maple_get_boot_time,
332 .set_rtc_time = maple_set_rtc_time,
333 .get_rtc_time = maple_get_rtc_time,
334 .calibrate_decr = generic_calibrate_decr,
335 .progress = maple_progress,
336 .power_save = power4_idle,
337};
338
339#ifdef CONFIG_EDAC
340
341
342
343
344#define MAPLE_CPC925_MODEL "Motorola,ATCA-6101"
345static int __init maple_cpc925_edac_setup(void)
346{
347 struct platform_device *pdev;
348 struct device_node *np = NULL;
349 struct resource r;
350 const unsigned char *model;
351 int ret;
352
353 np = of_find_node_by_path("/");
354 if (!np) {
355 printk(KERN_ERR "%s: Unable to get root node\n", __func__);
356 return -ENODEV;
357 }
358
359 model = (const unsigned char *)of_get_property(np, "model", NULL);
360 if (!model) {
361 printk(KERN_ERR "%s: Unabel to get model info\n", __func__);
362 return -ENODEV;
363 }
364
365 ret = strcmp(model, MAPLE_CPC925_MODEL);
366 of_node_put(np);
367
368 if (ret != 0)
369 return 0;
370
371 np = of_find_node_by_type(NULL, "memory-controller");
372 if (!np) {
373 printk(KERN_ERR "%s: Unable to find memory-controller node\n",
374 __func__);
375 return -ENODEV;
376 }
377
378 ret = of_address_to_resource(np, 0, &r);
379 of_node_put(np);
380
381 if (ret < 0) {
382 printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
383 __func__);
384 return -ENODEV;
385 }
386
387 pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
388 if (IS_ERR(pdev))
389 return PTR_ERR(pdev);
390
391 printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
392
393 return 0;
394}
395machine_device_initcall(maple, maple_cpc925_edac_setup);
396#endif
397