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