setup.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  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/ioport.h>
  15. #include <linux/export.h>
  16. #include <linux/screen_info.h>
  17. #include <linux/memblock.h>
  18. #include <linux/bootmem.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-contiguous.h>
  29. #include <linux/decompress/generic.h>
  30. #include <linux/of_fdt.h>
  31. #include <asm/addrspace.h>
  32. #include <asm/bootinfo.h>
  33. #include <asm/bugs.h>
  34. #include <asm/cache.h>
  35. #include <asm/cdmm.h>
  36. #include <asm/cpu.h>
  37. #include <asm/debug.h>
  38. #include <asm/dma-coherence.h>
  39. #include <asm/sections.h>
  40. #include <asm/setup.h>
  41. #include <asm/smp-ops.h>
  42. #include <asm/prom.h>
  43. #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
  44. const char __section(.appended_dtb) __appended_dtb[0x100000];
  45. #endif /* CONFIG_MIPS_ELF_APPENDED_DTB */
  46. struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
  47. EXPORT_SYMBOL(cpu_data);
  48. #ifdef CONFIG_VT
  49. struct screen_info screen_info;
  50. #endif
  51. /*
  52. * Setup information
  53. *
  54. * These are initialized so they are in the .data section
  55. */
  56. unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
  57. EXPORT_SYMBOL(mips_machtype);
  58. struct boot_mem_map boot_mem_map;
  59. static char __initdata command_line[COMMAND_LINE_SIZE];
  60. char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
  61. #ifdef CONFIG_CMDLINE_BOOL
  62. static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  63. #endif
  64. /*
  65. * mips_io_port_base is the begin of the address space to which x86 style
  66. * I/O ports are mapped.
  67. */
  68. const unsigned long mips_io_port_base = -1;
  69. EXPORT_SYMBOL(mips_io_port_base);
  70. static struct resource code_resource = { .name = "Kernel code", };
  71. static struct resource data_resource = { .name = "Kernel data", };
  72. static struct resource bss_resource = { .name = "Kernel bss", };
  73. static void *detect_magic __initdata = detect_memory_region;
  74. #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
  75. unsigned long ARCH_PFN_OFFSET;
  76. EXPORT_SYMBOL(ARCH_PFN_OFFSET);
  77. #endif
  78. void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
  79. {
  80. int x = boot_mem_map.nr_map;
  81. int i;
  82. /*
  83. * If the region reaches the top of the physical address space, adjust
  84. * the size slightly so that (start + size) doesn't overflow
  85. */
  86. if (start + size - 1 == PHYS_ADDR_MAX)
  87. --size;
  88. /* Sanity check */
  89. if (start + size < start) {
  90. pr_warn("Trying to add an invalid memory region, skipped\n");
  91. return;
  92. }
  93. /*
  94. * Try to merge with existing entry, if any.
  95. */
  96. for (i = 0; i < boot_mem_map.nr_map; i++) {
  97. struct boot_mem_map_entry *entry = boot_mem_map.map + i;
  98. unsigned long top;
  99. if (entry->type != type)
  100. continue;
  101. if (start + size < entry->addr)
  102. continue; /* no overlap */
  103. if (entry->addr + entry->size < start)
  104. continue; /* no overlap */
  105. top = max(entry->addr + entry->size, start + size);
  106. entry->addr = min(entry->addr, start);
  107. entry->size = top - entry->addr;
  108. return;
  109. }
  110. if (boot_mem_map.nr_map == BOOT_MEM_MAP_MAX) {
  111. pr_err("Ooops! Too many entries in the memory map!\n");
  112. return;
  113. }
  114. boot_mem_map.map[x].addr = start;
  115. boot_mem_map.map[x].size = size;
  116. boot_mem_map.map[x].type = type;
  117. boot_mem_map.nr_map++;
  118. }
  119. void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
  120. {
  121. void *dm = &detect_magic;
  122. phys_addr_t size;
  123. for (size = sz_min; size < sz_max; size <<= 1) {
  124. if (!memcmp(dm, dm + size, sizeof(detect_magic)))
  125. break;
  126. }
  127. pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
  128. ((unsigned long long) size) / SZ_1M,
  129. (unsigned long long) start,
  130. ((unsigned long long) sz_min) / SZ_1M,
  131. ((unsigned long long) sz_max) / SZ_1M);
  132. add_memory_region(start, size, BOOT_MEM_RAM);
  133. }
  134. static bool __init __maybe_unused memory_region_available(phys_addr_t start,
  135. phys_addr_t size)
  136. {
  137. int i;
  138. bool in_ram = false, free = true;
  139. for (i = 0; i < boot_mem_map.nr_map; i++) {
  140. phys_addr_t start_, end_;
  141. start_ = boot_mem_map.map[i].addr;
  142. end_ = boot_mem_map.map[i].addr + boot_mem_map.map[i].size;
  143. switch (boot_mem_map.map[i].type) {
  144. case BOOT_MEM_RAM:
  145. if (start >= start_ && start + size <= end_)
  146. in_ram = true;
  147. break;
  148. case BOOT_MEM_RESERVED:
  149. if ((start >= start_ && start < end_) ||
  150. (start < start_ && start + size >= start_))
  151. free = false;
  152. break;
  153. default:
  154. continue;
  155. }
  156. }
  157. return in_ram && free;
  158. }
  159. static void __init print_memory_map(void)
  160. {
  161. int i;
  162. const int field = 2 * sizeof(unsigned long);
  163. for (i = 0; i < boot_mem_map.nr_map; i++) {
  164. printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
  165. field, (unsigned long long) boot_mem_map.map[i].size,
  166. field, (unsigned long long) boot_mem_map.map[i].addr);
  167. switch (boot_mem_map.map[i].type) {
  168. case BOOT_MEM_RAM:
  169. printk(KERN_CONT "(usable)\n");
  170. break;
  171. case BOOT_MEM_INIT_RAM:
  172. printk(KERN_CONT "(usable after init)\n");
  173. break;
  174. case BOOT_MEM_ROM_DATA:
  175. printk(KERN_CONT "(ROM data)\n");
  176. break;
  177. case BOOT_MEM_RESERVED:
  178. printk(KERN_CONT "(reserved)\n");
  179. break;
  180. default:
  181. printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
  182. break;
  183. }
  184. }
  185. }
  186. /*
  187. * Manage initrd
  188. */
  189. #ifdef CONFIG_BLK_DEV_INITRD
  190. static int __init rd_start_early(char *p)
  191. {
  192. unsigned long start = memparse(p, &p);
  193. #ifdef CONFIG_64BIT
  194. /* Guess if the sign extension was forgotten by bootloader */
  195. if (start < XKPHYS)
  196. start = (int)start;
  197. #endif
  198. initrd_start = start;
  199. initrd_end += start;
  200. return 0;
  201. }
  202. early_param("rd_start", rd_start_early);
  203. static int __init rd_size_early(char *p)
  204. {
  205. initrd_end += memparse(p, &p);
  206. return 0;
  207. }
  208. early_param("rd_size", rd_size_early);
  209. /* it returns the next free pfn after initrd */
  210. static unsigned long __init init_initrd(void)
  211. {
  212. unsigned long end;
  213. /*
  214. * Board specific code or command line parser should have
  215. * already set up initrd_start and initrd_end. In these cases
  216. * perfom sanity checks and use them if all looks good.
  217. */
  218. if (!initrd_start || initrd_end <= initrd_start)
  219. goto disable;
  220. if (initrd_start & ~PAGE_MASK) {
  221. pr_err("initrd start must be page aligned\n");
  222. goto disable;
  223. }
  224. if (initrd_start < PAGE_OFFSET) {
  225. pr_err("initrd start < PAGE_OFFSET\n");
  226. goto disable;
  227. }
  228. /*
  229. * Sanitize initrd addresses. For example firmware
  230. * can't guess if they need to pass them through
  231. * 64-bits values if the kernel has been built in pure
  232. * 32-bit. We need also to switch from KSEG0 to XKPHYS
  233. * addresses now, so the code can now safely use __pa().
  234. */
  235. end = __pa(initrd_end);
  236. initrd_end = (unsigned long)__va(end);
  237. initrd_start = (unsigned long)__va(__pa(initrd_start));
  238. ROOT_DEV = Root_RAM0;
  239. return PFN_UP(end);
  240. disable:
  241. initrd_start = 0;
  242. initrd_end = 0;
  243. return 0;
  244. }
  245. /* In some conditions (e.g. big endian bootloader with a little endian
  246. kernel), the initrd might appear byte swapped. Try to detect this and
  247. byte swap it if needed. */
  248. static void __init maybe_bswap_initrd(void)
  249. {
  250. #if defined(CONFIG_CPU_CAVIUM_OCTEON)
  251. u64 buf;
  252. /* Check for CPIO signature */
  253. if (!memcmp((void *)initrd_start, "070701", 6))
  254. return;
  255. /* Check for compressed initrd */
  256. if (decompress_method((unsigned char *)initrd_start, 8, NULL))
  257. return;
  258. /* Try again with a byte swapped header */
  259. buf = swab64p((u64 *)initrd_start);
  260. if (!memcmp(&buf, "070701", 6) ||
  261. decompress_method((unsigned char *)(&buf), 8, NULL)) {
  262. unsigned long i;
  263. pr_info("Byteswapped initrd detected\n");
  264. for (i = initrd_start; i < ALIGN(initrd_end, 8); i += 8)
  265. swab64s((u64 *)i);
  266. }
  267. #endif
  268. }
  269. static void __init finalize_initrd(void)
  270. {
  271. unsigned long size = initrd_end - initrd_start;
  272. if (size == 0) {
  273. printk(KERN_INFO "Initrd not found or empty");
  274. goto disable;
  275. }
  276. if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
  277. printk(KERN_ERR "Initrd extends beyond end of memory");
  278. goto disable;
  279. }
  280. maybe_bswap_initrd();
  281. memblock_reserve(__pa(initrd_start), size);
  282. initrd_below_start_ok = 1;
  283. pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
  284. initrd_start, size);
  285. return;
  286. disable:
  287. printk(KERN_CONT " - disabling initrd\n");
  288. initrd_start = 0;
  289. initrd_end = 0;
  290. }
  291. #else /* !CONFIG_BLK_DEV_INITRD */
  292. static unsigned long __init init_initrd(void)
  293. {
  294. return 0;
  295. }
  296. #define finalize_initrd() do {} while (0)
  297. #endif
  298. /*
  299. * Initialize the bootmem allocator. It also setup initrd related data
  300. * if needed.
  301. */
  302. #if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_NUMA))
  303. static void __init bootmem_init(void)
  304. {
  305. init_initrd();
  306. finalize_initrd();
  307. }
  308. #else /* !CONFIG_SGI_IP27 */
  309. static void __init bootmem_init(void)
  310. {
  311. unsigned long reserved_end;
  312. phys_addr_t ramstart = PHYS_ADDR_MAX;
  313. int i;
  314. /*
  315. * Sanity check any INITRD first. We don't take it into account
  316. * for bootmem setup initially, rely on the end-of-kernel-code
  317. * as our memory range starting point. Once bootmem is inited we
  318. * will reserve the area used for the initrd.
  319. */
  320. init_initrd();
  321. reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
  322. memblock_reserve(PHYS_OFFSET, reserved_end << PAGE_SHIFT);
  323. /*
  324. * max_low_pfn is not a number of pages. The number of pages
  325. * of the system is given by 'max_low_pfn - min_low_pfn'.
  326. */
  327. min_low_pfn = ~0UL;
  328. max_low_pfn = 0;
  329. /*
  330. * Find the highest page frame number we have available
  331. * and the lowest used RAM address
  332. */
  333. for (i = 0; i < boot_mem_map.nr_map; i++) {
  334. unsigned long start, end;
  335. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  336. continue;
  337. start = PFN_UP(boot_mem_map.map[i].addr);
  338. end = PFN_DOWN(boot_mem_map.map[i].addr
  339. + boot_mem_map.map[i].size);
  340. ramstart = min(ramstart, boot_mem_map.map[i].addr);
  341. #ifndef CONFIG_HIGHMEM
  342. /*
  343. * Skip highmem here so we get an accurate max_low_pfn if low
  344. * memory stops short of high memory.
  345. * If the region overlaps HIGHMEM_START, end is clipped so
  346. * max_pfn excludes the highmem portion.
  347. */
  348. if (start >= PFN_DOWN(HIGHMEM_START))
  349. continue;
  350. if (end > PFN_DOWN(HIGHMEM_START))
  351. end = PFN_DOWN(HIGHMEM_START);
  352. #endif
  353. if (end > max_low_pfn)
  354. max_low_pfn = end;
  355. if (start < min_low_pfn)
  356. min_low_pfn = start;
  357. if (end <= reserved_end)
  358. continue;
  359. #ifdef CONFIG_BLK_DEV_INITRD
  360. /* Skip zones before initrd and initrd itself */
  361. if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
  362. continue;
  363. #endif
  364. }
  365. if (min_low_pfn >= max_low_pfn)
  366. panic("Incorrect memory mapping !!!");
  367. #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
  368. ARCH_PFN_OFFSET = PFN_UP(ramstart);
  369. #else
  370. /*
  371. * Reserve any memory between the start of RAM and PHYS_OFFSET
  372. */
  373. if (ramstart > PHYS_OFFSET) {
  374. add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
  375. BOOT_MEM_RESERVED);
  376. memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
  377. }
  378. if (min_low_pfn > ARCH_PFN_OFFSET) {
  379. pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
  380. (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
  381. min_low_pfn - ARCH_PFN_OFFSET);
  382. } else if (ARCH_PFN_OFFSET - min_low_pfn > 0UL) {
  383. pr_info("%lu free pages won't be used\n",
  384. ARCH_PFN_OFFSET - min_low_pfn);
  385. }
  386. min_low_pfn = ARCH_PFN_OFFSET;
  387. #endif
  388. /*
  389. * Determine low and high memory ranges
  390. */
  391. max_pfn = max_low_pfn;
  392. if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
  393. #ifdef CONFIG_HIGHMEM
  394. highstart_pfn = PFN_DOWN(HIGHMEM_START);
  395. highend_pfn = max_low_pfn;
  396. #endif
  397. max_low_pfn = PFN_DOWN(HIGHMEM_START);
  398. }
  399. for (i = 0; i < boot_mem_map.nr_map; i++) {
  400. unsigned long start, end;
  401. start = PFN_UP(boot_mem_map.map[i].addr);
  402. end = PFN_DOWN(boot_mem_map.map[i].addr
  403. + boot_mem_map.map[i].size);
  404. if (start <= min_low_pfn)
  405. start = min_low_pfn;
  406. if (start >= end)
  407. continue;
  408. #ifndef CONFIG_HIGHMEM
  409. if (end > max_low_pfn)
  410. end = max_low_pfn;
  411. /*
  412. * ... finally, is the area going away?
  413. */
  414. if (end <= start)
  415. continue;
  416. #endif
  417. memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
  418. }
  419. /*
  420. * Register fully available low RAM pages with the bootmem allocator.
  421. */
  422. for (i = 0; i < boot_mem_map.nr_map; i++) {
  423. unsigned long start, end, size;
  424. start = PFN_UP(boot_mem_map.map[i].addr);
  425. end = PFN_DOWN(boot_mem_map.map[i].addr
  426. + boot_mem_map.map[i].size);
  427. /*
  428. * Reserve usable memory.
  429. */
  430. switch (boot_mem_map.map[i].type) {
  431. case BOOT_MEM_RAM:
  432. break;
  433. case BOOT_MEM_INIT_RAM:
  434. memory_present(0, start, end);
  435. continue;
  436. default:
  437. /* Not usable memory */
  438. if (start > min_low_pfn && end < max_low_pfn)
  439. memblock_reserve(boot_mem_map.map[i].addr,
  440. boot_mem_map.map[i].size);
  441. continue;
  442. }
  443. /*
  444. * We are rounding up the start address of usable memory
  445. * and at the end of the usable range downwards.
  446. */
  447. if (start >= max_low_pfn)
  448. continue;
  449. if (start < reserved_end)
  450. start = reserved_end;
  451. if (end > max_low_pfn)
  452. end = max_low_pfn;
  453. /*
  454. * ... finally, is the area going away?
  455. */
  456. if (end <= start)
  457. continue;
  458. size = end - start;
  459. /* Register lowmem ranges */
  460. memory_present(0, start, end);
  461. }
  462. #ifdef CONFIG_RELOCATABLE
  463. /*
  464. * The kernel reserves all memory below its _end symbol as bootmem,
  465. * but the kernel may now be at a much higher address. The memory
  466. * between the original and new locations may be returned to the system.
  467. */
  468. if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
  469. unsigned long offset;
  470. extern void show_kernel_relocation(const char *level);
  471. offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
  472. free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
  473. #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
  474. /*
  475. * This information is necessary when debugging the kernel
  476. * But is a security vulnerability otherwise!
  477. */
  478. show_kernel_relocation(KERN_INFO);
  479. #endif
  480. }
  481. #endif
  482. /*
  483. * Reserve initrd memory if needed.
  484. */
  485. finalize_initrd();
  486. }
  487. #endif /* CONFIG_SGI_IP27 */
  488. static int usermem __initdata;
  489. static int __init early_parse_mem(char *p)
  490. {
  491. phys_addr_t start, size;
  492. /*
  493. * If a user specifies memory size, we
  494. * blow away any automatically generated
  495. * size.
  496. */
  497. if (usermem == 0) {
  498. boot_mem_map.nr_map = 0;
  499. usermem = 1;
  500. }
  501. start = 0;
  502. size = memparse(p, &p);
  503. if (*p == '@')
  504. start = memparse(p + 1, &p);
  505. add_memory_region(start, size, BOOT_MEM_RAM);
  506. return 0;
  507. }
  508. early_param("mem", early_parse_mem);
  509. static int __init early_parse_memmap(char *p)
  510. {
  511. char *oldp;
  512. u64 start_at, mem_size;
  513. if (!p)
  514. return -EINVAL;
  515. if (!strncmp(p, "exactmap", 8)) {
  516. pr_err("\"memmap=exactmap\" invalid on MIPS\n");
  517. return 0;
  518. }
  519. oldp = p;
  520. mem_size = memparse(p, &p);
  521. if (p == oldp)
  522. return -EINVAL;
  523. if (*p == '@') {
  524. start_at = memparse(p+1, &p);
  525. add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
  526. } else if (*p == '#') {
  527. pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
  528. return -EINVAL;
  529. } else if (*p == '$') {
  530. start_at = memparse(p+1, &p);
  531. add_memory_region(start_at, mem_size, BOOT_MEM_RESERVED);
  532. } else {
  533. pr_err("\"memmap\" invalid format!\n");
  534. return -EINVAL;
  535. }
  536. if (*p == '\0') {
  537. usermem = 1;
  538. return 0;
  539. } else
  540. return -EINVAL;
  541. }
  542. early_param("memmap", early_parse_memmap);
  543. #ifdef CONFIG_PROC_VMCORE
  544. unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
  545. static int __init early_parse_elfcorehdr(char *p)
  546. {
  547. int i;
  548. setup_elfcorehdr = memparse(p, &p);
  549. for (i = 0; i < boot_mem_map.nr_map; i++) {
  550. unsigned long start = boot_mem_map.map[i].addr;
  551. unsigned long end = (boot_mem_map.map[i].addr +
  552. boot_mem_map.map[i].size);
  553. if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
  554. /*
  555. * Reserve from the elf core header to the end of
  556. * the memory segment, that should all be kdump
  557. * reserved memory.
  558. */
  559. setup_elfcorehdr_size = end - setup_elfcorehdr;
  560. break;
  561. }
  562. }
  563. /*
  564. * If we don't find it in the memory map, then we shouldn't
  565. * have to worry about it, as the new kernel won't use it.
  566. */
  567. return 0;
  568. }
  569. early_param("elfcorehdr", early_parse_elfcorehdr);
  570. #endif
  571. static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
  572. {
  573. phys_addr_t size;
  574. int i;
  575. size = end - mem;
  576. if (!size)
  577. return;
  578. /* Make sure it is in the boot_mem_map */
  579. for (i = 0; i < boot_mem_map.nr_map; i++) {
  580. if (mem >= boot_mem_map.map[i].addr &&
  581. mem < (boot_mem_map.map[i].addr +
  582. boot_mem_map.map[i].size))
  583. return;
  584. }
  585. add_memory_region(mem, size, type);
  586. }
  587. #ifdef CONFIG_KEXEC
  588. static inline unsigned long long get_total_mem(void)
  589. {
  590. unsigned long long total;
  591. total = max_pfn - min_low_pfn;
  592. return total << PAGE_SHIFT;
  593. }
  594. static void __init mips_parse_crashkernel(void)
  595. {
  596. unsigned long long total_mem;
  597. unsigned long long crash_size, crash_base;
  598. int ret;
  599. total_mem = get_total_mem();
  600. ret = parse_crashkernel(boot_command_line, total_mem,
  601. &crash_size, &crash_base);
  602. if (ret != 0 || crash_size <= 0)
  603. return;
  604. if (!memory_region_available(crash_base, crash_size)) {
  605. pr_warn("Invalid memory region reserved for crash kernel\n");
  606. return;
  607. }
  608. crashk_res.start = crash_base;
  609. crashk_res.end = crash_base + crash_size - 1;
  610. }
  611. static void __init request_crashkernel(struct resource *res)
  612. {
  613. int ret;
  614. if (crashk_res.start == crashk_res.end)
  615. return;
  616. ret = request_resource(res, &crashk_res);
  617. if (!ret)
  618. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
  619. (unsigned long)((crashk_res.end -
  620. crashk_res.start + 1) >> 20),
  621. (unsigned long)(crashk_res.start >> 20));
  622. }
  623. #else /* !defined(CONFIG_KEXEC) */
  624. static void __init mips_parse_crashkernel(void)
  625. {
  626. }
  627. static void __init request_crashkernel(struct resource *res)
  628. {
  629. }
  630. #endif /* !defined(CONFIG_KEXEC) */
  631. #define USE_PROM_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER)
  632. #define USE_DTB_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB)
  633. #define EXTEND_WITH_PROM IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND)
  634. #define BUILTIN_EXTEND_WITH_PROM \
  635. IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND)
  636. /*
  637. * arch_mem_init - initialize memory management subsystem
  638. *
  639. * o plat_mem_setup() detects the memory configuration and will record detected
  640. * memory areas using add_memory_region.
  641. *
  642. * At this stage the memory configuration of the system is known to the
  643. * kernel but generic memory management system is still entirely uninitialized.
  644. *
  645. * o bootmem_init()
  646. * o sparse_init()
  647. * o paging_init()
  648. * o dma_contiguous_reserve()
  649. *
  650. * At this stage the bootmem allocator is ready to use.
  651. *
  652. * NOTE: historically plat_mem_setup did the entire platform initialization.
  653. * This was rather impractical because it meant plat_mem_setup had to
  654. * get away without any kind of memory allocator. To keep old code from
  655. * breaking plat_setup was just renamed to plat_mem_setup and a second platform
  656. * initialization hook for anything else was introduced.
  657. */
  658. static void __init arch_mem_init(char **cmdline_p)
  659. {
  660. struct memblock_region *reg;
  661. extern void plat_mem_setup(void);
  662. /*
  663. * Initialize boot_command_line to an innocuous but non-empty string in
  664. * order to prevent early_init_dt_scan_chosen() from copying
  665. * CONFIG_CMDLINE into it without our knowledge. We handle
  666. * CONFIG_CMDLINE ourselves below & don't want to duplicate its
  667. * content because repeating arguments can be problematic.
  668. */
  669. strlcpy(boot_command_line, " ", COMMAND_LINE_SIZE);
  670. /* call board setup routine */
  671. plat_mem_setup();
  672. /*
  673. * Make sure all kernel memory is in the maps. The "UP" and
  674. * "DOWN" are opposite for initdata since if it crosses over
  675. * into another memory section you don't want that to be
  676. * freed when the initdata is freed.
  677. */
  678. arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
  679. PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
  680. BOOT_MEM_RAM);
  681. arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
  682. PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
  683. BOOT_MEM_INIT_RAM);
  684. pr_info("Determined physical RAM map:\n");
  685. print_memory_map();
  686. #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
  687. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  688. #else
  689. if ((USE_PROM_CMDLINE && arcs_cmdline[0]) ||
  690. (USE_DTB_CMDLINE && !boot_command_line[0]))
  691. strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  692. if (EXTEND_WITH_PROM && arcs_cmdline[0]) {
  693. if (boot_command_line[0])
  694. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  695. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  696. }
  697. #if defined(CONFIG_CMDLINE_BOOL)
  698. if (builtin_cmdline[0]) {
  699. if (boot_command_line[0])
  700. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  701. strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  702. }
  703. if (BUILTIN_EXTEND_WITH_PROM && arcs_cmdline[0]) {
  704. if (boot_command_line[0])
  705. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  706. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  707. }
  708. #endif
  709. #endif
  710. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  711. *cmdline_p = command_line;
  712. parse_early_param();
  713. if (usermem) {
  714. pr_info("User-defined physical RAM map:\n");
  715. print_memory_map();
  716. }
  717. early_init_fdt_reserve_self();
  718. early_init_fdt_scan_reserved_mem();
  719. bootmem_init();
  720. /*
  721. * Prevent memblock from allocating high memory.
  722. * This cannot be done before max_low_pfn is detected, so up
  723. * to this point is possible to only reserve physical memory
  724. * with memblock_reserve; memblock_alloc* can be used
  725. * only after this point
  726. */
  727. memblock_set_current_limit(PFN_PHYS(max_low_pfn));
  728. #ifdef CONFIG_PROC_VMCORE
  729. if (setup_elfcorehdr && setup_elfcorehdr_size) {
  730. printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
  731. setup_elfcorehdr, setup_elfcorehdr_size);
  732. memblock_reserve(setup_elfcorehdr, setup_elfcorehdr_size);
  733. }
  734. #endif
  735. mips_parse_crashkernel();
  736. #ifdef CONFIG_KEXEC
  737. if (crashk_res.start != crashk_res.end)
  738. memblock_reserve(crashk_res.start,
  739. crashk_res.end - crashk_res.start + 1);
  740. #endif
  741. device_tree_init();
  742. sparse_init();
  743. plat_swiotlb_setup();
  744. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  745. /* Tell bootmem about cma reserved memblock section */
  746. for_each_memblock(reserved, reg)
  747. if (reg->size != 0)
  748. memblock_reserve(reg->base, reg->size);
  749. reserve_bootmem_region(__pa_symbol(&__nosave_begin),
  750. __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
  751. }
  752. static void __init resource_init(void)
  753. {
  754. int i;
  755. if (UNCAC_BASE != IO_BASE)
  756. return;
  757. code_resource.start = __pa_symbol(&_text);
  758. code_resource.end = __pa_symbol(&_etext) - 1;
  759. data_resource.start = __pa_symbol(&_etext);
  760. data_resource.end = __pa_symbol(&_edata) - 1;
  761. bss_resource.start = __pa_symbol(&__bss_start);
  762. bss_resource.end = __pa_symbol(&__bss_stop) - 1;
  763. for (i = 0; i < boot_mem_map.nr_map; i++) {
  764. struct resource *res;
  765. unsigned long start, end;
  766. start = boot_mem_map.map[i].addr;
  767. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  768. if (start >= HIGHMEM_START)
  769. continue;
  770. if (end >= HIGHMEM_START)
  771. end = HIGHMEM_START - 1;
  772. res = memblock_alloc(sizeof(struct resource), 0);
  773. res->start = start;
  774. res->end = end;
  775. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  776. switch (boot_mem_map.map[i].type) {
  777. case BOOT_MEM_RAM:
  778. case BOOT_MEM_INIT_RAM:
  779. case BOOT_MEM_ROM_DATA:
  780. res->name = "System RAM";
  781. res->flags |= IORESOURCE_SYSRAM;
  782. break;
  783. case BOOT_MEM_RESERVED:
  784. default:
  785. res->name = "reserved";
  786. }
  787. request_resource(&iomem_resource, res);
  788. /*
  789. * We don't know which RAM region contains kernel data,
  790. * so we try it repeatedly and let the resource manager
  791. * test it.
  792. */
  793. request_resource(res, &code_resource);
  794. request_resource(res, &data_resource);
  795. request_resource(res, &bss_resource);
  796. request_crashkernel(res);
  797. }
  798. }
  799. #ifdef CONFIG_SMP
  800. static void __init prefill_possible_map(void)
  801. {
  802. int i, possible = num_possible_cpus();
  803. if (possible > nr_cpu_ids)
  804. possible = nr_cpu_ids;
  805. for (i = 0; i < possible; i++)
  806. set_cpu_possible(i, true);
  807. for (; i < NR_CPUS; i++)
  808. set_cpu_possible(i, false);
  809. nr_cpu_ids = possible;
  810. }
  811. #else
  812. static inline void prefill_possible_map(void) {}
  813. #endif
  814. void __init setup_arch(char **cmdline_p)
  815. {
  816. cpu_probe();
  817. mips_cm_probe();
  818. prom_init();
  819. setup_early_fdc_console();
  820. #ifdef CONFIG_EARLY_PRINTK
  821. setup_early_printk();
  822. #endif
  823. cpu_report();
  824. check_bugs_early();
  825. #if defined(CONFIG_VT)
  826. #if defined(CONFIG_VGA_CONSOLE)
  827. conswitchp = &vga_con;
  828. #elif defined(CONFIG_DUMMY_CONSOLE)
  829. conswitchp = &dummy_con;
  830. #endif
  831. #endif
  832. arch_mem_init(cmdline_p);
  833. resource_init();
  834. plat_smp_setup();
  835. prefill_possible_map();
  836. cpu_cache_init();
  837. paging_init();
  838. }
  839. unsigned long kernelsp[NR_CPUS];
  840. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  841. #ifdef CONFIG_USE_OF
  842. unsigned long fw_passed_dtb;
  843. #endif
  844. #ifdef CONFIG_DEBUG_FS
  845. struct dentry *mips_debugfs_dir;
  846. static int __init debugfs_mips(void)
  847. {
  848. struct dentry *d;
  849. d = debugfs_create_dir("mips", NULL);
  850. if (!d)
  851. return -ENOMEM;
  852. mips_debugfs_dir = d;
  853. return 0;
  854. }
  855. arch_initcall(debugfs_mips);
  856. #endif
  857. #ifdef CONFIG_DMA_MAYBE_COHERENT
  858. /* User defined DMA coherency from command line. */
  859. enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT;
  860. EXPORT_SYMBOL_GPL(coherentio);
  861. int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
  862. static int __init setcoherentio(char *str)
  863. {
  864. coherentio = IO_COHERENCE_ENABLED;
  865. pr_info("Hardware DMA cache coherency (command line)\n");
  866. return 0;
  867. }
  868. early_param("coherentio", setcoherentio);
  869. static int __init setnocoherentio(char *str)
  870. {
  871. coherentio = IO_COHERENCE_DISABLED;
  872. pr_info("Software DMA cache coherency (command line)\n");
  873. return 0;
  874. }
  875. early_param("nocoherentio", setnocoherentio);
  876. #endif