setup_64.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * linux/arch/sparc64/kernel/setup.c
  3. *
  4. * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/sched.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mm.h>
  11. #include <linux/stddef.h>
  12. #include <linux/unistd.h>
  13. #include <linux/ptrace.h>
  14. #include <asm/smp.h>
  15. #include <linux/user.h>
  16. #include <linux/screen_info.h>
  17. #include <linux/delay.h>
  18. #include <linux/fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/syscalls.h>
  21. #include <linux/kdev_t.h>
  22. #include <linux/major.h>
  23. #include <linux/string.h>
  24. #include <linux/init.h>
  25. #include <linux/inet.h>
  26. #include <linux/console.h>
  27. #include <linux/root_dev.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/cpu.h>
  30. #include <linux/initrd.h>
  31. #include <linux/module.h>
  32. #include <asm/io.h>
  33. #include <asm/processor.h>
  34. #include <asm/oplib.h>
  35. #include <asm/page.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/idprom.h>
  38. #include <asm/head.h>
  39. #include <asm/starfire.h>
  40. #include <asm/mmu_context.h>
  41. #include <asm/timer.h>
  42. #include <asm/sections.h>
  43. #include <asm/setup.h>
  44. #include <asm/mmu.h>
  45. #include <asm/ns87303.h>
  46. #include <asm/btext.h>
  47. #include <asm/elf.h>
  48. #include <asm/mdesc.h>
  49. #include <asm/cacheflush.h>
  50. #ifdef CONFIG_IP_PNP
  51. #include <net/ipconfig.h>
  52. #endif
  53. #include "entry.h"
  54. #include "kernel.h"
  55. /* Used to synchronize accesses to NatSemi SUPER I/O chip configure
  56. * operations in asm/ns87303.h
  57. */
  58. DEFINE_SPINLOCK(ns87303_lock);
  59. EXPORT_SYMBOL(ns87303_lock);
  60. struct screen_info screen_info = {
  61. 0, 0, /* orig-x, orig-y */
  62. 0, /* unused */
  63. 0, /* orig-video-page */
  64. 0, /* orig-video-mode */
  65. 128, /* orig-video-cols */
  66. 0, 0, 0, /* unused, ega_bx, unused */
  67. 54, /* orig-video-lines */
  68. 0, /* orig-video-isVGA */
  69. 16 /* orig-video-points */
  70. };
  71. static void
  72. prom_console_write(struct console *con, const char *s, unsigned n)
  73. {
  74. prom_write(s, n);
  75. }
  76. /* Exported for mm/init.c:paging_init. */
  77. unsigned long cmdline_memory_size = 0;
  78. static struct console prom_early_console = {
  79. .name = "earlyprom",
  80. .write = prom_console_write,
  81. .flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
  82. .index = -1,
  83. };
  84. /*
  85. * Process kernel command line switches that are specific to the
  86. * SPARC or that require special low-level processing.
  87. */
  88. static void __init process_switch(char c)
  89. {
  90. switch (c) {
  91. case 'd':
  92. case 's':
  93. break;
  94. case 'h':
  95. prom_printf("boot_flags_init: Halt!\n");
  96. prom_halt();
  97. break;
  98. case 'p':
  99. prom_early_console.flags &= ~CON_BOOT;
  100. break;
  101. case 'P':
  102. /* Force UltraSPARC-III P-Cache on. */
  103. if (tlb_type != cheetah) {
  104. printk("BOOT: Ignoring P-Cache force option.\n");
  105. break;
  106. }
  107. cheetah_pcache_forced_on = 1;
  108. add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
  109. cheetah_enable_pcache();
  110. break;
  111. default:
  112. printk("Unknown boot switch (-%c)\n", c);
  113. break;
  114. }
  115. }
  116. static void __init boot_flags_init(char *commands)
  117. {
  118. while (*commands) {
  119. /* Move to the start of the next "argument". */
  120. while (*commands && *commands == ' ')
  121. commands++;
  122. /* Process any command switches, otherwise skip it. */
  123. if (*commands == '\0')
  124. break;
  125. if (*commands == '-') {
  126. commands++;
  127. while (*commands && *commands != ' ')
  128. process_switch(*commands++);
  129. continue;
  130. }
  131. if (!strncmp(commands, "mem=", 4))
  132. cmdline_memory_size = memparse(commands + 4, &commands);
  133. while (*commands && *commands != ' ')
  134. commands++;
  135. }
  136. }
  137. extern unsigned short root_flags;
  138. extern unsigned short root_dev;
  139. extern unsigned short ram_flags;
  140. #define RAMDISK_IMAGE_START_MASK 0x07FF
  141. #define RAMDISK_PROMPT_FLAG 0x8000
  142. #define RAMDISK_LOAD_FLAG 0x4000
  143. extern int root_mountflags;
  144. char reboot_command[COMMAND_LINE_SIZE];
  145. static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
  146. void __init per_cpu_patch(void)
  147. {
  148. struct cpuid_patch_entry *p;
  149. unsigned long ver;
  150. int is_jbus;
  151. if (tlb_type == spitfire && !this_is_starfire)
  152. return;
  153. is_jbus = 0;
  154. if (tlb_type != hypervisor) {
  155. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  156. is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
  157. (ver >> 32UL) == __SERRANO_ID);
  158. }
  159. p = &__cpuid_patch;
  160. while (p < &__cpuid_patch_end) {
  161. unsigned long addr = p->addr;
  162. unsigned int *insns;
  163. switch (tlb_type) {
  164. case spitfire:
  165. insns = &p->starfire[0];
  166. break;
  167. case cheetah:
  168. case cheetah_plus:
  169. if (is_jbus)
  170. insns = &p->cheetah_jbus[0];
  171. else
  172. insns = &p->cheetah_safari[0];
  173. break;
  174. case hypervisor:
  175. insns = &p->sun4v[0];
  176. break;
  177. default:
  178. prom_printf("Unknown cpu type, halting.\n");
  179. prom_halt();
  180. }
  181. *(unsigned int *) (addr + 0) = insns[0];
  182. wmb();
  183. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  184. *(unsigned int *) (addr + 4) = insns[1];
  185. wmb();
  186. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  187. *(unsigned int *) (addr + 8) = insns[2];
  188. wmb();
  189. __asm__ __volatile__("flush %0" : : "r" (addr + 8));
  190. *(unsigned int *) (addr + 12) = insns[3];
  191. wmb();
  192. __asm__ __volatile__("flush %0" : : "r" (addr + 12));
  193. p++;
  194. }
  195. }
  196. void sun4v_patch_1insn_range(struct sun4v_1insn_patch_entry *start,
  197. struct sun4v_1insn_patch_entry *end)
  198. {
  199. while (start < end) {
  200. unsigned long addr = start->addr;
  201. *(unsigned int *) (addr + 0) = start->insn;
  202. wmb();
  203. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  204. start++;
  205. }
  206. }
  207. void sun4v_patch_2insn_range(struct sun4v_2insn_patch_entry *start,
  208. struct sun4v_2insn_patch_entry *end)
  209. {
  210. while (start < end) {
  211. unsigned long addr = start->addr;
  212. *(unsigned int *) (addr + 0) = start->insns[0];
  213. wmb();
  214. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  215. *(unsigned int *) (addr + 4) = start->insns[1];
  216. wmb();
  217. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  218. start++;
  219. }
  220. }
  221. void __init sun4v_patch(void)
  222. {
  223. extern void sun4v_hvapi_init(void);
  224. if (tlb_type != hypervisor)
  225. return;
  226. sun4v_patch_1insn_range(&__sun4v_1insn_patch,
  227. &__sun4v_1insn_patch_end);
  228. sun4v_patch_2insn_range(&__sun4v_2insn_patch,
  229. &__sun4v_2insn_patch_end);
  230. sun4v_hvapi_init();
  231. }
  232. static void __init popc_patch(void)
  233. {
  234. struct popc_3insn_patch_entry *p3;
  235. struct popc_6insn_patch_entry *p6;
  236. p3 = &__popc_3insn_patch;
  237. while (p3 < &__popc_3insn_patch_end) {
  238. unsigned long i, addr = p3->addr;
  239. for (i = 0; i < 3; i++) {
  240. *(unsigned int *) (addr + (i * 4)) = p3->insns[i];
  241. wmb();
  242. __asm__ __volatile__("flush %0"
  243. : : "r" (addr + (i * 4)));
  244. }
  245. p3++;
  246. }
  247. p6 = &__popc_6insn_patch;
  248. while (p6 < &__popc_6insn_patch_end) {
  249. unsigned long i, addr = p6->addr;
  250. for (i = 0; i < 6; i++) {
  251. *(unsigned int *) (addr + (i * 4)) = p6->insns[i];
  252. wmb();
  253. __asm__ __volatile__("flush %0"
  254. : : "r" (addr + (i * 4)));
  255. }
  256. p6++;
  257. }
  258. }
  259. static void __init pause_patch(void)
  260. {
  261. struct pause_patch_entry *p;
  262. p = &__pause_3insn_patch;
  263. while (p < &__pause_3insn_patch_end) {
  264. unsigned long i, addr = p->addr;
  265. for (i = 0; i < 3; i++) {
  266. *(unsigned int *) (addr + (i * 4)) = p->insns[i];
  267. wmb();
  268. __asm__ __volatile__("flush %0"
  269. : : "r" (addr + (i * 4)));
  270. }
  271. p++;
  272. }
  273. }
  274. #ifdef CONFIG_SMP
  275. void __init boot_cpu_id_too_large(int cpu)
  276. {
  277. prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
  278. cpu, NR_CPUS);
  279. prom_halt();
  280. }
  281. #endif
  282. /* On Ultra, we support all of the v8 capabilities. */
  283. unsigned long sparc64_elf_hwcap = (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
  284. HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV |
  285. HWCAP_SPARC_V9);
  286. EXPORT_SYMBOL(sparc64_elf_hwcap);
  287. static const char *hwcaps[] = {
  288. "flush", "stbar", "swap", "muldiv", "v9",
  289. "ultra3", "blkinit", "n2",
  290. /* These strings are as they appear in the machine description
  291. * 'hwcap-list' property for cpu nodes.
  292. */
  293. "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
  294. "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
  295. "ima", "cspare", "pause", "cbcond",
  296. };
  297. static const char *crypto_hwcaps[] = {
  298. "aes", "des", "kasumi", "camellia", "md5", "sha1", "sha256",
  299. "sha512", "mpmul", "montmul", "montsqr", "crc32c",
  300. };
  301. void cpucap_info(struct seq_file *m)
  302. {
  303. unsigned long caps = sparc64_elf_hwcap;
  304. int i, printed = 0;
  305. seq_puts(m, "cpucaps\t\t: ");
  306. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  307. unsigned long bit = 1UL << i;
  308. if (caps & bit) {
  309. seq_printf(m, "%s%s",
  310. printed ? "," : "", hwcaps[i]);
  311. printed++;
  312. }
  313. }
  314. if (caps & HWCAP_SPARC_CRYPTO) {
  315. unsigned long cfr;
  316. __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
  317. for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
  318. unsigned long bit = 1UL << i;
  319. if (cfr & bit) {
  320. seq_printf(m, "%s%s",
  321. printed ? "," : "", crypto_hwcaps[i]);
  322. printed++;
  323. }
  324. }
  325. }
  326. seq_putc(m, '\n');
  327. }
  328. static void __init report_one_hwcap(int *printed, const char *name)
  329. {
  330. if ((*printed) == 0)
  331. printk(KERN_INFO "CPU CAPS: [");
  332. printk(KERN_CONT "%s%s",
  333. (*printed) ? "," : "", name);
  334. if (++(*printed) == 8) {
  335. printk(KERN_CONT "]\n");
  336. *printed = 0;
  337. }
  338. }
  339. static void __init report_crypto_hwcaps(int *printed)
  340. {
  341. unsigned long cfr;
  342. int i;
  343. __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
  344. for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
  345. unsigned long bit = 1UL << i;
  346. if (cfr & bit)
  347. report_one_hwcap(printed, crypto_hwcaps[i]);
  348. }
  349. }
  350. static void __init report_hwcaps(unsigned long caps)
  351. {
  352. int i, printed = 0;
  353. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  354. unsigned long bit = 1UL << i;
  355. if (caps & bit)
  356. report_one_hwcap(&printed, hwcaps[i]);
  357. }
  358. if (caps & HWCAP_SPARC_CRYPTO)
  359. report_crypto_hwcaps(&printed);
  360. if (printed != 0)
  361. printk(KERN_CONT "]\n");
  362. }
  363. static unsigned long __init mdesc_cpu_hwcap_list(void)
  364. {
  365. struct mdesc_handle *hp;
  366. unsigned long caps = 0;
  367. const char *prop;
  368. int len;
  369. u64 pn;
  370. hp = mdesc_grab();
  371. if (!hp)
  372. return 0;
  373. pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "cpu");
  374. if (pn == MDESC_NODE_NULL)
  375. goto out;
  376. prop = mdesc_get_property(hp, pn, "hwcap-list", &len);
  377. if (!prop)
  378. goto out;
  379. while (len) {
  380. int i, plen;
  381. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  382. unsigned long bit = 1UL << i;
  383. if (!strcmp(prop, hwcaps[i])) {
  384. caps |= bit;
  385. break;
  386. }
  387. }
  388. for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
  389. if (!strcmp(prop, crypto_hwcaps[i]))
  390. caps |= HWCAP_SPARC_CRYPTO;
  391. }
  392. plen = strlen(prop) + 1;
  393. prop += plen;
  394. len -= plen;
  395. }
  396. out:
  397. mdesc_release(hp);
  398. return caps;
  399. }
  400. /* This yields a mask that user programs can use to figure out what
  401. * instruction set this cpu supports.
  402. */
  403. static void __init init_sparc64_elf_hwcap(void)
  404. {
  405. unsigned long cap = sparc64_elf_hwcap;
  406. unsigned long mdesc_caps;
  407. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  408. cap |= HWCAP_SPARC_ULTRA3;
  409. else if (tlb_type == hypervisor) {
  410. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 ||
  411. sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  412. sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  413. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  414. sun4v_chip_type == SUN4V_CHIP_NIAGARA5 ||
  415. sun4v_chip_type == SUN4V_CHIP_SPARC_M6 ||
  416. sun4v_chip_type == SUN4V_CHIP_SPARC_M7 ||
  417. sun4v_chip_type == SUN4V_CHIP_SPARC64X)
  418. cap |= HWCAP_SPARC_BLKINIT;
  419. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  420. sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  421. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  422. sun4v_chip_type == SUN4V_CHIP_NIAGARA5 ||
  423. sun4v_chip_type == SUN4V_CHIP_SPARC_M6 ||
  424. sun4v_chip_type == SUN4V_CHIP_SPARC_M7 ||
  425. sun4v_chip_type == SUN4V_CHIP_SPARC64X)
  426. cap |= HWCAP_SPARC_N2;
  427. }
  428. cap |= (AV_SPARC_MUL32 | AV_SPARC_DIV32 | AV_SPARC_V8PLUS);
  429. mdesc_caps = mdesc_cpu_hwcap_list();
  430. if (!mdesc_caps) {
  431. if (tlb_type == spitfire)
  432. cap |= AV_SPARC_VIS;
  433. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  434. cap |= AV_SPARC_VIS | AV_SPARC_VIS2;
  435. if (tlb_type == cheetah_plus) {
  436. unsigned long impl, ver;
  437. __asm__ __volatile__("rdpr %%ver, %0" : "=r" (ver));
  438. impl = ((ver >> 32) & 0xffff);
  439. if (impl == PANTHER_IMPL)
  440. cap |= AV_SPARC_POPC;
  441. }
  442. if (tlb_type == hypervisor) {
  443. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1)
  444. cap |= AV_SPARC_ASI_BLK_INIT;
  445. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  446. sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  447. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  448. sun4v_chip_type == SUN4V_CHIP_NIAGARA5 ||
  449. sun4v_chip_type == SUN4V_CHIP_SPARC_M6 ||
  450. sun4v_chip_type == SUN4V_CHIP_SPARC_M7 ||
  451. sun4v_chip_type == SUN4V_CHIP_SPARC64X)
  452. cap |= (AV_SPARC_VIS | AV_SPARC_VIS2 |
  453. AV_SPARC_ASI_BLK_INIT |
  454. AV_SPARC_POPC);
  455. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  456. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  457. sun4v_chip_type == SUN4V_CHIP_NIAGARA5 ||
  458. sun4v_chip_type == SUN4V_CHIP_SPARC_M6 ||
  459. sun4v_chip_type == SUN4V_CHIP_SPARC_M7 ||
  460. sun4v_chip_type == SUN4V_CHIP_SPARC64X)
  461. cap |= (AV_SPARC_VIS3 | AV_SPARC_HPC |
  462. AV_SPARC_FMAF);
  463. }
  464. }
  465. sparc64_elf_hwcap = cap | mdesc_caps;
  466. report_hwcaps(sparc64_elf_hwcap);
  467. if (sparc64_elf_hwcap & AV_SPARC_POPC)
  468. popc_patch();
  469. if (sparc64_elf_hwcap & AV_SPARC_PAUSE)
  470. pause_patch();
  471. }
  472. void __init setup_arch(char **cmdline_p)
  473. {
  474. /* Initialize PROM console and command line. */
  475. *cmdline_p = prom_getbootargs();
  476. strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
  477. parse_early_param();
  478. boot_flags_init(*cmdline_p);
  479. #ifdef CONFIG_EARLYFB
  480. if (btext_find_display())
  481. #endif
  482. register_console(&prom_early_console);
  483. if (tlb_type == hypervisor)
  484. printk("ARCH: SUN4V\n");
  485. else
  486. printk("ARCH: SUN4U\n");
  487. #ifdef CONFIG_DUMMY_CONSOLE
  488. conswitchp = &dummy_con;
  489. #endif
  490. idprom_init();
  491. if (!root_flags)
  492. root_mountflags &= ~MS_RDONLY;
  493. ROOT_DEV = old_decode_dev(root_dev);
  494. #ifdef CONFIG_BLK_DEV_RAM
  495. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  496. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  497. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  498. #endif
  499. task_thread_info(&init_task)->kregs = &fake_swapper_regs;
  500. #ifdef CONFIG_IP_PNP
  501. if (!ic_set_manually) {
  502. phandle chosen = prom_finddevice("/chosen");
  503. u32 cl, sv, gw;
  504. cl = prom_getintdefault (chosen, "client-ip", 0);
  505. sv = prom_getintdefault (chosen, "server-ip", 0);
  506. gw = prom_getintdefault (chosen, "gateway-ip", 0);
  507. if (cl && sv) {
  508. ic_myaddr = cl;
  509. ic_servaddr = sv;
  510. if (gw)
  511. ic_gateway = gw;
  512. #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
  513. ic_proto_enabled = 0;
  514. #endif
  515. }
  516. }
  517. #endif
  518. /* Get boot processor trap_block[] setup. */
  519. init_cur_cpu_trap(current_thread_info());
  520. paging_init();
  521. init_sparc64_elf_hwcap();
  522. }
  523. extern int stop_a_enabled;
  524. void sun_do_break(void)
  525. {
  526. if (!stop_a_enabled)
  527. return;
  528. prom_printf("\n");
  529. flush_user_windows();
  530. prom_cmdline();
  531. }
  532. EXPORT_SYMBOL(sun_do_break);
  533. int stop_a_enabled = 1;
  534. EXPORT_SYMBOL(stop_a_enabled);