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