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