blob: f2b41243342c483a63088c5d5f8228744b09c2ef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/ppc/kernel/setup.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 * Adapted from 'alpha' version by Gary Thomas
6 * Modified by Cort Dougan (cort@cs.nmt.edu)
7 * Modified by PPC64 Team, IBM Corp
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15/*
16 * bootup setup stuff..
17 */
18
19#undef DEBUG
20
21#include <linux/config.h>
22#include <linux/errno.h>
23#include <linux/sched.h>
24#include <linux/kernel.h>
25#include <linux/mm.h>
26#include <linux/stddef.h>
27#include <linux/unistd.h>
28#include <linux/slab.h>
29#include <linux/user.h>
30#include <linux/a.out.h>
31#include <linux/tty.h>
32#include <linux/major.h>
33#include <linux/interrupt.h>
34#include <linux/reboot.h>
35#include <linux/init.h>
36#include <linux/ioport.h>
37#include <linux/console.h>
38#include <linux/pci.h>
39#include <linux/version.h>
40#include <linux/adb.h>
41#include <linux/module.h>
42#include <linux/delay.h>
43#include <linux/irq.h>
44#include <linux/seq_file.h>
45#include <linux/root_dev.h>
46
47#include <asm/mmu.h>
48#include <asm/processor.h>
49#include <asm/io.h>
50#include <asm/pgtable.h>
51#include <asm/prom.h>
52#include <asm/rtas.h>
53#include <asm/pci-bridge.h>
54#include <asm/iommu.h>
55#include <asm/dma.h>
56#include <asm/machdep.h>
57#include <asm/irq.h>
58#include <asm/time.h>
59#include <asm/nvram.h>
60#include <asm/plpar_wrappers.h>
61#include <asm/xics.h>
62#include <asm/cputable.h>
63
64#include "i8259.h"
65#include "mpic.h"
66#include "pci.h"
67
68#ifdef DEBUG
69#define DBG(fmt...) udbg_printf(fmt)
70#else
71#define DBG(fmt...)
72#endif
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern void find_udbg_vterm(void);
75extern void system_reset_fwnmi(void); /* from head.S */
76extern void machine_check_fwnmi(void); /* from head.S */
77extern void generic_find_legacy_serial_ports(u64 *physport,
78 unsigned int *default_speed);
79
80int fwnmi_active; /* TRUE if an FWNMI handler is present */
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern void pSeries_system_reset_exception(struct pt_regs *regs);
83extern int pSeries_machine_check_exception(struct pt_regs *regs);
84
85static volatile void __iomem * chrp_int_ack_special;
86struct mpic *pSeries_mpic;
87
88void pSeries_get_cpuinfo(struct seq_file *m)
89{
90 struct device_node *root;
91 const char *model = "";
92
93 root = of_find_node_by_path("/");
94 if (root)
95 model = get_property(root, "model", NULL);
96 seq_printf(m, "machine\t\t: CHRP %s\n", model);
97 of_node_put(root);
98}
99
100/* Initialize firmware assisted non-maskable interrupts if
101 * the firmware supports this feature.
102 *
103 */
104static void __init fwnmi_init(void)
105{
106 int ret;
107 int ibm_nmi_register = rtas_token("ibm,nmi-register");
108 if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
109 return;
110 ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
111 __pa((unsigned long)system_reset_fwnmi),
112 __pa((unsigned long)machine_check_fwnmi));
113 if (ret == 0)
114 fwnmi_active = 1;
115}
116
117static int pSeries_irq_cascade(struct pt_regs *regs, void *data)
118{
119 if (chrp_int_ack_special)
120 return readb(chrp_int_ack_special);
121 else
122 return i8259_irq(smp_processor_id());
123}
124
125static void __init pSeries_init_mpic(void)
126{
127 unsigned int *addrp;
128 struct device_node *np;
129 int i;
130
131 /* All ISUs are setup, complete initialization */
132 mpic_init(pSeries_mpic);
133
134 /* Check what kind of cascade ACK we have */
135 if (!(np = of_find_node_by_name(NULL, "pci"))
136 || !(addrp = (unsigned int *)
137 get_property(np, "8259-interrupt-acknowledge", NULL)))
138 printk(KERN_ERR "Cannot find pci to get ack address\n");
139 else
140 chrp_int_ack_special = ioremap(addrp[prom_n_addr_cells(np)-1], 1);
141 of_node_put(np);
142
143 /* Setup the legacy interrupts & controller */
144 for (i = 0; i < NUM_ISA_INTERRUPTS; i++)
145 irq_desc[i].handler = &i8259_pic;
146 i8259_init(0);
147
148 /* Hook cascade to mpic */
149 mpic_setup_cascade(NUM_ISA_INTERRUPTS, pSeries_irq_cascade, NULL);
150}
151
152static void __init pSeries_setup_mpic(void)
153{
154 unsigned int *opprop;
155 unsigned long openpic_addr = 0;
156 unsigned char senses[NR_IRQS - NUM_ISA_INTERRUPTS];
157 struct device_node *root;
158 int irq_count;
159
160 /* Find the Open PIC if present */
161 root = of_find_node_by_path("/");
162 opprop = (unsigned int *) get_property(root, "platform-open-pic", NULL);
163 if (opprop != 0) {
164 int n = prom_n_addr_cells(root);
165
166 for (openpic_addr = 0; n > 0; --n)
167 openpic_addr = (openpic_addr << 32) + *opprop++;
168 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
169 }
170 of_node_put(root);
171
172 BUG_ON(openpic_addr == 0);
173
174 /* Get the sense values from OF */
175 prom_get_irq_senses(senses, NUM_ISA_INTERRUPTS, NR_IRQS);
176
177 /* Setup the openpic driver */
178 irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
179 pSeries_mpic = mpic_alloc(openpic_addr, MPIC_PRIMARY,
180 16, 16, irq_count, /* isu size, irq offset, irq count */
181 NR_IRQS - 4, /* ipi offset */
182 senses, irq_count, /* sense & sense size */
183 " MPIC ");
184}
185
186static void __init pSeries_setup_arch(void)
187{
188 /* Fixup ppc_md depending on the type of interrupt controller */
189 if (ppc64_interrupt_controller == IC_OPEN_PIC) {
190 ppc_md.init_IRQ = pSeries_init_mpic;
191 ppc_md.get_irq = mpic_get_irq;
192 /* Allocate the mpic now, so that find_and_init_phbs() can
193 * fill the ISUs */
194 pSeries_setup_mpic();
195 } else {
196 ppc_md.init_IRQ = xics_init_IRQ;
197 ppc_md.get_irq = xics_get_irq;
198 }
199
200#ifdef CONFIG_SMP
201 smp_init_pSeries();
202#endif
203 /* openpic global configuration register (64-bit format). */
204 /* openpic Interrupt Source Unit pointer (64-bit format). */
205 /* python0 facility area (mmio) (64-bit format) REAL address. */
206
207 /* init to some ~sane value until calibrate_delay() runs */
208 loops_per_jiffy = 50000000;
209
210 if (ROOT_DEV == 0) {
211 printk("No ramdisk, default root is /dev/sda2\n");
212 ROOT_DEV = Root_SDA2;
213 }
214
215 fwnmi_init();
216
217 /* Find and initialize PCI host bridges */
218 init_pci_config_tokens();
219 eeh_init();
220 find_and_init_phbs();
221
222#ifdef CONFIG_DUMMY_CONSOLE
223 conswitchp = &dummy_con;
224#endif
225
226 pSeries_nvram_init();
227
228 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR)
229 vpa_init(boot_cpuid);
230}
231
232static int __init pSeries_init_panel(void)
233{
234 /* Manually leave the kernel version on the panel. */
235 ppc_md.progress("Linux ppc64\n", 0);
236 ppc_md.progress(UTS_RELEASE, 0);
237
238 return 0;
239}
240arch_initcall(pSeries_init_panel);
241
242
243/* Build up the firmware_features bitmask field
244 * using contents of device-tree/ibm,hypertas-functions.
245 * Ultimately this functionality may be moved into prom.c prom_init().
246 */
247void __init fw_feature_init(void)
248{
249 struct device_node * dn;
250 char * hypertas;
251 unsigned int len;
252
253 DBG(" -> fw_feature_init()\n");
254
255 cur_cpu_spec->firmware_features = 0;
256 dn = of_find_node_by_path("/rtas");
257 if (dn == NULL) {
258 printk(KERN_ERR "WARNING ! Cannot find RTAS in device-tree !\n");
259 goto no_rtas;
260 }
261
262 hypertas = get_property(dn, "ibm,hypertas-functions", &len);
263 if (hypertas) {
264 while (len > 0){
265 int i, hypertas_len;
266 /* check value against table of strings */
267 for(i=0; i < FIRMWARE_MAX_FEATURES ;i++) {
268 if ((firmware_features_table[i].name) &&
269 (strcmp(firmware_features_table[i].name,hypertas))==0) {
270 /* we have a match */
271 cur_cpu_spec->firmware_features |=
272 (firmware_features_table[i].val);
273 break;
274 }
275 }
276 hypertas_len = strlen(hypertas);
277 len -= hypertas_len +1;
278 hypertas+= hypertas_len +1;
279 }
280 }
281
282 of_node_put(dn);
283 no_rtas:
284 printk(KERN_INFO "firmware_features = 0x%lx\n",
285 cur_cpu_spec->firmware_features);
286
287 DBG(" <- fw_feature_init()\n");
288}
289
290
291static void __init pSeries_discover_pic(void)
292{
293 struct device_node *np;
294 char *typep;
295
296 /*
297 * Setup interrupt mapping options that are needed for finish_device_tree
298 * to properly parse the OF interrupt tree & do the virtual irq mapping
299 */
300 __irq_offset_value = NUM_ISA_INTERRUPTS;
301 ppc64_interrupt_controller = IC_INVALID;
302 for (np = NULL; (np = of_find_node_by_name(np, "interrupt-controller"));) {
303 typep = (char *)get_property(np, "compatible", NULL);
304 if (strstr(typep, "open-pic"))
305 ppc64_interrupt_controller = IC_OPEN_PIC;
306 else if (strstr(typep, "ppc-xicp"))
307 ppc64_interrupt_controller = IC_PPC_XIC;
308 else
309 printk("pSeries_discover_pic: failed to recognize"
310 " interrupt-controller\n");
311 break;
312 }
313}
314
315static void pSeries_mach_cpu_die(void)
316{
317 local_irq_disable();
318 idle_task_exit();
319 /* Some hardware requires clearing the CPPR, while other hardware does not
320 * it is safe either way
321 */
322 pSeriesLP_cppr_info(0, 0);
323 rtas_stop_self();
324 /* Should never get here... */
325 BUG();
326 for(;;);
327}
328
329
330/*
331 * Early initialization. Relocation is on but do not reference unbolted pages
332 */
333static void __init pSeries_init_early(void)
334{
335 void *comport;
336 int iommu_off = 0;
337 unsigned int default_speed;
338 u64 physport;
339
340 DBG(" -> pSeries_init_early()\n");
341
342 fw_feature_init();
343
344 if (systemcfg->platform & PLATFORM_LPAR)
345 hpte_init_lpar();
346 else {
347 hpte_init_native();
348 iommu_off = (of_chosen &&
349 get_property(of_chosen, "linux,iommu-off", NULL));
350 }
351
352 generic_find_legacy_serial_ports(&physport, &default_speed);
353
354 if (systemcfg->platform & PLATFORM_LPAR)
355 find_udbg_vterm();
356 else if (physport) {
357 /* Map the uart for udbg. */
Benjamin Herrenschmidtdfbacdc2005-04-16 15:24:33 -0700358 comport = (void *)ioremap(physport, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 udbg_init_uart(comport, default_speed);
360
361 ppc_md.udbg_putc = udbg_putc;
362 ppc_md.udbg_getc = udbg_getc;
363 ppc_md.udbg_getc_poll = udbg_getc_poll;
364 DBG("Hello World !\n");
365 }
366
367
368 iommu_init_early_pSeries();
369
370 pSeries_discover_pic();
371
372 DBG(" <- pSeries_init_early()\n");
373}
374
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376static int pSeries_check_legacy_ioport(unsigned int baseport)
377{
378 struct device_node *np;
379
380#define I8042_DATA_REG 0x60
381#define FDC_BASE 0x3f0
382
383
384 switch(baseport) {
385 case I8042_DATA_REG:
386 np = of_find_node_by_type(NULL, "8042");
387 if (np == NULL)
388 return -ENODEV;
389 of_node_put(np);
390 break;
391 case FDC_BASE:
392 np = of_find_node_by_type(NULL, "fdc");
393 if (np == NULL)
394 return -ENODEV;
395 of_node_put(np);
396 break;
397 }
398 return 0;
399}
400
401/*
402 * Called very early, MMU is off, device-tree isn't unflattened
403 */
404extern struct machdep_calls pSeries_md;
405
406static int __init pSeries_probe(int platform)
407{
408 if (platform != PLATFORM_PSERIES &&
409 platform != PLATFORM_PSERIES_LPAR)
410 return 0;
411
412 /* if we have some ppc_md fixups for LPAR to do, do
413 * it here ...
414 */
415
416 return 1;
417}
418
419struct machdep_calls __initdata pSeries_md = {
420 .probe = pSeries_probe,
421 .setup_arch = pSeries_setup_arch,
422 .init_early = pSeries_init_early,
423 .get_cpuinfo = pSeries_get_cpuinfo,
424 .log_error = pSeries_log_error,
425 .pcibios_fixup = pSeries_final_fixup,
John Rosedad32bb2005-06-23 17:09:54 +1000426 .irq_bus_setup = pSeries_irq_bus_setup,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 .restart = rtas_restart,
428 .power_off = rtas_power_off,
429 .halt = rtas_halt,
430 .panic = rtas_os_term,
431 .cpu_die = pSeries_mach_cpu_die,
Arnd Bergmann773bf9c2005-06-23 09:43:18 +1000432 .get_boot_time = rtas_get_boot_time,
433 .get_rtc_time = rtas_get_rtc_time,
434 .set_rtc_time = rtas_set_rtc_time,
Arnd Bergmann10f7e7c2005-06-23 09:43:07 +1000435 .calibrate_decr = generic_calibrate_decr,
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000436 .progress = rtas_progress,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 .check_legacy_ioport = pSeries_check_legacy_ioport,
438 .system_reset_exception = pSeries_system_reset_exception,
439 .machine_check_exception = pSeries_machine_check_exception,
440};