setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. /*
  110. * Process kernel command line switches that are specific to the
  111. * SPARC or that require special low-level processing.
  112. */
  113. static void __init process_switch(char c)
  114. {
  115. switch (c) {
  116. case 'd':
  117. boot_flags |= BOOTME_DEBUG;
  118. break;
  119. case 's':
  120. boot_flags |= BOOTME_SINGLE;
  121. break;
  122. case 'h':
  123. prom_printf("boot_flags_init: Halt!\n");
  124. prom_halt();
  125. break;
  126. case 'p':
  127. /* Use PROM debug console. */
  128. register_console(&prom_debug_console);
  129. break;
  130. default:
  131. printk("Unknown boot switch (-%c)\n", c);
  132. break;
  133. }
  134. }
  135. static void __init process_console(char *commands)
  136. {
  137. serial_console = 0;
  138. commands += 8;
  139. /* Linux-style serial */
  140. if (!strncmp(commands, "ttyS", 4))
  141. serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
  142. else if (!strncmp(commands, "tty", 3)) {
  143. char c = *(commands + 3);
  144. /* Solaris-style serial */
  145. if (c == 'a' || c == 'b')
  146. serial_console = c - 'a' + 1;
  147. /* else Linux-style fbcon, not serial */
  148. }
  149. #if defined(CONFIG_PROM_CONSOLE)
  150. if (!strncmp(commands, "prom", 4)) {
  151. char *p;
  152. for (p = commands - 8; *p && *p != ' '; p++)
  153. *p = ' ';
  154. conswitchp = &prom_con;
  155. }
  156. #endif
  157. }
  158. static void __init boot_flags_init(char *commands)
  159. {
  160. while (*commands) {
  161. /* Move to the start of the next "argument". */
  162. while (*commands && *commands == ' ')
  163. commands++;
  164. /* Process any command switches, otherwise skip it. */
  165. if (*commands == '\0')
  166. break;
  167. if (*commands == '-') {
  168. commands++;
  169. while (*commands && *commands != ' ')
  170. process_switch(*commands++);
  171. continue;
  172. }
  173. if (!strncmp(commands, "console=", 8)) {
  174. process_console(commands);
  175. } else if (!strncmp(commands, "mem=", 4)) {
  176. /*
  177. * "mem=XXX[kKmM] overrides the PROM-reported
  178. * memory size.
  179. */
  180. cmdline_memory_size = simple_strtoul(commands + 4,
  181. &commands, 0);
  182. if (*commands == 'K' || *commands == 'k') {
  183. cmdline_memory_size <<= 10;
  184. commands++;
  185. } else if (*commands=='M' || *commands=='m') {
  186. cmdline_memory_size <<= 20;
  187. commands++;
  188. }
  189. }
  190. while (*commands && *commands != ' ')
  191. commands++;
  192. }
  193. }
  194. /* This routine will in the future do all the nasty prom stuff
  195. * to probe for the mmu type and its parameters, etc. This will
  196. * also be where SMP things happen plus the Sparc specific memory
  197. * physical memory probe as on the alpha.
  198. */
  199. extern int prom_probe_memory(void);
  200. extern void sun4c_probe_vac(void);
  201. extern char cputypval;
  202. extern unsigned long start, end;
  203. extern void panic_setup(char *, int *);
  204. extern unsigned short root_flags;
  205. extern unsigned short root_dev;
  206. extern unsigned short ram_flags;
  207. #define RAMDISK_IMAGE_START_MASK 0x07FF
  208. #define RAMDISK_PROMPT_FLAG 0x8000
  209. #define RAMDISK_LOAD_FLAG 0x4000
  210. extern int root_mountflags;
  211. char reboot_command[COMMAND_LINE_SIZE];
  212. enum sparc_cpu sparc_cpu_model;
  213. struct tt_entry *sparc_ttable;
  214. struct pt_regs fake_swapper_regs;
  215. void __init setup_arch(char **cmdline_p)
  216. {
  217. int i;
  218. unsigned long highest_paddr;
  219. sparc_ttable = (struct tt_entry *) &start;
  220. /* Initialize PROM console and command line. */
  221. *cmdline_p = prom_getbootargs();
  222. strcpy(saved_command_line, *cmdline_p);
  223. /* Set sparc_cpu_model */
  224. sparc_cpu_model = sun_unknown;
  225. if(!strcmp(&cputypval,"sun4 ")) { sparc_cpu_model=sun4; }
  226. if(!strcmp(&cputypval,"sun4c")) { sparc_cpu_model=sun4c; }
  227. if(!strcmp(&cputypval,"sun4m")) { sparc_cpu_model=sun4m; }
  228. if(!strcmp(&cputypval,"sun4s")) { sparc_cpu_model=sun4m; } /* CP-1200 with PROM 2.30 -E */
  229. if(!strcmp(&cputypval,"sun4d")) { sparc_cpu_model=sun4d; }
  230. if(!strcmp(&cputypval,"sun4e")) { sparc_cpu_model=sun4e; }
  231. if(!strcmp(&cputypval,"sun4u")) { sparc_cpu_model=sun4u; }
  232. #ifdef CONFIG_SUN4
  233. if (sparc_cpu_model != sun4) {
  234. prom_printf("This kernel is for Sun4 architecture only.\n");
  235. prom_halt();
  236. }
  237. #endif
  238. printk("ARCH: ");
  239. switch(sparc_cpu_model) {
  240. case sun4:
  241. printk("SUN4\n");
  242. break;
  243. case sun4c:
  244. printk("SUN4C\n");
  245. break;
  246. case sun4m:
  247. printk("SUN4M\n");
  248. break;
  249. case sun4d:
  250. printk("SUN4D\n");
  251. break;
  252. case sun4e:
  253. printk("SUN4E\n");
  254. break;
  255. case sun4u:
  256. printk("SUN4U\n");
  257. break;
  258. default:
  259. printk("UNKNOWN!\n");
  260. break;
  261. };
  262. #ifdef CONFIG_DUMMY_CONSOLE
  263. conswitchp = &dummy_con;
  264. #elif defined(CONFIG_PROM_CONSOLE)
  265. conswitchp = &prom_con;
  266. #endif
  267. boot_flags_init(*cmdline_p);
  268. idprom_init();
  269. if (ARCH_SUN4C_SUN4)
  270. sun4c_probe_vac();
  271. load_mmu();
  272. (void) prom_probe_memory();
  273. phys_base = 0xffffffffUL;
  274. highest_paddr = 0UL;
  275. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  276. unsigned long top;
  277. if (sp_banks[i].base_addr < phys_base)
  278. phys_base = sp_banks[i].base_addr;
  279. top = sp_banks[i].base_addr +
  280. sp_banks[i].num_bytes;
  281. if (highest_paddr < top)
  282. highest_paddr = top;
  283. }
  284. pfn_base = phys_base >> PAGE_SHIFT;
  285. if (!root_flags)
  286. root_mountflags &= ~MS_RDONLY;
  287. ROOT_DEV = old_decode_dev(root_dev);
  288. #ifdef CONFIG_BLK_DEV_RAM
  289. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  290. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  291. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  292. #endif
  293. prom_setsync(prom_sync_me);
  294. if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
  295. ((*(short *)linux_dbvec) != -1)) {
  296. printk("Booted under KADB. Syncing trap table.\n");
  297. (*(linux_dbvec->teach_debugger))();
  298. }
  299. init_mm.context = (unsigned long) NO_CONTEXT;
  300. init_task.thread.kregs = &fake_swapper_regs;
  301. paging_init();
  302. smp_setup_cpu_possible_map();
  303. }
  304. static int __init set_preferred_console(void)
  305. {
  306. int idev, odev;
  307. /* The user has requested a console so this is already set up. */
  308. if (serial_console >= 0)
  309. return -EBUSY;
  310. idev = prom_query_input_device();
  311. odev = prom_query_output_device();
  312. if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
  313. serial_console = 0;
  314. } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
  315. serial_console = 1;
  316. } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
  317. serial_console = 2;
  318. } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OTTYA) {
  319. prom_printf("MrCoffee ttya\n");
  320. serial_console = 1;
  321. } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OSCREEN) {
  322. serial_console = 0;
  323. prom_printf("MrCoffee keyboard\n");
  324. } else {
  325. prom_printf("Confusing console (idev %d, odev %d)\n",
  326. idev, odev);
  327. serial_console = 1;
  328. }
  329. if (serial_console)
  330. return add_preferred_console("ttyS", serial_console - 1, NULL);
  331. return -ENODEV;
  332. }
  333. console_initcall(set_preferred_console);
  334. extern char *sparc_cpu_type;
  335. extern char *sparc_fpu_type;
  336. static int ncpus_probed;
  337. static int show_cpuinfo(struct seq_file *m, void *__unused)
  338. {
  339. seq_printf(m,
  340. "cpu\t\t: %s\n"
  341. "fpu\t\t: %s\n"
  342. "promlib\t\t: Version %d Revision %d\n"
  343. "prom\t\t: %d.%d\n"
  344. "type\t\t: %s\n"
  345. "ncpus probed\t: %d\n"
  346. "ncpus active\t: %d\n"
  347. #ifndef CONFIG_SMP
  348. "CPU0Bogo\t: %lu.%02lu\n"
  349. "CPU0ClkTck\t: %ld\n"
  350. #endif
  351. ,
  352. sparc_cpu_type ? sparc_cpu_type : "undetermined",
  353. sparc_fpu_type ? sparc_fpu_type : "undetermined",
  354. romvec->pv_romvers,
  355. prom_rev,
  356. romvec->pv_printrev >> 16,
  357. romvec->pv_printrev & 0xffff,
  358. &cputypval,
  359. ncpus_probed,
  360. num_online_cpus()
  361. #ifndef CONFIG_SMP
  362. , cpu_data(0).udelay_val/(500000/HZ),
  363. (cpu_data(0).udelay_val/(5000/HZ)) % 100,
  364. cpu_data(0).clock_tick
  365. #endif
  366. );
  367. #ifdef CONFIG_SMP
  368. smp_bogo(m);
  369. #endif
  370. mmu_info(m);
  371. #ifdef CONFIG_SMP
  372. smp_info(m);
  373. #endif
  374. return 0;
  375. }
  376. static void *c_start(struct seq_file *m, loff_t *pos)
  377. {
  378. /* The pointer we are returning is arbitrary,
  379. * it just has to be non-NULL and not IS_ERR
  380. * in the success case.
  381. */
  382. return *pos == 0 ? &c_start : NULL;
  383. }
  384. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  385. {
  386. ++*pos;
  387. return c_start(m, pos);
  388. }
  389. static void c_stop(struct seq_file *m, void *v)
  390. {
  391. }
  392. struct seq_operations cpuinfo_op = {
  393. .start =c_start,
  394. .next = c_next,
  395. .stop = c_stop,
  396. .show = show_cpuinfo,
  397. };
  398. extern int stop_a_enabled;
  399. void sun_do_break(void)
  400. {
  401. if (!stop_a_enabled)
  402. return;
  403. printk("\n");
  404. flush_user_windows();
  405. prom_cmdline();
  406. }
  407. int serial_console = -1;
  408. int stop_a_enabled = 1;
  409. static int __init topology_init(void)
  410. {
  411. int i, ncpus, err;
  412. /* Count the number of physically present processors in
  413. * the machine, even on uniprocessor, so that /proc/cpuinfo
  414. * output is consistent with 2.4.x
  415. */
  416. ncpus = 0;
  417. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  418. ncpus++;
  419. ncpus_probed = ncpus;
  420. err = 0;
  421. for_each_online_cpu(i) {
  422. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  423. if (!p)
  424. err = -ENOMEM;
  425. else
  426. register_cpu(p, i);
  427. }
  428. return err;
  429. }
  430. subsys_initcall(topology_init);