blob: 57567dfb98192cbf5fc781c144d28d67738487ea [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Paul Mackerras0cb7b2a2005-10-29 22:07:56 +10002 * Maple (970 eval board) setup code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org),
5 * IBM Corp.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
Benjamin Herrenschmidt980a6512006-07-03 17:22:05 +100014#undef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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/a.out.h>
27#include <linux/tty.h>
28#include <linux/string.h>
29#include <linux/delay.h>
30#include <linux/ioport.h>
31#include <linux/major.h>
32#include <linux/initrd.h>
33#include <linux/vt_kern.h>
34#include <linux/console.h>
35#include <linux/ide.h>
36#include <linux/pci.h>
37#include <linux/adb.h>
38#include <linux/cuda.h>
39#include <linux/pmu.h>
40#include <linux/irq.h>
41#include <linux/seq_file.h>
42#include <linux/root_dev.h>
43#include <linux/serial.h>
44#include <linux/smp.h>
45
46#include <asm/processor.h>
47#include <asm/sections.h>
48#include <asm/prom.h>
49#include <asm/system.h>
50#include <asm/pgtable.h>
51#include <asm/bitops.h>
52#include <asm/io.h>
Michael Ellerman3d1229d2005-11-14 23:35:00 +110053#include <asm/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#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/of_device.h>
61#include <asm/lmb.h>
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +100062#include <asm/mpic.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100063#include <asm/udbg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Paul Mackerras0cb7b2a2005-10-29 22:07:56 +100065#include "maple.h"
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#ifdef DEBUG
68#define DBG(fmt...) udbg_printf(fmt)
69#else
70#define DBG(fmt...)
71#endif
72
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +110073static unsigned long maple_find_nvram_base(void)
74{
75 struct device_node *rtcs;
76 unsigned long result = 0;
77
78 /* find NVRAM device */
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070099static void maple_restart(char *cmd)
100{
David Gibsond7152fe2005-06-23 17:14:39 +1000101 unsigned int maple_nvram_base;
102 unsigned int maple_nvram_offset;
103 unsigned int maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100104 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000105
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100106 maple_nvram_base = maple_find_nvram_base();
107 if (maple_nvram_base == 0)
108 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000109
110 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100111 sp = of_find_node_by_name(NULL, "service-processor");
112 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000113 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100114 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000115 }
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100116 maple_nvram_offset = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000117 "restart-addr", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100118 maple_nvram_command = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000119 "restart-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100120 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000121
122 /* send command */
123 outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
124 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100125 fail:
126 printk(KERN_EMERG "Maple: Manual Restart Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
129static void maple_power_off(void)
130{
David Gibsond7152fe2005-06-23 17:14:39 +1000131 unsigned int maple_nvram_base;
132 unsigned int maple_nvram_offset;
133 unsigned int maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100134 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000135
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100136 maple_nvram_base = maple_find_nvram_base();
137 if (maple_nvram_base == 0)
138 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000139
140 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100141 sp = of_find_node_by_name(NULL, "service-processor");
142 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000143 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100144 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000145 }
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100146 maple_nvram_offset = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000147 "power-off-addr", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100148 maple_nvram_command = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000149 "power-off-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100150 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000151
152 /* send command */
153 outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
154 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100155 fail:
156 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
159static void maple_halt(void)
160{
David Gibsond7152fe2005-06-23 17:14:39 +1000161 maple_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
164#ifdef CONFIG_SMP
165struct smp_ops_t maple_smp_ops = {
166 .probe = smp_mpic_probe,
167 .message_pass = smp_mpic_message_pass,
168 .kick_cpu = smp_generic_kick_cpu,
169 .setup_cpu = smp_mpic_setup_cpu,
170 .give_timebase = smp_generic_give_timebase,
171 .take_timebase = smp_generic_take_timebase,
172};
173#endif /* CONFIG_SMP */
174
175void __init maple_setup_arch(void)
176{
177 /* init to some ~sane value until calibrate_delay() runs */
178 loops_per_jiffy = 50000000;
179
180 /* Setup SMP callback */
181#ifdef CONFIG_SMP
182 smp_ops = &maple_smp_ops;
183#endif
184 /* Lookup PCI hosts */
185 maple_pci_init();
186
187#ifdef CONFIG_DUMMY_CONSOLE
188 conswitchp = &dummy_con;
189#endif
Michael Ellerman62d60e92005-07-07 17:56:30 -0700190
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500191 printk(KERN_DEBUG "Using native/NAP idle loop\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
194/*
195 * Early initialization.
196 */
197static void __init maple_init_early(void)
198{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 DBG(" -> maple_init_early\n");
200
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100201 iommu_init_early_dart();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 DBG(" <- maple_init_early\n");
204}
205
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000206/*
207 * This is almost identical to pSeries and CHRP. We need to make that
208 * code generic at one point, with appropriate bits in the device-tree to
209 * identify the presence of an HT APIC
210 */
211static void __init maple_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000213 struct device_node *root, *np, *mpic_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 unsigned int *opprop;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000215 unsigned long openpic_addr = 0;
216 int naddr, n, i, opplen, has_isus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 struct mpic *mpic;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000218 unsigned int flags = MPIC_PRIMARY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000220 /* Locate MPIC in the device-tree. Note that there is a bug
221 * in Maple device-tree where the type of the controller is
222 * open-pic and not interrupt-controller
223 */
Segher Boessenkool96278d22006-07-08 02:37:20 +0200224
225 for_each_node_by_type(np, "interrupt-controller")
226 if (device_is_compatible(np, "open-pic")) {
227 mpic_node = np;
228 break;
229 }
230 if (mpic_node == NULL)
231 for_each_node_by_type(np, "open-pic") {
232 mpic_node = np;
233 break;
234 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000235 if (mpic_node == NULL) {
236 printk(KERN_ERR
237 "Failed to locate the MPIC interrupt controller\n");
238 return;
239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000241 /* Find address list in /platform-open-pic */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 root = of_find_node_by_path("/");
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000243 naddr = prom_n_addr_cells(root);
244 opprop = (unsigned int *) get_property(root, "platform-open-pic",
245 &opplen);
246 if (opprop != 0) {
247 openpic_addr = of_read_number(opprop, naddr);
248 has_isus = (opplen > naddr);
249 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
250 openpic_addr, has_isus);
251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 of_node_put(root);
253
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000254 BUG_ON(openpic_addr == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000256 /* Check for a big endian MPIC */
257 if (get_property(np, "big-endian", NULL) != NULL)
258 flags |= MPIC_BIG_ENDIAN;
259
260 /* XXX Maple specific bits */
261 flags |= MPIC_BROKEN_U3 | MPIC_WANTS_RESET;
Segher Boessenkoold319a032006-07-08 02:37:23 +0200262 /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
263 flags |= MPIC_BIG_ENDIAN;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000264
265 /* Setup the openpic driver. More device-tree junks, we hard code no
266 * ISUs for now. I'll have to revisit some stuffs with the folks doing
267 * the firmware for those
268 */
269 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
270 /*has_isus ? 16 :*/ 0, 0, " MPIC ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 BUG_ON(mpic == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000273 /* Add ISUs */
274 opplen /= sizeof(u32);
275 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
276 unsigned long isuaddr = of_read_number(opprop + i, naddr);
277 mpic_assign_isu(mpic, n, isuaddr);
278 }
279
280 /* All ISUs are setup, complete initialization */
281 mpic_init(mpic);
282 ppc_md.get_irq = mpic_get_irq;
283 of_node_put(mpic_node);
284 of_node_put(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
287static void __init maple_progress(char *s, unsigned short hex)
288{
289 printk("*** %04x : %s\n", hex, s ? s : "");
290}
291
292
293/*
294 * Called very early, MMU is off, device-tree isn't unflattened
295 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100296static int __init maple_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100298 unsigned long root = of_get_flat_dt_root();
Benjamin Herrenschmidt980a6512006-07-03 17:22:05 +1000299
300 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
301 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 return 0;
303 /*
304 * On U3, the DART (iommu) must be allocated now since it
305 * has an impact on htab_initialize (due to the large page it
306 * occupies having to be broken up so the DART itself is not
307 * part of the cacheable linar mapping
308 */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100309 alloc_dart_table();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000311 hpte_init_native();
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return 1;
314}
315
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100316define_machine(maple_md) {
317 .name = "Maple",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 .probe = maple_probe,
319 .setup_arch = maple_setup_arch,
320 .init_early = maple_init_early,
321 .init_IRQ = maple_init_IRQ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 .pcibios_fixup = maple_pcibios_fixup,
323 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
324 .restart = maple_restart,
325 .power_off = maple_power_off,
326 .halt = maple_halt,
327 .get_boot_time = maple_get_boot_time,
328 .set_rtc_time = maple_set_rtc_time,
329 .get_rtc_time = maple_get_rtc_time,
Arnd Bergmann10f7e7c2005-06-23 09:43:07 +1000330 .calibrate_decr = generic_calibrate_decr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 .progress = maple_progress,
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100332 .power_save = power4_idle,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100333#ifdef CONFIG_KEXEC
334 .machine_kexec = default_machine_kexec,
335 .machine_kexec_prepare = default_machine_kexec_prepare,
Michael Ellermancc532912005-12-04 18:39:43 +1100336 .machine_crash_shutdown = default_machine_crash_shutdown,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100337#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338};