setup_mm.c 14 KB

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