setup.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
  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 unsigned long __init bootmap_bytes(unsigned long pages)
  310. {
  311. unsigned long bytes = DIV_ROUND_UP(pages, 8);
  312. return ALIGN(bytes, sizeof(long));
  313. }
  314. static void __init bootmem_init(void)
  315. {
  316. unsigned long reserved_end;
  317. unsigned long mapstart = ~0UL;
  318. unsigned long bootmap_size;
  319. phys_addr_t ramstart = PHYS_ADDR_MAX;
  320. bool bootmap_valid = false;
  321. int i;
  322. /*
  323. * Sanity check any INITRD first. We don't take it into account
  324. * for bootmem setup initially, rely on the end-of-kernel-code
  325. * as our memory range starting point. Once bootmem is inited we
  326. * will reserve the area used for the initrd.
  327. */
  328. init_initrd();
  329. reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
  330. /*
  331. * max_low_pfn is not a number of pages. The number of pages
  332. * of the system is given by 'max_low_pfn - min_low_pfn'.
  333. */
  334. min_low_pfn = ~0UL;
  335. max_low_pfn = 0;
  336. /*
  337. * Find the highest page frame number we have available
  338. * and the lowest used RAM address
  339. */
  340. for (i = 0; i < boot_mem_map.nr_map; i++) {
  341. unsigned long start, end;
  342. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  343. continue;
  344. start = PFN_UP(boot_mem_map.map[i].addr);
  345. end = PFN_DOWN(boot_mem_map.map[i].addr
  346. + boot_mem_map.map[i].size);
  347. ramstart = min(ramstart, boot_mem_map.map[i].addr);
  348. #ifndef CONFIG_HIGHMEM
  349. /*
  350. * Skip highmem here so we get an accurate max_low_pfn if low
  351. * memory stops short of high memory.
  352. * If the region overlaps HIGHMEM_START, end is clipped so
  353. * max_pfn excludes the highmem portion.
  354. */
  355. if (start >= PFN_DOWN(HIGHMEM_START))
  356. continue;
  357. if (end > PFN_DOWN(HIGHMEM_START))
  358. end = PFN_DOWN(HIGHMEM_START);
  359. #endif
  360. if (end > max_low_pfn)
  361. max_low_pfn = end;
  362. if (start < min_low_pfn)
  363. min_low_pfn = start;
  364. if (end <= reserved_end)
  365. continue;
  366. #ifdef CONFIG_BLK_DEV_INITRD
  367. /* Skip zones before initrd and initrd itself */
  368. if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
  369. continue;
  370. #endif
  371. if (start >= mapstart)
  372. continue;
  373. mapstart = max(reserved_end, start);
  374. }
  375. if (min_low_pfn >= max_low_pfn)
  376. panic("Incorrect memory mapping !!!");
  377. #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
  378. ARCH_PFN_OFFSET = PFN_UP(ramstart);
  379. #else
  380. /*
  381. * Reserve any memory between the start of RAM and PHYS_OFFSET
  382. */
  383. if (ramstart > PHYS_OFFSET)
  384. add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
  385. BOOT_MEM_RESERVED);
  386. if (min_low_pfn > ARCH_PFN_OFFSET) {
  387. pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
  388. (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
  389. min_low_pfn - ARCH_PFN_OFFSET);
  390. } else if (ARCH_PFN_OFFSET - min_low_pfn > 0UL) {
  391. pr_info("%lu free pages won't be used\n",
  392. ARCH_PFN_OFFSET - min_low_pfn);
  393. }
  394. min_low_pfn = ARCH_PFN_OFFSET;
  395. #endif
  396. /*
  397. * Determine low and high memory ranges
  398. */
  399. max_pfn = max_low_pfn;
  400. if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
  401. #ifdef CONFIG_HIGHMEM
  402. highstart_pfn = PFN_DOWN(HIGHMEM_START);
  403. highend_pfn = max_low_pfn;
  404. #endif
  405. max_low_pfn = PFN_DOWN(HIGHMEM_START);
  406. }
  407. #ifdef CONFIG_BLK_DEV_INITRD
  408. /*
  409. * mapstart should be after initrd_end
  410. */
  411. if (initrd_end)
  412. mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
  413. #endif
  414. /*
  415. * check that mapstart doesn't overlap with any of
  416. * memory regions that have been reserved through eg. DTB
  417. */
  418. bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
  419. bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
  420. bootmap_size);
  421. for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
  422. unsigned long mapstart_addr;
  423. switch (boot_mem_map.map[i].type) {
  424. case BOOT_MEM_RESERVED:
  425. mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
  426. boot_mem_map.map[i].size);
  427. if (PHYS_PFN(mapstart_addr) < mapstart)
  428. break;
  429. bootmap_valid = memory_region_available(mapstart_addr,
  430. bootmap_size);
  431. if (bootmap_valid)
  432. mapstart = PHYS_PFN(mapstart_addr);
  433. break;
  434. default:
  435. break;
  436. }
  437. }
  438. if (!bootmap_valid)
  439. panic("No memory area to place a bootmap bitmap");
  440. /*
  441. * Initialize the boot-time allocator with low memory only.
  442. */
  443. if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
  444. min_low_pfn, max_low_pfn))
  445. panic("Unexpected memory size required for bootmap");
  446. for (i = 0; i < boot_mem_map.nr_map; i++) {
  447. unsigned long start, end;
  448. start = PFN_UP(boot_mem_map.map[i].addr);
  449. end = PFN_DOWN(boot_mem_map.map[i].addr
  450. + boot_mem_map.map[i].size);
  451. if (start <= min_low_pfn)
  452. start = min_low_pfn;
  453. if (start >= end)
  454. continue;
  455. #ifndef CONFIG_HIGHMEM
  456. if (end > max_low_pfn)
  457. end = max_low_pfn;
  458. /*
  459. * ... finally, is the area going away?
  460. */
  461. if (end <= start)
  462. continue;
  463. #endif
  464. memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
  465. }
  466. /*
  467. * Register fully available low RAM pages with the bootmem allocator.
  468. */
  469. for (i = 0; i < boot_mem_map.nr_map; i++) {
  470. unsigned long start, end, size;
  471. start = PFN_UP(boot_mem_map.map[i].addr);
  472. end = PFN_DOWN(boot_mem_map.map[i].addr
  473. + boot_mem_map.map[i].size);
  474. /*
  475. * Reserve usable memory.
  476. */
  477. switch (boot_mem_map.map[i].type) {
  478. case BOOT_MEM_RAM:
  479. break;
  480. case BOOT_MEM_INIT_RAM:
  481. memory_present(0, start, end);
  482. continue;
  483. default:
  484. /* Not usable memory */
  485. if (start > min_low_pfn && end < max_low_pfn)
  486. reserve_bootmem(boot_mem_map.map[i].addr,
  487. boot_mem_map.map[i].size,
  488. BOOTMEM_DEFAULT);
  489. continue;
  490. }
  491. /*
  492. * We are rounding up the start address of usable memory
  493. * and at the end of the usable range downwards.
  494. */
  495. if (start >= max_low_pfn)
  496. continue;
  497. if (start < reserved_end)
  498. start = reserved_end;
  499. if (end > max_low_pfn)
  500. end = max_low_pfn;
  501. /*
  502. * ... finally, is the area going away?
  503. */
  504. if (end <= start)
  505. continue;
  506. size = end - start;
  507. /* Register lowmem ranges */
  508. free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
  509. memory_present(0, start, end);
  510. }
  511. /*
  512. * Reserve the bootmap memory.
  513. */
  514. reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
  515. #ifdef CONFIG_RELOCATABLE
  516. /*
  517. * The kernel reserves all memory below its _end symbol as bootmem,
  518. * but the kernel may now be at a much higher address. The memory
  519. * between the original and new locations may be returned to the system.
  520. */
  521. if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
  522. unsigned long offset;
  523. extern void show_kernel_relocation(const char *level);
  524. offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
  525. free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
  526. #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
  527. /*
  528. * This information is necessary when debugging the kernel
  529. * But is a security vulnerability otherwise!
  530. */
  531. show_kernel_relocation(KERN_INFO);
  532. #endif
  533. }
  534. #endif
  535. /*
  536. * Reserve initrd memory if needed.
  537. */
  538. finalize_initrd();
  539. }
  540. #endif /* CONFIG_SGI_IP27 */
  541. /*
  542. * arch_mem_init - initialize memory management subsystem
  543. *
  544. * o plat_mem_setup() detects the memory configuration and will record detected
  545. * memory areas using add_memory_region.
  546. *
  547. * At this stage the memory configuration of the system is known to the
  548. * kernel but generic memory management system is still entirely uninitialized.
  549. *
  550. * o bootmem_init()
  551. * o sparse_init()
  552. * o paging_init()
  553. * o dma_contiguous_reserve()
  554. *
  555. * At this stage the bootmem allocator is ready to use.
  556. *
  557. * NOTE: historically plat_mem_setup did the entire platform initialization.
  558. * This was rather impractical because it meant plat_mem_setup had to
  559. * get away without any kind of memory allocator. To keep old code from
  560. * breaking plat_setup was just renamed to plat_mem_setup and a second platform
  561. * initialization hook for anything else was introduced.
  562. */
  563. static int usermem __initdata;
  564. static int __init early_parse_mem(char *p)
  565. {
  566. phys_addr_t start, size;
  567. /*
  568. * If a user specifies memory size, we
  569. * blow away any automatically generated
  570. * size.
  571. */
  572. if (usermem == 0) {
  573. boot_mem_map.nr_map = 0;
  574. usermem = 1;
  575. }
  576. start = 0;
  577. size = memparse(p, &p);
  578. if (*p == '@')
  579. start = memparse(p + 1, &p);
  580. add_memory_region(start, size, BOOT_MEM_RAM);
  581. return 0;
  582. }
  583. early_param("mem", early_parse_mem);
  584. static int __init early_parse_memmap(char *p)
  585. {
  586. char *oldp;
  587. u64 start_at, mem_size;
  588. if (!p)
  589. return -EINVAL;
  590. if (!strncmp(p, "exactmap", 8)) {
  591. pr_err("\"memmap=exactmap\" invalid on MIPS\n");
  592. return 0;
  593. }
  594. oldp = p;
  595. mem_size = memparse(p, &p);
  596. if (p == oldp)
  597. return -EINVAL;
  598. if (*p == '@') {
  599. start_at = memparse(p+1, &p);
  600. add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
  601. } else if (*p == '#') {
  602. pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
  603. return -EINVAL;
  604. } else if (*p == '$') {
  605. start_at = memparse(p+1, &p);
  606. add_memory_region(start_at, mem_size, BOOT_MEM_RESERVED);
  607. } else {
  608. pr_err("\"memmap\" invalid format!\n");
  609. return -EINVAL;
  610. }
  611. if (*p == '\0') {
  612. usermem = 1;
  613. return 0;
  614. } else
  615. return -EINVAL;
  616. }
  617. early_param("memmap", early_parse_memmap);
  618. #ifdef CONFIG_PROC_VMCORE
  619. unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
  620. static int __init early_parse_elfcorehdr(char *p)
  621. {
  622. int i;
  623. setup_elfcorehdr = memparse(p, &p);
  624. for (i = 0; i < boot_mem_map.nr_map; i++) {
  625. unsigned long start = boot_mem_map.map[i].addr;
  626. unsigned long end = (boot_mem_map.map[i].addr +
  627. boot_mem_map.map[i].size);
  628. if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
  629. /*
  630. * Reserve from the elf core header to the end of
  631. * the memory segment, that should all be kdump
  632. * reserved memory.
  633. */
  634. setup_elfcorehdr_size = end - setup_elfcorehdr;
  635. break;
  636. }
  637. }
  638. /*
  639. * If we don't find it in the memory map, then we shouldn't
  640. * have to worry about it, as the new kernel won't use it.
  641. */
  642. return 0;
  643. }
  644. early_param("elfcorehdr", early_parse_elfcorehdr);
  645. #endif
  646. static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
  647. {
  648. phys_addr_t size;
  649. int i;
  650. size = end - mem;
  651. if (!size)
  652. return;
  653. /* Make sure it is in the boot_mem_map */
  654. for (i = 0; i < boot_mem_map.nr_map; i++) {
  655. if (mem >= boot_mem_map.map[i].addr &&
  656. mem < (boot_mem_map.map[i].addr +
  657. boot_mem_map.map[i].size))
  658. return;
  659. }
  660. add_memory_region(mem, size, type);
  661. }
  662. #ifdef CONFIG_KEXEC
  663. static inline unsigned long long get_total_mem(void)
  664. {
  665. unsigned long long total;
  666. total = max_pfn - min_low_pfn;
  667. return total << PAGE_SHIFT;
  668. }
  669. static void __init mips_parse_crashkernel(void)
  670. {
  671. unsigned long long total_mem;
  672. unsigned long long crash_size, crash_base;
  673. int ret;
  674. total_mem = get_total_mem();
  675. ret = parse_crashkernel(boot_command_line, total_mem,
  676. &crash_size, &crash_base);
  677. if (ret != 0 || crash_size <= 0)
  678. return;
  679. if (!memory_region_available(crash_base, crash_size)) {
  680. pr_warn("Invalid memory region reserved for crash kernel\n");
  681. return;
  682. }
  683. crashk_res.start = crash_base;
  684. crashk_res.end = crash_base + crash_size - 1;
  685. }
  686. static void __init request_crashkernel(struct resource *res)
  687. {
  688. int ret;
  689. if (crashk_res.start == crashk_res.end)
  690. return;
  691. ret = request_resource(res, &crashk_res);
  692. if (!ret)
  693. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
  694. (unsigned long)((crashk_res.end -
  695. crashk_res.start + 1) >> 20),
  696. (unsigned long)(crashk_res.start >> 20));
  697. }
  698. #else /* !defined(CONFIG_KEXEC) */
  699. static void __init mips_parse_crashkernel(void)
  700. {
  701. }
  702. static void __init request_crashkernel(struct resource *res)
  703. {
  704. }
  705. #endif /* !defined(CONFIG_KEXEC) */
  706. #define USE_PROM_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER)
  707. #define USE_DTB_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB)
  708. #define EXTEND_WITH_PROM IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND)
  709. #define BUILTIN_EXTEND_WITH_PROM \
  710. IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND)
  711. static void __init arch_mem_init(char **cmdline_p)
  712. {
  713. struct memblock_region *reg;
  714. extern void plat_mem_setup(void);
  715. /*
  716. * Initialize boot_command_line to an innocuous but non-empty string in
  717. * order to prevent early_init_dt_scan_chosen() from copying
  718. * CONFIG_CMDLINE into it without our knowledge. We handle
  719. * CONFIG_CMDLINE ourselves below & don't want to duplicate its
  720. * content because repeating arguments can be problematic.
  721. */
  722. strlcpy(boot_command_line, " ", COMMAND_LINE_SIZE);
  723. /* call board setup routine */
  724. plat_mem_setup();
  725. /*
  726. * Make sure all kernel memory is in the maps. The "UP" and
  727. * "DOWN" are opposite for initdata since if it crosses over
  728. * into another memory section you don't want that to be
  729. * freed when the initdata is freed.
  730. */
  731. arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
  732. PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
  733. BOOT_MEM_RAM);
  734. arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
  735. PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
  736. BOOT_MEM_INIT_RAM);
  737. pr_info("Determined physical RAM map:\n");
  738. print_memory_map();
  739. #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
  740. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  741. #else
  742. if ((USE_PROM_CMDLINE && arcs_cmdline[0]) ||
  743. (USE_DTB_CMDLINE && !boot_command_line[0]))
  744. strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  745. if (EXTEND_WITH_PROM && arcs_cmdline[0]) {
  746. if (boot_command_line[0])
  747. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  748. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  749. }
  750. #if defined(CONFIG_CMDLINE_BOOL)
  751. if (builtin_cmdline[0]) {
  752. if (boot_command_line[0])
  753. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  754. strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  755. }
  756. if (BUILTIN_EXTEND_WITH_PROM && arcs_cmdline[0]) {
  757. if (boot_command_line[0])
  758. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  759. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  760. }
  761. #endif
  762. #endif
  763. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  764. *cmdline_p = command_line;
  765. parse_early_param();
  766. if (usermem) {
  767. pr_info("User-defined physical RAM map:\n");
  768. print_memory_map();
  769. }
  770. early_init_fdt_reserve_self();
  771. early_init_fdt_scan_reserved_mem();
  772. bootmem_init();
  773. #ifdef CONFIG_PROC_VMCORE
  774. if (setup_elfcorehdr && setup_elfcorehdr_size) {
  775. printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
  776. setup_elfcorehdr, setup_elfcorehdr_size);
  777. reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
  778. BOOTMEM_DEFAULT);
  779. }
  780. #endif
  781. mips_parse_crashkernel();
  782. #ifdef CONFIG_KEXEC
  783. if (crashk_res.start != crashk_res.end)
  784. reserve_bootmem(crashk_res.start,
  785. crashk_res.end - crashk_res.start + 1,
  786. BOOTMEM_DEFAULT);
  787. #endif
  788. device_tree_init();
  789. sparse_init();
  790. plat_swiotlb_setup();
  791. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  792. /* Tell bootmem about cma reserved memblock section */
  793. for_each_memblock(reserved, reg)
  794. if (reg->size != 0)
  795. reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
  796. reserve_bootmem_region(__pa_symbol(&__nosave_begin),
  797. __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
  798. }
  799. static void __init resource_init(void)
  800. {
  801. int i;
  802. if (UNCAC_BASE != IO_BASE)
  803. return;
  804. code_resource.start = __pa_symbol(&_text);
  805. code_resource.end = __pa_symbol(&_etext) - 1;
  806. data_resource.start = __pa_symbol(&_etext);
  807. data_resource.end = __pa_symbol(&_edata) - 1;
  808. bss_resource.start = __pa_symbol(&__bss_start);
  809. bss_resource.end = __pa_symbol(&__bss_stop) - 1;
  810. for (i = 0; i < boot_mem_map.nr_map; i++) {
  811. struct resource *res;
  812. unsigned long start, end;
  813. start = boot_mem_map.map[i].addr;
  814. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  815. if (start >= HIGHMEM_START)
  816. continue;
  817. if (end >= HIGHMEM_START)
  818. end = HIGHMEM_START - 1;
  819. res = alloc_bootmem(sizeof(struct resource));
  820. res->start = start;
  821. res->end = end;
  822. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  823. switch (boot_mem_map.map[i].type) {
  824. case BOOT_MEM_RAM:
  825. case BOOT_MEM_INIT_RAM:
  826. case BOOT_MEM_ROM_DATA:
  827. res->name = "System RAM";
  828. res->flags |= IORESOURCE_SYSRAM;
  829. break;
  830. case BOOT_MEM_RESERVED:
  831. default:
  832. res->name = "reserved";
  833. }
  834. request_resource(&iomem_resource, res);
  835. /*
  836. * We don't know which RAM region contains kernel data,
  837. * so we try it repeatedly and let the resource manager
  838. * test it.
  839. */
  840. request_resource(res, &code_resource);
  841. request_resource(res, &data_resource);
  842. request_resource(res, &bss_resource);
  843. request_crashkernel(res);
  844. }
  845. }
  846. #ifdef CONFIG_SMP
  847. static void __init prefill_possible_map(void)
  848. {
  849. int i, possible = num_possible_cpus();
  850. if (possible > nr_cpu_ids)
  851. possible = nr_cpu_ids;
  852. for (i = 0; i < possible; i++)
  853. set_cpu_possible(i, true);
  854. for (; i < NR_CPUS; i++)
  855. set_cpu_possible(i, false);
  856. nr_cpu_ids = possible;
  857. }
  858. #else
  859. static inline void prefill_possible_map(void) {}
  860. #endif
  861. void __init setup_arch(char **cmdline_p)
  862. {
  863. cpu_probe();
  864. mips_cm_probe();
  865. prom_init();
  866. setup_early_fdc_console();
  867. #ifdef CONFIG_EARLY_PRINTK
  868. setup_early_printk();
  869. #endif
  870. cpu_report();
  871. check_bugs_early();
  872. #if defined(CONFIG_VT)
  873. #if defined(CONFIG_VGA_CONSOLE)
  874. conswitchp = &vga_con;
  875. #elif defined(CONFIG_DUMMY_CONSOLE)
  876. conswitchp = &dummy_con;
  877. #endif
  878. #endif
  879. arch_mem_init(cmdline_p);
  880. resource_init();
  881. plat_smp_setup();
  882. prefill_possible_map();
  883. cpu_cache_init();
  884. paging_init();
  885. }
  886. unsigned long kernelsp[NR_CPUS];
  887. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  888. #ifdef CONFIG_USE_OF
  889. unsigned long fw_passed_dtb;
  890. #endif
  891. #ifdef CONFIG_DEBUG_FS
  892. struct dentry *mips_debugfs_dir;
  893. static int __init debugfs_mips(void)
  894. {
  895. struct dentry *d;
  896. d = debugfs_create_dir("mips", NULL);
  897. if (!d)
  898. return -ENOMEM;
  899. mips_debugfs_dir = d;
  900. return 0;
  901. }
  902. arch_initcall(debugfs_mips);
  903. #endif
  904. #if defined(CONFIG_DMA_MAYBE_COHERENT) && !defined(CONFIG_DMA_PERDEV_COHERENT)
  905. /* User defined DMA coherency from command line. */
  906. enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT;
  907. EXPORT_SYMBOL_GPL(coherentio);
  908. int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
  909. static int __init setcoherentio(char *str)
  910. {
  911. coherentio = IO_COHERENCE_ENABLED;
  912. pr_info("Hardware DMA cache coherency (command line)\n");
  913. return 0;
  914. }
  915. early_param("coherentio", setcoherentio);
  916. static int __init setnocoherentio(char *str)
  917. {
  918. coherentio = IO_COHERENCE_DISABLED;
  919. pr_info("Software DMA cache coherency (command line)\n");
  920. return 0;
  921. }
  922. early_param("nocoherentio", setnocoherentio);
  923. #endif