Pull thermal into release branch
[deliverable/linux.git] / arch / ppc / kernel / setup.c
1 /*
2 * Common prep boot and setup code.
3 */
4
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>
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>
37 #include <asm/sections.h>
38 #include <asm/nvram.h>
39 #include <asm/xmon.h>
40 #include <asm/ocp.h>
41 #include <asm/prom.h>
42
43 #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
44 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
45 defined(CONFIG_PPC_MPC52xx))
46
47 #if USES_PPC_SYS
48 #include <asm/ppc_sys.h>
49 #endif
50
51 #if defined CONFIG_KGDB
52 #include <asm/kgdb.h>
53 #endif
54
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);
58
59 extern void ppc6xx_idle(void);
60 extern void power4_idle(void);
61
62 extern boot_infos_t *boot_infos;
63 struct 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. */
67 unsigned long boot_mem_size;
68
69 unsigned long ISA_DMA_THRESHOLD;
70 unsigned int DMA_MODE_READ;
71 unsigned int DMA_MODE_WRITE;
72
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);
76
77 dev_t boot_dev;
78 #endif /* CONFIG_PPC_PREP */
79
80 int have_of;
81 EXPORT_SYMBOL(have_of);
82
83 #ifdef __DO_IRQ_CANON
84 int ppc_do_canonicalize_irqs;
85 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
86 #endif
87
88 #ifdef CONFIG_VGA_CONSOLE
89 unsigned long vgacon_remap_base;
90 #endif
91
92 struct machdep_calls ppc_md;
93
94 /*
95 * These are used in binfmt_elf.c to put aux entries on the stack
96 * for each elf executable being started.
97 */
98 int dcache_bsize;
99 int icache_bsize;
100 int ucache_bsize;
101
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 */
106 0, /* unused */
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 */
114 };
115 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
116
117 void machine_restart(char *cmd)
118 {
119 #ifdef CONFIG_NVRAM
120 nvram_sync();
121 #endif
122 ppc_md.restart(cmd);
123 }
124
125 static void ppc_generic_power_off(void)
126 {
127 ppc_md.power_off();
128 }
129
130 void machine_halt(void)
131 {
132 #ifdef CONFIG_NVRAM
133 nvram_sync();
134 #endif
135 ppc_md.halt();
136 }
137
138 void (*pm_power_off)(void) = ppc_generic_power_off;
139
140 void machine_power_off(void)
141 {
142 #ifdef CONFIG_NVRAM
143 nvram_sync();
144 #endif
145 if (pm_power_off)
146 pm_power_off();
147 ppc_generic_power_off();
148 }
149
150 #ifdef CONFIG_TAU
151 extern u32 cpu_temp(unsigned long cpu);
152 extern u32 cpu_temp_both(unsigned long cpu);
153 #endif /* CONFIG_TAU */
154
155 int show_cpuinfo(struct seq_file *m, void *v)
156 {
157 int i = (int) v - 1;
158 int err = 0;
159 unsigned int pvr;
160 unsigned short maj, min;
161 unsigned long lpj;
162
163 if (i >= NR_CPUS) {
164 /* Show summary information */
165 #ifdef CONFIG_SMP
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 */
172
173 if (ppc_md.show_cpuinfo != NULL)
174 err = ppc_md.show_cpuinfo(m);
175 return err;
176 }
177
178 #ifdef CONFIG_SMP
179 if (!cpu_online(i))
180 return 0;
181 pvr = cpu_data[i].pvr;
182 lpj = cpu_data[i].loops_per_jiffy;
183 #else
184 pvr = mfspr(SPRN_PVR);
185 lpj = loops_per_jiffy;
186 #endif
187
188 seq_printf(m, "processor\t: %d\n", i);
189 seq_printf(m, "cpu\t\t: ");
190
191 if (cur_cpu_spec->pvr_mask)
192 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
193 else
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");
198 #endif
199 seq_printf(m, "\n");
200
201 #ifdef CONFIG_TAU
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",
206 cpu_temp(i));
207 #else
208 /* show the actual temp sensor range */
209 u32 temp;
210 temp = cpu_temp_both(i);
211 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
212 temp & 0xff, temp >> 16);
213 #endif
214 }
215 #endif /* CONFIG_TAU */
216
217 if (ppc_md.show_percpuinfo != NULL) {
218 err = ppc_md.show_percpuinfo(m, i);
219 if (err)
220 return err;
221 }
222
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) {
226 maj = PVR_MAJ(pvr);
227 min = PVR_MIN(pvr);
228 } else {
229 switch (PVR_VER(pvr)) {
230 case 0x0020: /* 403 family */
231 maj = PVR_MAJ(pvr) + 1;
232 min = PVR_MIN(pvr);
233 break;
234 case 0x1008: /* 740P/750P ?? */
235 maj = ((pvr >> 8) & 0xFF) - 1;
236 min = pvr & 0xFF;
237 break;
238 default:
239 maj = (pvr >> 8) & 0xFF;
240 min = pvr & 0xFF;
241 break;
242 }
243 }
244
245 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
246 maj, min, PVR_VER(pvr), PVR_REV(pvr));
247
248 seq_printf(m, "bogomips\t: %lu.%02lu\n",
249 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
250
251 #if USES_PPC_SYS
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);
255 #endif
256
257 #ifdef CONFIG_SMP
258 seq_printf(m, "\n");
259 #endif
260
261 return 0;
262 }
263
264 static void *c_start(struct seq_file *m, loff_t *pos)
265 {
266 int i = *pos;
267
268 return i <= NR_CPUS? (void *) (i + 1): NULL;
269 }
270
271 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
272 {
273 ++*pos;
274 return c_start(m, pos);
275 }
276
277 static void c_stop(struct seq_file *m, void *v)
278 {
279 }
280
281 struct seq_operations cpuinfo_op = {
282 .start =c_start,
283 .next = c_next,
284 .stop = c_stop,
285 .show = show_cpuinfo,
286 };
287
288 /*
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>
292 *
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
296 */
297 __init
298 unsigned long
299 early_init(int r3, int r4, int r5)
300 {
301 unsigned long phys;
302 unsigned long offset = reloc_offset();
303 struct cpu_spec *spec;
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 spec = identify_cpu(offset, mfspr(SPRN_PVR));
317 do_feature_fixups(spec->cpu_features,
318 PTRRELOC(&__start___ftr_fixup),
319 PTRRELOC(&__stop___ftr_fixup));
320
321 return phys;
322 }
323
324 #ifdef CONFIG_PPC_PREP
325 /*
326 * The PPC_PREP version of platform_init...
327 */
328 void __init
329 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
330 unsigned long r6, unsigned long r7)
331 {
332 #ifdef CONFIG_BOOTX_TEXT
333 if (boot_text_mapped) {
334 btext_clearscreen();
335 btext_welcome();
336 }
337 #endif
338
339 parse_bootinfo(find_bootinfo());
340
341 prep_init(r3, r4, r5, r6, r7);
342 }
343 #endif /* CONFIG_PPC_PREP */
344
345 struct bi_record *find_bootinfo(void)
346 {
347 struct bi_record *rec;
348
349 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
350 if ( rec->tag != BI_FIRST ) {
351 /*
352 * This 0x10000 offset is a terrible hack but it will go away when
353 * we have the bootloader handle all the relocation and
354 * prom calls -- Cort
355 */
356 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
357 if ( rec->tag != BI_FIRST )
358 return NULL;
359 }
360 return rec;
361 }
362
363 void parse_bootinfo(struct bi_record *rec)
364 {
365 if (rec == NULL || rec->tag != BI_FIRST)
366 return;
367 while (rec->tag != BI_LAST) {
368 ulong *data = rec->data;
369 switch (rec->tag) {
370 case BI_CMD_LINE:
371 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
372 break;
373 #ifdef CONFIG_BLK_DEV_INITRD
374 case BI_INITRD:
375 initrd_start = data[0] + KERNELBASE;
376 initrd_end = data[0] + data[1] + KERNELBASE;
377 break;
378 #endif /* CONFIG_BLK_DEV_INITRD */
379 case BI_MEMSIZE:
380 boot_mem_size = data[0];
381 break;
382 }
383 rec = (struct bi_record *)((ulong)rec + rec->size);
384 }
385 }
386
387 /*
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.
392 */
393 void __init
394 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
395 unsigned long r6, unsigned long r7)
396 {
397 #ifdef CONFIG_CMDLINE
398 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
399 #endif /* CONFIG_CMDLINE */
400
401 #ifdef CONFIG_6xx
402 ppc_md.power_save = ppc6xx_idle;
403 #endif
404
405 platform_init(r3, r4, r5, r6, r7);
406
407 if (ppc_md.progress)
408 ppc_md.progress("id mach(): done", 0x200);
409 }
410 #ifdef CONFIG_BOOKE_WDT
411 /* Checks wdt=x and wdt_period=xx command-line option */
412 int __init early_parse_wdt(char *p)
413 {
414 if (p && strncmp(p, "0", 1) != 0)
415 booke_wdt_enabled = 1;
416
417 return 0;
418 }
419 early_param("wdt", early_parse_wdt);
420
421 int __init early_parse_wdt_period (char *p)
422 {
423 if (p)
424 booke_wdt_period = simple_strtoul(p, NULL, 0);
425
426 return 0;
427 }
428 early_param("wdt_period", early_parse_wdt_period);
429 #endif /* CONFIG_BOOKE_WDT */
430
431 /* Checks "l2cr=xxxx" command-line option */
432 int __init ppc_setup_l2cr(char *str)
433 {
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 */
439 }
440 return 1;
441 }
442 __setup("l2cr=", ppc_setup_l2cr);
443
444 #ifdef CONFIG_GENERIC_NVRAM
445
446 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
447 unsigned char nvram_read_byte(int addr)
448 {
449 if (ppc_md.nvram_read_val)
450 return ppc_md.nvram_read_val(addr);
451 return 0xff;
452 }
453 EXPORT_SYMBOL(nvram_read_byte);
454
455 void nvram_write_byte(unsigned char val, int addr)
456 {
457 if (ppc_md.nvram_write_val)
458 ppc_md.nvram_write_val(addr, val);
459 }
460 EXPORT_SYMBOL(nvram_write_byte);
461
462 void nvram_sync(void)
463 {
464 if (ppc_md.nvram_sync)
465 ppc_md.nvram_sync();
466 }
467 EXPORT_SYMBOL(nvram_sync);
468
469 #endif /* CONFIG_NVRAM */
470
471 static struct cpu cpu_devices[NR_CPUS];
472
473 int __init ppc_init(void)
474 {
475 int i;
476
477 /* clear the progress line */
478 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
479
480 /* register CPU devices */
481 for_each_possible_cpu(i)
482 register_cpu(&cpu_devices[i], i);
483
484 /* call platform init */
485 if (ppc_md.init != NULL) {
486 ppc_md.init();
487 }
488 return 0;
489 }
490
491 arch_initcall(ppc_init);
492
493 /* Warning, IO base is not yet inited */
494 void __init setup_arch(char **cmdline_p)
495 {
496 extern char *klimit;
497 extern void do_init_bootmem(void);
498
499 /* so udelay does something sensible, assume <= 1000 bogomips */
500 loops_per_jiffy = 500000000 / HZ;
501
502 if (ppc_md.init_early)
503 ppc_md.init_early();
504
505 #ifdef CONFIG_XMON
506 xmon_init(1);
507 if (strstr(cmd_line, "xmon"))
508 xmon(NULL);
509 #endif /* CONFIG_XMON */
510 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
511
512 #if defined(CONFIG_KGDB)
513 if (ppc_md.kgdb_map_scc)
514 ppc_md.kgdb_map_scc();
515 set_debug_traps();
516 if (strstr(cmd_line, "gdb")) {
517 if (ppc_md.progress)
518 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
519 printk("kgdb breakpoint activated\n");
520 breakpoint();
521 }
522 #endif
523
524 /*
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.
528 */
529 if (! cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE)) {
530 dcache_bsize = cur_cpu_spec->dcache_bsize;
531 icache_bsize = cur_cpu_spec->icache_bsize;
532 ucache_bsize = 0;
533 } else
534 ucache_bsize = dcache_bsize = icache_bsize
535 = cur_cpu_spec->dcache_bsize;
536
537 /* reboot on panic */
538 panic_timeout = 180;
539
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;
544
545 /* Save unparsed command line copy for /proc/cmdline */
546 strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
547 *cmdline_p = cmd_line;
548
549 parse_early_param();
550
551 /* set up the bootmem stuff with available memory */
552 do_init_bootmem();
553 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
554
555 #ifdef CONFIG_PPC_OCP
556 /* Initialize OCP device list */
557 ocp_early_init();
558 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
559 #endif
560
561 #ifdef CONFIG_DUMMY_CONSOLE
562 conswitchp = &dummy_con;
563 #endif
564
565 ppc_md.setup_arch();
566 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
567
568 paging_init();
569 }
This page took 0.046159 seconds and 5 git commands to generate.