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 EXPORT_SYMBOL(have_of
);
94 int ppc_do_canonicalize_irqs
;
95 EXPORT_SYMBOL(ppc_do_canonicalize_irqs
);
98 #ifdef CONFIG_MAGIC_SYSRQ
99 unsigned long SYSRQ_KEY
= 0x54;
100 #endif /* CONFIG_MAGIC_SYSRQ */
102 #ifdef CONFIG_VGA_CONSOLE
103 unsigned long vgacon_remap_base
;
106 struct machdep_calls ppc_md
;
109 * These are used in binfmt_elf.c to put aux entries on the stack
110 * for each elf executable being started.
116 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
117 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
118 struct screen_info screen_info
= {
119 0, 25, /* orig-x, orig-y */
121 0, /* orig-video-page */
122 0, /* orig-video-mode */
123 80, /* orig-video-cols */
124 0,0,0, /* ega_ax, ega_bx, ega_cx */
125 25, /* orig-video-lines */
126 1, /* orig-video-isVGA */
127 16 /* orig-video-points */
129 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
131 void machine_restart(char *cmd
)
139 void machine_power_off(void)
147 void machine_halt(void)
155 void (*pm_power_off
)(void) = machine_power_off
;
158 extern u32
cpu_temp(unsigned long cpu
);
159 extern u32
cpu_temp_both(unsigned long cpu
);
160 #endif /* CONFIG_TAU */
162 int show_cpuinfo(struct seq_file
*m
, void *v
)
167 unsigned short maj
, min
;
171 /* Show summary information */
173 unsigned long bogosum
= 0;
174 for (i
= 0; i
< NR_CPUS
; ++i
)
176 bogosum
+= cpu_data
[i
].loops_per_jiffy
;
177 seq_printf(m
, "total bogomips\t: %lu.%02lu\n",
178 bogosum
/(500000/HZ
), bogosum
/(5000/HZ
) % 100);
179 #endif /* CONFIG_SMP */
181 if (ppc_md
.show_cpuinfo
!= NULL
)
182 err
= ppc_md
.show_cpuinfo(m
);
189 pvr
= cpu_data
[i
].pvr
;
190 lpj
= cpu_data
[i
].loops_per_jiffy
;
192 pvr
= mfspr(SPRN_PVR
);
193 lpj
= loops_per_jiffy
;
196 seq_printf(m
, "processor\t: %d\n", i
);
197 seq_printf(m
, "cpu\t\t: ");
199 if (cur_cpu_spec
->pvr_mask
)
200 seq_printf(m
, "%s", cur_cpu_spec
->cpu_name
);
202 seq_printf(m
, "unknown (%08x)", pvr
);
203 #ifdef CONFIG_ALTIVEC
204 if (cur_cpu_spec
->cpu_features
& CPU_FTR_ALTIVEC
)
205 seq_printf(m
, ", altivec supported");
210 if (cur_cpu_spec
->cpu_features
& CPU_FTR_TAU
) {
211 #ifdef CONFIG_TAU_AVERAGE
212 /* more straightforward, but potentially misleading */
213 seq_printf(m
, "temperature \t: %u C (uncalibrated)\n",
216 /* show the actual temp sensor range */
218 temp
= cpu_temp_both(i
);
219 seq_printf(m
, "temperature \t: %u-%u C (uncalibrated)\n",
220 temp
& 0xff, temp
>> 16);
223 #endif /* CONFIG_TAU */
225 if (ppc_md
.show_percpuinfo
!= NULL
) {
226 err
= ppc_md
.show_percpuinfo(m
, i
);
231 /* If we are a Freescale core do a simple check so
232 * we dont have to keep adding cases in the future */
233 if ((PVR_VER(pvr
) & 0x8000) == 0x8000) {
237 switch (PVR_VER(pvr
)) {
238 case 0x0020: /* 403 family */
239 maj
= PVR_MAJ(pvr
) + 1;
242 case 0x1008: /* 740P/750P ?? */
243 maj
= ((pvr
>> 8) & 0xFF) - 1;
247 maj
= (pvr
>> 8) & 0xFF;
253 seq_printf(m
, "revision\t: %hd.%hd (pvr %04x %04x)\n",
254 maj
, min
, PVR_VER(pvr
), PVR_REV(pvr
));
256 seq_printf(m
, "bogomips\t: %lu.%02lu\n",
257 lpj
/ (500000/HZ
), (lpj
/ (5000/HZ
)) % 100);
260 if (cur_ppc_sys_spec
->ppc_sys_name
)
261 seq_printf(m
, "chipset\t\t: %s\n",
262 cur_ppc_sys_spec
->ppc_sys_name
);
272 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
276 return i
<= NR_CPUS
? (void *) (i
+ 1): NULL
;
279 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
282 return c_start(m
, pos
);
285 static void c_stop(struct seq_file
*m
, void *v
)
289 struct seq_operations cpuinfo_op
= {
293 .show
= show_cpuinfo
,
297 * We're called here very early in the boot. We determine the machine
298 * type and call the appropriate low-level setup functions.
299 * -- Cort <cort@fsmlabs.com>
301 * Note that the kernel may be running at an address which is different
302 * from the address that it was linked at, so we must use RELOC/PTRRELOC
303 * to access static data (including strings). -- paulus
307 early_init(int r3
, int r4
, int r5
)
310 unsigned long offset
= reloc_offset();
313 phys
= offset
+ KERNELBASE
;
315 /* First zero the BSS -- use memset, some arches don't have
317 memset_io(PTRRELOC(&__bss_start
), 0, _end
- __bss_start
);
320 * Identify the CPU type and fix up code sections
321 * that depend on which cpu we have.
323 identify_cpu(offset
, 0);
324 do_cpu_ftr_fixups(offset
);
326 #if defined(CONFIG_PPC_MULTIPLATFORM)
329 /* If we came here from BootX, clear the screen,
330 * set up some pointers and return. */
331 if ((r3
== 0x426f6f58) && (r5
== 0))
332 bootx_init(r4
, phys
);
335 * don't do anything on prep
336 * for now, don't use bootinfo because it breaks yaboot 0.5
337 * and assume that if we didn't find a magic number, we have OF
339 else if (*(unsigned long *)(0) != 0xdeadc0de)
340 phys
= prom_init(r3
, r4
, (prom_entry
)r5
);
350 * Assume here that all clock rates are the same in a
351 * smp system. -- Cort
354 of_show_percpuinfo(struct seq_file
*m
, int i
)
356 struct device_node
*cpu_node
;
360 cpu_node
= find_type_devices("cpu");
363 for (s
= 0; s
< i
&& cpu_node
->next
; s
++)
364 cpu_node
= cpu_node
->next
;
365 fp
= (u32
*)get_property(cpu_node
, "clock-frequency", NULL
);
367 seq_printf(m
, "clock\t\t: %dMHz\n", *fp
/ 1000000);
372 intuit_machine_type(void)
375 struct device_node
*root
;
377 /* ask the OF info if we're a chrp or pmac */
378 root
= find_path_device("/");
380 /* assume pmac unless proven to be chrp -- Cort */
381 _machine
= _MACH_Pmac
;
382 model
= get_property(root
, "device_type", NULL
);
383 if (model
&& !strncmp("chrp", model
, 4))
384 _machine
= _MACH_chrp
;
386 model
= get_property(root
, "model", NULL
);
387 if (model
&& !strncmp(model
, "IBM", 3))
388 _machine
= _MACH_chrp
;
394 #ifdef CONFIG_PPC_MULTIPLATFORM
396 * The PPC_MULTIPLATFORM version of platform_init...
399 platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
400 unsigned long r6
, unsigned long r7
)
402 #ifdef CONFIG_BOOTX_TEXT
403 if (boot_text_mapped
) {
409 parse_bootinfo(find_bootinfo());
411 /* if we didn't get any bootinfo telling us what we are... */
413 /* prep boot loader tells us if we're prep or not */
414 if ( *(unsigned long *)(KERNELBASE
) == (0xdeadc0de) )
415 _machine
= _MACH_prep
;
418 #ifdef CONFIG_PPC_PREP
419 /* not much more to do here, if prep */
420 if (_machine
== _MACH_prep
) {
421 prep_init(r3
, r4
, r5
, r6
, r7
);
428 /* prom_init has already been called from __start */
432 /* If we aren't PReP, we can find out if we're Pmac
433 * or CHRP with this. */
435 intuit_machine_type();
437 /* finish_device_tree may need _machine defined. */
438 finish_device_tree();
441 * If we were booted via quik, r3 points to the physical
442 * address of the command-line parameters.
443 * If we were booted from an xcoff image (i.e. netbooted or
444 * booted from floppy), we get the command line from the
445 * bootargs property of the /chosen node.
446 * If an initial ramdisk is present, r3 and r4
447 * are used for initrd_start and initrd_size,
448 * otherwise they contain 0xdeadbeef.
450 if (r3
>= 0x4000 && r3
< 0x800000 && r4
== 0) {
451 strlcpy(cmd_line
, (char *)r3
+ KERNELBASE
,
453 } else if (boot_infos
!= 0) {
454 /* booted by BootX - check for ramdisk */
455 if (boot_infos
->kernelParamsOffset
!= 0)
456 strlcpy(cmd_line
, (char *) boot_infos
457 + boot_infos
->kernelParamsOffset
,
459 #ifdef CONFIG_BLK_DEV_INITRD
460 if (boot_infos
->ramDisk
) {
461 initrd_start
= (unsigned long) boot_infos
462 + boot_infos
->ramDisk
;
463 initrd_end
= initrd_start
+ boot_infos
->ramDiskSize
;
464 initrd_below_start_ok
= 1;
468 struct device_node
*chosen
;
471 #ifdef CONFIG_BLK_DEV_INITRD
472 if (r3
&& r4
&& r4
!= 0xdeadbeef) {
476 initrd_end
= r3
+ r4
;
477 ROOT_DEV
= Root_RAM0
;
478 initrd_below_start_ok
= 1;
481 chosen
= find_devices("chosen");
482 if (chosen
!= NULL
) {
483 p
= get_property(chosen
, "bootargs", NULL
);
485 strlcpy(cmd_line
, p
, sizeof(cmd_line
));
490 if (strstr(cmd_line
, "adb_sync")) {
491 extern int __adb_probe_sync
;
492 __adb_probe_sync
= 1;
494 #endif /* CONFIG_ADB */
497 #ifdef CONFIG_PPC_PMAC
499 pmac_init(r3
, r4
, r5
, r6
, r7
);
502 #ifdef CONFIG_PPC_CHRP
504 chrp_init(r3
, r4
, r5
, r6
, r7
);
510 #ifdef CONFIG_SERIAL_CORE_CONSOLE
511 extern char *of_stdout_device
;
513 static int __init
set_preferred_console(void)
515 struct device_node
*prom_stdout
;
519 if (of_stdout_device
== NULL
)
522 /* The user has requested a console so this is already set up. */
523 if (strstr(saved_command_line
, "console="))
526 prom_stdout
= find_path_device(of_stdout_device
);
530 name
= (char *)get_property(prom_stdout
, "name", NULL
);
534 if (strcmp(name
, "serial") == 0) {
536 u32
*reg
= (u32
*)get_property(prom_stdout
, "reg", &i
);
552 /* We dont recognise the serial port */
556 } else if (strcmp(name
, "ch-a") == 0)
558 else if (strcmp(name
, "ch-b") == 0)
562 return add_preferred_console("ttyS", offset
, NULL
);
564 console_initcall(set_preferred_console
);
565 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
566 #endif /* CONFIG_PPC_MULTIPLATFORM */
568 struct bi_record
*find_bootinfo(void)
570 struct bi_record
*rec
;
572 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+(1<<20)-1,(1<<20));
573 if ( rec
->tag
!= BI_FIRST
) {
575 * This 0x10000 offset is a terrible hack but it will go away when
576 * we have the bootloader handle all the relocation and
579 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+0x10000+(1<<20)-1,(1<<20));
580 if ( rec
->tag
!= BI_FIRST
)
586 void parse_bootinfo(struct bi_record
*rec
)
588 if (rec
== NULL
|| rec
->tag
!= BI_FIRST
)
590 while (rec
->tag
!= BI_LAST
) {
591 ulong
*data
= rec
->data
;
594 strlcpy(cmd_line
, (void *)data
, sizeof(cmd_line
));
596 #ifdef CONFIG_BLK_DEV_INITRD
598 initrd_start
= data
[0] + KERNELBASE
;
599 initrd_end
= data
[0] + data
[1] + KERNELBASE
;
601 #endif /* CONFIG_BLK_DEV_INITRD */
602 #ifdef CONFIG_PPC_MULTIPLATFORM
608 boot_mem_size
= data
[0];
611 rec
= (struct bi_record
*)((ulong
)rec
+ rec
->size
);
616 * Find out what kind of machine we're on and save any data we need
617 * from the early boot process (devtree is copied on pmac by prom_init()).
618 * This is called very early on the boot process, after a minimal
619 * MMU environment has been set up but before MMU_init is called.
622 machine_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
623 unsigned long r6
, unsigned long r7
)
625 #ifdef CONFIG_CMDLINE
626 strlcpy(cmd_line
, CONFIG_CMDLINE
, sizeof(cmd_line
));
627 #endif /* CONFIG_CMDLINE */
630 ppc_md
.power_save
= ppc6xx_idle
;
633 ppc_md
.power_save
= power4_idle
;
636 platform_init(r3
, r4
, r5
, r6
, r7
);
639 ppc_md
.progress("id mach(): done", 0x200);
641 #ifdef CONFIG_BOOKE_WDT
642 /* Checks wdt=x and wdt_period=xx command-line option */
643 int __init
early_parse_wdt(char *p
)
645 if (p
&& strncmp(p
, "0", 1) != 0)
646 booke_wdt_enabled
= 1;
650 early_param("wdt", early_parse_wdt
);
652 int __init
early_parse_wdt_period (char *p
)
655 booke_wdt_period
= simple_strtoul(p
, NULL
, 0);
659 early_param("wdt_period", early_parse_wdt_period
);
660 #endif /* CONFIG_BOOKE_WDT */
662 /* Checks "l2cr=xxxx" command-line option */
663 int __init
ppc_setup_l2cr(char *str
)
665 if (cpu_has_feature(CPU_FTR_L2CR
)) {
666 unsigned long val
= simple_strtoul(str
, NULL
, 0);
667 printk(KERN_INFO
"l2cr set to %lx\n", val
);
668 _set_L2CR(0); /* force invalidate by disable cache */
669 _set_L2CR(val
); /* and enable it */
673 __setup("l2cr=", ppc_setup_l2cr
);
675 #ifdef CONFIG_GENERIC_NVRAM
677 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
678 unsigned char nvram_read_byte(int addr
)
680 if (ppc_md
.nvram_read_val
)
681 return ppc_md
.nvram_read_val(addr
);
684 EXPORT_SYMBOL(nvram_read_byte
);
686 void nvram_write_byte(unsigned char val
, int addr
)
688 if (ppc_md
.nvram_write_val
)
689 ppc_md
.nvram_write_val(addr
, val
);
691 EXPORT_SYMBOL(nvram_write_byte
);
693 void nvram_sync(void)
695 if (ppc_md
.nvram_sync
)
698 EXPORT_SYMBOL(nvram_sync
);
700 #endif /* CONFIG_NVRAM */
702 static struct cpu cpu_devices
[NR_CPUS
];
704 int __init
ppc_init(void)
708 /* clear the progress line */
709 if ( ppc_md
.progress
) ppc_md
.progress(" ", 0xffff);
711 /* register CPU devices */
712 for (i
= 0; i
< NR_CPUS
; i
++)
714 register_cpu(&cpu_devices
[i
], i
, NULL
);
716 /* call platform init */
717 if (ppc_md
.init
!= NULL
) {
723 arch_initcall(ppc_init
);
725 /* Warning, IO base is not yet inited */
726 void __init
setup_arch(char **cmdline_p
)
729 extern void do_init_bootmem(void);
731 /* so udelay does something sensible, assume <= 1000 bogomips */
732 loops_per_jiffy
= 500000000 / HZ
;
734 #ifdef CONFIG_PPC_MULTIPLATFORM
735 /* This could be called "early setup arch", it must be done
736 * now because xmon need it
738 if (_machine
== _MACH_Pmac
)
739 pmac_feature_init(); /* New cool way */
744 if (strstr(cmd_line
, "xmon"))
746 #endif /* CONFIG_XMON */
747 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: enter", 0x3eab);
749 #if defined(CONFIG_KGDB)
750 if (ppc_md
.kgdb_map_scc
)
751 ppc_md
.kgdb_map_scc();
753 if (strstr(cmd_line
, "gdb")) {
755 ppc_md
.progress("setup_arch: kgdb breakpoint", 0x4000);
756 printk("kgdb breakpoint activated\n");
762 * Set cache line size based on type of cpu as a default.
763 * Systems with OF can look in the properties on the cpu node(s)
764 * for a possibly more accurate value.
766 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE
)) {
767 dcache_bsize
= cur_cpu_spec
->dcache_bsize
;
768 icache_bsize
= cur_cpu_spec
->icache_bsize
;
771 ucache_bsize
= dcache_bsize
= icache_bsize
772 = cur_cpu_spec
->dcache_bsize
;
774 /* reboot on panic */
777 init_mm
.start_code
= PAGE_OFFSET
;
778 init_mm
.end_code
= (unsigned long) _etext
;
779 init_mm
.end_data
= (unsigned long) _edata
;
780 init_mm
.brk
= (unsigned long) klimit
;
782 /* Save unparsed command line copy for /proc/cmdline */
783 strlcpy(saved_command_line
, cmd_line
, COMMAND_LINE_SIZE
);
784 *cmdline_p
= cmd_line
;
788 /* set up the bootmem stuff with available memory */
790 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: bootmem", 0x3eab);
792 #ifdef CONFIG_PPC_OCP
793 /* Initialize OCP device list */
795 if ( ppc_md
.progress
) ppc_md
.progress("ocp: exit", 0x3eab);
798 #ifdef CONFIG_DUMMY_CONSOLE
799 conswitchp
= &dummy_con
;
803 if ( ppc_md
.progress
) ppc_md
.progress("arch: exit", 0x3eab);
807 /* this is for modules since _machine can be a define -- Cort */
808 ppc_md
.ppc_machine
= _machine
;