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