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