setup.c 12 KB

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