init.c 18 KB

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