init.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /*
  2. * linux/arch/arm/mm/init.c
  3. *
  4. * Copyright (C) 1995-2005 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/swap.h>
  13. #include <linux/init.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/mman.h>
  16. #include <linux/export.h>
  17. #include <linux/nodemask.h>
  18. #include <linux/initrd.h>
  19. #include <linux/of_fdt.h>
  20. #include <linux/of_reserved_mem.h>
  21. #include <linux/highmem.h>
  22. #include <linux/gfp.h>
  23. #include <linux/memblock.h>
  24. #include <linux/dma-contiguous.h>
  25. #include <linux/sizes.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/memblock.h>
  28. #include <asm/prom.h>
  29. #include <asm/sections.h>
  30. #include <asm/setup.h>
  31. #include <asm/tlb.h>
  32. #include <asm/fixmap.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/map.h>
  35. #include "mm.h"
  36. static phys_addr_t phys_initrd_start __initdata = 0;
  37. static unsigned long phys_initrd_size __initdata = 0;
  38. static int __init early_initrd(char *p)
  39. {
  40. phys_addr_t start;
  41. unsigned long size;
  42. char *endp;
  43. start = memparse(p, &endp);
  44. if (*endp == ',') {
  45. size = memparse(endp + 1, NULL);
  46. phys_initrd_start = start;
  47. phys_initrd_size = size;
  48. }
  49. return 0;
  50. }
  51. early_param("initrd", early_initrd);
  52. static int __init parse_tag_initrd(const struct tag *tag)
  53. {
  54. printk(KERN_WARNING "ATAG_INITRD is deprecated; "
  55. "please update your bootloader.\n");
  56. phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
  57. phys_initrd_size = tag->u.initrd.size;
  58. return 0;
  59. }
  60. __tagtable(ATAG_INITRD, parse_tag_initrd);
  61. static int __init parse_tag_initrd2(const struct tag *tag)
  62. {
  63. phys_initrd_start = tag->u.initrd.start;
  64. phys_initrd_size = tag->u.initrd.size;
  65. return 0;
  66. }
  67. __tagtable(ATAG_INITRD2, parse_tag_initrd2);
  68. #ifdef CONFIG_OF_FLATTREE
  69. void __init early_init_dt_setup_initrd_arch(u64 start, u64 end)
  70. {
  71. phys_initrd_start = start;
  72. phys_initrd_size = end - start;
  73. }
  74. #endif /* CONFIG_OF_FLATTREE */
  75. /*
  76. * This keeps memory configuration data used by a couple memory
  77. * initialization functions, as well as show_mem() for the skipping
  78. * of holes in the memory map. It is populated by arm_add_memory().
  79. */
  80. struct meminfo meminfo;
  81. void show_mem(unsigned int filter)
  82. {
  83. int free = 0, total = 0, reserved = 0;
  84. int shared = 0, cached = 0, slab = 0, i;
  85. struct meminfo * mi = &meminfo;
  86. printk("Mem-info:\n");
  87. show_free_areas(filter);
  88. if (filter & SHOW_MEM_FILTER_PAGE_COUNT)
  89. return;
  90. for_each_bank (i, mi) {
  91. struct membank *bank = &mi->bank[i];
  92. unsigned int pfn1, pfn2;
  93. struct page *page, *end;
  94. pfn1 = bank_pfn_start(bank);
  95. pfn2 = bank_pfn_end(bank);
  96. page = pfn_to_page(pfn1);
  97. end = pfn_to_page(pfn2 - 1) + 1;
  98. do {
  99. total++;
  100. if (PageReserved(page))
  101. reserved++;
  102. else if (PageSwapCache(page))
  103. cached++;
  104. else if (PageSlab(page))
  105. slab++;
  106. else if (!page_count(page))
  107. free++;
  108. else
  109. shared += page_count(page) - 1;
  110. page++;
  111. } while (page < end);
  112. }
  113. printk("%d pages of RAM\n", total);
  114. printk("%d free pages\n", free);
  115. printk("%d reserved pages\n", reserved);
  116. printk("%d slab pages\n", slab);
  117. printk("%d pages shared\n", shared);
  118. printk("%d pages swap cached\n", cached);
  119. }
  120. static void __init find_limits(unsigned long *min, unsigned long *max_low,
  121. unsigned long *max_high)
  122. {
  123. struct meminfo *mi = &meminfo;
  124. int i;
  125. /* This assumes the meminfo array is properly sorted */
  126. *min = bank_pfn_start(&mi->bank[0]);
  127. for_each_bank (i, mi)
  128. if (mi->bank[i].highmem)
  129. break;
  130. *max_low = bank_pfn_end(&mi->bank[i - 1]);
  131. *max_high = bank_pfn_end(&mi->bank[mi->nr_banks - 1]);
  132. }
  133. static void __init arm_bootmem_init(unsigned long start_pfn,
  134. unsigned long end_pfn)
  135. {
  136. struct memblock_region *reg;
  137. unsigned int boot_pages;
  138. phys_addr_t bitmap;
  139. pg_data_t *pgdat;
  140. /*
  141. * Allocate the bootmem bitmap page. This must be in a region
  142. * of memory which has already been mapped.
  143. */
  144. boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  145. bitmap = memblock_alloc_base(boot_pages << PAGE_SHIFT, L1_CACHE_BYTES,
  146. __pfn_to_phys(end_pfn));
  147. /*
  148. * Initialise the bootmem allocator, handing the
  149. * memory banks over to bootmem.
  150. */
  151. node_set_online(0);
  152. pgdat = NODE_DATA(0);
  153. init_bootmem_node(pgdat, __phys_to_pfn(bitmap), start_pfn, end_pfn);
  154. /* Free the lowmem regions from memblock into bootmem. */
  155. for_each_memblock(memory, reg) {
  156. unsigned long start = memblock_region_memory_base_pfn(reg);
  157. unsigned long end = memblock_region_memory_end_pfn(reg);
  158. if (end >= end_pfn)
  159. end = end_pfn;
  160. if (start >= end)
  161. break;
  162. free_bootmem(__pfn_to_phys(start), (end - start) << PAGE_SHIFT);
  163. }
  164. /* Reserve the lowmem memblock reserved regions in bootmem. */
  165. for_each_memblock(reserved, reg) {
  166. unsigned long start = memblock_region_reserved_base_pfn(reg);
  167. unsigned long end = memblock_region_reserved_end_pfn(reg);
  168. if (end >= end_pfn)
  169. end = end_pfn;
  170. if (start >= end)
  171. break;
  172. reserve_bootmem(__pfn_to_phys(start),
  173. (end - start) << PAGE_SHIFT, BOOTMEM_DEFAULT);
  174. }
  175. }
  176. #ifdef CONFIG_ZONE_DMA
  177. phys_addr_t arm_dma_zone_size __read_mostly;
  178. EXPORT_SYMBOL(arm_dma_zone_size);
  179. /*
  180. * The DMA mask corresponding to the maximum bus address allocatable
  181. * using GFP_DMA. The default here places no restriction on DMA
  182. * allocations. This must be the smallest DMA mask in the system,
  183. * so a successful GFP_DMA allocation will always satisfy this.
  184. */
  185. phys_addr_t arm_dma_limit;
  186. static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole,
  187. unsigned long dma_size)
  188. {
  189. if (size[0] <= dma_size)
  190. return;
  191. size[ZONE_NORMAL] = size[0] - dma_size;
  192. size[ZONE_DMA] = dma_size;
  193. hole[ZONE_NORMAL] = hole[0];
  194. hole[ZONE_DMA] = 0;
  195. }
  196. #endif
  197. void __init setup_dma_zone(const struct machine_desc *mdesc)
  198. {
  199. #ifdef CONFIG_ZONE_DMA
  200. if (mdesc->dma_zone_size) {
  201. arm_dma_zone_size = mdesc->dma_zone_size;
  202. arm_dma_limit = PHYS_OFFSET + arm_dma_zone_size - 1;
  203. } else
  204. arm_dma_limit = 0xffffffff;
  205. #endif
  206. }
  207. static void __init arm_bootmem_free(unsigned long min, unsigned long max_low,
  208. unsigned long max_high)
  209. {
  210. unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
  211. struct memblock_region *reg;
  212. /*
  213. * initialise the zones.
  214. */
  215. memset(zone_size, 0, sizeof(zone_size));
  216. /*
  217. * The memory size has already been determined. If we need
  218. * to do anything fancy with the allocation of this memory
  219. * to the zones, now is the time to do it.
  220. */
  221. zone_size[0] = max_low - min;
  222. #ifdef CONFIG_HIGHMEM
  223. zone_size[ZONE_HIGHMEM] = max_high - max_low;
  224. #endif
  225. /*
  226. * Calculate the size of the holes.
  227. * holes = node_size - sum(bank_sizes)
  228. */
  229. memcpy(zhole_size, zone_size, sizeof(zhole_size));
  230. for_each_memblock(memory, reg) {
  231. unsigned long start = memblock_region_memory_base_pfn(reg);
  232. unsigned long end = memblock_region_memory_end_pfn(reg);
  233. if (start < max_low) {
  234. unsigned long low_end = min(end, max_low);
  235. zhole_size[0] -= low_end - start;
  236. }
  237. #ifdef CONFIG_HIGHMEM
  238. if (end > max_low) {
  239. unsigned long high_start = max(start, max_low);
  240. zhole_size[ZONE_HIGHMEM] -= end - high_start;
  241. }
  242. #endif
  243. }
  244. #ifdef CONFIG_ZONE_DMA
  245. /*
  246. * Adjust the sizes according to any special requirements for
  247. * this machine type.
  248. */
  249. if (arm_dma_zone_size)
  250. arm_adjust_dma_zone(zone_size, zhole_size,
  251. arm_dma_zone_size >> PAGE_SHIFT);
  252. #endif
  253. free_area_init_node(0, zone_size, min, zhole_size);
  254. }
  255. #ifdef CONFIG_HAVE_ARCH_PFN_VALID
  256. int pfn_valid(unsigned long pfn)
  257. {
  258. return memblock_is_memory(__pfn_to_phys(pfn));
  259. }
  260. EXPORT_SYMBOL(pfn_valid);
  261. #endif
  262. #ifndef CONFIG_SPARSEMEM
  263. static void __init arm_memory_present(void)
  264. {
  265. }
  266. #else
  267. static void __init arm_memory_present(void)
  268. {
  269. struct memblock_region *reg;
  270. for_each_memblock(memory, reg)
  271. memory_present(0, memblock_region_memory_base_pfn(reg),
  272. memblock_region_memory_end_pfn(reg));
  273. }
  274. #endif
  275. static bool arm_memblock_steal_permitted = true;
  276. phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)
  277. {
  278. phys_addr_t phys;
  279. BUG_ON(!arm_memblock_steal_permitted);
  280. phys = memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ANYWHERE);
  281. memblock_free(phys, size);
  282. memblock_remove(phys, size);
  283. return phys;
  284. }
  285. void __init arm_memblock_init(struct meminfo *mi,
  286. const struct machine_desc *mdesc)
  287. {
  288. int i;
  289. for (i = 0; i < mi->nr_banks; i++)
  290. memblock_add(mi->bank[i].start, mi->bank[i].size);
  291. /* Register the kernel text, kernel data and initrd with memblock. */
  292. #ifdef CONFIG_XIP_KERNEL
  293. memblock_reserve(__pa(_sdata), _end - _sdata);
  294. #else
  295. memblock_reserve(__pa(_stext), _end - _stext);
  296. #endif
  297. #ifdef CONFIG_BLK_DEV_INITRD
  298. if (phys_initrd_size &&
  299. !memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) {
  300. pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n",
  301. (u64)phys_initrd_start, phys_initrd_size);
  302. phys_initrd_start = phys_initrd_size = 0;
  303. }
  304. if (phys_initrd_size &&
  305. memblock_is_region_reserved(phys_initrd_start, phys_initrd_size)) {
  306. pr_err("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region - disabling initrd\n",
  307. (u64)phys_initrd_start, phys_initrd_size);
  308. phys_initrd_start = phys_initrd_size = 0;
  309. }
  310. if (phys_initrd_size) {
  311. memblock_reserve(phys_initrd_start, phys_initrd_size);
  312. /* Now convert initrd to virtual addresses */
  313. initrd_start = __phys_to_virt(phys_initrd_start);
  314. initrd_end = initrd_start + phys_initrd_size;
  315. }
  316. #endif
  317. arm_mm_memblock_reserve();
  318. arm_dt_memblock_reserve();
  319. /* reserve any platform specific memblock areas */
  320. if (mdesc->reserve)
  321. mdesc->reserve();
  322. early_init_dt_scan_reserved_mem();
  323. /*
  324. * reserve memory for DMA contigouos allocations,
  325. * must come from DMA area inside low memory
  326. */
  327. dma_contiguous_reserve(min(arm_dma_limit, arm_lowmem_limit));
  328. arm_memblock_steal_permitted = false;
  329. memblock_allow_resize();
  330. memblock_dump_all();
  331. }
  332. void __init bootmem_init(void)
  333. {
  334. unsigned long min, max_low, max_high;
  335. max_low = max_high = 0;
  336. find_limits(&min, &max_low, &max_high);
  337. arm_bootmem_init(min, max_low);
  338. /*
  339. * Sparsemem tries to allocate bootmem in memory_present(),
  340. * so must be done after the fixed reservations
  341. */
  342. arm_memory_present();
  343. /*
  344. * sparse_init() needs the bootmem allocator up and running.
  345. */
  346. sparse_init();
  347. /*
  348. * Now free the memory - free_area_init_node needs
  349. * the sparse mem_map arrays initialized by sparse_init()
  350. * for memmap_init_zone(), otherwise all PFNs are invalid.
  351. */
  352. arm_bootmem_free(min, max_low, max_high);
  353. /*
  354. * This doesn't seem to be used by the Linux memory manager any
  355. * more, but is used by ll_rw_block. If we can get rid of it, we
  356. * also get rid of some of the stuff above as well.
  357. *
  358. * Note: max_low_pfn and max_pfn reflect the number of _pages_ in
  359. * the system, not the maximum PFN.
  360. */
  361. max_low_pfn = max_low - PHYS_PFN_OFFSET;
  362. max_pfn = max_high - PHYS_PFN_OFFSET;
  363. }
  364. /*
  365. * Poison init memory with an undefined instruction (ARM) or a branch to an
  366. * undefined instruction (Thumb).
  367. */
  368. static inline void poison_init_mem(void *s, size_t count)
  369. {
  370. u32 *p = (u32 *)s;
  371. for (; count != 0; count -= 4)
  372. *p++ = 0xe7fddef0;
  373. }
  374. static inline void
  375. free_memmap(unsigned long start_pfn, unsigned long end_pfn)
  376. {
  377. struct page *start_pg, *end_pg;
  378. phys_addr_t pg, pgend;
  379. /*
  380. * Convert start_pfn/end_pfn to a struct page pointer.
  381. */
  382. start_pg = pfn_to_page(start_pfn - 1) + 1;
  383. end_pg = pfn_to_page(end_pfn - 1) + 1;
  384. /*
  385. * Convert to physical addresses, and
  386. * round start upwards and end downwards.
  387. */
  388. pg = PAGE_ALIGN(__pa(start_pg));
  389. pgend = __pa(end_pg) & PAGE_MASK;
  390. /*
  391. * If there are free pages between these,
  392. * free the section of the memmap array.
  393. */
  394. if (pg < pgend)
  395. free_bootmem(pg, pgend - pg);
  396. }
  397. /*
  398. * The mem_map array can get very big. Free the unused area of the memory map.
  399. */
  400. static void __init free_unused_memmap(struct meminfo *mi)
  401. {
  402. unsigned long bank_start, prev_bank_end = 0;
  403. unsigned int i;
  404. /*
  405. * This relies on each bank being in address order.
  406. * The banks are sorted previously in bootmem_init().
  407. */
  408. for_each_bank(i, mi) {
  409. struct membank *bank = &mi->bank[i];
  410. bank_start = bank_pfn_start(bank);
  411. #ifdef CONFIG_SPARSEMEM
  412. /*
  413. * Take care not to free memmap entries that don't exist
  414. * due to SPARSEMEM sections which aren't present.
  415. */
  416. bank_start = min(bank_start,
  417. ALIGN(prev_bank_end, PAGES_PER_SECTION));
  418. #else
  419. /*
  420. * Align down here since the VM subsystem insists that the
  421. * memmap entries are valid from the bank start aligned to
  422. * MAX_ORDER_NR_PAGES.
  423. */
  424. bank_start = round_down(bank_start, MAX_ORDER_NR_PAGES);
  425. #endif
  426. /*
  427. * If we had a previous bank, and there is a space
  428. * between the current bank and the previous, free it.
  429. */
  430. if (prev_bank_end && prev_bank_end < bank_start)
  431. free_memmap(prev_bank_end, bank_start);
  432. /*
  433. * Align up here since the VM subsystem insists that the
  434. * memmap entries are valid from the bank end aligned to
  435. * MAX_ORDER_NR_PAGES.
  436. */
  437. prev_bank_end = ALIGN(bank_pfn_end(bank), MAX_ORDER_NR_PAGES);
  438. }
  439. #ifdef CONFIG_SPARSEMEM
  440. if (!IS_ALIGNED(prev_bank_end, PAGES_PER_SECTION))
  441. free_memmap(prev_bank_end,
  442. ALIGN(prev_bank_end, PAGES_PER_SECTION));
  443. #endif
  444. }
  445. #ifdef CONFIG_HIGHMEM
  446. static inline void free_area_high(unsigned long pfn, unsigned long end)
  447. {
  448. for (; pfn < end; pfn++)
  449. free_highmem_page(pfn_to_page(pfn));
  450. }
  451. #endif
  452. static void __init free_highpages(void)
  453. {
  454. #ifdef CONFIG_HIGHMEM
  455. unsigned long max_low = max_low_pfn + PHYS_PFN_OFFSET;
  456. struct memblock_region *mem, *res;
  457. /* set highmem page free */
  458. for_each_memblock(memory, mem) {
  459. unsigned long start = memblock_region_memory_base_pfn(mem);
  460. unsigned long end = memblock_region_memory_end_pfn(mem);
  461. /* Ignore complete lowmem entries */
  462. if (end <= max_low)
  463. continue;
  464. /* Truncate partial highmem entries */
  465. if (start < max_low)
  466. start = max_low;
  467. /* Find and exclude any reserved regions */
  468. for_each_memblock(reserved, res) {
  469. unsigned long res_start, res_end;
  470. res_start = memblock_region_reserved_base_pfn(res);
  471. res_end = memblock_region_reserved_end_pfn(res);
  472. if (res_end < start)
  473. continue;
  474. if (res_start < start)
  475. res_start = start;
  476. if (res_start > end)
  477. res_start = end;
  478. if (res_end > end)
  479. res_end = end;
  480. if (res_start != start)
  481. free_area_high(start, res_start);
  482. start = res_end;
  483. if (start == end)
  484. break;
  485. }
  486. /* And now free anything which remains */
  487. if (start < end)
  488. free_area_high(start, end);
  489. }
  490. #endif
  491. }
  492. /*
  493. * mem_init() marks the free areas in the mem_map and tells us how much
  494. * memory is free. This is done after various parts of the system have
  495. * claimed their memory after the kernel image.
  496. */
  497. void __init mem_init(void)
  498. {
  499. #ifdef CONFIG_HAVE_TCM
  500. /* These pointers are filled in on TCM detection */
  501. extern u32 dtcm_end;
  502. extern u32 itcm_end;
  503. #endif
  504. max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
  505. /* this will put all unused low memory onto the freelists */
  506. free_unused_memmap(&meminfo);
  507. free_all_bootmem();
  508. #ifdef CONFIG_SA1111
  509. /* now that our DMA memory is actually so designated, we can free it */
  510. free_reserved_area(__va(PHYS_OFFSET), swapper_pg_dir, -1, NULL);
  511. #endif
  512. free_highpages();
  513. mem_init_print_info(NULL);
  514. #define MLK(b, t) b, t, ((t) - (b)) >> 10
  515. #define MLM(b, t) b, t, ((t) - (b)) >> 20
  516. #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
  517. printk(KERN_NOTICE "Virtual kernel memory layout:\n"
  518. " vector : 0x%08lx - 0x%08lx (%4ld kB)\n"
  519. #ifdef CONFIG_HAVE_TCM
  520. " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
  521. " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
  522. #endif
  523. " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
  524. " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
  525. " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
  526. #ifdef CONFIG_HIGHMEM
  527. " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
  528. #endif
  529. #ifdef CONFIG_MODULES
  530. " modules : 0x%08lx - 0x%08lx (%4ld MB)\n"
  531. #endif
  532. " .text : 0x%p" " - 0x%p" " (%4d kB)\n"
  533. " .init : 0x%p" " - 0x%p" " (%4d kB)\n"
  534. " .data : 0x%p" " - 0x%p" " (%4d kB)\n"
  535. " .bss : 0x%p" " - 0x%p" " (%4d kB)\n",
  536. MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) +
  537. (PAGE_SIZE)),
  538. #ifdef CONFIG_HAVE_TCM
  539. MLK(DTCM_OFFSET, (unsigned long) dtcm_end),
  540. MLK(ITCM_OFFSET, (unsigned long) itcm_end),
  541. #endif
  542. MLK(FIXADDR_START, FIXADDR_TOP),
  543. MLM(VMALLOC_START, VMALLOC_END),
  544. MLM(PAGE_OFFSET, (unsigned long)high_memory),
  545. #ifdef CONFIG_HIGHMEM
  546. MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) *
  547. (PAGE_SIZE)),
  548. #endif
  549. #ifdef CONFIG_MODULES
  550. MLM(MODULES_VADDR, MODULES_END),
  551. #endif
  552. MLK_ROUNDUP(_text, _etext),
  553. MLK_ROUNDUP(__init_begin, __init_end),
  554. MLK_ROUNDUP(_sdata, _edata),
  555. MLK_ROUNDUP(__bss_start, __bss_stop));
  556. #undef MLK
  557. #undef MLM
  558. #undef MLK_ROUNDUP
  559. /*
  560. * Check boundaries twice: Some fundamental inconsistencies can
  561. * be detected at build time already.
  562. */
  563. #ifdef CONFIG_MMU
  564. BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR);
  565. BUG_ON(TASK_SIZE > MODULES_VADDR);
  566. #endif
  567. #ifdef CONFIG_HIGHMEM
  568. BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
  569. BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
  570. #endif
  571. if (PAGE_SIZE >= 16384 && get_num_physpages() <= 128) {
  572. extern int sysctl_overcommit_memory;
  573. /*
  574. * On a machine this small we won't get
  575. * anywhere without overcommit, so turn
  576. * it on by default.
  577. */
  578. sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
  579. }
  580. }
  581. void free_initmem(void)
  582. {
  583. #ifdef CONFIG_HAVE_TCM
  584. extern char __tcm_start, __tcm_end;
  585. poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
  586. free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
  587. #endif
  588. poison_init_mem(__init_begin, __init_end - __init_begin);
  589. if (!machine_is_integrator() && !machine_is_cintegrator())
  590. free_initmem_default(-1);
  591. }
  592. #ifdef CONFIG_BLK_DEV_INITRD
  593. static int keep_initrd;
  594. void free_initrd_mem(unsigned long start, unsigned long end)
  595. {
  596. if (!keep_initrd) {
  597. poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
  598. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  599. }
  600. }
  601. static int __init keepinitrd_setup(char *__unused)
  602. {
  603. keep_initrd = 1;
  604. return 1;
  605. }
  606. __setup("keepinitrd", keepinitrd_setup);
  607. #endif