setup_32.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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/screen_info.h>
  20. #include <linux/delay.h>
  21. #include <linux/fs.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/kdev_t.h>
  25. #include <linux/major.h>
  26. #include <linux/string.h>
  27. #include <linux/init.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/console.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/root_dev.h>
  32. #include <linux/cpu.h>
  33. #include <linux/kdebug.h>
  34. #include <linux/export.h>
  35. #include <linux/start_kernel.h>
  36. #include <uapi/linux/mount.h>
  37. #include <asm/io.h>
  38. #include <asm/processor.h>
  39. #include <asm/oplib.h>
  40. #include <asm/page.h>
  41. #include <asm/traps.h>
  42. #include <asm/vaddrs.h>
  43. #include <asm/mbus.h>
  44. #include <asm/idprom.h>
  45. #include <asm/cpudata.h>
  46. #include <asm/setup.h>
  47. #include <asm/cacheflush.h>
  48. #include <asm/sections.h>
  49. #include "kernel.h"
  50. struct screen_info screen_info = {
  51. 0, 0, /* orig-x, orig-y */
  52. 0, /* unused */
  53. 0, /* orig-video-page */
  54. 0, /* orig-video-mode */
  55. 128, /* orig-video-cols */
  56. 0,0,0, /* ega_ax, ega_bx, ega_cx */
  57. 54, /* orig-video-lines */
  58. 0, /* orig-video-isVGA */
  59. 16 /* orig-video-points */
  60. };
  61. /* Typing sync at the prom prompt calls the function pointed to by
  62. * romvec->pv_synchook which I set to the following function.
  63. * This should sync all filesystems and return, for now it just
  64. * prints out pretty messages and returns.
  65. */
  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, NULL);
  79. if (!is_idle_task(current)) {
  80. local_irq_enable();
  81. ksys_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 int 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 == ' ')
  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 = &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. switch(sparc_cpu_model) {
  270. case sun4m:
  271. pr_info("ARCH: SUN4M\n");
  272. break;
  273. case sun4d:
  274. pr_info("ARCH: SUN4D\n");
  275. break;
  276. case sun4e:
  277. pr_info("ARCH: SUN4E\n");
  278. break;
  279. case sun4u:
  280. pr_info("ARCH: SUN4U\n");
  281. break;
  282. case sparc_leon:
  283. pr_info("ARCH: LEON\n");
  284. break;
  285. default:
  286. pr_info("ARCH: UNKNOWN!\n");
  287. break;
  288. }
  289. idprom_init();
  290. load_mmu();
  291. phys_base = 0xffffffffUL;
  292. highest_paddr = 0UL;
  293. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  294. unsigned long top;
  295. if (sp_banks[i].base_addr < phys_base)
  296. phys_base = sp_banks[i].base_addr;
  297. top = sp_banks[i].base_addr +
  298. sp_banks[i].num_bytes;
  299. if (highest_paddr < top)
  300. highest_paddr = top;
  301. }
  302. pfn_base = phys_base >> PAGE_SHIFT;
  303. if (!root_flags)
  304. root_mountflags &= ~MS_RDONLY;
  305. ROOT_DEV = old_decode_dev(root_dev);
  306. #ifdef CONFIG_BLK_DEV_RAM
  307. rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
  308. #endif
  309. prom_setsync(prom_sync_me);
  310. if((boot_flags & BOOTME_DEBUG) && (linux_dbvec != NULL) &&
  311. ((*(short *)linux_dbvec) != -1)) {
  312. printk("Booted under KADB. Syncing trap table.\n");
  313. (*(linux_dbvec->teach_debugger))();
  314. }
  315. init_task.thread.kregs = &fake_swapper_regs;
  316. /* Run-time patch instructions to match the cpu model */
  317. per_cpu_patch();
  318. paging_init();
  319. smp_setup_cpu_possible_map();
  320. }
  321. extern int stop_a_enabled;
  322. void sun_do_break(void)
  323. {
  324. if (!stop_a_enabled)
  325. return;
  326. printk("\n");
  327. flush_user_windows();
  328. prom_cmdline();
  329. }
  330. EXPORT_SYMBOL(sun_do_break);
  331. int stop_a_enabled = 1;
  332. static int __init topology_init(void)
  333. {
  334. int i, ncpus, err;
  335. /* Count the number of physically present processors in
  336. * the machine, even on uniprocessor, so that /proc/cpuinfo
  337. * output is consistent with 2.4.x
  338. */
  339. ncpus = 0;
  340. while (!cpu_find_by_instance(ncpus, NULL, NULL))
  341. ncpus++;
  342. ncpus_probed = ncpus;
  343. err = 0;
  344. for_each_online_cpu(i) {
  345. struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
  346. if (!p)
  347. err = -ENOMEM;
  348. else
  349. register_cpu(p, i);
  350. }
  351. return err;
  352. }
  353. subsys_initcall(topology_init);