setup_32.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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/cpudata.h>
  44. #include <asm/setup.h>
  45. #include <asm/cacheflush.h>
  46. #include "kernel.h"
  47. struct screen_info screen_info = {
  48. 0, 0, /* orig-x, orig-y */
  49. 0, /* unused */
  50. 0, /* orig-video-page */
  51. 0, /* orig-video-mode */
  52. 128, /* orig-video-cols */
  53. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  54. 54, /* orig-video-lines */
  55. 0, /* orig-video-isVGA */
  56. 16 /* orig-video-points */
  57. };
  58. /* Typing sync at the prom prompt calls the function pointed to by
  59. * romvec->pv_synchook which I set to the following function.
  60. * This should sync all filesystems and return, for now it just
  61. * prints out pretty messages and returns.
  62. */
  63. extern unsigned long trapbase;
  64. /* Pretty sick eh? */
  65. static 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. prom_printf("PROM SYNC COMMAND...\n");
  76. show_free_areas(0);
  77. if (!is_idle_task(current)) {
  78. local_irq_enable();
  79. sys_sync();
  80. local_irq_disable();
  81. }
  82. prom_printf("Returning to prom\n");
  83. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  84. "nop\n\t"
  85. "nop\n\t"
  86. "nop\n\t" : : "r" (prom_tbr));
  87. local_irq_restore(flags);
  88. }
  89. static unsigned int boot_flags __initdata = 0;
  90. #define BOOTME_DEBUG 0x1
  91. /* Exported for mm/init.c:paging_init. */
  92. unsigned long cmdline_memory_size __initdata = 0;
  93. /* which CPU booted us (0xff = not set) */
  94. unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */
  95. static void
  96. prom_console_write(struct console *con, const char *s, unsigned n)
  97. {
  98. prom_write(s, n);
  99. }
  100. static struct console prom_early_console = {
  101. .name = "earlyprom",
  102. .write = prom_console_write,
  103. .flags = CON_PRINTBUFFER | CON_BOOT,
  104. .index = -1,
  105. };
  106. /*
  107. * Process kernel command line switches that are specific to the
  108. * SPARC or that require special low-level processing.
  109. */
  110. static void __init process_switch(char c)
  111. {
  112. switch (c) {
  113. case 'd':
  114. boot_flags |= BOOTME_DEBUG;
  115. break;
  116. case 's':
  117. break;
  118. case 'h':
  119. prom_printf("boot_flags_init: Halt!\n");
  120. prom_halt();
  121. break;
  122. case 'p':
  123. prom_early_console.flags &= ~CON_BOOT;
  124. break;
  125. default:
  126. printk("Unknown boot switch (-%c)\n", c);
  127. break;
  128. }
  129. }
  130. static void __init boot_flags_init(char *commands)
  131. {
  132. while (*commands) {
  133. /* Move to the start of the next "argument". */
  134. while (*commands && *commands == ' ')
  135. commands++;
  136. /* Process any command switches, otherwise skip it. */
  137. if (*commands == '\0')
  138. break;
  139. if (*commands == '-') {
  140. commands++;
  141. while (*commands && *commands != ' ')
  142. process_switch(*commands++);
  143. continue;
  144. }
  145. if (!strncmp(commands, "mem=", 4)) {
  146. /*
  147. * "mem=XXX[kKmM] overrides the PROM-reported
  148. * memory size.
  149. */
  150. cmdline_memory_size = simple_strtoul(commands + 4,
  151. &commands, 0);
  152. if (*commands == 'K' || *commands == 'k') {
  153. cmdline_memory_size <<= 10;
  154. commands++;
  155. } else if (*commands=='M' || *commands=='m') {
  156. cmdline_memory_size <<= 20;
  157. commands++;
  158. }
  159. }
  160. while (*commands && *commands != ' ')
  161. commands++;
  162. }
  163. }
  164. extern unsigned short root_flags;
  165. extern unsigned short root_dev;
  166. extern unsigned short ram_flags;
  167. #define RAMDISK_IMAGE_START_MASK 0x07FF
  168. #define RAMDISK_PROMPT_FLAG 0x8000
  169. #define RAMDISK_LOAD_FLAG 0x4000
  170. extern int root_mountflags;
  171. char reboot_command[COMMAND_LINE_SIZE];
  172. struct cpuid_patch_entry {
  173. unsigned int addr;
  174. unsigned int sun4d[3];
  175. unsigned int leon[3];
  176. };
  177. extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
  178. static void __init per_cpu_patch(void)
  179. {
  180. struct cpuid_patch_entry *p;
  181. if (sparc_cpu_model == sun4m) {
  182. /* Nothing to do, this is what the unpatched code
  183. * targets.
  184. */
  185. return;
  186. }
  187. p = &__cpuid_patch;
  188. while (p < &__cpuid_patch_end) {
  189. unsigned long addr = p->addr;
  190. unsigned int *insns;
  191. switch (sparc_cpu_model) {
  192. case sun4d:
  193. insns = &p->sun4d[0];
  194. break;
  195. case sparc_leon:
  196. insns = &p->leon[0];
  197. break;
  198. default:
  199. prom_printf("Unknown cpu type, halting.\n");
  200. prom_halt();
  201. }
  202. *(unsigned int *) (addr + 0) = insns[0];
  203. *(unsigned int *) (addr + 4) = insns[1];
  204. *(unsigned int *) (addr + 8) = insns[2];
  205. p++;
  206. }
  207. #ifdef CONFIG_SMP
  208. local_ops->cache_all();
  209. #else
  210. sparc32_cachetlb_ops->cache_all();
  211. #endif
  212. }
  213. enum sparc_cpu sparc_cpu_model;
  214. EXPORT_SYMBOL(sparc_cpu_model);
  215. struct tt_entry *sparc_ttable;
  216. struct pt_regs fake_swapper_regs;
  217. void __init setup_arch(char **cmdline_p)
  218. {
  219. int i;
  220. unsigned long highest_paddr;
  221. sparc_ttable = (struct tt_entry *) &trapbase;
  222. /* Initialize PROM console and command line. */
  223. *cmdline_p = prom_getbootargs();
  224. strcpy(boot_command_line, *cmdline_p);
  225. parse_early_param();
  226. boot_flags_init(*cmdline_p);
  227. register_console(&prom_early_console);
  228. /* Set sparc_cpu_model */
  229. sparc_cpu_model = sun_unknown;
  230. if (!strcmp(&cputypval[0], "sun4m"))
  231. sparc_cpu_model = sun4m;
  232. if (!strcmp(&cputypval[0], "sun4s"))
  233. sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
  234. if (!strcmp(&cputypval[0], "sun4d"))
  235. sparc_cpu_model = sun4d;
  236. if (!strcmp(&cputypval[0], "sun4e"))
  237. sparc_cpu_model = sun4e;
  238. if (!strcmp(&cputypval[0], "sun4u"))
  239. sparc_cpu_model = sun4u;
  240. if (!strncmp(&cputypval[0], "leon" , 4))
  241. sparc_cpu_model = sparc_leon;
  242. printk("ARCH: ");
  243. switch(sparc_cpu_model) {
  244. case sun4m:
  245. printk("SUN4M\n");
  246. break;
  247. case sun4d:
  248. printk("SUN4D\n");
  249. break;
  250. case sun4e:
  251. printk("SUN4E\n");
  252. break;
  253. case sun4u:
  254. printk("SUN4U\n");
  255. break;
  256. case sparc_leon:
  257. printk("LEON\n");
  258. break;
  259. default:
  260. printk("UNKNOWN!\n");
  261. break;
  262. }
  263. #ifdef CONFIG_DUMMY_CONSOLE
  264. conswitchp = &dummy_con;
  265. #endif
  266. idprom_init();
  267. load_mmu();
  268. phys_base = 0xffffffffUL;
  269. highest_paddr = 0UL;
  270. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  271. unsigned long top;
  272. if (sp_banks[i].base_addr < phys_base)
  273. phys_base = sp_banks[i].base_addr;
  274. top = sp_banks[i].base_addr +
  275. sp_banks[i].num_bytes;
  276. if (highest_paddr < top)
  277. highest_paddr = top;
  278. }
  279. pfn_base = phys_base >> PAGE_SHIFT;
  280. if (!root_flags)
  281. root_mountflags &= ~MS_RDONLY;
  282. ROOT_DEV = old_decode_dev(root_dev);
  283. #ifdef CONFIG_BLK_DEV_RAM
  284. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  285. rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
  286. rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
  287. #endif
  288. prom_setsync(prom_sync_me);
  289. if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
  290. ((*(short *)linux_dbvec) != -1)) {
  291. printk("Booted under KADB. Syncing trap table.\n");
  292. (*(linux_dbvec->teach_debugger))();
  293. }
  294. init_mm.context = (unsigned long) NO_CONTEXT;
  295. init_task.thread.kregs = &fake_swapper_regs;
  296. paging_init();
  297. /* Now that we have the cache ops hooked up, we can patch
  298. * instructions.
  299. */
  300. per_cpu_patch();
  301. smp_setup_cpu_possible_map();
  302. }
  303. extern int stop_a_enabled;
  304. void sun_do_break(void)
  305. {
  306. if (!stop_a_enabled)
  307. return;
  308. printk("\n");
  309. flush_user_windows();
  310. prom_cmdline();
  311. }
  312. EXPORT_SYMBOL(sun_do_break);
  313. int stop_a_enabled = 1;
  314. static int __init topology_init(void)
  315. {
  316. int i, ncpus, err;
  317. /* Count the number of physically present processors in
  318. * the machine, even on uniprocessor, so that /proc/cpuinfo
  319. * output is consistent with 2.4.x
  320. */
  321. ncpus = 0;
  322. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  323. ncpus++;
  324. ncpus_probed = ncpus;
  325. err = 0;
  326. for_each_online_cpu(i) {
  327. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  328. if (!p)
  329. err = -ENOMEM;
  330. else
  331. register_cpu(p, i);
  332. }
  333. return err;
  334. }
  335. subsys_initcall(topology_init);