return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size);
 }
 
-void __init memblock_enforce_memory_limit(phys_addr_t limit)
+static phys_addr_t __init_memblock __find_max_addr(phys_addr_t limit)
 {
        phys_addr_t max_addr = (phys_addr_t)ULLONG_MAX;
        struct memblock_region *r;
 
-       if (!limit)
-               return;
-
-       /* find out max address */
+       /*
+        * translate the memory @limit size into the max address within one of
+        * the memory memblock regions, if the @limit exceeds the total size
+        * of those regions, max_addr will keep original value ULLONG_MAX
+        */
        for_each_memblock(memory, r) {
                if (limit <= r->size) {
                        max_addr = r->base + limit;
                limit -= r->size;
        }
 
+       return max_addr;
+}
+
+void __init memblock_enforce_memory_limit(phys_addr_t limit)
+{
+       phys_addr_t max_addr = (phys_addr_t)ULLONG_MAX;
+
+       if (!limit)
+               return;
+
+       max_addr = __find_max_addr(limit);
+
+       /* @limit exceeds the total size of the memory, do nothing */
+       if (max_addr == (phys_addr_t)ULLONG_MAX)
+               return;
+
        /* truncate both memory and reserved regions */
        memblock_remove_range(&memblock.memory, max_addr,
                              (phys_addr_t)ULLONG_MAX);
                              (phys_addr_t)ULLONG_MAX);
 }
 
+void __init memblock_mem_limit_remove_map(phys_addr_t limit)
+{
+       struct memblock_type *type = &memblock.memory;
+       phys_addr_t max_addr;
+       int i, ret, start_rgn, end_rgn;
+
+       if (!limit)
+               return;
+
+       max_addr = __find_max_addr(limit);
+
+       /* @limit exceeds the total size of the memory, do nothing */
+       if (max_addr == (phys_addr_t)ULLONG_MAX)
+               return;
+
+       ret = memblock_isolate_range(type, max_addr, (phys_addr_t)ULLONG_MAX,
+                               &start_rgn, &end_rgn);
+       if (ret)
+               return;
+
+       /* remove all the MAP regions above the limit */
+       for (i = end_rgn - 1; i >= start_rgn; i--) {
+               if (!memblock_is_nomap(&type->regions[i]))
+                       memblock_remove_region(type, i);
+       }
+       /* truncate the reserved regions */
+       memblock_remove_range(&memblock.reserved, max_addr,
+                             (phys_addr_t)ULLONG_MAX);
+}
+
 static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr)
 {
        unsigned int left = 0, right = type->cnt;