2 * Common prep 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/sections.h>
39 #include <asm/nvram.h>
43 #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
44 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
45 defined(CONFIG_PPC_MPC52xx))
48 #include <asm/ppc_sys.h>
51 #if defined CONFIG_KGDB
55 extern void platform_init(unsigned long r3, unsigned long r4,
56 unsigned long r5, unsigned long r6, unsigned long r7);
57 extern void identify_cpu(unsigned long offset, unsigned long cpu);
58 extern void do_cpu_ftr_fixups(unsigned long offset);
59 extern void reloc_got2(unsigned long offset);
61 extern void ppc6xx_idle(void);
62 extern void power4_idle(void);
64 extern boot_infos_t *boot_infos;
65 struct ide_machdep_calls ppc_ide_md;
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 int DMA_MODE_READ;
73 unsigned int DMA_MODE_WRITE;
75 #ifdef CONFIG_PPC_PREP
76 extern void prep_init(unsigned long r3, unsigned long r4,
77 unsigned long r5, unsigned long r6, unsigned long r7);
80 #endif /* CONFIG_PPC_PREP */
83 EXPORT_SYMBOL(have_of);
86 int ppc_do_canonicalize_irqs;
87 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
90 #ifdef CONFIG_MAGIC_SYSRQ
91 unsigned long SYSRQ_KEY = 0x54;
92 #endif /* CONFIG_MAGIC_SYSRQ */
94 #ifdef CONFIG_VGA_CONSOLE
95 unsigned long vgacon_remap_base;
98 struct machdep_calls ppc_md;
101 * These are used in binfmt_elf.c to put aux entries on the stack
102 * for each elf executable being started.
108 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
109 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
110 struct screen_info screen_info = {
111 0, 25, /* orig-x, orig-y */
113 0, /* orig-video-page */
114 0, /* orig-video-mode */
115 80, /* orig-video-cols */
116 0,0,0, /* ega_ax, ega_bx, ega_cx */
117 25, /* orig-video-lines */
118 1, /* orig-video-isVGA */
119 16 /* orig-video-points */
121 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
123 void machine_restart(char *cmd)
131 void machine_power_off(void)
139 void machine_halt(void)
147 void (*pm_power_off)(void) = machine_power_off;
150 extern u32 cpu_temp(unsigned long cpu);
151 extern u32 cpu_temp_both(unsigned long cpu);
152 #endif /* CONFIG_TAU */
154 int show_cpuinfo(struct seq_file *m, void *v)
159 unsigned short maj, min;
163 /* Show summary information */
165 unsigned long bogosum = 0;
166 for_each_online_cpu(i)
167 bogosum += cpu_data[i].loops_per_jiffy;
168 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
169 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
170 #endif /* CONFIG_SMP */
172 if (ppc_md.show_cpuinfo != NULL)
173 err = ppc_md.show_cpuinfo(m);
180 pvr = cpu_data[i].pvr;
181 lpj = cpu_data[i].loops_per_jiffy;
183 pvr = mfspr(SPRN_PVR);
184 lpj = loops_per_jiffy;
187 seq_printf(m, "processor\t: %d\n", i);
188 seq_printf(m, "cpu\t\t: ");
190 if (cur_cpu_spec->pvr_mask)
191 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
193 seq_printf(m, "unknown (%08x)", pvr);
194 #ifdef CONFIG_ALTIVEC
195 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
196 seq_printf(m, ", altivec supported");
201 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
202 #ifdef CONFIG_TAU_AVERAGE
203 /* more straightforward, but potentially misleading */
204 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
207 /* show the actual temp sensor range */
209 temp = cpu_temp_both(i);
210 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
211 temp & 0xff, temp >> 16);
214 #endif /* CONFIG_TAU */
216 if (ppc_md.show_percpuinfo != NULL) {
217 err = ppc_md.show_percpuinfo(m, i);
222 /* If we are a Freescale core do a simple check so
223 * we dont have to keep adding cases in the future */
224 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
228 switch (PVR_VER(pvr)) {
229 case 0x0020: /* 403 family */
230 maj = PVR_MAJ(pvr) + 1;
233 case 0x1008: /* 740P/750P ?? */
234 maj = ((pvr >> 8) & 0xFF) - 1;
238 maj = (pvr >> 8) & 0xFF;
244 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
245 maj, min, PVR_VER(pvr), PVR_REV(pvr));
247 seq_printf(m, "bogomips\t: %lu.%02lu\n",
248 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
251 if (cur_ppc_sys_spec->ppc_sys_name)
252 seq_printf(m, "chipset\t\t: %s\n",
253 cur_ppc_sys_spec->ppc_sys_name);
263 static void *c_start(struct seq_file *m, loff_t *pos)
267 return i <= NR_CPUS? (void *) (i + 1): NULL;
270 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
273 return c_start(m, pos);
276 static void c_stop(struct seq_file *m, void *v)
280 struct seq_operations cpuinfo_op = {
284 .show = show_cpuinfo,
288 * We're called here very early in the boot. We determine the machine
289 * type and call the appropriate low-level setup functions.
290 * -- Cort <cort@fsmlabs.com>
292 * Note that the kernel may be running at an address which is different
293 * from the address that it was linked at, so we must use RELOC/PTRRELOC
294 * to access static data (including strings). -- paulus
298 early_init(int r3, int r4, int r5)
301 unsigned long offset = reloc_offset();
304 phys = offset + KERNELBASE;
306 /* First zero the BSS -- use memset, some arches don't have
308 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
311 * Identify the CPU type and fix up code sections
312 * that depend on which cpu we have.
314 identify_cpu(offset, 0);
315 do_cpu_ftr_fixups(offset);
320 #ifdef CONFIG_PPC_PREP
322 * The PPC_PREP version of platform_init...
325 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
326 unsigned long r6, unsigned long r7)
328 #ifdef CONFIG_BOOTX_TEXT
329 if (boot_text_mapped) {
335 parse_bootinfo(find_bootinfo());
337 prep_init(r3, r4, r5, r6, r7);
339 #endif /* CONFIG_PPC_PREP */
341 struct bi_record *find_bootinfo(void)
343 struct bi_record *rec;
345 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
346 if ( rec->tag != BI_FIRST ) {
348 * This 0x10000 offset is a terrible hack but it will go away when
349 * we have the bootloader handle all the relocation and
352 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
353 if ( rec->tag != BI_FIRST )
359 void parse_bootinfo(struct bi_record *rec)
361 if (rec == NULL || rec->tag != BI_FIRST)
363 while (rec->tag != BI_LAST) {
364 ulong *data = rec->data;
367 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
369 #ifdef CONFIG_BLK_DEV_INITRD
371 initrd_start = data[0] + KERNELBASE;
372 initrd_end = data[0] + data[1] + KERNELBASE;
374 #endif /* CONFIG_BLK_DEV_INITRD */
376 boot_mem_size = data[0];
379 rec = (struct bi_record *)((ulong)rec + rec->size);
384 * Find out what kind of machine we're on and save any data we need
385 * from the early boot process (devtree is copied on pmac by prom_init()).
386 * This is called very early on the boot process, after a minimal
387 * MMU environment has been set up but before MMU_init is called.
390 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
391 unsigned long r6, unsigned long r7)
393 #ifdef CONFIG_CMDLINE
394 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
395 #endif /* CONFIG_CMDLINE */
398 ppc_md.power_save = ppc6xx_idle;
401 platform_init(r3, r4, r5, r6, r7);
404 ppc_md.progress("id mach(): done", 0x200);
406 #ifdef CONFIG_BOOKE_WDT
407 /* Checks wdt=x and wdt_period=xx command-line option */
408 int __init early_parse_wdt(char *p)
410 if (p && strncmp(p, "0", 1) != 0)
411 booke_wdt_enabled = 1;
415 early_param("wdt", early_parse_wdt);
417 int __init early_parse_wdt_period (char *p)
420 booke_wdt_period = simple_strtoul(p, NULL, 0);
424 early_param("wdt_period", early_parse_wdt_period);
425 #endif /* CONFIG_BOOKE_WDT */
427 /* Checks "l2cr=xxxx" command-line option */
428 int __init ppc_setup_l2cr(char *str)
430 if (cpu_has_feature(CPU_FTR_L2CR)) {
431 unsigned long val = simple_strtoul(str, NULL, 0);
432 printk(KERN_INFO "l2cr set to %lx\n", val);
433 _set_L2CR(0); /* force invalidate by disable cache */
434 _set_L2CR(val); /* and enable it */
438 __setup("l2cr=", ppc_setup_l2cr);
440 #ifdef CONFIG_GENERIC_NVRAM
442 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
443 unsigned char nvram_read_byte(int addr)
445 if (ppc_md.nvram_read_val)
446 return ppc_md.nvram_read_val(addr);
449 EXPORT_SYMBOL(nvram_read_byte);
451 void nvram_write_byte(unsigned char val, int addr)
453 if (ppc_md.nvram_write_val)
454 ppc_md.nvram_write_val(addr, val);
456 EXPORT_SYMBOL(nvram_write_byte);
458 void nvram_sync(void)
460 if (ppc_md.nvram_sync)
463 EXPORT_SYMBOL(nvram_sync);
465 #endif /* CONFIG_NVRAM */
467 static struct cpu cpu_devices[NR_CPUS];
469 int __init ppc_init(void)
473 /* clear the progress line */
474 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
476 /* register CPU devices */
478 register_cpu(&cpu_devices[i], i, NULL);
480 /* call platform init */
481 if (ppc_md.init != NULL) {
487 arch_initcall(ppc_init);
489 /* Warning, IO base is not yet inited */
490 void __init setup_arch(char **cmdline_p)
493 extern void do_init_bootmem(void);
495 /* so udelay does something sensible, assume <= 1000 bogomips */
496 loops_per_jiffy = 500000000 / HZ;
498 if (ppc_md.init_early)
503 if (strstr(cmd_line, "xmon"))
505 #endif /* CONFIG_XMON */
506 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
508 #if defined(CONFIG_KGDB)
509 if (ppc_md.kgdb_map_scc)
510 ppc_md.kgdb_map_scc();
512 if (strstr(cmd_line, "gdb")) {
514 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
515 printk("kgdb breakpoint activated\n");
521 * Set cache line size based on type of cpu as a default.
522 * Systems with OF can look in the properties on the cpu node(s)
523 * for a possibly more accurate value.
525 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
526 dcache_bsize = cur_cpu_spec->dcache_bsize;
527 icache_bsize = cur_cpu_spec->icache_bsize;
530 ucache_bsize = dcache_bsize = icache_bsize
531 = cur_cpu_spec->dcache_bsize;
533 /* reboot on panic */
536 init_mm.start_code = PAGE_OFFSET;
537 init_mm.end_code = (unsigned long) _etext;
538 init_mm.end_data = (unsigned long) _edata;
539 init_mm.brk = (unsigned long) klimit;
541 /* Save unparsed command line copy for /proc/cmdline */
542 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
543 *cmdline_p = cmd_line;
547 /* set up the bootmem stuff with available memory */
549 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
551 #ifdef CONFIG_PPC_OCP
552 /* Initialize OCP device list */
554 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
557 #ifdef CONFIG_DUMMY_CONSOLE
558 conswitchp = &dummy_con;
562 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);