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