setup_32.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/sparc/kernel/setup.c
  4. *
  5. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6. * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/sched.h>
  10. #include <linux/kernel.h>
  11. #include <linux/mm.h>
  12. #include <linux/stddef.h>
  13. #include <linux/unistd.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/slab.h>
  16. #include <linux/initrd.h>
  17. #include <asm/smp.h>
  18. #include <linux/user.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 <uapi/linux/mount.h>
  36. #include <asm/io.h>
  37. #include <asm/processor.h>
  38. #include <asm/oplib.h>
  39. #include <asm/page.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. /* Typing sync at the prom prompt calls the function pointed to by
  50. * romvec->pv_synchook which I set to the following function.
  51. * This should sync all filesystems and return, for now it just
  52. * prints out pretty messages and returns.
  53. */
  54. /* Pretty sick eh? */
  55. static void prom_sync_me(void)
  56. {
  57. unsigned long prom_tbr, flags;
  58. /* XXX Badly broken. FIX! - Anton */
  59. local_irq_save(flags);
  60. __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr));
  61. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  62. "nop\n\t"
  63. "nop\n\t"
  64. "nop\n\t" : : "r" (&trapbase[0]));
  65. prom_printf("PROM SYNC COMMAND...\n");
  66. show_mem();
  67. if (!is_idle_task(current)) {
  68. local_irq_enable();
  69. ksys_sync();
  70. local_irq_disable();
  71. }
  72. prom_printf("Returning to prom\n");
  73. __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
  74. "nop\n\t"
  75. "nop\n\t"
  76. "nop\n\t" : : "r" (prom_tbr));
  77. local_irq_restore(flags);
  78. }
  79. static unsigned int boot_flags __initdata = 0;
  80. #define BOOTME_DEBUG 0x1
  81. /* Exported for mm/init.c:paging_init. */
  82. unsigned long cmdline_memory_size __initdata = 0;
  83. /* which CPU booted us (0xff = not set) */
  84. unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */
  85. static void
  86. prom_console_write(struct console *con, const char *s, unsigned int n)
  87. {
  88. prom_write(s, n);
  89. }
  90. static struct console prom_early_console = {
  91. .name = "earlyprom",
  92. .write = prom_console_write,
  93. .flags = CON_PRINTBUFFER | CON_BOOT,
  94. .index = -1,
  95. };
  96. /*
  97. * Process kernel command line switches that are specific to the
  98. * SPARC or that require special low-level processing.
  99. */
  100. static void __init process_switch(char c)
  101. {
  102. switch (c) {
  103. case 'd':
  104. boot_flags |= BOOTME_DEBUG;
  105. break;
  106. case 's':
  107. break;
  108. case 'h':
  109. prom_printf("boot_flags_init: Halt!\n");
  110. prom_halt();
  111. break;
  112. case 'p':
  113. prom_early_console.flags &= ~CON_BOOT;
  114. break;
  115. default:
  116. printk("Unknown boot switch (-%c)\n", c);
  117. break;
  118. }
  119. }
  120. static void __init boot_flags_init(char *commands)
  121. {
  122. while (*commands) {
  123. /* Move to the start of the next "argument". */
  124. while (*commands == ' ')
  125. commands++;
  126. /* Process any command switches, otherwise skip it. */
  127. if (*commands == '\0')
  128. break;
  129. if (*commands == '-') {
  130. commands++;
  131. while (*commands && *commands != ' ')
  132. process_switch(*commands++);
  133. continue;
  134. }
  135. if (!strncmp(commands, "mem=", 4)) {
  136. /*
  137. * "mem=XXX[kKmM] overrides the PROM-reported
  138. * memory size.
  139. */
  140. cmdline_memory_size = simple_strtoul(commands + 4,
  141. &commands, 0);
  142. if (*commands == 'K' || *commands == 'k') {
  143. cmdline_memory_size <<= 10;
  144. commands++;
  145. } else if (*commands=='M' || *commands=='m') {
  146. cmdline_memory_size <<= 20;
  147. commands++;
  148. }
  149. }
  150. while (*commands && *commands != ' ')
  151. commands++;
  152. }
  153. }
  154. extern unsigned short root_flags;
  155. extern unsigned short root_dev;
  156. extern unsigned short ram_flags;
  157. #define RAMDISK_IMAGE_START_MASK 0x07FF
  158. #define RAMDISK_PROMPT_FLAG 0x8000
  159. #define RAMDISK_LOAD_FLAG 0x4000
  160. extern int root_mountflags;
  161. char reboot_command[COMMAND_LINE_SIZE];
  162. struct cpuid_patch_entry {
  163. unsigned int addr;
  164. unsigned int sun4d[3];
  165. unsigned int leon[3];
  166. };
  167. extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
  168. static void __init per_cpu_patch(void)
  169. {
  170. struct cpuid_patch_entry *p;
  171. if (sparc_cpu_model == sun4m) {
  172. /* Nothing to do, this is what the unpatched code
  173. * targets.
  174. */
  175. return;
  176. }
  177. p = &__cpuid_patch;
  178. while (p < &__cpuid_patch_end) {
  179. unsigned long addr = p->addr;
  180. unsigned int *insns;
  181. switch (sparc_cpu_model) {
  182. case sun4d:
  183. insns = &p->sun4d[0];
  184. break;
  185. case sparc_leon:
  186. insns = &p->leon[0];
  187. break;
  188. default:
  189. prom_printf("Unknown cpu type, halting.\n");
  190. prom_halt();
  191. }
  192. *(unsigned int *) (addr + 0) = insns[0];
  193. flushi(addr + 0);
  194. *(unsigned int *) (addr + 4) = insns[1];
  195. flushi(addr + 4);
  196. *(unsigned int *) (addr + 8) = insns[2];
  197. flushi(addr + 8);
  198. p++;
  199. }
  200. }
  201. struct leon_1insn_patch_entry {
  202. unsigned int addr;
  203. unsigned int insn;
  204. };
  205. enum sparc_cpu sparc_cpu_model;
  206. EXPORT_SYMBOL(sparc_cpu_model);
  207. static __init void leon_patch(void)
  208. {
  209. struct leon_1insn_patch_entry *start = (void *)__leon_1insn_patch;
  210. struct leon_1insn_patch_entry *end = (void *)__leon_1insn_patch_end;
  211. /* Default instruction is leon - no patching */
  212. if (sparc_cpu_model == sparc_leon)
  213. return;
  214. while (start < end) {
  215. unsigned long addr = start->addr;
  216. *(unsigned int *)(addr) = start->insn;
  217. flushi(addr);
  218. start++;
  219. }
  220. }
  221. struct tt_entry *sparc_ttable;
  222. /* Called from head_32.S - before we have setup anything
  223. * in the kernel. Be very careful with what you do here.
  224. */
  225. void __init sparc32_start_kernel(struct linux_romvec *rp)
  226. {
  227. prom_init(rp);
  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. leon_patch();
  243. start_kernel();
  244. }
  245. void __init setup_arch(char **cmdline_p)
  246. {
  247. int i;
  248. unsigned long highest_paddr;
  249. sparc_ttable = &trapbase[0];
  250. /* Initialize PROM console and command line. */
  251. *cmdline_p = prom_getbootargs();
  252. strscpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
  253. parse_early_param();
  254. boot_flags_init(*cmdline_p);
  255. register_console(&prom_early_console);
  256. switch(sparc_cpu_model) {
  257. case sun4m:
  258. pr_info("ARCH: SUN4M\n");
  259. break;
  260. case sun4d:
  261. pr_info("ARCH: SUN4D\n");
  262. break;
  263. case sun4e:
  264. pr_info("ARCH: SUN4E\n");
  265. break;
  266. case sun4u:
  267. pr_info("ARCH: SUN4U\n");
  268. break;
  269. case sparc_leon:
  270. pr_info("ARCH: LEON\n");
  271. break;
  272. default:
  273. pr_info("ARCH: UNKNOWN!\n");
  274. break;
  275. }
  276. idprom_init();
  277. load_mmu();
  278. phys_base = 0xffffffffUL;
  279. highest_paddr = 0UL;
  280. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  281. unsigned long top;
  282. if (sp_banks[i].base_addr < phys_base)
  283. phys_base = sp_banks[i].base_addr;
  284. top = sp_banks[i].base_addr +
  285. sp_banks[i].num_bytes;
  286. if (highest_paddr < top)
  287. highest_paddr = top;
  288. }
  289. pfn_base = phys_base >> PAGE_SHIFT;
  290. if (!root_flags)
  291. root_mountflags &= ~MS_RDONLY;
  292. ROOT_DEV = old_decode_dev(root_dev);
  293. #ifdef CONFIG_BLK_DEV_RAM
  294. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  295. #endif
  296. prom_setsync(prom_sync_me);
  297. if((boot_flags & BOOTME_DEBUG) && (linux_dbvec != NULL) &&
  298. ((*(short *)linux_dbvec) != -1)) {
  299. printk("Booted under KADB. Syncing trap table.\n");
  300. (*(linux_dbvec->teach_debugger))();
  301. }
  302. /* Run-time patch instructions to match the cpu model */
  303. per_cpu_patch();
  304. paging_init();
  305. smp_setup_cpu_possible_map();
  306. }
  307. extern int stop_a_enabled;
  308. void sun_do_break(void)
  309. {
  310. if (!stop_a_enabled)
  311. return;
  312. printk("\n");
  313. flush_user_windows();
  314. prom_cmdline();
  315. }
  316. EXPORT_SYMBOL(sun_do_break);
  317. int stop_a_enabled = 1;
  318. static int __init topology_init(void)
  319. {
  320. int i, ncpus, err;
  321. /* Count the number of physically present processors in
  322. * the machine, even on uniprocessor, so that /proc/cpuinfo
  323. * output is consistent with 2.4.x
  324. */
  325. ncpus = 0;
  326. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  327. ncpus++;
  328. ncpus_probed = ncpus;
  329. err = 0;
  330. for_each_online_cpu(i) {
  331. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  332. if (!p)
  333. err = -ENOMEM;
  334. else
  335. register_cpu(p, i);
  336. }
  337. return err;
  338. }
  339. subsys_initcall(topology_init);
  340. #if defined(CONFIG_SPARC32) && !defined(CONFIG_SMP)
  341. void __init arch_cpu_finalize_init(void)
  342. {
  343. cpu_data(0).udelay_val = loops_per_jiffy;
  344. }
  345. #endif