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>
30 #include <asm/cputable.h>
31 #include <asm/bootx.h>
32 #include <asm/btext.h>
33 #include <asm/machdep.h>
34 #include <asm/uaccess.h>
35 #include <asm/system.h>
36 #include <asm/sections.h>
37 #include <asm/nvram.h>
41 #define USES_PPC_SYS (defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
42 defined(CONFIG_PPC_MPC52xx))
45 #include <asm/ppc_sys.h>
48 #if defined CONFIG_KGDB
52 extern void platform_init(unsigned long r3
, unsigned long r4
,
53 unsigned long r5
, unsigned long r6
, unsigned long r7
);
54 extern void reloc_got2(unsigned long offset
);
56 extern void ppc6xx_idle(void);
57 extern void power4_idle(void);
59 extern boot_infos_t
*boot_infos
;
60 struct ide_machdep_calls ppc_ide_md
;
62 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
63 size value reported by the boot loader. */
64 unsigned long boot_mem_size
;
66 unsigned long ISA_DMA_THRESHOLD
;
67 unsigned int DMA_MODE_READ
;
68 unsigned int DMA_MODE_WRITE
;
70 #ifdef CONFIG_PPC_PREP
71 extern void prep_init(unsigned long r3
, unsigned long r4
,
72 unsigned long r5
, unsigned long r6
, unsigned long r7
);
75 #endif /* CONFIG_PPC_PREP */
78 EXPORT_SYMBOL(have_of
);
81 int ppc_do_canonicalize_irqs
;
82 EXPORT_SYMBOL(ppc_do_canonicalize_irqs
);
85 #ifdef CONFIG_VGA_CONSOLE
86 unsigned long vgacon_remap_base
;
89 struct machdep_calls ppc_md
;
92 * These are used in binfmt_elf.c to put aux entries on the stack
93 * for each elf executable being started.
99 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
100 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
101 struct screen_info screen_info
= {
102 0, 25, /* orig-x, orig-y */
104 0, /* orig-video-page */
105 0, /* orig-video-mode */
106 80, /* orig-video-cols */
107 0,0,0, /* ega_ax, ega_bx, ega_cx */
108 25, /* orig-video-lines */
109 1, /* orig-video-isVGA */
110 16 /* orig-video-points */
112 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
114 void machine_restart(char *cmd
)
122 static void ppc_generic_power_off(void)
127 void machine_halt(void)
135 void (*pm_power_off
)(void) = ppc_generic_power_off
;
137 void machine_power_off(void)
144 ppc_generic_power_off();
148 extern u32
cpu_temp(unsigned long cpu
);
149 extern u32
cpu_temp_both(unsigned long cpu
);
150 #endif /* CONFIG_TAU */
152 int show_cpuinfo(struct seq_file
*m
, void *v
)
157 unsigned short maj
, min
;
161 /* Show summary information */
163 unsigned long bogosum
= 0;
164 for_each_online_cpu(i
)
165 bogosum
+= cpu_data
[i
].loops_per_jiffy
;
166 seq_printf(m
, "total bogomips\t: %lu.%02lu\n",
167 bogosum
/(500000/HZ
), bogosum
/(5000/HZ
) % 100);
168 #endif /* CONFIG_SMP */
170 if (ppc_md
.show_cpuinfo
!= NULL
)
171 err
= ppc_md
.show_cpuinfo(m
);
178 pvr
= cpu_data
[i
].pvr
;
179 lpj
= cpu_data
[i
].loops_per_jiffy
;
181 pvr
= mfspr(SPRN_PVR
);
182 lpj
= loops_per_jiffy
;
185 seq_printf(m
, "processor\t: %d\n", i
);
186 seq_printf(m
, "cpu\t\t: ");
188 if (cur_cpu_spec
->pvr_mask
)
189 seq_printf(m
, "%s", cur_cpu_spec
->cpu_name
);
191 seq_printf(m
, "unknown (%08x)", pvr
);
192 #ifdef CONFIG_ALTIVEC
193 if (cur_cpu_spec
->cpu_features
& CPU_FTR_ALTIVEC
)
194 seq_printf(m
, ", altivec supported");
199 if (cur_cpu_spec
->cpu_features
& CPU_FTR_TAU
) {
200 #ifdef CONFIG_TAU_AVERAGE
201 /* more straightforward, but potentially misleading */
202 seq_printf(m
, "temperature \t: %u C (uncalibrated)\n",
205 /* show the actual temp sensor range */
207 temp
= cpu_temp_both(i
);
208 seq_printf(m
, "temperature \t: %u-%u C (uncalibrated)\n",
209 temp
& 0xff, temp
>> 16);
212 #endif /* CONFIG_TAU */
214 if (ppc_md
.show_percpuinfo
!= NULL
) {
215 err
= ppc_md
.show_percpuinfo(m
, i
);
220 /* If we are a Freescale core do a simple check so
221 * we dont have to keep adding cases in the future */
222 if ((PVR_VER(pvr
) & 0x8000) == 0x8000) {
226 switch (PVR_VER(pvr
)) {
227 case 0x0020: /* 403 family */
228 maj
= PVR_MAJ(pvr
) + 1;
231 case 0x1008: /* 740P/750P ?? */
232 maj
= ((pvr
>> 8) & 0xFF) - 1;
236 maj
= (pvr
>> 8) & 0xFF;
242 seq_printf(m
, "revision\t: %hd.%hd (pvr %04x %04x)\n",
243 maj
, min
, PVR_VER(pvr
), PVR_REV(pvr
));
245 seq_printf(m
, "bogomips\t: %lu.%02lu\n",
246 lpj
/ (500000/HZ
), (lpj
/ (5000/HZ
)) % 100);
249 if (cur_ppc_sys_spec
->ppc_sys_name
)
250 seq_printf(m
, "chipset\t\t: %s\n",
251 cur_ppc_sys_spec
->ppc_sys_name
);
261 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
265 return i
<= NR_CPUS
? (void *) (i
+ 1): NULL
;
268 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
271 return c_start(m
, pos
);
274 static void c_stop(struct seq_file
*m
, void *v
)
278 const struct seq_operations cpuinfo_op
= {
282 .show
= show_cpuinfo
,
286 * We're called here very early in the boot. We determine the machine
287 * type and call the appropriate low-level setup functions.
288 * -- Cort <cort@fsmlabs.com>
290 * Note that the kernel may be running at an address which is different
291 * from the address that it was linked at, so we must use RELOC/PTRRELOC
292 * to access static data (including strings). -- paulus
296 early_init(int r3
, int r4
, int r5
)
299 unsigned long offset
= reloc_offset();
300 struct cpu_spec
*spec
;
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 #if defined(CONFIG_440EP) && defined(CONFIG_PPC_FPU)
314 /* We pass the virtual PVR here for 440EP as 440EP and 440GR have
315 * identical PVRs and there is no reliable way to check for the FPU
317 spec
= identify_cpu(offset
, (mfspr(SPRN_PVR
) | 0x8));
319 spec
= identify_cpu(offset
, mfspr(SPRN_PVR
));
321 do_feature_fixups(spec
->cpu_features
,
322 PTRRELOC(&__start___ftr_fixup
),
323 PTRRELOC(&__stop___ftr_fixup
));
328 #ifdef CONFIG_PPC_PREP
330 * The PPC_PREP version of platform_init...
333 platform_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
334 unsigned long r6
, unsigned long r7
)
336 #ifdef CONFIG_BOOTX_TEXT
337 if (boot_text_mapped
) {
343 parse_bootinfo(find_bootinfo());
345 prep_init(r3
, r4
, r5
, r6
, r7
);
347 #endif /* CONFIG_PPC_PREP */
349 struct bi_record
*find_bootinfo(void)
351 struct bi_record
*rec
;
353 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+(1<<20)-1,(1<<20));
354 if ( rec
->tag
!= BI_FIRST
) {
356 * This 0x10000 offset is a terrible hack but it will go away when
357 * we have the bootloader handle all the relocation and
360 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+0x10000+(1<<20)-1,(1<<20));
361 if ( rec
->tag
!= BI_FIRST
)
367 void parse_bootinfo(struct bi_record
*rec
)
369 if (rec
== NULL
|| rec
->tag
!= BI_FIRST
)
371 while (rec
->tag
!= BI_LAST
) {
372 ulong
*data
= rec
->data
;
375 strlcpy(cmd_line
, (void *)data
, sizeof(cmd_line
));
377 #ifdef CONFIG_BLK_DEV_INITRD
379 initrd_start
= data
[0] + KERNELBASE
;
380 initrd_end
= data
[0] + data
[1] + KERNELBASE
;
382 #endif /* CONFIG_BLK_DEV_INITRD */
384 boot_mem_size
= data
[0];
387 rec
= (struct bi_record
*)((ulong
)rec
+ rec
->size
);
392 * Find out what kind of machine we're on and save any data we need
393 * from the early boot process (devtree is copied on pmac by prom_init()).
394 * This is called very early on the boot process, after a minimal
395 * MMU environment has been set up but before MMU_init is called.
398 machine_init(unsigned long r3
, unsigned long r4
, unsigned long r5
,
399 unsigned long r6
, unsigned long r7
)
401 #ifdef CONFIG_CMDLINE
402 strlcpy(cmd_line
, CONFIG_CMDLINE
, sizeof(cmd_line
));
403 #endif /* CONFIG_CMDLINE */
406 ppc_md
.power_save
= ppc6xx_idle
;
409 platform_init(r3
, r4
, r5
, r6
, r7
);
412 ppc_md
.progress("id mach(): done", 0x200);
414 #ifdef CONFIG_BOOKE_WDT
415 /* Checks wdt=x and wdt_period=xx command-line option */
416 int __init
early_parse_wdt(char *p
)
418 if (p
&& strncmp(p
, "0", 1) != 0)
419 booke_wdt_enabled
= 1;
423 early_param("wdt", early_parse_wdt
);
425 int __init
early_parse_wdt_period (char *p
)
428 booke_wdt_period
= simple_strtoul(p
, NULL
, 0);
432 early_param("wdt_period", early_parse_wdt_period
);
433 #endif /* CONFIG_BOOKE_WDT */
435 /* Checks "l2cr=xxxx" command-line option */
436 int __init
ppc_setup_l2cr(char *str
)
438 if (cpu_has_feature(CPU_FTR_L2CR
)) {
439 unsigned long val
= simple_strtoul(str
, NULL
, 0);
440 printk(KERN_INFO
"l2cr set to %lx\n", val
);
441 _set_L2CR(0); /* force invalidate by disable cache */
442 _set_L2CR(val
); /* and enable it */
446 __setup("l2cr=", ppc_setup_l2cr
);
448 #ifdef CONFIG_GENERIC_NVRAM
450 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
451 unsigned char nvram_read_byte(int addr
)
453 if (ppc_md
.nvram_read_val
)
454 return ppc_md
.nvram_read_val(addr
);
457 EXPORT_SYMBOL(nvram_read_byte
);
459 void nvram_write_byte(unsigned char val
, int addr
)
461 if (ppc_md
.nvram_write_val
)
462 ppc_md
.nvram_write_val(addr
, val
);
464 EXPORT_SYMBOL(nvram_write_byte
);
466 void nvram_sync(void)
468 if (ppc_md
.nvram_sync
)
471 EXPORT_SYMBOL(nvram_sync
);
473 #endif /* CONFIG_NVRAM */
475 static struct cpu cpu_devices
[NR_CPUS
];
477 int __init
ppc_init(void)
481 /* clear the progress line */
482 if ( ppc_md
.progress
) ppc_md
.progress(" ", 0xffff);
484 /* register CPU devices */
485 for_each_possible_cpu(i
)
486 register_cpu(&cpu_devices
[i
], i
);
488 /* call platform init */
489 if (ppc_md
.init
!= NULL
) {
495 arch_initcall(ppc_init
);
497 /* Warning, IO base is not yet inited */
498 void __init
setup_arch(char **cmdline_p
)
501 extern void do_init_bootmem(void);
503 /* so udelay does something sensible, assume <= 1000 bogomips */
504 loops_per_jiffy
= 500000000 / HZ
;
506 if (ppc_md
.init_early
)
511 if (strstr(cmd_line
, "xmon"))
513 #endif /* CONFIG_XMON */
514 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: enter", 0x3eab);
516 #if defined(CONFIG_KGDB)
517 if (ppc_md
.kgdb_map_scc
)
518 ppc_md
.kgdb_map_scc();
520 if (strstr(cmd_line
, "gdb")) {
522 ppc_md
.progress("setup_arch: kgdb breakpoint", 0x4000);
523 printk("kgdb breakpoint activated\n");
529 * Set cache line size based on type of cpu as a default.
530 * Systems with OF can look in the properties on the cpu node(s)
531 * for a possibly more accurate value.
533 if (! cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE
)) {
534 dcache_bsize
= cur_cpu_spec
->dcache_bsize
;
535 icache_bsize
= cur_cpu_spec
->icache_bsize
;
538 ucache_bsize
= dcache_bsize
= icache_bsize
539 = cur_cpu_spec
->dcache_bsize
;
541 /* reboot on panic */
544 init_mm
.start_code
= PAGE_OFFSET
;
545 init_mm
.end_code
= (unsigned long) _etext
;
546 init_mm
.end_data
= (unsigned long) _edata
;
547 init_mm
.brk
= (unsigned long) klimit
;
549 /* Save unparsed command line copy for /proc/cmdline */
550 strlcpy(boot_command_line
, cmd_line
, COMMAND_LINE_SIZE
);
551 *cmdline_p
= cmd_line
;
555 /* set up the bootmem stuff with available memory */
557 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: bootmem", 0x3eab);
559 #ifdef CONFIG_PPC_OCP
560 /* Initialize OCP device list */
562 if ( ppc_md
.progress
) ppc_md
.progress("ocp: exit", 0x3eab);
565 #ifdef CONFIG_DUMMY_CONSOLE
566 conswitchp
= &dummy_con
;
570 if ( ppc_md
.progress
) ppc_md
.progress("arch: exit", 0x3eab);