more changes on original files
[linux-2.4.git] / arch / m68k / kernel / setup.c
1 /*
2  *  linux/arch/m68k/kernel/setup.c
3  *
4  *  Copyright (C) 1995  Hamish Macdonald
5  */
6
7 /*
8  * This file handles the architecture-dependent parts of system setup
9  */
10
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/mm.h>
14 #include <linux/sched.h>
15 #include <linux/delay.h>
16 #include <linux/interrupt.h>
17 #include <linux/fs.h>
18 #include <linux/console.h>
19 #include <linux/genhd.h>
20 #include <linux/errno.h>
21 #include <linux/string.h>
22 #include <linux/init.h>
23 #include <linux/bootmem.h>
24 #include <linux/seq_file.h>
25 #include <linux/module.h>
26
27 #include <asm/bootinfo.h>
28 #include <asm/setup.h>
29 #include <asm/irq.h>
30 #include <asm/io.h>
31 #include <asm/machdep.h>
32 #ifdef CONFIG_AMIGA
33 #include <asm/amigahw.h>
34 #endif
35 #ifdef CONFIG_ATARI
36 #include <asm/atarihw.h>
37 #include <asm/atari_stram.h>
38 #endif
39 #ifdef CONFIG_SUN3X
40 #include <asm/dvma.h>
41 extern void sun_serial_setup(void);
42 #endif
43
44 #ifdef CONFIG_BLK_DEV_INITRD
45 #include <linux/blk.h>
46 #endif
47
48 unsigned long m68k_machtype;
49 unsigned long m68k_cputype;
50 unsigned long m68k_fputype;
51 unsigned long m68k_mmutype;
52 #ifdef CONFIG_VME
53 unsigned long vme_brdtype;
54 #endif
55
56 int m68k_is040or060 = 0;
57
58 extern int end;
59 extern unsigned long availmem;
60
61 int m68k_num_memory = 0;
62 int m68k_realnum_memory = 0;
63 unsigned long m68k_memoffset;
64 struct mem_info m68k_memory[NUM_MEMINFO];
65
66 static struct mem_info m68k_ramdisk = { 0, 0 };
67
68 static char m68k_command_line[CL_SIZE];
69 char saved_command_line[CL_SIZE];
70
71 char m68k_debug_device[6] = "";
72
73 void (*mach_sched_init) (void (*handler)(int, void *, struct pt_regs *)) __initdata = NULL;
74 /* machine dependent keyboard functions */
75 #ifdef CONFIG_VT
76 int (*mach_keyb_init) (void) __initdata = NULL;
77 int (*mach_kbdrate) (struct kbd_repeat *) = NULL;
78 void (*mach_kbd_leds) (unsigned int) = NULL;
79 int (*mach_kbd_translate)(unsigned char scancode, unsigned char *keycode, char raw_mode) = NULL;
80 #endif
81 /* machine dependent irq functions */
82 void (*mach_init_IRQ) (void) __initdata = NULL;
83 void (*(*mach_default_handler)[]) (int, void *, struct pt_regs *) = NULL;
84 void (*mach_get_model) (char *model) = NULL;
85 int (*mach_get_hardware_list) (char *buffer) = NULL;
86 int (*mach_get_irq_list) (char *) = NULL;
87 void (*mach_process_int) (int, struct pt_regs *) = NULL;
88 /* machine dependent timer functions */
89 unsigned long (*mach_gettimeoffset) (void);
90 void (*mach_gettod) (int*, int*, int*, int*, int*, int*);
91 int (*mach_hwclk) (int, struct rtc_time*) = NULL;
92 int (*mach_set_clock_mmss) (unsigned long) = NULL;
93 unsigned int (*mach_get_ss)(void) = NULL;
94 int (*mach_get_rtc_pll)(struct rtc_pll_info *) = NULL;
95 int (*mach_set_rtc_pll)(struct rtc_pll_info *) = NULL;
96 void (*mach_reset)( void );
97 void (*mach_halt)( void ) = NULL;
98 void (*mach_power_off)( void ) = NULL;
99 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
100 #if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY) 
101 void (*mach_floppy_setup) (char *, int *) __initdata = NULL;
102 #endif
103 #ifdef CONFIG_HEARTBEAT
104 void (*mach_heartbeat) (int) = NULL;
105 EXPORT_SYMBOL(mach_heartbeat);
106 #endif
107 #ifdef CONFIG_M68K_L2_CACHE
108 void (*mach_l2_flush) (int) = NULL;
109 #endif
110
111 #ifdef CONFIG_MAGIC_SYSRQ
112 unsigned int SYSRQ_KEY;
113 int mach_sysrq_key = -1;
114 int mach_sysrq_shift_state = 0;
115 int mach_sysrq_shift_mask = 0;
116 char *mach_sysrq_xlate = NULL;
117 #endif
118
119 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
120 int isa_type;
121 int isa_sex;
122 #endif
123
124 extern int amiga_parse_bootinfo(const struct bi_record *);
125 extern int atari_parse_bootinfo(const struct bi_record *);
126 extern int mac_parse_bootinfo(const struct bi_record *);
127 extern int q40_parse_bootinfo(const struct bi_record *);
128 extern int bvme6000_parse_bootinfo(const struct bi_record *);
129 extern int mvme16x_parse_bootinfo(const struct bi_record *);
130 extern int mvme147_parse_bootinfo(const struct bi_record *);
131
132 extern void config_amiga(void);
133 extern void config_atari(void);
134 extern void config_mac(void);
135 extern void config_sun3(void);
136 extern void config_apollo(void);
137 extern void config_mvme147(void);
138 extern void config_mvme16x(void);
139 extern void config_bvme6000(void);
140 extern void config_hp300(void);
141 extern void config_q40(void);
142 extern void config_sun3x(void);
143
144 extern void mac_debugging_short (int, short);
145 extern void mac_debugging_long  (int, long);
146
147 #define MASK_256K 0xfffc0000
148
149 extern void paging_init(void);
150
151 static void __init m68k_parse_bootinfo(const struct bi_record *record)
152 {
153     while (record->tag != BI_LAST) {
154         int unknown = 0;
155         const unsigned long *data = record->data;
156         switch (record->tag) {
157             case BI_MACHTYPE:
158             case BI_CPUTYPE:
159             case BI_FPUTYPE:
160             case BI_MMUTYPE:
161                 /* Already set up by head.S */
162                 break;
163
164             case BI_MEMCHUNK:
165                 if (m68k_num_memory < NUM_MEMINFO) {
166                     m68k_memory[m68k_num_memory].addr = data[0];
167                     m68k_memory[m68k_num_memory].size = data[1];
168                     m68k_num_memory++;
169                 } else
170                     printk("m68k_parse_bootinfo: too many memory chunks\n");
171                 break;
172
173             case BI_RAMDISK:
174                 m68k_ramdisk.addr = data[0];
175                 m68k_ramdisk.size = data[1];
176                 break;
177
178             case BI_COMMAND_LINE:
179                 strncpy(m68k_command_line, (const char *)data, CL_SIZE);
180                 m68k_command_line[CL_SIZE-1] = '\0';
181                 break;
182
183             default:
184                 if (MACH_IS_AMIGA)
185                     unknown = amiga_parse_bootinfo(record);
186                 else if (MACH_IS_ATARI)
187                     unknown = atari_parse_bootinfo(record);
188                 else if (MACH_IS_MAC)
189                     unknown = mac_parse_bootinfo(record);
190                 else if (MACH_IS_Q40)
191                     unknown = q40_parse_bootinfo(record);
192                 else if (MACH_IS_BVME6000)
193                     unknown = bvme6000_parse_bootinfo(record);
194                 else if (MACH_IS_MVME16x)
195                     unknown = mvme16x_parse_bootinfo(record);
196                 else if (MACH_IS_MVME147)
197                     unknown = mvme147_parse_bootinfo(record);
198                 else
199                     unknown = 1;
200         }
201         if (unknown)
202             printk("m68k_parse_bootinfo: unknown tag 0x%04x ignored\n",
203                    record->tag);
204         record = (struct bi_record *)((unsigned long)record+record->size);
205     }
206
207     m68k_realnum_memory = m68k_num_memory;
208 #ifdef CONFIG_SINGLE_MEMORY_CHUNK
209     if (m68k_num_memory > 1) {
210         printk("Ignoring last %i chunks of physical memory\n",
211                (m68k_num_memory - 1));
212         m68k_num_memory = 1;
213     }
214     m68k_memoffset = m68k_memory[0].addr-PAGE_OFFSET;
215 #endif
216 }
217
218 void __init setup_arch(char **cmdline_p)
219 {
220         extern int _etext, _edata, _end;
221 #ifndef CONFIG_SUN3
222         unsigned long endmem, startmem;
223 #endif
224         int i;
225         char *p, *q;
226
227         if (!MACH_IS_HP300) {
228                 /* The bootinfo is located right after the kernel bss */
229                 m68k_parse_bootinfo((const struct bi_record *)&_end);
230         } else {
231                 /* FIXME HP300 doesn't use bootinfo yet */
232                 extern unsigned long hp300_phys_ram_base;
233                 unsigned long hp300_mem_size = 0xffffffff-hp300_phys_ram_base;
234                 m68k_cputype = CPU_68030;
235                 m68k_fputype = FPU_68882;
236                 m68k_memory[0].addr = hp300_phys_ram_base;
237                 /* 0.5M fudge factor */
238                 m68k_memory[0].size = hp300_mem_size-512*1024;
239                 m68k_num_memory++;
240         }
241
242         if (CPU_IS_040)
243                 m68k_is040or060 = 4;
244         else if (CPU_IS_060)
245                 m68k_is040or060 = 6;
246
247         if (CPU_IS_060) {
248                 u32 pcr;
249
250                 asm (".chip 68060; movec %%pcr,%0; .chip 68k"
251                      : "=d" (pcr));
252                 if (((pcr >> 8) & 0xff) <= 5) {
253                         printk("Enabling workaround for errata I14\n");
254                         asm (".chip 68060; movec %0,%%pcr; .chip 68k"
255                              : : "d" (pcr | 0x20));
256                 }
257         }
258
259         /* FIXME: m68k_fputype is passed in by Penguin booter, which can
260          * be confused by software FPU emulation. BEWARE.
261          * We should really do our own FPU check at startup.
262          * [what do we do with buggy 68LC040s? if we have problems
263          *  with them, we should add a test to check_bugs() below] */
264 #ifndef CONFIG_M68KFPU_EMU_ONLY
265         /* clear the fpu if we have one */
266         if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060)) {
267                 volatile int zero = 0;
268                 asm __volatile__ ("frestore %0" : : "m" (zero));
269         }
270 #endif  
271
272         init_mm.start_code = PAGE_OFFSET;
273         init_mm.end_code = (unsigned long) &_etext;
274         init_mm.end_data = (unsigned long) &_edata;
275         init_mm.brk = (unsigned long) &_end;
276
277         *cmdline_p = m68k_command_line;
278         memcpy(saved_command_line, *cmdline_p, CL_SIZE);
279
280         /* Parse the command line for arch-specific options.
281          * For the m68k, this is currently only "debug=xxx" to enable printing
282          * certain kernel messages to some machine-specific device.
283          */
284         for( p = *cmdline_p; p && *p; ) {
285             i = 0;
286             if (!strncmp( p, "debug=", 6 )) {
287                 strncpy( m68k_debug_device, p+6, sizeof(m68k_debug_device)-1 );
288                 m68k_debug_device[sizeof(m68k_debug_device)-1] = 0;
289                 if ((q = strchr( m68k_debug_device, ' ' ))) *q = 0;
290                 i = 1;
291             }
292 #ifdef CONFIG_ATARI
293             /* These options must be parsed very early */
294             if (!strncmp( p, "switches=", 9 )) {
295                 extern void atari_switches_setup( const char *, int );
296                 atari_switches_setup( p+9, (q = strchr( p+9, ' ' )) ?
297                                            (q - (p+9)) : strlen(p+9) );
298                 i = 1;
299             }
300 #ifdef CONFIG_STRAM_SWAP
301             if (!strncmp( p, "stram_swap=", 11 )) {
302                 extern void stram_swap_setup( char * );
303                 stram_swap_setup( p+11 );
304                 i = 1;
305             }
306 #endif  /* CONFIG_STRAM_SWAP */
307 #endif
308
309             if (i) {
310                 /* option processed, delete it */
311                 if ((q = strchr( p, ' ' )))
312                     strcpy( p, q+1 );
313                 else
314                     *p = 0;
315             } else {
316                 if ((p = strchr( p, ' ' ))) ++p;
317             }
318         }
319
320         switch (m68k_machtype) {
321 #ifdef CONFIG_AMIGA
322             case MACH_AMIGA:
323                 config_amiga();
324                 break;
325 #endif
326 #ifdef CONFIG_ATARI
327             case MACH_ATARI:
328                 config_atari();
329                 break;
330 #endif
331 #ifdef CONFIG_MAC
332             case MACH_MAC:
333                 config_mac();
334                 break;
335 #endif
336 #ifdef CONFIG_SUN3
337             case MACH_SUN3:
338                 config_sun3();
339                 break;
340 #endif
341 #ifdef CONFIG_APOLLO
342             case MACH_APOLLO:
343                 config_apollo();
344                 break;
345 #endif
346 #ifdef CONFIG_MVME147
347             case MACH_MVME147:
348                 config_mvme147();
349                 break;
350 #endif
351 #ifdef CONFIG_MVME16x
352             case MACH_MVME16x:
353                 config_mvme16x();
354                 break;
355 #endif
356 #ifdef CONFIG_BVME6000
357             case MACH_BVME6000:
358                 config_bvme6000();
359                 break;
360 #endif
361 #ifdef CONFIG_HP300
362             case MACH_HP300:
363                 config_hp300();
364                 break;
365 #endif
366 #ifdef CONFIG_Q40
367             case MACH_Q40:
368                 config_q40();
369                 break;
370 #endif
371 #ifdef CONFIG_SUN3X
372             case MACH_SUN3X:
373                 config_sun3x();
374                 break;
375 #endif
376             default:
377                 panic ("No configuration setup");
378         }
379
380 #ifndef CONFIG_SUN3
381         startmem= m68k_memory[0].addr;
382         endmem = startmem + m68k_memory[0].size;
383         high_memory = PAGE_OFFSET;
384         for (i = 0; i < m68k_num_memory; i++) {
385                 m68k_memory[i].size &= MASK_256K;
386                 if (m68k_memory[i].addr < startmem)
387                         startmem = m68k_memory[i].addr;
388                 if (m68k_memory[i].addr+m68k_memory[i].size > endmem)
389                         endmem = m68k_memory[i].addr+m68k_memory[i].size;
390                 high_memory += m68k_memory[i].size;
391         }
392
393         availmem += init_bootmem_node(NODE_DATA(0), availmem >> PAGE_SHIFT,
394                                       startmem >> PAGE_SHIFT, endmem >> PAGE_SHIFT);
395
396         for (i = 0; i < m68k_num_memory; i++)
397                 free_bootmem(m68k_memory[i].addr, m68k_memory[i].size);
398
399         reserve_bootmem(m68k_memory[0].addr, availmem - m68k_memory[0].addr);
400
401 #ifdef CONFIG_BLK_DEV_INITRD
402         if (m68k_ramdisk.size) {
403                 reserve_bootmem(m68k_ramdisk.addr, m68k_ramdisk.size);
404                 initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
405                 initrd_end = initrd_start + m68k_ramdisk.size;
406                 printk ("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
407         }
408 #endif
409
410 #ifdef CONFIG_ATARI
411         if (MACH_IS_ATARI)
412                 atari_stram_reserve_pages((void *)availmem);
413 #endif
414 #ifdef CONFIG_SUN3X
415         if (MACH_IS_SUN3X) {
416                 dvma_init();
417 #ifdef CONFIG_SUN3X_ZS
418                 sun_serial_setup();
419 #endif
420         }
421 #endif
422
423 #endif /* !CONFIG_SUN3 */
424
425         paging_init();
426
427 /* set ISA defs early as possible */
428 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
429 #if defined(CONFIG_Q40) 
430         if (MACH_IS_Q40) {
431             isa_type = Q40_ISA;
432             isa_sex = 0;
433         } 
434 #elif defined(CONFIG_GG2)
435         if (MACH_IS_AMIGA && AMIGAHW_PRESENT(GG2_ISA)){
436             isa_type = GG2_ISA;
437             isa_sex = 0;
438         }
439 #elif defined(CONFIG_AMIGA_PCMCIA)
440         if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)){
441             isa_type = AG_ISA;
442             isa_sex = 1;
443         }
444 #endif
445 #endif
446 }
447
448 static int show_cpuinfo(struct seq_file *m, void *v)
449 {
450     const char *cpu, *mmu, *fpu;
451     unsigned long clockfreq, clockfactor;
452
453 #define LOOP_CYCLES_68020       (8)
454 #define LOOP_CYCLES_68030       (8)
455 #define LOOP_CYCLES_68040       (3)
456 #define LOOP_CYCLES_68060       (1)
457
458     if (CPU_IS_020) {
459         cpu = "68020";
460         clockfactor = LOOP_CYCLES_68020;
461     } else if (CPU_IS_030) {
462         cpu = "68030";
463         clockfactor = LOOP_CYCLES_68030;
464     } else if (CPU_IS_040) {
465         cpu = "68040";
466         clockfactor = LOOP_CYCLES_68040;
467     } else if (CPU_IS_060) {
468         cpu = "68060";
469         clockfactor = LOOP_CYCLES_68060;
470     } else {
471         cpu = "680x0";
472         clockfactor = 0;
473     }
474
475 #ifdef CONFIG_M68KFPU_EMU_ONLY
476     fpu="none(soft float)";
477 #else
478     if (m68k_fputype & FPU_68881)
479         fpu = "68881";
480     else if (m68k_fputype & FPU_68882)
481         fpu = "68882";
482     else if (m68k_fputype & FPU_68040)
483         fpu = "68040";
484     else if (m68k_fputype & FPU_68060)
485         fpu = "68060";
486     else if (m68k_fputype & FPU_SUNFPA)
487         fpu = "Sun FPA";
488     else
489         fpu = "none";
490 #endif
491
492     if (m68k_mmutype & MMU_68851)
493         mmu = "68851";
494     else if (m68k_mmutype & MMU_68030)
495         mmu = "68030";
496     else if (m68k_mmutype & MMU_68040)
497         mmu = "68040";
498     else if (m68k_mmutype & MMU_68060)
499         mmu = "68060";
500     else if (m68k_mmutype & MMU_SUN3)
501         mmu = "Sun-3";
502     else if (m68k_mmutype & MMU_APOLLO)
503         mmu = "Apollo";
504     else
505         mmu = "unknown";
506
507     clockfreq = loops_per_jiffy*HZ*clockfactor;
508
509     seq_printf(m, "CPU:\t\t%s\n"
510                    "MMU:\t\t%s\n"
511                    "FPU:\t\t%s\n"
512                    "Clocking:\t%lu.%1luMHz\n"
513                    "BogoMips:\t%lu.%02lu\n"
514                    "Calibration:\t%lu loops\n",
515                    cpu, mmu, fpu,
516                    clockfreq/1000000,(clockfreq/100000)%10,
517                    loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
518                    loops_per_jiffy);
519     return 0;
520 }
521
522 static void *c_start(struct seq_file *m, loff_t *pos)
523 {
524         return *pos < 1 ? (void *)1 : NULL;
525 }
526 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
527 {
528         ++*pos;
529         return NULL;
530 }
531 static void c_stop(struct seq_file *m, void *v)
532 {
533 }
534 struct seq_operations cpuinfo_op = {
535         start:  c_start,
536         next:   c_next,
537         stop:   c_stop,
538         show:   show_cpuinfo,
539 };
540
541 int get_hardware_list(char *buffer)
542 {
543     int len = 0;
544     char model[80];
545     unsigned long mem;
546     int i;
547
548     if (mach_get_model)
549         mach_get_model(model);
550     else
551         strcpy(model, "Unknown m68k");
552
553     len += sprintf(buffer+len, "Model:\t\t%s\n", model);
554     //len += get_cpuinfo(buffer+len);
555     for (mem = 0, i = 0; i < m68k_num_memory; i++)
556         mem += m68k_memory[i].size;
557     len += sprintf(buffer+len, "System Memory:\t%ldK\n", mem>>10);
558
559     if (mach_get_hardware_list)
560         len += mach_get_hardware_list(buffer+len);
561
562     return(len);
563 }
564
565
566 #if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY)
567 void __init floppy_setup(char *str, int *ints)
568 {
569         if (mach_floppy_setup)
570                 mach_floppy_setup (str, ints);
571 }
572
573 #endif
574
575 /* for "kbd-reset" cmdline param */
576 void __init kbd_reset_setup(char *str, int *ints)
577 {
578 }
579
580 void arch_gettod(int *year, int *mon, int *day, int *hour,
581                  int *min, int *sec)
582 {
583         if (mach_gettod)
584                 mach_gettod(year, mon, day, hour, min, sec);
585         else
586                 *year = *mon = *day = *hour = *min = *sec = 0;
587 }
588
589 void check_bugs(void)
590 {
591 #ifndef CONFIG_M68KFPU_EMU
592         if (m68k_fputype == 0) {
593                 printk( KERN_EMERG "*** YOU DO NOT HAVE A FLOATING POINT UNIT, "
594                                 "WHICH IS REQUIRED BY LINUX/M68K ***\n" );
595                 printk( KERN_EMERG "Upgrade your hardware or join the FPU "
596                                 "emulation project\n" );
597                 printk( KERN_EMERG "(see http://no-fpu.linux-m68k.org)\n" );
598                 panic( "no FPU" );
599         }
600 #endif /* !CONFIG_M68KFPU_EMU */
601 }