blob: 0bcbfe7b2c55ac53a9c638f1aab86757f4e85081 [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>
Paul Gortmaker66b15db2011-05-27 10:46:24 -040020#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/mm.h>
22#include <linux/stddef.h>
23#include <linux/unistd.h>
24#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#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>
Yinghai Lu95f72d12010-07-12 14:36:09 +100045#include <linux/memblock.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>
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>
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +100059#include <asm/mpic.h>
Nathan Lynch9e254c42006-12-06 18:50:46 -060060#include <asm/rtas.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100061#include <asm/udbg.h>
Nathan Lynch4297c982007-02-05 20:01:15 -060062#include <asm/nvram.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Paul Mackerras0cb7b2a2005-10-29 22:07:56 +100064#include "maple.h"
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#ifdef DEBUG
67#define DBG(fmt...) udbg_printf(fmt)
68#else
69#define DBG(fmt...)
70#endif
71
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +110072static unsigned long maple_find_nvram_base(void)
73{
74 struct device_node *rtcs;
75 unsigned long result = 0;
76
77 /* find NVRAM device */
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static void maple_restart(char *cmd)
99{
David Gibsond7152fe2005-06-23 17:14:39 +1000100 unsigned int maple_nvram_base;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000101 const unsigned int *maple_nvram_offset, *maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100102 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000103
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100104 maple_nvram_base = maple_find_nvram_base();
105 if (maple_nvram_base == 0)
106 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000107
108 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100109 sp = of_find_node_by_name(NULL, "service-processor");
110 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000111 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100112 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000113 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000114 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
115 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100116 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000117
118 /* send command */
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000119 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibsond7152fe2005-06-23 17:14:39 +1000120 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100121 fail:
122 printk(KERN_EMERG "Maple: Manual Restart Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
125static void maple_power_off(void)
126{
David Gibsond7152fe2005-06-23 17:14:39 +1000127 unsigned int maple_nvram_base;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000128 const unsigned int *maple_nvram_offset, *maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100129 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000130
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100131 maple_nvram_base = maple_find_nvram_base();
132 if (maple_nvram_base == 0)
133 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000134
135 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100136 sp = of_find_node_by_name(NULL, "service-processor");
137 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000138 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100139 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000140 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000141 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
142 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100143 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000144
145 /* send command */
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000146 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibsond7152fe2005-06-23 17:14:39 +1000147 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100148 fail:
149 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
152static void maple_halt(void)
153{
David Gibsond7152fe2005-06-23 17:14:39 +1000154 maple_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
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 /* CONFIG_SMP */
167
Nathan Lynch9e254c42006-12-06 18:50:46 -0600168static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178void __init maple_setup_arch(void)
179{
180 /* init to some ~sane value until calibrate_delay() runs */
181 loops_per_jiffy = 50000000;
182
183 /* Setup SMP callback */
184#ifdef CONFIG_SMP
185 smp_ops = &maple_smp_ops;
186#endif
187 /* Lookup PCI hosts */
188 maple_pci_init();
189
190#ifdef CONFIG_DUMMY_CONSOLE
191 conswitchp = &dummy_con;
192#endif
Nathan Lynch9e254c42006-12-06 18:50:46 -0600193 maple_use_rtas_reboot_and_halt_if_present();
Michael Ellerman62d60e92005-07-07 17:56:30 -0700194
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500195 printk(KERN_DEBUG "Using native/NAP idle loop\n");
Nathan Lynch4297c982007-02-05 20:01:15 -0600196
197 mmio_nvram_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
200/*
201 * Early initialization.
202 */
203static void __init maple_init_early(void)
204{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 DBG(" -> maple_init_early\n");
206
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100207 iommu_init_early_dart();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 DBG(" <- maple_init_early\n");
210}
211
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000212/*
213 * This is almost identical to pSeries and CHRP. We need to make that
214 * code generic at one point, with appropriate bits in the device-tree to
215 * identify the presence of an HT APIC
216 */
217static void __init maple_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000219 struct device_node *root, *np, *mpic_node = NULL;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000220 const unsigned int *opprop;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000221 unsigned long openpic_addr = 0;
222 int naddr, n, i, opplen, has_isus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 struct mpic *mpic;
Kyle Moffettbe8bec52011-12-02 06:28:03 +0000224 unsigned int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000226 /* Locate MPIC in the device-tree. Note that there is a bug
227 * in Maple device-tree where the type of the controller is
228 * open-pic and not interrupt-controller
229 */
Segher Boessenkool96278d22006-07-08 02:37:20 +0200230
231 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000232 if (of_device_is_compatible(np, "open-pic")) {
Segher Boessenkool96278d22006-07-08 02:37:20 +0200233 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 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000241 if (mpic_node == NULL) {
242 printk(KERN_ERR
243 "Failed to locate the MPIC interrupt controller\n");
244 return;
245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000247 /* Find address list in /platform-open-pic */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 root = of_find_node_by_path("/");
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000249 naddr = of_n_addr_cells(root);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000250 opprop = of_get_property(root, "platform-open-pic", &opplen);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000251 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000258 BUG_ON(openpic_addr == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000260 /* Check for a big endian MPIC */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000261 if (of_get_property(np, "big-endian", NULL) != NULL)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000262 flags |= MPIC_BIG_ENDIAN;
263
264 /* XXX Maple specific bits */
Michael Ellerman6cfef5b2007-04-23 18:47:08 +1000265 flags |= MPIC_U3_HT_IRQS | MPIC_WANTS_RESET;
Segher Boessenkoold319a032006-07-08 02:37:23 +0200266 /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
267 flags |= MPIC_BIG_ENDIAN;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000268
269 /* Setup the openpic driver. More device-tree junks, we hard code no
270 * ISUs for now. I'll have to revisit some stuffs with the folks doing
271 * the firmware for those
272 */
273 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
274 /*has_isus ? 16 :*/ 0, 0, " MPIC ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 BUG_ON(mpic == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000277 /* Add ISUs */
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 /* All ISUs are setup, complete initialization */
285 mpic_init(mpic);
286 ppc_md.get_irq = mpic_get_irq;
287 of_node_put(mpic_node);
288 of_node_put(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
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 * Called very early, MMU is off, device-tree isn't unflattened
299 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100300static int __init maple_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100302 unsigned long root = of_get_flat_dt_root();
Benjamin Herrenschmidt980a6512006-07-03 17:22:05 +1000303
304 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
305 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 return 0;
307 /*
308 * On U3, the DART (iommu) must be allocated now since it
309 * has an impact on htab_initialize (due to the large page it
310 * occupies having to be broken up so the DART itself is not
311 * part of the cacheable linar mapping
312 */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100313 alloc_dart_table();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000315 hpte_init_native();
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return 1;
318}
319
Nathan Lynch53378c22008-03-13 10:43:03 +1100320define_machine(maple) {
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100321 .name = "Maple",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 .probe = maple_probe,
323 .setup_arch = maple_setup_arch,
324 .init_early = maple_init_early,
325 .init_IRQ = maple_init_IRQ,
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100326 .pci_irq_fixup = maple_pci_irq_fixup,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 .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,
Arnd Bergmann10f7e7c2005-06-23 09:43:07 +1000334 .calibrate_decr = generic_calibrate_decr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 .progress = maple_progress,
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100336 .power_save = power4_idle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337};
Harry Ciao8f101a02009-06-17 16:28:00 -0700338
339#ifdef CONFIG_EDAC
340/*
341 * Register a platform device for CPC925 memory controller on
Dmitry Eremin-Solenikov8a0360a2011-06-17 02:51:46 +0000342 * all boards with U3H (CPC925) bridge.
Harry Ciao8f101a02009-06-17 16:28:00 -0700343 */
Harry Ciao8f101a02009-06-17 16:28:00 -0700344static int __init maple_cpc925_edac_setup(void)
345{
346 struct platform_device *pdev;
347 struct device_node *np = NULL;
348 struct resource r;
Harry Ciao8f101a02009-06-17 16:28:00 -0700349 int ret;
Dmitry Eremin-Solenikov8a0360a2011-06-17 02:51:46 +0000350 volatile void __iomem *mem;
351 u32 rev;
Harry Ciao8f101a02009-06-17 16:28:00 -0700352
353 np = of_find_node_by_type(NULL, "memory-controller");
354 if (!np) {
355 printk(KERN_ERR "%s: Unable to find memory-controller node\n",
356 __func__);
357 return -ENODEV;
358 }
359
360 ret = of_address_to_resource(np, 0, &r);
361 of_node_put(np);
362
363 if (ret < 0) {
364 printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
365 __func__);
366 return -ENODEV;
367 }
368
Dmitry Eremin-Solenikov8a0360a2011-06-17 02:51:46 +0000369 mem = ioremap(r.start, resource_size(&r));
370 if (!mem) {
371 printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
372 __func__);
373 return -ENOMEM;
374 }
375
376 rev = __raw_readl(mem);
377 iounmap(mem);
378
379 if (rev < 0x34 || rev > 0x3f) { /* U3H */
380 printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
381 __func__, rev);
382 return 0;
383 }
384
Harry Ciao8f101a02009-06-17 16:28:00 -0700385 pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
386 if (IS_ERR(pdev))
387 return PTR_ERR(pdev);
388
389 printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
390
391 return 0;
392}
393machine_device_initcall(maple, maple_cpc925_edac_setup);
394#endif