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