init.c 19 KB

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