setup_mm.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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 defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
  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. #ifndef 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. *cmdline_p = m68k_command_line;
  246. memcpy(boot_command_line, *cmdline_p, CL_SIZE);
  247. parse_early_param();
  248. #ifdef CONFIG_DUMMY_CONSOLE
  249. conswitchp = &dummy_con;
  250. #endif
  251. switch (m68k_machtype) {
  252. #ifdef CONFIG_AMIGA
  253. case MACH_AMIGA:
  254. config_amiga();
  255. break;
  256. #endif
  257. #ifdef CONFIG_ATARI
  258. case MACH_ATARI:
  259. config_atari();
  260. break;
  261. #endif
  262. #ifdef CONFIG_MAC
  263. case MACH_MAC:
  264. config_mac();
  265. break;
  266. #endif
  267. #ifdef CONFIG_SUN3
  268. case MACH_SUN3:
  269. config_sun3();
  270. break;
  271. #endif
  272. #ifdef CONFIG_APOLLO
  273. case MACH_APOLLO:
  274. config_apollo();
  275. break;
  276. #endif
  277. #ifdef CONFIG_MVME147
  278. case MACH_MVME147:
  279. config_mvme147();
  280. break;
  281. #endif
  282. #ifdef CONFIG_MVME16x
  283. case MACH_MVME16x:
  284. config_mvme16x();
  285. break;
  286. #endif
  287. #ifdef CONFIG_BVME6000
  288. case MACH_BVME6000:
  289. config_bvme6000();
  290. break;
  291. #endif
  292. #ifdef CONFIG_HP300
  293. case MACH_HP300:
  294. config_hp300();
  295. break;
  296. #endif
  297. #ifdef CONFIG_Q40
  298. case MACH_Q40:
  299. config_q40();
  300. break;
  301. #endif
  302. #ifdef CONFIG_SUN3X
  303. case MACH_SUN3X:
  304. config_sun3x();
  305. break;
  306. #endif
  307. #ifdef CONFIG_COLDFIRE
  308. case MACH_M54XX:
  309. config_BSP(NULL, 0);
  310. break;
  311. #endif
  312. default:
  313. panic("No configuration setup");
  314. }
  315. paging_init();
  316. #ifdef CONFIG_NATFEAT
  317. nf_init();
  318. #endif
  319. #ifndef CONFIG_SUN3
  320. for (i = 1; i < m68k_num_memory; i++)
  321. free_bootmem_node(NODE_DATA(i), m68k_memory[i].addr,
  322. m68k_memory[i].size);
  323. #ifdef CONFIG_BLK_DEV_INITRD
  324. if (m68k_ramdisk.size) {
  325. reserve_bootmem_node(__virt_to_node(phys_to_virt(m68k_ramdisk.addr)),
  326. m68k_ramdisk.addr, m68k_ramdisk.size,
  327. BOOTMEM_DEFAULT);
  328. initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
  329. initrd_end = initrd_start + m68k_ramdisk.size;
  330. pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
  331. }
  332. #endif
  333. #ifdef CONFIG_ATARI
  334. if (MACH_IS_ATARI)
  335. atari_stram_reserve_pages((void *)availmem);
  336. #endif
  337. #ifdef CONFIG_SUN3X
  338. if (MACH_IS_SUN3X) {
  339. dvma_init();
  340. }
  341. #endif
  342. #endif /* !CONFIG_SUN3 */
  343. /* set ISA defs early as possible */
  344. #if defined(CONFIG_ISA) && defined(MULTI_ISA)
  345. if (MACH_IS_Q40) {
  346. isa_type = ISA_TYPE_Q40;
  347. isa_sex = 0;
  348. }
  349. #ifdef CONFIG_AMIGA_PCMCIA
  350. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)) {
  351. isa_type = ISA_TYPE_AG;
  352. isa_sex = 1;
  353. }
  354. #endif
  355. #ifdef CONFIG_ATARI_ROM_ISA
  356. if (MACH_IS_ATARI) {
  357. isa_type = ISA_TYPE_ENEC;
  358. isa_sex = 0;
  359. }
  360. #endif
  361. #endif
  362. }
  363. static int show_cpuinfo(struct seq_file *m, void *v)
  364. {
  365. const char *cpu, *mmu, *fpu;
  366. unsigned long clockfreq, clockfactor;
  367. #define LOOP_CYCLES_68020 (8)
  368. #define LOOP_CYCLES_68030 (8)
  369. #define LOOP_CYCLES_68040 (3)
  370. #define LOOP_CYCLES_68060 (1)
  371. #define LOOP_CYCLES_COLDFIRE (2)
  372. if (CPU_IS_020) {
  373. cpu = "68020";
  374. clockfactor = LOOP_CYCLES_68020;
  375. } else if (CPU_IS_030) {
  376. cpu = "68030";
  377. clockfactor = LOOP_CYCLES_68030;
  378. } else if (CPU_IS_040) {
  379. cpu = "68040";
  380. clockfactor = LOOP_CYCLES_68040;
  381. } else if (CPU_IS_060) {
  382. cpu = "68060";
  383. clockfactor = LOOP_CYCLES_68060;
  384. } else if (CPU_IS_COLDFIRE) {
  385. cpu = "ColdFire";
  386. clockfactor = LOOP_CYCLES_COLDFIRE;
  387. } else {
  388. cpu = "680x0";
  389. clockfactor = 0;
  390. }
  391. #ifdef CONFIG_M68KFPU_EMU_ONLY
  392. fpu = "none(soft float)";
  393. #else
  394. if (m68k_fputype & FPU_68881)
  395. fpu = "68881";
  396. else if (m68k_fputype & FPU_68882)
  397. fpu = "68882";
  398. else if (m68k_fputype & FPU_68040)
  399. fpu = "68040";
  400. else if (m68k_fputype & FPU_68060)
  401. fpu = "68060";
  402. else if (m68k_fputype & FPU_SUNFPA)
  403. fpu = "Sun FPA";
  404. else if (m68k_fputype & FPU_COLDFIRE)
  405. fpu = "ColdFire";
  406. else
  407. fpu = "none";
  408. #endif
  409. if (m68k_mmutype & MMU_68851)
  410. mmu = "68851";
  411. else if (m68k_mmutype & MMU_68030)
  412. mmu = "68030";
  413. else if (m68k_mmutype & MMU_68040)
  414. mmu = "68040";
  415. else if (m68k_mmutype & MMU_68060)
  416. mmu = "68060";
  417. else if (m68k_mmutype & MMU_SUN3)
  418. mmu = "Sun-3";
  419. else if (m68k_mmutype & MMU_APOLLO)
  420. mmu = "Apollo";
  421. else if (m68k_mmutype & MMU_COLDFIRE)
  422. mmu = "ColdFire";
  423. else
  424. mmu = "unknown";
  425. clockfreq = loops_per_jiffy * HZ * clockfactor;
  426. seq_printf(m, "CPU:\t\t%s\n"
  427. "MMU:\t\t%s\n"
  428. "FPU:\t\t%s\n"
  429. "Clocking:\t%lu.%1luMHz\n"
  430. "BogoMips:\t%lu.%02lu\n"
  431. "Calibration:\t%lu loops\n",
  432. cpu, mmu, fpu,
  433. clockfreq/1000000,(clockfreq/100000)%10,
  434. loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
  435. loops_per_jiffy);
  436. return 0;
  437. }
  438. static void *c_start(struct seq_file *m, loff_t *pos)
  439. {
  440. return *pos < 1 ? (void *)1 : NULL;
  441. }
  442. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  443. {
  444. ++*pos;
  445. return NULL;
  446. }
  447. static void c_stop(struct seq_file *m, void *v)
  448. {
  449. }
  450. const struct seq_operations cpuinfo_op = {
  451. .start = c_start,
  452. .next = c_next,
  453. .stop = c_stop,
  454. .show = show_cpuinfo,
  455. };
  456. #ifdef CONFIG_PROC_HARDWARE
  457. static int hardware_proc_show(struct seq_file *m, void *v)
  458. {
  459. char model[80];
  460. unsigned long mem;
  461. int i;
  462. if (mach_get_model)
  463. mach_get_model(model);
  464. else
  465. strcpy(model, "Unknown m68k");
  466. seq_printf(m, "Model:\t\t%s\n", model);
  467. for (mem = 0, i = 0; i < m68k_num_memory; i++)
  468. mem += m68k_memory[i].size;
  469. seq_printf(m, "System Memory:\t%ldK\n", mem >> 10);
  470. if (mach_get_hardware_list)
  471. mach_get_hardware_list(m);
  472. return 0;
  473. }
  474. static int hardware_proc_open(struct inode *inode, struct file *file)
  475. {
  476. return single_open(file, hardware_proc_show, NULL);
  477. }
  478. static const struct file_operations hardware_proc_fops = {
  479. .open = hardware_proc_open,
  480. .read = seq_read,
  481. .llseek = seq_lseek,
  482. .release = single_release,
  483. };
  484. static int __init proc_hardware_init(void)
  485. {
  486. proc_create("hardware", 0, NULL, &hardware_proc_fops);
  487. return 0;
  488. }
  489. module_init(proc_hardware_init);
  490. #endif
  491. void check_bugs(void)
  492. {
  493. #ifndef CONFIG_M68KFPU_EMU
  494. if (m68k_fputype == 0) {
  495. pr_emerg("*** YOU DO NOT HAVE A FLOATING POINT UNIT, "
  496. "WHICH IS REQUIRED BY LINUX/M68K ***\n");
  497. pr_emerg("Upgrade your hardware or join the FPU "
  498. "emulation project\n");
  499. panic("no FPU");
  500. }
  501. #endif /* !CONFIG_M68KFPU_EMU */
  502. }
  503. #ifdef CONFIG_ADB
  504. static int __init adb_probe_sync_enable (char *str) {
  505. extern int __adb_probe_sync;
  506. __adb_probe_sync = 1;
  507. return 1;
  508. }
  509. __setup("adb_sync", adb_probe_sync_enable);
  510. #endif /* CONFIG_ADB */