]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/powerpc/platforms/maple/setup.c
[POWERPC] Maple: use mmio nvram
[linux-2.6.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/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 #include <asm/nvram.h>
66
67 #include "maple.h"
68
69 #ifdef DEBUG
70 #define DBG(fmt...) udbg_printf(fmt)
71 #else
72 #define DBG(fmt...)
73 #endif
74
75 static unsigned long maple_find_nvram_base(void)
76 {
77         struct device_node *rtcs;
78         unsigned long result = 0;
79
80         /* find NVRAM device */
81         rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
82         if (rtcs) {
83                 struct resource r;
84                 if (of_address_to_resource(rtcs, 0, &r)) {
85                         printk(KERN_EMERG "Maple: Unable to translate NVRAM"
86                                " address\n");
87                         goto bail;
88                 }
89                 if (!(r.flags & IORESOURCE_IO)) {
90                         printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
91                         goto bail;
92                 }
93                 result = r.start;
94         } else
95                 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
96  bail:
97         of_node_put(rtcs);
98         return result;
99 }
100
101 static void maple_restart(char *cmd)
102 {
103         unsigned int maple_nvram_base;
104         const unsigned int *maple_nvram_offset, *maple_nvram_command;
105         struct device_node *sp;
106
107         maple_nvram_base = maple_find_nvram_base();
108         if (maple_nvram_base == 0)
109                 goto fail;
110
111         /* find service processor device */
112         sp = of_find_node_by_name(NULL, "service-processor");
113         if (!sp) {
114                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
115                 goto fail;
116         }
117         maple_nvram_offset = get_property(sp, "restart-addr", NULL);
118         maple_nvram_command = get_property(sp, "restart-value", NULL);
119         of_node_put(sp);
120
121         /* send command */
122         outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
123         for (;;) ;
124  fail:
125         printk(KERN_EMERG "Maple: Manual Restart Required\n");
126 }
127
128 static void maple_power_off(void)
129 {
130         unsigned int maple_nvram_base;
131         const unsigned int *maple_nvram_offset, *maple_nvram_command;
132         struct device_node *sp;
133
134         maple_nvram_base = maple_find_nvram_base();
135         if (maple_nvram_base == 0)
136                 goto fail;
137
138         /* find service processor device */
139         sp = of_find_node_by_name(NULL, "service-processor");
140         if (!sp) {
141                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
142                 goto fail;
143         }
144         maple_nvram_offset = get_property(sp, "power-off-addr", NULL);
145         maple_nvram_command = get_property(sp, "power-off-value", NULL);
146         of_node_put(sp);
147
148         /* send command */
149         outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
150         for (;;) ;
151  fail:
152         printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
153 }
154
155 static void maple_halt(void)
156 {
157         maple_power_off();
158 }
159
160 #ifdef CONFIG_SMP
161 struct smp_ops_t maple_smp_ops = {
162         .probe          = smp_mpic_probe,
163         .message_pass   = smp_mpic_message_pass,
164         .kick_cpu       = smp_generic_kick_cpu,
165         .setup_cpu      = smp_mpic_setup_cpu,
166         .give_timebase  = smp_generic_give_timebase,
167         .take_timebase  = smp_generic_take_timebase,
168 };
169 #endif /* CONFIG_SMP */
170
171 static void __init maple_use_rtas_reboot_and_halt_if_present(void)
172 {
173         if (rtas_service_present("system-reboot") &&
174             rtas_service_present("power-off")) {
175                 ppc_md.restart = rtas_restart;
176                 ppc_md.power_off = rtas_power_off;
177                 ppc_md.halt = rtas_halt;
178         }
179 }
180
181 void __init maple_setup_arch(void)
182 {
183         /* init to some ~sane value until calibrate_delay() runs */
184         loops_per_jiffy = 50000000;
185
186         /* Setup SMP callback */
187 #ifdef CONFIG_SMP
188         smp_ops = &maple_smp_ops;
189 #endif
190         /* Lookup PCI hosts */
191         maple_pci_init();
192
193 #ifdef CONFIG_DUMMY_CONSOLE
194         conswitchp = &dummy_con;
195 #endif
196         maple_use_rtas_reboot_and_halt_if_present();
197
198         printk(KERN_DEBUG "Using native/NAP idle loop\n");
199
200         mmio_nvram_init();
201 }
202
203 /* 
204  * Early initialization.
205  */
206 static void __init maple_init_early(void)
207 {
208         DBG(" -> maple_init_early\n");
209
210         iommu_init_early_dart();
211
212         DBG(" <- maple_init_early\n");
213 }
214
215 /*
216  * This is almost identical to pSeries and CHRP. We need to make that
217  * code generic at one point, with appropriate bits in the device-tree to
218  * identify the presence of an HT APIC
219  */
220 static void __init maple_init_IRQ(void)
221 {
222         struct device_node *root, *np, *mpic_node = NULL;
223         const unsigned int *opprop;
224         unsigned long openpic_addr = 0;
225         int naddr, n, i, opplen, has_isus = 0;
226         struct mpic *mpic;
227         unsigned int flags = MPIC_PRIMARY;
228
229         /* Locate MPIC in the device-tree. Note that there is a bug
230          * in Maple device-tree where the type of the controller is
231          * open-pic and not interrupt-controller
232          */
233
234         for_each_node_by_type(np, "interrupt-controller")
235                 if (device_is_compatible(np, "open-pic")) {
236                         mpic_node = np;
237                         break;
238                 }
239         if (mpic_node == NULL)
240                 for_each_node_by_type(np, "open-pic") {
241                         mpic_node = np;
242                         break;
243                 }
244         if (mpic_node == NULL) {
245                 printk(KERN_ERR
246                        "Failed to locate the MPIC interrupt controller\n");
247                 return;
248         }
249
250         /* Find address list in /platform-open-pic */
251         root = of_find_node_by_path("/");
252         naddr = prom_n_addr_cells(root);
253         opprop = get_property(root, "platform-open-pic", &opplen);
254         if (opprop != 0) {
255                 openpic_addr = of_read_number(opprop, naddr);
256                 has_isus = (opplen > naddr);
257                 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
258                        openpic_addr, has_isus);
259         }
260
261         BUG_ON(openpic_addr == 0);
262
263         /* Check for a big endian MPIC */
264         if (get_property(np, "big-endian", NULL) != NULL)
265                 flags |= MPIC_BIG_ENDIAN;
266
267         /* XXX Maple specific bits */
268         flags |= MPIC_BROKEN_U3 | MPIC_WANTS_RESET;
269         /* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
270         flags |= MPIC_BIG_ENDIAN;
271
272         /* Setup the openpic driver. More device-tree junks, we hard code no
273          * ISUs for now. I'll have to revisit some stuffs with the folks doing
274          * the firmware for those
275          */
276         mpic = mpic_alloc(mpic_node, openpic_addr, flags,
277                           /*has_isus ? 16 :*/ 0, 0, " MPIC     ");
278         BUG_ON(mpic == NULL);
279
280         /* Add ISUs */
281         opplen /= sizeof(u32);
282         for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
283                 unsigned long isuaddr = of_read_number(opprop + i, naddr);
284                 mpic_assign_isu(mpic, n, isuaddr);
285         }
286
287         /* All ISUs are setup, complete initialization */
288         mpic_init(mpic);
289         ppc_md.get_irq = mpic_get_irq;
290         of_node_put(mpic_node);
291         of_node_put(root);
292 }
293
294 static void __init maple_progress(char *s, unsigned short hex)
295 {
296         printk("*** %04x : %s\n", hex, s ? s : "");
297 }
298
299
300 /*
301  * Called very early, MMU is off, device-tree isn't unflattened
302  */
303 static int __init maple_probe(void)
304 {
305         unsigned long root = of_get_flat_dt_root();
306
307         if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
308             !of_flat_dt_is_compatible(root, "Momentum,Apache"))
309                 return 0;
310         /*
311          * On U3, the DART (iommu) must be allocated now since it
312          * has an impact on htab_initialize (due to the large page it
313          * occupies having to be broken up so the DART itself is not
314          * part of the cacheable linar mapping
315          */
316         alloc_dart_table();
317
318         hpte_init_native();
319
320         return 1;
321 }
322
323 define_machine(maple_md) {
324         .name                   = "Maple",
325         .probe                  = maple_probe,
326         .setup_arch             = maple_setup_arch,
327         .init_early             = maple_init_early,
328         .init_IRQ               = maple_init_IRQ,
329         .pci_irq_fixup          = maple_pci_irq_fixup,
330         .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
331         .restart                = maple_restart,
332         .power_off              = maple_power_off,
333         .halt                   = maple_halt,
334         .get_boot_time          = maple_get_boot_time,
335         .set_rtc_time           = maple_set_rtc_time,
336         .get_rtc_time           = maple_get_rtc_time,
337         .calibrate_decr         = generic_calibrate_decr,
338         .progress               = maple_progress,
339         .power_save             = power4_idle,
340 #ifdef CONFIG_KEXEC
341         .machine_kexec          = default_machine_kexec,
342         .machine_kexec_prepare  = default_machine_kexec_prepare,
343         .machine_crash_shutdown = default_machine_crash_shutdown,
344 #endif
345 };