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