Merge branch 'linux-2.6'
[pandora-kernel.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/smp.h>
29 #include <asm/elf.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>
38 #include <asm/xmon.h>
39 #include <asm/ocp.h>
40
41 #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
42                       defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
43                       defined(CONFIG_PPC_MPC52xx))
44
45 #if USES_PPC_SYS
46 #include <asm/ppc_sys.h>
47 #endif
48
49 #if defined CONFIG_KGDB
50 #include <asm/kgdb.h>
51 #endif
52
53 extern void platform_init(unsigned long r3, unsigned long r4,
54                 unsigned long r5, unsigned long r6, unsigned long r7);
55 extern void reloc_got2(unsigned long offset);
56
57 extern void ppc6xx_idle(void);
58 extern void power4_idle(void);
59
60 extern boot_infos_t *boot_infos;
61 struct ide_machdep_calls ppc_ide_md;
62
63 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
64    size value reported by the boot loader. */
65 unsigned long boot_mem_size;
66
67 unsigned long ISA_DMA_THRESHOLD;
68 unsigned int DMA_MODE_READ;
69 unsigned int DMA_MODE_WRITE;
70
71 #ifdef CONFIG_PPC_PREP
72 extern void prep_init(unsigned long r3, unsigned long r4,
73                 unsigned long r5, unsigned long r6, unsigned long r7);
74
75 dev_t boot_dev;
76 #endif /* CONFIG_PPC_PREP */
77
78 int have_of;
79 EXPORT_SYMBOL(have_of);
80
81 #ifdef __DO_IRQ_CANON
82 int ppc_do_canonicalize_irqs;
83 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
84 #endif
85
86 #ifdef CONFIG_VGA_CONSOLE
87 unsigned long vgacon_remap_base;
88 #endif
89
90 struct machdep_calls ppc_md;
91
92 /*
93  * These are used in binfmt_elf.c to put aux entries on the stack
94  * for each elf executable being started.
95  */
96 int dcache_bsize;
97 int icache_bsize;
98 int ucache_bsize;
99
100 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
101     defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
102 struct screen_info screen_info = {
103         0, 25,                  /* orig-x, orig-y */
104         0,                      /* unused */
105         0,                      /* orig-video-page */
106         0,                      /* orig-video-mode */
107         80,                     /* orig-video-cols */
108         0,0,0,                  /* ega_ax, ega_bx, ega_cx */
109         25,                     /* orig-video-lines */
110         1,                      /* orig-video-isVGA */
111         16                      /* orig-video-points */
112 };
113 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
114
115 void machine_restart(char *cmd)
116 {
117 #ifdef CONFIG_NVRAM
118         nvram_sync();
119 #endif
120         ppc_md.restart(cmd);
121 }
122
123 static void ppc_generic_power_off(void)
124 {
125         ppc_md.power_off();
126 }
127
128 void machine_halt(void)
129 {
130 #ifdef CONFIG_NVRAM
131         nvram_sync();
132 #endif
133         ppc_md.halt();
134 }
135
136 void (*pm_power_off)(void) = ppc_generic_power_off;
137
138 void machine_power_off(void)
139 {
140 #ifdef CONFIG_NVRAM
141         nvram_sync();
142 #endif
143         if (pm_power_off)
144                 pm_power_off();
145         ppc_generic_power_off();
146 }
147
148 #ifdef CONFIG_TAU
149 extern u32 cpu_temp(unsigned long cpu);
150 extern u32 cpu_temp_both(unsigned long cpu);
151 #endif /* CONFIG_TAU */
152
153 int show_cpuinfo(struct seq_file *m, void *v)
154 {
155         int i = (int) v - 1;
156         int err = 0;
157         unsigned int pvr;
158         unsigned short maj, min;
159         unsigned long lpj;
160
161         if (i >= NR_CPUS) {
162                 /* Show summary information */
163 #ifdef CONFIG_SMP
164                 unsigned long bogosum = 0;
165                 for_each_online_cpu(i)
166                         bogosum += cpu_data[i].loops_per_jiffy;
167                 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
168                            bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
169 #endif /* CONFIG_SMP */
170
171                 if (ppc_md.show_cpuinfo != NULL)
172                         err = ppc_md.show_cpuinfo(m);
173                 return err;
174         }
175
176 #ifdef CONFIG_SMP
177         if (!cpu_online(i))
178                 return 0;
179         pvr = cpu_data[i].pvr;
180         lpj = cpu_data[i].loops_per_jiffy;
181 #else
182         pvr = mfspr(SPRN_PVR);
183         lpj = loops_per_jiffy;
184 #endif
185
186         seq_printf(m, "processor\t: %d\n", i);
187         seq_printf(m, "cpu\t\t: ");
188
189         if (cur_cpu_spec->pvr_mask)
190                 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
191         else
192                 seq_printf(m, "unknown (%08x)", pvr);
193 #ifdef CONFIG_ALTIVEC
194         if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
195                 seq_printf(m, ", altivec supported");
196 #endif
197         seq_printf(m, "\n");
198
199 #ifdef CONFIG_TAU
200         if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
201 #ifdef CONFIG_TAU_AVERAGE
202                 /* more straightforward, but potentially misleading */
203                 seq_printf(m,  "temperature \t: %u C (uncalibrated)\n",
204                            cpu_temp(i));
205 #else
206                 /* show the actual temp sensor range */
207                 u32 temp;
208                 temp = cpu_temp_both(i);
209                 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
210                            temp & 0xff, temp >> 16);
211 #endif
212         }
213 #endif /* CONFIG_TAU */
214
215         if (ppc_md.show_percpuinfo != NULL) {
216                 err = ppc_md.show_percpuinfo(m, i);
217                 if (err)
218                         return err;
219         }
220
221         /* If we are a Freescale core do a simple check so
222          * we dont have to keep adding cases in the future */
223         if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
224                 maj = PVR_MAJ(pvr);
225                 min = PVR_MIN(pvr);
226         } else {
227                 switch (PVR_VER(pvr)) {
228                         case 0x0020:    /* 403 family */
229                                 maj = PVR_MAJ(pvr) + 1;
230                                 min = PVR_MIN(pvr);
231                                 break;
232                         case 0x1008:    /* 740P/750P ?? */
233                                 maj = ((pvr >> 8) & 0xFF) - 1;
234                                 min = pvr & 0xFF;
235                                 break;
236                         default:
237                                 maj = (pvr >> 8) & 0xFF;
238                                 min = pvr & 0xFF;
239                                 break;
240                 }
241         }
242
243         seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
244                    maj, min, PVR_VER(pvr), PVR_REV(pvr));
245
246         seq_printf(m, "bogomips\t: %lu.%02lu\n",
247                    lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
248
249 #if USES_PPC_SYS
250         if (cur_ppc_sys_spec->ppc_sys_name)
251                 seq_printf(m, "chipset\t\t: %s\n",
252                         cur_ppc_sys_spec->ppc_sys_name);
253 #endif
254
255 #ifdef CONFIG_SMP
256         seq_printf(m, "\n");
257 #endif
258
259         return 0;
260 }
261
262 static void *c_start(struct seq_file *m, loff_t *pos)
263 {
264         int i = *pos;
265
266         return i <= NR_CPUS? (void *) (i + 1): NULL;
267 }
268
269 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
270 {
271         ++*pos;
272         return c_start(m, pos);
273 }
274
275 static void c_stop(struct seq_file *m, void *v)
276 {
277 }
278
279 struct seq_operations cpuinfo_op = {
280         .start =c_start,
281         .next = c_next,
282         .stop = c_stop,
283         .show = show_cpuinfo,
284 };
285
286 /*
287  * We're called here very early in the boot.  We determine the machine
288  * type and call the appropriate low-level setup functions.
289  *  -- Cort <cort@fsmlabs.com>
290  *
291  * Note that the kernel may be running at an address which is different
292  * from the address that it was linked at, so we must use RELOC/PTRRELOC
293  * to access static data (including strings).  -- paulus
294  */
295 __init
296 unsigned long
297 early_init(int r3, int r4, int r5)
298 {
299         unsigned long phys;
300         unsigned long offset = reloc_offset();
301         struct cpu_spec *spec;
302
303         /* Default */
304         phys = offset + KERNELBASE;
305
306         /* First zero the BSS -- use memset, some arches don't have
307          * caches on yet */
308         memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
309
310         /*
311          * Identify the CPU type and fix up code sections
312          * that depend on which cpu we have.
313          */
314 #if defined(CONFIG_440EP) && defined(CONFIG_PPC_FPU)
315         /* We pass the virtual PVR here for 440EP as 440EP and 440GR have
316          * identical PVRs and there is no reliable way to check for the FPU
317          */
318         spec = identify_cpu(offset, (mfspr(SPRN_PVR) | 0x8));
319 #else
320         spec = identify_cpu(offset, mfspr(SPRN_PVR));
321 #endif
322         do_feature_fixups(spec->cpu_features,
323                           PTRRELOC(&__start___ftr_fixup),
324                           PTRRELOC(&__stop___ftr_fixup));
325
326         return phys;
327 }
328
329 #ifdef CONFIG_PPC_PREP
330 /*
331  * The PPC_PREP version of platform_init...
332  */
333 void __init
334 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
335               unsigned long r6, unsigned long r7)
336 {
337 #ifdef CONFIG_BOOTX_TEXT
338         if (boot_text_mapped) {
339                 btext_clearscreen();
340                 btext_welcome();
341         }
342 #endif
343
344         parse_bootinfo(find_bootinfo());
345
346         prep_init(r3, r4, r5, r6, r7);
347 }
348 #endif /* CONFIG_PPC_PREP */
349
350 struct bi_record *find_bootinfo(void)
351 {
352         struct bi_record *rec;
353
354         rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
355         if ( rec->tag != BI_FIRST ) {
356                 /*
357                  * This 0x10000 offset is a terrible hack but it will go away when
358                  * we have the bootloader handle all the relocation and
359                  * prom calls -- Cort
360                  */
361                 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
362                 if ( rec->tag != BI_FIRST )
363                         return NULL;
364         }
365         return rec;
366 }
367
368 void parse_bootinfo(struct bi_record *rec)
369 {
370         if (rec == NULL || rec->tag != BI_FIRST)
371                 return;
372         while (rec->tag != BI_LAST) {
373                 ulong *data = rec->data;
374                 switch (rec->tag) {
375                 case BI_CMD_LINE:
376                         strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
377                         break;
378 #ifdef CONFIG_BLK_DEV_INITRD
379                 case BI_INITRD:
380                         initrd_start = data[0] + KERNELBASE;
381                         initrd_end = data[0] + data[1] + KERNELBASE;
382                         break;
383 #endif /* CONFIG_BLK_DEV_INITRD */
384                 case BI_MEMSIZE:
385                         boot_mem_size = data[0];
386                         break;
387                 }
388                 rec = (struct bi_record *)((ulong)rec + rec->size);
389         }
390 }
391
392 /*
393  * Find out what kind of machine we're on and save any data we need
394  * from the early boot process (devtree is copied on pmac by prom_init()).
395  * This is called very early on the boot process, after a minimal
396  * MMU environment has been set up but before MMU_init is called.
397  */
398 void __init
399 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
400              unsigned long r6, unsigned long r7)
401 {
402 #ifdef CONFIG_CMDLINE
403         strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
404 #endif /* CONFIG_CMDLINE */
405
406 #ifdef CONFIG_6xx
407         ppc_md.power_save = ppc6xx_idle;
408 #endif
409
410         platform_init(r3, r4, r5, r6, r7);
411
412         if (ppc_md.progress)
413                 ppc_md.progress("id mach(): done", 0x200);
414 }
415 #ifdef CONFIG_BOOKE_WDT
416 /* Checks wdt=x and wdt_period=xx command-line option */
417 int __init early_parse_wdt(char *p)
418 {
419         if (p && strncmp(p, "0", 1) != 0)
420                booke_wdt_enabled = 1;
421
422         return 0;
423 }
424 early_param("wdt", early_parse_wdt);
425
426 int __init early_parse_wdt_period (char *p)
427 {
428         if (p)
429                 booke_wdt_period = simple_strtoul(p, NULL, 0);
430
431         return 0;
432 }
433 early_param("wdt_period", early_parse_wdt_period);
434 #endif  /* CONFIG_BOOKE_WDT */
435
436 /* Checks "l2cr=xxxx" command-line option */
437 int __init ppc_setup_l2cr(char *str)
438 {
439         if (cpu_has_feature(CPU_FTR_L2CR)) {
440                 unsigned long val = simple_strtoul(str, NULL, 0);
441                 printk(KERN_INFO "l2cr set to %lx\n", val);
442                 _set_L2CR(0);           /* force invalidate by disable cache */
443                 _set_L2CR(val);         /* and enable it */
444         }
445         return 1;
446 }
447 __setup("l2cr=", ppc_setup_l2cr);
448
449 #ifdef CONFIG_GENERIC_NVRAM
450
451 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
452 unsigned char nvram_read_byte(int addr)
453 {
454         if (ppc_md.nvram_read_val)
455                 return ppc_md.nvram_read_val(addr);
456         return 0xff;
457 }
458 EXPORT_SYMBOL(nvram_read_byte);
459
460 void nvram_write_byte(unsigned char val, int addr)
461 {
462         if (ppc_md.nvram_write_val)
463                 ppc_md.nvram_write_val(addr, val);
464 }
465 EXPORT_SYMBOL(nvram_write_byte);
466
467 void nvram_sync(void)
468 {
469         if (ppc_md.nvram_sync)
470                 ppc_md.nvram_sync();
471 }
472 EXPORT_SYMBOL(nvram_sync);
473
474 #endif /* CONFIG_NVRAM */
475
476 static struct cpu cpu_devices[NR_CPUS];
477
478 int __init ppc_init(void)
479 {
480         int i;
481
482         /* clear the progress line */
483         if ( ppc_md.progress ) ppc_md.progress("             ", 0xffff);
484
485         /* register CPU devices */
486         for_each_possible_cpu(i)
487                 register_cpu(&cpu_devices[i], i);
488
489         /* call platform init */
490         if (ppc_md.init != NULL) {
491                 ppc_md.init();
492         }
493         return 0;
494 }
495
496 arch_initcall(ppc_init);
497
498 /* Warning, IO base is not yet inited */
499 void __init setup_arch(char **cmdline_p)
500 {
501         extern char *klimit;
502         extern void do_init_bootmem(void);
503
504         /* so udelay does something sensible, assume <= 1000 bogomips */
505         loops_per_jiffy = 500000000 / HZ;
506
507         if (ppc_md.init_early)
508                 ppc_md.init_early();
509
510 #ifdef CONFIG_XMON
511         xmon_init(1);
512         if (strstr(cmd_line, "xmon"))
513                 xmon(NULL);
514 #endif /* CONFIG_XMON */
515         if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
516
517 #if defined(CONFIG_KGDB)
518         if (ppc_md.kgdb_map_scc)
519                 ppc_md.kgdb_map_scc();
520         set_debug_traps();
521         if (strstr(cmd_line, "gdb")) {
522                 if (ppc_md.progress)
523                         ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
524                 printk("kgdb breakpoint activated\n");
525                 breakpoint();
526         }
527 #endif
528
529         /*
530          * Set cache line size based on type of cpu as a default.
531          * Systems with OF can look in the properties on the cpu node(s)
532          * for a possibly more accurate value.
533          */
534         if (! cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE)) {
535                 dcache_bsize = cur_cpu_spec->dcache_bsize;
536                 icache_bsize = cur_cpu_spec->icache_bsize;
537                 ucache_bsize = 0;
538         } else
539                 ucache_bsize = dcache_bsize = icache_bsize
540                         = cur_cpu_spec->dcache_bsize;
541
542         /* reboot on panic */
543         panic_timeout = 180;
544
545         init_mm.start_code = PAGE_OFFSET;
546         init_mm.end_code = (unsigned long) _etext;
547         init_mm.end_data = (unsigned long) _edata;
548         init_mm.brk = (unsigned long) klimit;
549
550         /* Save unparsed command line copy for /proc/cmdline */
551         strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
552         *cmdline_p = cmd_line;
553
554         parse_early_param();
555
556         /* set up the bootmem stuff with available memory */
557         do_init_bootmem();
558         if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
559
560 #ifdef CONFIG_PPC_OCP
561         /* Initialize OCP device list */
562         ocp_early_init();
563         if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
564 #endif
565
566 #ifdef CONFIG_DUMMY_CONSOLE
567         conswitchp = &dummy_con;
568 #endif
569
570         ppc_md.setup_arch();
571         if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
572
573         paging_init();
574 }