setup_mm.c 13 KB

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