2 * BK Id: SCCS/s.setup.c 1.116 01/28/03 09:17:05 porter
5 * Common prep/pmac/chrp boot and setup code.
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/string.h>
11 #include <linux/sched.h>
12 #include <linux/init.h>
13 #include <linux/reboot.h>
14 #include <linux/delay.h>
15 #include <linux/blk.h>
16 #include <linux/ide.h>
17 #include <linux/tty.h>
18 #include <linux/bootmem.h>
19 #include <linux/seq_file.h>
21 #include <asm/residual.h>
24 #include <asm/processor.h>
25 #include <asm/pgtable.h>
26 #include <asm/bootinfo.h>
27 #include <asm/setup.h>
28 #include <asm/amigappc.h>
31 #include <asm/cputable.h>
32 #include <asm/bootx.h>
33 #include <asm/btext.h>
34 #include <asm/machdep.h>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
37 #include <asm/pmac_feature.h>
39 #if defined CONFIG_KGDB
43 extern void platform_init(unsigned long r3, unsigned long r4,
44 unsigned long r5, unsigned long r6, unsigned long r7);
45 extern void bootx_init(unsigned long r4, unsigned long phys);
46 extern void identify_cpu(unsigned long offset, unsigned long cpu);
47 extern void do_cpu_ftr_fixups(unsigned long offset);
48 extern void reloc_got2(unsigned long offset);
51 extern void xmon_map_scc(void);
55 extern void kgdb_map_scc(void);
58 extern boot_infos_t *boot_infos;
59 char saved_command_line[512];
60 extern char cmd_line[512];
61 unsigned char aux_device_present;
62 struct ide_machdep_calls ppc_ide_md;
64 unsigned long sysmap_size;
66 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
67 size value reported by the boot loader. */
68 unsigned long boot_mem_size;
70 unsigned long ISA_DMA_THRESHOLD;
71 unsigned long DMA_MODE_READ, DMA_MODE_WRITE;
76 extern void prep_init(unsigned long r3, unsigned long r4,
77 unsigned long r5, unsigned long r6, unsigned long r7);
78 extern void pmac_init(unsigned long r3, unsigned long r4,
79 unsigned long r5, unsigned long r6, unsigned long r7);
80 extern void chrp_init(unsigned long r3, unsigned long r4,
81 unsigned long r5, unsigned long r6, unsigned long r7);
82 #endif /* CONFIG_ALL_PPC */
84 #ifdef CONFIG_MAGIC_SYSRQ
85 unsigned long SYSRQ_KEY;
86 #endif /* CONFIG_MAGIC_SYSRQ */
88 #ifdef CONFIG_VGA_CONSOLE
89 unsigned long vgacon_remap_base;
92 struct machdep_calls ppc_md;
95 * These are used in binfmt_elf.c to put aux entries on the stack
96 * for each elf executable being started.
102 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
103 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
104 struct screen_info screen_info = {
105 0, 25, /* orig-x, orig-y */
107 0, /* orig-video-page */
108 0, /* orig-video-mode */
109 80, /* orig-video-cols */
110 0,0,0, /* ega_ax, ega_bx, ega_cx */
111 25, /* orig-video-lines */
112 1, /* orig-video-isVGA */
113 16 /* orig-video-points */
115 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
117 void machine_restart(char *cmd)
122 void machine_power_off(void)
127 void machine_halt(void)
133 extern u32 cpu_temp(unsigned long cpu);
134 extern u32 cpu_temp_both(unsigned long cpu);
135 #endif /* CONFIG_TAU */
137 int show_cpuinfo(struct seq_file *m, void *v)
142 unsigned short maj, min;
146 /* Show summary information */
148 unsigned long bogosum = 0;
149 for (i = 0; i < smp_num_cpus; ++i)
150 if (cpu_online_map & (1 << i))
151 bogosum += cpu_data[i].loops_per_jiffy;
152 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
153 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
154 #endif /* CONFIG_SMP */
156 if (ppc_md.show_cpuinfo != NULL)
157 err = ppc_md.show_cpuinfo(m);
162 if (!(cpu_online_map & (1 << i)))
164 pvr = cpu_data[i].pvr;
165 lpj = cpu_data[i].loops_per_jiffy;
166 seq_printf(m, "processor\t: %lu\n", i);
169 lpj = loops_per_jiffy;
172 seq_printf(m, "cpu\t\t: ");
174 if (cur_cpu_spec[i]->pvr_mask)
175 seq_printf(m, "%s", cur_cpu_spec[i]->cpu_name);
177 seq_printf(m, "unknown (%08x)", pvr);
178 #ifdef CONFIG_ALTIVEC
179 if (cur_cpu_spec[i]->cpu_features & CPU_FTR_ALTIVEC)
180 seq_printf(m, ", altivec supported");
185 if (cur_cpu_spec[i]->cpu_features & CPU_FTR_TAU) {
186 #ifdef CONFIG_TAU_AVERAGE
187 /* more straightforward, but potentially misleading */
188 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
191 /* show the actual temp sensor range */
193 temp = cpu_temp_both(i);
194 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
195 temp & 0xff, temp >> 16);
198 #endif /* CONFIG_TAU */
200 if (ppc_md.show_percpuinfo != NULL) {
201 err = ppc_md.show_percpuinfo(m, i);
206 switch (PVR_VER(pvr)) {
207 case 0x0020: /* 403 family */
208 maj = PVR_MAJ(pvr) + 1;
211 case 0x1008: /* 740P/750P ?? */
212 maj = ((pvr >> 8) & 0xFF) - 1;
216 maj = (pvr >> 8) & 0xFF;
221 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
222 maj, min, PVR_VER(pvr), PVR_REV(pvr));
224 seq_printf(m, "bogomips\t: %lu.%02lu\n",
225 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
235 static void *c_start(struct seq_file *m, loff_t *pos)
239 return i <= NR_CPUS? (void *) (i + 1): NULL;
242 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
245 return c_start(m, pos);
248 static void c_stop(struct seq_file *m, void *v)
252 struct seq_operations cpuinfo_op = {
260 * We're called here very early in the boot. We determine the machine
261 * type and call the appropriate low-level setup functions.
262 * -- Cort <cort@fsmlabs.com>
264 * Note that the kernel may be running at an address which is different
265 * from the address that it was linked at, so we must use RELOC/PTRRELOC
266 * to access static data (including strings). -- paulus
270 early_init(int r3, int r4, int r5)
272 extern char __bss_start, _end;
274 unsigned long offset = reloc_offset();
277 phys = offset + KERNELBASE;
279 /* First zero the BSS -- use memset, some arches don't have
281 memset_io(PTRRELOC(&__bss_start), 0, &_end - &__bss_start);
284 * Identify the CPU type and fix up code sections
285 * that depend on which cpu we have.
287 identify_cpu(offset, 0);
288 do_cpu_ftr_fixups(offset);
290 #if defined(CONFIG_ALL_PPC)
293 /* If we came here from BootX, clear the screen,
294 * set up some pointers and return. */
295 if ((r3 == 0x426f6f58) && (r5 == 0))
296 bootx_init(r4, phys);
299 * don't do anything on prep
300 * for now, don't use bootinfo because it breaks yaboot 0.5
301 * and assume that if we didn't find a magic number, we have OF
303 else if (*(unsigned long *)(0) != 0xdeadc0de)
304 phys = prom_init(r3, r4, (prom_entry)r5);
312 #ifdef CONFIG_ALL_PPC
314 intuit_machine_type(void)
317 struct device_node *root;
319 /* ask the OF info if we're a chrp or pmac */
320 root = find_path_device("/");
322 /* assume pmac unless proven to be chrp -- Cort */
323 _machine = _MACH_Pmac;
324 model = get_property(root, "device_type", NULL);
325 if (model && !strncmp("chrp", model, 4))
326 _machine = _MACH_chrp;
328 model = get_property(root, "model", NULL);
329 if (model && !strncmp(model, "IBM", 3))
330 _machine = _MACH_chrp;
336 * The ALL_PPC version of platform_init...
339 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
340 unsigned long r6, unsigned long r7)
342 #ifdef CONFIG_BOOTX_TEXT
343 if (boot_text_mapped) {
349 parse_bootinfo(find_bootinfo());
351 /* if we didn't get any bootinfo telling us what we are... */
353 /* prep boot loader tells us if we're prep or not */
354 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
355 _machine = _MACH_prep;
358 /* not much more to do here, if prep */
359 if (_machine == _MACH_prep) {
360 prep_init(r3, r4, r5, r6, r7);
364 /* prom_init has already been called from __start */
368 /* If we aren't PReP, we can find out if we're Pmac
369 * or CHRP with this. */
371 intuit_machine_type();
373 /* finish_device_tree may need _machine defined. */
374 finish_device_tree();
377 * If we were booted via quik, r3 points to the physical
378 * address of the command-line parameters.
379 * If we were booted from an xcoff image (i.e. netbooted or
380 * booted from floppy), we get the command line from the
381 * bootargs property of the /chosen node.
382 * If an initial ramdisk is present, r3 and r4
383 * are used for initrd_start and initrd_size,
384 * otherwise they contain 0xdeadbeef.
386 if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
388 strncpy(cmd_line, (char *)r3 + KERNELBASE,
390 } else if (boot_infos != 0) {
391 /* booted by BootX - check for ramdisk */
392 if (boot_infos->kernelParamsOffset != 0)
393 strncpy(cmd_line, (char *) boot_infos
394 + boot_infos->kernelParamsOffset,
396 #ifdef CONFIG_BLK_DEV_INITRD
397 if (boot_infos->ramDisk) {
398 initrd_start = (unsigned long) boot_infos
399 + boot_infos->ramDisk;
400 initrd_end = initrd_start + boot_infos->ramDiskSize;
401 initrd_below_start_ok = 1;
405 struct device_node *chosen;
408 #ifdef CONFIG_BLK_DEV_INITRD
409 if (r3 && r4 && r4 != 0xdeadbeef) {
413 initrd_end = r3 + r4;
414 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
415 initrd_below_start_ok = 1;
418 chosen = find_devices("chosen");
419 if (chosen != NULL) {
420 p = get_property(chosen, "bootargs", NULL);
423 strncpy(cmd_line, p, sizeof(cmd_line));
427 cmd_line[sizeof(cmd_line) - 1] = 0;
429 if (strstr(cmd_line, "adb_sync")) {
430 extern int __adb_probe_sync;
431 __adb_probe_sync = 1;
433 #endif /* CONFIG_ADB */
437 pmac_init(r3, r4, r5, r6, r7);
440 chrp_init(r3, r4, r5, r6, r7);
444 #endif /* CONFIG_ALL_PPC */
447 struct bi_record *find_bootinfo(void)
449 struct bi_record *rec;
450 extern char __bss_start[];
452 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
453 if ( rec->tag != BI_FIRST ) {
455 * This 0x10000 offset is a terrible hack but it will go away when
456 * we have the bootloader handle all the relocation and
459 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
460 if ( rec->tag != BI_FIRST )
466 void parse_bootinfo(struct bi_record *rec)
468 if (rec == NULL || rec->tag != BI_FIRST)
470 while (rec->tag != BI_LAST) {
471 ulong *data = rec->data;
474 memcpy(cmd_line, (void *)data, rec->size -
475 sizeof(struct bi_record));
478 sysmap = (char *)((data[0] >= (KERNELBASE)) ? data[0] :
479 (data[0]+KERNELBASE));
480 sysmap_size = data[1];
482 #ifdef CONFIG_BLK_DEV_INITRD
484 initrd_start = data[0] + KERNELBASE;
485 initrd_end = data[0] + data[1] + KERNELBASE;
487 #endif /* CONFIG_BLK_DEV_INITRD */
488 #ifdef CONFIG_ALL_PPC
492 #endif /* CONFIG_ALL_PPC */
494 boot_mem_size = data[0];
497 rec = (struct bi_record *)((ulong)rec + rec->size);
500 #endif /* CONFIG_APUS */
503 * Find out what kind of machine we're on and save any data we need
504 * from the early boot process (devtree is copied on pmac by prom_init()).
505 * This is called very early on the boot process, after a minimal
506 * MMU environment has been set up but before MMU_init is called.
509 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
510 unsigned long r6, unsigned long r7)
512 #ifdef CONFIG_CMDLINE
513 strcpy(cmd_line, CONFIG_CMDLINE);
514 #endif /* CONFIG_CMDLINE */
516 platform_init(r3, r4, r5, r6, r7);
519 ppc_md.progress("id mach(): done", 0x200);
522 /* Checks "l2cr=xxxx" command-line option */
523 int __init ppc_setup_l2cr(char *str)
525 if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR) {
526 unsigned long val = simple_strtoul(str, NULL, 0);
527 printk(KERN_INFO "l2cr set to %lx\n", val);
528 _set_L2CR(0); /* force invalidate by disable cache */
529 _set_L2CR(val); /* and enable it */
533 __setup("l2cr=", ppc_setup_l2cr);
535 void __init arch_discover_root(void)
537 if (ppc_md.discover_root != NULL)
538 ppc_md.discover_root();
541 void __init ppc_init(void)
543 /* clear the progress line */
544 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
546 if (ppc_md.init != NULL) {
551 /* Warning, IO base is not yet inited */
552 void __init setup_arch(char **cmdline_p)
554 extern int panic_timeout;
555 extern char _etext[], _edata[];
557 extern void do_init_bootmem(void);
559 /* so udelay does something sensible, assume <= 1000 bogomips */
560 loops_per_jiffy = 500000000 / HZ;
561 #ifdef CONFIG_ALL_PPC
562 /* This could be called "early setup arch", it must be done
563 * now because xmon need it
565 if (_machine == _MACH_Pmac)
566 pmac_feature_init(); /* New cool way */
567 #endif /* CONFIG_ALL_PPC */
571 if (strstr(cmd_line, "xmon"))
573 #endif /* CONFIG_XMON */
574 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
576 #if defined(CONFIG_KGDB)
579 if (strstr(cmd_line, "nokgdb"))
580 printk("kgdb default breakpoint deactivated on command line\n");
582 if (ppc_md.progress) ppc_md.progress("setup_arch: kgdb bp", 0x4000);
583 printk("kgdb default breakpoint activated\n");
589 * Set cache line size based on type of cpu as a default.
590 * Systems with OF can look in the properties on the cpu node(s)
591 * for a possibly more accurate value.
593 if (cur_cpu_spec[0]->cpu_features & CPU_FTR_SPLIT_ID_CACHE) {
594 dcache_bsize = cur_cpu_spec[0]->dcache_bsize;
595 icache_bsize = cur_cpu_spec[0]->icache_bsize;
598 ucache_bsize = dcache_bsize = icache_bsize
599 = cur_cpu_spec[0]->dcache_bsize;
601 /* reboot on panic */
604 init_mm.start_code = PAGE_OFFSET;
605 init_mm.end_code = (unsigned long) _etext;
606 init_mm.end_data = (unsigned long) _edata;
607 init_mm.brk = (unsigned long) klimit;
609 /* Save unparsed command line copy for /proc/cmdline */
611 strcpy(saved_command_line, cmd_line);
612 *cmdline_p = cmd_line;
614 strcpy(saved_command_line, CONFIG_CMDLINE);
615 *cmdline_p = CONFIG_CMDLINE;
617 /* set up the bootmem stuff with available memory */
619 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
622 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
625 sort_exception_table();
627 /* this is for modules since _machine can be a define -- Cort */
628 ppc_md.ppc_machine = _machine;