Pull platform-drivers into test branch
[linux-2.6] / 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/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>
26 #include <linux/a.out.h>
27 #include <linux/tty.h>
28 #include <linux/string.h>
29 #include <linux/delay.h>
30 #include <linux/ioport.h>
31 #include <linux/major.h>
32 #include <linux/initrd.h>
33 #include <linux/vt_kern.h>
34 #include <linux/console.h>
35 #include <linux/ide.h>
36 #include <linux/pci.h>
37 #include <linux/adb.h>
38 #include <linux/cuda.h>
39 #include <linux/pmu.h>
40 #include <linux/irq.h>
41 #include <linux/seq_file.h>
42 #include <linux/root_dev.h>
43 #include <linux/serial.h>
44 #include <linux/smp.h>
45
46 #include <asm/processor.h>
47 #include <asm/sections.h>
48 #include <asm/prom.h>
49 #include <asm/system.h>
50 #include <asm/pgtable.h>
51 #include <asm/bitops.h>
52 #include <asm/io.h>
53 #include <asm/kexec.h>
54 #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>
60 #include <asm/of_device.h>
61 #include <asm/lmb.h>
62 #include <asm/mpic.h>
63 #include <asm/rtas.h>
64 #include <asm/udbg.h>
65
66 #include "maple.h"
67
68 #ifdef DEBUG
69 #define DBG(fmt...) udbg_printf(fmt)
70 #else
71 #define DBG(fmt...)
72 #endif
73
74 static 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
100 static void maple_restart(char *cmd)
101 {
102         unsigned int maple_nvram_base;
103         const unsigned int *maple_nvram_offset, *maple_nvram_command;
104         struct device_node *sp;
105
106         maple_nvram_base = maple_find_nvram_base();
107         if (maple_nvram_base == 0)
108                 goto fail;
109
110         /* find service processor device */
111         sp = of_find_node_by_name(NULL, "service-processor");
112         if (!sp) {
113                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
114                 goto fail;
115         }
116         maple_nvram_offset = get_property(sp, "restart-addr", NULL);
117         maple_nvram_command = get_property(sp, "restart-value", NULL);
118         of_node_put(sp);
119
120         /* send command */
121         outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
122         for (;;) ;
123  fail:
124         printk(KERN_EMERG "Maple: Manual Restart Required\n");
125 }
126
127 static void maple_power_off(void)
128 {
129         unsigned int maple_nvram_base;
130         const unsigned int *maple_nvram_offset, *maple_nvram_command;
131         struct device_node *sp;
132
133         maple_nvram_base = maple_find_nvram_base();
134         if (maple_nvram_base == 0)
135                 goto fail;
136
137         /* find service processor device */
138         sp = of_find_node_by_name(NULL, "service-processor");
139         if (!sp) {
140                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
141                 goto fail;
142         }
143         maple_nvram_offset = get_property(sp, "power-off-addr", NULL);
144         maple_nvram_command = get_property(sp, "power-off-value", NULL);
145         of_node_put(sp);
146
147         /* send command */
148         outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
149         for (;;) ;
150  fail:
151         printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
152 }
153
154 static void maple_halt(void)
155 {
156         maple_power_off();
157 }
158
159 #ifdef CONFIG_SMP
160 struct smp_ops_t maple_smp_ops = {
161         .probe          = smp_mpic_probe,
162         .message_pass   = smp_mpic_message_pass,
163         .kick_cpu       = smp_generic_kick_cpu,
164         .setup_cpu      = smp_mpic_setup_cpu,
165         .give_timebase  = smp_generic_give_timebase,
166         .take_timebase  = smp_generic_take_timebase,
167 };
168 #endif /* CONFIG_SMP */
169
170 static void __init maple_use_rtas_reboot_and_halt_if_present(void)
171 {
172         if (rtas_service_present("system-reboot") &&
173             rtas_service_present("power-off")) {
174                 ppc_md.restart = rtas_restart;
175                 ppc_md.power_off = rtas_power_off;
176                 ppc_md.halt = rtas_halt;
177         }
178 }
179
180 void __init maple_setup_arch(void)
181 {
182         /* init to some ~sane value until calibrate_delay() runs */
183         loops_per_jiffy = 50000000;
184
185         /* Setup SMP callback */
186 #ifdef CONFIG_SMP
187         smp_ops = &maple_smp_ops;
188 #endif
189         /* Lookup PCI hosts */
190         maple_pci_init();
191
192 #ifdef CONFIG_DUMMY_CONSOLE
193         conswitchp = &dummy_con;
194 #endif
195         maple_use_rtas_reboot_and_halt_if_present();
196
197         printk(KERN_DEBUG "Using native/NAP idle loop\n");
198 }
199
200 /* 
201  * Early initialization.
202  */
203 static void __init maple_init_early(void)
204 {
205         DBG(" -> maple_init_early\n");
206
207         iommu_init_early_dart();
208
209         DBG(" <- maple_init_early\n");
210 }
211
212 /*
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  */
217 static void __init maple_init_IRQ(void)
218 {
219         struct device_node *root, *np, *mpic_node = NULL;
220         const unsigned int *opprop;
221         unsigned long openpic_addr = 0;
222         int naddr, n, i, opplen, has_isus = 0;
223         struct mpic *mpic;
224         unsigned int flags = MPIC_PRIMARY;
225
226         /* 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          */
230
231         for_each_node_by_type(np, "interrupt-controller")
232                 if (device_is_compatible(np, "open-pic")) {
233                         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                 }
241         if (mpic_node == NULL) {
242                 printk(KERN_ERR
243                        "Failed to locate the MPIC interrupt controller\n");
244                 return;
245         }
246
247         /* Find address list in /platform-open-pic */
248         root = of_find_node_by_path("/");
249         naddr = prom_n_addr_cells(root);
250         opprop = get_property(root, "platform-open-pic", &opplen);
251         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         }
257         of_node_put(root);
258
259         BUG_ON(openpic_addr == 0);
260
261         /* Check for a big endian MPIC */
262         if (get_property(np, "big-endian", NULL) != NULL)
263                 flags |= MPIC_BIG_ENDIAN;
264
265         /* XXX Maple specific bits */
266         flags |= MPIC_BROKEN_U3 | MPIC_WANTS_RESET;
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          * 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          */
314         alloc_dart_table();
315
316         hpte_init_native();
317
318         return 1;
319 }
320
321 define_machine(maple_md) {
322         .name                   = "Maple",
323         .probe                  = maple_probe,
324         .setup_arch             = maple_setup_arch,
325         .init_early             = maple_init_early,
326         .init_IRQ               = maple_init_IRQ,
327         .pci_irq_fixup          = maple_pci_irq_fixup,
328         .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,
335         .calibrate_decr         = generic_calibrate_decr,
336         .progress               = maple_progress,
337         .power_save             = power4_idle,
338 #ifdef CONFIG_KEXEC
339         .machine_kexec          = default_machine_kexec,
340         .machine_kexec_prepare  = default_machine_kexec_prepare,
341         .machine_crash_shutdown = default_machine_crash_shutdown,
342 #endif
343 };