setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. struct sun4v_1insn_patch_entry *p1;
  241. struct sun4v_2insn_patch_entry *p2;
  242. if (tlb_type != hypervisor)
  243. return;
  244. p1 = &__sun4v_1insn_patch;
  245. while (p1 < &__sun4v_1insn_patch_end) {
  246. unsigned long addr = p1->addr;
  247. *(unsigned int *) (addr + 0) = p1->insn;
  248. wmb();
  249. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  250. p1++;
  251. }
  252. p2 = &__sun4v_2insn_patch;
  253. while (p2 < &__sun4v_2insn_patch_end) {
  254. unsigned long addr = p2->addr;
  255. *(unsigned int *) (addr + 0) = p2->insns[0];
  256. wmb();
  257. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  258. *(unsigned int *) (addr + 4) = p2->insns[1];
  259. wmb();
  260. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  261. p2++;
  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. void __init setup_arch(char **cmdline_p)
  273. {
  274. /* Initialize PROM console and command line. */
  275. *cmdline_p = prom_getbootargs();
  276. strcpy(saved_command_line, *cmdline_p);
  277. if (tlb_type == hypervisor)
  278. printk("ARCH: SUN4V\n");
  279. else
  280. printk("ARCH: SUN4U\n");
  281. #ifdef CONFIG_DUMMY_CONSOLE
  282. conswitchp = &dummy_con;
  283. #elif defined(CONFIG_PROM_CONSOLE)
  284. conswitchp = &prom_con;
  285. #endif
  286. boot_flags_init(*cmdline_p);
  287. idprom_init();
  288. if (!root_flags)
  289. root_mountflags &= ~MS_RDONLY;
  290. ROOT_DEV = old_decode_dev(root_dev);
  291. #ifdef CONFIG_BLK_DEV_RAM
  292. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  293. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  294. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  295. #endif
  296. task_thread_info(&init_task)->kregs = &fake_swapper_regs;
  297. #ifdef CONFIG_IP_PNP
  298. if (!ic_set_manually) {
  299. int chosen = prom_finddevice ("/chosen");
  300. u32 cl, sv, gw;
  301. cl = prom_getintdefault (chosen, "client-ip", 0);
  302. sv = prom_getintdefault (chosen, "server-ip", 0);
  303. gw = prom_getintdefault (chosen, "gateway-ip", 0);
  304. if (cl && sv) {
  305. ic_myaddr = cl;
  306. ic_servaddr = sv;
  307. if (gw)
  308. ic_gateway = gw;
  309. #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
  310. ic_proto_enabled = 0;
  311. #endif
  312. }
  313. }
  314. #endif
  315. /* Get boot processor trap_block[] setup. */
  316. init_cur_cpu_trap(current_thread_info());
  317. paging_init();
  318. smp_setup_cpu_possible_map();
  319. }
  320. static int __init set_preferred_console(void)
  321. {
  322. int idev, odev;
  323. /* The user has requested a console so this is already set up. */
  324. if (serial_console >= 0)
  325. return -EBUSY;
  326. idev = prom_query_input_device();
  327. odev = prom_query_output_device();
  328. if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
  329. serial_console = 0;
  330. } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
  331. serial_console = 1;
  332. } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
  333. serial_console = 2;
  334. } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
  335. serial_console = 3;
  336. } else if (idev == PROMDEV_IVCONS && odev == PROMDEV_OVCONS) {
  337. /* sunhv_console_init() doesn't check the serial_console
  338. * value anyways...
  339. */
  340. serial_console = 4;
  341. return add_preferred_console("ttyHV", 0, NULL);
  342. } else {
  343. prom_printf("Inconsistent console: "
  344. "input %d, output %d\n",
  345. idev, odev);
  346. prom_halt();
  347. }
  348. if (serial_console)
  349. return add_preferred_console("ttyS", serial_console - 1, NULL);
  350. return -ENODEV;
  351. }
  352. console_initcall(set_preferred_console);
  353. /* BUFFER is PAGE_SIZE bytes long. */
  354. extern char *sparc_cpu_type;
  355. extern char *sparc_fpu_type;
  356. extern void smp_info(struct seq_file *);
  357. extern void smp_bogo(struct seq_file *);
  358. extern void mmu_info(struct seq_file *);
  359. unsigned int dcache_parity_tl1_occurred;
  360. unsigned int icache_parity_tl1_occurred;
  361. static int ncpus_probed;
  362. static int show_cpuinfo(struct seq_file *m, void *__unused)
  363. {
  364. seq_printf(m,
  365. "cpu\t\t: %s\n"
  366. "fpu\t\t: %s\n"
  367. "prom\t\t: %s\n"
  368. "type\t\t: %s\n"
  369. "ncpus probed\t: %d\n"
  370. "ncpus active\t: %d\n"
  371. "D$ parity tl1\t: %u\n"
  372. "I$ parity tl1\t: %u\n"
  373. #ifndef CONFIG_SMP
  374. "Cpu0Bogo\t: %lu.%02lu\n"
  375. "Cpu0ClkTck\t: %016lx\n"
  376. #endif
  377. ,
  378. sparc_cpu_type,
  379. sparc_fpu_type,
  380. prom_version,
  381. ((tlb_type == hypervisor) ?
  382. "sun4v" :
  383. "sun4u"),
  384. ncpus_probed,
  385. num_online_cpus(),
  386. dcache_parity_tl1_occurred,
  387. icache_parity_tl1_occurred
  388. #ifndef CONFIG_SMP
  389. , cpu_data(0).udelay_val/(500000/HZ),
  390. (cpu_data(0).udelay_val/(5000/HZ)) % 100,
  391. cpu_data(0).clock_tick
  392. #endif
  393. );
  394. #ifdef CONFIG_SMP
  395. smp_bogo(m);
  396. #endif
  397. mmu_info(m);
  398. #ifdef CONFIG_SMP
  399. smp_info(m);
  400. #endif
  401. return 0;
  402. }
  403. static void *c_start(struct seq_file *m, loff_t *pos)
  404. {
  405. /* The pointer we are returning is arbitrary,
  406. * it just has to be non-NULL and not IS_ERR
  407. * in the success case.
  408. */
  409. return *pos == 0 ? &c_start : NULL;
  410. }
  411. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  412. {
  413. ++*pos;
  414. return c_start(m, pos);
  415. }
  416. static void c_stop(struct seq_file *m, void *v)
  417. {
  418. }
  419. struct seq_operations cpuinfo_op = {
  420. .start =c_start,
  421. .next = c_next,
  422. .stop = c_stop,
  423. .show = show_cpuinfo,
  424. };
  425. extern int stop_a_enabled;
  426. void sun_do_break(void)
  427. {
  428. if (!stop_a_enabled)
  429. return;
  430. prom_printf("\n");
  431. flush_user_windows();
  432. prom_cmdline();
  433. }
  434. int serial_console = -1;
  435. int stop_a_enabled = 1;
  436. static int __init topology_init(void)
  437. {
  438. int i, err;
  439. err = -ENOMEM;
  440. /* Count the number of physically present processors in
  441. * the machine, even on uniprocessor, so that /proc/cpuinfo
  442. * output is consistent with 2.4.x
  443. */
  444. ncpus_probed = 0;
  445. while (!cpu_find_by_instance(ncpus_probed, NULL, NULL))
  446. ncpus_probed++;
  447. for_each_possible_cpu(i) {
  448. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  449. if (p) {
  450. register_cpu(p, i);
  451. err = 0;
  452. }
  453. }
  454. return err;
  455. }
  456. subsys_initcall(topology_init);