initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / ppc64 / kernel / pSeries_setup.c
blob80e0289049dc806514aa42e77bdfadea85f934d0
1 /*
2 * linux/arch/ppc/kernel/setup.c
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
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.
16 * bootup setup stuff..
19 #undef DEBUG
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>
44 #include <linux/irq.h>
45 #include <linux/seq_file.h>
46 #include <linux/root_dev.h>
48 #include <asm/mmu.h>
49 #include <asm/processor.h>
50 #include <asm/io.h>
51 #include <asm/pgtable.h>
52 #include <asm/prom.h>
53 #include <asm/rtas.h>
54 #include <asm/pci-bridge.h>
55 #include <asm/iommu.h>
56 #include <asm/dma.h>
57 #include <asm/machdep.h>
58 #include <asm/irq.h>
59 #include <asm/naca.h>
60 #include <asm/time.h>
61 #include <asm/nvram.h>
63 #include "i8259.h"
64 #include "open_pic.h"
65 #include <asm/xics.h>
66 #include <asm/ppcdebug.h>
67 #include <asm/cputable.h>
69 #ifdef DEBUG
70 #define DBG(fmt...) udbg_printf(fmt)
71 #else
72 #define DBG(fmt...)
73 #endif
75 extern void pSeries_init_openpic(void);
77 extern void find_and_init_phbs(void);
78 extern void pSeries_final_fixup(void);
80 extern void pSeries_get_boot_time(struct rtc_time *rtc_time);
81 extern void pSeries_get_rtc_time(struct rtc_time *rtc_time);
82 extern int pSeries_set_rtc_time(struct rtc_time *rtc_time);
83 extern void find_udbg_vterm(void);
84 extern void SystemReset_FWNMI(void), MachineCheck_FWNMI(void); /* from head.S */
85 int fwnmi_active; /* TRUE if an FWNMI handler is present */
87 unsigned long virtPython0Facilities = 0; // python0 facility area (memory mapped io) (64-bit format) VIRTUAL address.
89 extern unsigned long loops_per_jiffy;
91 extern unsigned long ppc_proc_freq;
92 extern unsigned long ppc_tb_freq;
94 void pSeries_get_cpuinfo(struct seq_file *m)
96 struct device_node *root;
97 const char *model = "";
99 root = of_find_node_by_path("/");
100 if (root)
101 model = get_property(root, "model", NULL);
102 seq_printf(m, "machine\t\t: CHRP %s\n", model);
103 of_node_put(root);
106 /* Initialize firmware assisted non-maskable interrupts if
107 * the firmware supports this feature.
110 static void __init fwnmi_init(void)
112 int ret;
113 int ibm_nmi_register = rtas_token("ibm,nmi-register");
114 if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
115 return;
116 ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
117 __pa((unsigned long)SystemReset_FWNMI),
118 __pa((unsigned long)MachineCheck_FWNMI));
119 if (ret == 0)
120 fwnmi_active = 1;
123 static void __init pSeries_setup_arch(void)
125 struct device_node *root;
126 unsigned int *opprop;
128 /* Fixup ppc_md depending on the type of interrupt controller */
129 if (naca->interrupt_controller == IC_OPEN_PIC) {
130 ppc_md.init_IRQ = pSeries_init_openpic;
131 ppc_md.get_irq = openpic_get_irq;
132 } else {
133 ppc_md.init_IRQ = xics_init_IRQ;
134 ppc_md.get_irq = xics_get_irq;
137 #ifdef CONFIG_SMP
138 smp_init_pSeries();
139 #endif
140 /* openpic global configuration register (64-bit format). */
141 /* openpic Interrupt Source Unit pointer (64-bit format). */
142 /* python0 facility area (mmio) (64-bit format) REAL address. */
144 /* init to some ~sane value until calibrate_delay() runs */
145 loops_per_jiffy = 50000000;
147 if (ROOT_DEV == 0) {
148 printk("No ramdisk, default root is /dev/sda2\n");
149 ROOT_DEV = Root_SDA2;
152 fwnmi_init();
154 /* Find and initialize PCI host bridges */
155 /* iSeries needs to be done much later. */
156 eeh_init();
157 find_and_init_phbs();
159 /* Find the Open PIC if present */
160 root = of_find_node_by_path("/");
161 opprop = (unsigned int *) get_property(root,
162 "platform-open-pic", NULL);
163 if (opprop != 0) {
164 int n = prom_n_addr_cells(root);
165 unsigned long openpic;
167 for (openpic = 0; n > 0; --n)
168 openpic = (openpic << 32) + *opprop++;
169 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic);
170 OpenPIC_Addr = __ioremap(openpic, 0x40000, _PAGE_NO_CACHE);
172 of_node_put(root);
174 #ifdef CONFIG_DUMMY_CONSOLE
175 conswitchp = &dummy_con;
176 #endif
178 pSeries_nvram_init();
181 static int __init pSeries_init_panel(void)
183 /* Manually leave the kernel version on the panel. */
184 ppc_md.progress("Linux ppc64\n", 0);
185 ppc_md.progress(UTS_RELEASE, 0);
187 return 0;
189 arch_initcall(pSeries_init_panel);
193 void __init pSeries_find_serial_port(void)
195 struct device_node *np;
196 unsigned long encode_phys_size = 32;
197 u32 *sizeprop;
199 struct isa_reg_property {
200 u32 space;
201 u32 address;
202 u32 size;
204 struct pci_reg_property {
205 struct pci_address addr;
206 u32 size_hi;
207 u32 size_lo;
210 DBG(" -> pSeries_find_serial_port()\n");
212 naca->serialPortAddr = 0;
214 np = of_find_node_by_path("/");
215 if (!np)
216 return;
217 sizeprop = (u32 *)get_property(np, "#size-cells", NULL);
218 if (sizeprop != NULL)
219 encode_phys_size = (*sizeprop) << 5;
221 for (np = NULL; (np = of_find_node_by_type(np, "serial"));) {
222 struct device_node *isa, *pci;
223 struct isa_reg_property *reg;
224 union pci_range *rangesp;
225 char *typep;
227 typep = (char *)get_property(np, "ibm,aix-loc", NULL);
228 if ((typep == NULL) || (typep && strcmp(typep, "S1")))
229 continue;
231 reg = (struct isa_reg_property *)get_property(np, "reg", NULL);
233 isa = of_get_parent(np);
234 if (!isa) {
235 DBG("no isa parent found\n");
236 break;
238 pci = of_get_parent(isa);
239 if (!pci) {
240 DBG("no pci parent found\n");
241 break;
244 rangesp = (union pci_range *)get_property(pci, "ranges", NULL);
246 if ( encode_phys_size == 32 )
247 naca->serialPortAddr = rangesp->pci32.phys+reg->address;
248 else {
249 naca->serialPortAddr =
250 ((((unsigned long)rangesp->pci64.phys_hi) << 32)
252 (rangesp->pci64.phys_lo)) + reg->address;
254 break;
257 DBG(" <- pSeries_find_serial_port()\n");
261 /* Build up the firmware_features bitmask field
262 * using contents of device-tree/ibm,hypertas-functions.
263 * Ultimately this functionality may be moved into prom.c prom_init().
265 void __init fw_feature_init(void)
267 struct device_node * dn;
268 char * hypertas;
269 unsigned int len;
271 DBG(" -> fw_feature_init()\n");
273 cur_cpu_spec->firmware_features = 0;
274 dn = of_find_node_by_path("/rtas");
275 if (dn == NULL) {
276 printk(KERN_ERR "WARNING ! Cannot find RTAS in device-tree !\n");
277 goto no_rtas;
280 hypertas = get_property(dn, "ibm,hypertas-functions", &len);
281 if (hypertas) {
282 while (len > 0){
283 int i, hypertas_len;
284 /* check value against table of strings */
285 for(i=0; i < FIRMWARE_MAX_FEATURES ;i++) {
286 if ((firmware_features_table[i].name) &&
287 (strcmp(firmware_features_table[i].name,hypertas))==0) {
288 /* we have a match */
289 cur_cpu_spec->firmware_features |=
290 (firmware_features_table[i].val);
291 break;
294 hypertas_len = strlen(hypertas);
295 len -= hypertas_len +1;
296 hypertas+= hypertas_len +1;
300 of_node_put(dn);
301 no_rtas:
302 printk(KERN_INFO "firmware_features = 0x%lx\n",
303 cur_cpu_spec->firmware_features);
305 DBG(" <- fw_feature_init()\n");
309 static void __init pSeries_discover_pic(void)
311 struct device_node *np;
312 char *typep;
315 * Setup interrupt mapping options that are needed for finish_device_tree
316 * to properly parse the OF interrupt tree & do the virtual irq mapping
318 __irq_offset_value = NUM_ISA_INTERRUPTS;
319 naca->interrupt_controller = IC_INVALID;
320 for (np = NULL; (np = of_find_node_by_name(np, "interrupt-controller"));) {
321 typep = (char *)get_property(np, "compatible", NULL);
322 if (strstr(typep, "open-pic"))
323 naca->interrupt_controller = IC_OPEN_PIC;
324 else if (strstr(typep, "ppc-xicp"))
325 naca->interrupt_controller = IC_PPC_XIC;
326 else
327 printk("initialize_naca: failed to recognize"
328 " interrupt-controller\n");
329 break;
334 * Early initialization. Relocation is on but do not reference unbolted pages
336 static void __init pSeries_init_early(void)
338 void *comport;
339 int iommu_off = 0;
341 DBG(" -> pSeries_init_early()\n");
343 fw_feature_init();
345 if (systemcfg->platform & PLATFORM_LPAR)
346 hpte_init_lpar();
347 else {
348 hpte_init_native();
349 iommu_off = (of_chosen &&
350 get_property(of_chosen, "linux,iommu-off", NULL));
353 pSeries_find_serial_port();
355 if (systemcfg->platform & PLATFORM_LPAR)
356 find_udbg_vterm();
357 else if (naca->serialPortAddr) {
358 /* Map the uart for udbg. */
359 comport = (void *)__ioremap(naca->serialPortAddr, 16, _PAGE_NO_CACHE);
360 udbg_init_uart(comport);
362 ppc_md.udbg_putc = udbg_putc;
363 ppc_md.udbg_getc = udbg_getc;
364 ppc_md.udbg_getc_poll = udbg_getc_poll;
365 DBG("Hello World !\n");
369 if (iommu_off)
370 pci_dma_init_direct();
371 else
372 tce_init_pSeries();
374 pSeries_discover_pic();
376 DBG(" <- pSeries_init_early()\n");
380 static void pSeries_progress(char *s, unsigned short hex)
382 struct device_node *root;
383 int width, *p;
384 char *os;
385 static int display_character, set_indicator;
386 static int max_width;
387 static spinlock_t progress_lock = SPIN_LOCK_UNLOCKED;
388 static int pending_newline = 0; /* did last write end with unprinted newline? */
390 if (!rtas.base)
391 return;
393 if (max_width == 0) {
394 if ((root = find_path_device("/rtas")) &&
395 (p = (unsigned int *)get_property(root,
396 "ibm,display-line-length",
397 NULL)))
398 max_width = *p;
399 else
400 max_width = 0x10;
401 display_character = rtas_token("display-character");
402 set_indicator = rtas_token("set-indicator");
405 if (display_character == RTAS_UNKNOWN_SERVICE) {
406 /* use hex display if available */
407 if (set_indicator != RTAS_UNKNOWN_SERVICE)
408 rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
409 return;
412 spin_lock(&progress_lock);
415 * Last write ended with newline, but we didn't print it since
416 * it would just clear the bottom line of output. Print it now
417 * instead.
419 * If no newline is pending, print a CR to start output at the
420 * beginning of the line.
422 if (pending_newline) {
423 rtas_call(display_character, 1, 1, NULL, '\r');
424 rtas_call(display_character, 1, 1, NULL, '\n');
425 pending_newline = 0;
426 } else {
427 rtas_call(display_character, 1, 1, NULL, '\r');
430 width = max_width;
431 os = s;
432 while (*os) {
433 if (*os == '\n' || *os == '\r') {
434 /* Blank to end of line. */
435 while (width-- > 0)
436 rtas_call(display_character, 1, 1, NULL, ' ');
438 /* If newline is the last character, save it
439 * until next call to avoid bumping up the
440 * display output.
442 if (*os == '\n' && !os[1]) {
443 pending_newline = 1;
444 spin_unlock(&progress_lock);
445 return;
448 /* RTAS wants CR-LF, not just LF */
450 if (*os == '\n') {
451 rtas_call(display_character, 1, 1, NULL, '\r');
452 rtas_call(display_character, 1, 1, NULL, '\n');
453 } else {
454 /* CR might be used to re-draw a line, so we'll
455 * leave it alone and not add LF.
457 rtas_call(display_character, 1, 1, NULL, *os);
460 width = max_width;
461 } else {
462 width--;
463 rtas_call(display_character, 1, 1, NULL, *os);
466 os++;
468 /* if we overwrite the screen length */
469 if (width <= 0)
470 while ((*os != 0) && (*os != '\n') && (*os != '\r'))
471 os++;
474 /* Blank to end of line. */
475 while (width-- > 0)
476 rtas_call(display_character, 1, 1, NULL, ' ');
478 spin_unlock(&progress_lock);
481 extern void setup_default_decr(void);
483 /* Some sane defaults: 125 MHz timebase, 1GHz processor */
484 #define DEFAULT_TB_FREQ 125000000UL
485 #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
487 static void __init pSeries_calibrate_decr(void)
489 struct device_node *cpu;
490 struct div_result divres;
491 unsigned int *fp;
492 int node_found;
495 * The cpu node should have a timebase-frequency property
496 * to tell us the rate at which the decrementer counts.
498 cpu = of_find_node_by_type(NULL, "cpu");
500 ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */
501 node_found = 0;
502 if (cpu != 0) {
503 fp = (unsigned int *)get_property(cpu, "timebase-frequency",
504 NULL);
505 if (fp != 0) {
506 node_found = 1;
507 ppc_tb_freq = *fp;
510 if (!node_found)
511 printk(KERN_ERR "WARNING: Estimating decrementer frequency "
512 "(not found)\n");
514 ppc_proc_freq = DEFAULT_PROC_FREQ;
515 node_found = 0;
516 if (cpu != 0) {
517 fp = (unsigned int *)get_property(cpu, "clock-frequency",
518 NULL);
519 if (fp != 0) {
520 node_found = 1;
521 ppc_proc_freq = *fp;
524 if (!node_found)
525 printk(KERN_ERR "WARNING: Estimating processor frequency "
526 "(not found)\n");
528 of_node_put(cpu);
530 printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
531 ppc_tb_freq/1000000, ppc_tb_freq%1000000);
532 printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n",
533 ppc_proc_freq/1000000, ppc_proc_freq%1000000);
535 tb_ticks_per_jiffy = ppc_tb_freq / HZ;
536 tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
537 tb_ticks_per_usec = ppc_tb_freq / 1000000;
538 tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
539 div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
540 tb_to_xs = divres.result_low;
542 setup_default_decr();
546 * Called very early, MMU is off, device-tree isn't unflattened
548 extern struct machdep_calls pSeries_md;
550 static int __init pSeries_probe(int platform)
552 if (platform != PLATFORM_PSERIES &&
553 platform != PLATFORM_PSERIES_LPAR)
554 return 0;
556 /* if we have some ppc_md fixups for LPAR to do, do
557 * it here ...
560 return 1;
563 struct machdep_calls __initdata pSeries_md = {
564 .probe = pSeries_probe,
565 .setup_arch = pSeries_setup_arch,
566 .init_early = pSeries_init_early,
567 .get_cpuinfo = pSeries_get_cpuinfo,
568 .log_error = pSeries_log_error,
569 .pcibios_fixup = pSeries_final_fixup,
570 .restart = rtas_restart,
571 .power_off = rtas_power_off,
572 .halt = rtas_halt,
573 .panic = rtas_os_term,
574 .get_boot_time = pSeries_get_boot_time,
575 .get_rtc_time = pSeries_get_rtc_time,
576 .set_rtc_time = pSeries_set_rtc_time,
577 .calibrate_decr = pSeries_calibrate_decr,
578 .progress = pSeries_progress,