setup_mm.c 13 KB

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