blob: b95f7cf693e69b857cba6b396ea5d9e8bf7f4caa [file] [log] [blame]
Paul Mackerras9b6b5632005-10-06 12:06:20 +10001/*
2 * Common prep/pmac/chrp boot and setup code.
3 */
4
5#include <linux/config.h>
6#include <linux/module.h>
7#include <linux/string.h>
8#include <linux/sched.h>
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/reboot.h>
12#include <linux/delay.h>
13#include <linux/initrd.h>
14#include <linux/ide.h>
15#include <linux/tty.h>
16#include <linux/bootmem.h>
17#include <linux/seq_file.h>
18#include <linux/root_dev.h>
19#include <linux/cpu.h>
20#include <linux/console.h>
21
22#include <asm/residual.h>
23#include <asm/io.h>
24#include <asm/prom.h>
25#include <asm/processor.h>
26#include <asm/pgtable.h>
27#include <asm/bootinfo.h>
28#include <asm/setup.h>
29#include <asm/amigappc.h>
30#include <asm/smp.h>
31#include <asm/elf.h>
32#include <asm/cputable.h>
33#include <asm/bootx.h>
34#include <asm/btext.h>
35#include <asm/machdep.h>
36#include <asm/uaccess.h>
37#include <asm/system.h>
38#include <asm/pmac_feature.h>
39#include <asm/sections.h>
40#include <asm/nvram.h>
41#include <asm/xmon.h>
42#include <asm/ocp.h>
43
44#define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
45 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
46 defined(CONFIG_PPC_MPC52xx))
47
48#if USES_PPC_SYS
49#include <asm/ppc_sys.h>
50#endif
51
52#if defined CONFIG_KGDB
53#include <asm/kgdb.h>
54#endif
55
56extern void platform_init(void);
57extern void bootx_init(unsigned long r4, unsigned long phys);
58
59extern void ppc6xx_idle(void);
60extern void power4_idle(void);
61
62boot_infos_t *boot_infos;
63struct ide_machdep_calls ppc_ide_md;
64
65/* Used with the BI_MEMSIZE bootinfo parameter to store the memory
66 size value reported by the boot loader. */
67unsigned long boot_mem_size;
68
69unsigned long ISA_DMA_THRESHOLD;
70unsigned int DMA_MODE_READ;
71unsigned int DMA_MODE_WRITE;
72
Paul Mackerrase574d232005-10-10 22:58:10 +100073int have_of = 1;
74
Paul Mackerras9b6b5632005-10-06 12:06:20 +100075#ifdef CONFIG_PPC_MULTIPLATFORM
76int _machine = 0;
77
78extern void prep_init(void);
79extern void pmac_init(void);
80extern void chrp_init(void);
81
82dev_t boot_dev;
83#endif /* CONFIG_PPC_MULTIPLATFORM */
84
85#ifdef CONFIG_MAGIC_SYSRQ
86unsigned long SYSRQ_KEY = 0x54;
87#endif /* CONFIG_MAGIC_SYSRQ */
88
89#ifdef CONFIG_VGA_CONSOLE
90unsigned long vgacon_remap_base;
91#endif
92
93struct machdep_calls ppc_md;
Paul Mackerrase574d232005-10-10 22:58:10 +100094EXPORT_SYMBOL(ppc_md);
Paul Mackerras9b6b5632005-10-06 12:06:20 +100095
96/*
97 * These are used in binfmt_elf.c to put aux entries on the stack
98 * for each elf executable being started.
99 */
100int dcache_bsize;
101int icache_bsize;
102int ucache_bsize;
103
104#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
105 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
106struct screen_info screen_info = {
107 0, 25, /* orig-x, orig-y */
108 0, /* unused */
109 0, /* orig-video-page */
110 0, /* orig-video-mode */
111 80, /* orig-video-cols */
112 0,0,0, /* ega_ax, ega_bx, ega_cx */
113 25, /* orig-video-lines */
114 1, /* orig-video-isVGA */
115 16 /* orig-video-points */
116};
117#endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
118
119void machine_restart(char *cmd)
120{
121#ifdef CONFIG_NVRAM
122 nvram_sync();
123#endif
124 ppc_md.restart(cmd);
125}
126
127void machine_power_off(void)
128{
129#ifdef CONFIG_NVRAM
130 nvram_sync();
131#endif
132 ppc_md.power_off();
133}
134
135void machine_halt(void)
136{
137#ifdef CONFIG_NVRAM
138 nvram_sync();
139#endif
140 ppc_md.halt();
141}
142
143void (*pm_power_off)(void) = machine_power_off;
144
145#ifdef CONFIG_TAU
146extern u32 cpu_temp(unsigned long cpu);
147extern u32 cpu_temp_both(unsigned long cpu);
148#endif /* CONFIG_TAU */
149
150int show_cpuinfo(struct seq_file *m, void *v)
151{
152 int i = (int) v - 1;
153 int err = 0;
154 unsigned int pvr;
155 unsigned short maj, min;
156 unsigned long lpj;
157
158 if (i >= NR_CPUS) {
159 /* Show summary information */
160#ifdef CONFIG_SMP
161 unsigned long bogosum = 0;
162 for (i = 0; i < NR_CPUS; ++i)
163 if (cpu_online(i))
164 bogosum += cpu_data[i].loops_per_jiffy;
165 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
166 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
167#endif /* CONFIG_SMP */
168
169 if (ppc_md.show_cpuinfo != NULL)
170 err = ppc_md.show_cpuinfo(m);
171 return err;
172 }
173
174#ifdef CONFIG_SMP
175 if (!cpu_online(i))
176 return 0;
177 pvr = cpu_data[i].pvr;
178 lpj = cpu_data[i].loops_per_jiffy;
179#else
180 pvr = mfspr(SPRN_PVR);
181 lpj = loops_per_jiffy;
182#endif
183
184 seq_printf(m, "processor\t: %d\n", i);
185 seq_printf(m, "cpu\t\t: ");
186
187 if (cur_cpu_spec->pvr_mask)
188 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
189 else
190 seq_printf(m, "unknown (%08x)", pvr);
191#ifdef CONFIG_ALTIVEC
192 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
193 seq_printf(m, ", altivec supported");
194#endif
195 seq_printf(m, "\n");
196
197#ifdef CONFIG_TAU
198 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
199#ifdef CONFIG_TAU_AVERAGE
200 /* more straightforward, but potentially misleading */
201 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
202 cpu_temp(i));
203#else
204 /* show the actual temp sensor range */
205 u32 temp;
206 temp = cpu_temp_both(i);
207 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
208 temp & 0xff, temp >> 16);
209#endif
210 }
211#endif /* CONFIG_TAU */
212
213 if (ppc_md.show_percpuinfo != NULL) {
214 err = ppc_md.show_percpuinfo(m, i);
215 if (err)
216 return err;
217 }
218
219 /* If we are a Freescale core do a simple check so
220 * we dont have to keep adding cases in the future */
221 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
222 maj = PVR_MAJ(pvr);
223 min = PVR_MIN(pvr);
224 } else {
225 switch (PVR_VER(pvr)) {
226 case 0x0020: /* 403 family */
227 maj = PVR_MAJ(pvr) + 1;
228 min = PVR_MIN(pvr);
229 break;
230 case 0x1008: /* 740P/750P ?? */
231 maj = ((pvr >> 8) & 0xFF) - 1;
232 min = pvr & 0xFF;
233 break;
234 default:
235 maj = (pvr >> 8) & 0xFF;
236 min = pvr & 0xFF;
237 break;
238 }
239 }
240
241 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
242 maj, min, PVR_VER(pvr), PVR_REV(pvr));
243
244 seq_printf(m, "bogomips\t: %lu.%02lu\n",
245 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
246
247#if USES_PPC_SYS
248 if (cur_ppc_sys_spec->ppc_sys_name)
249 seq_printf(m, "chipset\t\t: %s\n",
250 cur_ppc_sys_spec->ppc_sys_name);
251#endif
252
253#ifdef CONFIG_SMP
254 seq_printf(m, "\n");
255#endif
256
257 return 0;
258}
259
260static void *c_start(struct seq_file *m, loff_t *pos)
261{
262 int i = *pos;
263
264 return i <= NR_CPUS? (void *) (i + 1): NULL;
265}
266
267static void *c_next(struct seq_file *m, void *v, loff_t *pos)
268{
269 ++*pos;
270 return c_start(m, pos);
271}
272
273static void c_stop(struct seq_file *m, void *v)
274{
275}
276
277struct seq_operations cpuinfo_op = {
278 .start =c_start,
279 .next = c_next,
280 .stop = c_stop,
281 .show = show_cpuinfo,
282};
283
284/*
285 * We're called here very early in the boot. We determine the machine
286 * type and call the appropriate low-level setup functions.
287 * -- Cort <cort@fsmlabs.com>
288 *
289 * Note that the kernel may be running at an address which is different
290 * from the address that it was linked at, so we must use RELOC/PTRRELOC
291 * to access static data (including strings). -- paulus
292 */
293unsigned long __init early_init(unsigned long dt_ptr)
294{
295 unsigned long offset = reloc_offset();
296
Paul Mackerrasdd1843432005-10-17 20:13:47 +1000297 /* First zero the BSS -- use memset_io, some platforms don't have
298 * caches on yet */
299 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
300
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000301 /*
302 * Identify the CPU type and fix up code sections
303 * that depend on which cpu we have.
304 */
305 identify_cpu(offset, 0);
306 do_cpu_ftr_fixups(offset);
307
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000308 return KERNELBASE + offset;
309}
310
311#ifdef CONFIG_PPC_OF
312/*
313 * Assume here that all clock rates are the same in a
314 * smp system. -- Cort
315 */
316int
317of_show_percpuinfo(struct seq_file *m, int i)
318{
319 struct device_node *cpu_node;
320 u32 *fp;
321 int s;
322
323 cpu_node = find_type_devices("cpu");
324 if (!cpu_node)
325 return 0;
326 for (s = 0; s < i && cpu_node->next; s++)
327 cpu_node = cpu_node->next;
328 fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL);
329 if (fp)
330 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
331 return 0;
332}
333
334void __init
335intuit_machine_type(void)
336{
337 char *model;
338 struct device_node *root;
339
340 /* ask the OF info if we're a chrp or pmac */
341 root = find_path_device("/");
342 if (root != 0) {
343 /* assume pmac unless proven to be chrp -- Cort */
344 _machine = _MACH_Pmac;
345 model = get_property(root, "device_type", NULL);
346 if (model && !strncmp("chrp", model, 4))
347 _machine = _MACH_chrp;
348 else {
349 model = get_property(root, "model", NULL);
350 if (model && !strncmp(model, "IBM", 3))
351 _machine = _MACH_chrp;
352 }
353 }
354}
355#endif
356
357#ifdef CONFIG_PPC_MULTIPLATFORM
358/*
359 * The PPC_MULTIPLATFORM version of platform_init...
360 */
361void __init platform_init(void)
362{
363 /* if we didn't get any bootinfo telling us what we are... */
364 if (_machine == 0) {
365 /* prep boot loader tells us if we're prep or not */
366 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
367 _machine = _MACH_prep;
368 }
369
370#ifdef CONFIG_PPC_PREP
371 /* not much more to do here, if prep */
372 if (_machine == _MACH_prep) {
373 prep_init();
374 return;
375 }
376#endif
377
378#ifdef CONFIG_ADB
379 if (strstr(cmd_line, "adb_sync")) {
380 extern int __adb_probe_sync;
381 __adb_probe_sync = 1;
382 }
383#endif /* CONFIG_ADB */
384
385 switch (_machine) {
386#ifdef CONFIG_PPC_PMAC
387 case _MACH_Pmac:
388 pmac_init();
389 break;
390#endif
391#ifdef CONFIG_PPC_CHRP
392 case _MACH_chrp:
393 chrp_init();
394 break;
395#endif
396 }
397}
398
399#ifdef CONFIG_SERIAL_CORE_CONSOLE
400extern char *of_stdout_device;
401
402static int __init set_preferred_console(void)
403{
404 struct device_node *prom_stdout;
405 char *name;
406 int offset = 0;
407
408 if (of_stdout_device == NULL)
409 return -ENODEV;
410
411 /* The user has requested a console so this is already set up. */
412 if (strstr(saved_command_line, "console="))
413 return -EBUSY;
414
415 prom_stdout = find_path_device(of_stdout_device);
416 if (!prom_stdout)
417 return -ENODEV;
418
419 name = (char *)get_property(prom_stdout, "name", NULL);
420 if (!name)
421 return -ENODEV;
422
423 if (strcmp(name, "serial") == 0) {
424 int i;
425 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
426 if (i > 8) {
427 switch (reg[1]) {
428 case 0x3f8:
429 offset = 0;
430 break;
431 case 0x2f8:
432 offset = 1;
433 break;
434 case 0x898:
435 offset = 2;
436 break;
437 case 0x890:
438 offset = 3;
439 break;
440 default:
441 /* We dont recognise the serial port */
442 return -ENODEV;
443 }
444 }
445 } else if (strcmp(name, "ch-a") == 0)
446 offset = 0;
447 else if (strcmp(name, "ch-b") == 0)
448 offset = 1;
449 else
450 return -ENODEV;
451 return add_preferred_console("ttyS", offset, NULL);
452}
453console_initcall(set_preferred_console);
454#endif /* CONFIG_SERIAL_CORE_CONSOLE */
455#endif /* CONFIG_PPC_MULTIPLATFORM */
456
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000457/*
458 * Find out what kind of machine we're on and save any data we need
459 * from the early boot process (devtree is copied on pmac by prom_init()).
460 * This is called very early on the boot process, after a minimal
461 * MMU environment has been set up but before MMU_init is called.
462 */
463void __init machine_init(unsigned long dt_ptr, unsigned long phys)
464{
465 early_init_devtree(__va(dt_ptr));
466
467#ifdef CONFIG_CMDLINE
468 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
469#endif /* CONFIG_CMDLINE */
470
471#ifdef CONFIG_6xx
472 ppc_md.power_save = ppc6xx_idle;
473#endif
474#ifdef CONFIG_POWER4
475 ppc_md.power_save = power4_idle;
476#endif
477
478 platform_init();
479
480 if (ppc_md.progress)
481 ppc_md.progress("id mach(): done", 0x200);
482}
483
484#ifdef CONFIG_BOOKE_WDT
485/* Checks wdt=x and wdt_period=xx command-line option */
486int __init early_parse_wdt(char *p)
487{
488 if (p && strncmp(p, "0", 1) != 0)
489 booke_wdt_enabled = 1;
490
491 return 0;
492}
493early_param("wdt", early_parse_wdt);
494
495int __init early_parse_wdt_period (char *p)
496{
497 if (p)
498 booke_wdt_period = simple_strtoul(p, NULL, 0);
499
500 return 0;
501}
502early_param("wdt_period", early_parse_wdt_period);
503#endif /* CONFIG_BOOKE_WDT */
504
505/* Checks "l2cr=xxxx" command-line option */
506int __init ppc_setup_l2cr(char *str)
507{
508 if (cpu_has_feature(CPU_FTR_L2CR)) {
509 unsigned long val = simple_strtoul(str, NULL, 0);
510 printk(KERN_INFO "l2cr set to %lx\n", val);
511 _set_L2CR(0); /* force invalidate by disable cache */
512 _set_L2CR(val); /* and enable it */
513 }
514 return 1;
515}
516__setup("l2cr=", ppc_setup_l2cr);
517
518#ifdef CONFIG_GENERIC_NVRAM
519
520/* Generic nvram hooks used by drivers/char/gen_nvram.c */
521unsigned char nvram_read_byte(int addr)
522{
523 if (ppc_md.nvram_read_val)
524 return ppc_md.nvram_read_val(addr);
525 return 0xff;
526}
527EXPORT_SYMBOL(nvram_read_byte);
528
529void nvram_write_byte(unsigned char val, int addr)
530{
531 if (ppc_md.nvram_write_val)
532 ppc_md.nvram_write_val(addr, val);
533}
534EXPORT_SYMBOL(nvram_write_byte);
535
536void nvram_sync(void)
537{
538 if (ppc_md.nvram_sync)
539 ppc_md.nvram_sync();
540}
541EXPORT_SYMBOL(nvram_sync);
542
543#endif /* CONFIG_NVRAM */
544
545static struct cpu cpu_devices[NR_CPUS];
546
547int __init ppc_init(void)
548{
549 int i;
550
551 /* clear the progress line */
552 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
553
554 /* register CPU devices */
555 for (i = 0; i < NR_CPUS; i++)
556 if (cpu_possible(i))
557 register_cpu(&cpu_devices[i], i, NULL);
558
559 /* call platform init */
560 if (ppc_md.init != NULL) {
561 ppc_md.init();
562 }
563 return 0;
564}
565
566arch_initcall(ppc_init);
567
568/* Warning, IO base is not yet inited */
569void __init setup_arch(char **cmdline_p)
570{
571 extern char *klimit;
572 extern void do_init_bootmem(void);
573
574 /* so udelay does something sensible, assume <= 1000 bogomips */
575 loops_per_jiffy = 500000000 / HZ;
576
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000577 unflatten_device_tree();
578 finish_device_tree();
579
Paul Mackerras30cd4a42005-10-17 19:20:46 +1000580#ifdef CONFIG_BOOTX_TEXT
581 init_boot_display();
582#endif
583
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000584#ifdef CONFIG_PPC_MULTIPLATFORM
585 /* This could be called "early setup arch", it must be done
586 * now because xmon need it
587 */
588 if (_machine == _MACH_Pmac)
589 pmac_feature_init(); /* New cool way */
590#endif
591
592#ifdef CONFIG_XMON
593 xmon_map_scc();
594 if (strstr(cmd_line, "xmon"))
595 xmon(NULL);
596#endif /* CONFIG_XMON */
597 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
598
599#if defined(CONFIG_KGDB)
600 if (ppc_md.kgdb_map_scc)
601 ppc_md.kgdb_map_scc();
602 set_debug_traps();
603 if (strstr(cmd_line, "gdb")) {
604 if (ppc_md.progress)
605 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
606 printk("kgdb breakpoint activated\n");
607 breakpoint();
608 }
609#endif
610
611 /*
612 * Set cache line size based on type of cpu as a default.
613 * Systems with OF can look in the properties on the cpu node(s)
614 * for a possibly more accurate value.
615 */
616 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
617 dcache_bsize = cur_cpu_spec->dcache_bsize;
618 icache_bsize = cur_cpu_spec->icache_bsize;
619 ucache_bsize = 0;
620 } else
621 ucache_bsize = dcache_bsize = icache_bsize
622 = cur_cpu_spec->dcache_bsize;
623
624 /* reboot on panic */
625 panic_timeout = 180;
626
627 init_mm.start_code = PAGE_OFFSET;
628 init_mm.end_code = (unsigned long) _etext;
629 init_mm.end_data = (unsigned long) _edata;
630 init_mm.brk = (unsigned long) klimit;
631
632 /* Save unparsed command line copy for /proc/cmdline */
633 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
634 *cmdline_p = cmd_line;
635
636 parse_early_param();
637
638 /* set up the bootmem stuff with available memory */
639 do_init_bootmem();
640 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
641
642#ifdef CONFIG_PPC_OCP
643 /* Initialize OCP device list */
644 ocp_early_init();
645 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
646#endif
647
648#ifdef CONFIG_DUMMY_CONSOLE
649 conswitchp = &dummy_con;
650#endif
651
652 ppc_md.setup_arch();
653 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
654
655 paging_init();
656
657 /* this is for modules since _machine can be a define -- Cort */
658 ppc_md.ppc_machine = _machine;
659}