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
);
86 #endif /* CONFIG_PPC_MULTIPLATFORM */
88 #ifdef CONFIG_MAGIC_SYSRQ
89 unsigned long SYSRQ_KEY
= 0x54;
90 #endif /* CONFIG_MAGIC_SYSRQ */
92 #ifdef CONFIG_VGA_CONSOLE
93 unsigned long vgacon_remap_base
;
96 struct machdep_calls ppc_md
;
99 * These are used in binfmt_elf.c to put aux entries on the stack
100 * for each elf executable being started.
106 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
107 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
108 struct screen_info screen_info
= {
109 0, 25, /* orig-x, orig-y */
111 0, /* orig-video-page */
112 0, /* orig-video-mode */
113 80, /* orig-video-cols */
114 0,0,0, /* ega_ax, ega_bx, ega_cx */
115 25, /* orig-video-lines */
116 1, /* orig-video-isVGA */
117 16 /* orig-video-points */
119 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
121 void machine_restart(char *cmd
)
129 void machine_power_off(void)
137 void machine_halt(void)
145 void (*pm_power_off
)(void) = machine_power_off
;
148 extern u32
cpu_temp(unsigned long cpu
);
149 extern u32
cpu_temp_both(unsigned long cpu
);
150 #endif /* CONFIG_TAU */
152 int show_cpuinfo(struct seq_file
*m
, void *v
)
157 unsigned short maj
, min
;
161 /* Show summary information */
163 unsigned long bogosum
= 0;
164 for (i
= 0; i
< NR_CPUS
; ++i
)
166 bogosum
+= cpu_data
[i
].loops_per_jiffy
;
167 seq_printf(m
, "total bogomips\t: %lu.%02lu\n",
168 bogosum
/(500000/HZ
), bogosum
/(5000/HZ
) % 100);
169 #endif /* CONFIG_SMP */
171 if (ppc_md
.show_cpuinfo
!= NULL
)
172 err
= ppc_md
.show_cpuinfo(m
);
179 pvr
= cpu_data
[i
].pvr
;
180 lpj
= cpu_data
[i
].loops_per_jiffy
;
182 pvr
= mfspr(SPRN_PVR
);
183 lpj
= loops_per_jiffy
;
186 seq_printf(m
, "processor\t: %d\n", i
);
187 seq_printf(m
, "cpu\t\t: ");
189 if (cur_cpu_spec
[i
]->pvr_mask
)
190 seq_printf(m
, "%s", cur_cpu_spec
[i
]->cpu_name
);
192 seq_printf(m
, "unknown (%08x)", pvr
);
193 #ifdef CONFIG_ALTIVEC
194 if (cur_cpu_spec
[i
]->cpu_features
& CPU_FTR_ALTIVEC
)
195 seq_printf(m
, ", altivec supported");
200 if (cur_cpu_spec
[i
]->cpu_features
& CPU_FTR_TAU
) {
201 #ifdef CONFIG_TAU_AVERAGE
202 /* more straightforward, but potentially misleading */
203 seq_printf(m
, "temperature \t: %u C (uncalibrated)\n",
206 /* show the actual temp sensor range */
208 temp
= cpu_temp_both(i
);
209 seq_printf(m
, "temperature \t: %u-%u C (uncalibrated)\n",
210 temp
& 0xff, temp
>> 16);
213 #endif /* CONFIG_TAU */
215 if (ppc_md
.show_percpuinfo
!= NULL
) {
216 err
= ppc_md
.show_percpuinfo(m
, i
);
221 /* If we are a Freescale core do a simple check so
222 * we dont have to keep adding cases in the future */
223 if ((PVR_VER(pvr
) & 0x8000) == 0x8000) {
227 switch (PVR_VER(pvr
)) {
228 case 0x0020: /* 403 family */
229 maj
= PVR_MAJ(pvr
) + 1;
232 case 0x1008: /* 740P/750P ?? */
233 maj
= ((pvr
>> 8) & 0xFF) - 1;
237 maj
= (pvr
>> 8) & 0xFF;
243 seq_printf(m
, "revision\t: %hd.%hd (pvr %04x %04x)\n",
244 maj
, min
, PVR_VER(pvr
), PVR_REV(pvr
));
246 seq_printf(m
, "bogomips\t: %lu.%02lu\n",
247 lpj
/ (500000/HZ
), (lpj
/ (5000/HZ
)) % 100);
250 if (cur_ppc_sys_spec
->ppc_sys_name
)
251 seq_printf(m
, "chipset\t\t: %s\n",
252 cur_ppc_sys_spec
->ppc_sys_name
);
262 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
266 return i
<= NR_CPUS
? (void *) (i
+ 1): NULL
;
269 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
272 return c_start(m
, pos
);
275 static void c_stop(struct seq_file
*m
, void *v
)
279 struct seq_operations cpuinfo_op
= {
283 .show
= show_cpuinfo
,
287 * We're called here very early in the boot. We determine the machine
288 * type and call the appropriate low-level setup functions.
289 * -- Cort <cort@fsmlabs.com>
291 * Note that the kernel may be running at an address which is different
292 * from the address that it was linked at, so we must use RELOC/PTRRELOC
293 * to access static data (including strings). -- paulus
297 early_init(int r3
, int r4
, int r5
)
300 unsigned long offset
= reloc_offset();
303 phys
= offset
+ KERNELBASE
;
305 /* First zero the BSS -- use memset, some arches don't have
307 memset_io(PTRRELOC(&__bss_start
), 0, _end
- __bss_start
);
310 * Identify the CPU type and fix up code sections
311 * that depend on which cpu we have.
313 identify_cpu(offset
, 0);
314 do_cpu_ftr_fixups(offset
);
316 #if defined(CONFIG_PPC_MULTIPLATFORM)
319 /* If we came here from BootX, clear the screen,
320 * set up some pointers and return. */
321 if ((r3
== 0x426f6f58) && (r5
== 0))
322 bootx_init(r4
, phys
);
325 * don't do anything on prep
326 * for now, don't use bootinfo because it breaks yaboot 0.5
327 * and assume that if we didn't find a magic number, we have OF
329 else if (*(unsigned long *)(0) != 0xdeadc0de)
330 phys
= prom_init(r3
, r4
, (prom_entry
)r5
);
340 * Assume here that all clock rates are the same in a
341 * smp system. -- Cort
344 of_show_percpuinfo(struct seq_file
*m
, int i
)
346 struct device_node
*cpu_node
;
350 cpu_node
= find_type_devices("cpu");
353 for (s
= 0; s
< i
&& cpu_node
->next
; s
++)
354 cpu_node
= cpu_node
->next
;
355 fp
= (u32
*)get_property(cpu_node
, "clock-frequency", NULL
);
357 seq_printf(m
, "clock\t\t: %dMHz\n", *fp
/ 1000000);
362 intuit_machine_type(void)
365 struct device_node
*root
;
367 /* ask the OF info if we're a chrp or pmac */
368 root
= find_path_device("/");
370 /* assume pmac unless proven to be chrp -- Cort */
371 _machine
= _MACH_Pmac
;
372 model
= get_property(root
, "device_type", NULL
);
373 if (model
&& !strncmp("chrp", model
, 4))
374 _machine
= _MACH_chrp
;
376 model
= get_property(root
, "model", NULL
);
377 if (model
&& !strncmp(model
, "IBM", 3))
378 _machine
= _MACH_chrp
;
384 #ifdef CONFIG_PPC_MULTIPLATFORM
386 * The PPC_MULTIPLATFORM version of platform_init...
389 platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
390 unsigned long r6
, unsigned long r7
)
392 #ifdef CONFIG_BOOTX_TEXT
393 if (boot_text_mapped
) {
399 parse_bootinfo(find_bootinfo());
401 /* if we didn't get any bootinfo telling us what we are... */
403 /* prep boot loader tells us if we're prep or not */
404 if ( *(unsigned long *)(KERNELBASE
) == (0xdeadc0de) )
405 _machine
= _MACH_prep
;
408 /* not much more to do here, if prep */
409 if (_machine
== _MACH_prep
) {
410 prep_init(r3
, r4
, r5
, r6
, r7
);
414 /* prom_init has already been called from __start */
418 /* If we aren't PReP, we can find out if we're Pmac
419 * or CHRP with this. */
421 intuit_machine_type();
423 /* finish_device_tree may need _machine defined. */
424 finish_device_tree();
427 * If we were booted via quik, r3 points to the physical
428 * address of the command-line parameters.
429 * If we were booted from an xcoff image (i.e. netbooted or
430 * booted from floppy), we get the command line from the
431 * bootargs property of the /chosen node.
432 * If an initial ramdisk is present, r3 and r4
433 * are used for initrd_start and initrd_size,
434 * otherwise they contain 0xdeadbeef.
436 if (r3
>= 0x4000 && r3
< 0x800000 && r4
== 0) {
437 strlcpy(cmd_line
, (char *)r3
+ KERNELBASE
,
439 } else if (boot_infos
!= 0) {
440 /* booted by BootX - check for ramdisk */
441 if (boot_infos
->kernelParamsOffset
!= 0)
442 strlcpy(cmd_line
, (char *) boot_infos
443 + boot_infos
->kernelParamsOffset
,
445 #ifdef CONFIG_BLK_DEV_INITRD
446 if (boot_infos
->ramDisk
) {
447 initrd_start
= (unsigned long) boot_infos
448 + boot_infos
->ramDisk
;
449 initrd_end
= initrd_start
+ boot_infos
->ramDiskSize
;
450 initrd_below_start_ok
= 1;
454 struct device_node
*chosen
;
457 #ifdef CONFIG_BLK_DEV_INITRD
458 if (r3
&& r4
&& r4
!= 0xdeadbeef) {
462 initrd_end
= r3
+ r4
;
463 ROOT_DEV
= Root_RAM0
;
464 initrd_below_start_ok
= 1;
467 chosen
= find_devices("chosen");
468 if (chosen
!= NULL
) {
469 p
= get_property(chosen
, "bootargs", NULL
);
471 strlcpy(cmd_line
, p
, sizeof(cmd_line
));
476 if (strstr(cmd_line
, "adb_sync")) {
477 extern int __adb_probe_sync
;
478 __adb_probe_sync
= 1;
480 #endif /* CONFIG_ADB */
484 pmac_init(r3
, r4
, r5
, r6
, r7
);
487 chrp_init(r3
, r4
, r5
, r6
, r7
);
492 #ifdef CONFIG_SERIAL_CORE_CONSOLE
493 extern char *of_stdout_device
;
495 static int __init
set_preferred_console(void)
497 struct device_node
*prom_stdout
;
501 if (of_stdout_device
== NULL
)
504 /* The user has requested a console so this is already set up. */
505 if (strstr(saved_command_line
, "console="))
508 prom_stdout
= find_path_device(of_stdout_device
);
512 name
= (char *)get_property(prom_stdout
, "name", NULL
);
516 if (strcmp(name
, "serial") == 0) {
518 u32
*reg
= (u32
*)get_property(prom_stdout
, "reg", &i
);
534 /* We dont recognise the serial port */
538 } else if (strcmp(name
, "ch-a") == 0)
540 else if (strcmp(name
, "ch-b") == 0)
544 return add_preferred_console("ttyS", offset
, NULL
);
546 console_initcall(set_preferred_console
);
547 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
548 #endif /* CONFIG_PPC_MULTIPLATFORM */
550 struct bi_record
*find_bootinfo(void)
552 struct bi_record
*rec
;
554 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+(1<<20)-1,(1<<20));
555 if ( rec
->tag
!= BI_FIRST
) {
557 * This 0x10000 offset is a terrible hack but it will go away when
558 * we have the bootloader handle all the relocation and
561 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+0x10000+(1<<20)-1,(1<<20));
562 if ( rec
->tag
!= BI_FIRST
)
568 void parse_bootinfo(struct bi_record
*rec
)
570 if (rec
== NULL
|| rec
->tag
!= BI_FIRST
)
572 while (rec
->tag
!= BI_LAST
) {
573 ulong
*data
= rec
->data
;
576 strlcpy(cmd_line
, (void *)data
, sizeof(cmd_line
));
578 #ifdef CONFIG_BLK_DEV_INITRD
580 initrd_start
= data
[0] + KERNELBASE
;
581 initrd_end
= data
[0] + data
[1] + KERNELBASE
;
583 #endif /* CONFIG_BLK_DEV_INITRD */
584 #ifdef CONFIG_PPC_MULTIPLATFORM
590 boot_mem_size
= data
[0];
593 rec
= (struct bi_record
*)((ulong
)rec
+ rec
->size
);
598 * Find out what kind of machine we're on and save any data we need
599 * from the early boot process (devtree is copied on pmac by prom_init()).
600 * This is called very early on the boot process, after a minimal
601 * MMU environment has been set up but before MMU_init is called.
604 machine_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
605 unsigned long r6
, unsigned long r7
)
607 #ifdef CONFIG_CMDLINE
608 strlcpy(cmd_line
, CONFIG_CMDLINE
, sizeof(cmd_line
));
609 #endif /* CONFIG_CMDLINE */
612 ppc_md
.power_save
= ppc6xx_idle
;
615 ppc_md
.power_save
= power4_idle
;
618 platform_init(r3
, r4
, r5
, r6
, r7
);
621 ppc_md
.progress("id mach(): done", 0x200);
623 #ifdef CONFIG_BOOKE_WDT
624 /* Checks wdt=x and wdt_period=xx command-line option */
625 int __init
early_parse_wdt(char *p
)
627 if (p
&& strncmp(p
, "0", 1) != 0)
628 booke_wdt_enabled
= 1;
632 early_param("wdt", early_parse_wdt
);
634 int __init
early_parse_wdt_period (char *p
)
637 booke_wdt_period
= simple_strtoul(p
, NULL
, 0);
641 early_param("wdt_period", early_parse_wdt_period
);
642 #endif /* CONFIG_BOOKE_WDT */
644 /* Checks "l2cr=xxxx" command-line option */
645 int __init
ppc_setup_l2cr(char *str
)
647 if (cpu_has_feature(CPU_FTR_L2CR
)) {
648 unsigned long val
= simple_strtoul(str
, NULL
, 0);
649 printk(KERN_INFO
"l2cr set to %lx\n", val
);
650 _set_L2CR(0); /* force invalidate by disable cache */
651 _set_L2CR(val
); /* and enable it */
655 __setup("l2cr=", ppc_setup_l2cr
);
657 #ifdef CONFIG_GENERIC_NVRAM
659 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
660 unsigned char nvram_read_byte(int addr
)
662 if (ppc_md
.nvram_read_val
)
663 return ppc_md
.nvram_read_val(addr
);
666 EXPORT_SYMBOL(nvram_read_byte
);
668 void nvram_write_byte(unsigned char val
, int addr
)
670 if (ppc_md
.nvram_write_val
)
671 ppc_md
.nvram_write_val(addr
, val
);
673 EXPORT_SYMBOL(nvram_write_byte
);
675 void nvram_sync(void)
677 if (ppc_md
.nvram_sync
)
680 EXPORT_SYMBOL(nvram_sync
);
682 #endif /* CONFIG_NVRAM */
684 static struct cpu cpu_devices
[NR_CPUS
];
686 int __init
ppc_init(void)
690 /* clear the progress line */
691 if ( ppc_md
.progress
) ppc_md
.progress(" ", 0xffff);
693 /* register CPU devices */
694 for (i
= 0; i
< NR_CPUS
; i
++)
696 register_cpu(&cpu_devices
[i
], i
, NULL
);
698 /* call platform init */
699 if (ppc_md
.init
!= NULL
) {
705 arch_initcall(ppc_init
);
707 /* Warning, IO base is not yet inited */
708 void __init
setup_arch(char **cmdline_p
)
711 extern void do_init_bootmem(void);
713 /* so udelay does something sensible, assume <= 1000 bogomips */
714 loops_per_jiffy
= 500000000 / HZ
;
716 #ifdef CONFIG_PPC_MULTIPLATFORM
717 /* This could be called "early setup arch", it must be done
718 * now because xmon need it
720 if (_machine
== _MACH_Pmac
)
721 pmac_feature_init(); /* New cool way */
726 if (strstr(cmd_line
, "xmon"))
728 #endif /* CONFIG_XMON */
729 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: enter", 0x3eab);
731 #if defined(CONFIG_KGDB)
732 if (ppc_md
.kgdb_map_scc
)
733 ppc_md
.kgdb_map_scc();
735 if (strstr(cmd_line
, "gdb")) {
737 ppc_md
.progress("setup_arch: kgdb breakpoint", 0x4000);
738 printk("kgdb breakpoint activated\n");
744 * Set cache line size based on type of cpu as a default.
745 * Systems with OF can look in the properties on the cpu node(s)
746 * for a possibly more accurate value.
748 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE
)) {
749 dcache_bsize
= cur_cpu_spec
[0]->dcache_bsize
;
750 icache_bsize
= cur_cpu_spec
[0]->icache_bsize
;
753 ucache_bsize
= dcache_bsize
= icache_bsize
754 = cur_cpu_spec
[0]->dcache_bsize
;
756 /* reboot on panic */
759 init_mm
.start_code
= PAGE_OFFSET
;
760 init_mm
.end_code
= (unsigned long) _etext
;
761 init_mm
.end_data
= (unsigned long) _edata
;
762 init_mm
.brk
= (unsigned long) klimit
;
764 /* Save unparsed command line copy for /proc/cmdline */
765 strlcpy(saved_command_line
, cmd_line
, COMMAND_LINE_SIZE
);
766 *cmdline_p
= cmd_line
;
770 /* set up the bootmem stuff with available memory */
772 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: bootmem", 0x3eab);
774 #ifdef CONFIG_PPC_OCP
775 /* Initialize OCP device list */
777 if ( ppc_md
.progress
) ppc_md
.progress("ocp: exit", 0x3eab);
780 #ifdef CONFIG_DUMMY_CONSOLE
781 conswitchp
= &dummy_con
;
785 if ( ppc_md
.progress
) ppc_md
.progress("arch: exit", 0x3eab);
789 /* this is for modules since _machine can be a define -- Cort */
790 ppc_md
.ppc_machine
= _machine
;