setup.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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. 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. /*
  790. * In order to reduce the possibility of kernel panic when failed to
  791. * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate
  792. * low memory as small as possible before plat_swiotlb_setup(), so
  793. * make sparse_init() using top-down allocation.
  794. */
  795. memblock_set_bottom_up(false);
  796. sparse_init();
  797. memblock_set_bottom_up(true);
  798. plat_swiotlb_setup();
  799. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  800. /* Tell bootmem about cma reserved memblock section */
  801. for_each_memblock(reserved, reg)
  802. if (reg->size != 0)
  803. reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
  804. reserve_bootmem_region(__pa_symbol(&__nosave_begin),
  805. __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
  806. }
  807. static void __init resource_init(void)
  808. {
  809. int i;
  810. if (UNCAC_BASE != IO_BASE)
  811. return;
  812. code_resource.start = __pa_symbol(&_text);
  813. code_resource.end = __pa_symbol(&_etext) - 1;
  814. data_resource.start = __pa_symbol(&_etext);
  815. data_resource.end = __pa_symbol(&_edata) - 1;
  816. bss_resource.start = __pa_symbol(&__bss_start);
  817. bss_resource.end = __pa_symbol(&__bss_stop) - 1;
  818. for (i = 0; i < boot_mem_map.nr_map; i++) {
  819. struct resource *res;
  820. unsigned long start, end;
  821. start = boot_mem_map.map[i].addr;
  822. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  823. if (start >= HIGHMEM_START)
  824. continue;
  825. if (end >= HIGHMEM_START)
  826. end = HIGHMEM_START - 1;
  827. res = alloc_bootmem(sizeof(struct resource));
  828. res->start = start;
  829. res->end = end;
  830. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  831. switch (boot_mem_map.map[i].type) {
  832. case BOOT_MEM_RAM:
  833. case BOOT_MEM_INIT_RAM:
  834. case BOOT_MEM_ROM_DATA:
  835. res->name = "System RAM";
  836. res->flags |= IORESOURCE_SYSRAM;
  837. break;
  838. case BOOT_MEM_RESERVED:
  839. default:
  840. res->name = "reserved";
  841. }
  842. request_resource(&iomem_resource, res);
  843. /*
  844. * We don't know which RAM region contains kernel data,
  845. * so we try it repeatedly and let the resource manager
  846. * test it.
  847. */
  848. request_resource(res, &code_resource);
  849. request_resource(res, &data_resource);
  850. request_resource(res, &bss_resource);
  851. request_crashkernel(res);
  852. }
  853. }
  854. #ifdef CONFIG_SMP
  855. static void __init prefill_possible_map(void)
  856. {
  857. int i, possible = num_possible_cpus();
  858. if (possible > nr_cpu_ids)
  859. possible = nr_cpu_ids;
  860. for (i = 0; i < possible; i++)
  861. set_cpu_possible(i, true);
  862. for (; i < NR_CPUS; i++)
  863. set_cpu_possible(i, false);
  864. nr_cpu_ids = possible;
  865. }
  866. #else
  867. static inline void prefill_possible_map(void) {}
  868. #endif
  869. void __init setup_arch(char **cmdline_p)
  870. {
  871. cpu_probe();
  872. mips_cm_probe();
  873. prom_init();
  874. setup_early_fdc_console();
  875. #ifdef CONFIG_EARLY_PRINTK
  876. setup_early_printk();
  877. #endif
  878. cpu_report();
  879. check_bugs_early();
  880. #if defined(CONFIG_VT)
  881. #if defined(CONFIG_VGA_CONSOLE)
  882. conswitchp = &vga_con;
  883. #elif defined(CONFIG_DUMMY_CONSOLE)
  884. conswitchp = &dummy_con;
  885. #endif
  886. #endif
  887. arch_mem_init(cmdline_p);
  888. resource_init();
  889. plat_smp_setup();
  890. prefill_possible_map();
  891. cpu_cache_init();
  892. paging_init();
  893. }
  894. unsigned long kernelsp[NR_CPUS];
  895. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  896. #ifdef CONFIG_USE_OF
  897. unsigned long fw_passed_dtb;
  898. #endif
  899. #ifdef CONFIG_DEBUG_FS
  900. struct dentry *mips_debugfs_dir;
  901. static int __init debugfs_mips(void)
  902. {
  903. struct dentry *d;
  904. d = debugfs_create_dir("mips", NULL);
  905. if (!d)
  906. return -ENOMEM;
  907. mips_debugfs_dir = d;
  908. return 0;
  909. }
  910. arch_initcall(debugfs_mips);
  911. #endif
  912. #if defined(CONFIG_DMA_MAYBE_COHERENT) && !defined(CONFIG_DMA_PERDEV_COHERENT)
  913. /* User defined DMA coherency from command line. */
  914. enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT;
  915. EXPORT_SYMBOL_GPL(coherentio);
  916. int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
  917. static int __init setcoherentio(char *str)
  918. {
  919. coherentio = IO_COHERENCE_ENABLED;
  920. pr_info("Hardware DMA cache coherency (command line)\n");
  921. return 0;
  922. }
  923. early_param("coherentio", setcoherentio);
  924. static int __init setnocoherentio(char *str)
  925. {
  926. coherentio = IO_COHERENCE_DISABLED;
  927. pr_info("Software DMA cache coherency (command line)\n");
  928. return 0;
  929. }
  930. early_param("nocoherentio", setnocoherentio);
  931. #endif