setup_32.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 <linux/start_kernel.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/mbus.h>
  43. #include <asm/idprom.h>
  44. #include <asm/cpudata.h>
  45. #include <asm/setup.h>
  46. #include <asm/cacheflush.h>
  47. #include <asm/sections.h>
  48. #include "kernel.h"
  49. struct screen_info screen_info = {
  50. 0, 0, /* orig-x, orig-y */
  51. 0, /* unused */
  52. 0, /* orig-video-page */
  53. 0, /* orig-video-mode */
  54. 128, /* orig-video-cols */
  55. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  56. 54, /* orig-video-lines */
  57. 0, /* orig-video-isVGA */
  58. 16 /* orig-video-points */
  59. };
  60. /* Typing sync at the prom prompt calls the function pointed to by
  61. * romvec->pv_synchook which I set to the following function.
  62. * This should sync all filesystems and return, for now it just
  63. * prints out pretty messages and returns.
  64. */
  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. static void
  97. prom_console_write(struct console *con, const char *s, unsigned int n)
  98. {
  99. prom_write(s, n);
  100. }
  101. static struct console prom_early_console = {
  102. .name = "earlyprom",
  103. .write = prom_console_write,
  104. .flags = CON_PRINTBUFFER | CON_BOOT,
  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. prom_early_console.flags &= ~CON_BOOT;
  125. break;
  126. default:
  127. printk("Unknown boot switch (-%c)\n", c);
  128. break;
  129. }
  130. }
  131. static void __init boot_flags_init(char *commands)
  132. {
  133. while (*commands) {
  134. /* Move to the start of the next "argument". */
  135. while (*commands && *commands == ' ')
  136. commands++;
  137. /* Process any command switches, otherwise skip it. */
  138. if (*commands == '\0')
  139. break;
  140. if (*commands == '-') {
  141. commands++;
  142. while (*commands && *commands != ' ')
  143. process_switch(*commands++);
  144. continue;
  145. }
  146. if (!strncmp(commands, "mem=", 4)) {
  147. /*
  148. * "mem=XXX[kKmM] overrides the PROM-reported
  149. * memory size.
  150. */
  151. cmdline_memory_size = simple_strtoul(commands + 4,
  152. &commands, 0);
  153. if (*commands == 'K' || *commands == 'k') {
  154. cmdline_memory_size <<= 10;
  155. commands++;
  156. } else if (*commands=='M' || *commands=='m') {
  157. cmdline_memory_size <<= 20;
  158. commands++;
  159. }
  160. }
  161. while (*commands && *commands != ' ')
  162. commands++;
  163. }
  164. }
  165. extern unsigned short root_flags;
  166. extern unsigned short root_dev;
  167. extern unsigned short ram_flags;
  168. #define RAMDISK_IMAGE_START_MASK 0x07FF
  169. #define RAMDISK_PROMPT_FLAG 0x8000
  170. #define RAMDISK_LOAD_FLAG 0x4000
  171. extern int root_mountflags;
  172. char reboot_command[COMMAND_LINE_SIZE];
  173. struct cpuid_patch_entry {
  174. unsigned int addr;
  175. unsigned int sun4d[3];
  176. unsigned int leon[3];
  177. };
  178. extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
  179. static void __init per_cpu_patch(void)
  180. {
  181. struct cpuid_patch_entry *p;
  182. if (sparc_cpu_model == sun4m) {
  183. /* Nothing to do, this is what the unpatched code
  184. * targets.
  185. */
  186. return;
  187. }
  188. p = &__cpuid_patch;
  189. while (p < &__cpuid_patch_end) {
  190. unsigned long addr = p->addr;
  191. unsigned int *insns;
  192. switch (sparc_cpu_model) {
  193. case sun4d:
  194. insns = &p->sun4d[0];
  195. break;
  196. case sparc_leon:
  197. insns = &p->leon[0];
  198. break;
  199. default:
  200. prom_printf("Unknown cpu type, halting.\n");
  201. prom_halt();
  202. }
  203. *(unsigned int *) (addr + 0) = insns[0];
  204. flushi(addr + 0);
  205. *(unsigned int *) (addr + 4) = insns[1];
  206. flushi(addr + 4);
  207. *(unsigned int *) (addr + 8) = insns[2];
  208. flushi(addr + 8);
  209. p++;
  210. }
  211. }
  212. struct leon_1insn_patch_entry {
  213. unsigned int addr;
  214. unsigned int insn;
  215. };
  216. enum sparc_cpu sparc_cpu_model;
  217. EXPORT_SYMBOL(sparc_cpu_model);
  218. static __init void leon_patch(void)
  219. {
  220. struct leon_1insn_patch_entry *start = (void *)__leon_1insn_patch;
  221. struct leon_1insn_patch_entry *end = (void *)__leon_1insn_patch_end;
  222. /* Default instruction is leon - no patching */
  223. if (sparc_cpu_model == sparc_leon)
  224. return;
  225. while (start < end) {
  226. unsigned long addr = start->addr;
  227. *(unsigned int *)(addr) = start->insn;
  228. flushi(addr);
  229. start++;
  230. }
  231. }
  232. struct tt_entry *sparc_ttable;
  233. static struct pt_regs fake_swapper_regs;
  234. /* Called from head_32.S - before we have setup anything
  235. * in the kernel. Be very careful with what you do here.
  236. */
  237. void __init sparc32_start_kernel(struct linux_romvec *rp)
  238. {
  239. prom_init(rp);
  240. /* Set sparc_cpu_model */
  241. sparc_cpu_model = sun_unknown;
  242. if (!strcmp(&cputypval[0], "sun4m"))
  243. sparc_cpu_model = sun4m;
  244. if (!strcmp(&cputypval[0], "sun4s"))
  245. sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
  246. if (!strcmp(&cputypval[0], "sun4d"))
  247. sparc_cpu_model = sun4d;
  248. if (!strcmp(&cputypval[0], "sun4e"))
  249. sparc_cpu_model = sun4e;
  250. if (!strcmp(&cputypval[0], "sun4u"))
  251. sparc_cpu_model = sun4u;
  252. if (!strncmp(&cputypval[0], "leon" , 4))
  253. sparc_cpu_model = sparc_leon;
  254. leon_patch();
  255. start_kernel();
  256. }
  257. void __init setup_arch(char **cmdline_p)
  258. {
  259. int i;
  260. unsigned long highest_paddr;
  261. sparc_ttable = &trapbase;
  262. /* Initialize PROM console and command line. */
  263. *cmdline_p = prom_getbootargs();
  264. strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
  265. parse_early_param();
  266. boot_flags_init(*cmdline_p);
  267. register_console(&prom_early_console);
  268. printk("ARCH: ");
  269. switch(sparc_cpu_model) {
  270. case sun4m:
  271. printk("SUN4M\n");
  272. break;
  273. case sun4d:
  274. printk("SUN4D\n");
  275. break;
  276. case sun4e:
  277. printk("SUN4E\n");
  278. break;
  279. case sun4u:
  280. printk("SUN4U\n");
  281. break;
  282. case sparc_leon:
  283. printk("LEON\n");
  284. break;
  285. default:
  286. printk("UNKNOWN!\n");
  287. break;
  288. }
  289. #ifdef CONFIG_DUMMY_CONSOLE
  290. conswitchp = &dummy_con;
  291. #endif
  292. idprom_init();
  293. load_mmu();
  294. phys_base = 0xffffffffUL;
  295. highest_paddr = 0UL;
  296. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  297. unsigned long top;
  298. if (sp_banks[i].base_addr < phys_base)
  299. phys_base = sp_banks[i].base_addr;
  300. top = sp_banks[i].base_addr +
  301. sp_banks[i].num_bytes;
  302. if (highest_paddr < top)
  303. highest_paddr = top;
  304. }
  305. pfn_base = phys_base >> PAGE_SHIFT;
  306. if (!root_flags)
  307. root_mountflags &= ~MS_RDONLY;
  308. ROOT_DEV = old_decode_dev(root_dev);
  309. #ifdef CONFIG_BLK_DEV_RAM
  310. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  311. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  312. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  313. #endif
  314. prom_setsync(prom_sync_me);
  315. if((boot_flags & BOOTME_DEBUG) && (linux_dbvec != NULL) &&
  316. ((*(short *)linux_dbvec) != -1)) {
  317. printk("Booted under KADB. Syncing trap table.\n");
  318. (*(linux_dbvec->teach_debugger))();
  319. }
  320. init_task.thread.kregs = &fake_swapper_regs;
  321. /* Run-time patch instructions to match the cpu model */
  322. per_cpu_patch();
  323. paging_init();
  324. smp_setup_cpu_possible_map();
  325. }
  326. extern int stop_a_enabled;
  327. void sun_do_break(void)
  328. {
  329. if (!stop_a_enabled)
  330. return;
  331. printk("\n");
  332. flush_user_windows();
  333. prom_cmdline();
  334. }
  335. EXPORT_SYMBOL(sun_do_break);
  336. int stop_a_enabled = 1;
  337. static int __init topology_init(void)
  338. {
  339. int i, ncpus, err;
  340. /* Count the number of physically present processors in
  341. * the machine, even on uniprocessor, so that /proc/cpuinfo
  342. * output is consistent with 2.4.x
  343. */
  344. ncpus = 0;
  345. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  346. ncpus++;
  347. ncpus_probed = ncpus;
  348. err = 0;
  349. for_each_online_cpu(i) {
  350. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  351. if (!p)
  352. err = -ENOMEM;
  353. else
  354. register_cpu(p, i);
  355. }
  356. return err;
  357. }
  358. subsys_initcall(topology_init);