blob: cb1b0b35a0c6ea66dd223e00d6fc7b6f0b93e458 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/io.h>
52#include <asm/pci-bridge.h>
53#include <asm/iommu.h>
54#include <asm/machdep.h>
55#include <asm/dma.h>
56#include <asm/cputable.h>
57#include <asm/time.h>
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +100058#include <asm/mpic.h>
Nathan Lynch9e254c42006-12-06 18:50:46 -060059#include <asm/rtas.h>
Paul Mackerras40ef8cb2005-10-10 22:50:37 +100060#include <asm/udbg.h>
Nathan Lynch4297c982007-02-05 20:01:15 -060061#include <asm/nvram.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Paul Mackerras0cb7b2a2005-10-29 22:07:56 +100063#include "maple.h"
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#ifdef DEBUG
66#define DBG(fmt...) udbg_printf(fmt)
67#else
68#define DBG(fmt...)
69#endif
70
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +110071static unsigned long maple_find_nvram_base(void)
72{
73 struct device_node *rtcs;
74 unsigned long result = 0;
75
76 /* find NVRAM device */
77 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
78 if (rtcs) {
79 struct resource r;
80 if (of_address_to_resource(rtcs, 0, &r)) {
81 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
82 " address\n");
83 goto bail;
84 }
85 if (!(r.flags & IORESOURCE_IO)) {
86 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
87 goto bail;
88 }
89 result = r.start;
90 } else
91 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
92 bail:
93 of_node_put(rtcs);
94 return result;
95}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static void maple_restart(char *cmd)
98{
David Gibsond7152fe2005-06-23 17:14:39 +100099 unsigned int maple_nvram_base;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000100 const unsigned int *maple_nvram_offset, *maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100101 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000102
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100103 maple_nvram_base = maple_find_nvram_base();
104 if (maple_nvram_base == 0)
105 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000106
107 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100108 sp = of_find_node_by_name(NULL, "service-processor");
109 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000110 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100111 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000112 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000113 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
114 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100115 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000116
117 /* send command */
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000118 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibsond7152fe2005-06-23 17:14:39 +1000119 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100120 fail:
121 printk(KERN_EMERG "Maple: Manual Restart Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
124static void maple_power_off(void)
125{
David Gibsond7152fe2005-06-23 17:14:39 +1000126 unsigned int maple_nvram_base;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000127 const unsigned int *maple_nvram_offset, *maple_nvram_command;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100128 struct device_node *sp;
David Gibsond7152fe2005-06-23 17:14:39 +1000129
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100130 maple_nvram_base = maple_find_nvram_base();
131 if (maple_nvram_base == 0)
132 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000133
134 /* find service processor device */
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100135 sp = of_find_node_by_name(NULL, "service-processor");
136 if (!sp) {
David Gibsond7152fe2005-06-23 17:14:39 +1000137 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100138 goto fail;
David Gibsond7152fe2005-06-23 17:14:39 +1000139 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000140 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
141 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100142 of_node_put(sp);
David Gibsond7152fe2005-06-23 17:14:39 +1000143
144 /* send command */
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000145 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibsond7152fe2005-06-23 17:14:39 +1000146 for (;;) ;
Benjamin Herrenschmidt4c882b02006-01-14 16:35:35 +1100147 fail:
148 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
151static void maple_halt(void)
152{
David Gibsond7152fe2005-06-23 17:14:39 +1000153 maple_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
155
156#ifdef CONFIG_SMP
157struct smp_ops_t maple_smp_ops = {
158 .probe = smp_mpic_probe,
159 .message_pass = smp_mpic_message_pass,
160 .kick_cpu = smp_generic_kick_cpu,
161 .setup_cpu = smp_mpic_setup_cpu,
162 .give_timebase = smp_generic_give_timebase,
163 .take_timebase = smp_generic_take_timebase,
164};
165#endif /* CONFIG_SMP */
166
Nathan Lynch9e254c42006-12-06 18:50:46 -0600167static void __init maple_use_rtas_reboot_and_halt_if_present(void)
168{
169 if (rtas_service_present("system-reboot") &&
170 rtas_service_present("power-off")) {
171 ppc_md.restart = rtas_restart;
172 ppc_md.power_off = rtas_power_off;
173 ppc_md.halt = rtas_halt;
174 }
175}
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177void __init maple_setup_arch(void)
178{
179 /* init to some ~sane value until calibrate_delay() runs */
180 loops_per_jiffy = 50000000;
181
182 /* Setup SMP callback */
183#ifdef CONFIG_SMP
184 smp_ops = &maple_smp_ops;
185#endif
186 /* Lookup PCI hosts */
187 maple_pci_init();
188
189#ifdef CONFIG_DUMMY_CONSOLE
190 conswitchp = &dummy_con;
191#endif
Nathan Lynch9e254c42006-12-06 18:50:46 -0600192 maple_use_rtas_reboot_and_halt_if_present();
Michael Ellerman62d60e92005-07-07 17:56:30 -0700193
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500194 printk(KERN_DEBUG "Using native/NAP idle loop\n");
Nathan Lynch4297c982007-02-05 20:01:15 -0600195
196 mmio_nvram_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
199/*
200 * Early initialization.
201 */
202static void __init maple_init_early(void)
203{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 DBG(" -> maple_init_early\n");
205
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100206 iommu_init_early_dart();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 DBG(" <- maple_init_early\n");
209}
210
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000211/*
212 * This is almost identical to pSeries and CHRP. We need to make that
213 * code generic at one point, with appropriate bits in the device-tree to
214 * identify the presence of an HT APIC
215 */
216static void __init maple_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000218 struct device_node *root, *np, *mpic_node = NULL;
Jeremy Kerreeb2b722006-07-12 15:40:17 +1000219 const unsigned int *opprop;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000220 unsigned long openpic_addr = 0;
221 int naddr, n, i, opplen, has_isus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 struct mpic *mpic;
Kyle Moffettbe8bec52011-12-02 06:28:03 +0000223 unsigned int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000225 /* Locate MPIC in the device-tree. Note that there is a bug
226 * in Maple device-tree where the type of the controller is
227 * open-pic and not interrupt-controller
228 */
Segher Boessenkool96278d22006-07-08 02:37:20 +0200229
230 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000231 if (of_device_is_compatible(np, "open-pic")) {
Segher Boessenkool96278d22006-07-08 02:37:20 +0200232 mpic_node = np;
233 break;
234 }
235 if (mpic_node == NULL)
236 for_each_node_by_type(np, "open-pic") {
237 mpic_node = np;
238 break;
239 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000240 if (mpic_node == NULL) {
241 printk(KERN_ERR
242 "Failed to locate the MPIC interrupt controller\n");
243 return;
244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000246 /* Find address list in /platform-open-pic */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 root = of_find_node_by_path("/");
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000248 naddr = of_n_addr_cells(root);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000249 opprop = of_get_property(root, "platform-open-pic", &opplen);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000250 if (opprop != 0) {
251 openpic_addr = of_read_number(opprop, naddr);
252 has_isus = (opplen > naddr);
253 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
254 openpic_addr, has_isus);
255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000257 BUG_ON(openpic_addr == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000259 /* Check for a big endian MPIC */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000260 if (of_get_property(np, "big-endian", NULL) != NULL)
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000261 flags |= MPIC_BIG_ENDIAN;
262
263 /* XXX Maple specific bits */
Kyle Moffette55d7f72011-12-22 10:19:14 +0000264 flags |= MPIC_U3_HT_IRQS;
Segher Boessenkoold319a032006-07-08 02:37:23 +0200265 /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
266 flags |= MPIC_BIG_ENDIAN;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000267
268 /* Setup the openpic driver. More device-tree junks, we hard code no
269 * ISUs for now. I'll have to revisit some stuffs with the folks doing
270 * the firmware for those
271 */
272 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
273 /*has_isus ? 16 :*/ 0, 0, " MPIC ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 BUG_ON(mpic == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000276 /* Add ISUs */
277 opplen /= sizeof(u32);
278 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
279 unsigned long isuaddr = of_read_number(opprop + i, naddr);
280 mpic_assign_isu(mpic, n, isuaddr);
281 }
282
283 /* All ISUs are setup, complete initialization */
284 mpic_init(mpic);
285 ppc_md.get_irq = mpic_get_irq;
286 of_node_put(mpic_node);
287 of_node_put(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
290static void __init maple_progress(char *s, unsigned short hex)
291{
292 printk("*** %04x : %s\n", hex, s ? s : "");
293}
294
295
296/*
297 * Called very early, MMU is off, device-tree isn't unflattened
298 */
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100299static int __init maple_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100301 unsigned long root = of_get_flat_dt_root();
Benjamin Herrenschmidt980a6512006-07-03 17:22:05 +1000302
303 if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
304 !of_flat_dt_is_compatible(root, "Momentum,Apache"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return 0;
306 /*
307 * On U3, the DART (iommu) must be allocated now since it
308 * has an impact on htab_initialize (due to the large page it
309 * occupies having to be broken up so the DART itself is not
310 * part of the cacheable linar mapping
311 */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100312 alloc_dart_table();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000314 hpte_init_native();
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return 1;
317}
318
Nathan Lynch53378c22008-03-13 10:43:03 +1100319define_machine(maple) {
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100320 .name = "Maple",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 .probe = maple_probe,
322 .setup_arch = maple_setup_arch,
323 .init_early = maple_init_early,
324 .init_IRQ = maple_init_IRQ,
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +1100325 .pci_irq_fixup = maple_pci_irq_fixup,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
327 .restart = maple_restart,
328 .power_off = maple_power_off,
329 .halt = maple_halt,
330 .get_boot_time = maple_get_boot_time,
331 .set_rtc_time = maple_set_rtc_time,
332 .get_rtc_time = maple_get_rtc_time,
Arnd Bergmann10f7e7c2005-06-23 09:43:07 +1000333 .calibrate_decr = generic_calibrate_decr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 .progress = maple_progress,
Paul Mackerrasa0652fc2006-03-27 15:03:03 +1100335 .power_save = power4_idle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336};
Harry Ciao8f101a02009-06-17 16:28:00 -0700337
338#ifdef CONFIG_EDAC
339/*
340 * Register a platform device for CPC925 memory controller on
Dmitry Eremin-Solenikov8a0360a2011-06-17 02:51:46 +0000341 * all boards with U3H (CPC925) bridge.
Harry Ciao8f101a02009-06-17 16:28:00 -0700342 */
Harry Ciao8f101a02009-06-17 16:28:00 -0700343static int __init maple_cpc925_edac_setup(void)
344{
345 struct platform_device *pdev;
346 struct device_node *np = NULL;
347 struct resource r;
Harry Ciao8f101a02009-06-17 16:28:00 -0700348 int ret;
Dmitry Eremin-Solenikov8a0360a2011-06-17 02:51:46 +0000349 volatile void __iomem *mem;
350 u32 rev;
Harry Ciao8f101a02009-06-17 16:28:00 -0700351
352 np = of_find_node_by_type(NULL, "memory-controller");
353 if (!np) {
354 printk(KERN_ERR "%s: Unable to find memory-controller node\n",
355 __func__);
356 return -ENODEV;
357 }
358
359 ret = of_address_to_resource(np, 0, &r);
360 of_node_put(np);
361
362 if (ret < 0) {
363 printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
364 __func__);
365 return -ENODEV;
366 }
367
Dmitry Eremin-Solenikov8a0360a2011-06-17 02:51:46 +0000368 mem = ioremap(r.start, resource_size(&r));
369 if (!mem) {
370 printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
371 __func__);
372 return -ENOMEM;
373 }
374
375 rev = __raw_readl(mem);
376 iounmap(mem);
377
378 if (rev < 0x34 || rev > 0x3f) { /* U3H */
379 printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
380 __func__, rev);
381 return 0;
382 }
383
Harry Ciao8f101a02009-06-17 16:28:00 -0700384 pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
385 if (IS_ERR(pdev))
386 return PTR_ERR(pdev);
387
388 printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
389
390 return 0;
391}
392machine_device_initcall(maple, maple_cpc925_edac_setup);
393#endif