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>
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 reloc_got2(unsigned long offset
);
59 extern void ppc6xx_idle(void);
60 extern void power4_idle(void);
62 extern boot_infos_t
*boot_infos
;
63 struct ide_machdep_calls ppc_ide_md
;
65 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
66 size value reported by the boot loader. */
67 unsigned long boot_mem_size
;
69 unsigned long ISA_DMA_THRESHOLD
;
70 unsigned int DMA_MODE_READ
;
71 unsigned int DMA_MODE_WRITE
;
73 #ifdef CONFIG_PPC_PREP
74 extern void prep_init(unsigned long r3
, unsigned long r4
,
75 unsigned long r5
, unsigned long r6
, unsigned long r7
);
78 #endif /* CONFIG_PPC_PREP */
81 EXPORT_SYMBOL(have_of
);
84 int ppc_do_canonicalize_irqs
;
85 EXPORT_SYMBOL(ppc_do_canonicalize_irqs
);
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
)
125 static void ppc_generic_power_off(void)
130 void machine_halt(void)
138 void (*pm_power_off
)(void) = ppc_generic_power_off
;
140 void machine_power_off(void)
147 ppc_generic_power_off();
151 extern u32
cpu_temp(unsigned long cpu
);
152 extern u32
cpu_temp_both(unsigned long cpu
);
153 #endif /* CONFIG_TAU */
155 int show_cpuinfo(struct seq_file
*m
, void *v
)
160 unsigned short maj
, min
;
164 /* Show summary information */
166 unsigned long bogosum
= 0;
167 for_each_online_cpu(i
)
168 bogosum
+= cpu_data
[i
].loops_per_jiffy
;
169 seq_printf(m
, "total bogomips\t: %lu.%02lu\n",
170 bogosum
/(500000/HZ
), bogosum
/(5000/HZ
) % 100);
171 #endif /* CONFIG_SMP */
173 if (ppc_md
.show_cpuinfo
!= NULL
)
174 err
= ppc_md
.show_cpuinfo(m
);
181 pvr
= cpu_data
[i
].pvr
;
182 lpj
= cpu_data
[i
].loops_per_jiffy
;
184 pvr
= mfspr(SPRN_PVR
);
185 lpj
= loops_per_jiffy
;
188 seq_printf(m
, "processor\t: %d\n", i
);
189 seq_printf(m
, "cpu\t\t: ");
191 if (cur_cpu_spec
->pvr_mask
)
192 seq_printf(m
, "%s", cur_cpu_spec
->cpu_name
);
194 seq_printf(m
, "unknown (%08x)", pvr
);
195 #ifdef CONFIG_ALTIVEC
196 if (cur_cpu_spec
->cpu_features
& CPU_FTR_ALTIVEC
)
197 seq_printf(m
, ", altivec supported");
202 if (cur_cpu_spec
->cpu_features
& CPU_FTR_TAU
) {
203 #ifdef CONFIG_TAU_AVERAGE
204 /* more straightforward, but potentially misleading */
205 seq_printf(m
, "temperature \t: %u C (uncalibrated)\n",
208 /* show the actual temp sensor range */
210 temp
= cpu_temp_both(i
);
211 seq_printf(m
, "temperature \t: %u-%u C (uncalibrated)\n",
212 temp
& 0xff, temp
>> 16);
215 #endif /* CONFIG_TAU */
217 if (ppc_md
.show_percpuinfo
!= NULL
) {
218 err
= ppc_md
.show_percpuinfo(m
, i
);
223 /* If we are a Freescale core do a simple check so
224 * we dont have to keep adding cases in the future */
225 if ((PVR_VER(pvr
) & 0x8000) == 0x8000) {
229 switch (PVR_VER(pvr
)) {
230 case 0x0020: /* 403 family */
231 maj
= PVR_MAJ(pvr
) + 1;
234 case 0x1008: /* 740P/750P ?? */
235 maj
= ((pvr
>> 8) & 0xFF) - 1;
239 maj
= (pvr
>> 8) & 0xFF;
245 seq_printf(m
, "revision\t: %hd.%hd (pvr %04x %04x)\n",
246 maj
, min
, PVR_VER(pvr
), PVR_REV(pvr
));
248 seq_printf(m
, "bogomips\t: %lu.%02lu\n",
249 lpj
/ (500000/HZ
), (lpj
/ (5000/HZ
)) % 100);
252 if (cur_ppc_sys_spec
->ppc_sys_name
)
253 seq_printf(m
, "chipset\t\t: %s\n",
254 cur_ppc_sys_spec
->ppc_sys_name
);
264 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
268 return i
<= NR_CPUS
? (void *) (i
+ 1): NULL
;
271 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
274 return c_start(m
, pos
);
277 static void c_stop(struct seq_file
*m
, void *v
)
281 struct seq_operations cpuinfo_op
= {
285 .show
= show_cpuinfo
,
289 * We're called here very early in the boot. We determine the machine
290 * type and call the appropriate low-level setup functions.
291 * -- Cort <cort@fsmlabs.com>
293 * Note that the kernel may be running at an address which is different
294 * from the address that it was linked at, so we must use RELOC/PTRRELOC
295 * to access static data (including strings). -- paulus
299 early_init(int r3
, int r4
, int r5
)
302 unsigned long offset
= reloc_offset();
303 struct cpu_spec
*spec
;
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 spec
= identify_cpu(offset
, mfspr(SPRN_PVR
));
317 do_feature_fixups(spec
->cpu_features
,
318 PTRRELOC(&__start___ftr_fixup
),
319 PTRRELOC(&__stop___ftr_fixup
));
324 #ifdef CONFIG_PPC_PREP
326 * The PPC_PREP version of platform_init...
329 platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
330 unsigned long r6
, unsigned long r7
)
332 #ifdef CONFIG_BOOTX_TEXT
333 if (boot_text_mapped
) {
339 parse_bootinfo(find_bootinfo());
341 prep_init(r3
, r4
, r5
, r6
, r7
);
343 #endif /* CONFIG_PPC_PREP */
345 struct bi_record
*find_bootinfo(void)
347 struct bi_record
*rec
;
349 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+(1<<20)-1,(1<<20));
350 if ( rec
->tag
!= BI_FIRST
) {
352 * This 0x10000 offset is a terrible hack but it will go away when
353 * we have the bootloader handle all the relocation and
356 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+0x10000+(1<<20)-1,(1<<20));
357 if ( rec
->tag
!= BI_FIRST
)
363 void parse_bootinfo(struct bi_record
*rec
)
365 if (rec
== NULL
|| rec
->tag
!= BI_FIRST
)
367 while (rec
->tag
!= BI_LAST
) {
368 ulong
*data
= rec
->data
;
371 strlcpy(cmd_line
, (void *)data
, sizeof(cmd_line
));
373 #ifdef CONFIG_BLK_DEV_INITRD
375 initrd_start
= data
[0] + KERNELBASE
;
376 initrd_end
= data
[0] + data
[1] + KERNELBASE
;
378 #endif /* CONFIG_BLK_DEV_INITRD */
380 boot_mem_size
= data
[0];
383 rec
= (struct bi_record
*)((ulong
)rec
+ rec
->size
);
388 * Find out what kind of machine we're on and save any data we need
389 * from the early boot process (devtree is copied on pmac by prom_init()).
390 * This is called very early on the boot process, after a minimal
391 * MMU environment has been set up but before MMU_init is called.
394 machine_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
395 unsigned long r6
, unsigned long r7
)
397 #ifdef CONFIG_CMDLINE
398 strlcpy(cmd_line
, CONFIG_CMDLINE
, sizeof(cmd_line
));
399 #endif /* CONFIG_CMDLINE */
402 ppc_md
.power_save
= ppc6xx_idle
;
405 platform_init(r3
, r4
, r5
, r6
, r7
);
408 ppc_md
.progress("id mach(): done", 0x200);
410 #ifdef CONFIG_BOOKE_WDT
411 /* Checks wdt=x and wdt_period=xx command-line option */
412 int __init
early_parse_wdt(char *p
)
414 if (p
&& strncmp(p
, "0", 1) != 0)
415 booke_wdt_enabled
= 1;
419 early_param("wdt", early_parse_wdt
);
421 int __init
early_parse_wdt_period (char *p
)
424 booke_wdt_period
= simple_strtoul(p
, NULL
, 0);
428 early_param("wdt_period", early_parse_wdt_period
);
429 #endif /* CONFIG_BOOKE_WDT */
431 /* Checks "l2cr=xxxx" command-line option */
432 int __init
ppc_setup_l2cr(char *str
)
434 if (cpu_has_feature(CPU_FTR_L2CR
)) {
435 unsigned long val
= simple_strtoul(str
, NULL
, 0);
436 printk(KERN_INFO
"l2cr set to %lx\n", val
);
437 _set_L2CR(0); /* force invalidate by disable cache */
438 _set_L2CR(val
); /* and enable it */
442 __setup("l2cr=", ppc_setup_l2cr
);
444 #ifdef CONFIG_GENERIC_NVRAM
446 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
447 unsigned char nvram_read_byte(int addr
)
449 if (ppc_md
.nvram_read_val
)
450 return ppc_md
.nvram_read_val(addr
);
453 EXPORT_SYMBOL(nvram_read_byte
);
455 void nvram_write_byte(unsigned char val
, int addr
)
457 if (ppc_md
.nvram_write_val
)
458 ppc_md
.nvram_write_val(addr
, val
);
460 EXPORT_SYMBOL(nvram_write_byte
);
462 void nvram_sync(void)
464 if (ppc_md
.nvram_sync
)
467 EXPORT_SYMBOL(nvram_sync
);
469 #endif /* CONFIG_NVRAM */
471 static struct cpu cpu_devices
[NR_CPUS
];
473 int __init
ppc_init(void)
477 /* clear the progress line */
478 if ( ppc_md
.progress
) ppc_md
.progress(" ", 0xffff);
480 /* register CPU devices */
481 for_each_possible_cpu(i
)
482 register_cpu(&cpu_devices
[i
], i
);
484 /* call platform init */
485 if (ppc_md
.init
!= NULL
) {
491 arch_initcall(ppc_init
);
493 /* Warning, IO base is not yet inited */
494 void __init
setup_arch(char **cmdline_p
)
497 extern void do_init_bootmem(void);
499 /* so udelay does something sensible, assume <= 1000 bogomips */
500 loops_per_jiffy
= 500000000 / HZ
;
502 if (ppc_md
.init_early
)
507 if (strstr(cmd_line
, "xmon"))
509 #endif /* CONFIG_XMON */
510 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: enter", 0x3eab);
512 #if defined(CONFIG_KGDB)
513 if (ppc_md
.kgdb_map_scc
)
514 ppc_md
.kgdb_map_scc();
516 if (strstr(cmd_line
, "gdb")) {
518 ppc_md
.progress("setup_arch: kgdb breakpoint", 0x4000);
519 printk("kgdb breakpoint activated\n");
525 * Set cache line size based on type of cpu as a default.
526 * Systems with OF can look in the properties on the cpu node(s)
527 * for a possibly more accurate value.
529 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE
)) {
530 dcache_bsize
= cur_cpu_spec
->dcache_bsize
;
531 icache_bsize
= cur_cpu_spec
->icache_bsize
;
534 ucache_bsize
= dcache_bsize
= icache_bsize
535 = cur_cpu_spec
->dcache_bsize
;
537 /* reboot on panic */
540 init_mm
.start_code
= PAGE_OFFSET
;
541 init_mm
.end_code
= (unsigned long) _etext
;
542 init_mm
.end_data
= (unsigned long) _edata
;
543 init_mm
.brk
= (unsigned long) klimit
;
545 /* Save unparsed command line copy for /proc/cmdline */
546 strlcpy(boot_command_line
, cmd_line
, COMMAND_LINE_SIZE
);
547 *cmdline_p
= cmd_line
;
551 /* set up the bootmem stuff with available memory */
553 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: bootmem", 0x3eab);
555 #ifdef CONFIG_PPC_OCP
556 /* Initialize OCP device list */
558 if ( ppc_md
.progress
) ppc_md
.progress("ocp: exit", 0x3eab);
561 #ifdef CONFIG_DUMMY_CONSOLE
562 conswitchp
= &dummy_con
;
566 if ( ppc_md
.progress
) ppc_md
.progress("arch: exit", 0x3eab);