setup_64.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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);
  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. /*
  133. * "mem=XXX[kKmM]" overrides the PROM-reported
  134. * memory size.
  135. */
  136. cmdline_memory_size = simple_strtoul(commands + 4,
  137. &commands, 0);
  138. if (*commands == 'K' || *commands == 'k') {
  139. cmdline_memory_size <<= 10;
  140. commands++;
  141. } else if (*commands=='M' || *commands=='m') {
  142. cmdline_memory_size <<= 20;
  143. commands++;
  144. }
  145. }
  146. while (*commands && *commands != ' ')
  147. commands++;
  148. }
  149. }
  150. extern unsigned short root_flags;
  151. extern unsigned short root_dev;
  152. extern unsigned short ram_flags;
  153. #define RAMDISK_IMAGE_START_MASK 0x07FF
  154. #define RAMDISK_PROMPT_FLAG 0x8000
  155. #define RAMDISK_LOAD_FLAG 0x4000
  156. extern int root_mountflags;
  157. char reboot_command[COMMAND_LINE_SIZE];
  158. static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
  159. void __init per_cpu_patch(void)
  160. {
  161. struct cpuid_patch_entry *p;
  162. unsigned long ver;
  163. int is_jbus;
  164. if (tlb_type == spitfire && !this_is_starfire)
  165. return;
  166. is_jbus = 0;
  167. if (tlb_type != hypervisor) {
  168. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  169. is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
  170. (ver >> 32UL) == __SERRANO_ID);
  171. }
  172. p = &__cpuid_patch;
  173. while (p < &__cpuid_patch_end) {
  174. unsigned long addr = p->addr;
  175. unsigned int *insns;
  176. switch (tlb_type) {
  177. case spitfire:
  178. insns = &p->starfire[0];
  179. break;
  180. case cheetah:
  181. case cheetah_plus:
  182. if (is_jbus)
  183. insns = &p->cheetah_jbus[0];
  184. else
  185. insns = &p->cheetah_safari[0];
  186. break;
  187. case hypervisor:
  188. insns = &p->sun4v[0];
  189. break;
  190. default:
  191. prom_printf("Unknown cpu type, halting.\n");
  192. prom_halt();
  193. }
  194. *(unsigned int *) (addr + 0) = insns[0];
  195. wmb();
  196. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  197. *(unsigned int *) (addr + 4) = insns[1];
  198. wmb();
  199. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  200. *(unsigned int *) (addr + 8) = insns[2];
  201. wmb();
  202. __asm__ __volatile__("flush %0" : : "r" (addr + 8));
  203. *(unsigned int *) (addr + 12) = insns[3];
  204. wmb();
  205. __asm__ __volatile__("flush %0" : : "r" (addr + 12));
  206. p++;
  207. }
  208. }
  209. void sun4v_patch_1insn_range(struct sun4v_1insn_patch_entry *start,
  210. struct sun4v_1insn_patch_entry *end)
  211. {
  212. while (start < end) {
  213. unsigned long addr = start->addr;
  214. *(unsigned int *) (addr + 0) = start->insn;
  215. wmb();
  216. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  217. start++;
  218. }
  219. }
  220. void sun4v_patch_2insn_range(struct sun4v_2insn_patch_entry *start,
  221. struct sun4v_2insn_patch_entry *end)
  222. {
  223. while (start < end) {
  224. unsigned long addr = start->addr;
  225. *(unsigned int *) (addr + 0) = start->insns[0];
  226. wmb();
  227. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  228. *(unsigned int *) (addr + 4) = start->insns[1];
  229. wmb();
  230. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  231. start++;
  232. }
  233. }
  234. void __init sun4v_patch(void)
  235. {
  236. extern void sun4v_hvapi_init(void);
  237. if (tlb_type != hypervisor)
  238. return;
  239. sun4v_patch_1insn_range(&__sun4v_1insn_patch,
  240. &__sun4v_1insn_patch_end);
  241. sun4v_patch_2insn_range(&__sun4v_2insn_patch,
  242. &__sun4v_2insn_patch_end);
  243. sun4v_hvapi_init();
  244. }
  245. static void __init popc_patch(void)
  246. {
  247. struct popc_3insn_patch_entry *p3;
  248. struct popc_6insn_patch_entry *p6;
  249. p3 = &__popc_3insn_patch;
  250. while (p3 < &__popc_3insn_patch_end) {
  251. unsigned long i, addr = p3->addr;
  252. for (i = 0; i < 3; i++) {
  253. *(unsigned int *) (addr + (i * 4)) = p3->insns[i];
  254. wmb();
  255. __asm__ __volatile__("flush %0"
  256. : : "r" (addr + (i * 4)));
  257. }
  258. p3++;
  259. }
  260. p6 = &__popc_6insn_patch;
  261. while (p6 < &__popc_6insn_patch_end) {
  262. unsigned long i, addr = p6->addr;
  263. for (i = 0; i < 6; i++) {
  264. *(unsigned int *) (addr + (i * 4)) = p6->insns[i];
  265. wmb();
  266. __asm__ __volatile__("flush %0"
  267. : : "r" (addr + (i * 4)));
  268. }
  269. p6++;
  270. }
  271. }
  272. #ifdef CONFIG_SMP
  273. void __init boot_cpu_id_too_large(int cpu)
  274. {
  275. prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
  276. cpu, NR_CPUS);
  277. prom_halt();
  278. }
  279. #endif
  280. /* On Ultra, we support all of the v8 capabilities. */
  281. unsigned long sparc64_elf_hwcap = (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
  282. HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV |
  283. HWCAP_SPARC_V9);
  284. EXPORT_SYMBOL(sparc64_elf_hwcap);
  285. static const char *hwcaps[] = {
  286. "flush", "stbar", "swap", "muldiv", "v9",
  287. "ultra3", "blkinit", "n2",
  288. /* These strings are as they appear in the machine description
  289. * 'hwcap-list' property for cpu nodes.
  290. */
  291. "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
  292. "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
  293. "ima", "cspare",
  294. };
  295. void cpucap_info(struct seq_file *m)
  296. {
  297. unsigned long caps = sparc64_elf_hwcap;
  298. int i, printed = 0;
  299. seq_puts(m, "cpucaps\t\t: ");
  300. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  301. unsigned long bit = 1UL << i;
  302. if (caps & bit) {
  303. seq_printf(m, "%s%s",
  304. printed ? "," : "", hwcaps[i]);
  305. printed++;
  306. }
  307. }
  308. seq_putc(m, '\n');
  309. }
  310. static void __init report_hwcaps(unsigned long caps)
  311. {
  312. int i, printed = 0;
  313. printk(KERN_INFO "CPU CAPS: [");
  314. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  315. unsigned long bit = 1UL << i;
  316. if (caps & bit) {
  317. printk(KERN_CONT "%s%s",
  318. printed ? "," : "", hwcaps[i]);
  319. if (++printed == 8) {
  320. printk(KERN_CONT "]\n");
  321. printk(KERN_INFO "CPU CAPS: [");
  322. printed = 0;
  323. }
  324. }
  325. }
  326. printk(KERN_CONT "]\n");
  327. }
  328. static unsigned long __init mdesc_cpu_hwcap_list(void)
  329. {
  330. struct mdesc_handle *hp;
  331. unsigned long caps = 0;
  332. const char *prop;
  333. int len;
  334. u64 pn;
  335. hp = mdesc_grab();
  336. if (!hp)
  337. return 0;
  338. pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "cpu");
  339. if (pn == MDESC_NODE_NULL)
  340. goto out;
  341. prop = mdesc_get_property(hp, pn, "hwcap-list", &len);
  342. if (!prop)
  343. goto out;
  344. while (len) {
  345. int i, plen;
  346. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  347. unsigned long bit = 1UL << i;
  348. if (!strcmp(prop, hwcaps[i])) {
  349. caps |= bit;
  350. break;
  351. }
  352. }
  353. plen = strlen(prop) + 1;
  354. prop += plen;
  355. len -= plen;
  356. }
  357. out:
  358. mdesc_release(hp);
  359. return caps;
  360. }
  361. /* This yields a mask that user programs can use to figure out what
  362. * instruction set this cpu supports.
  363. */
  364. static void __init init_sparc64_elf_hwcap(void)
  365. {
  366. unsigned long cap = sparc64_elf_hwcap;
  367. unsigned long mdesc_caps;
  368. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  369. cap |= HWCAP_SPARC_ULTRA3;
  370. else if (tlb_type == hypervisor) {
  371. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 ||
  372. sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  373. sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  374. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  375. sun4v_chip_type == SUN4V_CHIP_NIAGARA5)
  376. cap |= HWCAP_SPARC_BLKINIT;
  377. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  378. sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  379. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  380. sun4v_chip_type == SUN4V_CHIP_NIAGARA5)
  381. cap |= HWCAP_SPARC_N2;
  382. }
  383. cap |= (AV_SPARC_MUL32 | AV_SPARC_DIV32 | AV_SPARC_V8PLUS);
  384. mdesc_caps = mdesc_cpu_hwcap_list();
  385. if (!mdesc_caps) {
  386. if (tlb_type == spitfire)
  387. cap |= AV_SPARC_VIS;
  388. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  389. cap |= AV_SPARC_VIS | AV_SPARC_VIS2;
  390. if (tlb_type == cheetah_plus) {
  391. unsigned long impl, ver;
  392. __asm__ __volatile__("rdpr %%ver, %0" : "=r" (ver));
  393. impl = ((ver >> 32) & 0xffff);
  394. if (impl == PANTHER_IMPL)
  395. cap |= AV_SPARC_POPC;
  396. }
  397. if (tlb_type == hypervisor) {
  398. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1)
  399. cap |= AV_SPARC_ASI_BLK_INIT;
  400. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  401. sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  402. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  403. sun4v_chip_type == SUN4V_CHIP_NIAGARA5)
  404. cap |= (AV_SPARC_VIS | AV_SPARC_VIS2 |
  405. AV_SPARC_ASI_BLK_INIT |
  406. AV_SPARC_POPC);
  407. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA3 ||
  408. sun4v_chip_type == SUN4V_CHIP_NIAGARA4 ||
  409. sun4v_chip_type == SUN4V_CHIP_NIAGARA5)
  410. cap |= (AV_SPARC_VIS3 | AV_SPARC_HPC |
  411. AV_SPARC_FMAF);
  412. }
  413. }
  414. sparc64_elf_hwcap = cap | mdesc_caps;
  415. report_hwcaps(sparc64_elf_hwcap);
  416. if (sparc64_elf_hwcap & AV_SPARC_POPC)
  417. popc_patch();
  418. }
  419. void __init setup_arch(char **cmdline_p)
  420. {
  421. /* Initialize PROM console and command line. */
  422. *cmdline_p = prom_getbootargs();
  423. strcpy(boot_command_line, *cmdline_p);
  424. parse_early_param();
  425. boot_flags_init(*cmdline_p);
  426. #ifdef CONFIG_EARLYFB
  427. if (btext_find_display())
  428. #endif
  429. register_console(&prom_early_console);
  430. if (tlb_type == hypervisor)
  431. printk("ARCH: SUN4V\n");
  432. else
  433. printk("ARCH: SUN4U\n");
  434. #ifdef CONFIG_DUMMY_CONSOLE
  435. conswitchp = &dummy_con;
  436. #endif
  437. idprom_init();
  438. if (!root_flags)
  439. root_mountflags &= ~MS_RDONLY;
  440. ROOT_DEV = old_decode_dev(root_dev);
  441. #ifdef CONFIG_BLK_DEV_RAM
  442. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  443. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  444. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  445. #endif
  446. task_thread_info(&init_task)->kregs = &fake_swapper_regs;
  447. #ifdef CONFIG_IP_PNP
  448. if (!ic_set_manually) {
  449. phandle chosen = prom_finddevice("/chosen");
  450. u32 cl, sv, gw;
  451. cl = prom_getintdefault (chosen, "client-ip", 0);
  452. sv = prom_getintdefault (chosen, "server-ip", 0);
  453. gw = prom_getintdefault (chosen, "gateway-ip", 0);
  454. if (cl && sv) {
  455. ic_myaddr = cl;
  456. ic_servaddr = sv;
  457. if (gw)
  458. ic_gateway = gw;
  459. #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
  460. ic_proto_enabled = 0;
  461. #endif
  462. }
  463. }
  464. #endif
  465. /* Get boot processor trap_block[] setup. */
  466. init_cur_cpu_trap(current_thread_info());
  467. paging_init();
  468. init_sparc64_elf_hwcap();
  469. }
  470. extern int stop_a_enabled;
  471. void sun_do_break(void)
  472. {
  473. if (!stop_a_enabled)
  474. return;
  475. prom_printf("\n");
  476. flush_user_windows();
  477. prom_cmdline();
  478. }
  479. EXPORT_SYMBOL(sun_do_break);
  480. int stop_a_enabled = 1;
  481. EXPORT_SYMBOL(stop_a_enabled);