setup_64.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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/system.h>
  33. #include <asm/io.h>
  34. #include <asm/processor.h>
  35. #include <asm/oplib.h>
  36. #include <asm/page.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/idprom.h>
  39. #include <asm/head.h>
  40. #include <asm/starfire.h>
  41. #include <asm/mmu_context.h>
  42. #include <asm/timer.h>
  43. #include <asm/sections.h>
  44. #include <asm/setup.h>
  45. #include <asm/mmu.h>
  46. #include <asm/ns87303.h>
  47. #include <asm/btext.h>
  48. #include <asm/elf.h>
  49. #include <asm/mdesc.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. /* Just ignore, this behavior is now the default. */
  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 __init sun4v_patch(void)
  210. {
  211. extern void sun4v_hvapi_init(void);
  212. struct sun4v_1insn_patch_entry *p1;
  213. struct sun4v_2insn_patch_entry *p2;
  214. if (tlb_type != hypervisor)
  215. return;
  216. p1 = &__sun4v_1insn_patch;
  217. while (p1 < &__sun4v_1insn_patch_end) {
  218. unsigned long addr = p1->addr;
  219. *(unsigned int *) (addr + 0) = p1->insn;
  220. wmb();
  221. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  222. p1++;
  223. }
  224. p2 = &__sun4v_2insn_patch;
  225. while (p2 < &__sun4v_2insn_patch_end) {
  226. unsigned long addr = p2->addr;
  227. *(unsigned int *) (addr + 0) = p2->insns[0];
  228. wmb();
  229. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  230. *(unsigned int *) (addr + 4) = p2->insns[1];
  231. wmb();
  232. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  233. p2++;
  234. }
  235. sun4v_hvapi_init();
  236. }
  237. static void __init popc_patch(void)
  238. {
  239. struct popc_3insn_patch_entry *p3;
  240. struct popc_6insn_patch_entry *p6;
  241. p3 = &__popc_3insn_patch;
  242. while (p3 < &__popc_3insn_patch_end) {
  243. unsigned long i, addr = p3->addr;
  244. for (i = 0; i < 3; i++) {
  245. *(unsigned int *) (addr + (i * 4)) = p3->insns[i];
  246. wmb();
  247. __asm__ __volatile__("flush %0"
  248. : : "r" (addr + (i * 4)));
  249. }
  250. p3++;
  251. }
  252. p6 = &__popc_6insn_patch;
  253. while (p6 < &__popc_6insn_patch_end) {
  254. unsigned long i, addr = p6->addr;
  255. for (i = 0; i < 6; i++) {
  256. *(unsigned int *) (addr + (i * 4)) = p6->insns[i];
  257. wmb();
  258. __asm__ __volatile__("flush %0"
  259. : : "r" (addr + (i * 4)));
  260. }
  261. p6++;
  262. }
  263. }
  264. #ifdef CONFIG_SMP
  265. void __init boot_cpu_id_too_large(int cpu)
  266. {
  267. prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
  268. cpu, NR_CPUS);
  269. prom_halt();
  270. }
  271. #endif
  272. /* On Ultra, we support all of the v8 capabilities. */
  273. unsigned long sparc64_elf_hwcap = (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
  274. HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV |
  275. HWCAP_SPARC_V9);
  276. EXPORT_SYMBOL(sparc64_elf_hwcap);
  277. static const char *hwcaps[] = {
  278. "flush", "stbar", "swap", "muldiv", "v9",
  279. "ultra3", "blkinit", "n2",
  280. /* These strings are as they appear in the machine description
  281. * 'hwcap-list' property for cpu nodes.
  282. */
  283. "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
  284. "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
  285. "ima", "cspare",
  286. };
  287. void cpucap_info(struct seq_file *m)
  288. {
  289. unsigned long caps = sparc64_elf_hwcap;
  290. int i, printed = 0;
  291. seq_puts(m, "cpucaps\t\t: ");
  292. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  293. unsigned long bit = 1UL << i;
  294. if (caps & bit) {
  295. seq_printf(m, "%s%s",
  296. printed ? "," : "", hwcaps[i]);
  297. printed++;
  298. }
  299. }
  300. seq_putc(m, '\n');
  301. }
  302. static void __init report_hwcaps(unsigned long caps)
  303. {
  304. int i, printed = 0;
  305. printk(KERN_INFO "CPU CAPS: [");
  306. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  307. unsigned long bit = 1UL << i;
  308. if (caps & bit) {
  309. printk(KERN_CONT "%s%s",
  310. printed ? "," : "", hwcaps[i]);
  311. if (++printed == 8) {
  312. printk(KERN_CONT "]\n");
  313. printk(KERN_INFO "CPU CAPS: [");
  314. printed = 0;
  315. }
  316. }
  317. }
  318. printk(KERN_CONT "]\n");
  319. }
  320. static unsigned long __init mdesc_cpu_hwcap_list(void)
  321. {
  322. struct mdesc_handle *hp;
  323. unsigned long caps = 0;
  324. const char *prop;
  325. int len;
  326. u64 pn;
  327. hp = mdesc_grab();
  328. if (!hp)
  329. return 0;
  330. pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "cpu");
  331. if (pn == MDESC_NODE_NULL)
  332. goto out;
  333. prop = mdesc_get_property(hp, pn, "hwcap-list", &len);
  334. if (!prop)
  335. goto out;
  336. while (len) {
  337. int i, plen;
  338. for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
  339. unsigned long bit = 1UL << i;
  340. if (!strcmp(prop, hwcaps[i])) {
  341. caps |= bit;
  342. break;
  343. }
  344. }
  345. plen = strlen(prop) + 1;
  346. prop += plen;
  347. len -= plen;
  348. }
  349. out:
  350. mdesc_release(hp);
  351. return caps;
  352. }
  353. /* This yields a mask that user programs can use to figure out what
  354. * instruction set this cpu supports.
  355. */
  356. static void __init init_sparc64_elf_hwcap(void)
  357. {
  358. unsigned long cap = sparc64_elf_hwcap;
  359. unsigned long mdesc_caps;
  360. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  361. cap |= HWCAP_SPARC_ULTRA3;
  362. else if (tlb_type == hypervisor) {
  363. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1 ||
  364. sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  365. sun4v_chip_type == SUN4V_CHIP_NIAGARA3)
  366. cap |= HWCAP_SPARC_BLKINIT;
  367. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  368. sun4v_chip_type == SUN4V_CHIP_NIAGARA3)
  369. cap |= HWCAP_SPARC_N2;
  370. }
  371. cap |= (AV_SPARC_MUL32 | AV_SPARC_DIV32 | AV_SPARC_V8PLUS);
  372. mdesc_caps = mdesc_cpu_hwcap_list();
  373. if (!mdesc_caps) {
  374. if (tlb_type == spitfire)
  375. cap |= AV_SPARC_VIS;
  376. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  377. cap |= AV_SPARC_VIS | AV_SPARC_VIS2;
  378. if (tlb_type == cheetah_plus)
  379. cap |= AV_SPARC_POPC;
  380. if (tlb_type == hypervisor) {
  381. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA1)
  382. cap |= AV_SPARC_ASI_BLK_INIT;
  383. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA2 ||
  384. sun4v_chip_type == SUN4V_CHIP_NIAGARA3)
  385. cap |= (AV_SPARC_VIS | AV_SPARC_VIS2 |
  386. AV_SPARC_ASI_BLK_INIT |
  387. AV_SPARC_POPC);
  388. if (sun4v_chip_type == SUN4V_CHIP_NIAGARA3)
  389. cap |= (AV_SPARC_VIS3 | AV_SPARC_HPC |
  390. AV_SPARC_FMAF);
  391. }
  392. }
  393. sparc64_elf_hwcap = cap | mdesc_caps;
  394. report_hwcaps(sparc64_elf_hwcap);
  395. if (sparc64_elf_hwcap & AV_SPARC_POPC)
  396. popc_patch();
  397. }
  398. void __init setup_arch(char **cmdline_p)
  399. {
  400. /* Initialize PROM console and command line. */
  401. *cmdline_p = prom_getbootargs();
  402. strcpy(boot_command_line, *cmdline_p);
  403. parse_early_param();
  404. boot_flags_init(*cmdline_p);
  405. #ifdef CONFIG_EARLYFB
  406. if (btext_find_display())
  407. #endif
  408. register_console(&prom_early_console);
  409. if (tlb_type == hypervisor)
  410. printk("ARCH: SUN4V\n");
  411. else
  412. printk("ARCH: SUN4U\n");
  413. #ifdef CONFIG_DUMMY_CONSOLE
  414. conswitchp = &dummy_con;
  415. #endif
  416. idprom_init();
  417. if (!root_flags)
  418. root_mountflags &= ~MS_RDONLY;
  419. ROOT_DEV = old_decode_dev(root_dev);
  420. #ifdef CONFIG_BLK_DEV_RAM
  421. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  422. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  423. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  424. #endif
  425. task_thread_info(&init_task)->kregs = &fake_swapper_regs;
  426. #ifdef CONFIG_IP_PNP
  427. if (!ic_set_manually) {
  428. phandle chosen = prom_finddevice("/chosen");
  429. u32 cl, sv, gw;
  430. cl = prom_getintdefault (chosen, "client-ip", 0);
  431. sv = prom_getintdefault (chosen, "server-ip", 0);
  432. gw = prom_getintdefault (chosen, "gateway-ip", 0);
  433. if (cl && sv) {
  434. ic_myaddr = cl;
  435. ic_servaddr = sv;
  436. if (gw)
  437. ic_gateway = gw;
  438. #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
  439. ic_proto_enabled = 0;
  440. #endif
  441. }
  442. }
  443. #endif
  444. /* Get boot processor trap_block[] setup. */
  445. init_cur_cpu_trap(current_thread_info());
  446. paging_init();
  447. init_sparc64_elf_hwcap();
  448. }
  449. extern int stop_a_enabled;
  450. void sun_do_break(void)
  451. {
  452. if (!stop_a_enabled)
  453. return;
  454. prom_printf("\n");
  455. flush_user_windows();
  456. prom_cmdline();
  457. }
  458. EXPORT_SYMBOL(sun_do_break);
  459. int stop_a_enabled = 1;
  460. EXPORT_SYMBOL(stop_a_enabled);