commented early_printk patch because of rejects.
[linux-flexiantxendom0-3.2.10.git] / arch / ppc / kernel / setup.c
1 /*
2  * Common prep/pmac/chrp boot and setup code.
3  */
4
5 #include <linux/config.h>
6 #include <linux/module.h>
7 #include <linux/string.h>
8 #include <linux/sched.h>
9 #include <linux/init.h>
10 #include <linux/reboot.h>
11 #include <linux/delay.h>
12 #include <linux/initrd.h>
13 #include <linux/ide.h>
14 #include <linux/tty.h>
15 #include <linux/bootmem.h>
16 #include <linux/seq_file.h>
17 #include <linux/root_dev.h>
18 #include <linux/cpu.h>
19
20 #include <asm/residual.h>
21 #include <asm/io.h>
22 #include <asm/prom.h>
23 #include <asm/processor.h>
24 #include <asm/pgtable.h>
25 #include <asm/bootinfo.h>
26 #include <asm/setup.h>
27 #include <asm/amigappc.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/pmac_feature.h>
37 #include <asm/sections.h>
38 #include <asm/xmon.h>
39
40 #if defined CONFIG_KGDB
41 #include <asm/kgdb.h>
42 #endif
43
44 extern void platform_init(unsigned long r3, unsigned long r4,
45                 unsigned long r5, unsigned long r6, unsigned long r7);
46 extern void bootx_init(unsigned long r4, unsigned long phys);
47 extern void identify_cpu(unsigned long offset, unsigned long cpu);
48 extern void do_cpu_ftr_fixups(unsigned long offset);
49 extern void reloc_got2(unsigned long offset);
50
51
52 #ifdef CONFIG_KGDB
53 extern void kgdb_map_scc(void);
54 #endif
55
56 extern void ppc6xx_idle(void);
57
58 extern boot_infos_t *boot_infos;
59 char saved_command_line[256];
60 unsigned char aux_device_present;
61 struct ide_machdep_calls ppc_ide_md;
62 char *sysmap;
63 unsigned long sysmap_size;
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 long DMA_MODE_READ, DMA_MODE_WRITE;
71
72 #ifdef CONFIG_PPC_MULTIPLATFORM
73 int _machine = 0;
74
75 extern void prep_init(unsigned long r3, unsigned long r4,
76                 unsigned long r5, unsigned long r6, unsigned long r7);
77 extern void pmac_init(unsigned long r3, unsigned long r4,
78                 unsigned long r5, unsigned long r6, unsigned long r7);
79 extern void chrp_init(unsigned long r3, unsigned long r4,
80                 unsigned long r5, unsigned long r6, unsigned long r7);
81 #endif /* CONFIG_PPC_MULTIPLATFORM */
82
83 #ifdef CONFIG_MAGIC_SYSRQ
84 unsigned long SYSRQ_KEY = 0x54;
85 #endif /* CONFIG_MAGIC_SYSRQ */
86
87 #ifdef CONFIG_VGA_CONSOLE
88 unsigned long vgacon_remap_base;
89 #endif
90
91 struct machdep_calls ppc_md;
92
93 /*
94  * These are used in binfmt_elf.c to put aux entries on the stack
95  * for each elf executable being started.
96  */
97 int dcache_bsize;
98 int icache_bsize;
99 int ucache_bsize;
100
101 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
102     defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
103 struct screen_info screen_info = {
104         0, 25,                  /* orig-x, orig-y */
105         0,                      /* unused */
106         0,                      /* orig-video-page */
107         0,                      /* orig-video-mode */
108         80,                     /* orig-video-cols */
109         0,0,0,                  /* ega_ax, ega_bx, ega_cx */
110         25,                     /* orig-video-lines */
111         1,                      /* orig-video-isVGA */
112         16                      /* orig-video-points */
113 };
114 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
115
116 void machine_restart(char *cmd)
117 {
118         ppc_md.restart(cmd);
119 }
120   
121 void machine_power_off(void)
122 {
123         ppc_md.power_off();
124 }
125   
126 void machine_halt(void)
127 {
128         ppc_md.halt();
129 }
130
131 void (*pm_power_off)(void) = machine_power_off;
132
133 #ifdef CONFIG_TAU
134 extern u32 cpu_temp(unsigned long cpu);
135 extern u32 cpu_temp_both(unsigned long cpu);
136 #endif /* CONFIG_TAU */
137
138 int show_cpuinfo(struct seq_file *m, void *v)
139 {
140         int i = (int) v - 1;
141         int err = 0;
142         unsigned int pvr;
143         unsigned short maj, min;
144         unsigned long lpj;
145
146         if (i >= NR_CPUS) {
147                 /* Show summary information */
148 #ifdef CONFIG_SMP
149                 unsigned long bogosum = 0;
150                 for (i = 0; i < NR_CPUS; ++i)
151                         if (cpu_online(i))
152                                 bogosum += cpu_data[i].loops_per_jiffy;
153                 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
154                            bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
155 #endif /* CONFIG_SMP */
156
157                 if (ppc_md.show_cpuinfo != NULL)
158                         err = ppc_md.show_cpuinfo(m);
159                 return err;
160         }
161
162 #ifdef CONFIG_SMP
163         if (!(cpu_online_map & (1 << i)))
164                 return 0;
165         pvr = cpu_data[i].pvr;
166         lpj = cpu_data[i].loops_per_jiffy;
167         seq_printf(m, "processor\t: %d\n", i);
168 #else
169         pvr = mfspr(PVR);
170         lpj = loops_per_jiffy;
171 #endif
172
173         seq_printf(m, "cpu\t\t: ");
174
175         if (cur_cpu_spec[i]->pvr_mask)
176                 seq_printf(m, "%s", cur_cpu_spec[i]->cpu_name);
177         else
178                 seq_printf(m, "unknown (%08x)", pvr);
179 #ifdef CONFIG_ALTIVEC
180         if (cur_cpu_spec[i]->cpu_features & CPU_FTR_ALTIVEC)
181                 seq_printf(m, ", altivec supported");
182 #endif
183         seq_printf(m, "\n");
184
185 #ifdef CONFIG_TAU
186         if (cur_cpu_spec[i]->cpu_features & CPU_FTR_TAU) {
187 #ifdef CONFIG_TAU_AVERAGE
188                 /* more straightforward, but potentially misleading */
189                 seq_printf(m,  "temperature \t: %u C (uncalibrated)\n",
190                            cpu_temp(i));
191 #else
192                 /* show the actual temp sensor range */
193                 u32 temp;
194                 temp = cpu_temp_both(i);
195                 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
196                            temp & 0xff, temp >> 16);
197 #endif
198         }
199 #endif /* CONFIG_TAU */
200
201         if (ppc_md.show_percpuinfo != NULL) {
202                 err = ppc_md.show_percpuinfo(m, i);
203                 if (err)
204                         return err;
205         }
206
207         switch (PVR_VER(pvr)) {
208         case 0x0020:    /* 403 family */
209                 maj = PVR_MAJ(pvr) + 1;
210                 min = PVR_MIN(pvr);
211                 break;
212         case 0x1008:    /* 740P/750P ?? */
213                 maj = ((pvr >> 8) & 0xFF) - 1;
214                 min = pvr & 0xFF;
215                 break;
216         default:
217                 maj = (pvr >> 8) & 0xFF;
218                 min = pvr & 0xFF;
219                 break;
220         }
221
222         seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n", 
223                    maj, min, PVR_VER(pvr), PVR_REV(pvr));
224
225         seq_printf(m, "bogomips\t: %lu.%02lu\n",
226                    lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
227
228 #ifdef CONFIG_SMP
229         seq_printf(m, "\n");
230 #endif
231
232         return 0;
233 }
234
235 static void *c_start(struct seq_file *m, loff_t *pos)
236 {
237         int i = *pos;
238
239         return i <= NR_CPUS? (void *) (i + 1): NULL;
240 }
241
242 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
243 {
244         ++*pos;
245         return c_start(m, pos);
246 }
247
248 static void c_stop(struct seq_file *m, void *v)
249 {
250 }
251
252 struct seq_operations cpuinfo_op = {
253         .start =c_start,
254         .next = c_next,
255         .stop = c_stop,
256         .show = show_cpuinfo,
257 };
258
259 /*
260  * We're called here very early in the boot.  We determine the machine
261  * type and call the appropriate low-level setup functions.
262  *  -- Cort <cort@fsmlabs.com>
263  *
264  * Note that the kernel may be running at an address which is different
265  * from the address that it was linked at, so we must use RELOC/PTRRELOC
266  * to access static data (including strings).  -- paulus
267  */
268 __init
269 unsigned long
270 early_init(int r3, int r4, int r5)
271 {
272         unsigned long phys;
273         unsigned long offset = reloc_offset();
274
275         /* Default */
276         phys = offset + KERNELBASE;
277
278         /* First zero the BSS -- use memset, some arches don't have
279          * caches on yet */
280         memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
281
282         /*
283          * Identify the CPU type and fix up code sections
284          * that depend on which cpu we have.
285          */
286         identify_cpu(offset, 0);
287         do_cpu_ftr_fixups(offset);
288
289 #if defined(CONFIG_PPC_MULTIPLATFORM)
290         reloc_got2(offset);
291
292         /* If we came here from BootX, clear the screen,
293          * set up some pointers and return. */
294         if ((r3 == 0x426f6f58) && (r5 == 0))
295                 bootx_init(r4, phys);
296
297         /*
298          * don't do anything on prep
299          * for now, don't use bootinfo because it breaks yaboot 0.5
300          * and assume that if we didn't find a magic number, we have OF
301          */
302         else if (*(unsigned long *)(0) != 0xdeadc0de)
303                 phys = prom_init(r3, r4, (prom_entry)r5);
304
305         reloc_got2(-offset);
306 #endif
307
308         return phys;
309 }
310
311 #ifdef CONFIG_PPC_OF
312 /*
313  * Assume here that all clock rates are the same in a
314  * smp system.  -- Cort
315  */
316 int __openfirmware
317 of_show_percpuinfo(struct seq_file *m, int i)
318 {
319         struct device_node *cpu_node;
320         int *fp, s;
321                         
322         cpu_node = find_type_devices("cpu");
323         if (!cpu_node)
324                 return 0;
325         for (s = 0; s < i && cpu_node->next; s++)
326                 cpu_node = cpu_node->next;
327         fp = (int *) get_property(cpu_node, "clock-frequency", NULL);
328         if (fp)
329                 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
330         return 0;
331 }
332
333 void __init
334 intuit_machine_type(void)
335 {
336         char *model;
337         struct device_node *root;
338                         
339         /* ask the OF info if we're a chrp or pmac */
340         root = find_path_device("/");
341         if (root != 0) {
342                 /* assume pmac unless proven to be chrp -- Cort */
343                 _machine = _MACH_Pmac;
344                 model = get_property(root, "device_type", NULL);
345                 if (model && !strncmp("chrp", model, 4))
346                         _machine = _MACH_chrp;
347                 else {
348                         model = get_property(root, "model", NULL);
349                         if (model && !strncmp(model, "IBM", 3))
350                                 _machine = _MACH_chrp;
351                 }
352         }
353 }
354 #endif
355
356 #ifdef CONFIG_PPC_MULTIPLATFORM
357 /*
358  * The PPC_MULTIPLATFORM version of platform_init...
359  */
360 void __init
361 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
362               unsigned long r6, unsigned long r7)
363 {
364 #ifdef CONFIG_BOOTX_TEXT
365         if (boot_text_mapped) {
366                 btext_clearscreen();
367                 btext_welcome();
368         }
369 #endif  
370
371         parse_bootinfo(find_bootinfo());
372
373         /* if we didn't get any bootinfo telling us what we are... */
374         if (_machine == 0) {
375                 /* prep boot loader tells us if we're prep or not */
376                 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
377                         _machine = _MACH_prep;
378         }
379
380         /* not much more to do here, if prep */
381         if (_machine == _MACH_prep) {
382                 prep_init(r3, r4, r5, r6, r7);
383                 return;
384         }
385
386         /* prom_init has already been called from __start */
387         if (boot_infos)
388                 relocate_nodes();
389
390         /* If we aren't PReP, we can find out if we're Pmac
391          * or CHRP with this. */
392         if (_machine == 0)
393                 intuit_machine_type();
394
395         /* finish_device_tree may need _machine defined. */
396         finish_device_tree();
397
398         /*
399          * If we were booted via quik, r3 points to the physical
400          * address of the command-line parameters.
401          * If we were booted from an xcoff image (i.e. netbooted or
402          * booted from floppy), we get the command line from the
403          * bootargs property of the /chosen node.
404          * If an initial ramdisk is present, r3 and r4
405          * are used for initrd_start and initrd_size,
406          * otherwise they contain 0xdeadbeef.  
407          */
408         cmd_line[0] = 0;
409         if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
410                 strlcpy(cmd_line, (char *)r3 + KERNELBASE,
411                         sizeof(cmd_line));
412         } else if (boot_infos != 0) {
413                 /* booted by BootX - check for ramdisk */
414                 if (boot_infos->kernelParamsOffset != 0)
415                         strlcpy(cmd_line, (char *) boot_infos
416                                 + boot_infos->kernelParamsOffset,
417                                 sizeof(cmd_line));
418 #ifdef CONFIG_BLK_DEV_INITRD
419                 if (boot_infos->ramDisk) {
420                         initrd_start = (unsigned long) boot_infos
421                                 + boot_infos->ramDisk;
422                         initrd_end = initrd_start + boot_infos->ramDiskSize;
423                         initrd_below_start_ok = 1;
424                 }
425 #endif
426         } else {
427                 struct device_node *chosen;
428                 char *p;
429                         
430 #ifdef CONFIG_BLK_DEV_INITRD
431                 if (r3 && r4 && r4 != 0xdeadbeef) {
432                         if (r3 < KERNELBASE)
433                                 r3 += KERNELBASE;
434                         initrd_start = r3;
435                         initrd_end = r3 + r4;
436                         ROOT_DEV = Root_RAM0;
437                         initrd_below_start_ok = 1;
438                 }
439 #endif
440                 chosen = find_devices("chosen");
441                 if (chosen != NULL) {
442                         p = get_property(chosen, "bootargs", NULL);
443                         if (p && *p) {
444                                 strlcpy(cmd_line, p, sizeof(cmd_line));
445                         }
446                 }
447         }
448 #ifdef CONFIG_ADB
449         if (strstr(cmd_line, "adb_sync")) {
450                 extern int __adb_probe_sync;
451                 __adb_probe_sync = 1;
452         }
453 #endif /* CONFIG_ADB */ 
454
455         switch (_machine) {
456         case _MACH_Pmac:
457                 pmac_init(r3, r4, r5, r6, r7);
458                 break;
459         case _MACH_chrp:
460                 chrp_init(r3, r4, r5, r6, r7);
461                 break;
462         }
463 }
464 #endif /* CONFIG_PPC_MULTIPLATFORM */
465
466 struct bi_record *find_bootinfo(void)
467 {
468         struct bi_record *rec;
469
470         rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
471         if ( rec->tag != BI_FIRST ) {
472                 /*
473                  * This 0x10000 offset is a terrible hack but it will go away when
474                  * we have the bootloader handle all the relocation and
475                  * prom calls -- Cort
476                  */
477                 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
478                 if ( rec->tag != BI_FIRST )
479                         return NULL;
480         }
481         return rec;
482 }
483
484 void parse_bootinfo(struct bi_record *rec)
485 {
486         if (rec == NULL || rec->tag != BI_FIRST)
487                 return;
488         while (rec->tag != BI_LAST) {
489                 ulong *data = rec->data;
490                 switch (rec->tag) {
491                 case BI_CMD_LINE:
492                         memcpy(cmd_line, (void *)data, rec->size);
493                         break;
494                 case BI_SYSMAP:
495                         sysmap = (char *)((data[0] >= (KERNELBASE)) ? data[0] :
496                                           (data[0]+KERNELBASE));
497                         sysmap_size = data[1];
498                         break;
499 #ifdef CONFIG_BLK_DEV_INITRD
500                 case BI_INITRD:
501                         initrd_start = data[0] + KERNELBASE;
502                         initrd_end = data[0] + data[1] + KERNELBASE;
503                         break;
504 #endif /* CONFIG_BLK_DEV_INITRD */
505 #ifdef CONFIG_PPC_MULTIPLATFORM
506                 case BI_MACHTYPE:
507                         _machine = data[0];
508                         break;
509 #endif
510                 case BI_MEMSIZE:
511                         boot_mem_size = data[0];
512                         break;
513                 }
514                 rec = (struct bi_record *)((ulong)rec + rec->size);
515         }
516 }
517
518 /*
519  * Find out what kind of machine we're on and save any data we need
520  * from the early boot process (devtree is copied on pmac by prom_init()).
521  * This is called very early on the boot process, after a minimal
522  * MMU environment has been set up but before MMU_init is called.
523  */
524 void __init
525 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
526              unsigned long r6, unsigned long r7)
527 {
528 #ifdef CONFIG_CMDLINE
529         strcpy(cmd_line, CONFIG_CMDLINE);
530 #endif /* CONFIG_CMDLINE */
531
532 #if defined(CONFIG_6xx)
533         ppc_md.power_save = ppc6xx_idle;
534 #endif
535
536         platform_init(r3, r4, r5, r6, r7);
537
538         if (ppc_md.progress)
539                 ppc_md.progress("id mach(): done", 0x200);
540 }
541
542 /* Checks "l2cr=xxxx" command-line option */
543 int __init ppc_setup_l2cr(char *str)
544 {
545         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR) {
546                 unsigned long val = simple_strtoul(str, NULL, 0);
547                 printk(KERN_INFO "l2cr set to %lx\n", val);
548                 _set_L2CR(0);           /* force invalidate by disable cache */
549                 _set_L2CR(val);         /* and enable it */
550         }
551         return 1;
552 }
553 __setup("l2cr=", ppc_setup_l2cr);
554
555 #ifdef CONFIG_NVRAM
556 /* Generic nvram hooks we now look into ppc_md.nvram_read_val
557  * on pmac too ;)
558  * //XX Those 2 could be moved to headers
559  */
560 unsigned char
561 nvram_read_byte(int addr)
562 {
563         if (ppc_md.nvram_read_val)
564                 return ppc_md.nvram_read_val(addr);
565         return 0xff;
566 }
567
568 void
569 nvram_write_byte(unsigned char val, int addr)
570 {
571         if (ppc_md.nvram_write_val)
572                 ppc_md.nvram_write_val(val, addr);
573 }
574 #endif /* CONFIG_NVRAM */
575
576 static struct cpu cpu_devices[NR_CPUS];
577
578 int __init ppc_init(void)
579 {
580         int i;
581         
582         /* clear the progress line */
583         if ( ppc_md.progress ) ppc_md.progress("             ", 0xffff);
584
585         /* register CPU devices */
586         for (i = 0; i < NR_CPUS; i++)
587                 if (cpu_possible(i))
588                         register_cpu(&cpu_devices[i], i, NULL);
589
590         /* call platform init */
591         if (ppc_md.init != NULL) {
592                 ppc_md.init();
593         }
594         return 0;
595 }
596
597 arch_initcall(ppc_init);
598
599 /* Warning, IO base is not yet inited */
600 void __init setup_arch(char **cmdline_p)
601 {
602         extern int panic_timeout;
603         extern char *klimit;
604         extern void do_init_bootmem(void);
605
606         /* so udelay does something sensible, assume <= 1000 bogomips */
607         loops_per_jiffy = 500000000 / HZ;
608
609 #ifdef CONFIG_PPC_MULTIPLATFORM
610         /* This could be called "early setup arch", it must be done
611          * now because xmon need it
612          */
613         if (_machine == _MACH_Pmac)
614                 pmac_feature_init();    /* New cool way */
615 #endif
616
617 #ifdef CONFIG_XMON
618         xmon_map_scc();
619         if (strstr(cmd_line, "xmon"))
620                 xmon(0);
621 #endif /* CONFIG_XMON */
622         if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
623
624 #if defined(CONFIG_KGDB)
625         kgdb_map_scc();
626         set_debug_traps();
627         if (strstr(cmd_line, "nokgdb"))
628                 printk("kgdb default breakpoint deactivated on command line\n");
629         else {
630                 if (ppc_md.progress)
631                         ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
632                 printk("kgdb default breakpoint activated\n");
633                 breakpoint();
634         }
635 #endif
636
637         /*
638          * Set cache line size based on type of cpu as a default.
639          * Systems with OF can look in the properties on the cpu node(s)
640          * for a possibly more accurate value.
641          */
642         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_SPLIT_ID_CACHE) {
643                 dcache_bsize = cur_cpu_spec[0]->dcache_bsize;
644                 icache_bsize = cur_cpu_spec[0]->icache_bsize;
645                 ucache_bsize = 0;
646         } else
647                 ucache_bsize = dcache_bsize = icache_bsize
648                         = cur_cpu_spec[0]->dcache_bsize;
649
650         /* reboot on panic */
651         panic_timeout = 180;
652
653         init_mm.start_code = PAGE_OFFSET;
654         init_mm.end_code = (unsigned long) _etext;
655         init_mm.end_data = (unsigned long) _edata;
656         init_mm.brk = (unsigned long) klimit;
657         
658         /* Save unparsed command line copy for /proc/cmdline */
659         strcpy(saved_command_line, cmd_line);
660         *cmdline_p = cmd_line;
661
662         /* set up the bootmem stuff with available memory */
663         do_init_bootmem();
664         if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
665
666         ppc_md.setup_arch();
667         if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
668
669         paging_init();
670         sort_exception_table();
671
672         /* this is for modules since _machine can be a define -- Cort */
673         ppc_md.ppc_machine = _machine;
674 }