setup.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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/tty.h>
  19. #include <linux/delay.h>
  20. #include <linux/config.h>
  21. #include <linux/fs.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/kdev_t.h>
  25. #include <linux/major.h>
  26. #include <linux/string.h>
  27. #include <linux/init.h>
  28. #include <linux/inet.h>
  29. #include <linux/console.h>
  30. #include <linux/root_dev.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/cpu.h>
  33. #include <linux/initrd.h>
  34. #include <asm/system.h>
  35. #include <asm/io.h>
  36. #include <asm/processor.h>
  37. #include <asm/oplib.h>
  38. #include <asm/page.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/idprom.h>
  41. #include <asm/head.h>
  42. #include <asm/starfire.h>
  43. #include <asm/mmu_context.h>
  44. #include <asm/timer.h>
  45. #include <asm/sections.h>
  46. #include <asm/setup.h>
  47. #include <asm/mmu.h>
  48. #ifdef CONFIG_IP_PNP
  49. #include <net/ipconfig.h>
  50. #endif
  51. struct screen_info screen_info = {
  52. 0, 0, /* orig-x, orig-y */
  53. 0, /* unused */
  54. 0, /* orig-video-page */
  55. 0, /* orig-video-mode */
  56. 128, /* orig-video-cols */
  57. 0, 0, 0, /* unused, ega_bx, unused */
  58. 54, /* orig-video-lines */
  59. 0, /* orig-video-isVGA */
  60. 16 /* orig-video-points */
  61. };
  62. /* Typing sync at the prom prompt calls the function pointed to by
  63. * the sync callback which I set to the following function.
  64. * This should sync all filesystems and return, for now it just
  65. * prints out pretty messages and returns.
  66. */
  67. void (*prom_palette)(int);
  68. void (*prom_keyboard)(void);
  69. static void
  70. prom_console_write(struct console *con, const char *s, unsigned n)
  71. {
  72. prom_write(s, n);
  73. }
  74. static struct console prom_console = {
  75. .name = "prom",
  76. .write = prom_console_write,
  77. .flags = CON_CONSDEV | CON_ENABLED,
  78. .index = -1,
  79. };
  80. #define PROM_TRUE -1
  81. #define PROM_FALSE 0
  82. /* Pretty sick eh? */
  83. int prom_callback(long *args)
  84. {
  85. struct console *cons, *saved_console = NULL;
  86. unsigned long flags;
  87. char *cmd;
  88. extern spinlock_t prom_entry_lock;
  89. if (!args)
  90. return -1;
  91. if (!(cmd = (char *)args[0]))
  92. return -1;
  93. /*
  94. * The callback can be invoked on the cpu that first dropped
  95. * into prom_cmdline after taking the serial interrupt, or on
  96. * a slave processor that was smp_captured() if the
  97. * administrator has done a switch-cpu inside obp. In either
  98. * case, the cpu is marked as in-interrupt. Drop IRQ locks.
  99. */
  100. irq_exit();
  101. /* XXX Revisit the locking here someday. This is a debugging
  102. * XXX feature so it isnt all that critical. -DaveM
  103. */
  104. local_irq_save(flags);
  105. spin_unlock(&prom_entry_lock);
  106. cons = console_drivers;
  107. while (cons) {
  108. unregister_console(cons);
  109. cons->flags &= ~(CON_PRINTBUFFER);
  110. cons->next = saved_console;
  111. saved_console = cons;
  112. cons = console_drivers;
  113. }
  114. register_console(&prom_console);
  115. if (!strcmp(cmd, "sync")) {
  116. prom_printf("PROM `%s' command...\n", cmd);
  117. show_free_areas();
  118. if (current->pid != 0) {
  119. local_irq_enable();
  120. sys_sync();
  121. local_irq_disable();
  122. }
  123. args[2] = 0;
  124. args[args[1] + 3] = -1;
  125. prom_printf("Returning to PROM\n");
  126. } else if (!strcmp(cmd, "va>tte-data")) {
  127. unsigned long ctx, va;
  128. unsigned long tte = 0;
  129. long res = PROM_FALSE;
  130. ctx = args[3];
  131. va = args[4];
  132. if (ctx) {
  133. /*
  134. * Find process owning ctx, lookup mapping.
  135. */
  136. struct task_struct *p;
  137. struct mm_struct *mm = NULL;
  138. pgd_t *pgdp;
  139. pud_t *pudp;
  140. pmd_t *pmdp;
  141. pte_t *ptep;
  142. for_each_process(p) {
  143. mm = p->mm;
  144. if (CTX_NRBITS(mm->context) == ctx)
  145. break;
  146. }
  147. if (!mm ||
  148. CTX_NRBITS(mm->context) != ctx)
  149. goto done;
  150. pgdp = pgd_offset(mm, va);
  151. if (pgd_none(*pgdp))
  152. goto done;
  153. pudp = pud_offset(pgdp, va);
  154. if (pud_none(*pudp))
  155. goto done;
  156. pmdp = pmd_offset(pudp, va);
  157. if (pmd_none(*pmdp))
  158. goto done;
  159. /* Preemption implicitly disabled by virtue of
  160. * being called from inside OBP.
  161. */
  162. ptep = pte_offset_map(pmdp, va);
  163. if (pte_present(*ptep)) {
  164. tte = pte_val(*ptep);
  165. res = PROM_TRUE;
  166. }
  167. pte_unmap(ptep);
  168. goto done;
  169. }
  170. if ((va >= KERNBASE) && (va < (KERNBASE + (4 * 1024 * 1024)))) {
  171. extern unsigned long sparc64_kern_pri_context;
  172. /* Spitfire Errata #32 workaround */
  173. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  174. "flush %%g6"
  175. : /* No outputs */
  176. : "r" (sparc64_kern_pri_context),
  177. "r" (PRIMARY_CONTEXT),
  178. "i" (ASI_DMMU));
  179. /*
  180. * Locked down tlb entry.
  181. */
  182. if (tlb_type == spitfire)
  183. tte = spitfire_get_dtlb_data(SPITFIRE_HIGHEST_LOCKED_TLBENT);
  184. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  185. tte = cheetah_get_ldtlb_data(CHEETAH_HIGHEST_LOCKED_TLBENT);
  186. res = PROM_TRUE;
  187. goto done;
  188. }
  189. if (va < PGDIR_SIZE) {
  190. /*
  191. * vmalloc or prom_inherited mapping.
  192. */
  193. pgd_t *pgdp;
  194. pud_t *pudp;
  195. pmd_t *pmdp;
  196. pte_t *ptep;
  197. int error;
  198. if ((va >= LOW_OBP_ADDRESS) && (va < HI_OBP_ADDRESS)) {
  199. tte = prom_virt_to_phys(va, &error);
  200. if (!error)
  201. res = PROM_TRUE;
  202. goto done;
  203. }
  204. pgdp = pgd_offset_k(va);
  205. if (pgd_none(*pgdp))
  206. goto done;
  207. pudp = pud_offset(pgdp, va);
  208. if (pud_none(*pudp))
  209. goto done;
  210. pmdp = pmd_offset(pudp, va);
  211. if (pmd_none(*pmdp))
  212. goto done;
  213. /* Preemption implicitly disabled by virtue of
  214. * being called from inside OBP.
  215. */
  216. ptep = pte_offset_kernel(pmdp, va);
  217. if (pte_present(*ptep)) {
  218. tte = pte_val(*ptep);
  219. res = PROM_TRUE;
  220. }
  221. goto done;
  222. }
  223. if (va < PAGE_OFFSET) {
  224. /*
  225. * No mappings here.
  226. */
  227. goto done;
  228. }
  229. if (va & (1UL << 40)) {
  230. /*
  231. * I/O page.
  232. */
  233. tte = (__pa(va) & _PAGE_PADDR) |
  234. _PAGE_VALID | _PAGE_SZ4MB |
  235. _PAGE_E | _PAGE_P | _PAGE_W;
  236. res = PROM_TRUE;
  237. goto done;
  238. }
  239. /*
  240. * Normal page.
  241. */
  242. tte = (__pa(va) & _PAGE_PADDR) |
  243. _PAGE_VALID | _PAGE_SZ4MB |
  244. _PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W;
  245. res = PROM_TRUE;
  246. done:
  247. if (res == PROM_TRUE) {
  248. args[2] = 3;
  249. args[args[1] + 3] = 0;
  250. args[args[1] + 4] = res;
  251. args[args[1] + 5] = tte;
  252. } else {
  253. args[2] = 2;
  254. args[args[1] + 3] = 0;
  255. args[args[1] + 4] = res;
  256. }
  257. } else if (!strcmp(cmd, ".soft1")) {
  258. unsigned long tte;
  259. tte = args[3];
  260. prom_printf("%lx:\"%s%s%s%s%s\" ",
  261. (tte & _PAGE_SOFT) >> 7,
  262. tte & _PAGE_MODIFIED ? "M" : "-",
  263. tte & _PAGE_ACCESSED ? "A" : "-",
  264. tte & _PAGE_READ ? "W" : "-",
  265. tte & _PAGE_WRITE ? "R" : "-",
  266. tte & _PAGE_PRESENT ? "P" : "-");
  267. args[2] = 2;
  268. args[args[1] + 3] = 0;
  269. args[args[1] + 4] = PROM_TRUE;
  270. } else if (!strcmp(cmd, ".soft2")) {
  271. unsigned long tte;
  272. tte = args[3];
  273. prom_printf("%lx ", (tte & 0x07FC000000000000UL) >> 50);
  274. args[2] = 2;
  275. args[args[1] + 3] = 0;
  276. args[args[1] + 4] = PROM_TRUE;
  277. } else {
  278. prom_printf("unknown PROM `%s' command...\n", cmd);
  279. }
  280. unregister_console(&prom_console);
  281. while (saved_console) {
  282. cons = saved_console;
  283. saved_console = cons->next;
  284. register_console(cons);
  285. }
  286. spin_lock(&prom_entry_lock);
  287. local_irq_restore(flags);
  288. /*
  289. * Restore in-interrupt status for a resume from obp.
  290. */
  291. irq_enter();
  292. return 0;
  293. }
  294. unsigned int boot_flags = 0;
  295. #define BOOTME_DEBUG 0x1
  296. #define BOOTME_SINGLE 0x2
  297. /* Exported for mm/init.c:paging_init. */
  298. unsigned long cmdline_memory_size = 0;
  299. static struct console prom_debug_console = {
  300. .name = "debug",
  301. .write = prom_console_write,
  302. .flags = CON_PRINTBUFFER,
  303. .index = -1,
  304. };
  305. /* XXX Implement this at some point... */
  306. void kernel_enter_debugger(void)
  307. {
  308. }
  309. int obp_system_intr(void)
  310. {
  311. if (boot_flags & BOOTME_DEBUG) {
  312. printk("OBP: system interrupted\n");
  313. prom_halt();
  314. return 1;
  315. }
  316. return 0;
  317. }
  318. /*
  319. * Process kernel command line switches that are specific to the
  320. * SPARC or that require special low-level processing.
  321. */
  322. static void __init process_switch(char c)
  323. {
  324. switch (c) {
  325. case 'd':
  326. boot_flags |= BOOTME_DEBUG;
  327. break;
  328. case 's':
  329. boot_flags |= BOOTME_SINGLE;
  330. break;
  331. case 'h':
  332. prom_printf("boot_flags_init: Halt!\n");
  333. prom_halt();
  334. break;
  335. case 'p':
  336. /* Use PROM debug console. */
  337. register_console(&prom_debug_console);
  338. break;
  339. case 'P':
  340. /* Force UltraSPARC-III P-Cache on. */
  341. if (tlb_type != cheetah) {
  342. printk("BOOT: Ignoring P-Cache force option.\n");
  343. break;
  344. }
  345. cheetah_pcache_forced_on = 1;
  346. add_taint(TAINT_MACHINE_CHECK);
  347. cheetah_enable_pcache();
  348. break;
  349. default:
  350. printk("Unknown boot switch (-%c)\n", c);
  351. break;
  352. }
  353. }
  354. static void __init process_console(char *commands)
  355. {
  356. serial_console = 0;
  357. commands += 8;
  358. /* Linux-style serial */
  359. if (!strncmp(commands, "ttyS", 4))
  360. serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
  361. else if (!strncmp(commands, "tty", 3)) {
  362. char c = *(commands + 3);
  363. /* Solaris-style serial */
  364. if (c == 'a' || c == 'b') {
  365. serial_console = c - 'a' + 1;
  366. prom_printf ("Using /dev/tty%c as console.\n", c);
  367. }
  368. /* else Linux-style fbcon, not serial */
  369. }
  370. #if defined(CONFIG_PROM_CONSOLE)
  371. if (!strncmp(commands, "prom", 4)) {
  372. char *p;
  373. for (p = commands - 8; *p && *p != ' '; p++)
  374. *p = ' ';
  375. conswitchp = &prom_con;
  376. }
  377. #endif
  378. }
  379. static void __init boot_flags_init(char *commands)
  380. {
  381. while (*commands) {
  382. /* Move to the start of the next "argument". */
  383. while (*commands && *commands == ' ')
  384. commands++;
  385. /* Process any command switches, otherwise skip it. */
  386. if (*commands == '\0')
  387. break;
  388. if (*commands == '-') {
  389. commands++;
  390. while (*commands && *commands != ' ')
  391. process_switch(*commands++);
  392. continue;
  393. }
  394. if (!strncmp(commands, "console=", 8)) {
  395. process_console(commands);
  396. } else if (!strncmp(commands, "mem=", 4)) {
  397. /*
  398. * "mem=XXX[kKmM]" overrides the PROM-reported
  399. * memory size.
  400. */
  401. cmdline_memory_size = simple_strtoul(commands + 4,
  402. &commands, 0);
  403. if (*commands == 'K' || *commands == 'k') {
  404. cmdline_memory_size <<= 10;
  405. commands++;
  406. } else if (*commands=='M' || *commands=='m') {
  407. cmdline_memory_size <<= 20;
  408. commands++;
  409. }
  410. }
  411. while (*commands && *commands != ' ')
  412. commands++;
  413. }
  414. }
  415. extern void panic_setup(char *, int *);
  416. extern unsigned short root_flags;
  417. extern unsigned short root_dev;
  418. extern unsigned short ram_flags;
  419. #define RAMDISK_IMAGE_START_MASK 0x07FF
  420. #define RAMDISK_PROMPT_FLAG 0x8000
  421. #define RAMDISK_LOAD_FLAG 0x4000
  422. extern int root_mountflags;
  423. char reboot_command[COMMAND_LINE_SIZE];
  424. static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
  425. void register_prom_callbacks(void)
  426. {
  427. prom_setcallback(prom_callback);
  428. prom_feval(": linux-va>tte-data 2 \" va>tte-data\" $callback drop ; "
  429. "' linux-va>tte-data to va>tte-data");
  430. prom_feval(": linux-.soft1 1 \" .soft1\" $callback 2drop ; "
  431. "' linux-.soft1 to .soft1");
  432. prom_feval(": linux-.soft2 1 \" .soft2\" $callback 2drop ; "
  433. "' linux-.soft2 to .soft2");
  434. }
  435. void __init setup_arch(char **cmdline_p)
  436. {
  437. /* Initialize PROM console and command line. */
  438. *cmdline_p = prom_getbootargs();
  439. strcpy(saved_command_line, *cmdline_p);
  440. printk("ARCH: SUN4U\n");
  441. #ifdef CONFIG_DUMMY_CONSOLE
  442. conswitchp = &dummy_con;
  443. #elif defined(CONFIG_PROM_CONSOLE)
  444. conswitchp = &prom_con;
  445. #endif
  446. /* Work out if we are starfire early on */
  447. check_if_starfire();
  448. boot_flags_init(*cmdline_p);
  449. idprom_init();
  450. if (!root_flags)
  451. root_mountflags &= ~MS_RDONLY;
  452. ROOT_DEV = old_decode_dev(root_dev);
  453. #ifdef CONFIG_BLK_DEV_INITRD
  454. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  455. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  456. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  457. #endif
  458. init_task.thread_info->kregs = &fake_swapper_regs;
  459. #ifdef CONFIG_IP_PNP
  460. if (!ic_set_manually) {
  461. int chosen = prom_finddevice ("/chosen");
  462. u32 cl, sv, gw;
  463. cl = prom_getintdefault (chosen, "client-ip", 0);
  464. sv = prom_getintdefault (chosen, "server-ip", 0);
  465. gw = prom_getintdefault (chosen, "gateway-ip", 0);
  466. if (cl && sv) {
  467. ic_myaddr = cl;
  468. ic_servaddr = sv;
  469. if (gw)
  470. ic_gateway = gw;
  471. #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
  472. ic_proto_enabled = 0;
  473. #endif
  474. }
  475. }
  476. #endif
  477. paging_init();
  478. }
  479. static int __init set_preferred_console(void)
  480. {
  481. int idev, odev;
  482. /* The user has requested a console so this is already set up. */
  483. if (serial_console >= 0)
  484. return -EBUSY;
  485. idev = prom_query_input_device();
  486. odev = prom_query_output_device();
  487. if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
  488. serial_console = 0;
  489. } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
  490. serial_console = 1;
  491. } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
  492. serial_console = 2;
  493. } else {
  494. prom_printf("Inconsistent console: "
  495. "input %d, output %d\n",
  496. idev, odev);
  497. prom_halt();
  498. }
  499. if (serial_console)
  500. return add_preferred_console("ttyS", serial_console - 1, NULL);
  501. return -ENODEV;
  502. }
  503. console_initcall(set_preferred_console);
  504. /* BUFFER is PAGE_SIZE bytes long. */
  505. extern char *sparc_cpu_type;
  506. extern char *sparc_fpu_type;
  507. extern void smp_info(struct seq_file *);
  508. extern void smp_bogo(struct seq_file *);
  509. extern void mmu_info(struct seq_file *);
  510. unsigned int dcache_parity_tl1_occurred;
  511. unsigned int icache_parity_tl1_occurred;
  512. static int show_cpuinfo(struct seq_file *m, void *__unused)
  513. {
  514. seq_printf(m,
  515. "cpu\t\t: %s\n"
  516. "fpu\t\t: %s\n"
  517. "promlib\t\t: Version 3 Revision %d\n"
  518. "prom\t\t: %d.%d.%d\n"
  519. "type\t\t: sun4u\n"
  520. "ncpus probed\t: %ld\n"
  521. "ncpus active\t: %ld\n"
  522. "D$ parity tl1\t: %u\n"
  523. "I$ parity tl1\t: %u\n"
  524. #ifndef CONFIG_SMP
  525. "Cpu0Bogo\t: %lu.%02lu\n"
  526. "Cpu0ClkTck\t: %016lx\n"
  527. #endif
  528. ,
  529. sparc_cpu_type,
  530. sparc_fpu_type,
  531. prom_rev,
  532. prom_prev >> 16,
  533. (prom_prev >> 8) & 0xff,
  534. prom_prev & 0xff,
  535. (long)num_possible_cpus(),
  536. (long)num_online_cpus(),
  537. dcache_parity_tl1_occurred,
  538. icache_parity_tl1_occurred
  539. #ifndef CONFIG_SMP
  540. , cpu_data(0).udelay_val/(500000/HZ),
  541. (cpu_data(0).udelay_val/(5000/HZ)) % 100,
  542. cpu_data(0).clock_tick
  543. #endif
  544. );
  545. #ifdef CONFIG_SMP
  546. smp_bogo(m);
  547. #endif
  548. mmu_info(m);
  549. #ifdef CONFIG_SMP
  550. smp_info(m);
  551. #endif
  552. return 0;
  553. }
  554. static void *c_start(struct seq_file *m, loff_t *pos)
  555. {
  556. /* The pointer we are returning is arbitrary,
  557. * it just has to be non-NULL and not IS_ERR
  558. * in the success case.
  559. */
  560. return *pos == 0 ? &c_start : NULL;
  561. }
  562. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  563. {
  564. ++*pos;
  565. return c_start(m, pos);
  566. }
  567. static void c_stop(struct seq_file *m, void *v)
  568. {
  569. }
  570. struct seq_operations cpuinfo_op = {
  571. .start =c_start,
  572. .next = c_next,
  573. .stop = c_stop,
  574. .show = show_cpuinfo,
  575. };
  576. extern int stop_a_enabled;
  577. void sun_do_break(void)
  578. {
  579. if (!stop_a_enabled)
  580. return;
  581. prom_printf("\n");
  582. flush_user_windows();
  583. prom_cmdline();
  584. }
  585. int serial_console = -1;
  586. int stop_a_enabled = 1;
  587. static int __init topology_init(void)
  588. {
  589. int i, err;
  590. err = -ENOMEM;
  591. for (i = 0; i < NR_CPUS; i++) {
  592. if (cpu_possible(i)) {
  593. struct cpu *p = kmalloc(sizeof(*p), GFP_KERNEL);
  594. if (p) {
  595. memset(p, 0, sizeof(*p));
  596. register_cpu(p, i, NULL);
  597. err = 0;
  598. }
  599. }
  600. }
  601. return err;
  602. }
  603. subsys_initcall(topology_init);