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(unsigned long r3, unsigned long r4,
57 unsigned long r5, unsigned long r6, unsigned long r7);
58 extern void bootx_init(unsigned long r4, unsigned long phys);
59 extern void identify_cpu(unsigned long offset, unsigned long cpu);
60 extern void do_cpu_ftr_fixups(unsigned long offset);
61 extern void reloc_got2(unsigned long offset);
63 extern void ppc6xx_idle(void);
64 extern void power4_idle(void);
66 extern boot_infos_t *boot_infos;
67 struct ide_machdep_calls ppc_ide_md;
69 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
70 size value reported by the boot loader. */
71 unsigned long boot_mem_size;
73 unsigned long ISA_DMA_THRESHOLD;
74 unsigned int DMA_MODE_READ;
75 unsigned int DMA_MODE_WRITE;
77 #ifdef CONFIG_PPC_MULTIPLATFORM
80 extern void prep_init(unsigned long r3, unsigned long r4,
81 unsigned long r5, unsigned long r6, unsigned long r7);
82 extern void pmac_init(unsigned long r3, unsigned long r4,
83 unsigned long r5, unsigned long r6, unsigned long r7);
84 extern void chrp_init(unsigned long r3, unsigned long r4,
85 unsigned long r5, unsigned long r6, unsigned long r7);
88 #endif /* CONFIG_PPC_MULTIPLATFORM */
91 int ppc_do_canonicalize_irqs;
92 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
95 #ifdef CONFIG_MAGIC_SYSRQ
96 unsigned long SYSRQ_KEY = 0x54;
97 #endif /* CONFIG_MAGIC_SYSRQ */
99 #ifdef CONFIG_VGA_CONSOLE
100 unsigned long vgacon_remap_base;
103 struct machdep_calls ppc_md;
106 * These are used in binfmt_elf.c to put aux entries on the stack
107 * for each elf executable being started.
113 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
114 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
115 struct screen_info screen_info = {
116 0, 25, /* orig-x, orig-y */
118 0, /* orig-video-page */
119 0, /* orig-video-mode */
120 80, /* orig-video-cols */
121 0,0,0, /* ega_ax, ega_bx, ega_cx */
122 25, /* orig-video-lines */
123 1, /* orig-video-isVGA */
124 16 /* orig-video-points */
126 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
128 void machine_restart(char *cmd)
136 void machine_power_off(void)
144 void machine_halt(void)
152 void (*pm_power_off)(void) = machine_power_off;
155 extern u32 cpu_temp(unsigned long cpu);
156 extern u32 cpu_temp_both(unsigned long cpu);
157 #endif /* CONFIG_TAU */
159 int show_cpuinfo(struct seq_file *m, void *v)
164 unsigned short maj, min;
168 /* Show summary information */
170 unsigned long bogosum = 0;
171 for (i = 0; i < NR_CPUS; ++i)
173 bogosum += cpu_data[i].loops_per_jiffy;
174 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
175 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
176 #endif /* CONFIG_SMP */
178 if (ppc_md.show_cpuinfo != NULL)
179 err = ppc_md.show_cpuinfo(m);
186 pvr = cpu_data[i].pvr;
187 lpj = cpu_data[i].loops_per_jiffy;
189 pvr = mfspr(SPRN_PVR);
190 lpj = loops_per_jiffy;
193 seq_printf(m, "processor\t: %d\n", i);
194 seq_printf(m, "cpu\t\t: ");
196 if (cur_cpu_spec->pvr_mask)
197 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
199 seq_printf(m, "unknown (%08x)", pvr);
200 #ifdef CONFIG_ALTIVEC
201 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
202 seq_printf(m, ", altivec supported");
207 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
208 #ifdef CONFIG_TAU_AVERAGE
209 /* more straightforward, but potentially misleading */
210 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
213 /* show the actual temp sensor range */
215 temp = cpu_temp_both(i);
216 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
217 temp & 0xff, temp >> 16);
220 #endif /* CONFIG_TAU */
222 if (ppc_md.show_percpuinfo != NULL) {
223 err = ppc_md.show_percpuinfo(m, i);
228 /* If we are a Freescale core do a simple check so
229 * we dont have to keep adding cases in the future */
230 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
234 switch (PVR_VER(pvr)) {
235 case 0x0020: /* 403 family */
236 maj = PVR_MAJ(pvr) + 1;
239 case 0x1008: /* 740P/750P ?? */
240 maj = ((pvr >> 8) & 0xFF) - 1;
244 maj = (pvr >> 8) & 0xFF;
250 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
251 maj, min, PVR_VER(pvr), PVR_REV(pvr));
253 seq_printf(m, "bogomips\t: %lu.%02lu\n",
254 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
257 if (cur_ppc_sys_spec->ppc_sys_name)
258 seq_printf(m, "chipset\t\t: %s\n",
259 cur_ppc_sys_spec->ppc_sys_name);
269 static void *c_start(struct seq_file *m, loff_t *pos)
273 return i <= NR_CPUS? (void *) (i + 1): NULL;
276 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
279 return c_start(m, pos);
282 static void c_stop(struct seq_file *m, void *v)
286 struct seq_operations cpuinfo_op = {
290 .show = show_cpuinfo,
294 * We're called here very early in the boot. We determine the machine
295 * type and call the appropriate low-level setup functions.
296 * -- Cort <cort@fsmlabs.com>
298 * Note that the kernel may be running at an address which is different
299 * from the address that it was linked at, so we must use RELOC/PTRRELOC
300 * to access static data (including strings). -- paulus
304 early_init(int r3, int r4, int r5)
307 unsigned long offset = reloc_offset();
310 phys = offset + KERNELBASE;
312 /* First zero the BSS -- use memset, some arches don't have
314 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
317 * Identify the CPU type and fix up code sections
318 * that depend on which cpu we have.
320 identify_cpu(offset, 0);
321 do_cpu_ftr_fixups(offset);
323 #if defined(CONFIG_PPC_MULTIPLATFORM)
326 /* If we came here from BootX, clear the screen,
327 * set up some pointers and return. */
328 if ((r3 == 0x426f6f58) && (r5 == 0))
329 bootx_init(r4, phys);
332 * don't do anything on prep
333 * for now, don't use bootinfo because it breaks yaboot 0.5
334 * and assume that if we didn't find a magic number, we have OF
336 else if (*(unsigned long *)(0) != 0xdeadc0de)
337 phys = prom_init(r3, r4, (prom_entry)r5);
347 * Assume here that all clock rates are the same in a
348 * smp system. -- Cort
351 of_show_percpuinfo(struct seq_file *m, int i)
353 struct device_node *cpu_node;
357 cpu_node = find_type_devices("cpu");
360 for (s = 0; s < i && cpu_node->next; s++)
361 cpu_node = cpu_node->next;
362 fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL);
364 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
369 intuit_machine_type(void)
372 struct device_node *root;
374 /* ask the OF info if we're a chrp or pmac */
375 root = find_path_device("/");
377 /* assume pmac unless proven to be chrp -- Cort */
378 _machine = _MACH_Pmac;
379 model = get_property(root, "device_type", NULL);
380 if (model && !strncmp("chrp", model, 4))
381 _machine = _MACH_chrp;
383 model = get_property(root, "model", NULL);
384 if (model && !strncmp(model, "IBM", 3))
385 _machine = _MACH_chrp;
391 #ifdef CONFIG_PPC_MULTIPLATFORM
393 * The PPC_MULTIPLATFORM version of platform_init...
396 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
397 unsigned long r6, unsigned long r7)
399 #ifdef CONFIG_BOOTX_TEXT
400 if (boot_text_mapped) {
406 parse_bootinfo(find_bootinfo());
408 /* if we didn't get any bootinfo telling us what we are... */
410 /* prep boot loader tells us if we're prep or not */
411 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
412 _machine = _MACH_prep;
415 #ifdef CONFIG_PPC_PREP
416 /* not much more to do here, if prep */
417 if (_machine == _MACH_prep) {
418 prep_init(r3, r4, r5, r6, r7);
423 /* prom_init has already been called from __start */
427 /* If we aren't PReP, we can find out if we're Pmac
428 * or CHRP with this. */
430 intuit_machine_type();
432 /* finish_device_tree may need _machine defined. */
433 finish_device_tree();
436 * If we were booted via quik, r3 points to the physical
437 * address of the command-line parameters.
438 * If we were booted from an xcoff image (i.e. netbooted or
439 * booted from floppy), we get the command line from the
440 * bootargs property of the /chosen node.
441 * If an initial ramdisk is present, r3 and r4
442 * are used for initrd_start and initrd_size,
443 * otherwise they contain 0xdeadbeef.
445 if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
446 strlcpy(cmd_line, (char *)r3 + KERNELBASE,
448 } else if (boot_infos != 0) {
449 /* booted by BootX - check for ramdisk */
450 if (boot_infos->kernelParamsOffset != 0)
451 strlcpy(cmd_line, (char *) boot_infos
452 + boot_infos->kernelParamsOffset,
454 #ifdef CONFIG_BLK_DEV_INITRD
455 if (boot_infos->ramDisk) {
456 initrd_start = (unsigned long) boot_infos
457 + boot_infos->ramDisk;
458 initrd_end = initrd_start + boot_infos->ramDiskSize;
459 initrd_below_start_ok = 1;
463 struct device_node *chosen;
466 #ifdef CONFIG_BLK_DEV_INITRD
467 if (r3 && r4 && r4 != 0xdeadbeef) {
471 initrd_end = r3 + r4;
472 ROOT_DEV = Root_RAM0;
473 initrd_below_start_ok = 1;
476 chosen = find_devices("chosen");
477 if (chosen != NULL) {
478 p = get_property(chosen, "bootargs", NULL);
480 strlcpy(cmd_line, p, sizeof(cmd_line));
485 if (strstr(cmd_line, "adb_sync")) {
486 extern int __adb_probe_sync;
487 __adb_probe_sync = 1;
489 #endif /* CONFIG_ADB */
492 #ifdef CONFIG_PPC_PMAC
494 pmac_init(r3, r4, r5, r6, r7);
497 #ifdef CONFIG_PPC_CHRP
499 chrp_init(r3, r4, r5, r6, r7);
505 #ifdef CONFIG_SERIAL_CORE_CONSOLE
506 extern char *of_stdout_device;
508 static int __init set_preferred_console(void)
510 struct device_node *prom_stdout;
514 if (of_stdout_device == NULL)
517 /* The user has requested a console so this is already set up. */
518 if (strstr(saved_command_line, "console="))
521 prom_stdout = find_path_device(of_stdout_device);
525 name = (char *)get_property(prom_stdout, "name", NULL);
529 if (strcmp(name, "serial") == 0) {
531 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
547 /* We dont recognise the serial port */
551 } else if (strcmp(name, "ch-a") == 0)
553 else if (strcmp(name, "ch-b") == 0)
557 return add_preferred_console("ttyS", offset, NULL);
559 console_initcall(set_preferred_console);
560 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
561 #endif /* CONFIG_PPC_MULTIPLATFORM */
563 struct bi_record *find_bootinfo(void)
565 struct bi_record *rec;
567 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
568 if ( rec->tag != BI_FIRST ) {
570 * This 0x10000 offset is a terrible hack but it will go away when
571 * we have the bootloader handle all the relocation and
574 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
575 if ( rec->tag != BI_FIRST )
581 void parse_bootinfo(struct bi_record *rec)
583 if (rec == NULL || rec->tag != BI_FIRST)
585 while (rec->tag != BI_LAST) {
586 ulong *data = rec->data;
589 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
591 #ifdef CONFIG_BLK_DEV_INITRD
593 initrd_start = data[0] + KERNELBASE;
594 initrd_end = data[0] + data[1] + KERNELBASE;
596 #endif /* CONFIG_BLK_DEV_INITRD */
597 #ifdef CONFIG_PPC_MULTIPLATFORM
603 boot_mem_size = data[0];
606 rec = (struct bi_record *)((ulong)rec + rec->size);
611 * Find out what kind of machine we're on and save any data we need
612 * from the early boot process (devtree is copied on pmac by prom_init()).
613 * This is called very early on the boot process, after a minimal
614 * MMU environment has been set up but before MMU_init is called.
617 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
618 unsigned long r6, unsigned long r7)
620 #ifdef CONFIG_CMDLINE
621 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
622 #endif /* CONFIG_CMDLINE */
625 ppc_md.power_save = ppc6xx_idle;
628 ppc_md.power_save = power4_idle;
631 platform_init(r3, r4, r5, r6, r7);
634 ppc_md.progress("id mach(): done", 0x200);
636 #ifdef CONFIG_BOOKE_WDT
637 /* Checks wdt=x and wdt_period=xx command-line option */
638 int __init early_parse_wdt(char *p)
640 if (p && strncmp(p, "0", 1) != 0)
641 booke_wdt_enabled = 1;
645 early_param("wdt", early_parse_wdt);
647 int __init early_parse_wdt_period (char *p)
650 booke_wdt_period = simple_strtoul(p, NULL, 0);
654 early_param("wdt_period", early_parse_wdt_period);
655 #endif /* CONFIG_BOOKE_WDT */
657 /* Checks "l2cr=xxxx" command-line option */
658 int __init ppc_setup_l2cr(char *str)
660 if (cpu_has_feature(CPU_FTR_L2CR)) {
661 unsigned long val = simple_strtoul(str, NULL, 0);
662 printk(KERN_INFO "l2cr set to %lx\n", val);
663 _set_L2CR(0); /* force invalidate by disable cache */
664 _set_L2CR(val); /* and enable it */
668 __setup("l2cr=", ppc_setup_l2cr);
670 #ifdef CONFIG_GENERIC_NVRAM
672 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
673 unsigned char nvram_read_byte(int addr)
675 if (ppc_md.nvram_read_val)
676 return ppc_md.nvram_read_val(addr);
679 EXPORT_SYMBOL(nvram_read_byte);
681 void nvram_write_byte(unsigned char val, int addr)
683 if (ppc_md.nvram_write_val)
684 ppc_md.nvram_write_val(addr, val);
686 EXPORT_SYMBOL(nvram_write_byte);
688 void nvram_sync(void)
690 if (ppc_md.nvram_sync)
693 EXPORT_SYMBOL(nvram_sync);
695 #endif /* CONFIG_NVRAM */
697 static struct cpu cpu_devices[NR_CPUS];
699 int __init ppc_init(void)
703 /* clear the progress line */
704 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
706 /* register CPU devices */
707 for (i = 0; i < NR_CPUS; i++)
709 register_cpu(&cpu_devices[i], i, NULL);
711 /* call platform init */
712 if (ppc_md.init != NULL) {
718 arch_initcall(ppc_init);
720 /* Warning, IO base is not yet inited */
721 void __init setup_arch(char **cmdline_p)
724 extern void do_init_bootmem(void);
726 /* so udelay does something sensible, assume <= 1000 bogomips */
727 loops_per_jiffy = 500000000 / HZ;
729 #ifdef CONFIG_PPC_MULTIPLATFORM
730 /* This could be called "early setup arch", it must be done
731 * now because xmon need it
733 if (_machine == _MACH_Pmac)
734 pmac_feature_init(); /* New cool way */
739 if (strstr(cmd_line, "xmon"))
741 #endif /* CONFIG_XMON */
742 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
744 #if defined(CONFIG_KGDB)
745 if (ppc_md.kgdb_map_scc)
746 ppc_md.kgdb_map_scc();
748 if (strstr(cmd_line, "gdb")) {
750 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
751 printk("kgdb breakpoint activated\n");
757 * Set cache line size based on type of cpu as a default.
758 * Systems with OF can look in the properties on the cpu node(s)
759 * for a possibly more accurate value.
761 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
762 dcache_bsize = cur_cpu_spec->dcache_bsize;
763 icache_bsize = cur_cpu_spec->icache_bsize;
766 ucache_bsize = dcache_bsize = icache_bsize
767 = cur_cpu_spec->dcache_bsize;
769 /* reboot on panic */
772 init_mm.start_code = PAGE_OFFSET;
773 init_mm.end_code = (unsigned long) _etext;
774 init_mm.end_data = (unsigned long) _edata;
775 init_mm.brk = (unsigned long) klimit;
777 /* Save unparsed command line copy for /proc/cmdline */
778 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
779 *cmdline_p = cmd_line;
783 /* set up the bootmem stuff with available memory */
785 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
787 #ifdef CONFIG_PPC_OCP
788 /* Initialize OCP device list */
790 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
793 #ifdef CONFIG_DUMMY_CONSOLE
794 conswitchp = &dummy_con;
798 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
802 /* this is for modules since _machine can be a define -- Cort */
803 ppc_md.ppc_machine = _machine;