init.c 18 KB

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