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/reboot.h>
11 #include <linux/delay.h>
12 #include <linux/initrd.h>
13 #include <linux/ide.h>
14 #include <linux/tty.h>
15 #include <linux/bootmem.h>
16 #include <linux/seq_file.h>
17 #include <linux/root_dev.h>
18 #include <linux/cpu.h>
20 #include <asm/residual.h>
23 #include <asm/processor.h>
24 #include <asm/pgtable.h>
25 #include <asm/bootinfo.h>
26 #include <asm/setup.h>
27 #include <asm/amigappc.h>
30 #include <asm/cputable.h>
31 #include <asm/bootx.h>
32 #include <asm/btext.h>
33 #include <asm/machdep.h>
34 #include <asm/uaccess.h>
35 #include <asm/system.h>
36 #include <asm/pmac_feature.h>
37 #include <asm/sections.h>
38 #include <asm/nvram.h>
41 #if defined CONFIG_KGDB
45 extern void platform_init(unsigned long r3, unsigned long r4,
46 unsigned long r5, unsigned long r6, unsigned long r7);
47 extern void bootx_init(unsigned long r4, unsigned long phys);
48 extern void identify_cpu(unsigned long offset, unsigned long cpu);
49 extern void do_cpu_ftr_fixups(unsigned long offset);
50 extern void reloc_got2(unsigned long offset);
52 extern void ppc6xx_idle(void);
53 extern void power4_idle(void);
55 extern boot_infos_t *boot_infos;
56 char saved_command_line[COMMAND_LINE_SIZE];
57 unsigned char aux_device_present;
58 struct ide_machdep_calls ppc_ide_md;
60 unsigned long sysmap_size;
62 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
63 size value reported by the boot loader. */
64 unsigned long boot_mem_size;
66 unsigned long ISA_DMA_THRESHOLD;
67 unsigned long DMA_MODE_READ, DMA_MODE_WRITE;
69 #ifdef CONFIG_PPC_MULTIPLATFORM
72 extern void prep_init(unsigned long r3, unsigned long r4,
73 unsigned long r5, unsigned long r6, unsigned long r7);
74 extern void pmac_init(unsigned long r3, unsigned long r4,
75 unsigned long r5, unsigned long r6, unsigned long r7);
76 extern void chrp_init(unsigned long r3, unsigned long r4,
77 unsigned long r5, unsigned long r6, unsigned long r7);
78 #endif /* CONFIG_PPC_MULTIPLATFORM */
80 #ifdef CONFIG_MAGIC_SYSRQ
81 unsigned long SYSRQ_KEY = 0x54;
82 #endif /* CONFIG_MAGIC_SYSRQ */
84 #ifdef CONFIG_VGA_CONSOLE
85 unsigned long vgacon_remap_base;
88 struct machdep_calls ppc_md;
91 * These are used in binfmt_elf.c to put aux entries on the stack
92 * for each elf executable being started.
98 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
99 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
100 struct screen_info screen_info = {
101 0, 25, /* orig-x, orig-y */
103 0, /* orig-video-page */
104 0, /* orig-video-mode */
105 80, /* orig-video-cols */
106 0,0,0, /* ega_ax, ega_bx, ega_cx */
107 25, /* orig-video-lines */
108 1, /* orig-video-isVGA */
109 16 /* orig-video-points */
111 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
113 void machine_restart(char *cmd)
121 EXPORT_SYMBOL(machine_restart);
123 void machine_power_off(void)
131 EXPORT_SYMBOL(machine_power_off);
133 void machine_halt(void)
141 EXPORT_SYMBOL(machine_halt);
143 void (*pm_power_off)(void) = machine_power_off;
146 extern u32 cpu_temp(unsigned long cpu);
147 extern u32 cpu_temp_both(unsigned long cpu);
148 #endif /* CONFIG_TAU */
150 int show_cpuinfo(struct seq_file *m, void *v)
155 unsigned short maj, min;
159 /* Show summary information */
161 unsigned long bogosum = 0;
162 for (i = 0; i < NR_CPUS; ++i)
164 bogosum += cpu_data[i].loops_per_jiffy;
165 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
166 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
167 #endif /* CONFIG_SMP */
169 if (ppc_md.show_cpuinfo != NULL)
170 err = ppc_md.show_cpuinfo(m);
177 pvr = cpu_data[i].pvr;
178 lpj = cpu_data[i].loops_per_jiffy;
181 lpj = loops_per_jiffy;
184 seq_printf(m, "processor\t: %d\n", i);
185 seq_printf(m, "cpu\t\t: ");
187 if (cur_cpu_spec[i]->pvr_mask)
188 seq_printf(m, "%s", cur_cpu_spec[i]->cpu_name);
190 seq_printf(m, "unknown (%08x)", pvr);
191 #ifdef CONFIG_ALTIVEC
192 if (cur_cpu_spec[i]->cpu_features & CPU_FTR_ALTIVEC)
193 seq_printf(m, ", altivec supported");
198 if (cur_cpu_spec[i]->cpu_features & CPU_FTR_TAU) {
199 #ifdef CONFIG_TAU_AVERAGE
200 /* more straightforward, but potentially misleading */
201 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
204 /* show the actual temp sensor range */
206 temp = cpu_temp_both(i);
207 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
208 temp & 0xff, temp >> 16);
211 #endif /* CONFIG_TAU */
213 if (ppc_md.show_percpuinfo != NULL) {
214 err = ppc_md.show_percpuinfo(m, i);
219 switch (PVR_VER(pvr)) {
220 case 0x0020: /* 403 family */
221 maj = PVR_MAJ(pvr) + 1;
224 case 0x1008: /* 740P/750P ?? */
225 maj = ((pvr >> 8) & 0xFF) - 1;
229 maj = (pvr >> 8) & 0xFF;
234 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
235 maj, min, PVR_VER(pvr), PVR_REV(pvr));
237 seq_printf(m, "bogomips\t: %lu.%02lu\n",
238 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
247 static void *c_start(struct seq_file *m, loff_t *pos)
251 return i <= NR_CPUS? (void *) (i + 1): NULL;
254 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
257 return c_start(m, pos);
260 static void c_stop(struct seq_file *m, void *v)
264 struct seq_operations cpuinfo_op = {
268 .show = show_cpuinfo,
272 * We're called here very early in the boot. We determine the machine
273 * type and call the appropriate low-level setup functions.
274 * -- Cort <cort@fsmlabs.com>
276 * Note that the kernel may be running at an address which is different
277 * from the address that it was linked at, so we must use RELOC/PTRRELOC
278 * to access static data (including strings). -- paulus
282 early_init(int r3, int r4, int r5)
285 unsigned long offset = reloc_offset();
288 phys = offset + KERNELBASE;
290 /* First zero the BSS -- use memset, some arches don't have
292 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
295 * Identify the CPU type and fix up code sections
296 * that depend on which cpu we have.
298 identify_cpu(offset, 0);
299 do_cpu_ftr_fixups(offset);
301 #if defined(CONFIG_PPC_MULTIPLATFORM)
304 /* If we came here from BootX, clear the screen,
305 * set up some pointers and return. */
306 if ((r3 == 0x426f6f58) && (r5 == 0))
307 bootx_init(r4, phys);
310 * don't do anything on prep
311 * for now, don't use bootinfo because it breaks yaboot 0.5
312 * and assume that if we didn't find a magic number, we have OF
314 else if (*(unsigned long *)(0) != 0xdeadc0de)
315 phys = prom_init(r3, r4, (prom_entry)r5);
325 * Assume here that all clock rates are the same in a
326 * smp system. -- Cort
329 of_show_percpuinfo(struct seq_file *m, int i)
331 struct device_node *cpu_node;
334 cpu_node = find_type_devices("cpu");
337 for (s = 0; s < i && cpu_node->next; s++)
338 cpu_node = cpu_node->next;
339 fp = (int *) get_property(cpu_node, "clock-frequency", NULL);
341 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
346 intuit_machine_type(void)
349 struct device_node *root;
351 /* ask the OF info if we're a chrp or pmac */
352 root = find_path_device("/");
354 /* assume pmac unless proven to be chrp -- Cort */
355 _machine = _MACH_Pmac;
356 model = get_property(root, "device_type", NULL);
357 if (model && !strncmp("chrp", model, 4))
358 _machine = _MACH_chrp;
360 model = get_property(root, "model", NULL);
361 if (model && !strncmp(model, "IBM", 3))
362 _machine = _MACH_chrp;
368 #ifdef CONFIG_PPC_MULTIPLATFORM
370 * The PPC_MULTIPLATFORM version of platform_init...
373 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
374 unsigned long r6, unsigned long r7)
376 #ifdef CONFIG_BOOTX_TEXT
377 if (boot_text_mapped) {
383 parse_bootinfo(find_bootinfo());
385 /* if we didn't get any bootinfo telling us what we are... */
387 /* prep boot loader tells us if we're prep or not */
388 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
389 _machine = _MACH_prep;
392 /* not much more to do here, if prep */
393 if (_machine == _MACH_prep) {
394 prep_init(r3, r4, r5, r6, r7);
398 /* prom_init has already been called from __start */
402 /* If we aren't PReP, we can find out if we're Pmac
403 * or CHRP with this. */
405 intuit_machine_type();
407 /* finish_device_tree may need _machine defined. */
408 finish_device_tree();
411 * If we were booted via quik, r3 points to the physical
412 * address of the command-line parameters.
413 * If we were booted from an xcoff image (i.e. netbooted or
414 * booted from floppy), we get the command line from the
415 * bootargs property of the /chosen node.
416 * If an initial ramdisk is present, r3 and r4
417 * are used for initrd_start and initrd_size,
418 * otherwise they contain 0xdeadbeef.
421 if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
422 strlcpy(cmd_line, (char *)r3 + KERNELBASE,
424 } else if (boot_infos != 0) {
425 /* booted by BootX - check for ramdisk */
426 if (boot_infos->kernelParamsOffset != 0)
427 strlcpy(cmd_line, (char *) boot_infos
428 + boot_infos->kernelParamsOffset,
430 #ifdef CONFIG_BLK_DEV_INITRD
431 if (boot_infos->ramDisk) {
432 initrd_start = (unsigned long) boot_infos
433 + boot_infos->ramDisk;
434 initrd_end = initrd_start + boot_infos->ramDiskSize;
435 initrd_below_start_ok = 1;
439 struct device_node *chosen;
442 #ifdef CONFIG_BLK_DEV_INITRD
443 if (r3 && r4 && r4 != 0xdeadbeef) {
447 initrd_end = r3 + r4;
448 ROOT_DEV = Root_RAM0;
449 initrd_below_start_ok = 1;
452 chosen = find_devices("chosen");
453 if (chosen != NULL) {
454 p = get_property(chosen, "bootargs", NULL);
456 strlcpy(cmd_line, p, sizeof(cmd_line));
461 if (strstr(cmd_line, "adb_sync")) {
462 extern int __adb_probe_sync;
463 __adb_probe_sync = 1;
465 #endif /* CONFIG_ADB */
469 pmac_init(r3, r4, r5, r6, r7);
472 chrp_init(r3, r4, r5, r6, r7);
476 #endif /* CONFIG_PPC_MULTIPLATFORM */
478 struct bi_record *find_bootinfo(void)
480 struct bi_record *rec;
482 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
483 if ( rec->tag != BI_FIRST ) {
485 * This 0x10000 offset is a terrible hack but it will go away when
486 * we have the bootloader handle all the relocation and
489 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
490 if ( rec->tag != BI_FIRST )
496 void parse_bootinfo(struct bi_record *rec)
498 if (rec == NULL || rec->tag != BI_FIRST)
500 while (rec->tag != BI_LAST) {
501 ulong *data = rec->data;
504 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
507 sysmap = (char *)((data[0] >= (KERNELBASE)) ? data[0] :
508 (data[0]+KERNELBASE));
509 sysmap_size = data[1];
511 #ifdef CONFIG_BLK_DEV_INITRD
513 initrd_start = data[0] + KERNELBASE;
514 initrd_end = data[0] + data[1] + KERNELBASE;
516 #endif /* CONFIG_BLK_DEV_INITRD */
517 #ifdef CONFIG_PPC_MULTIPLATFORM
523 boot_mem_size = data[0];
526 rec = (struct bi_record *)((ulong)rec + rec->size);
531 * Find out what kind of machine we're on and save any data we need
532 * from the early boot process (devtree is copied on pmac by prom_init()).
533 * This is called very early on the boot process, after a minimal
534 * MMU environment has been set up but before MMU_init is called.
537 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
538 unsigned long r6, unsigned long r7)
540 #ifdef CONFIG_CMDLINE
541 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
542 #endif /* CONFIG_CMDLINE */
545 ppc_md.power_save = ppc6xx_idle;
548 ppc_md.power_save = power4_idle;
551 platform_init(r3, r4, r5, r6, r7);
554 ppc_md.progress("id mach(): done", 0x200);
557 /* Checks "l2cr=xxxx" command-line option */
558 int __init ppc_setup_l2cr(char *str)
560 if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR) {
561 unsigned long val = simple_strtoul(str, NULL, 0);
562 printk(KERN_INFO "l2cr set to %lx\n", val);
563 _set_L2CR(0); /* force invalidate by disable cache */
564 _set_L2CR(val); /* and enable it */
568 __setup("l2cr=", ppc_setup_l2cr);
572 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
573 unsigned char nvram_read_byte(int addr)
575 if (ppc_md.nvram_read_val)
576 return ppc_md.nvram_read_val(addr);
579 EXPORT_SYMBOL(nvram_read_byte);
581 void nvram_write_byte(unsigned char val, int addr)
583 if (ppc_md.nvram_write_val)
584 ppc_md.nvram_write_val(addr, val);
586 EXPORT_SYMBOL(nvram_write_byte);
588 void nvram_sync(void)
590 if (ppc_md.nvram_sync)
593 EXPORT_SYMBOL(nvram_sync);
595 #endif /* CONFIG_NVRAM */
597 static struct cpu cpu_devices[NR_CPUS];
599 int __init ppc_init(void)
603 /* clear the progress line */
604 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
606 /* register CPU devices */
607 for (i = 0; i < NR_CPUS; i++)
609 register_cpu(&cpu_devices[i], i, NULL);
611 /* call platform init */
612 if (ppc_md.init != NULL) {
618 arch_initcall(ppc_init);
620 /* Warning, IO base is not yet inited */
621 void __init setup_arch(char **cmdline_p)
623 extern int panic_timeout;
625 extern void do_init_bootmem(void);
627 /* so udelay does something sensible, assume <= 1000 bogomips */
628 loops_per_jiffy = 500000000 / HZ;
630 #ifdef CONFIG_PPC_MULTIPLATFORM
631 /* This could be called "early setup arch", it must be done
632 * now because xmon need it
634 if (_machine == _MACH_Pmac)
635 pmac_feature_init(); /* New cool way */
640 if (strstr(cmd_line, "xmon"))
642 #endif /* CONFIG_XMON */
643 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
645 #if defined(CONFIG_KGDB)
646 if (ppc_md.kgdb_map_scc)
647 ppc_md.kgdb_map_scc();
649 if (strstr(cmd_line, "gdb")) {
651 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
652 printk("kgdb breakpoint activated\n");
658 * Set cache line size based on type of cpu as a default.
659 * Systems with OF can look in the properties on the cpu node(s)
660 * for a possibly more accurate value.
662 if (cur_cpu_spec[0]->cpu_features & CPU_FTR_SPLIT_ID_CACHE) {
663 dcache_bsize = cur_cpu_spec[0]->dcache_bsize;
664 icache_bsize = cur_cpu_spec[0]->icache_bsize;
667 ucache_bsize = dcache_bsize = icache_bsize
668 = cur_cpu_spec[0]->dcache_bsize;
670 /* reboot on panic */
673 init_mm.start_code = PAGE_OFFSET;
674 init_mm.end_code = (unsigned long) _etext;
675 init_mm.end_data = (unsigned long) _edata;
676 init_mm.brk = (unsigned long) klimit;
678 /* Save unparsed command line copy for /proc/cmdline */
679 strlcpy(saved_command_line, cmd_line, sizeof(saved_command_line));
680 *cmdline_p = cmd_line;
682 /* set up the bootmem stuff with available memory */
684 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
687 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
691 /* this is for modules since _machine can be a define -- Cort */
692 ppc_md.ppc_machine = _machine;