PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/sparc/kernel/setup.c

https://bitbucket.org/evzijst/gittest
C | 476 lines | 377 code | 59 blank | 40 comment | 90 complexity | 25d9edc2410fb4af46048d0e39820eb4 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  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/tty.h>
  20. #include <linux/delay.h>
  21. #include <linux/config.h>
  22. #include <linux/fs.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/kdev_t.h>
  26. #include <linux/major.h>
  27. #include <linux/string.h>
  28. #include <linux/init.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/console.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/root_dev.h>
  33. #include <asm/segment.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/traps.h>
  41. #include <asm/vaddrs.h>
  42. #include <asm/kdebug.h>
  43. #include <asm/mbus.h>
  44. #include <asm/idprom.h>
  45. #include <asm/machines.h>
  46. #include <asm/cpudata.h>
  47. #include <asm/setup.h>
  48. struct screen_info screen_info = {
  49. 0, 0, /* orig-x, orig-y */
  50. 0, /* unused */
  51. 0, /* orig-video-page */
  52. 0, /* orig-video-mode */
  53. 128, /* orig-video-cols */
  54. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  55. 54, /* orig-video-lines */
  56. 0, /* orig-video-isVGA */
  57. 16 /* orig-video-points */
  58. };
  59. /* Typing sync at the prom prompt calls the function pointed to by
  60. * romvec->pv_synchook which I set to the following function.
  61. * This should sync all filesystems and return, for now it just
  62. * prints out pretty messages and returns.
  63. */
  64. extern unsigned long trapbase;
  65. void (*prom_palette)(int);
  66. /* Pretty sick eh? */
  67. void prom_sync_me(void)
  68. {
  69. unsigned long prom_tbr, flags;
  70. /* XXX Badly broken. FIX! - Anton */
  71. local_irq_save(flags);
  72. __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr));
  73. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  74. "nop\n\t"
  75. "nop\n\t"
  76. "nop\n\t" : : "r" (&trapbase));
  77. if (prom_palette)
  78. prom_palette(1);
  79. prom_printf("PROM SYNC COMMAND...\n");
  80. show_free_areas();
  81. if(current->pid != 0) {
  82. local_irq_enable();
  83. sys_sync();
  84. local_irq_disable();
  85. }
  86. prom_printf("Returning to prom\n");
  87. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  88. "nop\n\t"
  89. "nop\n\t"
  90. "nop\n\t" : : "r" (prom_tbr));
  91. local_irq_restore(flags);
  92. return;
  93. }
  94. unsigned int boot_flags __initdata = 0;
  95. #define BOOTME_DEBUG 0x1
  96. #define BOOTME_SINGLE 0x2
  97. /* Exported for mm/init.c:paging_init. */
  98. unsigned long cmdline_memory_size __initdata = 0;
  99. static void
  100. prom_console_write(struct console *con, const char *s, unsigned n)
  101. {
  102. prom_write(s, n);
  103. }
  104. static struct console prom_debug_console = {
  105. .name = "debug",
  106. .write = prom_console_write,
  107. .flags = CON_PRINTBUFFER,
  108. .index = -1,
  109. };
  110. int obp_system_intr(void)
  111. {
  112. if (boot_flags & BOOTME_DEBUG) {
  113. printk("OBP: system interrupted\n");
  114. prom_halt();
  115. return 1;
  116. }
  117. return 0;
  118. }
  119. /*
  120. * Process kernel command line switches that are specific to the
  121. * SPARC or that require special low-level processing.
  122. */
  123. static void __init process_switch(char c)
  124. {
  125. switch (c) {
  126. case 'd':
  127. boot_flags |= BOOTME_DEBUG;
  128. break;
  129. case 's':
  130. boot_flags |= BOOTME_SINGLE;
  131. break;
  132. case 'h':
  133. prom_printf("boot_flags_init: Halt!\n");
  134. prom_halt();
  135. break;
  136. case 'p':
  137. /* Use PROM debug console. */
  138. register_console(&prom_debug_console);
  139. break;
  140. default:
  141. printk("Unknown boot switch (-%c)\n", c);
  142. break;
  143. }
  144. }
  145. static void __init process_console(char *commands)
  146. {
  147. serial_console = 0;
  148. commands += 8;
  149. /* Linux-style serial */
  150. if (!strncmp(commands, "ttyS", 4))
  151. serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
  152. else if (!strncmp(commands, "tty", 3)) {
  153. char c = *(commands + 3);
  154. /* Solaris-style serial */
  155. if (c == 'a' || c == 'b')
  156. serial_console = c - 'a' + 1;
  157. /* else Linux-style fbcon, not serial */
  158. }
  159. #if defined(CONFIG_PROM_CONSOLE)
  160. if (!strncmp(commands, "prom", 4)) {
  161. char *p;
  162. for (p = commands - 8; *p && *p != ' '; p++)
  163. *p = ' ';
  164. conswitchp = &prom_con;
  165. }
  166. #endif
  167. }
  168. static void __init boot_flags_init(char *commands)
  169. {
  170. while (*commands) {
  171. /* Move to the start of the next "argument". */
  172. while (*commands && *commands == ' ')
  173. commands++;
  174. /* Process any command switches, otherwise skip it. */
  175. if (*commands == '\0')
  176. break;
  177. if (*commands == '-') {
  178. commands++;
  179. while (*commands && *commands != ' ')
  180. process_switch(*commands++);
  181. continue;
  182. }
  183. if (!strncmp(commands, "console=", 8)) {
  184. process_console(commands);
  185. } else if (!strncmp(commands, "mem=", 4)) {
  186. /*
  187. * "mem=XXX[kKmM] overrides the PROM-reported
  188. * memory size.
  189. */
  190. cmdline_memory_size = simple_strtoul(commands + 4,
  191. &commands, 0);
  192. if (*commands == 'K' || *commands == 'k') {
  193. cmdline_memory_size <<= 10;
  194. commands++;
  195. } else if (*commands=='M' || *commands=='m') {
  196. cmdline_memory_size <<= 20;
  197. commands++;
  198. }
  199. }
  200. while (*commands && *commands != ' ')
  201. commands++;
  202. }
  203. }
  204. /* This routine will in the future do all the nasty prom stuff
  205. * to probe for the mmu type and its parameters, etc. This will
  206. * also be where SMP things happen plus the Sparc specific memory
  207. * physical memory probe as on the alpha.
  208. */
  209. extern int prom_probe_memory(void);
  210. extern void sun4c_probe_vac(void);
  211. extern char cputypval;
  212. extern unsigned long start, end;
  213. extern void panic_setup(char *, int *);
  214. extern unsigned short root_flags;
  215. extern unsigned short root_dev;
  216. extern unsigned short ram_flags;
  217. #define RAMDISK_IMAGE_START_MASK 0x07FF
  218. #define RAMDISK_PROMPT_FLAG 0x8000
  219. #define RAMDISK_LOAD_FLAG 0x4000
  220. extern int root_mountflags;
  221. char reboot_command[COMMAND_LINE_SIZE];
  222. enum sparc_cpu sparc_cpu_model;
  223. struct tt_entry *sparc_ttable;
  224. struct pt_regs fake_swapper_regs;
  225. extern void paging_init(void);
  226. void __init setup_arch(char **cmdline_p)
  227. {
  228. int i;
  229. unsigned long highest_paddr;
  230. sparc_ttable = (struct tt_entry *) &start;
  231. /* Initialize PROM console and command line. */
  232. *cmdline_p = prom_getbootargs();
  233. strcpy(saved_command_line, *cmdline_p);
  234. /* Set sparc_cpu_model */
  235. sparc_cpu_model = sun_unknown;
  236. if(!strcmp(&cputypval,"sun4 ")) { sparc_cpu_model=sun4; }
  237. if(!strcmp(&cputypval,"sun4c")) { sparc_cpu_model=sun4c; }
  238. if(!strcmp(&cputypval,"sun4m")) { sparc_cpu_model=sun4m; }
  239. if(!strcmp(&cputypval,"sun4s")) { sparc_cpu_model=sun4m; } /* CP-1200 with PROM 2.30 -E */
  240. if(!strcmp(&cputypval,"sun4d")) { sparc_cpu_model=sun4d; }
  241. if(!strcmp(&cputypval,"sun4e")) { sparc_cpu_model=sun4e; }
  242. if(!strcmp(&cputypval,"sun4u")) { sparc_cpu_model=sun4u; }
  243. #ifdef CONFIG_SUN4
  244. if (sparc_cpu_model != sun4) {
  245. prom_printf("This kernel is for Sun4 architecture only.\n");
  246. prom_halt();
  247. }
  248. #endif
  249. printk("ARCH: ");
  250. switch(sparc_cpu_model) {
  251. case sun4:
  252. printk("SUN4\n");
  253. break;
  254. case sun4c:
  255. printk("SUN4C\n");
  256. break;
  257. case sun4m:
  258. printk("SUN4M\n");
  259. break;
  260. case sun4d:
  261. printk("SUN4D\n");
  262. break;
  263. case sun4e:
  264. printk("SUN4E\n");
  265. break;
  266. case sun4u:
  267. printk("SUN4U\n");
  268. break;
  269. default:
  270. printk("UNKNOWN!\n");
  271. break;
  272. };
  273. #ifdef CONFIG_DUMMY_CONSOLE
  274. conswitchp = &dummy_con;
  275. #elif defined(CONFIG_PROM_CONSOLE)
  276. conswitchp = &prom_con;
  277. #endif
  278. boot_flags_init(*cmdline_p);
  279. idprom_init();
  280. if (ARCH_SUN4C_SUN4)
  281. sun4c_probe_vac();
  282. load_mmu();
  283. (void) prom_probe_memory();
  284. phys_base = 0xffffffffUL;
  285. highest_paddr = 0UL;
  286. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  287. unsigned long top;
  288. if (sp_banks[i].base_addr < phys_base)
  289. phys_base = sp_banks[i].base_addr;
  290. top = sp_banks[i].base_addr +
  291. sp_banks[i].num_bytes;
  292. if (highest_paddr < top)
  293. highest_paddr = top;
  294. }
  295. pfn_base = phys_base >> PAGE_SHIFT;
  296. if (!root_flags)
  297. root_mountflags &= ~MS_RDONLY;
  298. ROOT_DEV = old_decode_dev(root_dev);
  299. #ifdef CONFIG_BLK_DEV_INITRD
  300. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  301. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  302. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  303. #endif
  304. prom_setsync(prom_sync_me);
  305. if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
  306. ((*(short *)linux_dbvec) != -1)) {
  307. printk("Booted under KADB. Syncing trap table.\n");
  308. (*(linux_dbvec->teach_debugger))();
  309. }
  310. init_mm.context = (unsigned long) NO_CONTEXT;
  311. init_task.thread.kregs = &fake_swapper_regs;
  312. paging_init();
  313. }
  314. static int __init set_preferred_console(void)
  315. {
  316. int idev, odev;
  317. /* The user has requested a console so this is already set up. */
  318. if (serial_console >= 0)
  319. return -EBUSY;
  320. idev = prom_query_input_device();
  321. odev = prom_query_output_device();
  322. if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
  323. serial_console = 0;
  324. } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
  325. serial_console = 1;
  326. } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
  327. serial_console = 2;
  328. } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OTTYA) {
  329. prom_printf("MrCoffee ttya\n");
  330. serial_console = 1;
  331. } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OSCREEN) {
  332. serial_console = 0;
  333. prom_printf("MrCoffee keyboard\n");
  334. } else {
  335. prom_printf("Confusing console (idev %d, odev %d)\n",
  336. idev, odev);
  337. serial_console = 1;
  338. }
  339. if (serial_console)
  340. return add_preferred_console("ttyS", serial_console - 1, NULL);
  341. return -ENODEV;
  342. }
  343. console_initcall(set_preferred_console);
  344. extern char *sparc_cpu_type;
  345. extern char *sparc_fpu_type;
  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. num_possible_cpus(),
  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;