2 * Common prep/pmac/chrp boot and setup code.
5 #include <linux/config.h>
6 #include <linux/module.h>
7 #include <linux/string.h>
8 #include <linux/sched.h>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/reboot.h>
12 #include <linux/delay.h>
13 #include <linux/initrd.h>
14 #include <linux/ide.h>
15 #include <linux/tty.h>
16 #include <linux/bootmem.h>
17 #include <linux/seq_file.h>
18 #include <linux/root_dev.h>
19 #include <linux/cpu.h>
20 #include <linux/console.h>
22 #include <asm/residual.h>
25 #include <asm/processor.h>
26 #include <asm/pgtable.h>
27 #include <asm/bootinfo.h>
28 #include <asm/setup.h>
29 #include <asm/amigappc.h>
32 #include <asm/cputable.h>
33 #include <asm/bootx.h>
34 #include <asm/btext.h>
35 #include <asm/machdep.h>
36 #include <asm/uaccess.h>
37 #include <asm/system.h>
38 #include <asm/pmac_feature.h>
39 #include <asm/sections.h>
40 #include <asm/nvram.h>
44 #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
45 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
46 defined(CONFIG_PPC_MPC52xx))
49 #include <asm/ppc_sys.h>
52 #if defined CONFIG_KGDB
56 extern void platform_init(void);
57 extern void bootx_init(unsigned long r4, unsigned long phys);
59 extern void ppc6xx_idle(void);
60 extern void power4_idle(void);
62 boot_infos_t *boot_infos;
63 struct ide_machdep_calls ppc_ide_md;
65 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
66 size value reported by the boot loader. */
67 unsigned long boot_mem_size;
69 unsigned long ISA_DMA_THRESHOLD;
70 unsigned int DMA_MODE_READ;
71 unsigned int DMA_MODE_WRITE;
75 #ifdef CONFIG_PPC_MULTIPLATFORM
78 extern void prep_init(void);
79 extern void pmac_init(void);
80 extern void chrp_init(void);
83 #endif /* CONFIG_PPC_MULTIPLATFORM */
85 #ifdef CONFIG_MAGIC_SYSRQ
86 unsigned long SYSRQ_KEY = 0x54;
87 #endif /* CONFIG_MAGIC_SYSRQ */
89 #ifdef CONFIG_VGA_CONSOLE
90 unsigned long vgacon_remap_base;
93 struct machdep_calls ppc_md;
94 EXPORT_SYMBOL(ppc_md);
97 * These are used in binfmt_elf.c to put aux entries on the stack
98 * for each elf executable being started.
104 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
105 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
106 struct screen_info screen_info = {
107 0, 25, /* orig-x, orig-y */
109 0, /* orig-video-page */
110 0, /* orig-video-mode */
111 80, /* orig-video-cols */
112 0,0,0, /* ega_ax, ega_bx, ega_cx */
113 25, /* orig-video-lines */
114 1, /* orig-video-isVGA */
115 16 /* orig-video-points */
117 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
119 void machine_restart(char *cmd)
127 void machine_power_off(void)
135 void machine_halt(void)
143 void (*pm_power_off)(void) = machine_power_off;
146 extern u32 cpu_temp(unsigned long cpu);
147 extern u32 cpu_temp_both(unsigned long cpu);
148 #endif /* CONFIG_TAU */
150 int show_cpuinfo(struct seq_file *m, void *v)
155 unsigned short maj, min;
159 /* Show summary information */
161 unsigned long bogosum = 0;
162 for (i = 0; i < NR_CPUS; ++i)
164 bogosum += cpu_data[i].loops_per_jiffy;
165 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
166 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
167 #endif /* CONFIG_SMP */
169 if (ppc_md.show_cpuinfo != NULL)
170 err = ppc_md.show_cpuinfo(m);
177 pvr = cpu_data[i].pvr;
178 lpj = cpu_data[i].loops_per_jiffy;
180 pvr = mfspr(SPRN_PVR);
181 lpj = loops_per_jiffy;
184 seq_printf(m, "processor\t: %d\n", i);
185 seq_printf(m, "cpu\t\t: ");
187 if (cur_cpu_spec->pvr_mask)
188 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
190 seq_printf(m, "unknown (%08x)", pvr);
191 #ifdef CONFIG_ALTIVEC
192 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
193 seq_printf(m, ", altivec supported");
198 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
199 #ifdef CONFIG_TAU_AVERAGE
200 /* more straightforward, but potentially misleading */
201 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
204 /* show the actual temp sensor range */
206 temp = cpu_temp_both(i);
207 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
208 temp & 0xff, temp >> 16);
211 #endif /* CONFIG_TAU */
213 if (ppc_md.show_percpuinfo != NULL) {
214 err = ppc_md.show_percpuinfo(m, i);
219 /* If we are a Freescale core do a simple check so
220 * we dont have to keep adding cases in the future */
221 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
225 switch (PVR_VER(pvr)) {
226 case 0x0020: /* 403 family */
227 maj = PVR_MAJ(pvr) + 1;
230 case 0x1008: /* 740P/750P ?? */
231 maj = ((pvr >> 8) & 0xFF) - 1;
235 maj = (pvr >> 8) & 0xFF;
241 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
242 maj, min, PVR_VER(pvr), PVR_REV(pvr));
244 seq_printf(m, "bogomips\t: %lu.%02lu\n",
245 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
248 if (cur_ppc_sys_spec->ppc_sys_name)
249 seq_printf(m, "chipset\t\t: %s\n",
250 cur_ppc_sys_spec->ppc_sys_name);
260 static void *c_start(struct seq_file *m, loff_t *pos)
264 return i <= NR_CPUS? (void *) (i + 1): NULL;
267 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
270 return c_start(m, pos);
273 static void c_stop(struct seq_file *m, void *v)
277 struct seq_operations cpuinfo_op = {
281 .show = show_cpuinfo,
285 * We're called here very early in the boot. We determine the machine
286 * type and call the appropriate low-level setup functions.
287 * -- Cort <cort@fsmlabs.com>
289 * Note that the kernel may be running at an address which is different
290 * from the address that it was linked at, so we must use RELOC/PTRRELOC
291 * to access static data (including strings). -- paulus
293 unsigned long __init early_init(unsigned long dt_ptr)
295 unsigned long offset = reloc_offset();
300 * Identify the CPU type and fix up code sections
301 * that depend on which cpu we have.
303 identify_cpu(offset, 0);
304 do_cpu_ftr_fixups(offset);
306 #ifdef CONFIG_BOOTX_TEXT
312 return KERNELBASE + offset;
317 * Assume here that all clock rates are the same in a
318 * smp system. -- Cort
321 of_show_percpuinfo(struct seq_file *m, int i)
323 struct device_node *cpu_node;
327 cpu_node = find_type_devices("cpu");
330 for (s = 0; s < i && cpu_node->next; s++)
331 cpu_node = cpu_node->next;
332 fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL);
334 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
339 intuit_machine_type(void)
342 struct device_node *root;
344 /* ask the OF info if we're a chrp or pmac */
345 root = find_path_device("/");
347 /* assume pmac unless proven to be chrp -- Cort */
348 _machine = _MACH_Pmac;
349 model = get_property(root, "device_type", NULL);
350 if (model && !strncmp("chrp", model, 4))
351 _machine = _MACH_chrp;
353 model = get_property(root, "model", NULL);
354 if (model && !strncmp(model, "IBM", 3))
355 _machine = _MACH_chrp;
361 #ifdef CONFIG_PPC_MULTIPLATFORM
363 * The PPC_MULTIPLATFORM version of platform_init...
365 void __init platform_init(void)
367 /* if we didn't get any bootinfo telling us what we are... */
369 /* prep boot loader tells us if we're prep or not */
370 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
371 _machine = _MACH_prep;
374 #ifdef CONFIG_PPC_PREP
375 /* not much more to do here, if prep */
376 if (_machine == _MACH_prep) {
383 if (strstr(cmd_line, "adb_sync")) {
384 extern int __adb_probe_sync;
385 __adb_probe_sync = 1;
387 #endif /* CONFIG_ADB */
390 #ifdef CONFIG_PPC_PMAC
395 #ifdef CONFIG_PPC_CHRP
403 #ifdef CONFIG_SERIAL_CORE_CONSOLE
404 extern char *of_stdout_device;
406 static int __init set_preferred_console(void)
408 struct device_node *prom_stdout;
412 if (of_stdout_device == NULL)
415 /* The user has requested a console so this is already set up. */
416 if (strstr(saved_command_line, "console="))
419 prom_stdout = find_path_device(of_stdout_device);
423 name = (char *)get_property(prom_stdout, "name", NULL);
427 if (strcmp(name, "serial") == 0) {
429 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
445 /* We dont recognise the serial port */
449 } else if (strcmp(name, "ch-a") == 0)
451 else if (strcmp(name, "ch-b") == 0)
455 return add_preferred_console("ttyS", offset, NULL);
457 console_initcall(set_preferred_console);
458 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
459 #endif /* CONFIG_PPC_MULTIPLATFORM */
462 * Find out what kind of machine we're on and save any data we need
463 * from the early boot process (devtree is copied on pmac by prom_init()).
464 * This is called very early on the boot process, after a minimal
465 * MMU environment has been set up but before MMU_init is called.
467 void __init machine_init(unsigned long dt_ptr, unsigned long phys)
469 early_init_devtree(__va(dt_ptr));
471 #ifdef CONFIG_CMDLINE
472 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
473 #endif /* CONFIG_CMDLINE */
476 ppc_md.power_save = ppc6xx_idle;
479 ppc_md.power_save = power4_idle;
485 ppc_md.progress("id mach(): done", 0x200);
488 #ifdef CONFIG_BOOKE_WDT
489 /* Checks wdt=x and wdt_period=xx command-line option */
490 int __init early_parse_wdt(char *p)
492 if (p && strncmp(p, "0", 1) != 0)
493 booke_wdt_enabled = 1;
497 early_param("wdt", early_parse_wdt);
499 int __init early_parse_wdt_period (char *p)
502 booke_wdt_period = simple_strtoul(p, NULL, 0);
506 early_param("wdt_period", early_parse_wdt_period);
507 #endif /* CONFIG_BOOKE_WDT */
509 /* Checks "l2cr=xxxx" command-line option */
510 int __init ppc_setup_l2cr(char *str)
512 if (cpu_has_feature(CPU_FTR_L2CR)) {
513 unsigned long val = simple_strtoul(str, NULL, 0);
514 printk(KERN_INFO "l2cr set to %lx\n", val);
515 _set_L2CR(0); /* force invalidate by disable cache */
516 _set_L2CR(val); /* and enable it */
520 __setup("l2cr=", ppc_setup_l2cr);
522 #ifdef CONFIG_GENERIC_NVRAM
524 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
525 unsigned char nvram_read_byte(int addr)
527 if (ppc_md.nvram_read_val)
528 return ppc_md.nvram_read_val(addr);
531 EXPORT_SYMBOL(nvram_read_byte);
533 void nvram_write_byte(unsigned char val, int addr)
535 if (ppc_md.nvram_write_val)
536 ppc_md.nvram_write_val(addr, val);
538 EXPORT_SYMBOL(nvram_write_byte);
540 void nvram_sync(void)
542 if (ppc_md.nvram_sync)
545 EXPORT_SYMBOL(nvram_sync);
547 #endif /* CONFIG_NVRAM */
549 static struct cpu cpu_devices[NR_CPUS];
551 int __init ppc_init(void)
555 /* clear the progress line */
556 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
558 /* register CPU devices */
559 for (i = 0; i < NR_CPUS; i++)
561 register_cpu(&cpu_devices[i], i, NULL);
563 /* call platform init */
564 if (ppc_md.init != NULL) {
570 arch_initcall(ppc_init);
572 /* Warning, IO base is not yet inited */
573 void __init setup_arch(char **cmdline_p)
576 extern void do_init_bootmem(void);
578 /* so udelay does something sensible, assume <= 1000 bogomips */
579 loops_per_jiffy = 500000000 / HZ;
581 #ifdef CONFIG_BOOTX_TEXT
585 unflatten_device_tree();
586 finish_device_tree();
588 #ifdef CONFIG_PPC_MULTIPLATFORM
589 /* This could be called "early setup arch", it must be done
590 * now because xmon need it
592 if (_machine == _MACH_Pmac)
593 pmac_feature_init(); /* New cool way */
598 if (strstr(cmd_line, "xmon"))
600 #endif /* CONFIG_XMON */
601 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
603 #if defined(CONFIG_KGDB)
604 if (ppc_md.kgdb_map_scc)
605 ppc_md.kgdb_map_scc();
607 if (strstr(cmd_line, "gdb")) {
609 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
610 printk("kgdb breakpoint activated\n");
616 * Set cache line size based on type of cpu as a default.
617 * Systems with OF can look in the properties on the cpu node(s)
618 * for a possibly more accurate value.
620 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
621 dcache_bsize = cur_cpu_spec->dcache_bsize;
622 icache_bsize = cur_cpu_spec->icache_bsize;
625 ucache_bsize = dcache_bsize = icache_bsize
626 = cur_cpu_spec->dcache_bsize;
628 /* reboot on panic */
631 init_mm.start_code = PAGE_OFFSET;
632 init_mm.end_code = (unsigned long) _etext;
633 init_mm.end_data = (unsigned long) _edata;
634 init_mm.brk = (unsigned long) klimit;
636 /* Save unparsed command line copy for /proc/cmdline */
637 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
638 *cmdline_p = cmd_line;
642 /* set up the bootmem stuff with available memory */
644 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
646 #ifdef CONFIG_PPC_OCP
647 /* Initialize OCP device list */
649 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
652 #ifdef CONFIG_DUMMY_CONSOLE
653 conswitchp = &dummy_con;
657 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
661 /* this is for modules since _machine can be a define -- Cort */
662 ppc_md.ppc_machine = _machine;