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 #include <linux/config.h>
20 #include <linux/errno.h>
21 #include <linux/sched.h>
22 #include <linux/kernel.h>
24 #include <linux/stddef.h>
25 #include <linux/unistd.h>
26 #include <linux/ptrace.h>
27 #include <linux/slab.h>
28 #include <linux/user.h>
29 #include <linux/a.out.h>
30 #include <linux/tty.h>
31 #include <linux/major.h>
32 #include <linux/interrupt.h>
33 #include <linux/reboot.h>
34 #include <linux/init.h>
35 #include <linux/blk.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>
48 #include <asm/processor.h>
50 #include <asm/pgtable.h>
53 #include <asm/pci-bridge.h>
54 #include <asm/pci_dma.h>
56 #include <asm/machdep.h>
58 #include <asm/keyboard.h>
63 #include "local_irq.h"
67 #include <asm/ppcdebug.h>
68 #include <asm/cputable.h>
70 extern volatile unsigned char *chrp_int_ack_special;
72 void chrp_setup_pci_ptrs(void);
73 void chrp_progress(char *, unsigned short);
74 void chrp_request_regions(void);
76 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
77 extern int pckbd_getkeycode(unsigned int scancode);
78 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
80 extern char pckbd_unexpected_up(unsigned char keycode);
81 extern void pckbd_leds(unsigned char leds);
82 extern void pckbd_init_hw(void);
83 extern unsigned char pckbd_sysrq_xlate[128];
84 extern void openpic_init_IRQ(void);
85 extern void openpic_init_irq_desc(irq_desc_t *);
86 extern void init_ras_IRQ(void);
88 extern void find_and_init_phbs(void);
89 extern void pSeries_pcibios_fixup(void);
90 extern void iSeries_pcibios_fixup(void);
92 extern void pSeries_get_boot_time(struct rtc_time *rtc_time);
93 extern void pSeries_get_rtc_time(struct rtc_time *rtc_time);
94 extern int pSeries_set_rtc_time(struct rtc_time *rtc_time);
95 void pSeries_calibrate_decr(void);
96 static void machine_check_init(void);
97 extern void SystemReset_FWNMI(void), MachineCheck_FWNMI(void); /* from head.S */
98 int fwnmi_active = 0; /* TRUE if an FWNMI handler is present */
99 int check_exception_flag = 0; /* TRUE if a check-exception handler present */
102 unsigned long virtPython0Facilities = 0; // python0 facility area (memory mapped io) (64-bit format) VIRTUAL address.
104 extern HPTE *Hash, *Hash_end;
105 extern unsigned long Hash_size, Hash_mask;
106 extern int probingmem;
107 extern unsigned long loops_per_jiffy;
109 extern unsigned long ppc_proc_freq;
110 extern unsigned long ppc_tb_freq;
111 #ifdef CONFIG_BLK_DEV_RAM
112 extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */
113 extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */
114 extern int rd_image_start; /* starting block # of image */
118 chrp_get_cpuinfo(struct seq_file *m)
120 struct device_node *root;
121 const char *model = "";
123 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
125 root = find_path_device("/");
127 model = get_property(root, "model", NULL);
128 seq_printf(m, "machine\t\t: CHRP %s\n", model);
131 void __init chrp_request_regions(void) {
132 request_region(0x20,0x20,"pic1");
133 request_region(0xa0,0x20,"pic2");
134 request_region(0x00,0x20,"dma1");
135 request_region(0x40,0x20,"timer");
136 request_region(0x80,0x10,"dma page reg");
137 request_region(0xc0,0x20,"dma2");
141 chrp_setup_arch(void)
143 struct device_node *root;
144 unsigned int *opprop;
146 /* openpic global configuration register (64-bit format). */
147 /* openpic Interrupt Source Unit pointer (64-bit format). */
148 /* python0 facility area (mmio) (64-bit format) REAL address. */
150 /* init to some ~sane value until calibrate_delay() runs */
151 loops_per_jiffy = 50000000;
153 #ifdef CONFIG_BLK_DEV_INITRD
154 /* this is fine for chrp */
155 initrd_below_start_ok = 1;
158 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
161 ROOT_DEV = to_kdev_t(0x0803); /* sda3 (sda1 is for the kernel or the bootloader) */
163 machine_check_init();
165 #ifndef CONFIG_PPC_ISERIES
166 /* Find and initialize PCI host bridges */
167 /* iSeries needs to be done much later. */
169 find_and_init_phbs();
172 /* Find the Open PIC if present */
173 root = find_path_device("/");
174 opprop = (unsigned int *) get_property(root,
175 "platform-open-pic", NULL);
177 int n = prom_n_addr_cells(root);
178 unsigned long openpic;
180 for (openpic = 0; n > 0; --n)
181 openpic = (openpic << 32) + *opprop++;
182 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic);
183 OpenPIC_Addr = __ioremap(openpic, 0x40000, _PAGE_NO_CACHE);
186 #ifdef CONFIG_DUMMY_CONSOLE
187 conswitchp = &dummy_con;
195 * It is sensitive, when this is called (not too earlu)
198 chrp_request_regions();
199 /* Manually leave the kernel version on the panel. */
200 ppc_md.progress("Linux ppc64\n", 0);
201 ppc_md.progress(UTS_RELEASE, 0);
204 /* Initialize firmware assisted non-maskable interrupts if
205 * the firmware supports this feature. If it does not,
206 * look for the check-exception property.
208 static void __init machine_check_init(void)
212 int ibm_nmi_register = rtas_token("ibm,nmi-register");
214 if (ibm_nmi_register != RTAS_UNKNOWN_SERVICE) {
215 ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
216 __pa((unsigned long)SystemReset_FWNMI),
217 __pa((unsigned long)MachineCheck_FWNMI));
221 check_ex_token = rtas_token("check-exception");
222 if (check_ex_token != RTAS_UNKNOWN_SERVICE)
223 check_exception_flag = 1;
228 /* Early initialization. Relocation is on but do not reference unbolted pages */
229 void __init pSeries_init_early(void)
231 #ifdef CONFIG_PPC_PSERIES /* This ifdef should go away */
236 pSeries_pcibios_init_early();
242 /* Map the uart for udbg. */
243 comport = (void *)__ioremap(naca->serialPortAddr, 16, _PAGE_NO_CACHE);
244 udbg_init_uart(comport);
246 ppc_md.udbg_putc = udbg_putc;
247 ppc_md.udbg_getc = udbg_getc;
248 ppc_md.udbg_getc_poll = udbg_getc_poll;
253 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
254 unsigned long r6, unsigned long r7)
256 #if 0 /* PPPBBB remove this later... -Peter */
257 #ifdef CONFIG_BLK_DEV_INITRD
258 /* take care of initrd if we have one */
261 initrd_start = __va(r6);
262 initrd_end = __va(r6 + r7);
264 #endif /* CONFIG_BLK_DEV_INITRD */
267 ppc_md.ppc_machine = systemcfg->platform;
269 ppc_md.setup_arch = chrp_setup_arch;
270 ppc_md.setup_residual = NULL;
271 ppc_md.get_cpuinfo = chrp_get_cpuinfo;
272 if(naca->interrupt_controller == IC_OPEN_PIC) {
273 ppc_md.init_IRQ = openpic_init_IRQ;
274 ppc_md.init_irq_desc = openpic_init_irq_desc;
275 ppc_md.get_irq = openpic_get_irq;
277 ppc_md.init_IRQ = xics_init_IRQ;
278 ppc_md.init_irq_desc = xics_init_irq_desc;
279 ppc_md.get_irq = xics_get_irq;
281 ppc_md.init_ras_IRQ = init_ras_IRQ;
283 #ifndef CONFIG_PPC_ISERIES
284 ppc_md.pcibios_fixup = pSeries_pcibios_fixup;
285 ppc_md.log_error = pSeries_log_error;
287 ppc_md.pcibios_fixup = NULL;
288 // ppc_md.pcibios_fixup = iSeries_pcibios_fixup;
289 ppc_md.log_error = NULL;
293 ppc_md.init = chrp_init2;
295 ppc_md.restart = rtas_restart;
296 ppc_md.power_off = rtas_power_off;
297 ppc_md.halt = rtas_halt;
299 ppc_md.time_init = NULL;
300 ppc_md.get_boot_time = pSeries_get_boot_time;
301 ppc_md.get_rtc_time = pSeries_get_rtc_time;
302 ppc_md.set_rtc_time = pSeries_set_rtc_time;
303 ppc_md.calibrate_decr = pSeries_calibrate_decr;
305 ppc_md.progress = chrp_progress;
308 ppc_md.kbd_setkeycode = pckbd_setkeycode;
309 ppc_md.kbd_getkeycode = pckbd_getkeycode;
310 ppc_md.kbd_translate = pckbd_translate;
311 ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
312 ppc_md.kbd_leds = pckbd_leds;
313 ppc_md.kbd_init_hw = pckbd_init_hw;
314 #ifdef CONFIG_MAGIC_SYSRQ
315 ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
316 SYSRQ_KEY = 0x63; /* Print Screen */
319 /* Build up the firmware_features bitmask field
320 * using contents of device-tree/ibm,hypertas-functions.
321 * Ultimately this functionality may be moved into prom.c prom_init().
323 struct device_node * dn;
326 dn = find_path_device("/rtas");
327 cur_cpu_spec->firmware_features=0;
328 hypertas = get_property(dn, "ibm,hypertas-functions", &len);
332 /* check value against table of strings */
333 for(i=0; i < FIRMWARE_MAX_FEATURES; i++) {
334 if ((firmware_features_table[i].name) &&
335 (strcmp(firmware_features_table[i].name,hypertas))==0) {
336 /* we have a match */
337 cur_cpu_spec->firmware_features |=
338 (firmware_features_table[i].val);
342 hypertas_len = strlen(hypertas);
343 len -= hypertas_len +1;
344 hypertas+= hypertas_len +1;
348 printk(KERN_INFO "firmware_features = 0x%lx\n",
349 cur_cpu_spec->firmware_features);
353 chrp_progress(char *s, unsigned short hex)
355 struct device_node *root;
358 static int display_character, set_indicator;
359 static int max_width;
360 static spinlock_t progress_lock = SPIN_LOCK_UNLOCKED;
361 static int pending_newline = 0; /* did last write end with unprinted newline? */
366 if (max_width == 0) {
367 if ( (root = find_path_device("/rtas")) &&
368 (p = (unsigned int *)get_property(root,
369 "ibm,display-line-length",
374 display_character = rtas_token("display-character");
375 set_indicator = rtas_token("set-indicator");
378 if(display_character == RTAS_UNKNOWN_SERVICE) {
379 /* use hex display if available */
380 if(set_indicator != RTAS_UNKNOWN_SERVICE)
381 rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
385 spin_lock(&progress_lock);
387 /* Last write ended with newline, but we didn't print it since
388 * it would just clear the bottom line of output. Print it now
391 * If no newline is pending, print a CR to start output at the
392 * beginning of the line.
394 if(pending_newline) {
395 rtas_call(display_character, 1, 1, NULL, '\r');
396 rtas_call(display_character, 1, 1, NULL, '\n');
399 rtas_call(display_character, 1, 1, NULL, '\r');
404 if(*os == '\n' || *os == '\r') {
405 /* Blank to end of line. */
407 rtas_call(display_character, 1, 1, NULL, ' ');
409 /* If newline is the last character, save it
410 * until next call to avoid bumping up the
413 if(*os == '\n' && !os[1]) {
415 spin_unlock(&progress_lock);
419 /* RTAS wants CR-LF, not just LF */
422 rtas_call(display_character, 1, 1, NULL, '\r');
423 rtas_call(display_character, 1, 1, NULL, '\n');
425 /* CR might be used to re-draw a line, so we'll
426 * leave it alone and not add LF.
428 rtas_call(display_character, 1, 1, NULL, *os);
434 rtas_call(display_character, 1, 1, NULL, *os);
439 /* if we overwrite the screen length */
441 while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
445 /* Blank to end of line. */
446 while ( width-- > 0 )
447 rtas_call(display_character, 1, 1, NULL, ' ' );
449 spin_unlock(&progress_lock);
452 extern void setup_default_decr(void);
454 void __init pSeries_calibrate_decr(void)
456 struct device_node *cpu;
457 struct div_result divres;
459 unsigned long freq, processor_freq;
462 * The cpu node should have a timebase-frequency property
463 * to tell us the rate at which the decrementer counts.
465 freq = 16666000; /* hardcoded default */
466 cpu = find_type_devices("cpu");
468 fp = (int *) get_property(cpu, "timebase-frequency", NULL);
473 processor_freq = freq;
475 fp = (int *) get_property(cpu, "clock-frequency", NULL);
477 processor_freq = *fp;
479 ppc_proc_freq = processor_freq;
481 printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
482 freq/1000000, freq%1000000 );
483 printk("time_init: processor frequency = %lu.%.6lu MHz\n",
484 processor_freq/1000000, processor_freq%1000000 );
486 tb_ticks_per_jiffy = freq / HZ;
487 tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
488 tb_ticks_per_usec = freq / 1000000;
489 div128_by_32( 1024*1024, 0, tb_ticks_per_sec, &divres );
490 tb_to_xs = divres.result_low;
492 setup_default_decr();