More Makefile cleanups, otherwise mainly noticeable are the netfilter fix
[davej-history.git] / arch / m68k / kernel / setup.c
blob040f96d97e636e41f32c76eefe9629a2a5b86c82
1 /*
2 * linux/arch/m68k/kernel/setup.c
4 * Copyright (C) 1995 Hamish Macdonald
5 */
7 /*
8 * This file handles the architecture-dependent parts of system setup
9 */
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/module.h>
26 #include <asm/bootinfo.h>
27 #include <asm/setup.h>
28 #include <asm/irq.h>
29 #include <asm/io.h>
30 #include <asm/machdep.h>
31 #ifdef CONFIG_AMIGA
32 #include <asm/amigahw.h>
33 #endif
34 #ifdef CONFIG_ATARI
35 #include <asm/atarihw.h>
36 #endif
38 #ifdef CONFIG_BLK_DEV_INITRD
39 #include <linux/blk.h>
40 #endif
42 #ifndef CONFIG_AMIGA
43 #define dbprintf printk
44 #endif
46 unsigned long m68k_machtype;
47 unsigned long m68k_cputype;
48 unsigned long m68k_fputype;
49 unsigned long m68k_mmutype;
50 #ifdef CONFIG_VME
51 unsigned long vme_brdtype;
52 #endif
54 int m68k_is040or060 = 0;
56 extern int end;
57 extern unsigned long availmem;
59 int m68k_num_memory = 0;
60 int m68k_realnum_memory = 0;
61 unsigned long m68k_memoffset;
62 struct mem_info m68k_memory[NUM_MEMINFO];
64 static struct mem_info m68k_ramdisk = { 0, 0 };
66 static char m68k_command_line[CL_SIZE];
67 char saved_command_line[CL_SIZE];
69 char m68k_debug_device[6] = "";
71 void (*mach_sched_init) (void (*handler)(int, void *, struct pt_regs *)) __initdata = NULL;
72 /* machine dependent keyboard functions */
73 int (*mach_keyb_init) (void) __initdata = NULL;
74 int (*mach_kbdrate) (struct kbd_repeat *) = NULL;
75 void (*mach_kbd_leds) (unsigned int) = NULL;
76 int (*mach_kbd_translate)(unsigned char scancode, unsigned char *keycode, char raw_mode) = NULL;
77 unsigned int SYSRQ_KEY;
78 /* machine dependent irq functions */
79 void (*mach_init_IRQ) (void) __initdata = NULL;
80 void (*(*mach_default_handler)[]) (int, void *, struct pt_regs *) = NULL;
81 void (*mach_get_model) (char *model) = NULL;
82 int (*mach_get_hardware_list) (char *buffer) = NULL;
83 int (*mach_get_irq_list) (char *) = NULL;
84 void (*mach_process_int) (int, struct pt_regs *) = NULL;
85 /* machine dependent timer functions */
86 unsigned long (*mach_gettimeoffset) (void);
87 void (*mach_gettod) (int*, int*, int*, int*, int*, int*);
88 int (*mach_hwclk) (int, struct hwclk_time*) = NULL;
89 int (*mach_set_clock_mmss) (unsigned long) = NULL;
90 void (*mach_reset)( void );
91 void (*mach_halt)( void ) = NULL;
92 void (*mach_power_off)( void ) = NULL;
93 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
94 #if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY) || defined(CONFIG_BLK_DEV_FD)
95 void (*mach_floppy_setup) (char *, int *) __initdata = NULL;
96 void (*mach_floppy_eject) (void) = NULL;
97 #endif
98 struct serial_struct;
99 #ifdef CONFIG_SERIAL
100 long serial_rs_init(void);
101 int serial_register_serial(struct serial_struct *);
102 void serial_unregister_serial(int);
103 long ser_console_init(long, long );
104 #endif
105 #if defined(CONFIG_USERIAL)||defined(CONFIG_HPDCA)||defined(CONFIG_WHIPPET_SERIAL)||defined(CONFIG_MULTIFACE_III_TTY)||defined(CONFIG_GVPIOEXT)||defined(CONFIG_AMIGA_BUILTIN_SERIAL)||defined(CONFIG_MAC_SCC)||defined(CONFIG_ATARI_MIDI)||defined(CONFIG_ATARI_SCC)||defined(CONFIG_ATARI_MFPSER)
106 #define M68K_SERIAL
107 #endif
108 #ifdef M68K_SERIAL
109 long m68k_rs_init(void);
110 int m68k_register_serial(struct serial_struct *);
111 void m68k_unregister_serial(int);
112 long m68k_serial_console_init(void);
113 #endif
114 #ifdef CONFIG_HEARTBEAT
115 void (*mach_heartbeat) (int) = NULL;
116 EXPORT_SYMBOL(mach_heartbeat);
117 #endif
118 #ifdef CONFIG_M68K_L2_CACHE
119 void (*mach_l2_flush) (int) = NULL;
120 #endif
122 #ifdef CONFIG_MAGIC_SYSRQ
123 int mach_sysrq_key = -1;
124 int mach_sysrq_shift_state = 0;
125 int mach_sysrq_shift_mask = 0;
126 char *mach_sysrq_xlate = NULL;
127 #endif
129 extern int amiga_parse_bootinfo(const struct bi_record *);
130 extern int atari_parse_bootinfo(const struct bi_record *);
131 extern int mac_parse_bootinfo(const struct bi_record *);
132 extern int q40_parse_bootinfo(const struct bi_record *);
133 extern int bvme6000_parse_bootinfo(const struct bi_record *);
134 extern int mvme16x_parse_bootinfo(const struct bi_record *);
135 extern int mvme147_parse_bootinfo(const struct bi_record *);
137 extern void config_amiga(void);
138 extern void config_atari(void);
139 extern void config_mac(void);
140 extern void config_sun3(unsigned long *, unsigned long *);
141 extern void config_apollo(void);
142 extern void config_mvme147(void);
143 extern void config_mvme16x(void);
144 extern void config_bvme6000(void);
145 extern void config_hp300(void);
146 extern void config_q40(void);
147 extern void config_sun3x(void);
149 extern void mac_debugging_short (int, short);
150 extern void mac_debugging_long (int, long);
152 #define MASK_256K 0xfffc0000
154 static void __init m68k_parse_bootinfo(const struct bi_record *record)
156 while (record->tag != BI_LAST) {
157 int unknown = 0;
158 const u_long *data = record->data;
159 switch (record->tag) {
160 case BI_MACHTYPE:
161 case BI_CPUTYPE:
162 case BI_FPUTYPE:
163 case BI_MMUTYPE:
164 /* Already set up by head.S */
165 break;
167 case BI_MEMCHUNK:
168 if (m68k_num_memory < NUM_MEMINFO) {
169 m68k_memory[m68k_num_memory].addr = data[0];
170 m68k_memory[m68k_num_memory].size = data[1];
171 m68k_num_memory++;
172 } else
173 printk("m68k_parse_bootinfo: too many memory chunks\n");
174 break;
176 case BI_RAMDISK:
177 m68k_ramdisk.addr = data[0];
178 m68k_ramdisk.size = data[1];
179 break;
181 case BI_COMMAND_LINE:
182 strncpy(m68k_command_line, (const char *)data, CL_SIZE);
183 m68k_command_line[CL_SIZE-1] = '\0';
184 break;
186 default:
187 if (MACH_IS_AMIGA)
188 unknown = amiga_parse_bootinfo(record);
189 else if (MACH_IS_ATARI)
190 unknown = atari_parse_bootinfo(record);
191 else if (MACH_IS_MAC)
192 unknown = mac_parse_bootinfo(record);
193 else if (MACH_IS_Q40)
194 unknown = q40_parse_bootinfo(record);
195 else if (MACH_IS_BVME6000)
196 unknown = bvme6000_parse_bootinfo(record);
197 else if (MACH_IS_MVME16x)
198 unknown = mvme16x_parse_bootinfo(record);
199 else if (MACH_IS_MVME147)
200 unknown = mvme147_parse_bootinfo(record);
201 else
202 unknown = 1;
204 if (unknown)
205 printk("m68k_parse_bootinfo: unknown tag 0x%04x ignored\n",
206 record->tag);
207 record = (struct bi_record *)((u_long)record+record->size);
210 m68k_realnum_memory = m68k_num_memory;
211 #ifdef CONFIG_SINGLE_MEMORY_CHUNK
212 if (m68k_num_memory > 1) {
213 printk("Ignoring last %i chunks of physical memory\n",
214 (m68k_num_memory - 1));
215 m68k_num_memory = 1;
217 m68k_memoffset = m68k_memory[0].addr-PAGE_OFFSET;
218 #endif
221 void __init setup_arch(char **cmdline_p)
223 extern int _etext, _edata, _end;
224 unsigned long endmem, startmem;
225 int i;
226 char *p, *q;
228 /* The bootinfo is located right after the kernel bss */
229 m68k_parse_bootinfo((const struct bi_record *)&_end);
231 if (CPU_IS_040)
232 m68k_is040or060 = 4;
233 else if (CPU_IS_060)
234 m68k_is040or060 = 6;
236 /* FIXME: m68k_fputype is passed in by Penguin booter, which can
237 * be confused by software FPU emulation. BEWARE.
238 * We should really do our own FPU check at startup.
239 * [what do we do with buggy 68LC040s? if we have problems
240 * with them, we should add a test to check_bugs() below] */
241 #ifndef CONFIG_M68KFPU_EMU_ONLY
242 /* clear the fpu if we have one */
243 if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060)) {
244 volatile int zero = 0;
245 asm __volatile__ ("frestore %0" : : "m" (zero));
247 #endif
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;
254 *cmdline_p = m68k_command_line;
255 memcpy(saved_command_line, *cmdline_p, CL_SIZE);
257 /* Parse the command line for arch-specific options.
258 * For the m68k, this is currently only "debug=xxx" to enable printing
259 * certain kernel messages to some machine-specific device.
261 for( p = *cmdline_p; p && *p; ) {
262 i = 0;
263 if (!strncmp( p, "debug=", 6 )) {
264 strncpy( m68k_debug_device, p+6, sizeof(m68k_debug_device)-1 );
265 m68k_debug_device[sizeof(m68k_debug_device)-1] = 0;
266 if ((q = strchr( m68k_debug_device, ' ' ))) *q = 0;
267 i = 1;
269 #ifdef CONFIG_ATARI
270 /* This option must be parsed very early */
271 if (!strncmp( p, "switches=", 9 )) {
272 extern void atari_switches_setup( const char *, int );
273 atari_switches_setup( p+9, (q = strchr( p+9, ' ' )) ?
274 (q - (p+9)) : strlen(p+9) );
275 i = 1;
277 #endif
279 if (i) {
280 /* option processed, delete it */
281 if ((q = strchr( p, ' ' )))
282 strcpy( p, q+1 );
283 else
284 *p = 0;
285 } else {
286 if ((p = strchr( p, ' ' ))) ++p;
290 switch (m68k_machtype) {
291 #ifdef CONFIG_AMIGA
292 case MACH_AMIGA:
293 config_amiga();
294 break;
295 #endif
296 #ifdef CONFIG_ATARI
297 case MACH_ATARI:
298 config_atari();
299 break;
300 #endif
301 #ifdef CONFIG_MAC
302 case MACH_MAC:
303 config_mac();
304 break;
305 #endif
306 #ifdef CONFIG_SUN3
307 case MACH_SUN3:
308 config_sun3(memory_start_p, memory_end_p);
309 break;
310 #endif
311 #ifdef CONFIG_APOLLO
312 case MACH_APOLLO:
313 config_apollo();
314 break;
315 #endif
316 #ifdef CONFIG_MVME147
317 case MACH_MVME147:
318 config_mvme147();
319 break;
320 #endif
321 #ifdef CONFIG_MVME16x
322 case MACH_MVME16x:
323 config_mvme16x();
324 break;
325 #endif
326 #ifdef CONFIG_BVME6000
327 case MACH_BVME6000:
328 config_bvme6000();
329 break;
330 #endif
331 #ifdef CONFIG_HP300
332 case MACH_HP300:
333 config_hp300();
334 break;
335 #endif
336 #ifdef CONFIG_Q40
337 case MACH_Q40:
338 config_q40();
339 break;
340 #endif
341 #ifdef CONFIG_SUN3X
342 case MACH_SUN3X:
343 config_sun3x();
344 break;
345 #endif
346 default:
347 panic ("No configuration setup");
350 #ifdef CONFIG_BLK_DEV_INITRD
351 if (m68k_ramdisk.size) {
352 initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
353 initrd_end = initrd_start + m68k_ramdisk.size;
355 #endif
357 #ifndef CONFIG_SUN3
358 startmem= m68k_memory[0].addr;
359 endmem = startmem + m68k_memory[0].size;
360 high_memory = PAGE_OFFSET;
361 for (i = 0; i < m68k_num_memory; i++) {
362 m68k_memory[i].size &= MASK_256K;
363 if (m68k_memory[i].addr < startmem)
364 startmem = m68k_memory[i].addr;
365 if (m68k_memory[i].addr+m68k_memory[i].size > endmem)
366 endmem = m68k_memory[i].addr+m68k_memory[i].size;
367 high_memory += m68k_memory[i].size;
370 availmem += init_bootmem_node(NODE_DATA(0), availmem >> PAGE_SHIFT,
371 startmem >> PAGE_SHIFT, endmem >> PAGE_SHIFT);
373 for (i = 0; i < m68k_num_memory; i++)
374 free_bootmem(m68k_memory[0].addr, m68k_memory[0].size);
376 reserve_bootmem(m68k_memory[0].addr, availmem - m68k_memory[0].addr);
377 #endif
380 int get_cpuinfo(char * buffer)
382 const char *cpu, *mmu, *fpu;
383 u_long clockfreq, clockfactor;
385 #define LOOP_CYCLES_68020 (8)
386 #define LOOP_CYCLES_68030 (8)
387 #define LOOP_CYCLES_68040 (3)
388 #define LOOP_CYCLES_68060 (1)
390 if (CPU_IS_020) {
391 cpu = "68020";
392 clockfactor = LOOP_CYCLES_68020;
393 } else if (CPU_IS_030) {
394 cpu = "68030";
395 clockfactor = LOOP_CYCLES_68030;
396 } else if (CPU_IS_040) {
397 cpu = "68040";
398 clockfactor = LOOP_CYCLES_68040;
399 } else if (CPU_IS_060) {
400 cpu = "68060";
401 clockfactor = LOOP_CYCLES_68060;
402 } else {
403 cpu = "680x0";
404 clockfactor = 0;
407 #ifdef CONFIG_M68KFPU_EMU_ONLY
408 fpu="none(soft float)";
409 #else
410 if (m68k_fputype & FPU_68881)
411 fpu = "68881";
412 else if (m68k_fputype & FPU_68882)
413 fpu = "68882";
414 else if (m68k_fputype & FPU_68040)
415 fpu = "68040";
416 else if (m68k_fputype & FPU_68060)
417 fpu = "68060";
418 else if (m68k_fputype & FPU_SUNFPA)
419 fpu = "Sun FPA";
420 else
421 fpu = "none";
422 #endif
424 if (m68k_mmutype & MMU_68851)
425 mmu = "68851";
426 else if (m68k_mmutype & MMU_68030)
427 mmu = "68030";
428 else if (m68k_mmutype & MMU_68040)
429 mmu = "68040";
430 else if (m68k_mmutype & MMU_68060)
431 mmu = "68060";
432 else if (m68k_mmutype & MMU_SUN3)
433 mmu = "Sun-3";
434 else if (m68k_mmutype & MMU_APOLLO)
435 mmu = "Apollo";
436 else
437 mmu = "unknown";
439 clockfreq = loops_per_sec*clockfactor;
441 return(sprintf(buffer, "CPU:\t\t%s\n"
442 "MMU:\t\t%s\n"
443 "FPU:\t\t%s\n"
444 "Clocking:\t%lu.%1luMHz\n"
445 "BogoMips:\t%lu.%02lu\n"
446 "Calibration:\t%lu loops\n",
447 cpu, mmu, fpu,
448 clockfreq/1000000,(clockfreq/100000)%10,
449 loops_per_sec/500000,(loops_per_sec/5000)%100,
450 loops_per_sec));
454 int get_hardware_list(char *buffer)
456 int len = 0;
457 char model[80];
458 u_long mem;
459 int i;
461 if (mach_get_model)
462 mach_get_model(model);
463 else
464 strcpy(model, "Unknown m68k");
466 len += sprintf(buffer+len, "Model:\t\t%s\n", model);
467 len += get_cpuinfo(buffer+len);
468 for (mem = 0, i = 0; i < m68k_num_memory; i++)
469 mem += m68k_memory[i].size;
470 len += sprintf(buffer+len, "System Memory:\t%ldK\n", mem>>10);
472 if (mach_get_hardware_list)
473 len += mach_get_hardware_list(buffer+len);
475 return(len);
478 #if defined(CONFIG_SERIAL) || defined(M68K_SERIAL)
479 int rs_init(void)
481 #ifdef CONFIG_SERIAL
482 if (MACH_IS_Q40)
483 return serial_rs_init();
484 #endif
485 #ifdef M68K_SERIAL
486 return m68k_rs_init();
487 #endif
489 int register_serial(struct serial_struct *p)
491 #ifdef CONFIG_SERIAL
492 if (MACH_IS_Q40)
493 return serial_register_serial(p);
494 #endif
495 #ifdef M68K_SERIAL
496 return m68k_register_serial(p);
497 #endif
499 void unregister_serial(int i)
501 #ifdef CONFIG_SERIAL
502 if (MACH_IS_Q40)
503 serial_unregister_serial(i);
504 #endif
505 #ifdef M68K_SERIAL
506 m68k_unregister_serial(i);
507 #endif
509 EXPORT_SYMBOL(register_serial);
510 EXPORT_SYMBOL(unregister_serial);
512 #ifdef CONFIG_SERIAL_CONSOLE
513 void serial_console_init(void)
515 #ifdef CONFIG_Q40_SERIAL
516 if (MACH_IS_Q40) {
517 ser_console_init();
518 return;
520 #endif
521 #if defined(M68K_SERIAL) && defined(CONFIG_SERIAL_CONSOLE)
522 m68k_serial_console_init();
523 #endif
525 #endif
526 #endif
528 #if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY) || defined(CONFIG_BLK_DEV_FD)
529 void __init floppy_setup(char *str, int *ints)
531 if (mach_floppy_setup)
532 mach_floppy_setup (str, ints);
535 void floppy_eject(void)
537 if (mach_floppy_eject)
538 mach_floppy_eject();
540 #endif
542 /* for "kbd-reset" cmdline param */
543 void __init kbd_reset_setup(char *str, int *ints)
547 void arch_gettod(int *year, int *mon, int *day, int *hour,
548 int *min, int *sec)
550 if (mach_gettod)
551 mach_gettod(year, mon, day, hour, min, sec);
552 else
553 *year = *mon = *day = *hour = *min = *sec = 0;
556 void check_bugs(void)
558 #ifndef CONFIG_M68KFPU_EMU
559 if (m68k_fputype == 0) {
560 printk( KERN_EMERG "*** YOU DO NOT HAVE A FLOATING POINT UNIT, "
561 "WHICH IS REQUIRED BY LINUX/M68K ***\n" );
562 printk( KERN_EMERG "Upgrade your hardware or join the FPU "
563 "emulation project\n" );
564 printk( KERN_EMERG "(see http://no-fpu.linux-m68k.org)\n" );
565 panic( "no FPU" );
567 #endif