]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - mm/memblock.c
Merge tag 'for-linus-3.16-merge-window' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / mm / memblock.c
index 9edd0928daab7f6b006abab4681ddb873f953aec..6d2f219a48b01d371c1eb763f611d29a346890d9 100644 (file)
@@ -27,6 +27,9 @@
 
 static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
 static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
+#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
+static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS] __initdata_memblock;
+#endif
 
 struct memblock memblock __initdata_memblock = {
        .memory.regions         = memblock_memory_init_regions,
@@ -37,6 +40,12 @@ struct memblock memblock __initdata_memblock = {
        .reserved.cnt           = 1,    /* empty dummy entry */
        .reserved.max           = INIT_MEMBLOCK_REGIONS,
 
+#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
+       .physmem.regions        = memblock_physmem_init_regions,
+       .physmem.cnt            = 1,    /* empty dummy entry */
+       .physmem.max            = INIT_PHYSMEM_REGIONS,
+#endif
+
        .bottom_up              = false,
        .current_limit          = MEMBLOCK_ALLOC_ANYWHERE,
 };
@@ -682,6 +691,7 @@ int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size)
                     (unsigned long long)base + size - 1,
                     (void *)_RET_IP_);
 
+       kmemleak_free_part(__va(base), size);
        return memblock_remove_range(&memblock.reserved, base, size);
 }
 
@@ -1024,22 +1034,40 @@ int __init_memblock memblock_set_node(phys_addr_t base, phys_addr_t size,
 }
 #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
 
-static phys_addr_t __init memblock_alloc_base_nid(phys_addr_t size,
-                                       phys_addr_t align, phys_addr_t max_addr,
-                                       int nid)
+static phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,
+                                       phys_addr_t align, phys_addr_t start,
+                                       phys_addr_t end, int nid)
 {
        phys_addr_t found;
 
        if (!align)
                align = SMP_CACHE_BYTES;
 
-       found = memblock_find_in_range_node(size, align, 0, max_addr, nid);
-       if (found && !memblock_reserve(found, size))
+       found = memblock_find_in_range_node(size, align, start, end, nid);
+       if (found && !memblock_reserve(found, size)) {
+               /*
+                * The min_count is set to 0 so that memblock allocations are
+                * never reported as leaks.
+                */
+               kmemleak_alloc(__va(found), size, 0, 0);
                return found;
-
+       }
        return 0;
 }
 
+phys_addr_t __init memblock_alloc_range(phys_addr_t size, phys_addr_t align,
+                                       phys_addr_t start, phys_addr_t end)
+{
+       return memblock_alloc_range_nid(size, align, start, end, NUMA_NO_NODE);
+}
+
+static phys_addr_t __init memblock_alloc_base_nid(phys_addr_t size,
+                                       phys_addr_t align, phys_addr_t max_addr,
+                                       int nid)
+{
+       return memblock_alloc_range_nid(size, align, 0, max_addr, nid);
+}
+
 phys_addr_t __init memblock_alloc_nid(phys_addr_t size, phys_addr_t align, int nid)
 {
        return memblock_alloc_base_nid(size, align, MEMBLOCK_ALLOC_ACCESSIBLE, nid);
@@ -1380,9 +1408,8 @@ int __init_memblock memblock_search_pfn_nid(unsigned long pfn,
        if (mid == -1)
                return -1;
 
-       *start_pfn = type->regions[mid].base >> PAGE_SHIFT;
-       *end_pfn = (type->regions[mid].base + type->regions[mid].size)
-                       >> PAGE_SHIFT;
+       *start_pfn = PFN_DOWN(type->regions[mid].base);
+       *end_pfn = PFN_DOWN(type->regions[mid].base + type->regions[mid].size);
 
        return type->regions[mid].nid;
 }
@@ -1553,6 +1580,9 @@ static int __init memblock_init_debugfs(void)
                return -ENXIO;
        debugfs_create_file("memory", S_IRUGO, root, &memblock.memory, &memblock_debug_fops);
        debugfs_create_file("reserved", S_IRUGO, root, &memblock.reserved, &memblock_debug_fops);
+#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
+       debugfs_create_file("physmem", S_IRUGO, root, &memblock.physmem, &memblock_debug_fops);
+#endif
 
        return 0;
 }