2 * Common prep boot and setup code.
5 #include <linux/module.h>
6 #include <linux/string.h>
7 #include <linux/sched.h>
8 #include <linux/init.h>
9 #include <linux/kernel.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>
19 #include <linux/console.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/sections.h>
38 #include <asm/nvram.h>
42 #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
43 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
44 defined(CONFIG_PPC_MPC52xx))
47 #include <asm/ppc_sys.h>
50 #if defined CONFIG_KGDB
54 extern void platform_init(unsigned long r3, unsigned long r4,
55 unsigned long r5, unsigned long r6, unsigned long r7);
56 extern void identify_cpu(unsigned long offset, unsigned long cpu);
57 extern void do_cpu_ftr_fixups(unsigned long offset);
58 extern void reloc_got2(unsigned long offset);
60 extern void ppc6xx_idle(void);
61 extern void power4_idle(void);
63 extern boot_infos_t *boot_infos;
64 struct ide_machdep_calls ppc_ide_md;
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 int DMA_MODE_READ;
72 unsigned int DMA_MODE_WRITE;
74 #ifdef CONFIG_PPC_PREP
75 extern void prep_init(unsigned long r3, unsigned long r4,
76 unsigned long r5, unsigned long r6, unsigned long r7);
79 #endif /* CONFIG_PPC_PREP */
82 EXPORT_SYMBOL(have_of);
85 int ppc_do_canonicalize_irqs;
86 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
89 #ifdef CONFIG_MAGIC_SYSRQ
90 unsigned long SYSRQ_KEY = 0x54;
91 #endif /* CONFIG_MAGIC_SYSRQ */
93 #ifdef CONFIG_VGA_CONSOLE
94 unsigned long vgacon_remap_base;
97 struct machdep_calls ppc_md;
100 * These are used in binfmt_elf.c to put aux entries on the stack
101 * for each elf executable being started.
107 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
108 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
109 struct screen_info screen_info = {
110 0, 25, /* orig-x, orig-y */
112 0, /* orig-video-page */
113 0, /* orig-video-mode */
114 80, /* orig-video-cols */
115 0,0,0, /* ega_ax, ega_bx, ega_cx */
116 25, /* orig-video-lines */
117 1, /* orig-video-isVGA */
118 16 /* orig-video-points */
120 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
122 void machine_restart(char *cmd)
130 void machine_power_off(void)
138 void machine_halt(void)
146 void (*pm_power_off)(void) = machine_power_off;
149 extern u32 cpu_temp(unsigned long cpu);
150 extern u32 cpu_temp_both(unsigned long cpu);
151 #endif /* CONFIG_TAU */
153 int show_cpuinfo(struct seq_file *m, void *v)
158 unsigned short maj, min;
162 /* Show summary information */
164 unsigned long bogosum = 0;
165 for_each_online_cpu(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->pvr_mask)
190 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
192 seq_printf(m, "unknown (%08x)", pvr);
193 #ifdef CONFIG_ALTIVEC
194 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
195 seq_printf(m, ", altivec supported");
200 if (cur_cpu_spec->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);
319 #ifdef CONFIG_PPC_PREP
321 * The PPC_PREP version of platform_init...
324 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
325 unsigned long r6, unsigned long r7)
327 #ifdef CONFIG_BOOTX_TEXT
328 if (boot_text_mapped) {
334 parse_bootinfo(find_bootinfo());
336 prep_init(r3, r4, r5, r6, r7);
338 #endif /* CONFIG_PPC_PREP */
340 struct bi_record *find_bootinfo(void)
342 struct bi_record *rec;
344 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
345 if ( rec->tag != BI_FIRST ) {
347 * This 0x10000 offset is a terrible hack but it will go away when
348 * we have the bootloader handle all the relocation and
351 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
352 if ( rec->tag != BI_FIRST )
358 void parse_bootinfo(struct bi_record *rec)
360 if (rec == NULL || rec->tag != BI_FIRST)
362 while (rec->tag != BI_LAST) {
363 ulong *data = rec->data;
366 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
368 #ifdef CONFIG_BLK_DEV_INITRD
370 initrd_start = data[0] + KERNELBASE;
371 initrd_end = data[0] + data[1] + KERNELBASE;
373 #endif /* CONFIG_BLK_DEV_INITRD */
375 boot_mem_size = data[0];
378 rec = (struct bi_record *)((ulong)rec + rec->size);
383 * Find out what kind of machine we're on and save any data we need
384 * from the early boot process (devtree is copied on pmac by prom_init()).
385 * This is called very early on the boot process, after a minimal
386 * MMU environment has been set up but before MMU_init is called.
389 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
390 unsigned long r6, unsigned long r7)
392 #ifdef CONFIG_CMDLINE
393 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
394 #endif /* CONFIG_CMDLINE */
397 ppc_md.power_save = ppc6xx_idle;
400 platform_init(r3, r4, r5, r6, r7);
403 ppc_md.progress("id mach(): done", 0x200);
405 #ifdef CONFIG_BOOKE_WDT
406 /* Checks wdt=x and wdt_period=xx command-line option */
407 int __init early_parse_wdt(char *p)
409 if (p && strncmp(p, "0", 1) != 0)
410 booke_wdt_enabled = 1;
414 early_param("wdt", early_parse_wdt);
416 int __init early_parse_wdt_period (char *p)
419 booke_wdt_period = simple_strtoul(p, NULL, 0);
423 early_param("wdt_period", early_parse_wdt_period);
424 #endif /* CONFIG_BOOKE_WDT */
426 /* Checks "l2cr=xxxx" command-line option */
427 int __init ppc_setup_l2cr(char *str)
429 if (cpu_has_feature(CPU_FTR_L2CR)) {
430 unsigned long val = simple_strtoul(str, NULL, 0);
431 printk(KERN_INFO "l2cr set to %lx\n", val);
432 _set_L2CR(0); /* force invalidate by disable cache */
433 _set_L2CR(val); /* and enable it */
437 __setup("l2cr=", ppc_setup_l2cr);
439 #ifdef CONFIG_GENERIC_NVRAM
441 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
442 unsigned char nvram_read_byte(int addr)
444 if (ppc_md.nvram_read_val)
445 return ppc_md.nvram_read_val(addr);
448 EXPORT_SYMBOL(nvram_read_byte);
450 void nvram_write_byte(unsigned char val, int addr)
452 if (ppc_md.nvram_write_val)
453 ppc_md.nvram_write_val(addr, val);
455 EXPORT_SYMBOL(nvram_write_byte);
457 void nvram_sync(void)
459 if (ppc_md.nvram_sync)
462 EXPORT_SYMBOL(nvram_sync);
464 #endif /* CONFIG_NVRAM */
466 static struct cpu cpu_devices[NR_CPUS];
468 int __init ppc_init(void)
472 /* clear the progress line */
473 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
475 /* register CPU devices */
476 for_each_possible_cpu(i)
477 register_cpu(&cpu_devices[i], i);
479 /* call platform init */
480 if (ppc_md.init != NULL) {
486 arch_initcall(ppc_init);
488 /* Warning, IO base is not yet inited */
489 void __init setup_arch(char **cmdline_p)
492 extern void do_init_bootmem(void);
494 /* so udelay does something sensible, assume <= 1000 bogomips */
495 loops_per_jiffy = 500000000 / HZ;
497 if (ppc_md.init_early)
502 if (strstr(cmd_line, "xmon"))
504 #endif /* CONFIG_XMON */
505 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
507 #if defined(CONFIG_KGDB)
508 if (ppc_md.kgdb_map_scc)
509 ppc_md.kgdb_map_scc();
511 if (strstr(cmd_line, "gdb")) {
513 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
514 printk("kgdb breakpoint activated\n");
520 * Set cache line size based on type of cpu as a default.
521 * Systems with OF can look in the properties on the cpu node(s)
522 * for a possibly more accurate value.
524 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
525 dcache_bsize = cur_cpu_spec->dcache_bsize;
526 icache_bsize = cur_cpu_spec->icache_bsize;
529 ucache_bsize = dcache_bsize = icache_bsize
530 = cur_cpu_spec->dcache_bsize;
532 /* reboot on panic */
535 init_mm.start_code = PAGE_OFFSET;
536 init_mm.end_code = (unsigned long) _etext;
537 init_mm.end_data = (unsigned long) _edata;
538 init_mm.brk = (unsigned long) klimit;
540 /* Save unparsed command line copy for /proc/cmdline */
541 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
542 *cmdline_p = cmd_line;
546 /* set up the bootmem stuff with available memory */
548 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
550 #ifdef CONFIG_PPC_OCP
551 /* Initialize OCP device list */
553 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
556 #ifdef CONFIG_DUMMY_CONSOLE
557 conswitchp = &dummy_con;
561 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);