blob: 4e32a5417fd14897e17cf1bf69ae3fa6b5c43ed0 [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
14#define DEBUG
15
16#include <linux/config.h>
17#include <linux/init.h>
18#include <linux/errno.h>
19#include <linux/sched.h>
20#include <linux/kernel.h>
21#include <linux/mm.h>
22#include <linux/stddef.h>
23#include <linux/unistd.h>
24#include <linux/ptrace.h>
25#include <linux/slab.h>
26#include <linux/user.h>
27#include <linux/a.out.h>
28#include <linux/tty.h>
29#include <linux/string.h>
30#include <linux/delay.h>
31#include <linux/ioport.h>
32#include <linux/major.h>
33#include <linux/initrd.h>
34#include <linux/vt_kern.h>
35#include <linux/console.h>
36#include <linux/ide.h>
37#include <linux/pci.h>
38#include <linux/adb.h>
39#include <linux/cuda.h>
40#include <linux/pmu.h>
41#include <linux/irq.h>
42#include <linux/seq_file.h>
43#include <linux/root_dev.h>
44#include <linux/serial.h>
45#include <linux/smp.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/bitops.h>
53#include <asm/io.h>
Michael Ellerman3d1229d2005-11-14 23:35:00 +110054#include <asm/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/pci-bridge.h>
56#include <asm/iommu.h>
57#include <asm/machdep.h>
58#include <asm/dma.h>
59#include <asm/cputable.h>
60#include <asm/time.h>
61#include <asm/of_device.h>
62#include <asm/lmb.h>
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +100063#include <asm/mpic.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100064#include <asm/udbg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Paul Mackerras0cb7b2a2005-10-29 22:07:56 +100066#include "maple.h"
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#ifdef DEBUG
69#define DBG(fmt...) udbg_printf(fmt)
70#else
71#define DBG(fmt...)
72#endif
73
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +110074static unsigned long maple_find_nvram_base(void)
75{
76 struct device_node *rtcs;
77 unsigned long result = 0;
78
79 /* find NVRAM device */
80 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
81 if (rtcs) {
82 struct resource r;
83 if (of_address_to_resource(rtcs, 0, &r)) {
84 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
85 " address\n");
86 goto bail;
87 }
88 if (!(r.flags & IORESOURCE_IO)) {
89 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
90 goto bail;
91 }
92 result = r.start;
93 } else
94 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
95 bail:
96 of_node_put(rtcs);
97 return result;
98}
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100static void maple_restart(char *cmd)
101{
David Gibsond7152fe2005-06-23 17:14:39 +1000102 unsigned int maple_nvram_base;
103 unsigned int maple_nvram_offset;
104 unsigned int maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100105 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000106
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100107 maple_nvram_base = maple_find_nvram_base();
108 if (maple_nvram_base == 0)
109 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000110
111 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100112 sp = of_find_node_by_name(NULL, "service-processor");
113 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000114 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100115 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000116 }
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100117 maple_nvram_offset = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000118 "restart-addr", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100119 maple_nvram_command = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000120 "restart-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100121 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000122
123 /* send command */
124 outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
125 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100126 fail:
127 printk(KERN_EMERG "Maple: Manual Restart Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
130static void maple_power_off(void)
131{
David Gibsond7152fe2005-06-23 17:14:39 +1000132 unsigned int maple_nvram_base;
133 unsigned int maple_nvram_offset;
134 unsigned int maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100135 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000136
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100137 maple_nvram_base = maple_find_nvram_base();
138 if (maple_nvram_base == 0)
139 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000140
141 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100142 sp = of_find_node_by_name(NULL, "service-processor");
143 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000144 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100145 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000146 }
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100147 maple_nvram_offset = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000148 "power-off-addr", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100149 maple_nvram_command = *(unsigned int*) get_property(sp,
David Gibsond7152fe2005-06-23 17:14:39 +1000150 "power-off-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100151 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000152
153 /* send command */
154 outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
155 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100156 fail:
157 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160static void maple_halt(void)
161{
David Gibsond7152fe2005-06-23 17:14:39 +1000162 maple_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165#ifdef CONFIG_SMP
166struct smp_ops_t maple_smp_ops = {
167 .probe = smp_mpic_probe,
168 .message_pass = smp_mpic_message_pass,
169 .kick_cpu = smp_generic_kick_cpu,
170 .setup_cpu = smp_mpic_setup_cpu,
171 .give_timebase = smp_generic_give_timebase,
172 .take_timebase = smp_generic_take_timebase,
173};
174#endif /* CONFIG_SMP */
175
176void __init maple_setup_arch(void)
177{
178 /* init to some ~sane value until calibrate_delay() runs */
179 loops_per_jiffy = 50000000;
180
181 /* Setup SMP callback */
182#ifdef CONFIG_SMP
183 smp_ops = &maple_smp_ops;
184#endif
185 /* Lookup PCI hosts */
186 maple_pci_init();
187
188#ifdef CONFIG_DUMMY_CONSOLE
189 conswitchp = &dummy_con;
190#endif
Michael Ellerman62d60e92005-07-07 17:56:30 -0700191
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500192 printk(KERN_DEBUG "Using native/NAP idle loop\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195/*
196 * Early initialization.
197 */
198static void __init maple_init_early(void)
199{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 DBG(" -> maple_init_early\n");
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 /* Setup interrupt mapping options */
203 ppc64_interrupt_controller = IC_OPEN_PIC;
204
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100205 iommu_init_early_dart();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 DBG(" <- maple_init_early\n");
208}
209
210
211static __init void maple_init_IRQ(void)
212{
213 struct device_node *root;
214 unsigned int *opprop;
215 unsigned long opic_addr;
216 struct mpic *mpic;
217 unsigned char senses[128];
218 int n;
219
220 DBG(" -> maple_init_IRQ\n");
221
222 /* XXX: Non standard, replace that with a proper openpic/mpic node
223 * in the device-tree. Find the Open PIC if present */
224 root = of_find_node_by_path("/");
225 opprop = (unsigned int *) get_property(root,
226 "platform-open-pic", NULL);
227 if (opprop == 0)
228 panic("OpenPIC not found !\n");
229
230 n = prom_n_addr_cells(root);
231 for (opic_addr = 0; n > 0; --n)
232 opic_addr = (opic_addr << 32) + *opprop++;
233 of_node_put(root);
234
235 /* Obtain sense values from device-tree */
236 prom_get_irq_senses(senses, 0, 128);
237
238 mpic = mpic_alloc(opic_addr,
239 MPIC_PRIMARY | MPIC_BIG_ENDIAN |
240 MPIC_BROKEN_U3 | MPIC_WANTS_RESET,
241 0, 0, 128, 128, senses, 128, "U3-MPIC");
242 BUG_ON(mpic == NULL);
243 mpic_init(mpic);
244
245 DBG(" <- maple_init_IRQ\n");
246}
247
248static void __init maple_progress(char *s, unsigned short hex)
249{
250 printk("*** %04x : %s\n", hex, s ? s : "");
251}
252
253
254/*
255 * Called very early, MMU is off, device-tree isn't unflattened
256 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100257static int __init maple_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100259 unsigned long root = of_get_flat_dt_root();
260 if (!of_flat_dt_is_compatible(root, "Momentum,Maple"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return 0;
262 /*
263 * On U3, the DART (iommu) must be allocated now since it
264 * has an impact on htab_initialize (due to the large page it
265 * occupies having to be broken up so the DART itself is not
266 * part of the cacheable linar mapping
267 */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100268 alloc_dart_table();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000270 hpte_init_native();
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 return 1;
273}
274
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100275define_machine(maple_md) {
276 .name = "Maple",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .probe = maple_probe,
278 .setup_arch = maple_setup_arch,
279 .init_early = maple_init_early,
280 .init_IRQ = maple_init_IRQ,
281 .get_irq = mpic_get_irq,
282 .pcibios_fixup = maple_pcibios_fixup,
283 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
284 .restart = maple_restart,
285 .power_off = maple_power_off,
286 .halt = maple_halt,
287 .get_boot_time = maple_get_boot_time,
288 .set_rtc_time = maple_set_rtc_time,
289 .get_rtc_time = maple_get_rtc_time,
Arnd Bergmann10f7e7c2005-06-23 09:43:07 +1000290 .calibrate_decr = generic_calibrate_decr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 .progress = maple_progress,
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100292 .power_save = power4_idle,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100293#ifdef CONFIG_KEXEC
294 .machine_kexec = default_machine_kexec,
295 .machine_kexec_prepare = default_machine_kexec_prepare,
Michael Ellermancc532912005-12-04 18:39:43 +1100296 .machine_crash_shutdown = default_machine_crash_shutdown,
Michael Ellerman3d1229d2005-11-14 23:35:00 +1100297#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298};