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)
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 unsigned long sysmap_size
;
67 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
68 size value reported by the boot loader. */
69 unsigned long boot_mem_size
;
71 unsigned long ISA_DMA_THRESHOLD
;
72 unsigned long DMA_MODE_READ
, DMA_MODE_WRITE
;
74 #ifdef CONFIG_PPC_MULTIPLATFORM
77 extern void prep_init(unsigned long r3
, unsigned long r4
,
78 unsigned long r5
, unsigned long r6
, unsigned long r7
);
79 extern void pmac_init(unsigned long r3
, unsigned long r4
,
80 unsigned long r5
, unsigned long r6
, unsigned long r7
);
81 extern void chrp_init(unsigned long r3
, unsigned long r4
,
82 unsigned long r5
, unsigned long r6
, unsigned long r7
);
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
;
96 * These are used in binfmt_elf.c to put aux entries on the stack
97 * for each elf executable being started.
103 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
104 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
105 struct screen_info screen_info
= {
106 0, 25, /* orig-x, orig-y */
108 0, /* orig-video-page */
109 0, /* orig-video-mode */
110 80, /* orig-video-cols */
111 0,0,0, /* ega_ax, ega_bx, ega_cx */
112 25, /* orig-video-lines */
113 1, /* orig-video-isVGA */
114 16 /* orig-video-points */
116 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
118 void machine_restart(char *cmd
)
126 EXPORT_SYMBOL(machine_restart
);
128 void machine_power_off(void)
136 EXPORT_SYMBOL(machine_power_off
);
138 void machine_halt(void)
146 EXPORT_SYMBOL(machine_halt
);
148 void (*pm_power_off
)(void) = machine_power_off
;
151 extern u32
cpu_temp(unsigned long cpu
);
152 extern u32
cpu_temp_both(unsigned long cpu
);
153 #endif /* CONFIG_TAU */
155 int show_cpuinfo(struct seq_file
*m
, void *v
)
160 unsigned short maj
, min
;
164 /* Show summary information */
166 unsigned long bogosum
= 0;
167 for (i
= 0; i
< NR_CPUS
; ++i
)
169 bogosum
+= cpu_data
[i
].loops_per_jiffy
;
170 seq_printf(m
, "total bogomips\t: %lu.%02lu\n",
171 bogosum
/(500000/HZ
), bogosum
/(5000/HZ
) % 100);
172 #endif /* CONFIG_SMP */
174 if (ppc_md
.show_cpuinfo
!= NULL
)
175 err
= ppc_md
.show_cpuinfo(m
);
182 pvr
= cpu_data
[i
].pvr
;
183 lpj
= cpu_data
[i
].loops_per_jiffy
;
185 pvr
= mfspr(SPRN_PVR
);
186 lpj
= loops_per_jiffy
;
189 seq_printf(m
, "processor\t: %d\n", i
);
190 seq_printf(m
, "cpu\t\t: ");
192 if (cur_cpu_spec
[i
]->pvr_mask
)
193 seq_printf(m
, "%s", cur_cpu_spec
[i
]->cpu_name
);
195 seq_printf(m
, "unknown (%08x)", pvr
);
196 #ifdef CONFIG_ALTIVEC
197 if (cur_cpu_spec
[i
]->cpu_features
& CPU_FTR_ALTIVEC
)
198 seq_printf(m
, ", altivec supported");
203 if (cur_cpu_spec
[i
]->cpu_features
& CPU_FTR_TAU
) {
204 #ifdef CONFIG_TAU_AVERAGE
205 /* more straightforward, but potentially misleading */
206 seq_printf(m
, "temperature \t: %u C (uncalibrated)\n",
209 /* show the actual temp sensor range */
211 temp
= cpu_temp_both(i
);
212 seq_printf(m
, "temperature \t: %u-%u C (uncalibrated)\n",
213 temp
& 0xff, temp
>> 16);
216 #endif /* CONFIG_TAU */
218 if (ppc_md
.show_percpuinfo
!= NULL
) {
219 err
= ppc_md
.show_percpuinfo(m
, i
);
224 /* If we are a Freescale core do a simple check so
225 * we dont have to keep adding cases in the future */
226 if ((PVR_VER(pvr
) & 0x8000) == 0x8000) {
230 switch (PVR_VER(pvr
)) {
231 case 0x0020: /* 403 family */
232 maj
= PVR_MAJ(pvr
) + 1;
235 case 0x1008: /* 740P/750P ?? */
236 maj
= ((pvr
>> 8) & 0xFF) - 1;
240 maj
= (pvr
>> 8) & 0xFF;
246 seq_printf(m
, "revision\t: %hd.%hd (pvr %04x %04x)\n",
247 maj
, min
, PVR_VER(pvr
), PVR_REV(pvr
));
249 seq_printf(m
, "bogomips\t: %lu.%02lu\n",
250 lpj
/ (500000/HZ
), (lpj
/ (5000/HZ
)) % 100);
252 #if defined(CONFIG_85xx) || defined(CONFIG_83xx)
253 if (cur_ppc_sys_spec
->ppc_sys_name
)
254 seq_printf(m
, "chipset\t\t: %s\n",
255 cur_ppc_sys_spec
->ppc_sys_name
);
265 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
269 return i
<= NR_CPUS
? (void *) (i
+ 1): NULL
;
272 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
275 return c_start(m
, pos
);
278 static void c_stop(struct seq_file
*m
, void *v
)
282 struct seq_operations cpuinfo_op
= {
286 .show
= show_cpuinfo
,
290 * We're called here very early in the boot. We determine the machine
291 * type and call the appropriate low-level setup functions.
292 * -- Cort <cort@fsmlabs.com>
294 * Note that the kernel may be running at an address which is different
295 * from the address that it was linked at, so we must use RELOC/PTRRELOC
296 * to access static data (including strings). -- paulus
300 early_init(int r3
, int r4
, int r5
)
303 unsigned long offset
= reloc_offset();
306 phys
= offset
+ KERNELBASE
;
308 /* First zero the BSS -- use memset, some arches don't have
310 memset_io(PTRRELOC(&__bss_start
), 0, _end
- __bss_start
);
313 * Identify the CPU type and fix up code sections
314 * that depend on which cpu we have.
316 identify_cpu(offset
, 0);
317 do_cpu_ftr_fixups(offset
);
319 #if defined(CONFIG_PPC_MULTIPLATFORM)
322 /* If we came here from BootX, clear the screen,
323 * set up some pointers and return. */
324 if ((r3
== 0x426f6f58) && (r5
== 0))
325 bootx_init(r4
, phys
);
328 * don't do anything on prep
329 * for now, don't use bootinfo because it breaks yaboot 0.5
330 * and assume that if we didn't find a magic number, we have OF
332 else if (*(unsigned long *)(0) != 0xdeadc0de)
333 phys
= prom_init(r3
, r4
, (prom_entry
)r5
);
343 * Assume here that all clock rates are the same in a
344 * smp system. -- Cort
347 of_show_percpuinfo(struct seq_file
*m
, int i
)
349 struct device_node
*cpu_node
;
353 cpu_node
= find_type_devices("cpu");
356 for (s
= 0; s
< i
&& cpu_node
->next
; s
++)
357 cpu_node
= cpu_node
->next
;
358 fp
= (u32
*)get_property(cpu_node
, "clock-frequency", NULL
);
360 seq_printf(m
, "clock\t\t: %dMHz\n", *fp
/ 1000000);
365 intuit_machine_type(void)
368 struct device_node
*root
;
370 /* ask the OF info if we're a chrp or pmac */
371 root
= find_path_device("/");
373 /* assume pmac unless proven to be chrp -- Cort */
374 _machine
= _MACH_Pmac
;
375 model
= get_property(root
, "device_type", NULL
);
376 if (model
&& !strncmp("chrp", model
, 4))
377 _machine
= _MACH_chrp
;
379 model
= get_property(root
, "model", NULL
);
380 if (model
&& !strncmp(model
, "IBM", 3))
381 _machine
= _MACH_chrp
;
387 #ifdef CONFIG_PPC_MULTIPLATFORM
389 * The PPC_MULTIPLATFORM version of platform_init...
392 platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
393 unsigned long r6
, unsigned long r7
)
395 #ifdef CONFIG_BOOTX_TEXT
396 if (boot_text_mapped
) {
402 parse_bootinfo(find_bootinfo());
404 /* if we didn't get any bootinfo telling us what we are... */
406 /* prep boot loader tells us if we're prep or not */
407 if ( *(unsigned long *)(KERNELBASE
) == (0xdeadc0de) )
408 _machine
= _MACH_prep
;
411 /* not much more to do here, if prep */
412 if (_machine
== _MACH_prep
) {
413 prep_init(r3
, r4
, r5
, r6
, r7
);
417 /* prom_init has already been called from __start */
421 /* If we aren't PReP, we can find out if we're Pmac
422 * or CHRP with this. */
424 intuit_machine_type();
426 /* finish_device_tree may need _machine defined. */
427 finish_device_tree();
430 * If we were booted via quik, r3 points to the physical
431 * address of the command-line parameters.
432 * If we were booted from an xcoff image (i.e. netbooted or
433 * booted from floppy), we get the command line from the
434 * bootargs property of the /chosen node.
435 * If an initial ramdisk is present, r3 and r4
436 * are used for initrd_start and initrd_size,
437 * otherwise they contain 0xdeadbeef.
439 if (r3
>= 0x4000 && r3
< 0x800000 && r4
== 0) {
440 strlcpy(cmd_line
, (char *)r3
+ KERNELBASE
,
442 } else if (boot_infos
!= 0) {
443 /* booted by BootX - check for ramdisk */
444 if (boot_infos
->kernelParamsOffset
!= 0)
445 strlcpy(cmd_line
, (char *) boot_infos
446 + boot_infos
->kernelParamsOffset
,
448 #ifdef CONFIG_BLK_DEV_INITRD
449 if (boot_infos
->ramDisk
) {
450 initrd_start
= (unsigned long) boot_infos
451 + boot_infos
->ramDisk
;
452 initrd_end
= initrd_start
+ boot_infos
->ramDiskSize
;
453 initrd_below_start_ok
= 1;
457 struct device_node
*chosen
;
460 #ifdef CONFIG_BLK_DEV_INITRD
461 if (r3
&& r4
&& r4
!= 0xdeadbeef) {
465 initrd_end
= r3
+ r4
;
466 ROOT_DEV
= Root_RAM0
;
467 initrd_below_start_ok
= 1;
470 chosen
= find_devices("chosen");
471 if (chosen
!= NULL
) {
472 p
= get_property(chosen
, "bootargs", NULL
);
474 strlcpy(cmd_line
, p
, sizeof(cmd_line
));
479 if (strstr(cmd_line
, "adb_sync")) {
480 extern int __adb_probe_sync
;
481 __adb_probe_sync
= 1;
483 #endif /* CONFIG_ADB */
487 pmac_init(r3
, r4
, r5
, r6
, r7
);
490 chrp_init(r3
, r4
, r5
, r6
, r7
);
495 #ifdef CONFIG_SERIAL_CORE_CONSOLE
496 extern char *of_stdout_device
;
498 static int __init
set_preferred_console(void)
500 struct device_node
*prom_stdout
;
504 if (of_stdout_device
== NULL
)
507 /* The user has requested a console so this is already set up. */
508 if (strstr(saved_command_line
, "console="))
511 prom_stdout
= find_path_device(of_stdout_device
);
515 name
= (char *)get_property(prom_stdout
, "name", NULL
);
519 if (strcmp(name
, "serial") == 0) {
521 u32
*reg
= (u32
*)get_property(prom_stdout
, "reg", &i
);
537 /* We dont recognise the serial port */
541 } else if (strcmp(name
, "ch-a") == 0)
543 else if (strcmp(name
, "ch-b") == 0)
547 return add_preferred_console("ttyS", offset
, NULL
);
549 console_initcall(set_preferred_console
);
550 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
551 #endif /* CONFIG_PPC_MULTIPLATFORM */
553 struct bi_record
*find_bootinfo(void)
555 struct bi_record
*rec
;
557 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+(1<<20)-1,(1<<20));
558 if ( rec
->tag
!= BI_FIRST
) {
560 * This 0x10000 offset is a terrible hack but it will go away when
561 * we have the bootloader handle all the relocation and
564 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+0x10000+(1<<20)-1,(1<<20));
565 if ( rec
->tag
!= BI_FIRST
)
571 void parse_bootinfo(struct bi_record
*rec
)
573 if (rec
== NULL
|| rec
->tag
!= BI_FIRST
)
575 while (rec
->tag
!= BI_LAST
) {
576 ulong
*data
= rec
->data
;
579 strlcpy(cmd_line
, (void *)data
, sizeof(cmd_line
));
582 sysmap
= (char *)((data
[0] >= (KERNELBASE
)) ? data
[0] :
583 (data
[0]+KERNELBASE
));
584 sysmap_size
= data
[1];
586 #ifdef CONFIG_BLK_DEV_INITRD
588 initrd_start
= data
[0] + KERNELBASE
;
589 initrd_end
= data
[0] + data
[1] + KERNELBASE
;
591 #endif /* CONFIG_BLK_DEV_INITRD */
592 #ifdef CONFIG_PPC_MULTIPLATFORM
598 boot_mem_size
= data
[0];
601 rec
= (struct bi_record
*)((ulong
)rec
+ rec
->size
);
606 * Find out what kind of machine we're on and save any data we need
607 * from the early boot process (devtree is copied on pmac by prom_init()).
608 * This is called very early on the boot process, after a minimal
609 * MMU environment has been set up but before MMU_init is called.
612 machine_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
613 unsigned long r6
, unsigned long r7
)
615 #ifdef CONFIG_CMDLINE
616 strlcpy(cmd_line
, CONFIG_CMDLINE
, sizeof(cmd_line
));
617 #endif /* CONFIG_CMDLINE */
620 ppc_md
.power_save
= ppc6xx_idle
;
623 ppc_md
.power_save
= power4_idle
;
626 platform_init(r3
, r4
, r5
, r6
, r7
);
629 ppc_md
.progress("id mach(): done", 0x200);
632 /* Checks "l2cr=xxxx" command-line option */
633 int __init
ppc_setup_l2cr(char *str
)
635 if (cpu_has_feature(CPU_FTR_L2CR
)) {
636 unsigned long val
= simple_strtoul(str
, NULL
, 0);
637 printk(KERN_INFO
"l2cr set to %lx\n", val
);
638 _set_L2CR(0); /* force invalidate by disable cache */
639 _set_L2CR(val
); /* and enable it */
643 __setup("l2cr=", ppc_setup_l2cr
);
645 #ifdef CONFIG_GENERIC_NVRAM
647 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
648 unsigned char nvram_read_byte(int addr
)
650 if (ppc_md
.nvram_read_val
)
651 return ppc_md
.nvram_read_val(addr
);
654 EXPORT_SYMBOL(nvram_read_byte
);
656 void nvram_write_byte(unsigned char val
, int addr
)
658 if (ppc_md
.nvram_write_val
)
659 ppc_md
.nvram_write_val(addr
, val
);
661 EXPORT_SYMBOL(nvram_write_byte
);
663 void nvram_sync(void)
665 if (ppc_md
.nvram_sync
)
668 EXPORT_SYMBOL(nvram_sync
);
670 #endif /* CONFIG_NVRAM */
672 static struct cpu cpu_devices
[NR_CPUS
];
674 int __init
ppc_init(void)
678 /* clear the progress line */
679 if ( ppc_md
.progress
) ppc_md
.progress(" ", 0xffff);
681 /* register CPU devices */
682 for (i
= 0; i
< NR_CPUS
; i
++)
684 register_cpu(&cpu_devices
[i
], i
, NULL
);
686 /* call platform init */
687 if (ppc_md
.init
!= NULL
) {
693 arch_initcall(ppc_init
);
695 /* Warning, IO base is not yet inited */
696 void __init
setup_arch(char **cmdline_p
)
699 extern void do_init_bootmem(void);
701 /* so udelay does something sensible, assume <= 1000 bogomips */
702 loops_per_jiffy
= 500000000 / HZ
;
704 #ifdef CONFIG_PPC_MULTIPLATFORM
705 /* This could be called "early setup arch", it must be done
706 * now because xmon need it
708 if (_machine
== _MACH_Pmac
)
709 pmac_feature_init(); /* New cool way */
714 if (strstr(cmd_line
, "xmon"))
716 #endif /* CONFIG_XMON */
717 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: enter", 0x3eab);
719 #if defined(CONFIG_KGDB)
720 if (ppc_md
.kgdb_map_scc
)
721 ppc_md
.kgdb_map_scc();
723 if (strstr(cmd_line
, "gdb")) {
725 ppc_md
.progress("setup_arch: kgdb breakpoint", 0x4000);
726 printk("kgdb breakpoint activated\n");
732 * Set cache line size based on type of cpu as a default.
733 * Systems with OF can look in the properties on the cpu node(s)
734 * for a possibly more accurate value.
736 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE
)) {
737 dcache_bsize
= cur_cpu_spec
[0]->dcache_bsize
;
738 icache_bsize
= cur_cpu_spec
[0]->icache_bsize
;
741 ucache_bsize
= dcache_bsize
= icache_bsize
742 = cur_cpu_spec
[0]->dcache_bsize
;
744 /* reboot on panic */
747 init_mm
.start_code
= PAGE_OFFSET
;
748 init_mm
.end_code
= (unsigned long) _etext
;
749 init_mm
.end_data
= (unsigned long) _edata
;
750 init_mm
.brk
= (unsigned long) klimit
;
752 /* Save unparsed command line copy for /proc/cmdline */
753 strlcpy(saved_command_line
, cmd_line
, COMMAND_LINE_SIZE
);
754 *cmdline_p
= cmd_line
;
758 /* set up the bootmem stuff with available memory */
760 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: bootmem", 0x3eab);
762 #ifdef CONFIG_PPC_OCP
763 /* Initialize OCP device list */
765 if ( ppc_md
.progress
) ppc_md
.progress("ocp: exit", 0x3eab);
768 #ifdef CONFIG_DUMMY_CONSOLE
769 conswitchp
= &dummy_con
;
773 if ( ppc_md
.progress
) ppc_md
.progress("arch: exit", 0x3eab);
777 /* this is for modules since _machine can be a define -- Cort */
778 ppc_md
.ppc_machine
= _machine
;