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