setup_mm.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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/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. int (*mach_set_clock_mmss) (unsigned long);
  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. #ifndef CONFIG_SUN3
  203. int i;
  204. #endif
  205. /* The bootinfo is located right after the kernel */
  206. if (!CPU_IS_COLDFIRE)
  207. m68k_parse_bootinfo((const struct bi_record *)_end);
  208. if (CPU_IS_040)
  209. m68k_is040or060 = 4;
  210. else if (CPU_IS_060)
  211. m68k_is040or060 = 6;
  212. /* FIXME: m68k_fputype is passed in by Penguin booter, which can
  213. * be confused by software FPU emulation. BEWARE.
  214. * We should really do our own FPU check at startup.
  215. * [what do we do with buggy 68LC040s? if we have problems
  216. * with them, we should add a test to check_bugs() below] */
  217. #if defined(CONFIG_FPU) && !defined(CONFIG_M68KFPU_EMU_ONLY)
  218. /* clear the fpu if we have one */
  219. if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060|FPU_COLDFIRE)) {
  220. volatile int zero = 0;
  221. asm volatile ("frestore %0" : : "m" (zero));
  222. }
  223. #endif
  224. if (CPU_IS_060) {
  225. u32 pcr;
  226. asm (".chip 68060; movec %%pcr,%0; .chip 68k"
  227. : "=d" (pcr));
  228. if (((pcr >> 8) & 0xff) <= 5) {
  229. pr_warn("Enabling workaround for errata I14\n");
  230. asm (".chip 68060; movec %0,%%pcr; .chip 68k"
  231. : : "d" (pcr | 0x20));
  232. }
  233. }
  234. init_mm.start_code = PAGE_OFFSET;
  235. init_mm.end_code = (unsigned long)_etext;
  236. init_mm.end_data = (unsigned long)_edata;
  237. init_mm.brk = (unsigned long)_end;
  238. #if defined(CONFIG_BOOTPARAM)
  239. strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
  240. m68k_command_line[CL_SIZE - 1] = 0;
  241. #endif /* CONFIG_BOOTPARAM */
  242. process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
  243. *cmdline_p = m68k_command_line;
  244. memcpy(boot_command_line, *cmdline_p, CL_SIZE);
  245. parse_early_param();
  246. #ifdef CONFIG_DUMMY_CONSOLE
  247. conswitchp = &dummy_con;
  248. #endif
  249. switch (m68k_machtype) {
  250. #ifdef CONFIG_AMIGA
  251. case MACH_AMIGA:
  252. config_amiga();
  253. break;
  254. #endif
  255. #ifdef CONFIG_ATARI
  256. case MACH_ATARI:
  257. config_atari();
  258. break;
  259. #endif
  260. #ifdef CONFIG_MAC
  261. case MACH_MAC:
  262. config_mac();
  263. break;
  264. #endif
  265. #ifdef CONFIG_SUN3
  266. case MACH_SUN3:
  267. config_sun3();
  268. break;
  269. #endif
  270. #ifdef CONFIG_APOLLO
  271. case MACH_APOLLO:
  272. config_apollo();
  273. break;
  274. #endif
  275. #ifdef CONFIG_MVME147
  276. case MACH_MVME147:
  277. config_mvme147();
  278. break;
  279. #endif
  280. #ifdef CONFIG_MVME16x
  281. case MACH_MVME16x:
  282. config_mvme16x();
  283. break;
  284. #endif
  285. #ifdef CONFIG_BVME6000
  286. case MACH_BVME6000:
  287. config_bvme6000();
  288. break;
  289. #endif
  290. #ifdef CONFIG_HP300
  291. case MACH_HP300:
  292. config_hp300();
  293. break;
  294. #endif
  295. #ifdef CONFIG_Q40
  296. case MACH_Q40:
  297. config_q40();
  298. break;
  299. #endif
  300. #ifdef CONFIG_SUN3X
  301. case MACH_SUN3X:
  302. config_sun3x();
  303. break;
  304. #endif
  305. #ifdef CONFIG_COLDFIRE
  306. case MACH_M54XX:
  307. case MACH_M5441X:
  308. cf_bootmem_alloc();
  309. cf_mmu_context_init();
  310. config_BSP(NULL, 0);
  311. break;
  312. #endif
  313. default:
  314. panic("No configuration setup");
  315. }
  316. paging_init();
  317. #ifdef CONFIG_NATFEAT
  318. nf_init();
  319. #endif
  320. #ifndef CONFIG_SUN3
  321. for (i = 1; i < m68k_num_memory; i++)
  322. free_bootmem_node(NODE_DATA(i), m68k_memory[i].addr,
  323. m68k_memory[i].size);
  324. #ifdef CONFIG_BLK_DEV_INITRD
  325. if (m68k_ramdisk.size) {
  326. reserve_bootmem_node(__virt_to_node(phys_to_virt(m68k_ramdisk.addr)),
  327. m68k_ramdisk.addr, m68k_ramdisk.size,
  328. BOOTMEM_DEFAULT);
  329. initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
  330. initrd_end = initrd_start + m68k_ramdisk.size;
  331. pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
  332. }
  333. #endif
  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. #endif /* !CONFIG_SUN3 */
  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. static int show_cpuinfo(struct seq_file *m, void *v)
  365. {
  366. const char *cpu, *mmu, *fpu;
  367. unsigned long clockfreq, clockfactor;
  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. if (CPU_IS_020) {
  374. cpu = "68020";
  375. clockfactor = LOOP_CYCLES_68020;
  376. } else if (CPU_IS_030) {
  377. cpu = "68030";
  378. clockfactor = LOOP_CYCLES_68030;
  379. } else if (CPU_IS_040) {
  380. cpu = "68040";
  381. clockfactor = LOOP_CYCLES_68040;
  382. } else if (CPU_IS_060) {
  383. cpu = "68060";
  384. clockfactor = LOOP_CYCLES_68060;
  385. } else if (CPU_IS_COLDFIRE) {
  386. cpu = "ColdFire";
  387. clockfactor = LOOP_CYCLES_COLDFIRE;
  388. } else {
  389. cpu = "680x0";
  390. clockfactor = 0;
  391. }
  392. #ifdef CONFIG_M68KFPU_EMU_ONLY
  393. fpu = "none(soft float)";
  394. #else
  395. if (m68k_fputype & FPU_68881)
  396. fpu = "68881";
  397. else if (m68k_fputype & FPU_68882)
  398. fpu = "68882";
  399. else if (m68k_fputype & FPU_68040)
  400. fpu = "68040";
  401. else if (m68k_fputype & FPU_68060)
  402. fpu = "68060";
  403. else if (m68k_fputype & FPU_SUNFPA)
  404. fpu = "Sun FPA";
  405. else if (m68k_fputype & FPU_COLDFIRE)
  406. fpu = "ColdFire";
  407. else
  408. fpu = "none";
  409. #endif
  410. if (m68k_mmutype & MMU_68851)
  411. mmu = "68851";
  412. else if (m68k_mmutype & MMU_68030)
  413. mmu = "68030";
  414. else if (m68k_mmutype & MMU_68040)
  415. mmu = "68040";
  416. else if (m68k_mmutype & MMU_68060)
  417. mmu = "68060";
  418. else if (m68k_mmutype & MMU_SUN3)
  419. mmu = "Sun-3";
  420. else if (m68k_mmutype & MMU_APOLLO)
  421. mmu = "Apollo";
  422. else if (m68k_mmutype & MMU_COLDFIRE)
  423. mmu = "ColdFire";
  424. else
  425. mmu = "unknown";
  426. clockfreq = loops_per_jiffy * HZ * clockfactor;
  427. seq_printf(m, "CPU:\t\t%s\n"
  428. "MMU:\t\t%s\n"
  429. "FPU:\t\t%s\n"
  430. "Clocking:\t%lu.%1luMHz\n"
  431. "BogoMips:\t%lu.%02lu\n"
  432. "Calibration:\t%lu loops\n",
  433. cpu, mmu, fpu,
  434. clockfreq/1000000,(clockfreq/100000)%10,
  435. loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
  436. loops_per_jiffy);
  437. return 0;
  438. }
  439. static void *c_start(struct seq_file *m, loff_t *pos)
  440. {
  441. return *pos < 1 ? (void *)1 : NULL;
  442. }
  443. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  444. {
  445. ++*pos;
  446. return NULL;
  447. }
  448. static void c_stop(struct seq_file *m, void *v)
  449. {
  450. }
  451. const struct seq_operations cpuinfo_op = {
  452. .start = c_start,
  453. .next = c_next,
  454. .stop = c_stop,
  455. .show = show_cpuinfo,
  456. };
  457. #ifdef CONFIG_PROC_HARDWARE
  458. static int hardware_proc_show(struct seq_file *m, void *v)
  459. {
  460. char model[80];
  461. unsigned long mem;
  462. int i;
  463. if (mach_get_model)
  464. mach_get_model(model);
  465. else
  466. strcpy(model, "Unknown m68k");
  467. seq_printf(m, "Model:\t\t%s\n", model);
  468. for (mem = 0, i = 0; i < m68k_num_memory; i++)
  469. mem += m68k_memory[i].size;
  470. seq_printf(m, "System Memory:\t%ldK\n", mem >> 10);
  471. if (mach_get_hardware_list)
  472. mach_get_hardware_list(m);
  473. return 0;
  474. }
  475. static int __init proc_hardware_init(void)
  476. {
  477. proc_create_single("hardware", 0, NULL, hardware_proc_show);
  478. return 0;
  479. }
  480. module_init(proc_hardware_init);
  481. #endif
  482. void check_bugs(void)
  483. {
  484. #if defined(CONFIG_FPU) && !defined(CONFIG_M68KFPU_EMU)
  485. if (m68k_fputype == 0) {
  486. pr_emerg("*** YOU DO NOT HAVE A FLOATING POINT UNIT, "
  487. "WHICH IS REQUIRED BY LINUX/M68K ***\n");
  488. pr_emerg("Upgrade your hardware or join the FPU "
  489. "emulation project\n");
  490. panic("no FPU");
  491. }
  492. #endif /* !CONFIG_M68KFPU_EMU */
  493. }
  494. #ifdef CONFIG_ADB
  495. static int __init adb_probe_sync_enable (char *str) {
  496. extern int __adb_probe_sync;
  497. __adb_probe_sync = 1;
  498. return 1;
  499. }
  500. __setup("adb_sync", adb_probe_sync_enable);
  501. #endif /* CONFIG_ADB */