blob: d4c61c3c9669fabaf76f7f48670f30a7427a7abd [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#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>
Jiri Slaby1977f032007-10-18 23:40:25 -070043#include <linux/bitops.h>
Jon Loeliger0173d422008-01-08 05:07:15 +110044#include <linux/of_device.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080045#include <linux/lmb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#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>
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +100060#include <asm/mpic.h>
Nathan Lynch9e254c42006-12-06 18:50:46 -060061#include <asm/rtas.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100062#include <asm/udbg.h>
Nathan Lynch4297c982007-02-05 20:01:15 -060063#include <asm/nvram.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;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000102 const unsigned int *maple_nvram_offset, *maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100103 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000104
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100105 maple_nvram_base = maple_find_nvram_base();
106 if (maple_nvram_base == 0)
107 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000108
109 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100110 sp = of_find_node_by_name(NULL, "service-processor");
111 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000112 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100113 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000114 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000115 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
116 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100117 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000118
119 /* send command */
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000120 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibsond7152fe2005-06-23 17:14:39 +1000121 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100122 fail:
123 printk(KERN_EMERG "Maple: Manual Restart Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
126static void maple_power_off(void)
127{
David Gibsond7152fe2005-06-23 17:14:39 +1000128 unsigned int maple_nvram_base;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000129 const unsigned int *maple_nvram_offset, *maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100130 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000131
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100132 maple_nvram_base = maple_find_nvram_base();
133 if (maple_nvram_base == 0)
134 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000135
136 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100137 sp = of_find_node_by_name(NULL, "service-processor");
138 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000139 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100140 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000141 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000142 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
143 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100144 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000145
146 /* send command */
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000147 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibsond7152fe2005-06-23 17:14:39 +1000148 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100149 fail:
150 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
153static void maple_halt(void)
154{
David Gibsond7152fe2005-06-23 17:14:39 +1000155 maple_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
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 /* CONFIG_SMP */
168
Nathan Lynch9e254c42006-12-06 18:50:46 -0600169static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179void __init maple_setup_arch(void)
180{
181 /* init to some ~sane value until calibrate_delay() runs */
182 loops_per_jiffy = 50000000;
183
184 /* Setup SMP callback */
185#ifdef CONFIG_SMP
186 smp_ops = &maple_smp_ops;
187#endif
188 /* Lookup PCI hosts */
189 maple_pci_init();
190
191#ifdef CONFIG_DUMMY_CONSOLE
192 conswitchp = &dummy_con;
193#endif
Nathan Lynch9e254c42006-12-06 18:50:46 -0600194 maple_use_rtas_reboot_and_halt_if_present();
Michael Ellerman62d60e92005-07-07 17:56:30 -0700195
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500196 printk(KERN_DEBUG "Using native/NAP idle loop\n");
Nathan Lynch4297c982007-02-05 20:01:15 -0600197
198 mmio_nvram_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
201/*
202 * Early initialization.
203 */
204static void __init maple_init_early(void)
205{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 DBG(" -> maple_init_early\n");
207
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100208 iommu_init_early_dart();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 DBG(" <- maple_init_early\n");
211}
212
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000213/*
214 * This is almost identical to pSeries and CHRP. We need to make that
215 * code generic at one point, with appropriate bits in the device-tree to
216 * identify the presence of an HT APIC
217 */
218static void __init maple_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000220 struct device_node *root, *np, *mpic_node = NULL;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000221 const unsigned int *opprop;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000222 unsigned long openpic_addr = 0;
223 int naddr, n, i, opplen, has_isus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 struct mpic *mpic;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000225 unsigned int flags = MPIC_PRIMARY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000227 /* Locate MPIC in the device-tree. Note that there is a bug
228 * in Maple device-tree where the type of the controller is
229 * open-pic and not interrupt-controller
230 */
Segher Boessenkool96278d22006-07-08 02:37:20 +0200231
232 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000233 if (of_device_is_compatible(np, "open-pic")) {
Segher Boessenkool96278d22006-07-08 02:37:20 +0200234 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 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000242 if (mpic_node == NULL) {
243 printk(KERN_ERR
244 "Failed to locate the MPIC interrupt controller\n");
245 return;
246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000248 /* Find address list in /platform-open-pic */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 root = of_find_node_by_path("/");
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000250 naddr = of_n_addr_cells(root);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000251 opprop = of_get_property(root, "platform-open-pic", &opplen);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000252 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000259 BUG_ON(openpic_addr == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000261 /* Check for a big endian MPIC */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000262 if (of_get_property(np, "big-endian", NULL) != NULL)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000263 flags |= MPIC_BIG_ENDIAN;
264
265 /* XXX Maple specific bits */
Michael Ellerman6cfef5b2007-04-23 18:47:08 +1000266 flags |= MPIC_U3_HT_IRQS | MPIC_WANTS_RESET;
Segher Boessenkoold319a032006-07-08 02:37:23 +0200267 /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
268 flags |= MPIC_BIG_ENDIAN;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000269
270 /* Setup the openpic driver. More device-tree junks, we hard code no
271 * ISUs for now. I'll have to revisit some stuffs with the folks doing
272 * the firmware for those
273 */
274 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
275 /*has_isus ? 16 :*/ 0, 0, " MPIC ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 BUG_ON(mpic == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000278 /* Add ISUs */
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 /* All ISUs are setup, complete initialization */
286 mpic_init(mpic);
287 ppc_md.get_irq = mpic_get_irq;
288 of_node_put(mpic_node);
289 of_node_put(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
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 * Called very early, MMU is off, device-tree isn't unflattened
300 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100301static int __init maple_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100303 unsigned long root = of_get_flat_dt_root();
Benjamin Herrenschmidt980a6512006-07-03 17:22:05 +1000304
305 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
306 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return 0;
308 /*
309 * On U3, the DART (iommu) must be allocated now since it
310 * has an impact on htab_initialize (due to the large page it
311 * occupies having to be broken up so the DART itself is not
312 * part of the cacheable linar mapping
313 */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100314 alloc_dart_table();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000316 hpte_init_native();
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return 1;
319}
320
Nathan Lynch53378c22008-03-13 10:43:03 +1100321define_machine(maple) {
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100322 .name = "Maple",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 .probe = maple_probe,
324 .setup_arch = maple_setup_arch,
325 .init_early = maple_init_early,
326 .init_IRQ = maple_init_IRQ,
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100327 .pci_irq_fixup = maple_pci_irq_fixup,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 .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,
Arnd Bergmann10f7e7c2005-06-23 09:43:07 +1000335 .calibrate_decr = generic_calibrate_decr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 .progress = maple_progress,
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100337 .power_save = power4_idle,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100338#ifdef CONFIG_KEXEC
339 .machine_kexec = default_machine_kexec,
340 .machine_kexec_prepare = default_machine_kexec_prepare,
Michael Ellermancc532912005-12-04 18:39:43 +1100341 .machine_crash_shutdown = default_machine_crash_shutdown,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100342#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343};