setup_32.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  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 <linux/export.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. #include <asm/cacheflush.h>
  47. #include "kernel.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. /* Pretty sick eh? */
  66. static 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. prom_printf("PROM SYNC COMMAND...\n");
  77. show_free_areas(0);
  78. if (!is_idle_task(current)) {
  79. local_irq_enable();
  80. sys_sync();
  81. local_irq_disable();
  82. }
  83. prom_printf("Returning to prom\n");
  84. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  85. "nop\n\t"
  86. "nop\n\t"
  87. "nop\n\t" : : "r" (prom_tbr));
  88. local_irq_restore(flags);
  89. }
  90. static unsigned int boot_flags __initdata = 0;
  91. #define BOOTME_DEBUG 0x1
  92. /* Exported for mm/init.c:paging_init. */
  93. unsigned long cmdline_memory_size __initdata = 0;
  94. /* which CPU booted us (0xff = not set) */
  95. unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */
  96. unsigned char boot_cpu_id4; /* boot_cpu_id << 2 */
  97. static void
  98. prom_console_write(struct console *con, const char *s, unsigned n)
  99. {
  100. prom_write(s, n);
  101. }
  102. static struct console prom_early_console = {
  103. .name = "earlyprom",
  104. .write = prom_console_write,
  105. .flags = CON_PRINTBUFFER | CON_BOOT,
  106. .index = -1,
  107. };
  108. /*
  109. * Process kernel command line switches that are specific to the
  110. * SPARC or that require special low-level processing.
  111. */
  112. static void __init process_switch(char c)
  113. {
  114. switch (c) {
  115. case 'd':
  116. boot_flags |= BOOTME_DEBUG;
  117. break;
  118. case 's':
  119. break;
  120. case 'h':
  121. prom_printf("boot_flags_init: Halt!\n");
  122. prom_halt();
  123. break;
  124. case 'p':
  125. prom_early_console.flags &= ~CON_BOOT;
  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. extern unsigned short root_flags;
  167. extern unsigned short root_dev;
  168. extern unsigned short ram_flags;
  169. #define RAMDISK_IMAGE_START_MASK 0x07FF
  170. #define RAMDISK_PROMPT_FLAG 0x8000
  171. #define RAMDISK_LOAD_FLAG 0x4000
  172. extern int root_mountflags;
  173. char reboot_command[COMMAND_LINE_SIZE];
  174. enum sparc_cpu sparc_cpu_model;
  175. EXPORT_SYMBOL(sparc_cpu_model);
  176. struct tt_entry *sparc_ttable;
  177. struct pt_regs fake_swapper_regs;
  178. void __init setup_arch(char **cmdline_p)
  179. {
  180. int i;
  181. unsigned long highest_paddr;
  182. sparc_ttable = (struct tt_entry *) &trapbase;
  183. /* Initialize PROM console and command line. */
  184. *cmdline_p = prom_getbootargs();
  185. strcpy(boot_command_line, *cmdline_p);
  186. parse_early_param();
  187. boot_flags_init(*cmdline_p);
  188. register_console(&prom_early_console);
  189. /* Set sparc_cpu_model */
  190. sparc_cpu_model = sun_unknown;
  191. if (!strcmp(&cputypval[0], "sun4 "))
  192. sparc_cpu_model = sun4;
  193. if (!strcmp(&cputypval[0], "sun4c"))
  194. sparc_cpu_model = sun4c;
  195. if (!strcmp(&cputypval[0], "sun4m"))
  196. sparc_cpu_model = sun4m;
  197. if (!strcmp(&cputypval[0], "sun4s"))
  198. sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
  199. if (!strcmp(&cputypval[0], "sun4d"))
  200. sparc_cpu_model = sun4d;
  201. if (!strcmp(&cputypval[0], "sun4e"))
  202. sparc_cpu_model = sun4e;
  203. if (!strcmp(&cputypval[0], "sun4u"))
  204. sparc_cpu_model = sun4u;
  205. if (!strncmp(&cputypval[0], "leon" , 4))
  206. sparc_cpu_model = sparc_leon;
  207. printk("ARCH: ");
  208. switch(sparc_cpu_model) {
  209. case sun4:
  210. printk("SUN4\n");
  211. break;
  212. case sun4c:
  213. printk("SUN4C\n");
  214. break;
  215. case sun4m:
  216. printk("SUN4M\n");
  217. break;
  218. case sun4d:
  219. printk("SUN4D\n");
  220. break;
  221. case sun4e:
  222. printk("SUN4E\n");
  223. break;
  224. case sun4u:
  225. printk("SUN4U\n");
  226. break;
  227. case sparc_leon:
  228. printk("LEON\n");
  229. break;
  230. default:
  231. printk("UNKNOWN!\n");
  232. break;
  233. }
  234. #ifdef CONFIG_DUMMY_CONSOLE
  235. conswitchp = &dummy_con;
  236. #endif
  237. idprom_init();
  238. load_mmu();
  239. phys_base = 0xffffffffUL;
  240. highest_paddr = 0UL;
  241. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  242. unsigned long top;
  243. if (sp_banks[i].base_addr < phys_base)
  244. phys_base = sp_banks[i].base_addr;
  245. top = sp_banks[i].base_addr +
  246. sp_banks[i].num_bytes;
  247. if (highest_paddr < top)
  248. highest_paddr = top;
  249. }
  250. pfn_base = phys_base >> PAGE_SHIFT;
  251. if (!root_flags)
  252. root_mountflags &= ~MS_RDONLY;
  253. ROOT_DEV = old_decode_dev(root_dev);
  254. #ifdef CONFIG_BLK_DEV_RAM
  255. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  256. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  257. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  258. #endif
  259. prom_setsync(prom_sync_me);
  260. if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
  261. ((*(short *)linux_dbvec) != -1)) {
  262. printk("Booted under KADB. Syncing trap table.\n");
  263. (*(linux_dbvec->teach_debugger))();
  264. }
  265. init_mm.context = (unsigned long) NO_CONTEXT;
  266. init_task.thread.kregs = &fake_swapper_regs;
  267. paging_init();
  268. smp_setup_cpu_possible_map();
  269. }
  270. extern int stop_a_enabled;
  271. void sun_do_break(void)
  272. {
  273. if (!stop_a_enabled)
  274. return;
  275. printk("\n");
  276. flush_user_windows();
  277. prom_cmdline();
  278. }
  279. EXPORT_SYMBOL(sun_do_break);
  280. int stop_a_enabled = 1;
  281. static int __init topology_init(void)
  282. {
  283. int i, ncpus, err;
  284. /* Count the number of physically present processors in
  285. * the machine, even on uniprocessor, so that /proc/cpuinfo
  286. * output is consistent with 2.4.x
  287. */
  288. ncpus = 0;
  289. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  290. ncpus++;
  291. ncpus_probed = ncpus;
  292. err = 0;
  293. for_each_online_cpu(i) {
  294. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  295. if (!p)
  296. err = -ENOMEM;
  297. else
  298. register_cpu(p, i);
  299. }
  300. return err;
  301. }
  302. subsys_initcall(topology_init);