1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/m68k/kernel/setup.c
5 * Copyright (C) 1995 Hamish Macdonald
9 * This file handles the architecture-dependent parts of system setup
12 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/delay.h>
16 #include <linux/interrupt.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>
29 #include <asm/bootinfo.h>
30 #include <asm/byteorder.h>
31 #include <asm/sections.h>
32 #include <asm/setup.h>
36 #include <asm/machdep.h>
38 #include <asm/amigahw.h>
40 #include <asm/atarihw.h>
42 #include <asm/atari_stram.h>
47 #include <asm/macintosh.h>
48 #include <asm/natfeat.h>
49 #include <asm/config.h>
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?
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);
64 unsigned long vme_brdtype;
65 EXPORT_SYMBOL(vme_brdtype);
69 EXPORT_SYMBOL(m68k_is040or060);
71 extern unsigned long availmem;
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);
81 static struct m68k_mem_info m68k_ramdisk __initdata;
83 static char m68k_command_line[CL_SIZE] __initdata;
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);
96 #ifdef CONFIG_M68K_L2_CACHE
97 void (*mach_l2_flush) (int);
99 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
102 EXPORT_SYMBOL(isa_type);
103 EXPORT_SYMBOL(isa_sex);
106 #define MASK_256K 0xfffc0000
108 extern void paging_init(void);
110 static void __init m68k_parse_bootinfo(const struct bi_record *record)
114 save_bootinfo(record);
116 while ((tag = be16_to_cpu(record->tag)) != BI_LAST) {
118 const void *data = record->data;
119 uint16_t size = be16_to_cpu(record->size);
126 /* Already set up by head.S */
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);
138 pr_warn("%s: too many memory chunks\n",
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);
150 case BI_COMMAND_LINE:
151 strlcpy(m68k_command_line, data,
152 sizeof(m68k_command_line));
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);
180 pr_warn("%s: unknown tag 0x%04x ignored\n", __func__,
182 record = (struct bi_record *)((unsigned long)record + size);
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));
195 void __init setup_arch(char **cmdline_p)
197 /* The bootinfo is located right after the kernel */
198 if (!CPU_IS_COLDFIRE)
199 m68k_parse_bootinfo((const struct bi_record *)_end);
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));
222 asm (".chip 68060; movec %%pcr,%0; .chip 68k"
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));
231 setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
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);
243 switch (m68k_machtype) {
269 #ifdef CONFIG_MVME147
274 #ifdef CONFIG_MVME16x
279 #ifdef CONFIG_BVME6000
299 #ifdef CONFIG_COLDFIRE
303 cf_mmu_context_init();
313 panic("No configuration setup");
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);
327 #ifdef CONFIG_NATFEAT
333 atari_stram_reserve_pages((void *)availmem);
341 /* set ISA defs early as possible */
342 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
344 isa_type = ISA_TYPE_Q40;
347 #ifdef CONFIG_AMIGA_PCMCIA
348 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)) {
349 isa_type = ISA_TYPE_AG;
353 #ifdef CONFIG_ATARI_ROM_ISA
355 isa_type = ISA_TYPE_ENEC;
362 static int show_cpuinfo(struct seq_file *m, void *v)
364 const char *cpu, *mmu, *fpu;
365 unsigned long clockfreq, clockfactor;
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)
375 clockfactor = LOOP_CYCLES_68020;
376 } else if (CPU_IS_030) {
378 clockfactor = LOOP_CYCLES_68030;
379 } else if (CPU_IS_040) {
381 clockfactor = LOOP_CYCLES_68040;
382 } else if (CPU_IS_060) {
384 clockfactor = LOOP_CYCLES_68060;
385 } else if (CPU_IS_COLDFIRE) {
387 clockfactor = LOOP_CYCLES_COLDFIRE;
393 #ifdef CONFIG_M68KFPU_EMU_ONLY
394 fpu = "none(soft float)";
396 if (m68k_fputype & FPU_68881)
398 else if (m68k_fputype & FPU_68882)
400 else if (m68k_fputype & FPU_68040)
402 else if (m68k_fputype & FPU_68060)
404 else if (m68k_fputype & FPU_SUNFPA)
406 else if (m68k_fputype & FPU_COLDFIRE)
412 if (m68k_mmutype & MMU_68851)
414 else if (m68k_mmutype & MMU_68030)
416 else if (m68k_mmutype & MMU_68040)
418 else if (m68k_mmutype & MMU_68060)
420 else if (m68k_mmutype & MMU_SUN3)
422 else if (m68k_mmutype & MMU_APOLLO)
424 else if (m68k_mmutype & MMU_COLDFIRE)
429 clockfreq = loops_per_jiffy * HZ * clockfactor;
431 seq_printf(m, "CPU:\t\t%s\n"
434 "Clocking:\t%lu.%1luMHz\n"
435 "BogoMips:\t%lu.%02lu\n"
436 "Calibration:\t%lu loops\n",
438 clockfreq/1000000,(clockfreq/100000)%10,
439 loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
444 static void *c_start(struct seq_file *m, loff_t *pos)
446 return *pos < 1 ? (void *)1 : NULL;
448 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
453 static void c_stop(struct seq_file *m, void *v)
456 const struct seq_operations cpuinfo_op = {
460 .show = show_cpuinfo,
463 #ifdef CONFIG_PROC_HARDWARE
464 static int hardware_proc_show(struct seq_file *m, void *v)
471 mach_get_model(model);
473 strcpy(model, "Unknown m68k");
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);
480 if (mach_get_hardware_list)
481 mach_get_hardware_list(m);
486 static int __init proc_hardware_init(void)
488 proc_create_single("hardware", 0, NULL, hardware_proc_show);
491 module_init(proc_hardware_init);
494 void check_bugs(void)
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");
504 #endif /* !CONFIG_M68KFPU_EMU */
508 static int __init adb_probe_sync_enable (char *str) {
509 extern int __adb_probe_sync;
510 __adb_probe_sync = 1;
514 __setup("adb_sync", adb_probe_sync_enable);
515 #endif /* CONFIG_ADB */
517 #if IS_ENABLED(CONFIG_NVRAM)
519 static unsigned char m68k_nvram_read_byte(int addr)
522 return mac_pram_read_byte(addr);
526 static void m68k_nvram_write_byte(unsigned char val, int addr)
529 mac_pram_write_byte(val, addr);
531 #endif /* CONFIG_MAC */
534 static ssize_t m68k_nvram_read(char *buf, size_t count, loff_t *ppos)
537 return atari_nvram_read(buf, count, ppos);
538 else if (MACH_IS_MAC)
539 return nvram_read_bytes(buf, count, ppos);
543 static ssize_t m68k_nvram_write(char *buf, size_t count, loff_t *ppos)
546 return atari_nvram_write(buf, count, ppos);
547 else if (MACH_IS_MAC)
548 return nvram_write_bytes(buf, count, ppos);
552 static long m68k_nvram_set_checksum(void)
555 return atari_nvram_set_checksum();
559 static long m68k_nvram_initialize(void)
562 return atari_nvram_initialize();
565 #endif /* CONFIG_ATARI */
567 static ssize_t m68k_nvram_get_size(void)
570 return atari_nvram_get_size();
571 else if (MACH_IS_MAC)
572 return mac_pram_get_size();
576 /* Atari device drivers call .read (to get checksum validation) whereas
577 * Mac and PowerMac device drivers just use .read_byte.
579 const struct nvram_ops arch_nvram_ops = {
581 .read_byte = m68k_nvram_read_byte,
582 .write_byte = m68k_nvram_write_byte,
585 .read = m68k_nvram_read,
586 .write = m68k_nvram_write,
587 .set_checksum = m68k_nvram_set_checksum,
588 .initialize = m68k_nvram_initialize,
590 .get_size = m68k_nvram_get_size,
592 EXPORT_SYMBOL(arch_nvram_ops);
593 #endif /* CONFIG_NVRAM */