1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/m68k/kernel/setup.c
4 *
5 * Copyright (C) 1995 Hamish Macdonald
6 */
7
8 /*
9 * This file handles the architecture-dependent parts of system setup
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/cpu.h>
14 #include <linux/mm.h>
15 #include <linux/sched.h>
16 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/fs.h>
19 #include <linux/console.h>
20 #include <linux/genhd.h>
21 #include <linux/errno.h>
22 #include <linux/string.h>
23 #include <linux/init.h>
24 #include <linux/memblock.h>
25 #include <linux/proc_fs.h>
26 #include <linux/seq_file.h>
27 #include <linux/module.h>
28 #include <linux/nvram.h>
29 #include <linux/initrd.h>
30
31 #include <asm/bootinfo.h>
32 #include <asm/byteorder.h>
33 #include <asm/sections.h>
34 #include <asm/setup.h>
35 #include <asm/fpu.h>
36 #include <asm/irq.h>
37 #include <asm/io.h>
38 #include <asm/machdep.h>
39 #ifdef CONFIG_AMIGA
40 #include <asm/amigahw.h>
41 #endif
42 #include <asm/atarihw.h>
43 #ifdef CONFIG_ATARI
44 #include <asm/atari_stram.h>
45 #endif
46 #ifdef CONFIG_SUN3X
47 #include <asm/dvma.h>
48 #endif
49 #include <asm/macintosh.h>
50 #include <asm/natfeat.h>
51
52 #if !FPSTATESIZE || !NR_IRQS
53 #warning No CPU/platform type selected, your kernel will not work!
54 #warning Are you building an allnoconfig kernel?
55 #endif
56
57 unsigned long m68k_machtype;
58 EXPORT_SYMBOL(m68k_machtype);
59 unsigned long m68k_cputype;
60 EXPORT_SYMBOL(m68k_cputype);
61 unsigned long m68k_fputype;
62 unsigned long m68k_mmutype;
63 EXPORT_SYMBOL(m68k_mmutype);
64 #ifdef CONFIG_VME
65 unsigned long vme_brdtype;
66 EXPORT_SYMBOL(vme_brdtype);
67 #endif
68
69 int m68k_is040or060;
70 EXPORT_SYMBOL(m68k_is040or060);
71
72 extern unsigned long availmem;
73
74 int m68k_num_memory;
75 EXPORT_SYMBOL(m68k_num_memory);
76 int m68k_realnum_memory;
77 EXPORT_SYMBOL(m68k_realnum_memory);
78 unsigned long m68k_memoffset;
79 struct m68k_mem_info m68k_memory[NUM_MEMINFO];
80 EXPORT_SYMBOL(m68k_memory);
81
82 static struct m68k_mem_info m68k_ramdisk __initdata;
83
84 static char m68k_command_line[CL_SIZE] __initdata;
85
86 void (*mach_sched_init) (void) __initdata = NULL;
87 /* machine dependent irq functions */
88 void (*mach_init_IRQ) (void) __initdata = NULL;
89 void (*mach_get_model) (char *model);
90 void (*mach_get_hardware_list) (struct seq_file *m);
91 unsigned int (*mach_get_ss)(void);
92 EXPORT_SYMBOL(mach_get_ss);
93 void (*mach_reset)( void );
94 void (*mach_halt)( void );
95 void (*mach_power_off)( void );
96 #ifdef CONFIG_HEARTBEAT
97 void (*mach_heartbeat) (int);
98 EXPORT_SYMBOL(mach_heartbeat);
99 #endif
100 #ifdef CONFIG_M68K_L2_CACHE
101 void (*mach_l2_flush) (int);
102 #endif
103 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
104 int isa_type;
105 int isa_sex;
106 EXPORT_SYMBOL(isa_type);
107 EXPORT_SYMBOL(isa_sex);
108 #endif
109
110 extern int amiga_parse_bootinfo(const struct bi_record *);
111 extern int atari_parse_bootinfo(const struct bi_record *);
112 extern int mac_parse_bootinfo(const struct bi_record *);
113 extern int q40_parse_bootinfo(const struct bi_record *);
114 extern int bvme6000_parse_bootinfo(const struct bi_record *);
115 extern int mvme16x_parse_bootinfo(const struct bi_record *);
116 extern int mvme147_parse_bootinfo(const struct bi_record *);
117 extern int hp300_parse_bootinfo(const struct bi_record *);
118 extern int apollo_parse_bootinfo(const struct bi_record *);
119
120 extern void config_amiga(void);
121 extern void config_atari(void);
122 extern void config_mac(void);
123 extern void config_sun3(void);
124 extern void config_apollo(void);
125 extern void config_mvme147(void);
126 extern void config_mvme16x(void);
127 extern void config_bvme6000(void);
128 extern void config_hp300(void);
129 extern void config_q40(void);
130 extern void config_sun3x(void);
131
132 #define MASK_256K 0xfffc0000
133
134 extern void paging_init(void);
135
m68k_parse_bootinfo(const struct bi_record * record)136 static void __init m68k_parse_bootinfo(const struct bi_record *record)
137 {
138 uint16_t tag;
139
140 save_bootinfo(record);
141
142 while ((tag = be16_to_cpu(record->tag)) != BI_LAST) {
143 int unknown = 0;
144 const void *data = record->data;
145 uint16_t size = be16_to_cpu(record->size);
146
147 switch (tag) {
148 case BI_MACHTYPE:
149 case BI_CPUTYPE:
150 case BI_FPUTYPE:
151 case BI_MMUTYPE:
152 /* Already set up by head.S */
153 break;
154
155 case BI_MEMCHUNK:
156 if (m68k_num_memory < NUM_MEMINFO) {
157 const struct mem_info *m = data;
158 m68k_memory[m68k_num_memory].addr =
159 be32_to_cpu(m->addr);
160 m68k_memory[m68k_num_memory].size =
161 be32_to_cpu(m->size);
162 m68k_num_memory++;
163 } else
164 pr_warn("%s: too many memory chunks\n",
165 __func__);
166 break;
167
168 case BI_RAMDISK:
169 {
170 const struct mem_info *m = data;
171 m68k_ramdisk.addr = be32_to_cpu(m->addr);
172 m68k_ramdisk.size = be32_to_cpu(m->size);
173 }
174 break;
175
176 case BI_COMMAND_LINE:
177 strlcpy(m68k_command_line, data,
178 sizeof(m68k_command_line));
179 break;
180
181 default:
182 if (MACH_IS_AMIGA)
183 unknown = amiga_parse_bootinfo(record);
184 else if (MACH_IS_ATARI)
185 unknown = atari_parse_bootinfo(record);
186 else if (MACH_IS_MAC)
187 unknown = mac_parse_bootinfo(record);
188 else if (MACH_IS_Q40)
189 unknown = q40_parse_bootinfo(record);
190 else if (MACH_IS_BVME6000)
191 unknown = bvme6000_parse_bootinfo(record);
192 else if (MACH_IS_MVME16x)
193 unknown = mvme16x_parse_bootinfo(record);
194 else if (MACH_IS_MVME147)
195 unknown = mvme147_parse_bootinfo(record);
196 else if (MACH_IS_HP300)
197 unknown = hp300_parse_bootinfo(record);
198 else if (MACH_IS_APOLLO)
199 unknown = apollo_parse_bootinfo(record);
200 else
201 unknown = 1;
202 }
203 if (unknown)
204 pr_warn("%s: unknown tag 0x%04x ignored\n", __func__,
205 tag);
206 record = (struct bi_record *)((unsigned long)record + size);
207 }
208
209 m68k_realnum_memory = m68k_num_memory;
210 #ifdef CONFIG_SINGLE_MEMORY_CHUNK
211 if (m68k_num_memory > 1) {
212 pr_warn("%s: ignoring last %i chunks of physical memory\n",
213 __func__, (m68k_num_memory - 1));
214 m68k_num_memory = 1;
215 }
216 #endif
217 }
218
setup_arch(char ** cmdline_p)219 void __init setup_arch(char **cmdline_p)
220 {
221 /* The bootinfo is located right after the kernel */
222 if (!CPU_IS_COLDFIRE)
223 m68k_parse_bootinfo((const struct bi_record *)_end);
224
225 if (CPU_IS_040)
226 m68k_is040or060 = 4;
227 else if (CPU_IS_060)
228 m68k_is040or060 = 6;
229
230 /* FIXME: m68k_fputype is passed in by Penguin booter, which can
231 * be confused by software FPU emulation. BEWARE.
232 * We should really do our own FPU check at startup.
233 * [what do we do with buggy 68LC040s? if we have problems
234 * with them, we should add a test to check_bugs() below] */
235 #if defined(CONFIG_FPU) && !defined(CONFIG_M68KFPU_EMU_ONLY)
236 /* clear the fpu if we have one */
237 if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060|FPU_COLDFIRE)) {
238 volatile int zero = 0;
239 asm volatile ("frestore %0" : : "m" (zero));
240 }
241 #endif
242
243 if (CPU_IS_060) {
244 u32 pcr;
245
246 asm (".chip 68060; movec %%pcr,%0; .chip 68k"
247 : "=d" (pcr));
248 if (((pcr >> 8) & 0xff) <= 5) {
249 pr_warn("Enabling workaround for errata I14\n");
250 asm (".chip 68060; movec %0,%%pcr; .chip 68k"
251 : : "d" (pcr | 0x20));
252 }
253 }
254
255 setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
256
257 #if defined(CONFIG_BOOTPARAM)
258 strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
259 m68k_command_line[CL_SIZE - 1] = 0;
260 #endif /* CONFIG_BOOTPARAM */
261 process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
262 *cmdline_p = m68k_command_line;
263 memcpy(boot_command_line, *cmdline_p, CL_SIZE);
264
265 parse_early_param();
266
267 switch (m68k_machtype) {
268 #ifdef CONFIG_AMIGA
269 case MACH_AMIGA:
270 config_amiga();
271 break;
272 #endif
273 #ifdef CONFIG_ATARI
274 case MACH_ATARI:
275 config_atari();
276 break;
277 #endif
278 #ifdef CONFIG_MAC
279 case MACH_MAC:
280 config_mac();
281 break;
282 #endif
283 #ifdef CONFIG_SUN3
284 case MACH_SUN3:
285 config_sun3();
286 break;
287 #endif
288 #ifdef CONFIG_APOLLO
289 case MACH_APOLLO:
290 config_apollo();
291 break;
292 #endif
293 #ifdef CONFIG_MVME147
294 case MACH_MVME147:
295 config_mvme147();
296 break;
297 #endif
298 #ifdef CONFIG_MVME16x
299 case MACH_MVME16x:
300 config_mvme16x();
301 break;
302 #endif
303 #ifdef CONFIG_BVME6000
304 case MACH_BVME6000:
305 config_bvme6000();
306 break;
307 #endif
308 #ifdef CONFIG_HP300
309 case MACH_HP300:
310 config_hp300();
311 break;
312 #endif
313 #ifdef CONFIG_Q40
314 case MACH_Q40:
315 config_q40();
316 break;
317 #endif
318 #ifdef CONFIG_SUN3X
319 case MACH_SUN3X:
320 config_sun3x();
321 break;
322 #endif
323 #ifdef CONFIG_COLDFIRE
324 case MACH_M54XX:
325 case MACH_M5441X:
326 cf_bootmem_alloc();
327 cf_mmu_context_init();
328 config_BSP(NULL, 0);
329 break;
330 #endif
331 default:
332 panic("No configuration setup");
333 }
334
335 paging_init();
336
337 #ifdef CONFIG_NATFEAT
338 nf_init();
339 #endif
340
341 #ifndef CONFIG_SUN3
342 #ifdef CONFIG_BLK_DEV_INITRD
343 if (m68k_ramdisk.size) {
344 memblock_reserve(m68k_ramdisk.addr, m68k_ramdisk.size);
345 initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
346 initrd_end = initrd_start + m68k_ramdisk.size;
347 pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
348 }
349 #endif
350
351 #ifdef CONFIG_ATARI
352 if (MACH_IS_ATARI)
353 atari_stram_reserve_pages((void *)availmem);
354 #endif
355 #ifdef CONFIG_SUN3X
356 if (MACH_IS_SUN3X) {
357 dvma_init();
358 }
359 #endif
360
361 #endif /* !CONFIG_SUN3 */
362
363 /* set ISA defs early as possible */
364 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
365 if (MACH_IS_Q40) {
366 isa_type = ISA_TYPE_Q40;
367 isa_sex = 0;
368 }
369 #ifdef CONFIG_AMIGA_PCMCIA
370 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)) {
371 isa_type = ISA_TYPE_AG;
372 isa_sex = 1;
373 }
374 #endif
375 #ifdef CONFIG_ATARI_ROM_ISA
376 if (MACH_IS_ATARI) {
377 isa_type = ISA_TYPE_ENEC;
378 isa_sex = 0;
379 }
380 #endif
381 #endif
382 }
383
show_cpuinfo(struct seq_file * m,void * v)384 static int show_cpuinfo(struct seq_file *m, void *v)
385 {
386 const char *cpu, *mmu, *fpu;
387 unsigned long clockfreq, clockfactor;
388
389 #define LOOP_CYCLES_68020 (8)
390 #define LOOP_CYCLES_68030 (8)
391 #define LOOP_CYCLES_68040 (3)
392 #define LOOP_CYCLES_68060 (1)
393 #define LOOP_CYCLES_COLDFIRE (2)
394
395 if (CPU_IS_020) {
396 cpu = "68020";
397 clockfactor = LOOP_CYCLES_68020;
398 } else if (CPU_IS_030) {
399 cpu = "68030";
400 clockfactor = LOOP_CYCLES_68030;
401 } else if (CPU_IS_040) {
402 cpu = "68040";
403 clockfactor = LOOP_CYCLES_68040;
404 } else if (CPU_IS_060) {
405 cpu = "68060";
406 clockfactor = LOOP_CYCLES_68060;
407 } else if (CPU_IS_COLDFIRE) {
408 cpu = "ColdFire";
409 clockfactor = LOOP_CYCLES_COLDFIRE;
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 if (m68k_fputype & FPU_COLDFIRE)
429 fpu = "ColdFire";
430 else
431 fpu = "none";
432 #endif
433
434 if (m68k_mmutype & MMU_68851)
435 mmu = "68851";
436 else if (m68k_mmutype & MMU_68030)
437 mmu = "68030";
438 else if (m68k_mmutype & MMU_68040)
439 mmu = "68040";
440 else if (m68k_mmutype & MMU_68060)
441 mmu = "68060";
442 else if (m68k_mmutype & MMU_SUN3)
443 mmu = "Sun-3";
444 else if (m68k_mmutype & MMU_APOLLO)
445 mmu = "Apollo";
446 else if (m68k_mmutype & MMU_COLDFIRE)
447 mmu = "ColdFire";
448 else
449 mmu = "unknown";
450
451 clockfreq = loops_per_jiffy * HZ * clockfactor;
452
453 seq_printf(m, "CPU:\t\t%s\n"
454 "MMU:\t\t%s\n"
455 "FPU:\t\t%s\n"
456 "Clocking:\t%lu.%1luMHz\n"
457 "BogoMips:\t%lu.%02lu\n"
458 "Calibration:\t%lu loops\n",
459 cpu, mmu, fpu,
460 clockfreq/1000000,(clockfreq/100000)%10,
461 loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
462 loops_per_jiffy);
463 return 0;
464 }
465
c_start(struct seq_file * m,loff_t * pos)466 static void *c_start(struct seq_file *m, loff_t *pos)
467 {
468 return *pos < 1 ? (void *)1 : NULL;
469 }
c_next(struct seq_file * m,void * v,loff_t * pos)470 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
471 {
472 ++*pos;
473 return NULL;
474 }
c_stop(struct seq_file * m,void * v)475 static void c_stop(struct seq_file *m, void *v)
476 {
477 }
478 const struct seq_operations cpuinfo_op = {
479 .start = c_start,
480 .next = c_next,
481 .stop = c_stop,
482 .show = show_cpuinfo,
483 };
484
485 #ifdef CONFIG_PROC_HARDWARE
hardware_proc_show(struct seq_file * m,void * v)486 static int hardware_proc_show(struct seq_file *m, void *v)
487 {
488 char model[80];
489 unsigned long mem;
490 int i;
491
492 if (mach_get_model)
493 mach_get_model(model);
494 else
495 strcpy(model, "Unknown m68k");
496
497 seq_printf(m, "Model:\t\t%s\n", model);
498 for (mem = 0, i = 0; i < m68k_num_memory; i++)
499 mem += m68k_memory[i].size;
500 seq_printf(m, "System Memory:\t%ldK\n", mem >> 10);
501
502 if (mach_get_hardware_list)
503 mach_get_hardware_list(m);
504
505 return 0;
506 }
507
proc_hardware_init(void)508 static int __init proc_hardware_init(void)
509 {
510 proc_create_single("hardware", 0, NULL, hardware_proc_show);
511 return 0;
512 }
513 module_init(proc_hardware_init);
514 #endif
515
arch_cpu_finalize_init(void)516 void __init arch_cpu_finalize_init(void)
517 {
518 #if defined(CONFIG_FPU) && !defined(CONFIG_M68KFPU_EMU)
519 if (m68k_fputype == 0) {
520 pr_emerg("*** YOU DO NOT HAVE A FLOATING POINT UNIT, "
521 "WHICH IS REQUIRED BY LINUX/M68K ***\n");
522 pr_emerg("Upgrade your hardware or join the FPU "
523 "emulation project\n");
524 panic("no FPU");
525 }
526 #endif /* !CONFIG_M68KFPU_EMU */
527 }
528
529 #ifdef CONFIG_ADB
adb_probe_sync_enable(char * str)530 static int __init adb_probe_sync_enable (char *str) {
531 extern int __adb_probe_sync;
532 __adb_probe_sync = 1;
533 return 1;
534 }
535
536 __setup("adb_sync", adb_probe_sync_enable);
537 #endif /* CONFIG_ADB */
538
539 #if IS_ENABLED(CONFIG_NVRAM)
540 #ifdef CONFIG_MAC
m68k_nvram_read_byte(int addr)541 static unsigned char m68k_nvram_read_byte(int addr)
542 {
543 if (MACH_IS_MAC)
544 return mac_pram_read_byte(addr);
545 return 0xff;
546 }
547
m68k_nvram_write_byte(unsigned char val,int addr)548 static void m68k_nvram_write_byte(unsigned char val, int addr)
549 {
550 if (MACH_IS_MAC)
551 mac_pram_write_byte(val, addr);
552 }
553 #endif /* CONFIG_MAC */
554
555 #ifdef CONFIG_ATARI
m68k_nvram_read(char * buf,size_t count,loff_t * ppos)556 static ssize_t m68k_nvram_read(char *buf, size_t count, loff_t *ppos)
557 {
558 if (MACH_IS_ATARI)
559 return atari_nvram_read(buf, count, ppos);
560 else if (MACH_IS_MAC)
561 return nvram_read_bytes(buf, count, ppos);
562 return -EINVAL;
563 }
564
m68k_nvram_write(char * buf,size_t count,loff_t * ppos)565 static ssize_t m68k_nvram_write(char *buf, size_t count, loff_t *ppos)
566 {
567 if (MACH_IS_ATARI)
568 return atari_nvram_write(buf, count, ppos);
569 else if (MACH_IS_MAC)
570 return nvram_write_bytes(buf, count, ppos);
571 return -EINVAL;
572 }
573
m68k_nvram_set_checksum(void)574 static long m68k_nvram_set_checksum(void)
575 {
576 if (MACH_IS_ATARI)
577 return atari_nvram_set_checksum();
578 return -EINVAL;
579 }
580
m68k_nvram_initialize(void)581 static long m68k_nvram_initialize(void)
582 {
583 if (MACH_IS_ATARI)
584 return atari_nvram_initialize();
585 return -EINVAL;
586 }
587 #endif /* CONFIG_ATARI */
588
m68k_nvram_get_size(void)589 static ssize_t m68k_nvram_get_size(void)
590 {
591 if (MACH_IS_ATARI)
592 return atari_nvram_get_size();
593 else if (MACH_IS_MAC)
594 return mac_pram_get_size();
595 return -ENODEV;
596 }
597
598 /* Atari device drivers call .read (to get checksum validation) whereas
599 * Mac and PowerMac device drivers just use .read_byte.
600 */
601 const struct nvram_ops arch_nvram_ops = {
602 #ifdef CONFIG_MAC
603 .read_byte = m68k_nvram_read_byte,
604 .write_byte = m68k_nvram_write_byte,
605 #endif
606 #ifdef CONFIG_ATARI
607 .read = m68k_nvram_read,
608 .write = m68k_nvram_write,
609 .set_checksum = m68k_nvram_set_checksum,
610 .initialize = m68k_nvram_initialize,
611 #endif
612 .get_size = m68k_nvram_get_size,
613 };
614 EXPORT_SYMBOL(arch_nvram_ops);
615 #endif /* CONFIG_NVRAM */
616