aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/memblock.h2
-rw-r--r--mm/memblock.c42
2 files changed, 36 insertions, 8 deletions
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 4b6931327b22..47bceb187058 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -56,6 +56,8 @@ extern u64 __init __memblock_alloc_base(u64 size,
56extern u64 __init memblock_phys_mem_size(void); 56extern u64 __init memblock_phys_mem_size(void);
57extern u64 memblock_end_of_DRAM(void); 57extern u64 memblock_end_of_DRAM(void);
58extern void __init memblock_enforce_memory_limit(u64 memory_limit); 58extern void __init memblock_enforce_memory_limit(u64 memory_limit);
59extern int memblock_is_memory(u64 addr);
60extern int memblock_is_region_memory(u64 base, u64 size);
59extern int __init memblock_is_reserved(u64 addr); 61extern int __init memblock_is_reserved(u64 addr);
60extern int memblock_is_region_reserved(u64 base, u64 size); 62extern int memblock_is_region_reserved(u64 base, u64 size);
61extern int memblock_find(struct memblock_region *res); 63extern int memblock_find(struct memblock_region *res);
diff --git a/mm/memblock.c b/mm/memblock.c
index 6f407ccf604e..aa88c62bce7f 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -487,17 +487,43 @@ void __init memblock_enforce_memory_limit(u64 memory_limit)
487 } 487 }
488} 488}
489 489
490static int memblock_search(struct memblock_type *type, u64 addr)
491{
492 unsigned int left = 0, right = type->cnt;
493
494 do {
495 unsigned int mid = (right + left) / 2;
496
497 if (addr < type->regions[mid].base)
498 right = mid;
499 else if (addr >= (type->regions[mid].base +
500 type->regions[mid].size))
501 left = mid + 1;
502 else
503 return mid;
504 } while (left < right);
505 return -1;
506}
507
490int __init memblock_is_reserved(u64 addr) 508int __init memblock_is_reserved(u64 addr)
491{ 509{
492 int i; 510 return memblock_search(&memblock.reserved, addr) != -1;
511}
493 512
494 for (i = 0; i < memblock.reserved.cnt; i++) { 513int memblock_is_memory(u64 addr)
495 u64 upper = memblock.reserved.regions[i].base + 514{
496 memblock.reserved.regions[i].size - 1; 515 return memblock_search(&memblock.memory, addr) != -1;
497 if ((addr >= memblock.reserved.regions[i].base) && (addr <= upper)) 516}
498 return 1; 517
499 } 518int memblock_is_region_memory(u64 base, u64 size)
500 return 0; 519{
520 int idx = memblock_search(&memblock.reserved, base);
521
522 if (idx == -1)
523 return 0;
524 return memblock.reserved.regions[idx].base <= base &&
525 (memblock.reserved.regions[idx].base +
526 memblock.reserved.regions[idx].size) >= (base + size);
501} 527}
502 528
503int memblock_is_region_reserved(u64 base, u64 size) 529int memblock_is_region_reserved(u64 base, u64 size)