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/screen_info.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_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 static void ppc_generic_power_off(void)
131 void machine_halt(void)
139 void (*pm_power_off)(void) = ppc_generic_power_off;
141 void machine_power_off(void)
148 ppc_generic_power_off();
152 extern u32 cpu_temp(unsigned long cpu);
153 extern u32 cpu_temp_both(unsigned long cpu);
154 #endif /* CONFIG_TAU */
156 int show_cpuinfo(struct seq_file *m, void *v)
161 unsigned short maj, min;
165 /* Show summary information */
167 unsigned long bogosum = 0;
168 for_each_online_cpu(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->pvr_mask)
193 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
195 seq_printf(m, "unknown (%08x)", pvr);
196 #ifdef CONFIG_ALTIVEC
197 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
198 seq_printf(m, ", altivec supported");
203 if (cur_cpu_spec->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);
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);
322 #ifdef CONFIG_PPC_PREP
324 * The PPC_PREP version of platform_init...
327 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
328 unsigned long r6, unsigned long r7)
330 #ifdef CONFIG_BOOTX_TEXT
331 if (boot_text_mapped) {
337 parse_bootinfo(find_bootinfo());
339 prep_init(r3, r4, r5, r6, r7);
341 #endif /* CONFIG_PPC_PREP */
343 struct bi_record *find_bootinfo(void)
345 struct bi_record *rec;
347 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
348 if ( rec->tag != BI_FIRST ) {
350 * This 0x10000 offset is a terrible hack but it will go away when
351 * we have the bootloader handle all the relocation and
354 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
355 if ( rec->tag != BI_FIRST )
361 void parse_bootinfo(struct bi_record *rec)
363 if (rec == NULL || rec->tag != BI_FIRST)
365 while (rec->tag != BI_LAST) {
366 ulong *data = rec->data;
369 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
371 #ifdef CONFIG_BLK_DEV_INITRD
373 initrd_start = data[0] + KERNELBASE;
374 initrd_end = data[0] + data[1] + KERNELBASE;
376 #endif /* CONFIG_BLK_DEV_INITRD */
378 boot_mem_size = data[0];
381 rec = (struct bi_record *)((ulong)rec + rec->size);
386 * Find out what kind of machine we're on and save any data we need
387 * from the early boot process (devtree is copied on pmac by prom_init()).
388 * This is called very early on the boot process, after a minimal
389 * MMU environment has been set up but before MMU_init is called.
392 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
393 unsigned long r6, unsigned long r7)
395 #ifdef CONFIG_CMDLINE
396 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
397 #endif /* CONFIG_CMDLINE */
400 ppc_md.power_save = ppc6xx_idle;
403 platform_init(r3, r4, r5, r6, r7);
406 ppc_md.progress("id mach(): done", 0x200);
408 #ifdef CONFIG_BOOKE_WDT
409 /* Checks wdt=x and wdt_period=xx command-line option */
410 int __init early_parse_wdt(char *p)
412 if (p && strncmp(p, "0", 1) != 0)
413 booke_wdt_enabled = 1;
417 early_param("wdt", early_parse_wdt);
419 int __init early_parse_wdt_period (char *p)
422 booke_wdt_period = simple_strtoul(p, NULL, 0);
426 early_param("wdt_period", early_parse_wdt_period);
427 #endif /* CONFIG_BOOKE_WDT */
429 /* Checks "l2cr=xxxx" command-line option */
430 int __init ppc_setup_l2cr(char *str)
432 if (cpu_has_feature(CPU_FTR_L2CR)) {
433 unsigned long val = simple_strtoul(str, NULL, 0);
434 printk(KERN_INFO "l2cr set to %lx\n", val);
435 _set_L2CR(0); /* force invalidate by disable cache */
436 _set_L2CR(val); /* and enable it */
440 __setup("l2cr=", ppc_setup_l2cr);
442 #ifdef CONFIG_GENERIC_NVRAM
444 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
445 unsigned char nvram_read_byte(int addr)
447 if (ppc_md.nvram_read_val)
448 return ppc_md.nvram_read_val(addr);
451 EXPORT_SYMBOL(nvram_read_byte);
453 void nvram_write_byte(unsigned char val, int addr)
455 if (ppc_md.nvram_write_val)
456 ppc_md.nvram_write_val(addr, val);
458 EXPORT_SYMBOL(nvram_write_byte);
460 void nvram_sync(void)
462 if (ppc_md.nvram_sync)
465 EXPORT_SYMBOL(nvram_sync);
467 #endif /* CONFIG_NVRAM */
469 static struct cpu cpu_devices[NR_CPUS];
471 int __init ppc_init(void)
475 /* clear the progress line */
476 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
478 /* register CPU devices */
479 for_each_possible_cpu(i)
480 register_cpu(&cpu_devices[i], i);
482 /* call platform init */
483 if (ppc_md.init != NULL) {
489 arch_initcall(ppc_init);
491 /* Warning, IO base is not yet inited */
492 void __init setup_arch(char **cmdline_p)
495 extern void do_init_bootmem(void);
497 /* so udelay does something sensible, assume <= 1000 bogomips */
498 loops_per_jiffy = 500000000 / HZ;
500 if (ppc_md.init_early)
505 if (strstr(cmd_line, "xmon"))
507 #endif /* CONFIG_XMON */
508 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
510 #if defined(CONFIG_KGDB)
511 if (ppc_md.kgdb_map_scc)
512 ppc_md.kgdb_map_scc();
514 if (strstr(cmd_line, "gdb")) {
516 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
517 printk("kgdb breakpoint activated\n");
523 * Set cache line size based on type of cpu as a default.
524 * Systems with OF can look in the properties on the cpu node(s)
525 * for a possibly more accurate value.
527 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
528 dcache_bsize = cur_cpu_spec->dcache_bsize;
529 icache_bsize = cur_cpu_spec->icache_bsize;
532 ucache_bsize = dcache_bsize = icache_bsize
533 = cur_cpu_spec->dcache_bsize;
535 /* reboot on panic */
538 init_mm.start_code = PAGE_OFFSET;
539 init_mm.end_code = (unsigned long) _etext;
540 init_mm.end_data = (unsigned long) _edata;
541 init_mm.brk = (unsigned long) klimit;
543 /* Save unparsed command line copy for /proc/cmdline */
544 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
545 *cmdline_p = cmd_line;
549 /* set up the bootmem stuff with available memory */
551 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
553 #ifdef CONFIG_PPC_OCP
554 /* Initialize OCP device list */
556 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
559 #ifdef CONFIG_DUMMY_CONSOLE
560 conswitchp = &dummy_con;
564 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);