powerpc/dart: Use a cachable DART
[cascardo/linux.git] / arch / powerpc / platforms / maple / setup.c
1 /*
2  *  Maple (970 eval board) setup code
3  *
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 #undef DEBUG
15
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/export.h>
21 #include <linux/mm.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/user.h>
26 #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>
34 #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>
43 #include <linux/bitops.h>
44 #include <linux/of_device.h>
45 #include <linux/memblock.h>
46
47 #include <asm/processor.h>
48 #include <asm/sections.h>
49 #include <asm/prom.h>
50 #include <asm/pgtable.h>
51 #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>
58 #include <asm/mpic.h>
59 #include <asm/rtas.h>
60 #include <asm/udbg.h>
61 #include <asm/nvram.h>
62
63 #include "maple.h"
64
65 #ifdef DEBUG
66 #define DBG(fmt...) udbg_printf(fmt)
67 #else
68 #define DBG(fmt...)
69 #endif
70
71 static 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
97 static void __noreturn maple_restart(char *cmd)
98 {
99         unsigned int maple_nvram_base;
100         const unsigned int *maple_nvram_offset, *maple_nvram_command;
101         struct device_node *sp;
102
103         maple_nvram_base = maple_find_nvram_base();
104         if (maple_nvram_base == 0)
105                 goto fail;
106
107         /* find service processor device */
108         sp = of_find_node_by_name(NULL, "service-processor");
109         if (!sp) {
110                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
111                 goto fail;
112         }
113         maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
114         maple_nvram_command = of_get_property(sp, "restart-value", NULL);
115         of_node_put(sp);
116
117         /* send command */
118         outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
119         for (;;) ;
120  fail:
121         printk(KERN_EMERG "Maple: Manual Restart Required\n");
122         for (;;) ;
123 }
124
125 static void __noreturn maple_power_off(void)
126 {
127         unsigned int maple_nvram_base;
128         const unsigned int *maple_nvram_offset, *maple_nvram_command;
129         struct device_node *sp;
130
131         maple_nvram_base = maple_find_nvram_base();
132         if (maple_nvram_base == 0)
133                 goto fail;
134
135         /* find service processor device */
136         sp = of_find_node_by_name(NULL, "service-processor");
137         if (!sp) {
138                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
139                 goto fail;
140         }
141         maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
142         maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
143         of_node_put(sp);
144
145         /* send command */
146         outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
147         for (;;) ;
148  fail:
149         printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
150         for (;;) ;
151 }
152
153 static void __noreturn maple_halt(void)
154 {
155         maple_power_off();
156 }
157
158 #ifdef CONFIG_SMP
159 struct 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
169 static 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                 pm_power_off = rtas_power_off;
175                 ppc_md.halt = rtas_halt;
176         }
177 }
178
179 void __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
194         maple_use_rtas_reboot_and_halt_if_present();
195
196         printk(KERN_DEBUG "Using native/NAP idle loop\n");
197
198         mmio_nvram_init();
199 }
200
201 /* 
202  * Early initialization.
203  */
204 static void __init maple_init_early(void)
205 {
206         DBG(" -> maple_init_early\n");
207
208         iommu_init_early_dart(&maple_pci_controller_ops);
209
210         DBG(" <- maple_init_early\n");
211 }
212
213 /*
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  */
218 static void __init maple_init_IRQ(void)
219 {
220         struct device_node *root, *np, *mpic_node = NULL;
221         const unsigned int *opprop;
222         unsigned long openpic_addr = 0;
223         int naddr, n, i, opplen, has_isus = 0;
224         struct mpic *mpic;
225         unsigned int flags = 0;
226
227         /* 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          */
231
232         for_each_node_by_type(np, "interrupt-controller")
233                 if (of_device_is_compatible(np, "open-pic")) {
234                         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                 }
242         if (mpic_node == NULL) {
243                 printk(KERN_ERR
244                        "Failed to locate the MPIC interrupt controller\n");
245                 return;
246         }
247
248         /* Find address list in /platform-open-pic */
249         root = of_find_node_by_path("/");
250         naddr = of_n_addr_cells(root);
251         opprop = of_get_property(root, "platform-open-pic", &opplen);
252         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         }
258
259         BUG_ON(openpic_addr == 0);
260
261         /* Check for a big endian MPIC */
262         if (of_get_property(np, "big-endian", NULL) != NULL)
263                 flags |= MPIC_BIG_ENDIAN;
264
265         /* XXX Maple specific bits */
266         flags |= MPIC_U3_HT_IRQS;
267         /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
268         flags |= MPIC_BIG_ENDIAN;
269
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     ");
276         BUG_ON(mpic == NULL);
277
278         /* 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);
290 }
291
292 static 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  */
301 static int __init maple_probe(void)
302 {
303         unsigned long root = of_get_flat_dt_root();
304
305         if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
306             !of_flat_dt_is_compatible(root, "Momentum,Apache"))
307                 return 0;
308
309         hpte_init_native();
310         pm_power_off = maple_power_off;
311
312         return 1;
313 }
314
315 define_machine(maple) {
316         .name                   = "Maple",
317         .probe                  = maple_probe,
318         .setup_arch             = maple_setup_arch,
319         .init_early             = maple_init_early,
320         .init_IRQ               = maple_init_IRQ,
321         .pci_irq_fixup          = maple_pci_irq_fixup,
322         .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
323         .restart                = maple_restart,
324         .halt                   = maple_halt,
325         .get_boot_time          = maple_get_boot_time,
326         .set_rtc_time           = maple_set_rtc_time,
327         .get_rtc_time           = maple_get_rtc_time,
328         .calibrate_decr         = generic_calibrate_decr,
329         .progress               = maple_progress,
330         .power_save             = power4_idle,
331 };
332
333 #ifdef CONFIG_EDAC
334 /*
335  * Register a platform device for CPC925 memory controller on
336  * all boards with U3H (CPC925) bridge.
337  */
338 static int __init maple_cpc925_edac_setup(void)
339 {
340         struct platform_device *pdev;
341         struct device_node *np = NULL;
342         struct resource r;
343         int ret;
344         volatile void __iomem *mem;
345         u32 rev;
346
347         np = of_find_node_by_type(NULL, "memory-controller");
348         if (!np) {
349                 printk(KERN_ERR "%s: Unable to find memory-controller node\n",
350                         __func__);
351                 return -ENODEV;
352         }
353
354         ret = of_address_to_resource(np, 0, &r);
355         of_node_put(np);
356
357         if (ret < 0) {
358                 printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
359                         __func__);
360                 return -ENODEV;
361         }
362
363         mem = ioremap(r.start, resource_size(&r));
364         if (!mem) {
365                 printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
366                                 __func__);
367                 return -ENOMEM;
368         }
369
370         rev = __raw_readl(mem);
371         iounmap(mem);
372
373         if (rev < 0x34 || rev > 0x3f) { /* U3H */
374                 printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
375                         __func__, rev);
376                 return 0;
377         }
378
379         pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
380         if (IS_ERR(pdev))
381                 return PTR_ERR(pdev);
382
383         printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
384
385         return 0;
386 }
387 machine_device_initcall(maple, maple_cpc925_edac_setup);
388 #endif