setup.c 12 KB

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