setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /* $Id: setup.c,v 1.72 2002/02/09 19:49:30 davem Exp $
  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 <linux/slab.h>
  15. #include <asm/smp.h>
  16. #include <linux/user.h>
  17. #include <linux/a.out.h>
  18. #include <linux/tty.h>
  19. #include <linux/delay.h>
  20. #include <linux/config.h>
  21. #include <linux/fs.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/kdev_t.h>
  25. #include <linux/major.h>
  26. #include <linux/string.h>
  27. #include <linux/init.h>
  28. #include <linux/inet.h>
  29. #include <linux/console.h>
  30. #include <linux/root_dev.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/cpu.h>
  33. #include <linux/initrd.h>
  34. #include <asm/system.h>
  35. #include <asm/io.h>
  36. #include <asm/processor.h>
  37. #include <asm/oplib.h>
  38. #include <asm/page.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/idprom.h>
  41. #include <asm/head.h>
  42. #include <asm/starfire.h>
  43. #include <asm/mmu_context.h>
  44. #include <asm/timer.h>
  45. #include <asm/sections.h>
  46. #include <asm/setup.h>
  47. #include <asm/mmu.h>
  48. #ifdef CONFIG_IP_PNP
  49. #include <net/ipconfig.h>
  50. #endif
  51. struct screen_info screen_info = {
  52. 0, 0, /* orig-x, orig-y */
  53. 0, /* unused */
  54. 0, /* orig-video-page */
  55. 0, /* orig-video-mode */
  56. 128, /* orig-video-cols */
  57. 0, 0, 0, /* unused, ega_bx, unused */
  58. 54, /* orig-video-lines */
  59. 0, /* orig-video-isVGA */
  60. 16 /* orig-video-points */
  61. };
  62. void (*prom_palette)(int);
  63. void (*prom_keyboard)(void);
  64. static void
  65. prom_console_write(struct console *con, const char *s, unsigned n)
  66. {
  67. prom_write(s, n);
  68. }
  69. unsigned int boot_flags = 0;
  70. #define BOOTME_DEBUG 0x1
  71. #define BOOTME_SINGLE 0x2
  72. /* Exported for mm/init.c:paging_init. */
  73. unsigned long cmdline_memory_size = 0;
  74. static struct console prom_debug_console = {
  75. .name = "debug",
  76. .write = prom_console_write,
  77. .flags = CON_PRINTBUFFER,
  78. .index = -1,
  79. };
  80. /* XXX Implement this at some point... */
  81. void kernel_enter_debugger(void)
  82. {
  83. }
  84. int obp_system_intr(void)
  85. {
  86. if (boot_flags & BOOTME_DEBUG) {
  87. printk("OBP: system interrupted\n");
  88. prom_halt();
  89. return 1;
  90. }
  91. return 0;
  92. }
  93. /*
  94. * Process kernel command line switches that are specific to the
  95. * SPARC or that require special low-level processing.
  96. */
  97. static void __init process_switch(char c)
  98. {
  99. switch (c) {
  100. case 'd':
  101. boot_flags |= BOOTME_DEBUG;
  102. break;
  103. case 's':
  104. boot_flags |= BOOTME_SINGLE;
  105. break;
  106. case 'h':
  107. prom_printf("boot_flags_init: Halt!\n");
  108. prom_halt();
  109. break;
  110. case 'p':
  111. /* Use PROM debug console. */
  112. register_console(&prom_debug_console);
  113. break;
  114. case 'P':
  115. /* Force UltraSPARC-III P-Cache on. */
  116. if (tlb_type != cheetah) {
  117. printk("BOOT: Ignoring P-Cache force option.\n");
  118. break;
  119. }
  120. cheetah_pcache_forced_on = 1;
  121. add_taint(TAINT_MACHINE_CHECK);
  122. cheetah_enable_pcache();
  123. break;
  124. default:
  125. printk("Unknown boot switch (-%c)\n", c);
  126. break;
  127. }
  128. }
  129. static void __init process_console(char *commands)
  130. {
  131. serial_console = 0;
  132. commands += 8;
  133. /* Linux-style serial */
  134. if (!strncmp(commands, "ttyS", 4))
  135. serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
  136. else if (!strncmp(commands, "tty", 3)) {
  137. char c = *(commands + 3);
  138. /* Solaris-style serial */
  139. if (c == 'a' || c == 'b') {
  140. serial_console = c - 'a' + 1;
  141. prom_printf ("Using /dev/tty%c as console.\n", c);
  142. }
  143. /* else Linux-style fbcon, not serial */
  144. }
  145. #if defined(CONFIG_PROM_CONSOLE)
  146. if (!strncmp(commands, "prom", 4)) {
  147. char *p;
  148. for (p = commands - 8; *p && *p != ' '; p++)
  149. *p = ' ';
  150. conswitchp = &prom_con;
  151. }
  152. #endif
  153. }
  154. static void __init boot_flags_init(char *commands)
  155. {
  156. while (*commands) {
  157. /* Move to the start of the next "argument". */
  158. while (*commands && *commands == ' ')
  159. commands++;
  160. /* Process any command switches, otherwise skip it. */
  161. if (*commands == '\0')
  162. break;
  163. if (*commands == '-') {
  164. commands++;
  165. while (*commands && *commands != ' ')
  166. process_switch(*commands++);
  167. continue;
  168. }
  169. if (!strncmp(commands, "console=", 8)) {
  170. process_console(commands);
  171. } else if (!strncmp(commands, "mem=", 4)) {
  172. /*
  173. * "mem=XXX[kKmM]" overrides the PROM-reported
  174. * memory size.
  175. */
  176. cmdline_memory_size = simple_strtoul(commands + 4,
  177. &commands, 0);
  178. if (*commands == 'K' || *commands == 'k') {
  179. cmdline_memory_size <<= 10;
  180. commands++;
  181. } else if (*commands=='M' || *commands=='m') {
  182. cmdline_memory_size <<= 20;
  183. commands++;
  184. }
  185. }
  186. while (*commands && *commands != ' ')
  187. commands++;
  188. }
  189. }
  190. extern void panic_setup(char *, int *);
  191. extern unsigned short root_flags;
  192. extern unsigned short root_dev;
  193. extern unsigned short ram_flags;
  194. #define RAMDISK_IMAGE_START_MASK 0x07FF
  195. #define RAMDISK_PROMPT_FLAG 0x8000
  196. #define RAMDISK_LOAD_FLAG 0x4000
  197. extern int root_mountflags;
  198. char reboot_command[COMMAND_LINE_SIZE];
  199. static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
  200. static void __init per_cpu_patch(void)
  201. {
  202. #ifdef CONFIG_SMP
  203. struct cpuid_patch_entry *p;
  204. unsigned long ver;
  205. int is_jbus;
  206. if (tlb_type == spitfire && !this_is_starfire)
  207. return;
  208. is_jbus = 0;
  209. if (tlb_type != hypervisor) {
  210. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  211. is_jbus = ((ver >> 32) == __JALAPENO_ID ||
  212. (ver >> 32) == __SERRANO_ID);
  213. }
  214. p = &__cpuid_patch;
  215. while (p < &__cpuid_patch_end) {
  216. unsigned long addr = p->addr;
  217. unsigned int *insns;
  218. switch (tlb_type) {
  219. case spitfire:
  220. insns = &p->starfire[0];
  221. break;
  222. case cheetah:
  223. case cheetah_plus:
  224. if (is_jbus)
  225. insns = &p->cheetah_jbus[0];
  226. else
  227. insns = &p->cheetah_safari[0];
  228. break;
  229. case hypervisor:
  230. insns = &p->sun4v[0];
  231. break;
  232. default:
  233. prom_printf("Unknown cpu type, halting.\n");
  234. prom_halt();
  235. };
  236. *(unsigned int *) (addr + 0) = insns[0];
  237. wmb();
  238. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  239. *(unsigned int *) (addr + 4) = insns[1];
  240. wmb();
  241. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  242. *(unsigned int *) (addr + 8) = insns[2];
  243. wmb();
  244. __asm__ __volatile__("flush %0" : : "r" (addr + 8));
  245. *(unsigned int *) (addr + 12) = insns[3];
  246. wmb();
  247. __asm__ __volatile__("flush %0" : : "r" (addr + 12));
  248. p++;
  249. }
  250. #endif
  251. }
  252. static void __init sun4v_patch(void)
  253. {
  254. struct sun4v_1insn_patch_entry *p1;
  255. struct sun4v_2insn_patch_entry *p2;
  256. if (tlb_type != hypervisor)
  257. return;
  258. p1 = &__sun4v_1insn_patch;
  259. while (p1 < &__sun4v_1insn_patch_end) {
  260. unsigned long addr = p1->addr;
  261. *(unsigned int *) (addr + 0) = p1->insn;
  262. wmb();
  263. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  264. p1++;
  265. }
  266. p2 = &__sun4v_2insn_patch;
  267. while (p2 < &__sun4v_2insn_patch_end) {
  268. unsigned long addr = p2->addr;
  269. *(unsigned int *) (addr + 0) = p2->insns[0];
  270. wmb();
  271. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  272. *(unsigned int *) (addr + 4) = p2->insns[1];
  273. wmb();
  274. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  275. p2++;
  276. }
  277. }
  278. void __init setup_arch(char **cmdline_p)
  279. {
  280. /* Initialize PROM console and command line. */
  281. *cmdline_p = prom_getbootargs();
  282. strcpy(saved_command_line, *cmdline_p);
  283. if (tlb_type == hypervisor)
  284. printk("ARCH: SUN4V\n");
  285. else
  286. printk("ARCH: SUN4U\n");
  287. #ifdef CONFIG_DUMMY_CONSOLE
  288. conswitchp = &dummy_con;
  289. #elif defined(CONFIG_PROM_CONSOLE)
  290. conswitchp = &prom_con;
  291. #endif
  292. /* Work out if we are starfire early on */
  293. check_if_starfire();
  294. /* Now we know enough to patch the get_cpuid sequences
  295. * used by trap code.
  296. */
  297. per_cpu_patch();
  298. sun4v_patch();
  299. boot_flags_init(*cmdline_p);
  300. idprom_init();
  301. if (!root_flags)
  302. root_mountflags &= ~MS_RDONLY;
  303. ROOT_DEV = old_decode_dev(root_dev);
  304. #ifdef CONFIG_BLK_DEV_INITRD
  305. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  306. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  307. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  308. #endif
  309. task_thread_info(&init_task)->kregs = &fake_swapper_regs;
  310. #ifdef CONFIG_IP_PNP
  311. if (!ic_set_manually) {
  312. int chosen = prom_finddevice ("/chosen");
  313. u32 cl, sv, gw;
  314. cl = prom_getintdefault (chosen, "client-ip", 0);
  315. sv = prom_getintdefault (chosen, "server-ip", 0);
  316. gw = prom_getintdefault (chosen, "gateway-ip", 0);
  317. if (cl && sv) {
  318. ic_myaddr = cl;
  319. ic_servaddr = sv;
  320. if (gw)
  321. ic_gateway = gw;
  322. #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
  323. ic_proto_enabled = 0;
  324. #endif
  325. }
  326. }
  327. #endif
  328. smp_setup_cpu_possible_map();
  329. paging_init();
  330. /* Get boot processor trap_block[] setup. */
  331. init_cur_cpu_trap();
  332. }
  333. static int __init set_preferred_console(void)
  334. {
  335. int idev, odev;
  336. /* The user has requested a console so this is already set up. */
  337. if (serial_console >= 0)
  338. return -EBUSY;
  339. idev = prom_query_input_device();
  340. odev = prom_query_output_device();
  341. if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
  342. serial_console = 0;
  343. } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
  344. serial_console = 1;
  345. } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
  346. serial_console = 2;
  347. } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
  348. serial_console = 3;
  349. } else if (idev == PROMDEV_IVCONS && odev == PROMDEV_OVCONS) {
  350. /* sunhv_console_init() doesn't check the serial_console
  351. * value anyways...
  352. */
  353. serial_console = 4;
  354. } else {
  355. prom_printf("Inconsistent console: "
  356. "input %d, output %d\n",
  357. idev, odev);
  358. prom_halt();
  359. }
  360. if (serial_console)
  361. return add_preferred_console("ttyS", serial_console - 1, NULL);
  362. return -ENODEV;
  363. }
  364. console_initcall(set_preferred_console);
  365. /* BUFFER is PAGE_SIZE bytes long. */
  366. extern char *sparc_cpu_type;
  367. extern char *sparc_fpu_type;
  368. extern void smp_info(struct seq_file *);
  369. extern void smp_bogo(struct seq_file *);
  370. extern void mmu_info(struct seq_file *);
  371. unsigned int dcache_parity_tl1_occurred;
  372. unsigned int icache_parity_tl1_occurred;
  373. static int ncpus_probed;
  374. static int show_cpuinfo(struct seq_file *m, void *__unused)
  375. {
  376. seq_printf(m,
  377. "cpu\t\t: %s\n"
  378. "fpu\t\t: %s\n"
  379. "promlib\t\t: Version 3 Revision %d\n"
  380. "prom\t\t: %d.%d.%d\n"
  381. "type\t\t: sun4u\n"
  382. "ncpus probed\t: %d\n"
  383. "ncpus active\t: %d\n"
  384. "D$ parity tl1\t: %u\n"
  385. "I$ parity tl1\t: %u\n"
  386. #ifndef CONFIG_SMP
  387. "Cpu0Bogo\t: %lu.%02lu\n"
  388. "Cpu0ClkTck\t: %016lx\n"
  389. #endif
  390. ,
  391. sparc_cpu_type,
  392. sparc_fpu_type,
  393. prom_rev,
  394. prom_prev >> 16,
  395. (prom_prev >> 8) & 0xff,
  396. prom_prev & 0xff,
  397. ncpus_probed,
  398. num_online_cpus(),
  399. dcache_parity_tl1_occurred,
  400. icache_parity_tl1_occurred
  401. #ifndef CONFIG_SMP
  402. , cpu_data(0).udelay_val/(500000/HZ),
  403. (cpu_data(0).udelay_val/(5000/HZ)) % 100,
  404. cpu_data(0).clock_tick
  405. #endif
  406. );
  407. #ifdef CONFIG_SMP
  408. smp_bogo(m);
  409. #endif
  410. mmu_info(m);
  411. #ifdef CONFIG_SMP
  412. smp_info(m);
  413. #endif
  414. return 0;
  415. }
  416. static void *c_start(struct seq_file *m, loff_t *pos)
  417. {
  418. /* The pointer we are returning is arbitrary,
  419. * it just has to be non-NULL and not IS_ERR
  420. * in the success case.
  421. */
  422. return *pos == 0 ? &c_start : NULL;
  423. }
  424. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  425. {
  426. ++*pos;
  427. return c_start(m, pos);
  428. }
  429. static void c_stop(struct seq_file *m, void *v)
  430. {
  431. }
  432. struct seq_operations cpuinfo_op = {
  433. .start =c_start,
  434. .next = c_next,
  435. .stop = c_stop,
  436. .show = show_cpuinfo,
  437. };
  438. extern int stop_a_enabled;
  439. void sun_do_break(void)
  440. {
  441. if (!stop_a_enabled)
  442. return;
  443. prom_printf("\n");
  444. flush_user_windows();
  445. prom_cmdline();
  446. }
  447. int serial_console = -1;
  448. int stop_a_enabled = 1;
  449. static int __init topology_init(void)
  450. {
  451. int i, err;
  452. err = -ENOMEM;
  453. /* Count the number of physically present processors in
  454. * the machine, even on uniprocessor, so that /proc/cpuinfo
  455. * output is consistent with 2.4.x
  456. */
  457. ncpus_probed = 0;
  458. while (!cpu_find_by_instance(ncpus_probed, NULL, NULL))
  459. ncpus_probed++;
  460. for (i = 0; i < NR_CPUS; i++) {
  461. if (cpu_possible(i)) {
  462. struct cpu *p = kmalloc(sizeof(*p), GFP_KERNEL);
  463. if (p) {
  464. memset(p, 0, sizeof(*p));
  465. register_cpu(p, i, NULL);
  466. err = 0;
  467. }
  468. }
  469. }
  470. return err;
  471. }
  472. subsys_initcall(topology_init);