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