setup.c 9.5 KB

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