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..
21 #include <linux/config.h>
22 #include <linux/errno.h>
23 #include <linux/sched.h>
24 #include <linux/kernel.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>
49 #include <asm/processor.h>
51 #include <asm/pgtable.h>
54 #include <asm/pci-bridge.h>
55 #include <asm/iommu.h>
57 #include <asm/machdep.h>
61 #include <asm/nvram.h>
66 #include <asm/ppcdebug.h>
67 #include <asm/cputable.h>
70 #define DBG(fmt...) udbg_printf(fmt)
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("/");
101 model
= get_property(root
, "model", NULL
);
102 seq_printf(m
, "machine\t\t: CHRP %s\n", model
);
106 /* Initialize firmware assisted non-maskable interrupts if
107 * the firmware supports this feature.
110 static void __init
fwnmi_init(void)
113 int ibm_nmi_register
= rtas_token("ibm,nmi-register");
114 if (ibm_nmi_register
== RTAS_UNKNOWN_SERVICE
)
116 ret
= rtas_call(ibm_nmi_register
, 2, 1, NULL
,
117 __pa((unsigned long)SystemReset_FWNMI
),
118 __pa((unsigned long)MachineCheck_FWNMI
));
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
;
133 ppc_md
.init_IRQ
= xics_init_IRQ
;
134 ppc_md
.get_irq
= xics_get_irq
;
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;
148 printk("No ramdisk, default root is /dev/sda2\n");
149 ROOT_DEV
= Root_SDA2
;
154 /* Find and initialize PCI host bridges */
155 /* iSeries needs to be done much later. */
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
);
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
);
174 #ifdef CONFIG_DUMMY_CONSOLE
175 conswitchp
= &dummy_con
;
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);
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;
199 struct isa_reg_property
{
204 struct pci_reg_property
{
205 struct pci_address addr
;
210 DBG(" -> pSeries_find_serial_port()\n");
212 naca
->serialPortAddr
= 0;
214 np
= of_find_node_by_path("/");
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
;
227 typep
= (char *)get_property(np
, "ibm,aix-loc", NULL
);
228 if ((typep
== NULL
) || (typep
&& strcmp(typep
, "S1")))
231 reg
= (struct isa_reg_property
*)get_property(np
, "reg", NULL
);
233 isa
= of_get_parent(np
);
235 DBG("no isa parent found\n");
238 pci
= of_get_parent(isa
);
240 DBG("no pci parent found\n");
244 rangesp
= (union pci_range
*)get_property(pci
, "ranges", NULL
);
246 if ( encode_phys_size
== 32 )
247 naca
->serialPortAddr
= rangesp
->pci32
.phys
+reg
->address
;
249 naca
->serialPortAddr
=
250 ((((unsigned long)rangesp
->pci64
.phys_hi
) << 32)
252 (rangesp
->pci64
.phys_lo
)) + reg
->address
;
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
;
271 DBG(" -> fw_feature_init()\n");
273 cur_cpu_spec
->firmware_features
= 0;
274 dn
= of_find_node_by_path("/rtas");
276 printk(KERN_ERR
"WARNING ! Cannot find RTAS in device-tree !\n");
280 hypertas
= get_property(dn
, "ibm,hypertas-functions", &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
);
294 hypertas_len
= strlen(hypertas
);
295 len
-= hypertas_len
+1;
296 hypertas
+= hypertas_len
+1;
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
;
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
;
327 printk("initialize_naca: failed to recognize"
328 " interrupt-controller\n");
334 * Early initialization. Relocation is on but do not reference unbolted pages
336 static void __init
pSeries_init_early(void)
341 DBG(" -> pSeries_init_early()\n");
345 if (systemcfg
->platform
& PLATFORM_LPAR
)
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
)
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");
370 pci_dma_init_direct();
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
;
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? */
393 if (max_width
== 0) {
394 if ((root
= find_path_device("/rtas")) &&
395 (p
= (unsigned int *)get_property(root
,
396 "ibm,display-line-length",
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
);
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
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');
427 rtas_call(display_character
, 1, 1, NULL
, '\r');
433 if (*os
== '\n' || *os
== '\r') {
434 /* Blank to end of line. */
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
442 if (*os
== '\n' && !os
[1]) {
444 spin_unlock(&progress_lock
);
448 /* RTAS wants CR-LF, not just LF */
451 rtas_call(display_character
, 1, 1, NULL
, '\r');
452 rtas_call(display_character
, 1, 1, NULL
, '\n');
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
);
463 rtas_call(display_character
, 1, 1, NULL
, *os
);
468 /* if we overwrite the screen length */
470 while ((*os
!= 0) && (*os
!= '\n') && (*os
!= '\r'))
474 /* Blank to end of line. */
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
;
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 */
503 fp
= (unsigned int *)get_property(cpu
, "timebase-frequency",
511 printk(KERN_ERR
"WARNING: Estimating decrementer frequency "
514 ppc_proc_freq
= DEFAULT_PROC_FREQ
;
517 fp
= (unsigned int *)get_property(cpu
, "clock-frequency",
525 printk(KERN_ERR
"WARNING: Estimating processor frequency "
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
)
556 /* if we have some ppc_md fixups for LPAR to do, do
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
,
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
,