Pull release into acpica 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 #define DEBUG
15
16 #include <linux/config.h>
17 #include <linux/init.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/slab.h>
26 #include <linux/user.h>
27 #include <linux/a.out.h>
28 #include <linux/tty.h>
29 #include <linux/string.h>
30 #include <linux/delay.h>
31 #include <linux/ioport.h>
32 #include <linux/major.h>
33 #include <linux/initrd.h>
34 #include <linux/vt_kern.h>
35 #include <linux/console.h>
36 #include <linux/ide.h>
37 #include <linux/pci.h>
38 #include <linux/adb.h>
39 #include <linux/cuda.h>
40 #include <linux/pmu.h>
41 #include <linux/irq.h>
42 #include <linux/seq_file.h>
43 #include <linux/root_dev.h>
44 #include <linux/serial.h>
45 #include <linux/smp.h>
46
47 #include <asm/processor.h>
48 #include <asm/sections.h>
49 #include <asm/prom.h>
50 #include <asm/system.h>
51 #include <asm/pgtable.h>
52 #include <asm/bitops.h>
53 #include <asm/io.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 extern void generic_find_legacy_serial_ports(u64 *physport,
74                 unsigned int *default_speed);
75
76 static void maple_restart(char *cmd)
77 {
78         unsigned int maple_nvram_base;
79         unsigned int maple_nvram_offset;
80         unsigned int maple_nvram_command;
81         struct device_node *rtcs;
82
83         /* find NVRAM device */
84         rtcs = find_compatible_devices("nvram", "AMD8111");
85         if (rtcs && rtcs->addrs) {
86                 maple_nvram_base = rtcs->addrs[0].address;
87         } else {
88                 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
89                 printk(KERN_EMERG "Maple: Manual Restart Required\n");
90                 return;
91         }
92
93         /* find service processor device */
94         rtcs = find_devices("service-processor");
95         if (!rtcs) {
96                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
97                 printk(KERN_EMERG "Maple: Manual Restart Required\n");
98                 return;
99         }
100         maple_nvram_offset = *(unsigned int*) get_property(rtcs,
101                         "restart-addr", NULL);
102         maple_nvram_command = *(unsigned int*) get_property(rtcs,
103                         "restart-value", NULL);
104
105         /* send command */
106         outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
107         for (;;) ;
108 }
109
110 static void maple_power_off(void)
111 {
112         unsigned int maple_nvram_base;
113         unsigned int maple_nvram_offset;
114         unsigned int maple_nvram_command;
115         struct device_node *rtcs;
116
117         /* find NVRAM device */
118         rtcs = find_compatible_devices("nvram", "AMD8111");
119         if (rtcs && rtcs->addrs) {
120                 maple_nvram_base = rtcs->addrs[0].address;
121         } else {
122                 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
123                 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
124                 return;
125         }
126
127         /* find service processor device */
128         rtcs = find_devices("service-processor");
129         if (!rtcs) {
130                 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
131                 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
132                 return;
133         }
134         maple_nvram_offset = *(unsigned int*) get_property(rtcs,
135                         "power-off-addr", NULL);
136         maple_nvram_command = *(unsigned int*) get_property(rtcs,
137                         "power-off-value", NULL);
138
139         /* send command */
140         outb_p(maple_nvram_command, maple_nvram_base + maple_nvram_offset);
141         for (;;) ;
142 }
143
144 static void maple_halt(void)
145 {
146         maple_power_off();
147 }
148
149 #ifdef CONFIG_SMP
150 struct smp_ops_t maple_smp_ops = {
151         .probe          = smp_mpic_probe,
152         .message_pass   = smp_mpic_message_pass,
153         .kick_cpu       = smp_generic_kick_cpu,
154         .setup_cpu      = smp_mpic_setup_cpu,
155         .give_timebase  = smp_generic_give_timebase,
156         .take_timebase  = smp_generic_take_timebase,
157 };
158 #endif /* CONFIG_SMP */
159
160 void __init maple_setup_arch(void)
161 {
162         /* init to some ~sane value until calibrate_delay() runs */
163         loops_per_jiffy = 50000000;
164
165         /* Setup SMP callback */
166 #ifdef CONFIG_SMP
167         smp_ops = &maple_smp_ops;
168 #endif
169         /* Lookup PCI hosts */
170         maple_pci_init();
171
172 #ifdef CONFIG_DUMMY_CONSOLE
173         conswitchp = &dummy_con;
174 #endif
175
176         printk(KERN_INFO "Using native/NAP idle loop\n");
177 }
178
179 /* 
180  * Early initialization.
181  */
182 static void __init maple_init_early(void)
183 {
184         unsigned int default_speed;
185         u64 physport;
186
187         DBG(" -> maple_init_early\n");
188
189         /* Initialize hash table, from now on, we can take hash faults
190          * and call ioremap
191          */
192         hpte_init_native();
193
194         /* Find the serial port */
195         generic_find_legacy_serial_ports(&physport, &default_speed);
196
197         DBG("phys port addr: %lx\n", (long)physport);
198
199         if (physport) {
200                 void *comport;
201                 /* Map the uart for udbg. */
202                 comport = (void *)ioremap(physport, 16);
203                 udbg_init_uart(comport, default_speed);
204
205                 DBG("Hello World !\n");
206         }
207
208         /* Setup interrupt mapping options */
209         ppc64_interrupt_controller = IC_OPEN_PIC;
210
211         iommu_init_early_u3();
212
213         DBG(" <- maple_init_early\n");
214 }
215
216
217 static __init void maple_init_IRQ(void)
218 {
219         struct device_node *root;
220         unsigned int *opprop;
221         unsigned long opic_addr;
222         struct mpic *mpic;
223         unsigned char senses[128];
224         int n;
225
226         DBG(" -> maple_init_IRQ\n");
227
228         /* XXX: Non standard, replace that with a proper openpic/mpic node
229          * in the device-tree. Find the Open PIC if present */
230         root = of_find_node_by_path("/");
231         opprop = (unsigned int *) get_property(root,
232                                 "platform-open-pic", NULL);
233         if (opprop == 0)
234                 panic("OpenPIC not found !\n");
235
236         n = prom_n_addr_cells(root);
237         for (opic_addr = 0; n > 0; --n)
238                 opic_addr = (opic_addr << 32) + *opprop++;
239         of_node_put(root);
240
241         /* Obtain sense values from device-tree */
242         prom_get_irq_senses(senses, 0, 128);
243
244         mpic = mpic_alloc(opic_addr,
245                           MPIC_PRIMARY | MPIC_BIG_ENDIAN |
246                           MPIC_BROKEN_U3 | MPIC_WANTS_RESET,
247                           0, 0, 128, 128, senses, 128, "U3-MPIC");
248         BUG_ON(mpic == NULL);
249         mpic_init(mpic);
250
251         DBG(" <- maple_init_IRQ\n");
252 }
253
254 static void __init maple_progress(char *s, unsigned short hex)
255 {
256         printk("*** %04x : %s\n", hex, s ? s : "");
257 }
258
259
260 /*
261  * Called very early, MMU is off, device-tree isn't unflattened
262  */
263 static int __init maple_probe(int platform)
264 {
265         if (platform != PLATFORM_MAPLE)
266                 return 0;
267         /*
268          * On U3, the DART (iommu) must be allocated now since it
269          * has an impact on htab_initialize (due to the large page it
270          * occupies having to be broken up so the DART itself is not
271          * part of the cacheable linar mapping
272          */
273         alloc_u3_dart_table();
274
275         return 1;
276 }
277
278 struct machdep_calls __initdata maple_md = {
279         .probe                  = maple_probe,
280         .setup_arch             = maple_setup_arch,
281         .init_early             = maple_init_early,
282         .init_IRQ               = maple_init_IRQ,
283         .get_irq                = mpic_get_irq,
284         .pcibios_fixup          = maple_pcibios_fixup,
285         .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
286         .restart                = maple_restart,
287         .power_off              = maple_power_off,
288         .halt                   = maple_halt,
289         .get_boot_time          = maple_get_boot_time,
290         .set_rtc_time           = maple_set_rtc_time,
291         .get_rtc_time           = maple_get_rtc_time,
292         .calibrate_decr         = generic_calibrate_decr,
293         .progress               = maple_progress,
294         .idle_loop              = native_idle,
295 };