make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / arch / ppc / kernel / setup.c
1 /*
2  * BK Id: SCCS/s.setup.c 1.116 01/28/03 09:17:05 porter
3  */
4 /*
5  * Common prep/pmac/chrp boot and setup code.
6  */
7
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/string.h>
11 #include <linux/sched.h>
12 #include <linux/init.h>
13 #include <linux/reboot.h>
14 #include <linux/delay.h>
15 #include <linux/blk.h>
16 #include <linux/ide.h>
17 #include <linux/tty.h>
18 #include <linux/bootmem.h>
19 #include <linux/seq_file.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/pmac_feature.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 #ifdef CONFIG_XMON
51 extern void xmon_map_scc(void);
52 #endif
53
54 #ifdef CONFIG_KGDB
55 extern void kgdb_map_scc(void);
56 #endif
57
58 extern boot_infos_t *boot_infos;
59 char saved_command_line[512];
60 extern char cmd_line[512];
61 unsigned char aux_device_present;
62 struct ide_machdep_calls ppc_ide_md;
63 char *sysmap;
64 unsigned long sysmap_size;
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 long DMA_MODE_READ, DMA_MODE_WRITE;
72
73 #ifdef CONFIG_ALL_PPC
74 int _machine = 0;
75
76 extern void prep_init(unsigned long r3, unsigned long r4,
77                 unsigned long r5, unsigned long r6, unsigned long r7);
78 extern void pmac_init(unsigned long r3, unsigned long r4,
79                 unsigned long r5, unsigned long r6, unsigned long r7);
80 extern void chrp_init(unsigned long r3, unsigned long r4,
81                 unsigned long r5, unsigned long r6, unsigned long r7);
82 #endif /* CONFIG_ALL_PPC */
83
84 #ifdef CONFIG_MAGIC_SYSRQ
85 unsigned long SYSRQ_KEY;
86 #endif /* CONFIG_MAGIC_SYSRQ */
87
88 #ifdef CONFIG_VGA_CONSOLE
89 unsigned long vgacon_remap_base;
90 #endif
91
92 struct machdep_calls ppc_md;
93
94 /*
95  * These are used in binfmt_elf.c to put aux entries on the stack
96  * for each elf executable being started.
97  */
98 int dcache_bsize;
99 int icache_bsize;
100 int ucache_bsize;
101
102 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
103     defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
104 struct screen_info screen_info = {
105         0, 25,                  /* orig-x, orig-y */
106         0,                      /* unused */
107         0,                      /* orig-video-page */
108         0,                      /* orig-video-mode */
109         80,                     /* orig-video-cols */
110         0,0,0,                  /* ega_ax, ega_bx, ega_cx */
111         25,                     /* orig-video-lines */
112         1,                      /* orig-video-isVGA */
113         16                      /* orig-video-points */
114 };
115 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
116
117 void machine_restart(char *cmd)
118 {
119         ppc_md.restart(cmd);
120 }
121   
122 void machine_power_off(void)
123 {
124         ppc_md.power_off();
125 }
126   
127 void machine_halt(void)
128 {
129         ppc_md.halt();
130 }
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 < smp_num_cpus; ++i)
150                         if (cpu_online_map & (1 << 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: %lu\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
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         extern char __bss_start, _end;
273         unsigned long phys;
274         unsigned long offset = reloc_offset();
275
276         /* Default */
277         phys = offset + KERNELBASE;
278
279         /* First zero the BSS -- use memset, some arches don't have
280          * caches on yet */
281         memset_io(PTRRELOC(&__bss_start), 0, &_end - &__bss_start);
282
283         /*
284          * Identify the CPU type and fix up code sections
285          * that depend on which cpu we have.
286          */
287         identify_cpu(offset, 0);
288         do_cpu_ftr_fixups(offset);
289
290 #if defined(CONFIG_ALL_PPC)
291         reloc_got2(offset);
292
293         /* If we came here from BootX, clear the screen,
294          * set up some pointers and return. */
295         if ((r3 == 0x426f6f58) && (r5 == 0))
296                 bootx_init(r4, phys);
297
298         /*
299          * don't do anything on prep
300          * for now, don't use bootinfo because it breaks yaboot 0.5
301          * and assume that if we didn't find a magic number, we have OF
302          */
303         else if (*(unsigned long *)(0) != 0xdeadc0de)
304                 phys = prom_init(r3, r4, (prom_entry)r5);
305
306         reloc_got2(-offset);
307 #endif
308
309         return phys;
310 }
311
312 #ifdef CONFIG_ALL_PPC
313 void __init
314 intuit_machine_type(void)
315 {
316         char *model;
317         struct device_node *root;
318                         
319         /* ask the OF info if we're a chrp or pmac */
320         root = find_path_device("/");
321         if (root != 0) {
322                 /* assume pmac unless proven to be chrp -- Cort */
323                 _machine = _MACH_Pmac;
324                 model = get_property(root, "device_type", NULL);
325                 if (model && !strncmp("chrp", model, 4))
326                         _machine = _MACH_chrp;
327                 else {
328                         model = get_property(root, "model", NULL);
329                         if (model && !strncmp(model, "IBM", 3))
330                                 _machine = _MACH_chrp;
331                 }
332         }
333 }
334
335 /*
336  * The ALL_PPC version of platform_init...
337  */
338 void __init
339 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
340               unsigned long r6, unsigned long r7)
341 {
342 #ifdef CONFIG_BOOTX_TEXT
343         if (boot_text_mapped) {
344                 btext_clearscreen();
345                 btext_welcome();
346         }
347 #endif  
348
349         parse_bootinfo(find_bootinfo());
350
351         /* if we didn't get any bootinfo telling us what we are... */
352         if (_machine == 0) {
353                 /* prep boot loader tells us if we're prep or not */
354                 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
355                         _machine = _MACH_prep;
356         }
357
358         /* not much more to do here, if prep */
359         if (_machine == _MACH_prep) {
360                 prep_init(r3, r4, r5, r6, r7);
361                 return;
362         }
363
364         /* prom_init has already been called from __start */
365         if (boot_infos)
366                 relocate_nodes();
367
368         /* If we aren't PReP, we can find out if we're Pmac
369          * or CHRP with this. */
370         if (_machine == 0)
371                 intuit_machine_type();
372
373         /* finish_device_tree may need _machine defined. */
374         finish_device_tree();
375
376         /*
377          * If we were booted via quik, r3 points to the physical
378          * address of the command-line parameters.
379          * If we were booted from an xcoff image (i.e. netbooted or
380          * booted from floppy), we get the command line from the
381          * bootargs property of the /chosen node.
382          * If an initial ramdisk is present, r3 and r4
383          * are used for initrd_start and initrd_size,
384          * otherwise they contain 0xdeadbeef.  
385          */
386         if (r3 >= 0x4000 && r3 < 0x800000 && r4 == 0) {
387                 cmd_line[0] = 0;
388                 strncpy(cmd_line, (char *)r3 + KERNELBASE,
389                         sizeof(cmd_line));
390         } else if (boot_infos != 0) {
391                 /* booted by BootX - check for ramdisk */
392                 if (boot_infos->kernelParamsOffset != 0)
393                         strncpy(cmd_line, (char *) boot_infos
394                                 + boot_infos->kernelParamsOffset,
395                                 sizeof(cmd_line));
396 #ifdef CONFIG_BLK_DEV_INITRD
397                 if (boot_infos->ramDisk) {
398                         initrd_start = (unsigned long) boot_infos
399                                 + boot_infos->ramDisk;
400                         initrd_end = initrd_start + boot_infos->ramDiskSize;
401                         initrd_below_start_ok = 1;
402                 }
403 #endif
404         } else {
405                 struct device_node *chosen;
406                 char *p;
407                         
408 #ifdef CONFIG_BLK_DEV_INITRD
409                 if (r3 && r4 && r4 != 0xdeadbeef) {
410                         if (r3 < KERNELBASE)
411                                 r3 += KERNELBASE;
412                         initrd_start = r3;
413                         initrd_end = r3 + r4;
414                         ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
415                         initrd_below_start_ok = 1;
416                 }
417 #endif
418                 chosen = find_devices("chosen");
419                 if (chosen != NULL) {
420                         p = get_property(chosen, "bootargs", NULL);
421                         if (p && *p) {
422                                 cmd_line[0] = 0;
423                                 strncpy(cmd_line, p, sizeof(cmd_line));
424                         }
425                 }
426         }
427         cmd_line[sizeof(cmd_line) - 1] = 0;
428 #ifdef CONFIG_ADB
429         if (strstr(cmd_line, "adb_sync")) {
430                 extern int __adb_probe_sync;
431                 __adb_probe_sync = 1;
432         }
433 #endif /* CONFIG_ADB */ 
434
435         switch (_machine) {
436         case _MACH_Pmac:
437                 pmac_init(r3, r4, r5, r6, r7);
438                 break;
439         case _MACH_chrp:
440                 chrp_init(r3, r4, r5, r6, r7);
441                 break;
442         }
443 }
444 #endif /* CONFIG_ALL_PPC */
445
446 #ifndef CONFIG_APUS
447 struct bi_record *find_bootinfo(void)
448 {
449         struct bi_record *rec;
450         extern char __bss_start[];
451
452         rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
453         if ( rec->tag != BI_FIRST ) {
454                 /*
455                  * This 0x10000 offset is a terrible hack but it will go away when
456                  * we have the bootloader handle all the relocation and
457                  * prom calls -- Cort
458                  */
459                 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
460                 if ( rec->tag != BI_FIRST )
461                         return NULL;
462         }
463         return rec;
464 }
465
466 void parse_bootinfo(struct bi_record *rec)
467 {
468         if (rec == NULL || rec->tag != BI_FIRST)
469                 return;
470         while (rec->tag != BI_LAST) {
471                 ulong *data = rec->data;
472                 switch (rec->tag) {
473                 case BI_CMD_LINE:
474                         memcpy(cmd_line, (void *)data, rec->size - 
475                                         sizeof(struct bi_record));
476                         break;
477                 case BI_SYSMAP:
478                         sysmap = (char *)((data[0] >= (KERNELBASE)) ? data[0] :
479                                           (data[0]+KERNELBASE));
480                         sysmap_size = data[1];
481                         break;
482 #ifdef CONFIG_BLK_DEV_INITRD
483                 case BI_INITRD:
484                         initrd_start = data[0] + KERNELBASE;
485                         initrd_end = data[0] + data[1] + KERNELBASE;
486                         break;
487 #endif /* CONFIG_BLK_DEV_INITRD */
488 #ifdef CONFIG_ALL_PPC
489                 case BI_MACHTYPE:
490                         _machine = data[0];
491                         break;
492 #endif /* CONFIG_ALL_PPC */
493                 case BI_MEMSIZE:
494                         boot_mem_size = data[0];
495                         break;
496                 }
497                 rec = (struct bi_record *)((ulong)rec + rec->size);
498         }
499 }
500 #endif /* CONFIG_APUS */
501
502 /*
503  * Find out what kind of machine we're on and save any data we need
504  * from the early boot process (devtree is copied on pmac by prom_init()).
505  * This is called very early on the boot process, after a minimal
506  * MMU environment has been set up but before MMU_init is called.
507  */
508 void __init
509 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
510              unsigned long r6, unsigned long r7)
511 {
512 #ifdef CONFIG_CMDLINE
513         strcpy(cmd_line, CONFIG_CMDLINE);
514 #endif /* CONFIG_CMDLINE */
515
516         platform_init(r3, r4, r5, r6, r7);
517
518         if (ppc_md.progress)
519                 ppc_md.progress("id mach(): done", 0x200);
520 }
521
522 /* Checks "l2cr=xxxx" command-line option */
523 int __init ppc_setup_l2cr(char *str)
524 {
525         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR) {
526                 unsigned long val = simple_strtoul(str, NULL, 0);
527                 printk(KERN_INFO "l2cr set to %lx\n", val);
528                 _set_L2CR(0);           /* force invalidate by disable cache */
529                 _set_L2CR(val);         /* and enable it */
530         }
531         return 1;
532 }
533 __setup("l2cr=", ppc_setup_l2cr);
534
535 void __init arch_discover_root(void)
536 {
537         if (ppc_md.discover_root != NULL)
538                 ppc_md.discover_root();
539 }
540
541 void __init ppc_init(void)
542 {
543         /* clear the progress line */
544         if ( ppc_md.progress ) ppc_md.progress("             ", 0xffff);
545         
546         if (ppc_md.init != NULL) {
547                 ppc_md.init();
548         }
549 }
550
551 /* Warning, IO base is not yet inited */
552 void __init setup_arch(char **cmdline_p)
553 {
554         extern int panic_timeout;
555         extern char _etext[], _edata[];
556         extern char *klimit;
557         extern void do_init_bootmem(void);
558
559         /* so udelay does something sensible, assume <= 1000 bogomips */
560         loops_per_jiffy = 500000000 / HZ;
561 #ifdef CONFIG_ALL_PPC
562         /* This could be called "early setup arch", it must be done
563          * now because xmon need it
564          */
565         if (_machine == _MACH_Pmac)
566                 pmac_feature_init();    /* New cool way */
567 #endif /* CONFIG_ALL_PPC */
568
569 #ifdef CONFIG_XMON
570         xmon_map_scc();
571         if (strstr(cmd_line, "xmon"))
572                 xmon(0);
573 #endif /* CONFIG_XMON */
574         if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
575
576 #if defined(CONFIG_KGDB)
577         kgdb_map_scc();
578         set_debug_traps();
579         if (strstr(cmd_line, "nokgdb"))
580                 printk("kgdb default breakpoint deactivated on command line\n");
581         else {
582                 if (ppc_md.progress) ppc_md.progress("setup_arch: kgdb bp", 0x4000);
583                 printk("kgdb default breakpoint activated\n");
584                 breakpoint();
585         }
586 #endif
587
588         /*
589          * Set cache line size based on type of cpu as a default.
590          * Systems with OF can look in the properties on the cpu node(s)
591          * for a possibly more accurate value.
592          */
593         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_SPLIT_ID_CACHE) {
594                 dcache_bsize = cur_cpu_spec[0]->dcache_bsize;
595                 icache_bsize = cur_cpu_spec[0]->icache_bsize;
596                 ucache_bsize = 0;
597         } else
598                 ucache_bsize = dcache_bsize = icache_bsize
599                         = cur_cpu_spec[0]->dcache_bsize;
600
601         /* reboot on panic */
602         panic_timeout = 180;
603
604         init_mm.start_code = PAGE_OFFSET;
605         init_mm.end_code = (unsigned long) _etext;
606         init_mm.end_data = (unsigned long) _edata;
607         init_mm.brk = (unsigned long) klimit;
608         
609         /* Save unparsed command line copy for /proc/cmdline */
610 /*
611         strcpy(saved_command_line, cmd_line);
612         *cmdline_p = cmd_line;
613 */
614         strcpy(saved_command_line, CONFIG_CMDLINE);
615         *cmdline_p = CONFIG_CMDLINE;
616
617         /* set up the bootmem stuff with available memory */
618         do_init_bootmem();
619         if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
620
621         ppc_md.setup_arch();
622         if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
623
624         paging_init();
625         sort_exception_table();
626
627         /* this is for modules since _machine can be a define -- Cort */
628         ppc_md.ppc_machine = _machine;
629 }