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/kexec.h>
54#include <asm/pci-bridge.h>
55#include <asm/iommu.h>
56#include <asm/machdep.h>
57#include <asm/dma.h>
58#include <asm/cputable.h>
59#include <asm/time.h>
60#include <asm/mpic.h>
61#include <asm/rtas.h>
62#include <asm/udbg.h>
63#include <asm/nvram.h>
64
65#include "maple.h"
66
67#ifdef DEBUG
68#define DBG(fmt...) udbg_printf(fmt)
69#else
70#define DBG(fmt...)
71#endif
72
73static unsigned long maple_find_nvram_base(void)
74{
75 struct device_node *rtcs;
76 unsigned long result = 0;
77
78
79 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
80 if (rtcs) {
81 struct resource r;
82 if (of_address_to_resource(rtcs, 0, &r)) {
83 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
84 " address\n");
85 goto bail;
86 }
87 if (!(r.flags & IORESOURCE_IO)) {
88 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
89 goto bail;
90 }
91 result = r.start;
92 } else
93 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
94 bail:
95 of_node_put(rtcs);
96 return result;
97}
98
99static void maple_restart(char *cmd)
100{
101 unsigned int maple_nvram_base;
102 const unsigned int *maple_nvram_offset, *maple_nvram_command;
103 struct device_node *sp;
104
105 maple_nvram_base = maple_find_nvram_base();
106 if (maple_nvram_base == 0)
107 goto fail;
108
109
110 sp = of_find_node_by_name(NULL, "service-processor");
111 if (!sp) {
112 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
113 goto fail;
114 }
115 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
116 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
117 of_node_put(sp);
118
119
120 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
121 for (;;) ;
122 fail:
123 printk(KERN_EMERG "Maple: Manual Restart Required\n");
124}
125
126static void maple_power_off(void)
127{
128 unsigned int maple_nvram_base;
129 const unsigned int *maple_nvram_offset, *maple_nvram_command;
130 struct device_node *sp;
131
132 maple_nvram_base = maple_find_nvram_base();
133 if (maple_nvram_base == 0)
134 goto fail;
135
136
137 sp = of_find_node_by_name(NULL, "service-processor");
138 if (!sp) {
139 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
140 goto fail;
141 }
142 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
143 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
144 of_node_put(sp);
145
146
147 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
148 for (;;) ;
149 fail:
150 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
151}
152
153static void maple_halt(void)
154{
155 maple_power_off();
156}
157
158#ifdef CONFIG_SMP
159struct smp_ops_t maple_smp_ops = {
160 .probe = smp_mpic_probe,
161 .message_pass = smp_mpic_message_pass,
162 .kick_cpu = smp_generic_kick_cpu,
163 .setup_cpu = smp_mpic_setup_cpu,
164 .give_timebase = smp_generic_give_timebase,
165 .take_timebase = smp_generic_take_timebase,
166};
167#endif
168
169static void __init maple_use_rtas_reboot_and_halt_if_present(void)
170{
171 if (rtas_service_present("system-reboot") &&
172 rtas_service_present("power-off")) {
173 ppc_md.restart = rtas_restart;
174 ppc_md.power_off = rtas_power_off;
175 ppc_md.halt = rtas_halt;
176 }
177}
178
179void __init maple_setup_arch(void)
180{
181
182 loops_per_jiffy = 50000000;
183
184
185#ifdef CONFIG_SMP
186 smp_ops = &maple_smp_ops;
187#endif
188
189 maple_pci_init();
190
191#ifdef CONFIG_DUMMY_CONSOLE
192 conswitchp = &dummy_con;
193#endif
194 maple_use_rtas_reboot_and_halt_if_present();
195
196 printk(KERN_DEBUG "Using native/NAP idle loop\n");
197
198 mmio_nvram_init();
199}
200
201
202
203
204static void __init maple_init_early(void)
205{
206 DBG(" -> maple_init_early\n");
207
208 iommu_init_early_dart();
209
210 DBG(" <- maple_init_early\n");
211}
212
213
214
215
216
217
218static void __init maple_init_IRQ(void)
219{
220 struct device_node *root, *np, *mpic_node = NULL;
221 const unsigned int *opprop;
222 unsigned long openpic_addr = 0;
223 int naddr, n, i, opplen, has_isus = 0;
224 struct mpic *mpic;
225 unsigned int flags = MPIC_PRIMARY;
226
227
228
229
230
231
232 for_each_node_by_type(np, "interrupt-controller")
233 if (of_device_is_compatible(np, "open-pic")) {
234 mpic_node = np;
235 break;
236 }
237 if (mpic_node == NULL)
238 for_each_node_by_type(np, "open-pic") {
239 mpic_node = np;
240 break;
241 }
242 if (mpic_node == NULL) {
243 printk(KERN_ERR
244 "Failed to locate the MPIC interrupt controller\n");
245 return;
246 }
247
248
249 root = of_find_node_by_path("/");
250 naddr = of_n_addr_cells(root);
251 opprop = of_get_property(root, "platform-open-pic", &opplen);
252 if (opprop != 0) {
253 openpic_addr = of_read_number(opprop, naddr);
254 has_isus = (opplen > naddr);
255 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
256 openpic_addr, has_isus);
257 }
258
259 BUG_ON(openpic_addr == 0);
260
261
262 if (of_get_property(np, "big-endian", NULL) != NULL)
263 flags |= MPIC_BIG_ENDIAN;
264
265
266 flags |= MPIC_U3_HT_IRQS | MPIC_WANTS_RESET;
267
268 flags |= MPIC_BIG_ENDIAN;
269
270
271
272
273
274 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
275 0, 0, " MPIC ");
276 BUG_ON(mpic == NULL);
277
278
279 opplen /= sizeof(u32);
280 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
281 unsigned long isuaddr = of_read_number(opprop + i, naddr);
282 mpic_assign_isu(mpic, n, isuaddr);
283 }
284
285
286 mpic_init(mpic);
287 ppc_md.get_irq = mpic_get_irq;
288 of_node_put(mpic_node);
289 of_node_put(root);
290}
291
292static void __init maple_progress(char *s, unsigned short hex)
293{
294 printk("*** %04x : %s\n", hex, s ? s : "");
295}
296
297
298
299
300
301static int __init maple_probe(void)
302{
303 unsigned long root = of_get_flat_dt_root();
304
305 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
306 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
307 return 0;
308
309
310
311
312
313
314 alloc_dart_table();
315
316 hpte_init_native();
317
318 return 1;
319}
320
321define_machine(maple) {
322 .name = "Maple",
323 .probe = maple_probe,
324 .setup_arch = maple_setup_arch,
325 .init_early = maple_init_early,
326 .init_IRQ = maple_init_IRQ,
327 .pci_irq_fixup = maple_pci_irq_fixup,
328 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
329 .restart = maple_restart,
330 .power_off = maple_power_off,
331 .halt = maple_halt,
332 .get_boot_time = maple_get_boot_time,
333 .set_rtc_time = maple_set_rtc_time,
334 .get_rtc_time = maple_get_rtc_time,
335 .calibrate_decr = generic_calibrate_decr,
336 .progress = maple_progress,
337 .power_save = power4_idle,
338#ifdef CONFIG_KEXEC
339 .machine_kexec = default_machine_kexec,
340 .machine_kexec_prepare = default_machine_kexec_prepare,
341 .machine_crash_shutdown = default_machine_crash_shutdown,
342#endif
343};
344