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