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/slab.h>
27 #include <linux/user.h>
28 #include <linux/a.out.h>
29 #include <linux/tty.h>
30 #include <linux/major.h>
31 #include <linux/interrupt.h>
32 #include <linux/reboot.h>
33 #include <linux/init.h>
34 #include <linux/ioport.h>
35 #include <linux/console.h>
36 #include <linux/pci.h>
37 #include <linux/version.h>
38 #include <linux/adb.h>
39 #include <linux/module.h>
40 #include <linux/delay.h>
42 #include <linux/irq.h>
43 #include <linux/seq_file.h>
44 #include <linux/root_dev.h>
47 #include <asm/processor.h>
49 #include <asm/pgtable.h>
52 #include <asm/pci-bridge.h>
53 #include <asm/iommu.h>
55 #include <asm/machdep.h>
59 #include <asm/nvram.h>
64 #include <asm/ppcdebug.h>
65 #include <asm/cputable.h>
67 void chrp_progress(char *, unsigned short);
69 extern void pSeries_init_openpic(void);
71 extern void find_and_init_phbs(void);
72 extern void pSeries_final_fixup(void);
74 extern void pSeries_get_boot_time(struct rtc_time *rtc_time);
75 extern void pSeries_get_rtc_time(struct rtc_time *rtc_time);
76 extern int pSeries_set_rtc_time(struct rtc_time *rtc_time);
77 void pSeries_calibrate_decr(void);
78 void fwnmi_init(void);
79 extern void SystemReset_FWNMI(void), MachineCheck_FWNMI(void); /* from head.S */
80 int fwnmi_active; /* TRUE if an FWNMI handler is present */
83 unsigned long virtPython0Facilities = 0; // python0 facility area (memory mapped io) (64-bit format) VIRTUAL address.
85 extern unsigned long loops_per_jiffy;
87 extern unsigned long ppc_proc_freq;
88 extern unsigned long ppc_tb_freq;
90 void chrp_get_cpuinfo(struct seq_file *m)
92 struct device_node *root;
93 const char *model = "";
95 root = of_find_node_by_path("/");
97 model = get_property(root, "model", NULL);
98 seq_printf(m, "machine\t\t: CHRP %s\n", model);
102 #define I8042_DATA_REG 0x60
104 void __init chrp_request_regions(void)
106 struct device_node *i8042;
108 request_region(0x20,0x20,"pic1");
109 request_region(0xa0,0x20,"pic2");
110 request_region(0x00,0x20,"dma1");
111 request_region(0x40,0x20,"timer");
112 request_region(0x80,0x10,"dma page reg");
113 request_region(0xc0,0x20,"dma2");
116 * Some machines have an unterminated i8042 so check the device
117 * tree and reserve the region if it does not appear. Later on
118 * the i8042 code will try and reserve this region and fail.
120 if (!(i8042 = of_find_node_by_type(NULL, "8042")))
121 request_region(I8042_DATA_REG, 16, "reserved (no i8042)");
126 chrp_setup_arch(void)
128 struct device_node *root;
129 unsigned int *opprop;
131 /* openpic global configuration register (64-bit format). */
132 /* openpic Interrupt Source Unit pointer (64-bit format). */
133 /* python0 facility area (mmio) (64-bit format) REAL address. */
135 /* init to some ~sane value until calibrate_delay() runs */
136 loops_per_jiffy = 50000000;
139 printk("No ramdisk, default root is /dev/sda2\n");
140 ROOT_DEV = Root_SDA2;
143 printk("Boot arguments: %s\n", cmd_line);
147 #ifndef CONFIG_PPC_ISERIES
148 /* Find and initialize PCI host bridges */
149 /* iSeries needs to be done much later. */
151 find_and_init_phbs();
154 /* Find the Open PIC if present */
155 root = of_find_node_by_path("/");
156 opprop = (unsigned int *) get_property(root,
157 "platform-open-pic", NULL);
159 int n = prom_n_addr_cells(root);
160 unsigned long openpic;
162 for (openpic = 0; n > 0; --n)
163 openpic = (openpic << 32) + *opprop++;
164 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic);
165 OpenPIC_Addr = __ioremap(openpic, 0x40000, _PAGE_NO_CACHE);
169 #ifdef CONFIG_DUMMY_CONSOLE
170 conswitchp = &dummy_con;
173 #ifdef CONFIG_PPC_PSERIES
174 pSeries_nvram_init();
181 /* Manually leave the kernel version on the panel. */
182 ppc_md.progress("Linux ppc64\n", 0);
183 ppc_md.progress(UTS_RELEASE, 0);
186 /* Initialize firmware assisted non-maskable interrupts if
187 * the firmware supports this feature.
190 void __init fwnmi_init(void)
193 int ibm_nmi_register = rtas_token("ibm,nmi-register");
194 if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
196 ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
197 __pa((unsigned long)SystemReset_FWNMI),
198 __pa((unsigned long)MachineCheck_FWNMI));
203 /* Early initialization. Relocation is on but do not reference unbolted pages */
204 void __init pSeries_init_early(void)
211 pci_dma_init_direct();
219 /* Map the uart for udbg. */
220 comport = (void *)__ioremap(naca->serialPortAddr, 16, _PAGE_NO_CACHE);
221 udbg_init_uart(comport);
223 ppc_md.udbg_putc = udbg_putc;
224 ppc_md.udbg_getc = udbg_getc;
225 ppc_md.udbg_getc_poll = udbg_getc_poll;
229 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
230 unsigned long r6, unsigned long r7)
232 struct device_node * dn;
236 ppc_md.setup_arch = chrp_setup_arch;
237 ppc_md.get_cpuinfo = chrp_get_cpuinfo;
238 if (naca->interrupt_controller == IC_OPEN_PIC) {
239 ppc_md.init_IRQ = pSeries_init_openpic;
240 ppc_md.get_irq = openpic_get_irq;
242 ppc_md.init_IRQ = xics_init_IRQ;
243 ppc_md.get_irq = xics_get_irq;
246 ppc_md.log_error = pSeries_log_error;
248 ppc_md.init = chrp_init2;
250 ppc_md.pcibios_fixup = pSeries_final_fixup;
252 ppc_md.restart = rtas_restart;
253 ppc_md.power_off = rtas_power_off;
254 ppc_md.halt = rtas_halt;
255 ppc_md.panic = rtas_os_term;
257 ppc_md.get_boot_time = pSeries_get_boot_time;
258 ppc_md.get_rtc_time = pSeries_get_rtc_time;
259 ppc_md.set_rtc_time = pSeries_set_rtc_time;
260 ppc_md.calibrate_decr = pSeries_calibrate_decr;
262 ppc_md.progress = chrp_progress;
264 /* Build up the firmware_features bitmask field
265 * using contents of device-tree/ibm,hypertas-functions.
266 * Ultimately this functionality may be moved into prom.c prom_init().
268 cur_cpu_spec->firmware_features = 0;
269 dn = of_find_node_by_path("/rtas");
271 printk(KERN_ERR "WARNING ! Cannot find RTAS in device-tree !\n");
275 hypertas = get_property(dn, "ibm,hypertas-functions", &len);
279 /* check value against table of strings */
280 for(i=0; i < FIRMWARE_MAX_FEATURES ;i++) {
281 if ((firmware_features_table[i].name) &&
282 (strcmp(firmware_features_table[i].name,hypertas))==0) {
283 /* we have a match */
284 cur_cpu_spec->firmware_features |=
285 (firmware_features_table[i].val);
289 hypertas_len = strlen(hypertas);
290 len -= hypertas_len +1;
291 hypertas+= hypertas_len +1;
297 printk(KERN_INFO "firmware_features = 0x%lx\n",
298 cur_cpu_spec->firmware_features);
301 void chrp_progress(char *s, unsigned short hex)
303 struct device_node *root;
306 static int display_character, set_indicator;
307 static int max_width;
308 static spinlock_t progress_lock = SPIN_LOCK_UNLOCKED;
309 static int pending_newline = 0; /* did last write end with unprinted newline? */
314 if (max_width == 0) {
315 if ((root = find_path_device("/rtas")) &&
316 (p = (unsigned int *)get_property(root,
317 "ibm,display-line-length",
322 display_character = rtas_token("display-character");
323 set_indicator = rtas_token("set-indicator");
326 if (display_character == RTAS_UNKNOWN_SERVICE) {
327 /* use hex display if available */
328 if (set_indicator != RTAS_UNKNOWN_SERVICE)
329 rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
333 spin_lock(&progress_lock);
336 * Last write ended with newline, but we didn't print it since
337 * it would just clear the bottom line of output. Print it now
340 * If no newline is pending, print a CR to start output at the
341 * beginning of the line.
343 if (pending_newline) {
344 rtas_call(display_character, 1, 1, NULL, '\r');
345 rtas_call(display_character, 1, 1, NULL, '\n');
348 rtas_call(display_character, 1, 1, NULL, '\r');
354 if (*os == '\n' || *os == '\r') {
355 /* Blank to end of line. */
357 rtas_call(display_character, 1, 1, NULL, ' ');
359 /* If newline is the last character, save it
360 * until next call to avoid bumping up the
363 if (*os == '\n' && !os[1]) {
365 spin_unlock(&progress_lock);
369 /* RTAS wants CR-LF, not just LF */
372 rtas_call(display_character, 1, 1, NULL, '\r');
373 rtas_call(display_character, 1, 1, NULL, '\n');
375 /* CR might be used to re-draw a line, so we'll
376 * leave it alone and not add LF.
378 rtas_call(display_character, 1, 1, NULL, *os);
384 rtas_call(display_character, 1, 1, NULL, *os);
389 /* if we overwrite the screen length */
391 while ((*os != 0) && (*os != '\n') && (*os != '\r'))
395 /* Blank to end of line. */
397 rtas_call(display_character, 1, 1, NULL, ' ');
399 spin_unlock(&progress_lock);
402 extern void setup_default_decr(void);
404 /* Some sane defaults: 125 MHz timebase, 1GHz processor */
405 #define DEFAULT_TB_FREQ 125000000UL
406 #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
408 void __init pSeries_calibrate_decr(void)
410 struct device_node *cpu;
411 struct div_result divres;
416 * The cpu node should have a timebase-frequency property
417 * to tell us the rate at which the decrementer counts.
419 cpu = of_find_node_by_type(NULL, "cpu");
421 ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */
424 fp = (unsigned int *)get_property(cpu, "timebase-frequency",
432 printk(KERN_ERR "WARNING: Estimating decrementer frequency "
435 ppc_proc_freq = DEFAULT_PROC_FREQ;
438 fp = (unsigned int *)get_property(cpu, "clock-frequency",
446 printk(KERN_ERR "WARNING: Estimating processor frequency "
451 printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
452 ppc_tb_freq/1000000, ppc_tb_freq%1000000);
453 printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n",
454 ppc_proc_freq/1000000, ppc_proc_freq%1000000);
456 tb_ticks_per_jiffy = ppc_tb_freq / HZ;
457 tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
458 tb_ticks_per_usec = ppc_tb_freq / 1000000;
459 tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
460 div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
461 tb_to_xs = divres.result_low;
463 setup_default_decr();