[PATCH] m68k: isa_{type,sex} should be exported
[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         switch (m68k_machtype) {
286 #ifdef CONFIG_AMIGA
287             case MACH_AMIGA:
288                 config_amiga();
289                 break;
290 #endif
291 #ifdef CONFIG_ATARI
292             case MACH_ATARI:
293                 config_atari();
294                 break;
295 #endif
296 #ifdef CONFIG_MAC
297             case MACH_MAC:
298                 config_mac();
299                 break;
300 #endif
301 #ifdef CONFIG_SUN3
302             case MACH_SUN3:
303                 config_sun3();
304                 break;
305 #endif
306 #ifdef CONFIG_APOLLO
307             case MACH_APOLLO:
308                 config_apollo();
309                 break;
310 #endif
311 #ifdef CONFIG_MVME147
312             case MACH_MVME147:
313                 config_mvme147();
314                 break;
315 #endif
316 #ifdef CONFIG_MVME16x
317             case MACH_MVME16x:
318                 config_mvme16x();
319                 break;
320 #endif
321 #ifdef CONFIG_BVME6000
322             case MACH_BVME6000:
323                 config_bvme6000();
324                 break;
325 #endif
326 #ifdef CONFIG_HP300
327             case MACH_HP300:
328                 config_hp300();
329                 break;
330 #endif
331 #ifdef CONFIG_Q40
332             case MACH_Q40:
333                 config_q40();
334                 break;
335 #endif
336 #ifdef CONFIG_SUN3X
337             case MACH_SUN3X:
338                 config_sun3x();
339                 break;
340 #endif
341             default:
342                 panic ("No configuration setup");
343         }
344
345 #ifndef CONFIG_SUN3
346         startmem= m68k_memory[0].addr;
347         endmem = startmem + m68k_memory[0].size;
348         high_memory = (void *)PAGE_OFFSET;
349         for (i = 0; i < m68k_num_memory; i++) {
350                 m68k_memory[i].size &= MASK_256K;
351                 if (m68k_memory[i].addr < startmem)
352                         startmem = m68k_memory[i].addr;
353                 if (m68k_memory[i].addr+m68k_memory[i].size > endmem)
354                         endmem = m68k_memory[i].addr+m68k_memory[i].size;
355                 high_memory += m68k_memory[i].size;
356         }
357
358         availmem += init_bootmem_node(NODE_DATA(0), availmem >> PAGE_SHIFT,
359                                       startmem >> PAGE_SHIFT, endmem >> PAGE_SHIFT);
360
361         for (i = 0; i < m68k_num_memory; i++)
362                 free_bootmem(m68k_memory[i].addr, m68k_memory[i].size);
363
364         reserve_bootmem(m68k_memory[0].addr, availmem - m68k_memory[0].addr);
365
366 #ifdef CONFIG_BLK_DEV_INITRD
367         if (m68k_ramdisk.size) {
368                 reserve_bootmem(m68k_ramdisk.addr, m68k_ramdisk.size);
369                 initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
370                 initrd_end = initrd_start + m68k_ramdisk.size;
371                 printk ("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
372         }
373 #endif
374
375 #ifdef CONFIG_ATARI
376         if (MACH_IS_ATARI)
377                 atari_stram_reserve_pages((void *)availmem);
378 #endif
379 #ifdef CONFIG_SUN3X
380         if (MACH_IS_SUN3X) {
381                 dvma_init();
382         }
383 #endif
384
385 #endif /* !CONFIG_SUN3 */
386
387         paging_init();
388
389 /* set ISA defs early as possible */
390 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
391 #if defined(CONFIG_Q40)
392         if (MACH_IS_Q40) {
393             isa_type = Q40_ISA;
394             isa_sex = 0;
395         }
396 #elif defined(CONFIG_GG2)
397         if (MACH_IS_AMIGA && AMIGAHW_PRESENT(GG2_ISA)){
398             isa_type = GG2_ISA;
399             isa_sex = 0;
400         }
401 #elif defined(CONFIG_AMIGA_PCMCIA)
402         if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)){
403             isa_type = AG_ISA;
404             isa_sex = 1;
405         }
406 #endif
407 #endif
408 }
409
410 static int show_cpuinfo(struct seq_file *m, void *v)
411 {
412     const char *cpu, *mmu, *fpu;
413     unsigned long clockfreq, clockfactor;
414
415 #define LOOP_CYCLES_68020       (8)
416 #define LOOP_CYCLES_68030       (8)
417 #define LOOP_CYCLES_68040       (3)
418 #define LOOP_CYCLES_68060       (1)
419
420     if (CPU_IS_020) {
421         cpu = "68020";
422         clockfactor = LOOP_CYCLES_68020;
423     } else if (CPU_IS_030) {
424         cpu = "68030";
425         clockfactor = LOOP_CYCLES_68030;
426     } else if (CPU_IS_040) {
427         cpu = "68040";
428         clockfactor = LOOP_CYCLES_68040;
429     } else if (CPU_IS_060) {
430         cpu = "68060";
431         clockfactor = LOOP_CYCLES_68060;
432     } else {
433         cpu = "680x0";
434         clockfactor = 0;
435     }
436
437 #ifdef CONFIG_M68KFPU_EMU_ONLY
438     fpu="none(soft float)";
439 #else
440     if (m68k_fputype & FPU_68881)
441         fpu = "68881";
442     else if (m68k_fputype & FPU_68882)
443         fpu = "68882";
444     else if (m68k_fputype & FPU_68040)
445         fpu = "68040";
446     else if (m68k_fputype & FPU_68060)
447         fpu = "68060";
448     else if (m68k_fputype & FPU_SUNFPA)
449         fpu = "Sun FPA";
450     else
451         fpu = "none";
452 #endif
453
454     if (m68k_mmutype & MMU_68851)
455         mmu = "68851";
456     else if (m68k_mmutype & MMU_68030)
457         mmu = "68030";
458     else if (m68k_mmutype & MMU_68040)
459         mmu = "68040";
460     else if (m68k_mmutype & MMU_68060)
461         mmu = "68060";
462     else if (m68k_mmutype & MMU_SUN3)
463         mmu = "Sun-3";
464     else if (m68k_mmutype & MMU_APOLLO)
465         mmu = "Apollo";
466     else
467         mmu = "unknown";
468
469     clockfreq = loops_per_jiffy*HZ*clockfactor;
470
471     seq_printf(m, "CPU:\t\t%s\n"
472                    "MMU:\t\t%s\n"
473                    "FPU:\t\t%s\n"
474                    "Clocking:\t%lu.%1luMHz\n"
475                    "BogoMips:\t%lu.%02lu\n"
476                    "Calibration:\t%lu loops\n",
477                    cpu, mmu, fpu,
478                    clockfreq/1000000,(clockfreq/100000)%10,
479                    loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
480                    loops_per_jiffy);
481     return 0;
482 }
483
484 static void *c_start(struct seq_file *m, loff_t *pos)
485 {
486         return *pos < 1 ? (void *)1 : NULL;
487 }
488 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
489 {
490         ++*pos;
491         return NULL;
492 }
493 static void c_stop(struct seq_file *m, void *v)
494 {
495 }
496 struct seq_operations cpuinfo_op = {
497         .start =        c_start,
498         .next =         c_next,
499         .stop =         c_stop,
500         .show =         show_cpuinfo,
501 };
502
503 int get_hardware_list(char *buffer)
504 {
505     int len = 0;
506     char model[80];
507     unsigned long mem;
508     int i;
509
510     if (mach_get_model)
511         mach_get_model(model);
512     else
513         strcpy(model, "Unknown m68k");
514
515     len += sprintf(buffer+len, "Model:\t\t%s\n", model);
516     for (mem = 0, i = 0; i < m68k_num_memory; i++)
517         mem += m68k_memory[i].size;
518     len += sprintf(buffer+len, "System Memory:\t%ldK\n", mem>>10);
519
520     if (mach_get_hardware_list)
521         len += mach_get_hardware_list(buffer+len);
522
523     return(len);
524 }
525
526
527 #if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY)
528 void __init floppy_setup(char *str, int *ints)
529 {
530         if (mach_floppy_setup)
531                 mach_floppy_setup (str, ints);
532 }
533
534 #endif
535
536 void check_bugs(void)
537 {
538 #ifndef CONFIG_M68KFPU_EMU
539         if (m68k_fputype == 0) {
540                 printk( KERN_EMERG "*** YOU DO NOT HAVE A FLOATING POINT UNIT, "
541                                 "WHICH IS REQUIRED BY LINUX/M68K ***\n" );
542                 printk( KERN_EMERG "Upgrade your hardware or join the FPU "
543                                 "emulation project\n" );
544                 panic( "no FPU" );
545         }
546 #endif /* !CONFIG_M68KFPU_EMU */
547 }