setup.c 11 KB

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