setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. /* $Id: setup.c,v 1.126 2001/11/13 00:49:27 davem Exp $
  2. * linux/arch/sparc/kernel/setup.c
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
  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 <linux/initrd.h>
  16. #include <asm/smp.h>
  17. #include <linux/user.h>
  18. #include <linux/a.out.h>
  19. #include <linux/screen_info.h>
  20. #include <linux/delay.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/interrupt.h>
  29. #include <linux/console.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/root_dev.h>
  32. #include <linux/cpu.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/traps.h>
  40. #include <asm/vaddrs.h>
  41. #include <asm/kdebug.h>
  42. #include <asm/mbus.h>
  43. #include <asm/idprom.h>
  44. #include <asm/machines.h>
  45. #include <asm/cpudata.h>
  46. #include <asm/setup.h>
  47. struct screen_info screen_info = {
  48. 0, 0, /* orig-x, orig-y */
  49. 0, /* unused */
  50. 0, /* orig-video-page */
  51. 0, /* orig-video-mode */
  52. 128, /* orig-video-cols */
  53. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  54. 54, /* orig-video-lines */
  55. 0, /* orig-video-isVGA */
  56. 16 /* orig-video-points */
  57. };
  58. /* Typing sync at the prom prompt calls the function pointed to by
  59. * romvec->pv_synchook which I set to the following function.
  60. * This should sync all filesystems and return, for now it just
  61. * prints out pretty messages and returns.
  62. */
  63. extern unsigned long trapbase;
  64. void (*prom_palette)(int);
  65. /* Pretty sick eh? */
  66. void prom_sync_me(void)
  67. {
  68. unsigned long prom_tbr, flags;
  69. /* XXX Badly broken. FIX! - Anton */
  70. local_irq_save(flags);
  71. __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr));
  72. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  73. "nop\n\t"
  74. "nop\n\t"
  75. "nop\n\t" : : "r" (&trapbase));
  76. if (prom_palette)
  77. prom_palette(1);
  78. prom_printf("PROM SYNC COMMAND...\n");
  79. show_free_areas();
  80. if(current->pid != 0) {
  81. local_irq_enable();
  82. sys_sync();
  83. local_irq_disable();
  84. }
  85. prom_printf("Returning to prom\n");
  86. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  87. "nop\n\t"
  88. "nop\n\t"
  89. "nop\n\t" : : "r" (prom_tbr));
  90. local_irq_restore(flags);
  91. return;
  92. }
  93. unsigned int boot_flags __initdata = 0;
  94. #define BOOTME_DEBUG 0x1
  95. #define BOOTME_SINGLE 0x2
  96. /* Exported for mm/init.c:paging_init. */
  97. unsigned long cmdline_memory_size __initdata = 0;
  98. static void
  99. prom_console_write(struct console *con, const char *s, unsigned n)
  100. {
  101. prom_write(s, n);
  102. }
  103. static struct console prom_debug_console = {
  104. .name = "debug",
  105. .write = prom_console_write,
  106. .flags = CON_PRINTBUFFER,
  107. .index = -1,
  108. };
  109. int obp_system_intr(void)
  110. {
  111. if (boot_flags & BOOTME_DEBUG) {
  112. printk("OBP: system interrupted\n");
  113. prom_halt();
  114. return 1;
  115. }
  116. return 0;
  117. }
  118. /*
  119. * Process kernel command line switches that are specific to the
  120. * SPARC or that require special low-level processing.
  121. */
  122. static void __init process_switch(char c)
  123. {
  124. switch (c) {
  125. case 'd':
  126. boot_flags |= BOOTME_DEBUG;
  127. break;
  128. case 's':
  129. boot_flags |= BOOTME_SINGLE;
  130. break;
  131. case 'h':
  132. prom_printf("boot_flags_init: Halt!\n");
  133. prom_halt();
  134. break;
  135. case 'p':
  136. /* Use PROM debug console. */
  137. register_console(&prom_debug_console);
  138. break;
  139. default:
  140. printk("Unknown boot switch (-%c)\n", c);
  141. break;
  142. }
  143. }
  144. static void __init process_console(char *commands)
  145. {
  146. serial_console = 0;
  147. commands += 8;
  148. /* Linux-style serial */
  149. if (!strncmp(commands, "ttyS", 4))
  150. serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
  151. else if (!strncmp(commands, "tty", 3)) {
  152. char c = *(commands + 3);
  153. /* Solaris-style serial */
  154. if (c == 'a' || c == 'b')
  155. serial_console = c - 'a' + 1;
  156. /* else Linux-style fbcon, not serial */
  157. }
  158. #if defined(CONFIG_PROM_CONSOLE)
  159. if (!strncmp(commands, "prom", 4)) {
  160. char *p;
  161. for (p = commands - 8; *p && *p != ' '; p++)
  162. *p = ' ';
  163. conswitchp = &prom_con;
  164. }
  165. #endif
  166. }
  167. static void __init boot_flags_init(char *commands)
  168. {
  169. while (*commands) {
  170. /* Move to the start of the next "argument". */
  171. while (*commands && *commands == ' ')
  172. commands++;
  173. /* Process any command switches, otherwise skip it. */
  174. if (*commands == '\0')
  175. break;
  176. if (*commands == '-') {
  177. commands++;
  178. while (*commands && *commands != ' ')
  179. process_switch(*commands++);
  180. continue;
  181. }
  182. if (!strncmp(commands, "console=", 8)) {
  183. process_console(commands);
  184. } else if (!strncmp(commands, "mem=", 4)) {
  185. /*
  186. * "mem=XXX[kKmM] overrides the PROM-reported
  187. * memory size.
  188. */
  189. cmdline_memory_size = simple_strtoul(commands + 4,
  190. &commands, 0);
  191. if (*commands == 'K' || *commands == 'k') {
  192. cmdline_memory_size <<= 10;
  193. commands++;
  194. } else if (*commands=='M' || *commands=='m') {
  195. cmdline_memory_size <<= 20;
  196. commands++;
  197. }
  198. }
  199. while (*commands && *commands != ' ')
  200. commands++;
  201. }
  202. }
  203. /* This routine will in the future do all the nasty prom stuff
  204. * to probe for the mmu type and its parameters, etc. This will
  205. * also be where SMP things happen plus the Sparc specific memory
  206. * physical memory probe as on the alpha.
  207. */
  208. extern int prom_probe_memory(void);
  209. extern void sun4c_probe_vac(void);
  210. extern char cputypval;
  211. extern unsigned long start, end;
  212. extern void panic_setup(char *, int *);
  213. extern unsigned short root_flags;
  214. extern unsigned short root_dev;
  215. extern unsigned short ram_flags;
  216. #define RAMDISK_IMAGE_START_MASK 0x07FF
  217. #define RAMDISK_PROMPT_FLAG 0x8000
  218. #define RAMDISK_LOAD_FLAG 0x4000
  219. extern int root_mountflags;
  220. char reboot_command[COMMAND_LINE_SIZE];
  221. enum sparc_cpu sparc_cpu_model;
  222. struct tt_entry *sparc_ttable;
  223. struct pt_regs fake_swapper_regs;
  224. void __init setup_arch(char **cmdline_p)
  225. {
  226. int i;
  227. unsigned long highest_paddr;
  228. sparc_ttable = (struct tt_entry *) &start;
  229. /* Initialize PROM console and command line. */
  230. *cmdline_p = prom_getbootargs();
  231. strcpy(saved_command_line, *cmdline_p);
  232. /* Set sparc_cpu_model */
  233. sparc_cpu_model = sun_unknown;
  234. if(!strcmp(&cputypval,"sun4 ")) { sparc_cpu_model=sun4; }
  235. if(!strcmp(&cputypval,"sun4c")) { sparc_cpu_model=sun4c; }
  236. if(!strcmp(&cputypval,"sun4m")) { sparc_cpu_model=sun4m; }
  237. if(!strcmp(&cputypval,"sun4s")) { sparc_cpu_model=sun4m; } /* CP-1200 with PROM 2.30 -E */
  238. if(!strcmp(&cputypval,"sun4d")) { sparc_cpu_model=sun4d; }
  239. if(!strcmp(&cputypval,"sun4e")) { sparc_cpu_model=sun4e; }
  240. if(!strcmp(&cputypval,"sun4u")) { sparc_cpu_model=sun4u; }
  241. #ifdef CONFIG_SUN4
  242. if (sparc_cpu_model != sun4) {
  243. prom_printf("This kernel is for Sun4 architecture only.\n");
  244. prom_halt();
  245. }
  246. #endif
  247. printk("ARCH: ");
  248. switch(sparc_cpu_model) {
  249. case sun4:
  250. printk("SUN4\n");
  251. break;
  252. case sun4c:
  253. printk("SUN4C\n");
  254. break;
  255. case sun4m:
  256. printk("SUN4M\n");
  257. break;
  258. case sun4d:
  259. printk("SUN4D\n");
  260. break;
  261. case sun4e:
  262. printk("SUN4E\n");
  263. break;
  264. case sun4u:
  265. printk("SUN4U\n");
  266. break;
  267. default:
  268. printk("UNKNOWN!\n");
  269. break;
  270. };
  271. #ifdef CONFIG_DUMMY_CONSOLE
  272. conswitchp = &dummy_con;
  273. #elif defined(CONFIG_PROM_CONSOLE)
  274. conswitchp = &prom_con;
  275. #endif
  276. boot_flags_init(*cmdline_p);
  277. idprom_init();
  278. if (ARCH_SUN4C_SUN4)
  279. sun4c_probe_vac();
  280. load_mmu();
  281. (void) prom_probe_memory();
  282. phys_base = 0xffffffffUL;
  283. highest_paddr = 0UL;
  284. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  285. unsigned long top;
  286. if (sp_banks[i].base_addr < phys_base)
  287. phys_base = sp_banks[i].base_addr;
  288. top = sp_banks[i].base_addr +
  289. sp_banks[i].num_bytes;
  290. if (highest_paddr < top)
  291. highest_paddr = top;
  292. }
  293. pfn_base = phys_base >> PAGE_SHIFT;
  294. if (!root_flags)
  295. root_mountflags &= ~MS_RDONLY;
  296. ROOT_DEV = old_decode_dev(root_dev);
  297. #ifdef CONFIG_BLK_DEV_RAM
  298. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  299. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  300. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  301. #endif
  302. prom_setsync(prom_sync_me);
  303. if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
  304. ((*(short *)linux_dbvec) != -1)) {
  305. printk("Booted under KADB. Syncing trap table.\n");
  306. (*(linux_dbvec->teach_debugger))();
  307. }
  308. init_mm.context = (unsigned long) NO_CONTEXT;
  309. init_task.thread.kregs = &fake_swapper_regs;
  310. paging_init();
  311. smp_setup_cpu_possible_map();
  312. }
  313. static int __init set_preferred_console(void)
  314. {
  315. int idev, odev;
  316. /* The user has requested a console so this is already set up. */
  317. if (serial_console >= 0)
  318. return -EBUSY;
  319. idev = prom_query_input_device();
  320. odev = prom_query_output_device();
  321. if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
  322. serial_console = 0;
  323. } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
  324. serial_console = 1;
  325. } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
  326. serial_console = 2;
  327. } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OTTYA) {
  328. prom_printf("MrCoffee ttya\n");
  329. serial_console = 1;
  330. } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OSCREEN) {
  331. serial_console = 0;
  332. prom_printf("MrCoffee keyboard\n");
  333. } else {
  334. prom_printf("Confusing console (idev %d, odev %d)\n",
  335. idev, odev);
  336. serial_console = 1;
  337. }
  338. if (serial_console)
  339. return add_preferred_console("ttyS", serial_console - 1, NULL);
  340. return -ENODEV;
  341. }
  342. console_initcall(set_preferred_console);
  343. extern char *sparc_cpu_type;
  344. extern char *sparc_fpu_type;
  345. static int ncpus_probed;
  346. static int show_cpuinfo(struct seq_file *m, void *__unused)
  347. {
  348. seq_printf(m,
  349. "cpu\t\t: %s\n"
  350. "fpu\t\t: %s\n"
  351. "promlib\t\t: Version %d Revision %d\n"
  352. "prom\t\t: %d.%d\n"
  353. "type\t\t: %s\n"
  354. "ncpus probed\t: %d\n"
  355. "ncpus active\t: %d\n"
  356. #ifndef CONFIG_SMP
  357. "CPU0Bogo\t: %lu.%02lu\n"
  358. "CPU0ClkTck\t: %ld\n"
  359. #endif
  360. ,
  361. sparc_cpu_type ? sparc_cpu_type : "undetermined",
  362. sparc_fpu_type ? sparc_fpu_type : "undetermined",
  363. romvec->pv_romvers,
  364. prom_rev,
  365. romvec->pv_printrev >> 16,
  366. romvec->pv_printrev & 0xffff,
  367. &cputypval,
  368. ncpus_probed,
  369. num_online_cpus()
  370. #ifndef CONFIG_SMP
  371. , cpu_data(0).udelay_val/(500000/HZ),
  372. (cpu_data(0).udelay_val/(5000/HZ)) % 100,
  373. cpu_data(0).clock_tick
  374. #endif
  375. );
  376. #ifdef CONFIG_SMP
  377. smp_bogo(m);
  378. #endif
  379. mmu_info(m);
  380. #ifdef CONFIG_SMP
  381. smp_info(m);
  382. #endif
  383. return 0;
  384. }
  385. static void *c_start(struct seq_file *m, loff_t *pos)
  386. {
  387. /* The pointer we are returning is arbitrary,
  388. * it just has to be non-NULL and not IS_ERR
  389. * in the success case.
  390. */
  391. return *pos == 0 ? &c_start : NULL;
  392. }
  393. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  394. {
  395. ++*pos;
  396. return c_start(m, pos);
  397. }
  398. static void c_stop(struct seq_file *m, void *v)
  399. {
  400. }
  401. struct seq_operations cpuinfo_op = {
  402. .start =c_start,
  403. .next = c_next,
  404. .stop = c_stop,
  405. .show = show_cpuinfo,
  406. };
  407. extern int stop_a_enabled;
  408. void sun_do_break(void)
  409. {
  410. if (!stop_a_enabled)
  411. return;
  412. printk("\n");
  413. flush_user_windows();
  414. prom_cmdline();
  415. }
  416. int serial_console = -1;
  417. int stop_a_enabled = 1;
  418. static int __init topology_init(void)
  419. {
  420. int i, ncpus, err;
  421. /* Count the number of physically present processors in
  422. * the machine, even on uniprocessor, so that /proc/cpuinfo
  423. * output is consistent with 2.4.x
  424. */
  425. ncpus = 0;
  426. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  427. ncpus++;
  428. ncpus_probed = ncpus;
  429. err = 0;
  430. for_each_online_cpu(i) {
  431. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  432. if (!p)
  433. err = -ENOMEM;
  434. else
  435. register_cpu(p, i);
  436. }
  437. return err;
  438. }
  439. subsys_initcall(topology_init);