setup_32.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. extern unsigned long trapbase;
  66. /* Pretty sick eh? */
  67. static 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. prom_printf("PROM SYNC COMMAND...\n");
  78. show_free_areas(0);
  79. if (!is_idle_task(current)) {
  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. }
  91. static unsigned int boot_flags __initdata = 0;
  92. #define BOOTME_DEBUG 0x1
  93. /* Exported for mm/init.c:paging_init. */
  94. unsigned long cmdline_memory_size __initdata = 0;
  95. /* which CPU booted us (0xff = not set) */
  96. unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */
  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. struct cpuid_patch_entry {
  175. unsigned int addr;
  176. unsigned int sun4d[3];
  177. unsigned int leon[3];
  178. };
  179. extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
  180. static void __init per_cpu_patch(void)
  181. {
  182. struct cpuid_patch_entry *p;
  183. if (sparc_cpu_model == sun4m) {
  184. /* Nothing to do, this is what the unpatched code
  185. * targets.
  186. */
  187. return;
  188. }
  189. p = &__cpuid_patch;
  190. while (p < &__cpuid_patch_end) {
  191. unsigned long addr = p->addr;
  192. unsigned int *insns;
  193. switch (sparc_cpu_model) {
  194. case sun4d:
  195. insns = &p->sun4d[0];
  196. break;
  197. case sparc_leon:
  198. insns = &p->leon[0];
  199. break;
  200. default:
  201. prom_printf("Unknown cpu type, halting.\n");
  202. prom_halt();
  203. }
  204. *(unsigned int *) (addr + 0) = insns[0];
  205. flushi(addr + 0);
  206. *(unsigned int *) (addr + 4) = insns[1];
  207. flushi(addr + 4);
  208. *(unsigned int *) (addr + 8) = insns[2];
  209. flushi(addr + 8);
  210. p++;
  211. }
  212. }
  213. struct leon_1insn_patch_entry {
  214. unsigned int addr;
  215. unsigned int insn;
  216. };
  217. enum sparc_cpu sparc_cpu_model;
  218. EXPORT_SYMBOL(sparc_cpu_model);
  219. static __init void leon_patch(void)
  220. {
  221. struct leon_1insn_patch_entry *start = (void *)__leon_1insn_patch;
  222. struct leon_1insn_patch_entry *end = (void *)__leon_1insn_patch_end;
  223. /* Default instruction is leon - no patching */
  224. if (sparc_cpu_model == sparc_leon)
  225. return;
  226. while (start < end) {
  227. unsigned long addr = start->addr;
  228. *(unsigned int *)(addr) = start->insn;
  229. flushi(addr);
  230. start++;
  231. }
  232. }
  233. struct tt_entry *sparc_ttable;
  234. static struct pt_regs fake_swapper_regs;
  235. /* Called from head_32.S - before we have setup anything
  236. * in the kernel. Be very careful with what you do here.
  237. */
  238. void __init sparc32_start_kernel(struct linux_romvec *rp)
  239. {
  240. prom_init(rp);
  241. /* Set sparc_cpu_model */
  242. sparc_cpu_model = sun_unknown;
  243. if (!strcmp(&cputypval[0], "sun4m"))
  244. sparc_cpu_model = sun4m;
  245. if (!strcmp(&cputypval[0], "sun4s"))
  246. sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
  247. if (!strcmp(&cputypval[0], "sun4d"))
  248. sparc_cpu_model = sun4d;
  249. if (!strcmp(&cputypval[0], "sun4e"))
  250. sparc_cpu_model = sun4e;
  251. if (!strcmp(&cputypval[0], "sun4u"))
  252. sparc_cpu_model = sun4u;
  253. if (!strncmp(&cputypval[0], "leon" , 4))
  254. sparc_cpu_model = sparc_leon;
  255. leon_patch();
  256. start_kernel();
  257. }
  258. void __init setup_arch(char **cmdline_p)
  259. {
  260. int i;
  261. unsigned long highest_paddr;
  262. sparc_ttable = (struct tt_entry *) &trapbase;
  263. /* Initialize PROM console and command line. */
  264. *cmdline_p = prom_getbootargs();
  265. strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
  266. parse_early_param();
  267. boot_flags_init(*cmdline_p);
  268. register_console(&prom_early_console);
  269. printk("ARCH: ");
  270. switch(sparc_cpu_model) {
  271. case sun4m:
  272. printk("SUN4M\n");
  273. break;
  274. case sun4d:
  275. printk("SUN4D\n");
  276. break;
  277. case sun4e:
  278. printk("SUN4E\n");
  279. break;
  280. case sun4u:
  281. printk("SUN4U\n");
  282. break;
  283. case sparc_leon:
  284. printk("LEON\n");
  285. break;
  286. default:
  287. printk("UNKNOWN!\n");
  288. break;
  289. }
  290. #ifdef CONFIG_DUMMY_CONSOLE
  291. conswitchp = &dummy_con;
  292. #endif
  293. idprom_init();
  294. load_mmu();
  295. phys_base = 0xffffffffUL;
  296. highest_paddr = 0UL;
  297. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  298. unsigned long top;
  299. if (sp_banks[i].base_addr < phys_base)
  300. phys_base = sp_banks[i].base_addr;
  301. top = sp_banks[i].base_addr +
  302. sp_banks[i].num_bytes;
  303. if (highest_paddr < top)
  304. highest_paddr = top;
  305. }
  306. pfn_base = phys_base >> PAGE_SHIFT;
  307. if (!root_flags)
  308. root_mountflags &= ~MS_RDONLY;
  309. ROOT_DEV = old_decode_dev(root_dev);
  310. #ifdef CONFIG_BLK_DEV_RAM
  311. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  312. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  313. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  314. #endif
  315. prom_setsync(prom_sync_me);
  316. if((boot_flags & BOOTME_DEBUG) && (linux_dbvec != NULL) &&
  317. ((*(short *)linux_dbvec) != -1)) {
  318. printk("Booted under KADB. Syncing trap table.\n");
  319. (*(linux_dbvec->teach_debugger))();
  320. }
  321. init_task.thread.kregs = &fake_swapper_regs;
  322. /* Run-time patch instructions to match the cpu model */
  323. per_cpu_patch();
  324. paging_init();
  325. smp_setup_cpu_possible_map();
  326. }
  327. extern int stop_a_enabled;
  328. void sun_do_break(void)
  329. {
  330. if (!stop_a_enabled)
  331. return;
  332. printk("\n");
  333. flush_user_windows();
  334. prom_cmdline();
  335. }
  336. EXPORT_SYMBOL(sun_do_break);
  337. int stop_a_enabled = 1;
  338. static int __init topology_init(void)
  339. {
  340. int i, ncpus, err;
  341. /* Count the number of physically present processors in
  342. * the machine, even on uniprocessor, so that /proc/cpuinfo
  343. * output is consistent with 2.4.x
  344. */
  345. ncpus = 0;
  346. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  347. ncpus++;
  348. ncpus_probed = ncpus;
  349. err = 0;
  350. for_each_online_cpu(i) {
  351. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  352. if (!p)
  353. err = -ENOMEM;
  354. else
  355. register_cpu(p, i);
  356. }
  357. return err;
  358. }
  359. subsys_initcall(topology_init);