blob: 75fe13815be27c23e817ac7527c00079476f1c0b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Paul Mackerras0a26b132006-03-28 10:22:10 +11002 * Common prep boot and setup code.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 */
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#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>
Jon Smirl894673e2006-07-10 04:44:13 -070014#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#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>
20
21#include <asm/residual.h>
22#include <asm/io.h>
23#include <asm/prom.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>
29#include <asm/smp.h>
30#include <asm/elf.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/sections.h>
38#include <asm/nvram.h>
39#include <asm/xmon.h>
40#include <asm/ocp.h>
41
Kumar Gala8e8fff02005-09-03 15:55:34 -070042#define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
43 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
44 defined(CONFIG_PPC_MPC52xx))
45
46#if USES_PPC_SYS
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/ppc_sys.h>
48#endif
49
50#if defined CONFIG_KGDB
51#include <asm/kgdb.h>
52#endif
53
54extern void platform_init(unsigned long r3, unsigned long r4,
55 unsigned long r5, unsigned long r6, unsigned long r7);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056extern void identify_cpu(unsigned long offset, unsigned long cpu);
57extern void do_cpu_ftr_fixups(unsigned long offset);
58extern void reloc_got2(unsigned long offset);
59
60extern void ppc6xx_idle(void);
61extern void power4_idle(void);
62
63extern boot_infos_t *boot_infos;
64struct ide_machdep_calls ppc_ide_md;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66/* Used with the BI_MEMSIZE bootinfo parameter to store the memory
67 size value reported by the boot loader. */
68unsigned long boot_mem_size;
69
70unsigned long ISA_DMA_THRESHOLD;
Jon Loeligerb8f114d2005-09-21 14:54:51 -050071unsigned int DMA_MODE_READ;
72unsigned int DMA_MODE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Paul Mackerras0a26b132006-03-28 10:22:10 +110074#ifdef CONFIG_PPC_PREP
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern void prep_init(unsigned long r3, unsigned long r4,
76 unsigned long r5, unsigned long r6, unsigned long r7);
Paul Mackerras14cf11a2005-09-26 16:04:21 +100077
78dev_t boot_dev;
Paul Mackerras0a26b132006-03-28 10:22:10 +110079#endif /* CONFIG_PPC_PREP */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Paul Mackerrasfd582ec2005-10-11 22:08:12 +100081int have_of;
82EXPORT_SYMBOL(have_of);
83
Paul Mackerras35d81a42005-10-11 22:03:09 +100084#ifdef __DO_IRQ_CANON
85int ppc_do_canonicalize_irqs;
86EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
87#endif
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#ifdef CONFIG_VGA_CONSOLE
90unsigned long vgacon_remap_base;
91#endif
92
93struct machdep_calls ppc_md;
94
95/*
96 * These are used in binfmt_elf.c to put aux entries on the stack
97 * for each elf executable being started.
98 */
99int dcache_bsize;
100int icache_bsize;
101int ucache_bsize;
102
103#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
104 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
105struct screen_info screen_info = {
106 0, 25, /* orig-x, orig-y */
107 0, /* unused */
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 */
115};
116#endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
117
118void machine_restart(char *cmd)
119{
120#ifdef CONFIG_NVRAM
121 nvram_sync();
122#endif
123 ppc_md.restart(cmd);
124}
125
Corey Minyard477bcae2006-09-06 09:02:53 -0500126static void ppc_generic_power_off(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 ppc_md.power_off();
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131void machine_halt(void)
132{
133#ifdef CONFIG_NVRAM
134 nvram_sync();
135#endif
136 ppc_md.halt();
137}
138
Corey Minyard477bcae2006-09-06 09:02:53 -0500139void (*pm_power_off)(void) = ppc_generic_power_off;
140
141void machine_power_off(void)
142{
143#ifdef CONFIG_NVRAM
144 nvram_sync();
145#endif
146 if (pm_power_off)
147 pm_power_off();
148 ppc_generic_power_off();
149}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151#ifdef CONFIG_TAU
152extern u32 cpu_temp(unsigned long cpu);
153extern u32 cpu_temp_both(unsigned long cpu);
154#endif /* CONFIG_TAU */
155
156int show_cpuinfo(struct seq_file *m, void *v)
157{
158 int i = (int) v - 1;
159 int err = 0;
160 unsigned int pvr;
161 unsigned short maj, min;
162 unsigned long lpj;
163
164 if (i >= NR_CPUS) {
165 /* Show summary information */
166#ifdef CONFIG_SMP
167 unsigned long bogosum = 0;
Andrew Morton394e3902006-03-23 03:01:05 -0800168 for_each_online_cpu(i)
169 bogosum += cpu_data[i].loops_per_jiffy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
171 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
172#endif /* CONFIG_SMP */
173
174 if (ppc_md.show_cpuinfo != NULL)
175 err = ppc_md.show_cpuinfo(m);
176 return err;
177 }
178
179#ifdef CONFIG_SMP
180 if (!cpu_online(i))
181 return 0;
182 pvr = cpu_data[i].pvr;
183 lpj = cpu_data[i].loops_per_jiffy;
184#else
185 pvr = mfspr(SPRN_PVR);
186 lpj = loops_per_jiffy;
187#endif
188
189 seq_printf(m, "processor\t: %d\n", i);
190 seq_printf(m, "cpu\t\t: ");
191
Kumar Gala400d2212005-09-27 15:13:12 -0500192 if (cur_cpu_spec->pvr_mask)
193 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 else
195 seq_printf(m, "unknown (%08x)", pvr);
196#ifdef CONFIG_ALTIVEC
Kumar Gala400d2212005-09-27 15:13:12 -0500197 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 seq_printf(m, ", altivec supported");
199#endif
200 seq_printf(m, "\n");
201
202#ifdef CONFIG_TAU
Kumar Gala400d2212005-09-27 15:13:12 -0500203 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#ifdef CONFIG_TAU_AVERAGE
205 /* more straightforward, but potentially misleading */
206 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
207 cpu_temp(i));
208#else
209 /* show the actual temp sensor range */
210 u32 temp;
211 temp = cpu_temp_both(i);
212 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
213 temp & 0xff, temp >> 16);
214#endif
215 }
216#endif /* CONFIG_TAU */
217
218 if (ppc_md.show_percpuinfo != NULL) {
219 err = ppc_md.show_percpuinfo(m, i);
220 if (err)
221 return err;
222 }
223
Kumar Gala696c2b92005-05-05 16:15:10 -0700224 /* 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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 maj = PVR_MAJ(pvr);
228 min = PVR_MIN(pvr);
Kumar Gala696c2b92005-05-05 16:15:10 -0700229 } else {
230 switch (PVR_VER(pvr)) {
231 case 0x0020: /* 403 family */
232 maj = PVR_MAJ(pvr) + 1;
233 min = PVR_MIN(pvr);
234 break;
235 case 0x1008: /* 740P/750P ?? */
236 maj = ((pvr >> 8) & 0xFF) - 1;
237 min = pvr & 0xFF;
238 break;
239 default:
240 maj = (pvr >> 8) & 0xFF;
241 min = pvr & 0xFF;
242 break;
243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245
246 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
247 maj, min, PVR_VER(pvr), PVR_REV(pvr));
248
249 seq_printf(m, "bogomips\t: %lu.%02lu\n",
250 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
251
Kumar Gala8e8fff02005-09-03 15:55:34 -0700252#if USES_PPC_SYS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 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);
256#endif
257
258#ifdef CONFIG_SMP
259 seq_printf(m, "\n");
260#endif
261
262 return 0;
263}
264
265static void *c_start(struct seq_file *m, loff_t *pos)
266{
267 int i = *pos;
268
269 return i <= NR_CPUS? (void *) (i + 1): NULL;
270}
271
272static void *c_next(struct seq_file *m, void *v, loff_t *pos)
273{
274 ++*pos;
275 return c_start(m, pos);
276}
277
278static void c_stop(struct seq_file *m, void *v)
279{
280}
281
282struct seq_operations cpuinfo_op = {
283 .start =c_start,
284 .next = c_next,
285 .stop = c_stop,
286 .show = show_cpuinfo,
287};
288
289/*
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>
293 *
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
297 */
298__init
299unsigned long
300early_init(int r3, int r4, int r5)
301{
302 unsigned long phys;
303 unsigned long offset = reloc_offset();
304
305 /* Default */
306 phys = offset + KERNELBASE;
307
308 /* First zero the BSS -- use memset, some arches don't have
309 * caches on yet */
310 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
311
312 /*
313 * Identify the CPU type and fix up code sections
314 * that depend on which cpu we have.
315 */
316 identify_cpu(offset, 0);
317 do_cpu_ftr_fixups(offset);
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return phys;
320}
321
Paul Mackerras0a26b132006-03-28 10:22:10 +1100322#ifdef CONFIG_PPC_PREP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/*
Paul Mackerras0a26b132006-03-28 10:22:10 +1100324 * The PPC_PREP version of platform_init...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 */
326void __init
327platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
328 unsigned long r6, unsigned long r7)
329{
330#ifdef CONFIG_BOOTX_TEXT
331 if (boot_text_mapped) {
332 btext_clearscreen();
333 btext_welcome();
334 }
335#endif
336
337 parse_bootinfo(find_bootinfo());
338
Paul Mackerras0a26b132006-03-28 10:22:10 +1100339 prep_init(r3, r4, r5, r6, r7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
Paul Mackerras0a26b132006-03-28 10:22:10 +1100341#endif /* CONFIG_PPC_PREP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343struct bi_record *find_bootinfo(void)
344{
345 struct bi_record *rec;
346
347 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
348 if ( rec->tag != BI_FIRST ) {
349 /*
350 * This 0x10000 offset is a terrible hack but it will go away when
351 * we have the bootloader handle all the relocation and
352 * prom calls -- Cort
353 */
354 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
355 if ( rec->tag != BI_FIRST )
356 return NULL;
357 }
358 return rec;
359}
360
361void parse_bootinfo(struct bi_record *rec)
362{
363 if (rec == NULL || rec->tag != BI_FIRST)
364 return;
365 while (rec->tag != BI_LAST) {
366 ulong *data = rec->data;
367 switch (rec->tag) {
368 case BI_CMD_LINE:
369 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
370 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#ifdef CONFIG_BLK_DEV_INITRD
372 case BI_INITRD:
373 initrd_start = data[0] + KERNELBASE;
374 initrd_end = data[0] + data[1] + KERNELBASE;
375 break;
376#endif /* CONFIG_BLK_DEV_INITRD */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 case BI_MEMSIZE:
378 boot_mem_size = data[0];
379 break;
380 }
381 rec = (struct bi_record *)((ulong)rec + rec->size);
382 }
383}
384
385/*
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.
390 */
391void __init
392machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
393 unsigned long r6, unsigned long r7)
394{
395#ifdef CONFIG_CMDLINE
396 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
397#endif /* CONFIG_CMDLINE */
398
399#ifdef CONFIG_6xx
400 ppc_md.power_save = ppc6xx_idle;
401#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 platform_init(r3, r4, r5, r6, r7);
404
405 if (ppc_md.progress)
406 ppc_md.progress("id mach(): done", 0x200);
407}
Kumar Galaa2f40cc2005-09-03 15:55:33 -0700408#ifdef CONFIG_BOOKE_WDT
409/* Checks wdt=x and wdt_period=xx command-line option */
410int __init early_parse_wdt(char *p)
411{
Kumar Galaa2f40cc2005-09-03 15:55:33 -0700412 if (p && strncmp(p, "0", 1) != 0)
Kumar Gala39cdc4b2005-09-03 15:55:39 -0700413 booke_wdt_enabled = 1;
Kumar Galaa2f40cc2005-09-03 15:55:33 -0700414
415 return 0;
416}
417early_param("wdt", early_parse_wdt);
418
419int __init early_parse_wdt_period (char *p)
420{
Kumar Galaa2f40cc2005-09-03 15:55:33 -0700421 if (p)
Kumar Gala39cdc4b2005-09-03 15:55:39 -0700422 booke_wdt_period = simple_strtoul(p, NULL, 0);
Kumar Galaa2f40cc2005-09-03 15:55:33 -0700423
424 return 0;
425}
426early_param("wdt_period", early_parse_wdt_period);
427#endif /* CONFIG_BOOKE_WDT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429/* Checks "l2cr=xxxx" command-line option */
430int __init ppc_setup_l2cr(char *str)
431{
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 */
437 }
438 return 1;
439}
440__setup("l2cr=", ppc_setup_l2cr);
441
442#ifdef CONFIG_GENERIC_NVRAM
443
444/* Generic nvram hooks used by drivers/char/gen_nvram.c */
445unsigned char nvram_read_byte(int addr)
446{
447 if (ppc_md.nvram_read_val)
448 return ppc_md.nvram_read_val(addr);
449 return 0xff;
450}
451EXPORT_SYMBOL(nvram_read_byte);
452
453void nvram_write_byte(unsigned char val, int addr)
454{
455 if (ppc_md.nvram_write_val)
456 ppc_md.nvram_write_val(addr, val);
457}
458EXPORT_SYMBOL(nvram_write_byte);
459
460void nvram_sync(void)
461{
462 if (ppc_md.nvram_sync)
463 ppc_md.nvram_sync();
464}
465EXPORT_SYMBOL(nvram_sync);
466
467#endif /* CONFIG_NVRAM */
468
469static struct cpu cpu_devices[NR_CPUS];
470
471int __init ppc_init(void)
472{
473 int i;
474
475 /* clear the progress line */
476 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
477
478 /* register CPU devices */
KAMEZAWA Hiroyukib848e0a2006-03-28 14:50:52 -0800479 for_each_possible_cpu(i)
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700480 register_cpu(&cpu_devices[i], i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 /* call platform init */
483 if (ppc_md.init != NULL) {
484 ppc_md.init();
485 }
486 return 0;
487}
488
489arch_initcall(ppc_init);
490
491/* Warning, IO base is not yet inited */
492void __init setup_arch(char **cmdline_p)
493{
494 extern char *klimit;
495 extern void do_init_bootmem(void);
496
497 /* so udelay does something sensible, assume <= 1000 bogomips */
498 loops_per_jiffy = 500000000 / HZ;
499
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100500 if (ppc_md.init_early)
501 ppc_md.init_early();
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#ifdef CONFIG_XMON
Paul Mackerrasfd582ec2005-10-11 22:08:12 +1000504 xmon_init(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (strstr(cmd_line, "xmon"))
506 xmon(NULL);
507#endif /* CONFIG_XMON */
508 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
509
510#if defined(CONFIG_KGDB)
511 if (ppc_md.kgdb_map_scc)
512 ppc_md.kgdb_map_scc();
513 set_debug_traps();
514 if (strstr(cmd_line, "gdb")) {
515 if (ppc_md.progress)
516 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
517 printk("kgdb breakpoint activated\n");
518 breakpoint();
519 }
520#endif
521
522 /*
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.
526 */
527 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
Kumar Gala400d2212005-09-27 15:13:12 -0500528 dcache_bsize = cur_cpu_spec->dcache_bsize;
529 icache_bsize = cur_cpu_spec->icache_bsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 ucache_bsize = 0;
531 } else
532 ucache_bsize = dcache_bsize = icache_bsize
Kumar Gala400d2212005-09-27 15:13:12 -0500533 = cur_cpu_spec->dcache_bsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 /* reboot on panic */
536 panic_timeout = 180;
537
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;
542
543 /* Save unparsed command line copy for /proc/cmdline */
544 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
545 *cmdline_p = cmd_line;
546
Paul Mackerras19bbdf02005-05-17 16:48:39 +1000547 parse_early_param();
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 /* set up the bootmem stuff with available memory */
550 do_init_bootmem();
551 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
552
553#ifdef CONFIG_PPC_OCP
554 /* Initialize OCP device list */
555 ocp_early_init();
556 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
557#endif
558
559#ifdef CONFIG_DUMMY_CONSOLE
560 conswitchp = &dummy_con;
561#endif
562
563 ppc_md.setup_arch();
564 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
565
566 paging_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}