setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. void __init per_cpu_patch(void)
  201. {
  202. struct cpuid_patch_entry *p;
  203. unsigned long ver;
  204. int is_jbus;
  205. if (tlb_type == spitfire && !this_is_starfire)
  206. return;
  207. is_jbus = 0;
  208. if (tlb_type != hypervisor) {
  209. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  210. is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
  211. (ver >> 32UL) == __SERRANO_ID);
  212. }
  213. p = &__cpuid_patch;
  214. while (p < &__cpuid_patch_end) {
  215. unsigned long addr = p->addr;
  216. unsigned int *insns;
  217. switch (tlb_type) {
  218. case spitfire:
  219. insns = &p->starfire[0];
  220. break;
  221. case cheetah:
  222. case cheetah_plus:
  223. if (is_jbus)
  224. insns = &p->cheetah_jbus[0];
  225. else
  226. insns = &p->cheetah_safari[0];
  227. break;
  228. case hypervisor:
  229. insns = &p->sun4v[0];
  230. break;
  231. default:
  232. prom_printf("Unknown cpu type, halting.\n");
  233. prom_halt();
  234. };
  235. *(unsigned int *) (addr + 0) = insns[0];
  236. wmb();
  237. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  238. *(unsigned int *) (addr + 4) = insns[1];
  239. wmb();
  240. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  241. *(unsigned int *) (addr + 8) = insns[2];
  242. wmb();
  243. __asm__ __volatile__("flush %0" : : "r" (addr + 8));
  244. *(unsigned int *) (addr + 12) = insns[3];
  245. wmb();
  246. __asm__ __volatile__("flush %0" : : "r" (addr + 12));
  247. p++;
  248. }
  249. }
  250. void __init sun4v_patch(void)
  251. {
  252. struct sun4v_1insn_patch_entry *p1;
  253. struct sun4v_2insn_patch_entry *p2;
  254. if (tlb_type != hypervisor)
  255. return;
  256. p1 = &__sun4v_1insn_patch;
  257. while (p1 < &__sun4v_1insn_patch_end) {
  258. unsigned long addr = p1->addr;
  259. *(unsigned int *) (addr + 0) = p1->insn;
  260. wmb();
  261. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  262. p1++;
  263. }
  264. p2 = &__sun4v_2insn_patch;
  265. while (p2 < &__sun4v_2insn_patch_end) {
  266. unsigned long addr = p2->addr;
  267. *(unsigned int *) (addr + 0) = p2->insns[0];
  268. wmb();
  269. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  270. *(unsigned int *) (addr + 4) = p2->insns[1];
  271. wmb();
  272. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  273. p2++;
  274. }
  275. }
  276. #ifdef CONFIG_SMP
  277. void __init boot_cpu_id_too_large(int cpu)
  278. {
  279. prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
  280. cpu, NR_CPUS);
  281. prom_halt();
  282. }
  283. #endif
  284. void __init setup_arch(char **cmdline_p)
  285. {
  286. /* Initialize PROM console and command line. */
  287. *cmdline_p = prom_getbootargs();
  288. strcpy(saved_command_line, *cmdline_p);
  289. if (tlb_type == hypervisor)
  290. printk("ARCH: SUN4V\n");
  291. else
  292. printk("ARCH: SUN4U\n");
  293. #ifdef CONFIG_DUMMY_CONSOLE
  294. conswitchp = &dummy_con;
  295. #elif defined(CONFIG_PROM_CONSOLE)
  296. conswitchp = &prom_con;
  297. #endif
  298. boot_flags_init(*cmdline_p);
  299. idprom_init();
  300. if (!root_flags)
  301. root_mountflags &= ~MS_RDONLY;
  302. ROOT_DEV = old_decode_dev(root_dev);
  303. #ifdef CONFIG_BLK_DEV_RAM
  304. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  305. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  306. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  307. #endif
  308. task_thread_info(&init_task)->kregs = &fake_swapper_regs;
  309. #ifdef CONFIG_IP_PNP
  310. if (!ic_set_manually) {
  311. int chosen = prom_finddevice ("/chosen");
  312. u32 cl, sv, gw;
  313. cl = prom_getintdefault (chosen, "client-ip", 0);
  314. sv = prom_getintdefault (chosen, "server-ip", 0);
  315. gw = prom_getintdefault (chosen, "gateway-ip", 0);
  316. if (cl && sv) {
  317. ic_myaddr = cl;
  318. ic_servaddr = sv;
  319. if (gw)
  320. ic_gateway = gw;
  321. #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
  322. ic_proto_enabled = 0;
  323. #endif
  324. }
  325. }
  326. #endif
  327. smp_setup_cpu_possible_map();
  328. /* Get boot processor trap_block[] setup. */
  329. init_cur_cpu_trap(current_thread_info());
  330. paging_init();
  331. }
  332. static int __init set_preferred_console(void)
  333. {
  334. int idev, odev;
  335. /* The user has requested a console so this is already set up. */
  336. if (serial_console >= 0)
  337. return -EBUSY;
  338. idev = prom_query_input_device();
  339. odev = prom_query_output_device();
  340. if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
  341. serial_console = 0;
  342. } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
  343. serial_console = 1;
  344. } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
  345. serial_console = 2;
  346. } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
  347. serial_console = 3;
  348. } else if (idev == PROMDEV_IVCONS && odev == PROMDEV_OVCONS) {
  349. /* sunhv_console_init() doesn't check the serial_console
  350. * value anyways...
  351. */
  352. serial_console = 4;
  353. return add_preferred_console("ttyHV", 0, NULL);
  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. "prom\t\t: %s\n"
  380. "type\t\t: %s\n"
  381. "ncpus probed\t: %d\n"
  382. "ncpus active\t: %d\n"
  383. "D$ parity tl1\t: %u\n"
  384. "I$ parity tl1\t: %u\n"
  385. #ifndef CONFIG_SMP
  386. "Cpu0Bogo\t: %lu.%02lu\n"
  387. "Cpu0ClkTck\t: %016lx\n"
  388. #endif
  389. ,
  390. sparc_cpu_type,
  391. sparc_fpu_type,
  392. prom_version,
  393. ((tlb_type == hypervisor) ?
  394. "sun4v" :
  395. "sun4u"),
  396. ncpus_probed,
  397. num_online_cpus(),
  398. dcache_parity_tl1_occurred,
  399. icache_parity_tl1_occurred
  400. #ifndef CONFIG_SMP
  401. , cpu_data(0).udelay_val/(500000/HZ),
  402. (cpu_data(0).udelay_val/(5000/HZ)) % 100,
  403. cpu_data(0).clock_tick
  404. #endif
  405. );
  406. #ifdef CONFIG_SMP
  407. smp_bogo(m);
  408. #endif
  409. mmu_info(m);
  410. #ifdef CONFIG_SMP
  411. smp_info(m);
  412. #endif
  413. return 0;
  414. }
  415. static void *c_start(struct seq_file *m, loff_t *pos)
  416. {
  417. /* The pointer we are returning is arbitrary,
  418. * it just has to be non-NULL and not IS_ERR
  419. * in the success case.
  420. */
  421. return *pos == 0 ? &c_start : NULL;
  422. }
  423. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  424. {
  425. ++*pos;
  426. return c_start(m, pos);
  427. }
  428. static void c_stop(struct seq_file *m, void *v)
  429. {
  430. }
  431. struct seq_operations cpuinfo_op = {
  432. .start =c_start,
  433. .next = c_next,
  434. .stop = c_stop,
  435. .show = show_cpuinfo,
  436. };
  437. extern int stop_a_enabled;
  438. void sun_do_break(void)
  439. {
  440. if (!stop_a_enabled)
  441. return;
  442. prom_printf("\n");
  443. flush_user_windows();
  444. prom_cmdline();
  445. }
  446. int serial_console = -1;
  447. int stop_a_enabled = 1;
  448. static int __init topology_init(void)
  449. {
  450. int i, err;
  451. err = -ENOMEM;
  452. /* Count the number of physically present processors in
  453. * the machine, even on uniprocessor, so that /proc/cpuinfo
  454. * output is consistent with 2.4.x
  455. */
  456. ncpus_probed = 0;
  457. while (!cpu_find_by_instance(ncpus_probed, NULL, NULL))
  458. ncpus_probed++;
  459. for_each_possible_cpu(i) {
  460. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  461. if (p) {
  462. register_cpu(p, i, NULL);
  463. err = 0;
  464. }
  465. }
  466. return err;
  467. }
  468. subsys_initcall(topology_init);