setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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. /*
  84. * Process kernel command line switches that are specific to the
  85. * SPARC or that require special low-level processing.
  86. */
  87. static void __init process_switch(char c)
  88. {
  89. switch (c) {
  90. case 'd':
  91. boot_flags |= BOOTME_DEBUG;
  92. break;
  93. case 's':
  94. boot_flags |= BOOTME_SINGLE;
  95. break;
  96. case 'h':
  97. prom_printf("boot_flags_init: Halt!\n");
  98. prom_halt();
  99. break;
  100. case 'p':
  101. /* Use PROM debug console. */
  102. register_console(&prom_debug_console);
  103. break;
  104. case 'P':
  105. /* Force UltraSPARC-III P-Cache on. */
  106. if (tlb_type != cheetah) {
  107. printk("BOOT: Ignoring P-Cache force option.\n");
  108. break;
  109. }
  110. cheetah_pcache_forced_on = 1;
  111. add_taint(TAINT_MACHINE_CHECK);
  112. cheetah_enable_pcache();
  113. break;
  114. default:
  115. printk("Unknown boot switch (-%c)\n", c);
  116. break;
  117. }
  118. }
  119. static void __init process_console(char *commands)
  120. {
  121. serial_console = 0;
  122. commands += 8;
  123. /* Linux-style serial */
  124. if (!strncmp(commands, "ttyS", 4))
  125. serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
  126. else if (!strncmp(commands, "tty", 3)) {
  127. char c = *(commands + 3);
  128. /* Solaris-style serial */
  129. if (c == 'a' || c == 'b') {
  130. serial_console = c - 'a' + 1;
  131. prom_printf ("Using /dev/tty%c as console.\n", c);
  132. }
  133. /* else Linux-style fbcon, not serial */
  134. }
  135. #if defined(CONFIG_PROM_CONSOLE)
  136. if (!strncmp(commands, "prom", 4)) {
  137. char *p;
  138. for (p = commands - 8; *p && *p != ' '; p++)
  139. *p = ' ';
  140. conswitchp = &prom_con;
  141. }
  142. #endif
  143. }
  144. static void __init boot_flags_init(char *commands)
  145. {
  146. while (*commands) {
  147. /* Move to the start of the next "argument". */
  148. while (*commands && *commands == ' ')
  149. commands++;
  150. /* Process any command switches, otherwise skip it. */
  151. if (*commands == '\0')
  152. break;
  153. if (*commands == '-') {
  154. commands++;
  155. while (*commands && *commands != ' ')
  156. process_switch(*commands++);
  157. continue;
  158. }
  159. if (!strncmp(commands, "console=", 8)) {
  160. process_console(commands);
  161. } else if (!strncmp(commands, "mem=", 4)) {
  162. /*
  163. * "mem=XXX[kKmM]" overrides the PROM-reported
  164. * memory size.
  165. */
  166. cmdline_memory_size = simple_strtoul(commands + 4,
  167. &commands, 0);
  168. if (*commands == 'K' || *commands == 'k') {
  169. cmdline_memory_size <<= 10;
  170. commands++;
  171. } else if (*commands=='M' || *commands=='m') {
  172. cmdline_memory_size <<= 20;
  173. commands++;
  174. }
  175. }
  176. while (*commands && *commands != ' ')
  177. commands++;
  178. }
  179. }
  180. extern void panic_setup(char *, int *);
  181. extern unsigned short root_flags;
  182. extern unsigned short root_dev;
  183. extern unsigned short ram_flags;
  184. #define RAMDISK_IMAGE_START_MASK 0x07FF
  185. #define RAMDISK_PROMPT_FLAG 0x8000
  186. #define RAMDISK_LOAD_FLAG 0x4000
  187. extern int root_mountflags;
  188. char reboot_command[COMMAND_LINE_SIZE];
  189. static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
  190. void __init per_cpu_patch(void)
  191. {
  192. struct cpuid_patch_entry *p;
  193. unsigned long ver;
  194. int is_jbus;
  195. if (tlb_type == spitfire && !this_is_starfire)
  196. return;
  197. is_jbus = 0;
  198. if (tlb_type != hypervisor) {
  199. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  200. is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
  201. (ver >> 32UL) == __SERRANO_ID);
  202. }
  203. p = &__cpuid_patch;
  204. while (p < &__cpuid_patch_end) {
  205. unsigned long addr = p->addr;
  206. unsigned int *insns;
  207. switch (tlb_type) {
  208. case spitfire:
  209. insns = &p->starfire[0];
  210. break;
  211. case cheetah:
  212. case cheetah_plus:
  213. if (is_jbus)
  214. insns = &p->cheetah_jbus[0];
  215. else
  216. insns = &p->cheetah_safari[0];
  217. break;
  218. case hypervisor:
  219. insns = &p->sun4v[0];
  220. break;
  221. default:
  222. prom_printf("Unknown cpu type, halting.\n");
  223. prom_halt();
  224. };
  225. *(unsigned int *) (addr + 0) = insns[0];
  226. wmb();
  227. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  228. *(unsigned int *) (addr + 4) = insns[1];
  229. wmb();
  230. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  231. *(unsigned int *) (addr + 8) = insns[2];
  232. wmb();
  233. __asm__ __volatile__("flush %0" : : "r" (addr + 8));
  234. *(unsigned int *) (addr + 12) = insns[3];
  235. wmb();
  236. __asm__ __volatile__("flush %0" : : "r" (addr + 12));
  237. p++;
  238. }
  239. }
  240. void __init sun4v_patch(void)
  241. {
  242. struct sun4v_1insn_patch_entry *p1;
  243. struct sun4v_2insn_patch_entry *p2;
  244. if (tlb_type != hypervisor)
  245. return;
  246. p1 = &__sun4v_1insn_patch;
  247. while (p1 < &__sun4v_1insn_patch_end) {
  248. unsigned long addr = p1->addr;
  249. *(unsigned int *) (addr + 0) = p1->insn;
  250. wmb();
  251. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  252. p1++;
  253. }
  254. p2 = &__sun4v_2insn_patch;
  255. while (p2 < &__sun4v_2insn_patch_end) {
  256. unsigned long addr = p2->addr;
  257. *(unsigned int *) (addr + 0) = p2->insns[0];
  258. wmb();
  259. __asm__ __volatile__("flush %0" : : "r" (addr + 0));
  260. *(unsigned int *) (addr + 4) = p2->insns[1];
  261. wmb();
  262. __asm__ __volatile__("flush %0" : : "r" (addr + 4));
  263. p2++;
  264. }
  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(saved_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);