setup.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995 Linus Torvalds
  7. * Copyright (C) 1995 Waldorf Electronics
  8. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03 Ralf Baechle
  9. * Copyright (C) 1996 Stoned Elipot
  10. * Copyright (C) 1999 Silicon Graphics, Inc.
  11. * Copyright (C) 2000, 2001, 2002, 2007 Maciej W. Rozycki
  12. */
  13. #include <linux/init.h>
  14. #include <linux/cpu.h>
  15. #include <linux/delay.h>
  16. #include <linux/ioport.h>
  17. #include <linux/export.h>
  18. #include <linux/memblock.h>
  19. #include <linux/initrd.h>
  20. #include <linux/root_dev.h>
  21. #include <linux/highmem.h>
  22. #include <linux/console.h>
  23. #include <linux/pfn.h>
  24. #include <linux/debugfs.h>
  25. #include <linux/kexec.h>
  26. #include <linux/sizes.h>
  27. #include <linux/device.h>
  28. #include <linux/dma-map-ops.h>
  29. #include <linux/decompress/generic.h>
  30. #include <linux/of_fdt.h>
  31. #include <linux/dmi.h>
  32. #include <linux/crash_dump.h>
  33. #include <asm/addrspace.h>
  34. #include <asm/bootinfo.h>
  35. #include <asm/bugs.h>
  36. #include <asm/cache.h>
  37. #include <asm/cdmm.h>
  38. #include <asm/cpu.h>
  39. #include <asm/debug.h>
  40. #include <asm/mmzone.h>
  41. #include <asm/sections.h>
  42. #include <asm/setup.h>
  43. #include <asm/smp-ops.h>
  44. #include <asm/mips-cps.h>
  45. #include <asm/prom.h>
  46. #include <asm/fw/fw.h>
  47. #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
  48. char __section(".appended_dtb") __appended_dtb[0x100000];
  49. #endif /* CONFIG_MIPS_ELF_APPENDED_DTB */
  50. struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
  51. EXPORT_SYMBOL(cpu_data);
  52. /*
  53. * Setup information
  54. *
  55. * These are initialized so they are in the .data section
  56. */
  57. unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
  58. EXPORT_SYMBOL(mips_machtype);
  59. static char __initdata command_line[COMMAND_LINE_SIZE];
  60. char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
  61. #ifdef CONFIG_CMDLINE_BOOL
  62. static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE;
  63. #else
  64. static const char builtin_cmdline[] __initconst = "";
  65. #endif
  66. /*
  67. * mips_io_port_base is the begin of the address space to which x86 style
  68. * I/O ports are mapped.
  69. */
  70. unsigned long mips_io_port_base = -1;
  71. EXPORT_SYMBOL(mips_io_port_base);
  72. static struct resource code_resource = { .name = "Kernel code", };
  73. static struct resource data_resource = { .name = "Kernel data", };
  74. static struct resource bss_resource = { .name = "Kernel bss", };
  75. unsigned long __kaslr_offset __ro_after_init;
  76. EXPORT_SYMBOL(__kaslr_offset);
  77. static void *detect_magic __initdata = detect_memory_region;
  78. #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
  79. unsigned long ARCH_PFN_OFFSET;
  80. EXPORT_SYMBOL(ARCH_PFN_OFFSET);
  81. #endif
  82. void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
  83. {
  84. void *dm = &detect_magic;
  85. phys_addr_t size;
  86. for (size = sz_min; size < sz_max; size <<= 1) {
  87. if (!memcmp(dm, dm + size, sizeof(detect_magic)))
  88. break;
  89. }
  90. pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
  91. ((unsigned long long) size) / SZ_1M,
  92. (unsigned long long) start,
  93. ((unsigned long long) sz_min) / SZ_1M,
  94. ((unsigned long long) sz_max) / SZ_1M);
  95. memblock_add(start, size);
  96. }
  97. /*
  98. * Manage initrd
  99. */
  100. #ifdef CONFIG_BLK_DEV_INITRD
  101. static int __init rd_start_early(char *p)
  102. {
  103. unsigned long start = memparse(p, &p);
  104. #ifdef CONFIG_64BIT
  105. /* Guess if the sign extension was forgotten by bootloader */
  106. if (start < XKPHYS)
  107. start = (int)start;
  108. #endif
  109. initrd_start = start;
  110. initrd_end += start;
  111. return 0;
  112. }
  113. early_param("rd_start", rd_start_early);
  114. static int __init rd_size_early(char *p)
  115. {
  116. initrd_end += memparse(p, &p);
  117. return 0;
  118. }
  119. early_param("rd_size", rd_size_early);
  120. /* it returns the next free pfn after initrd */
  121. static unsigned long __init init_initrd(void)
  122. {
  123. unsigned long end;
  124. /*
  125. * Board specific code or command line parser should have
  126. * already set up initrd_start and initrd_end. In these cases
  127. * perform sanity checks and use them if all looks good.
  128. */
  129. if (!initrd_start || initrd_end <= initrd_start)
  130. goto disable;
  131. if (initrd_start & ~PAGE_MASK) {
  132. pr_err("initrd start must be page aligned\n");
  133. goto disable;
  134. }
  135. /*
  136. * Sanitize initrd addresses. For example firmware
  137. * can't guess if they need to pass them through
  138. * 64-bits values if the kernel has been built in pure
  139. * 32-bit. We need also to switch from KSEG0 to XKPHYS
  140. * addresses now, so the code can now safely use __pa().
  141. */
  142. end = __pa(initrd_end);
  143. initrd_end = (unsigned long)__va(end);
  144. initrd_start = (unsigned long)__va(__pa(initrd_start));
  145. if (initrd_start < PAGE_OFFSET) {
  146. pr_err("initrd start < PAGE_OFFSET\n");
  147. goto disable;
  148. }
  149. ROOT_DEV = Root_RAM0;
  150. return PFN_UP(end);
  151. disable:
  152. initrd_start = 0;
  153. initrd_end = 0;
  154. return 0;
  155. }
  156. /* In some conditions (e.g. big endian bootloader with a little endian
  157. kernel), the initrd might appear byte swapped. Try to detect this and
  158. byte swap it if needed. */
  159. static void __init maybe_bswap_initrd(void)
  160. {
  161. #if defined(CONFIG_CPU_CAVIUM_OCTEON)
  162. u64 buf;
  163. /* Check for CPIO signature */
  164. if (!memcmp((void *)initrd_start, "070701", 6))
  165. return;
  166. /* Check for compressed initrd */
  167. if (decompress_method((unsigned char *)initrd_start, 8, NULL))
  168. return;
  169. /* Try again with a byte swapped header */
  170. buf = swab64p((u64 *)initrd_start);
  171. if (!memcmp(&buf, "070701", 6) ||
  172. decompress_method((unsigned char *)(&buf), 8, NULL)) {
  173. unsigned long i;
  174. pr_info("Byteswapped initrd detected\n");
  175. for (i = initrd_start; i < ALIGN(initrd_end, 8); i += 8)
  176. swab64s((u64 *)i);
  177. }
  178. #endif
  179. }
  180. static void __init finalize_initrd(void)
  181. {
  182. unsigned long size = initrd_end - initrd_start;
  183. if (size == 0) {
  184. printk(KERN_INFO "Initrd not found or empty");
  185. goto disable;
  186. }
  187. if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
  188. printk(KERN_ERR "Initrd extends beyond end of memory");
  189. goto disable;
  190. }
  191. maybe_bswap_initrd();
  192. memblock_reserve(__pa(initrd_start), size);
  193. initrd_below_start_ok = 1;
  194. pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
  195. initrd_start, size);
  196. return;
  197. disable:
  198. printk(KERN_CONT " - disabling initrd\n");
  199. initrd_start = 0;
  200. initrd_end = 0;
  201. }
  202. #else /* !CONFIG_BLK_DEV_INITRD */
  203. static unsigned long __init init_initrd(void)
  204. {
  205. return 0;
  206. }
  207. #define finalize_initrd() do {} while (0)
  208. #endif
  209. /*
  210. * Initialize the bootmem allocator. It also setup initrd related data
  211. * if needed.
  212. */
  213. #if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON64) && defined(CONFIG_NUMA))
  214. static void __init bootmem_init(void)
  215. {
  216. init_initrd();
  217. finalize_initrd();
  218. }
  219. #else /* !CONFIG_SGI_IP27 */
  220. static void __init bootmem_init(void)
  221. {
  222. phys_addr_t ramstart, ramend;
  223. unsigned long start, end;
  224. int i;
  225. ramstart = memblock_start_of_DRAM();
  226. ramend = memblock_end_of_DRAM();
  227. /*
  228. * Sanity check any INITRD first. We don't take it into account
  229. * for bootmem setup initially, rely on the end-of-kernel-code
  230. * as our memory range starting point. Once bootmem is inited we
  231. * will reserve the area used for the initrd.
  232. */
  233. init_initrd();
  234. /* Reserve memory occupied by kernel. */
  235. memblock_reserve(__pa_symbol(&_text),
  236. __pa_symbol(&_end) - __pa_symbol(&_text));
  237. /* max_low_pfn is not a number of pages but the end pfn of low mem */
  238. #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
  239. ARCH_PFN_OFFSET = PFN_UP(ramstart);
  240. #else
  241. /*
  242. * Reserve any memory between the start of RAM and PHYS_OFFSET
  243. */
  244. if (ramstart > PHYS_OFFSET)
  245. memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
  246. if (PFN_UP(ramstart) > ARCH_PFN_OFFSET) {
  247. pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
  248. (unsigned long)((PFN_UP(ramstart) - ARCH_PFN_OFFSET) * sizeof(struct page)),
  249. (unsigned long)(PFN_UP(ramstart) - ARCH_PFN_OFFSET));
  250. }
  251. #endif
  252. min_low_pfn = ARCH_PFN_OFFSET;
  253. max_pfn = PFN_DOWN(ramend);
  254. for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, NULL) {
  255. /*
  256. * Skip highmem here so we get an accurate max_low_pfn if low
  257. * memory stops short of high memory.
  258. * If the region overlaps HIGHMEM_START, end is clipped so
  259. * max_pfn excludes the highmem portion.
  260. */
  261. if (start >= PFN_DOWN(HIGHMEM_START))
  262. continue;
  263. if (end > PFN_DOWN(HIGHMEM_START))
  264. end = PFN_DOWN(HIGHMEM_START);
  265. if (end > max_low_pfn)
  266. max_low_pfn = end;
  267. }
  268. if (min_low_pfn >= max_low_pfn)
  269. panic("Incorrect memory mapping !!!");
  270. if (max_pfn > PFN_DOWN(HIGHMEM_START)) {
  271. max_low_pfn = PFN_DOWN(HIGHMEM_START);
  272. #ifdef CONFIG_HIGHMEM
  273. highstart_pfn = max_low_pfn;
  274. highend_pfn = max_pfn;
  275. #else
  276. max_pfn = max_low_pfn;
  277. #endif
  278. }
  279. /*
  280. * Reserve initrd memory if needed.
  281. */
  282. finalize_initrd();
  283. }
  284. #endif /* CONFIG_SGI_IP27 */
  285. static int usermem __initdata;
  286. static int __init early_parse_mem(char *p)
  287. {
  288. phys_addr_t start, size;
  289. if (!p) {
  290. pr_err("mem parameter is empty, do nothing\n");
  291. return -EINVAL;
  292. }
  293. /*
  294. * If a user specifies memory size, we
  295. * blow away any automatically generated
  296. * size.
  297. */
  298. if (usermem == 0) {
  299. usermem = 1;
  300. memblock_remove(memblock_start_of_DRAM(),
  301. memblock_end_of_DRAM() - memblock_start_of_DRAM());
  302. }
  303. start = 0;
  304. size = memparse(p, &p);
  305. if (*p == '@')
  306. start = memparse(p + 1, &p);
  307. if (IS_ENABLED(CONFIG_NUMA))
  308. memblock_add_node(start, size, pa_to_nid(start), MEMBLOCK_NONE);
  309. else
  310. memblock_add(start, size);
  311. return 0;
  312. }
  313. early_param("mem", early_parse_mem);
  314. static int __init early_parse_memmap(char *p)
  315. {
  316. char *oldp;
  317. u64 start_at, mem_size;
  318. if (!p)
  319. return -EINVAL;
  320. if (!strncmp(p, "exactmap", 8)) {
  321. pr_err("\"memmap=exactmap\" invalid on MIPS\n");
  322. return 0;
  323. }
  324. oldp = p;
  325. mem_size = memparse(p, &p);
  326. if (p == oldp)
  327. return -EINVAL;
  328. if (*p == '@') {
  329. start_at = memparse(p+1, &p);
  330. memblock_add(start_at, mem_size);
  331. } else if (*p == '#') {
  332. pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
  333. return -EINVAL;
  334. } else if (*p == '$') {
  335. start_at = memparse(p+1, &p);
  336. memblock_add(start_at, mem_size);
  337. memblock_reserve(start_at, mem_size);
  338. } else {
  339. pr_err("\"memmap\" invalid format!\n");
  340. return -EINVAL;
  341. }
  342. if (*p == '\0') {
  343. usermem = 1;
  344. return 0;
  345. } else
  346. return -EINVAL;
  347. }
  348. early_param("memmap", early_parse_memmap);
  349. static void __init mips_reserve_vmcore(void)
  350. {
  351. #ifdef CONFIG_PROC_VMCORE
  352. phys_addr_t start, end;
  353. u64 i;
  354. if (!elfcorehdr_size) {
  355. for_each_mem_range(i, &start, &end) {
  356. if (elfcorehdr_addr >= start && elfcorehdr_addr < end) {
  357. /*
  358. * Reserve from the elf core header to the end of
  359. * the memory segment, that should all be kdump
  360. * reserved memory.
  361. */
  362. elfcorehdr_size = end - elfcorehdr_addr;
  363. break;
  364. }
  365. }
  366. }
  367. pr_info("Reserving %ldKB of memory at %ldKB for kdump\n",
  368. (unsigned long)elfcorehdr_size >> 10, (unsigned long)elfcorehdr_addr >> 10);
  369. memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
  370. #endif
  371. }
  372. /* 64M alignment for crash kernel regions */
  373. #define CRASH_ALIGN SZ_64M
  374. #define CRASH_ADDR_MAX SZ_512M
  375. static void __init mips_parse_crashkernel(void)
  376. {
  377. unsigned long long total_mem;
  378. unsigned long long crash_size, crash_base;
  379. int ret;
  380. if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
  381. return;
  382. total_mem = memblock_phys_mem_size();
  383. ret = parse_crashkernel(boot_command_line, total_mem,
  384. &crash_size, &crash_base,
  385. NULL, NULL);
  386. if (ret != 0 || crash_size <= 0)
  387. return;
  388. if (crash_base <= 0) {
  389. crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
  390. CRASH_ALIGN,
  391. CRASH_ADDR_MAX);
  392. if (!crash_base) {
  393. pr_warn("crashkernel reservation failed - No suitable area found.\n");
  394. return;
  395. }
  396. } else {
  397. unsigned long long start;
  398. start = memblock_phys_alloc_range(crash_size, 1,
  399. crash_base,
  400. crash_base + crash_size);
  401. if (start != crash_base) {
  402. pr_warn("Invalid memory region reserved for crash kernel\n");
  403. return;
  404. }
  405. }
  406. crashk_res.start = crash_base;
  407. crashk_res.end = crash_base + crash_size - 1;
  408. }
  409. static void __init request_crashkernel(struct resource *res)
  410. {
  411. int ret;
  412. if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
  413. return;
  414. if (crashk_res.start == crashk_res.end)
  415. return;
  416. ret = request_resource(res, &crashk_res);
  417. if (!ret)
  418. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
  419. (unsigned long)(resource_size(&crashk_res) >> 20),
  420. (unsigned long)(crashk_res.start >> 20));
  421. }
  422. static void __init check_kernel_sections_mem(void)
  423. {
  424. phys_addr_t start = __pa_symbol(&_text);
  425. phys_addr_t size = __pa_symbol(&_end) - start;
  426. if (!memblock_is_region_memory(start, size)) {
  427. pr_info("Kernel sections are not in the memory maps\n");
  428. memblock_add(start, size);
  429. }
  430. }
  431. static void __init bootcmdline_append(const char *s, size_t max)
  432. {
  433. if (!s[0] || !max)
  434. return;
  435. if (boot_command_line[0])
  436. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  437. strlcat(boot_command_line, s, max);
  438. }
  439. #ifdef CONFIG_OF_EARLY_FLATTREE
  440. static int __init bootcmdline_scan_chosen(unsigned long node, const char *uname,
  441. int depth, void *data)
  442. {
  443. bool *dt_bootargs = data;
  444. const char *p;
  445. int l;
  446. if (depth != 1 || !data ||
  447. (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
  448. return 0;
  449. p = of_get_flat_dt_prop(node, "bootargs", &l);
  450. if (p != NULL && l > 0) {
  451. bootcmdline_append(p, min(l, COMMAND_LINE_SIZE));
  452. *dt_bootargs = true;
  453. }
  454. return 1;
  455. }
  456. #endif /* CONFIG_OF_EARLY_FLATTREE */
  457. static void __init bootcmdline_init(void)
  458. {
  459. bool dt_bootargs = false;
  460. /*
  461. * If CMDLINE_OVERRIDE is enabled then initializing the command line is
  462. * trivial - we simply use the built-in command line unconditionally &
  463. * unmodified.
  464. */
  465. if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
  466. strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  467. return;
  468. }
  469. /*
  470. * If the user specified a built-in command line &
  471. * MIPS_CMDLINE_BUILTIN_EXTEND, then the built-in command line is
  472. * prepended to arguments from the bootloader or DT so we'll copy them
  473. * to the start of boot_command_line here. Otherwise, empty
  474. * boot_command_line to undo anything early_init_dt_scan_chosen() did.
  475. */
  476. if (IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND))
  477. strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  478. else
  479. boot_command_line[0] = 0;
  480. #ifdef CONFIG_OF_EARLY_FLATTREE
  481. /*
  482. * If we're configured to take boot arguments from DT, look for those
  483. * now.
  484. */
  485. if (IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB) ||
  486. IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND))
  487. of_scan_flat_dt(bootcmdline_scan_chosen, &dt_bootargs);
  488. #endif
  489. /*
  490. * If we didn't get any arguments from DT (regardless of whether that's
  491. * because we weren't configured to look for them, or because we looked
  492. * & found none) then we'll take arguments from the bootloader.
  493. * plat_mem_setup() should have filled arcs_cmdline with arguments from
  494. * the bootloader.
  495. */
  496. if (IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND) || !dt_bootargs)
  497. bootcmdline_append(arcs_cmdline, COMMAND_LINE_SIZE);
  498. /*
  499. * If the user specified a built-in command line & we didn't already
  500. * prepend it, we append it to boot_command_line here.
  501. */
  502. if (IS_ENABLED(CONFIG_CMDLINE_BOOL) &&
  503. !IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND))
  504. bootcmdline_append(builtin_cmdline, COMMAND_LINE_SIZE);
  505. }
  506. /*
  507. * arch_mem_init - initialize memory management subsystem
  508. *
  509. * o plat_mem_setup() detects the memory configuration and will record detected
  510. * memory areas using memblock_add.
  511. *
  512. * At this stage the memory configuration of the system is known to the
  513. * kernel but generic memory management system is still entirely uninitialized.
  514. *
  515. * o bootmem_init()
  516. * o sparse_init()
  517. * o paging_init()
  518. * o dma_contiguous_reserve()
  519. *
  520. * At this stage the bootmem allocator is ready to use.
  521. *
  522. * NOTE: historically plat_mem_setup did the entire platform initialization.
  523. * This was rather impractical because it meant plat_mem_setup had to
  524. * get away without any kind of memory allocator. To keep old code from
  525. * breaking plat_setup was just renamed to plat_mem_setup and a second platform
  526. * initialization hook for anything else was introduced.
  527. */
  528. static void __init arch_mem_init(char **cmdline_p)
  529. {
  530. /* call board setup routine */
  531. plat_mem_setup();
  532. memblock_set_bottom_up(true);
  533. bootcmdline_init();
  534. strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  535. *cmdline_p = command_line;
  536. parse_early_param();
  537. if (usermem)
  538. pr_info("User-defined physical RAM map overwrite\n");
  539. check_kernel_sections_mem();
  540. early_init_fdt_reserve_self();
  541. early_init_fdt_scan_reserved_mem();
  542. #ifndef CONFIG_NUMA
  543. memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);
  544. #endif
  545. bootmem_init();
  546. /*
  547. * Prevent memblock from allocating high memory.
  548. * This cannot be done before max_low_pfn is detected, so up
  549. * to this point is possible to only reserve physical memory
  550. * with memblock_reserve; memblock_alloc* can be used
  551. * only after this point
  552. */
  553. memblock_set_current_limit(PFN_PHYS(max_low_pfn));
  554. mips_reserve_vmcore();
  555. mips_parse_crashkernel();
  556. device_tree_init();
  557. /*
  558. * In order to reduce the possibility of kernel panic when failed to
  559. * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate
  560. * low memory as small as possible before plat_swiotlb_setup(), so
  561. * make sparse_init() using top-down allocation.
  562. */
  563. memblock_set_bottom_up(false);
  564. sparse_init();
  565. memblock_set_bottom_up(true);
  566. plat_swiotlb_setup();
  567. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  568. /* Reserve for hibernation. */
  569. memblock_reserve(__pa_symbol(&__nosave_begin),
  570. __pa_symbol(&__nosave_end) - __pa_symbol(&__nosave_begin));
  571. early_memtest(PFN_PHYS(ARCH_PFN_OFFSET), PFN_PHYS(max_low_pfn));
  572. }
  573. static void __init resource_init(void)
  574. {
  575. phys_addr_t start, end;
  576. u64 i;
  577. if (UNCAC_BASE != IO_BASE)
  578. return;
  579. code_resource.start = __pa_symbol(&_text);
  580. code_resource.end = __pa_symbol(&_etext) - 1;
  581. data_resource.start = __pa_symbol(&_etext);
  582. data_resource.end = __pa_symbol(&_edata) - 1;
  583. bss_resource.start = __pa_symbol(&__bss_start);
  584. bss_resource.end = __pa_symbol(&__bss_stop) - 1;
  585. for_each_mem_range(i, &start, &end) {
  586. struct resource *res;
  587. res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
  588. if (!res)
  589. panic("%s: Failed to allocate %zu bytes\n", __func__,
  590. sizeof(struct resource));
  591. res->start = start;
  592. /*
  593. * In memblock, end points to the first byte after the
  594. * range while in resourses, end points to the last byte in
  595. * the range.
  596. */
  597. res->end = end - 1;
  598. res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
  599. res->name = "System RAM";
  600. request_resource(&iomem_resource, res);
  601. /*
  602. * We don't know which RAM region contains kernel data,
  603. * so we try it repeatedly and let the resource manager
  604. * test it.
  605. */
  606. request_resource(res, &code_resource);
  607. request_resource(res, &data_resource);
  608. request_resource(res, &bss_resource);
  609. request_crashkernel(res);
  610. }
  611. }
  612. #ifdef CONFIG_SMP
  613. static void __init prefill_possible_map(void)
  614. {
  615. int i, possible = num_possible_cpus();
  616. if (possible > nr_cpu_ids)
  617. possible = nr_cpu_ids;
  618. for (i = 0; i < possible; i++)
  619. set_cpu_possible(i, true);
  620. for (; i < NR_CPUS; i++)
  621. set_cpu_possible(i, false);
  622. set_nr_cpu_ids(possible);
  623. }
  624. #else
  625. static inline void prefill_possible_map(void) {}
  626. #endif
  627. static void __init setup_rng_seed(void)
  628. {
  629. char *rng_seed_hex = fw_getenv("rngseed");
  630. u8 rng_seed[512];
  631. size_t len;
  632. if (!rng_seed_hex)
  633. return;
  634. len = min(sizeof(rng_seed), strlen(rng_seed_hex) / 2);
  635. if (hex2bin(rng_seed, rng_seed_hex, len))
  636. return;
  637. add_bootloader_randomness(rng_seed, len);
  638. memzero_explicit(rng_seed, len);
  639. memzero_explicit(rng_seed_hex, len * 2);
  640. }
  641. void __init setup_arch(char **cmdline_p)
  642. {
  643. cpu_probe();
  644. mips_cm_probe();
  645. prom_init();
  646. setup_early_fdc_console();
  647. #ifdef CONFIG_EARLY_PRINTK
  648. setup_early_printk();
  649. #endif
  650. cpu_report();
  651. if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
  652. check_bugs64_early();
  653. arch_mem_init(cmdline_p);
  654. dmi_setup();
  655. resource_init();
  656. plat_smp_setup();
  657. prefill_possible_map();
  658. cpu_cache_init();
  659. paging_init();
  660. memblock_dump_all();
  661. setup_rng_seed();
  662. }
  663. unsigned long kernelsp[NR_CPUS];
  664. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  665. #ifdef CONFIG_DEBUG_FS
  666. struct dentry *mips_debugfs_dir;
  667. static int __init debugfs_mips(void)
  668. {
  669. mips_debugfs_dir = debugfs_create_dir("mips", NULL);
  670. return 0;
  671. }
  672. arch_initcall(debugfs_mips);
  673. #endif
  674. #ifdef CONFIG_DMA_NONCOHERENT
  675. static int __init setcoherentio(char *str)
  676. {
  677. dma_default_coherent = true;
  678. pr_info("Hardware DMA cache coherency (command line)\n");
  679. return 0;
  680. }
  681. early_param("coherentio", setcoherentio);
  682. static int __init setnocoherentio(char *str)
  683. {
  684. dma_default_coherent = false;
  685. pr_info("Software DMA cache coherency (command line)\n");
  686. return 0;
  687. }
  688. early_param("nocoherentio", setnocoherentio);
  689. #endif
  690. void __init arch_cpu_finalize_init(void)
  691. {
  692. unsigned int cpu = smp_processor_id();
  693. cpu_data[cpu].udelay_val = loops_per_jiffy;
  694. check_bugs32();
  695. if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
  696. check_bugs64();
  697. }