init.c 18 KB

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