···3030#include <linux/clk.h>3131#include <linux/delay.h>3232#include <linux/platform_device.h>3333+#include <linux/lmb.h>3334#include <asm/uaccess.h>3435#include <asm/io.h>3536#include <asm/page.h>···234233void __init setup_bootmem_allocator(unsigned long free_pfn)235234{236235 unsigned long bootmap_size;236236+ unsigned long bootmap_pages, bootmem_paddr;237237+ u64 total_pages = (lmb_end_of_DRAM() - __MEMORY_START) >> PAGE_SHIFT;238238+ int i;239239+240240+ bootmap_pages = bootmem_bootmap_pages(total_pages);241241+242242+ bootmem_paddr = lmb_alloc(bootmap_pages << PAGE_SHIFT, PAGE_SIZE);237243238244 /*239245 * Find a proper area for the bootmem bitmap. After this240246 * bootstrap step all allocations (until the page allocator241247 * is intact) must be done via bootmem_alloc().242248 */243243- bootmap_size = init_bootmem_node(NODE_DATA(0), free_pfn,249249+ bootmap_size = init_bootmem_node(NODE_DATA(0),250250+ bootmem_paddr >> PAGE_SHIFT,244251 min_low_pfn, max_low_pfn);245252246246- __add_active_range(0, min_low_pfn, max_low_pfn);253253+ /* Add active regions with valid PFNs. */254254+ for (i = 0; i < lmb.memory.cnt; i++) {255255+ unsigned long start_pfn, end_pfn;256256+ start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;257257+ end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);258258+ __add_active_range(0, start_pfn, end_pfn);259259+ }260260+261261+ /*262262+ * Add all physical memory to the bootmem map and mark each263263+ * area as present.264264+ */247265 register_bootmem_low_pages();248266249249- node_set_online(0);250250-251251- /*252252- * Reserve the kernel text and253253- * Reserve the bootmem bitmap. We do this in two steps (first step254254- * was init_bootmem()), because this catches the (definitely buggy)255255- * case of us accidentally initializing the bootmem allocator with256256- * an invalid RAM area.257257- */258258- reserve_bootmem(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,259259- (PFN_PHYS(free_pfn) + bootmap_size + PAGE_SIZE - 1) -260260- (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET),261261- BOOTMEM_DEFAULT);262262-263263- /*264264- * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.265265- */266266- if (CONFIG_ZERO_PAGE_OFFSET != 0)267267- reserve_bootmem(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET,267267+ /* Reserve the sections we're already using. */268268+ for (i = 0; i < lmb.reserved.cnt; i++)269269+ reserve_bootmem(lmb.reserved.region[i].base,270270+ lmb_size_bytes(&lmb.reserved, i),268271 BOOTMEM_DEFAULT);272272+273273+ node_set_online(0);269274270275 sparse_memory_present_with_active_regions(0);271276···303296static void __init setup_memory(void)304297{305298 unsigned long start_pfn;299299+ u64 base = min_low_pfn << PAGE_SHIFT;300300+ u64 size = (max_low_pfn << PAGE_SHIFT) - base;306301307302 /*308303 * Partially used pages are not usable - thus309304 * we are rounding upwards:310305 */311306 start_pfn = PFN_UP(__pa(_end));307307+308308+ lmb_add(base, size);309309+310310+ /*311311+ * Reserve the kernel text and312312+ * Reserve the bootmem bitmap. We do this in two steps (first step313313+ * was init_bootmem()), because this catches the (definitely buggy)314314+ * case of us accidentally initializing the bootmem allocator with315315+ * an invalid RAM area.316316+ */317317+ lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,318318+ (PFN_PHYS(start_pfn) + PAGE_SIZE - 1) -319319+ (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));320320+321321+ /*322322+ * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.323323+ */324324+ if (CONFIG_ZERO_PAGE_OFFSET != 0)325325+ lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);326326+327327+ lmb_analyze();328328+ lmb_dump_all();329329+312330 setup_bootmem_allocator(start_pfn);313331}314332#else···434402 nodes_clear(node_online_map);435403436404 /* Setup bootmem with available RAM */405405+ lmb_init();437406 setup_memory();438407 sparse_init();439408