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