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 #if defined(CONFIG_85xx) || defined(CONFIG_83xx) || defined(CONFIG_MPC10X_BRIDGE)
45 #include <asm/ppc_sys.h>
48 #if defined CONFIG_KGDB
52 extern void platform_init(unsigned long r3, unsigned long r4,
53 unsigned long r5, unsigned long r6, unsigned long r7);
54 extern void bootx_init(unsigned long r4, unsigned long phys);
55 extern void identify_cpu(unsigned long offset, unsigned long cpu);
56 extern void do_cpu_ftr_fixups(unsigned long offset);
57 extern void reloc_got2(unsigned long offset);
59 extern void ppc6xx_idle(void);
60 extern void power4_idle(void);
62 extern 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 long DMA_MODE_READ, DMA_MODE_WRITE;
72 #ifdef CONFIG_PPC_MULTIPLATFORM
75 extern void prep_init(unsigned long r3, unsigned long r4,
76 unsigned long r5, unsigned long r6, unsigned long r7);
77 extern void pmac_init(unsigned long r3, unsigned long r4,
78 unsigned long r5, unsigned long r6, unsigned long r7);
79 extern void chrp_init(unsigned long r3, unsigned long r4,
80 unsigned long r5, unsigned long r6, unsigned long r7);
81 #endif /* CONFIG_PPC_MULTIPLATFORM */
83 #ifdef CONFIG_MAGIC_SYSRQ
84 unsigned long SYSRQ_KEY = 0x54;
85 #endif /* CONFIG_MAGIC_SYSRQ */
87 #ifdef CONFIG_VGA_CONSOLE
88 unsigned long vgacon_remap_base;
91 struct machdep_calls ppc_md;
94 * These are used in binfmt_elf.c to put aux entries on the stack
95 * for each elf executable being started.
101 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
102 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
103 struct screen_info screen_info = {
104 0, 25, /* orig-x, orig-y */
106 0, /* orig-video-page */
107 0, /* orig-video-mode */
108 80, /* orig-video-cols */
109 0,0,0, /* ega_ax, ega_bx, ega_cx */
110 25, /* orig-video-lines */
111 1, /* orig-video-isVGA */
112 16 /* orig-video-points */
114 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
116 void machine_restart(char *cmd)
124 EXPORT_SYMBOL(machine_restart);
126 void machine_power_off(void)
134 EXPORT_SYMBOL(machine_power_off);
136 void machine_halt(void)
144 EXPORT_SYMBOL(machine_halt);
146 void (*pm_power_off)(void) = machine_power_off;
149 extern u32 cpu_temp(unsigned long cpu);
150 extern u32 cpu_temp_both(unsigned long cpu);
151 #endif /* CONFIG_TAU */
153 int show_cpuinfo(struct seq_file *m, void *v)
158 unsigned short maj, min;
162 /* Show summary information */
164 unsigned long bogosum = 0;
165 for (i = 0; i < NR_CPUS; ++i)
167 bogosum += cpu_data[i].loops_per_jiffy;
168 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
169 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
170 #endif /* CONFIG_SMP */
172 if (ppc_md.show_cpuinfo != NULL)
173 err = ppc_md.show_cpuinfo(m);
180 pvr = cpu_data[i].pvr;
181 lpj = cpu_data[i].loops_per_jiffy;
183 pvr = mfspr(SPRN_PVR);
184 lpj = loops_per_jiffy;
187 seq_printf(m, "processor\t: %d\n", i);
188 seq_printf(m, "cpu\t\t: ");
190 if (cur_cpu_spec[i]->pvr_mask)
191 seq_printf(m, "%s", cur_cpu_spec[i]->cpu_name);
193 seq_printf(m, "unknown (%08x)", pvr);
194 #ifdef CONFIG_ALTIVEC
195 if (cur_cpu_spec[i]->cpu_features & CPU_FTR_ALTIVEC)
196 seq_printf(m, ", altivec supported");
201 if (cur_cpu_spec[i]->cpu_features & CPU_FTR_TAU) {
202 #ifdef CONFIG_TAU_AVERAGE
203 /* more straightforward, but potentially misleading */
204 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
207 /* show the actual temp sensor range */
209 temp = cpu_temp_both(i);
210 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
211 temp & 0xff, temp >> 16);
214 #endif /* CONFIG_TAU */
216 if (ppc_md.show_percpuinfo != NULL) {
217 err = ppc_md.show_percpuinfo(m, i);
222 /* If we are a Freescale core do a simple check so
223 * we dont have to keep adding cases in the future */
224 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
228 switch (PVR_VER(pvr)) {
229 case 0x0020: /* 403 family */
230 maj = PVR_MAJ(pvr) + 1;
233 case 0x1008: /* 740P/750P ?? */
234 maj = ((pvr >> 8) & 0xFF) - 1;
238 maj = (pvr >> 8) & 0xFF;
244 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
245 maj, min, PVR_VER(pvr), PVR_REV(pvr));
247 seq_printf(m, "bogomips\t: %lu.%02lu\n",
248 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
250 #if defined(CONFIG_85xx) || defined(CONFIG_83xx) || defined(CONFIG_MPC10X_BRIDGE)
251 if (cur_ppc_sys_spec->ppc_sys_name)
252 seq_printf(m, "chipset\t\t: %s\n",
253 cur_ppc_sys_spec->ppc_sys_name);
263 static void *c_start(struct seq_file *m, loff_t *pos)
267 return i <= NR_CPUS? (void *) (i + 1): NULL;
270 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
273 return c_start(m, pos);
276 static void c_stop(struct seq_file *m, void *v)
280 struct seq_operations cpuinfo_op = {
284 .show = show_cpuinfo,
288 * We're called here very early in the boot. We determine the machine
289 * type and call the appropriate low-level setup functions.
290 * -- Cort <cort@fsmlabs.com>
292 * Note that the kernel may be running at an address which is different
293 * from the address that it was linked at, so we must use RELOC/PTRRELOC
294 * to access static data (including strings). -- paulus
298 early_init(int r3, int r4, int r5)
301 unsigned long offset = reloc_offset();
304 phys = offset + KERNELBASE;
306 /* First zero the BSS -- use memset, some arches don't have
308 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
311 * Identify the CPU type and fix up code sections
312 * that depend on which cpu we have.
314 identify_cpu(offset, 0);
315 do_cpu_ftr_fixups(offset);
317 #if defined(CONFIG_PPC_MULTIPLATFORM)
320 /* If we came here from BootX, clear the screen,
321 * set up some pointers and return. */
322 if ((r3 == 0x426f6f58) && (r5 == 0))
323 bootx_init(r4, phys);
326 * don't do anything on prep
327 * for now, don't use bootinfo because it breaks yaboot 0.5
328 * and assume that if we didn't find a magic number, we have OF
330 else if (*(unsigned long *)(0) != 0xdeadc0de)
331 phys = prom_init(r3, r4, (prom_entry)r5);
341 * Assume here that all clock rates are the same in a
342 * smp system. -- Cort
345 of_show_percpuinfo(struct seq_file *m, int i)
347 struct device_node *cpu_node;
351 cpu_node = find_type_devices("cpu");
354 for (s = 0; s < i && cpu_node->next; s++)
355 cpu_node = cpu_node->next;
356 fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL);
358 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
363 intuit_machine_type(void)
366 struct device_node *root;
368 /* ask the OF info if we're a chrp or pmac */
369 root = find_path_device("/");
371 /* assume pmac unless proven to be chrp -- Cort */
372 _machine = _MACH_Pmac;
373 model = get_property(root, "device_type", NULL);
374 if (model && !strncmp("chrp", model, 4))
375 _machine = _MACH_chrp;
377 model = get_property(root, "model", NULL);
378 if (model && !strncmp(model, "IBM", 3))
379 _machine = _MACH_chrp;
385 #ifdef CONFIG_PPC_MULTIPLATFORM
387 * The PPC_MULTIPLATFORM version of platform_init...
390 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
391 unsigned long r6, unsigned long r7)
393 #ifdef CONFIG_BOOTX_TEXT
394 if (boot_text_mapped) {
400 parse_bootinfo(find_bootinfo());
402 /* if we didn't get any bootinfo telling us what we are... */
404 /* prep boot loader tells us if we're prep or not */
405 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
406 _machine = _MACH_prep;
409 /* not much more to do here, if prep */
410 if (_machine == _MACH_prep) {
411 prep_init(r3, r4, r5, r6, r7);
415 /* prom_init has already been called from __start */
419 /* If we aren't PReP, we can find out if we're Pmac
420 * or CHRP with this. */
422 intuit_machine_type();
424 /* finish_device_tree may need _machine defined. */
425 finish_device_tree();
428 * If we were booted via quik, r3 points to the physical
429 * address of the command-line parameters.
430 * If we were booted from an xcoff image (i.e. netbooted or
431 * booted from floppy), we get the command line from the
432 * bootargs property of the /chosen node.
433 * If an initial ramdisk is present, r3 and r4
434 * are used for initrd_start and initrd_size,
435 * otherwise they contain 0xdeadbeef.
437 if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
438 strlcpy(cmd_line, (char *)r3 + KERNELBASE,
440 } else if (boot_infos != 0) {
441 /* booted by BootX - check for ramdisk */
442 if (boot_infos->kernelParamsOffset != 0)
443 strlcpy(cmd_line, (char *) boot_infos
444 + boot_infos->kernelParamsOffset,
446 #ifdef CONFIG_BLK_DEV_INITRD
447 if (boot_infos->ramDisk) {
448 initrd_start = (unsigned long) boot_infos
449 + boot_infos->ramDisk;
450 initrd_end = initrd_start + boot_infos->ramDiskSize;
451 initrd_below_start_ok = 1;
455 struct device_node *chosen;
458 #ifdef CONFIG_BLK_DEV_INITRD
459 if (r3 && r4 && r4 != 0xdeadbeef) {
463 initrd_end = r3 + r4;
464 ROOT_DEV = Root_RAM0;
465 initrd_below_start_ok = 1;
468 chosen = find_devices("chosen");
469 if (chosen != NULL) {
470 p = get_property(chosen, "bootargs", NULL);
472 strlcpy(cmd_line, p, sizeof(cmd_line));
477 if (strstr(cmd_line, "adb_sync")) {
478 extern int __adb_probe_sync;
479 __adb_probe_sync = 1;
481 #endif /* CONFIG_ADB */
485 pmac_init(r3, r4, r5, r6, r7);
488 chrp_init(r3, r4, r5, r6, r7);
493 #ifdef CONFIG_SERIAL_CORE_CONSOLE
494 extern char *of_stdout_device;
496 static int __init set_preferred_console(void)
498 struct device_node *prom_stdout;
502 if (of_stdout_device == NULL)
505 /* The user has requested a console so this is already set up. */
506 if (strstr(saved_command_line, "console="))
509 prom_stdout = find_path_device(of_stdout_device);
513 name = (char *)get_property(prom_stdout, "name", NULL);
517 if (strcmp(name, "serial") == 0) {
519 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
535 /* We dont recognise the serial port */
539 } else if (strcmp(name, "ch-a") == 0)
541 else if (strcmp(name, "ch-b") == 0)
545 return add_preferred_console("ttyS", offset, NULL);
547 console_initcall(set_preferred_console);
548 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
549 #endif /* CONFIG_PPC_MULTIPLATFORM */
551 struct bi_record *find_bootinfo(void)
553 struct bi_record *rec;
555 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
556 if ( rec->tag != BI_FIRST ) {
558 * This 0x10000 offset is a terrible hack but it will go away when
559 * we have the bootloader handle all the relocation and
562 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
563 if ( rec->tag != BI_FIRST )
569 void parse_bootinfo(struct bi_record *rec)
571 if (rec == NULL || rec->tag != BI_FIRST)
573 while (rec->tag != BI_LAST) {
574 ulong *data = rec->data;
577 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
579 #ifdef CONFIG_BLK_DEV_INITRD
581 initrd_start = data[0] + KERNELBASE;
582 initrd_end = data[0] + data[1] + KERNELBASE;
584 #endif /* CONFIG_BLK_DEV_INITRD */
585 #ifdef CONFIG_PPC_MULTIPLATFORM
591 boot_mem_size = data[0];
594 rec = (struct bi_record *)((ulong)rec + rec->size);
599 * Find out what kind of machine we're on and save any data we need
600 * from the early boot process (devtree is copied on pmac by prom_init()).
601 * This is called very early on the boot process, after a minimal
602 * MMU environment has been set up but before MMU_init is called.
605 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
606 unsigned long r6, unsigned long r7)
608 #ifdef CONFIG_CMDLINE
609 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
610 #endif /* CONFIG_CMDLINE */
613 ppc_md.power_save = ppc6xx_idle;
616 ppc_md.power_save = power4_idle;
619 platform_init(r3, r4, r5, r6, r7);
622 ppc_md.progress("id mach(): done", 0x200);
625 /* Checks "l2cr=xxxx" command-line option */
626 int __init ppc_setup_l2cr(char *str)
628 if (cpu_has_feature(CPU_FTR_L2CR)) {
629 unsigned long val = simple_strtoul(str, NULL, 0);
630 printk(KERN_INFO "l2cr set to %lx\n", val);
631 _set_L2CR(0); /* force invalidate by disable cache */
632 _set_L2CR(val); /* and enable it */
636 __setup("l2cr=", ppc_setup_l2cr);
638 #ifdef CONFIG_GENERIC_NVRAM
640 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
641 unsigned char nvram_read_byte(int addr)
643 if (ppc_md.nvram_read_val)
644 return ppc_md.nvram_read_val(addr);
647 EXPORT_SYMBOL(nvram_read_byte);
649 void nvram_write_byte(unsigned char val, int addr)
651 if (ppc_md.nvram_write_val)
652 ppc_md.nvram_write_val(addr, val);
654 EXPORT_SYMBOL(nvram_write_byte);
656 void nvram_sync(void)
658 if (ppc_md.nvram_sync)
661 EXPORT_SYMBOL(nvram_sync);
663 #endif /* CONFIG_NVRAM */
665 static struct cpu cpu_devices[NR_CPUS];
667 int __init ppc_init(void)
671 /* clear the progress line */
672 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
674 /* register CPU devices */
675 for (i = 0; i < NR_CPUS; i++)
677 register_cpu(&cpu_devices[i], i, NULL);
679 /* call platform init */
680 if (ppc_md.init != NULL) {
686 arch_initcall(ppc_init);
688 /* Warning, IO base is not yet inited */
689 void __init setup_arch(char **cmdline_p)
692 extern void do_init_bootmem(void);
694 /* so udelay does something sensible, assume <= 1000 bogomips */
695 loops_per_jiffy = 500000000 / HZ;
697 #ifdef CONFIG_PPC_MULTIPLATFORM
698 /* This could be called "early setup arch", it must be done
699 * now because xmon need it
701 if (_machine == _MACH_Pmac)
702 pmac_feature_init(); /* New cool way */
707 if (strstr(cmd_line, "xmon"))
709 #endif /* CONFIG_XMON */
710 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
712 #if defined(CONFIG_KGDB)
713 if (ppc_md.kgdb_map_scc)
714 ppc_md.kgdb_map_scc();
716 if (strstr(cmd_line, "gdb")) {
718 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
719 printk("kgdb breakpoint activated\n");
725 * Set cache line size based on type of cpu as a default.
726 * Systems with OF can look in the properties on the cpu node(s)
727 * for a possibly more accurate value.
729 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
730 dcache_bsize = cur_cpu_spec[0]->dcache_bsize;
731 icache_bsize = cur_cpu_spec[0]->icache_bsize;
734 ucache_bsize = dcache_bsize = icache_bsize
735 = cur_cpu_spec[0]->dcache_bsize;
737 /* reboot on panic */
740 init_mm.start_code = PAGE_OFFSET;
741 init_mm.end_code = (unsigned long) _etext;
742 init_mm.end_data = (unsigned long) _edata;
743 init_mm.brk = (unsigned long) klimit;
745 /* Save unparsed command line copy for /proc/cmdline */
746 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
747 *cmdline_p = cmd_line;
751 /* set up the bootmem stuff with available memory */
753 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
755 #ifdef CONFIG_PPC_OCP
756 /* Initialize OCP device list */
758 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
761 #ifdef CONFIG_DUMMY_CONSOLE
762 conswitchp = &dummy_con;
766 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
770 /* this is for modules since _machine can be a define -- Cort */
771 ppc_md.ppc_machine = _machine;