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