]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/powerpc/kernel/setup_32.c
[PATCH] powerpc: Add support for Book-E timer config to generic_calibrate_decr
[mirror_ubuntu-zesty-kernel.git] / arch / powerpc / kernel / setup_32.c
CommitLineData
9b6b563c
PM
1/*
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
e574d238
PM
73int have_of = 1;
74
9b6b563c
PM
75#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;
e574d238 94EXPORT_SYMBOL(ppc_md);
9b6b563c
PM
95
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;
9b6b563c
PM
153 unsigned int pvr;
154 unsigned short maj, min;
155 unsigned long lpj;
156
157 if (i >= NR_CPUS) {
158 /* Show summary information */
159#ifdef CONFIG_SMP
160 unsigned long bogosum = 0;
161 for (i = 0; i < NR_CPUS; ++i)
162 if (cpu_online(i))
163 bogosum += cpu_data[i].loops_per_jiffy;
164 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
165 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
166#endif /* CONFIG_SMP */
167
168 if (ppc_md.show_cpuinfo != NULL)
0dd194d0
PM
169 ppc_md.show_cpuinfo(m);
170 return 0;
9b6b563c
PM
171 }
172
173#ifdef CONFIG_SMP
174 if (!cpu_online(i))
175 return 0;
176 pvr = cpu_data[i].pvr;
177 lpj = cpu_data[i].loops_per_jiffy;
178#else
179 pvr = mfspr(SPRN_PVR);
180 lpj = loops_per_jiffy;
181#endif
182
183 seq_printf(m, "processor\t: %d\n", i);
184 seq_printf(m, "cpu\t\t: ");
185
186 if (cur_cpu_spec->pvr_mask)
187 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
188 else
189 seq_printf(m, "unknown (%08x)", pvr);
190#ifdef CONFIG_ALTIVEC
191 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
192 seq_printf(m, ", altivec supported");
193#endif
194 seq_printf(m, "\n");
195
196#ifdef CONFIG_TAU
197 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
198#ifdef CONFIG_TAU_AVERAGE
199 /* more straightforward, but potentially misleading */
200 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
201 cpu_temp(i));
202#else
203 /* show the actual temp sensor range */
204 u32 temp;
205 temp = cpu_temp_both(i);
206 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
207 temp & 0xff, temp >> 16);
208#endif
209 }
210#endif /* CONFIG_TAU */
211
0dd194d0
PM
212 if (ppc_md.show_percpuinfo != NULL)
213 ppc_md.show_percpuinfo(m, i);
9b6b563c
PM
214
215 /* If we are a Freescale core do a simple check so
216 * we dont have to keep adding cases in the future */
0dd194d0 217 if (PVR_VER(pvr) & 0x8000) {
9b6b563c
PM
218 maj = PVR_MAJ(pvr);
219 min = PVR_MIN(pvr);
220 } else {
221 switch (PVR_VER(pvr)) {
222 case 0x0020: /* 403 family */
223 maj = PVR_MAJ(pvr) + 1;
224 min = PVR_MIN(pvr);
225 break;
226 case 0x1008: /* 740P/750P ?? */
227 maj = ((pvr >> 8) & 0xFF) - 1;
228 min = pvr & 0xFF;
229 break;
230 default:
231 maj = (pvr >> 8) & 0xFF;
232 min = pvr & 0xFF;
233 break;
234 }
235 }
236
237 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
238 maj, min, PVR_VER(pvr), PVR_REV(pvr));
239
240 seq_printf(m, "bogomips\t: %lu.%02lu\n",
241 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
242
243#if USES_PPC_SYS
244 if (cur_ppc_sys_spec->ppc_sys_name)
245 seq_printf(m, "chipset\t\t: %s\n",
246 cur_ppc_sys_spec->ppc_sys_name);
247#endif
248
249#ifdef CONFIG_SMP
250 seq_printf(m, "\n");
251#endif
252
253 return 0;
254}
255
256static void *c_start(struct seq_file *m, loff_t *pos)
257{
258 int i = *pos;
259
260 return i <= NR_CPUS? (void *) (i + 1): NULL;
261}
262
263static void *c_next(struct seq_file *m, void *v, loff_t *pos)
264{
265 ++*pos;
266 return c_start(m, pos);
267}
268
269static void c_stop(struct seq_file *m, void *v)
270{
271}
272
273struct seq_operations cpuinfo_op = {
274 .start =c_start,
275 .next = c_next,
276 .stop = c_stop,
277 .show = show_cpuinfo,
278};
279
280/*
281 * We're called here very early in the boot. We determine the machine
282 * type and call the appropriate low-level setup functions.
283 * -- Cort <cort@fsmlabs.com>
284 *
285 * Note that the kernel may be running at an address which is different
286 * from the address that it was linked at, so we must use RELOC/PTRRELOC
287 * to access static data (including strings). -- paulus
288 */
289unsigned long __init early_init(unsigned long dt_ptr)
290{
291 unsigned long offset = reloc_offset();
292
dd184343
PM
293 /* First zero the BSS -- use memset_io, some platforms don't have
294 * caches on yet */
295 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
296
9b6b563c
PM
297 /*
298 * Identify the CPU type and fix up code sections
299 * that depend on which cpu we have.
300 */
301 identify_cpu(offset, 0);
302 do_cpu_ftr_fixups(offset);
303
9b6b563c
PM
304 return KERNELBASE + offset;
305}
306
307#ifdef CONFIG_PPC_OF
308/*
309 * Assume here that all clock rates are the same in a
310 * smp system. -- Cort
311 */
312int
313of_show_percpuinfo(struct seq_file *m, int i)
314{
315 struct device_node *cpu_node;
316 u32 *fp;
317 int s;
318
319 cpu_node = find_type_devices("cpu");
320 if (!cpu_node)
321 return 0;
322 for (s = 0; s < i && cpu_node->next; s++)
323 cpu_node = cpu_node->next;
324 fp = (u32 *)get_property(cpu_node, "clock-frequency", NULL);
325 if (fp)
326 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
327 return 0;
328}
329
330void __init
331intuit_machine_type(void)
332{
333 char *model;
334 struct device_node *root;
335
336 /* ask the OF info if we're a chrp or pmac */
337 root = find_path_device("/");
338 if (root != 0) {
339 /* assume pmac unless proven to be chrp -- Cort */
340 _machine = _MACH_Pmac;
341 model = get_property(root, "device_type", NULL);
342 if (model && !strncmp("chrp", model, 4))
343 _machine = _MACH_chrp;
344 else {
345 model = get_property(root, "model", NULL);
346 if (model && !strncmp(model, "IBM", 3))
347 _machine = _MACH_chrp;
348 }
349 }
350}
351#endif
352
353#ifdef CONFIG_PPC_MULTIPLATFORM
354/*
355 * The PPC_MULTIPLATFORM version of platform_init...
356 */
357void __init platform_init(void)
358{
359 /* if we didn't get any bootinfo telling us what we are... */
360 if (_machine == 0) {
361 /* prep boot loader tells us if we're prep or not */
362 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
363 _machine = _MACH_prep;
364 }
365
366#ifdef CONFIG_PPC_PREP
367 /* not much more to do here, if prep */
368 if (_machine == _MACH_prep) {
369 prep_init();
370 return;
371 }
372#endif
373
374#ifdef CONFIG_ADB
375 if (strstr(cmd_line, "adb_sync")) {
376 extern int __adb_probe_sync;
377 __adb_probe_sync = 1;
378 }
379#endif /* CONFIG_ADB */
380
381 switch (_machine) {
382#ifdef CONFIG_PPC_PMAC
383 case _MACH_Pmac:
384 pmac_init();
385 break;
386#endif
387#ifdef CONFIG_PPC_CHRP
388 case _MACH_chrp:
389 chrp_init();
390 break;
391#endif
392 }
393}
394
395#ifdef CONFIG_SERIAL_CORE_CONSOLE
396extern char *of_stdout_device;
397
398static int __init set_preferred_console(void)
399{
400 struct device_node *prom_stdout;
401 char *name;
402 int offset = 0;
403
404 if (of_stdout_device == NULL)
405 return -ENODEV;
406
407 /* The user has requested a console so this is already set up. */
408 if (strstr(saved_command_line, "console="))
409 return -EBUSY;
410
411 prom_stdout = find_path_device(of_stdout_device);
412 if (!prom_stdout)
413 return -ENODEV;
414
415 name = (char *)get_property(prom_stdout, "name", NULL);
416 if (!name)
417 return -ENODEV;
418
419 if (strcmp(name, "serial") == 0) {
420 int i;
421 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
422 if (i > 8) {
423 switch (reg[1]) {
424 case 0x3f8:
425 offset = 0;
426 break;
427 case 0x2f8:
428 offset = 1;
429 break;
430 case 0x898:
431 offset = 2;
432 break;
433 case 0x890:
434 offset = 3;
435 break;
436 default:
437 /* We dont recognise the serial port */
438 return -ENODEV;
439 }
440 }
441 } else if (strcmp(name, "ch-a") == 0)
442 offset = 0;
443 else if (strcmp(name, "ch-b") == 0)
444 offset = 1;
445 else
446 return -ENODEV;
447 return add_preferred_console("ttyS", offset, NULL);
448}
449console_initcall(set_preferred_console);
450#endif /* CONFIG_SERIAL_CORE_CONSOLE */
451#endif /* CONFIG_PPC_MULTIPLATFORM */
452
9b6b563c
PM
453/*
454 * Find out what kind of machine we're on and save any data we need
455 * from the early boot process (devtree is copied on pmac by prom_init()).
456 * This is called very early on the boot process, after a minimal
457 * MMU environment has been set up but before MMU_init is called.
458 */
459void __init machine_init(unsigned long dt_ptr, unsigned long phys)
460{
461 early_init_devtree(__va(dt_ptr));
462
463#ifdef CONFIG_CMDLINE
464 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
465#endif /* CONFIG_CMDLINE */
466
35499c01
PM
467 platform_init();
468
9b6b563c
PM
469#ifdef CONFIG_6xx
470 ppc_md.power_save = ppc6xx_idle;
471#endif
9b6b563c
PM
472
473 if (ppc_md.progress)
474 ppc_md.progress("id mach(): done", 0x200);
475}
476
477#ifdef CONFIG_BOOKE_WDT
478/* Checks wdt=x and wdt_period=xx command-line option */
479int __init early_parse_wdt(char *p)
480{
481 if (p && strncmp(p, "0", 1) != 0)
482 booke_wdt_enabled = 1;
483
484 return 0;
485}
486early_param("wdt", early_parse_wdt);
487
488int __init early_parse_wdt_period (char *p)
489{
490 if (p)
491 booke_wdt_period = simple_strtoul(p, NULL, 0);
492
493 return 0;
494}
495early_param("wdt_period", early_parse_wdt_period);
496#endif /* CONFIG_BOOKE_WDT */
497
498/* Checks "l2cr=xxxx" command-line option */
499int __init ppc_setup_l2cr(char *str)
500{
501 if (cpu_has_feature(CPU_FTR_L2CR)) {
502 unsigned long val = simple_strtoul(str, NULL, 0);
503 printk(KERN_INFO "l2cr set to %lx\n", val);
504 _set_L2CR(0); /* force invalidate by disable cache */
505 _set_L2CR(val); /* and enable it */
506 }
507 return 1;
508}
509__setup("l2cr=", ppc_setup_l2cr);
510
511#ifdef CONFIG_GENERIC_NVRAM
512
513/* Generic nvram hooks used by drivers/char/gen_nvram.c */
514unsigned char nvram_read_byte(int addr)
515{
516 if (ppc_md.nvram_read_val)
517 return ppc_md.nvram_read_val(addr);
518 return 0xff;
519}
520EXPORT_SYMBOL(nvram_read_byte);
521
522void nvram_write_byte(unsigned char val, int addr)
523{
524 if (ppc_md.nvram_write_val)
525 ppc_md.nvram_write_val(addr, val);
526}
527EXPORT_SYMBOL(nvram_write_byte);
528
529void nvram_sync(void)
530{
531 if (ppc_md.nvram_sync)
532 ppc_md.nvram_sync();
533}
534EXPORT_SYMBOL(nvram_sync);
535
536#endif /* CONFIG_NVRAM */
537
538static struct cpu cpu_devices[NR_CPUS];
539
540int __init ppc_init(void)
541{
542 int i;
543
544 /* clear the progress line */
545 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
546
547 /* register CPU devices */
548 for (i = 0; i < NR_CPUS; i++)
549 if (cpu_possible(i))
550 register_cpu(&cpu_devices[i], i, NULL);
551
552 /* call platform init */
553 if (ppc_md.init != NULL) {
554 ppc_md.init();
555 }
556 return 0;
557}
558
559arch_initcall(ppc_init);
560
561/* Warning, IO base is not yet inited */
562void __init setup_arch(char **cmdline_p)
563{
564 extern char *klimit;
565 extern void do_init_bootmem(void);
566
567 /* so udelay does something sensible, assume <= 1000 bogomips */
568 loops_per_jiffy = 500000000 / HZ;
569
9b6b563c
PM
570 unflatten_device_tree();
571 finish_device_tree();
572
30cd4a4e
PM
573#ifdef CONFIG_BOOTX_TEXT
574 init_boot_display();
575#endif
576
9b6b563c
PM
577#ifdef CONFIG_PPC_MULTIPLATFORM
578 /* This could be called "early setup arch", it must be done
579 * now because xmon need it
580 */
581 if (_machine == _MACH_Pmac)
582 pmac_feature_init(); /* New cool way */
583#endif
584
585#ifdef CONFIG_XMON
586 xmon_map_scc();
587 if (strstr(cmd_line, "xmon"))
588 xmon(NULL);
589#endif /* CONFIG_XMON */
590 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
591
592#if defined(CONFIG_KGDB)
593 if (ppc_md.kgdb_map_scc)
594 ppc_md.kgdb_map_scc();
595 set_debug_traps();
596 if (strstr(cmd_line, "gdb")) {
597 if (ppc_md.progress)
598 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
599 printk("kgdb breakpoint activated\n");
600 breakpoint();
601 }
602#endif
603
604 /*
605 * Set cache line size based on type of cpu as a default.
606 * Systems with OF can look in the properties on the cpu node(s)
607 * for a possibly more accurate value.
608 */
609 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
610 dcache_bsize = cur_cpu_spec->dcache_bsize;
611 icache_bsize = cur_cpu_spec->icache_bsize;
612 ucache_bsize = 0;
613 } else
614 ucache_bsize = dcache_bsize = icache_bsize
615 = cur_cpu_spec->dcache_bsize;
616
617 /* reboot on panic */
618 panic_timeout = 180;
619
620 init_mm.start_code = PAGE_OFFSET;
621 init_mm.end_code = (unsigned long) _etext;
622 init_mm.end_data = (unsigned long) _edata;
623 init_mm.brk = (unsigned long) klimit;
624
625 /* Save unparsed command line copy for /proc/cmdline */
626 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
627 *cmdline_p = cmd_line;
628
629 parse_early_param();
630
631 /* set up the bootmem stuff with available memory */
632 do_init_bootmem();
633 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
634
635#ifdef CONFIG_PPC_OCP
636 /* Initialize OCP device list */
637 ocp_early_init();
638 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
639#endif
640
641#ifdef CONFIG_DUMMY_CONSOLE
642 conswitchp = &dummy_con;
643#endif
644
645 ppc_md.setup_arch();
646 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
647
648 paging_init();
649
650 /* this is for modules since _machine can be a define -- Cort */
651 ppc_md.ppc_machine = _machine;
652}