#include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/memblock.h>
 #include <linux/sizes.h>
 #include <linux/string.h>
 
        if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
                memsize = SZ_64M; /* minimum memsize is 64MB RAM */
 
-       add_memory_region(0, memsize, BOOT_MEM_RAM);
+       memblock_add(0, memsize);
 }
 
 static inline unsigned char str2hexnum(unsigned char c)
 
        unsigned long pages;
 
        pages = memsize() >> PAGE_SHIFT;
-       add_memory_region(PHYS_OFFSET, pages << PAGE_SHIFT, BOOT_MEM_RAM);
+       memblock_add(PHYS_OFFSET, pages << PAGE_SHIFT);
 }
 
 void __init prom_free_prom_memory(void)
 
 #include <linux/bitops.h>
 #include <linux/irqdomain.h>
 #include <linux/interrupt.h>
+#include <linux/memblock.h>
 #include <linux/platform_device.h>
 #include <linux/reboot.h>
 #include <asm/bootinfo.h>
        memsize <<= 1 + ATH25_REG_MS(memcfg, AR2315_MEM_CFG_COL_WIDTH);
        memsize <<= 1 + ATH25_REG_MS(memcfg, AR2315_MEM_CFG_ROW_WIDTH);
        memsize <<= 3;
-       add_memory_region(0, memsize, BOOT_MEM_RAM);
+       memblock_add(0, memsize);
        iounmap(sdram_base);
 
        ar2315_rst_base = ioremap(AR2315_RST_BASE, AR2315_RST_SIZE);
 
 #include <linux/bitops.h>
 #include <linux/irqdomain.h>
 #include <linux/interrupt.h>
+#include <linux/memblock.h>
 #include <linux/platform_device.h>
 #include <linux/mtd/physmap.h>
 #include <linux/reboot.h>
        memsize = (bank0_ac ? (1 << (bank0_ac + 1)) : 0) +
                  (bank1_ac ? (1 << (bank1_ac + 1)) : 0);
        memsize <<= 20;
-       add_memory_region(0, memsize, BOOT_MEM_RAM);
+       memblock_add(0, memsize);
        iounmap(sdram_base);
 
        ar5312_rst_base = ioremap(AR5312_RST_BASE, AR5312_RST_SIZE);
 
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/memblock.h>
 #include <linux/spinlock.h>
 #include <linux/ssb/ssb_driver_chipcommon.h>
 #include <linux/ssb/ssb_regs.h>
         */
        if (c->cputype == CPU_74K && (mem == (128  << 20)))
                mem -= 0x1000;
-       add_memory_region(0, mem, BOOT_MEM_RAM);
+       memblock_add(0, mem);
 }
 
 /*
 
 
 /*
  * Memory setup is done in the early part of MIPS's arch_mem_init. It's supposed
- * to detect memory and record it with add_memory_region.
+ * to detect memory and record it with memblock_add.
  * Any extra initializaion performed here must not use kmalloc or bootmem.
  */
 void __init plat_mem_setup(void)
 
 
 void __init plat_mem_setup(void)
 {
-       add_memory_region(0, bcm63xx_get_memory_size(), BOOT_MEM_RAM);
+       memblock_add(0, bcm63xx_get_memory_size());
 
        _machine_halt = bcm63xx_machine_halt;
        _machine_restart = __bcm63xx_machine_reboot;
 
 #include <linux/export.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/memblock.h>
 #include <linux/serial.h>
 #include <linux/smp.h>
 #include <linux/types.h>
 {
        if (addr > *mem && addr < *mem + *size) {
                u64 inc = addr - *mem;
-               add_memory_region(*mem, inc, BOOT_MEM_RAM);
+               memblock_add(*mem, inc);
                *mem += inc;
                *size -= inc;
        }
 
 /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
 #ifdef CONFIG_CRASH_DUMP
-       add_memory_region(reserve_low_mem, max_memory, BOOT_MEM_RAM);
+       memblock_add(reserve_low_mem, max_memory);
        total += max_memory;
 #else
 #ifdef CONFIG_KEXEC
        if (crashk_size > 0) {
-               add_memory_region(crashk_base, crashk_size, BOOT_MEM_RAM);
+               memblock_add(crashk_base, crashk_size);
                crashk_end = crashk_base + crashk_size;
        }
 #endif
        /*
-        * When allocating memory, we want incrementing addresses from
-        * bootmem_alloc so the code in add_memory_region can merge
-        * regions next to each other.
+        * When allocating memory, we want incrementing addresses,
+        * which is handled by memblock
         */
        cvmx_bootmem_lock();
        while (total < max_memory) {
                         */
                        if (memory < crashk_base && end >  crashk_end) {
                                /* region is fully in */
-                               add_memory_region(memory,
-                                                 crashk_base - memory,
-                                                 BOOT_MEM_RAM);
+                               memblock_add(memory, crashk_base - memory);
                                total += crashk_base - memory;
-                               add_memory_region(crashk_end,
-                                                 end - crashk_end,
-                                                 BOOT_MEM_RAM);
+                               memblock_add(crashk_end, end - crashk_end);
                                total += end - crashk_end;
                                continue;
                        }
                                 */
                                mem_alloc_size -= end - crashk_base;
 #endif
-                       add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
+                       memblock_add(memory, mem_alloc_size);
                        total += mem_alloc_size;
                        /* Recovering mem_alloc_size */
                        mem_alloc_size = 4 << 20;
 
        /* Adjust for physical offset. */
        kernel_start &= ~0xffffffff80000000ULL;
-       add_memory_region(kernel_start, kernel_size, BOOT_MEM_RAM);
+       memblock_add(kernel_start, kernel_size);
 #endif /* CONFIG_CRASH_DUMP */
 
 #ifdef CONFIG_CAVIUM_RESERVE32
 
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/ioport.h>
+#include <linux/memblock.h>
 #include <linux/pm.h>
 
 #include <asm/bootinfo.h>
                        strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
        }
 
-       add_memory_region(0x0, memsz, BOOT_MEM_RAM);
+       memblock_add(0, memsz);
 
        setup_8250_early_printk_port(CKSEG1ADDR(0x1c800000), 0, 0);
 }
 
 #include <linux/types.h>
 
 #include <asm/addrspace.h>
-#include <asm/bootinfo.h>
 #include <asm/dec/machtype.h>
 #include <asm/dec/prom.h>
 #include <asm/page.h>
        }
        memcpy((void *)(CKSEG0 + 0x80), &old_handler, 0x80);
 
-       add_memory_region(0, (unsigned long)memory_page - CKSEG1 - CHUNK_SIZE,
-                         BOOT_MEM_RAM);
+       memblock_add(0, (unsigned long)memory_page - CKSEG1 - CHUNK_SIZE);
 }
 
 /*
                else if (!mem_size)
                        mem_start += (8 * bm->pagesize);
                else {
-                       add_memory_region(mem_start, mem_size, BOOT_MEM_RAM);
+                       memblock_add(mem_start, mem_size);
                        mem_start += mem_size + (8 * bm->pagesize);
                        mem_size = 0;
                }
        }
        if (mem_size)
-               add_memory_region(mem_start, mem_size, BOOT_MEM_RAM);
+               memblock_add(mem_start, mem_size);
 }
 
 void __init prom_meminit(u32 magic)
 
                                                : arc_mtypes[a.arc]
 #endif
 
+enum {
+       mem_free, mem_prom_used, mem_reserved
+};
+
 static inline int memtype_classify_arcs(union linux_memtypes type)
 {
        switch (type.arcs) {
        case arcs_fcontig:
        case arcs_free:
-               return BOOT_MEM_RAM;
+               return mem_free;
        case arcs_atmp:
-               return BOOT_MEM_ROM_DATA;
+               return mem_prom_used;
        case arcs_eblock:
        case arcs_rvpage:
        case arcs_bmem:
        case arcs_prog:
        case arcs_aperm:
-               return BOOT_MEM_RESERVED;
+               return mem_reserved;
        default:
                BUG();
        }
        switch (type.arc) {
        case arc_free:
        case arc_fcontig:
-               return BOOT_MEM_RAM;
+               return mem_free;
        case arc_atmp:
-               return BOOT_MEM_ROM_DATA;
+               return mem_prom_used;
        case arc_eblock:
        case arc_rvpage:
        case arc_bmem:
        case arc_prog:
        case arc_aperm:
-               return BOOT_MEM_RESERVED;
+               return mem_reserved;
        default:
                BUG();
        }
                size = p->pages << ARC_PAGE_SHIFT;
                type = prom_memtype_classify(p->type);
 
-               add_memory_region(base, size, type);
+               /* ignore mirrored RAM on IP28/IP30 */
+               if (base < PHYS_OFFSET)
+                       continue;
+
+               memblock_add(base, size);
+
+               if (type == mem_reserved)
+                       memblock_reserve(base, size);
 
-               if (type == BOOT_MEM_ROM_DATA) {
+               if (type == mem_prom_used) {
+                       memblock_reserve(base, size);
                        if (nr_prom_mem >= 5) {
                                pr_err("Too many ROM DATA regions");
                                continue;
 
 
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/memblock.h>
 #include <linux/string.h>
 #include <linux/console.h>
 
                }
                pr_debug("Bank%d: %08x @ %08x\n", i,
                        memconf[i].size, memconf[i].base);
-               add_memory_region(memconf[i].base, memconf[i].size,
-                                 BOOT_MEM_RAM);
+               memblock_add(memconf[i].base, memconf[i].size);
        }
 }
 
 
 
 extern unsigned long mips_machtype;
 
-#define BOOT_MEM_RAM           1
-#define BOOT_MEM_ROM_DATA      2
-#define BOOT_MEM_RESERVED      3
-#define BOOT_MEM_INIT_RAM      4
-#define BOOT_MEM_NOMAP         5
-
-extern void add_memory_region(phys_addr_t start, phys_addr_t size, long type);
 extern void detect_memory_region(phys_addr_t start, phys_addr_t sz_min,  phys_addr_t sz_max);
 
 extern void prom_init(void);
 
                uint32_t type;          /* type of memory segment */
        } map[NLM_BOOT_MEM_MAP_MAX];
 };
+#define NLM_BOOT_MEM_RAM       1
 
 /* Pointer to saved boot loader info */
 extern struct psb_info nlm_prom_info;
 
 }
 
 #ifdef CONFIG_USE_OF
-void __init early_init_dt_add_memory_arch(u64 base, u64 size)
-{
-       if (base >= PHYS_ADDR_MAX) {
-               pr_warn("Trying to add an invalid memory region, skipped\n");
-               return;
-       }
-
-       /* Truncate the passed memory region instead of type casting */
-       if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) {
-               pr_warn("Truncate memory region %llx @ %llx to size %llx\n",
-                       size, base, PHYS_ADDR_MAX - base);
-               size = PHYS_ADDR_MAX - base;
-       }
-
-       add_memory_region(base, size, BOOT_MEM_RAM);
-}
-
-int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
-                                       phys_addr_t size, bool nomap)
-{
-       add_memory_region(base, size,
-                         nomap ? BOOT_MEM_NOMAP : BOOT_MEM_RESERVED);
-
-       return 0;
-}
 
 void __init __dt_setup_arch(void *bph)
 {
 
 EXPORT_SYMBOL(ARCH_PFN_OFFSET);
 #endif
 
-void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
-{
-       /*
-        * Note: This function only exists for historical reason,
-        * new code should use memblock_add or memblock_add_node instead.
-        */
-
-       /*
-        * If the region reaches the top of the physical address space, adjust
-        * the size slightly so that (start + size) doesn't overflow
-        */
-       if (start + size - 1 == PHYS_ADDR_MAX)
-               --size;
-
-       /* Sanity check */
-       if (start + size < start) {
-               pr_warn("Trying to add an invalid memory region, skipped\n");
-               return;
-       }
-
-       if (start < PHYS_OFFSET)
-               return;
-
-       memblock_add(start, size);
-       /* Reserve any memory except the ordinary RAM ranges. */
-       switch (type) {
-       case BOOT_MEM_RAM:
-               break;
-
-       case BOOT_MEM_NOMAP: /* Discard the range from the system. */
-               memblock_remove(start, size);
-               break;
-
-       default: /* Reserve the rest of the memory types at boot time */
-               memblock_reserve(start, size);
-               break;
-       }
-}
-
 void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
 {
        void *dm = &detect_magic;
                ((unsigned long long) sz_min) / SZ_1M,
                ((unsigned long long) sz_max) / SZ_1M);
 
-       add_memory_region(start, size, BOOT_MEM_RAM);
+       memblock_add(start, size);
 }
 
 /*
        if (*p == '@')
                start = memparse(p + 1, &p);
 
-       add_memory_region(start, size, BOOT_MEM_RAM);
+       memblock_add(start, size);
 
        return 0;
 }
 
        if (*p == '@') {
                start_at = memparse(p+1, &p);
-               add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
+               memblock_add(start_at, mem_size);
        } else if (*p == '#') {
                pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
                return -EINVAL;
        } else if (*p == '$') {
                start_at = memparse(p+1, &p);
-               add_memory_region(start_at, mem_size, BOOT_MEM_RESERVED);
+               memblock_add(start_at, mem_size);
+               memblock_reserve(start_at, mem_size);
        } else {
                pr_err("\"memmap\" invalid format!\n");
                return -EINVAL;
  * arch_mem_init - initialize memory management subsystem
  *
  *  o plat_mem_setup() detects the memory configuration and will record detected
- *    memory areas using add_memory_region.
+ *    memory areas using memblock_add.
  *
  * At this stage the memory configuration of the system is known to the
  * kernel but generic memory management system is still entirely uninitialized.
 
 
 void __init prom_init_memory(void)
 {
-       add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
-
-       add_memory_region(memsize << 20, LOONGSON_PCI_MEM_START - (memsize <<
-                               20), BOOT_MEM_RESERVED);
+       memblock_add(0x0, (memsize << 20));
 
 #ifdef CONFIG_CPU_SUPPORTS_ADDRWINCFG
        {
 
 #ifdef CONFIG_64BIT
        if (highmemsize > 0)
-               add_memory_region(LOONGSON_HIGHMEM_START,
-                                 highmemsize << 20, BOOT_MEM_RAM);
-
-       add_memory_region(LOONGSON_PCI_MEM_END + 1, LOONGSON_HIGHMEM_START -
-                         LOONGSON_PCI_MEM_END - 1, BOOT_MEM_RESERVED);
-
+               memblock_add(LOONGSON_HIGHMEM_START, highmemsize << 20);
 #endif /* !CONFIG_64BIT */
 }
 
 
 
 #include <linux/io.h>
 #include <linux/init.h>
+#include <linux/memblock.h>
 #include <linux/serial_reg.h>
-#include <asm/bootinfo.h>
 #include <asm/fw/fw.h>
 
 #include <loongson1.h>
 
 void __init plat_mem_setup(void)
 {
-       add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
+       memblock_add(0x0, (memsize << 20));
 }
 
                if (map[i] > 0x10000000 && map[i] < 0x20000000)
                        map[i] = 0x20000000;
 
-               add_memory_region(map[i], map[i+1] - map[i], BOOT_MEM_RAM);
+               memblock_add(map[i], map[i+1] - map[i]);
        }
 }
 
 
 
 #include <linux/kernel.h>
 #include <linux/serial_8250.h>
+#include <linux/memblock.h>
 #include <linux/pm.h>
 
 #include <asm/idle.h>
 
        bootm = (void *)(long)nlm_prom_info.psb_mem_map;
        for (i = 0; i < bootm->nr_map; i++) {
-               if (bootm->map[i].type != BOOT_MEM_RAM)
+               if (bootm->map[i].type != NLM_BOOT_MEM_RAM)
                        continue;
                start = bootm->map[i].addr;
                size   = bootm->map[i].size;
                if (i == 0 && start == 0 && size == 0x0c000000)
                        size = 0x0ff00000;
 
-               add_memory_region(start, size - pref_backup, BOOT_MEM_RAM);
+               memblock_add(start, size - pref_backup);
        }
 }
 
 
        if (memory_dtb)
                of_scan_flat_dt(early_init_dt_scan_memory, NULL);
        else if (soc_info.mem_size)
-               add_memory_region(soc_info.mem_base, soc_info.mem_size * SZ_1M,
-                                 BOOT_MEM_RAM);
+               memblock_add(soc_info.mem_base, soc_info.mem_size * SZ_1M);
        else
                detect_memory_region(soc_info.mem_base,
                                     soc_info.mem_size_min * SZ_1M,
 
 
        /* give all RAM to boot allocator,
         * except for the first 0x400 and the last 0x200 bytes */
-       add_memory_region(ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
+       memblock_add(ddrbase + 0x400, memsize - 0x600);
 }
 
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/memblock.h>
 #include <linux/mm.h>
 
 #include <asm/ip32/crime.h>
 
                printk("CRIME MC: bank %u base 0x%016Lx size %LuMiB\n",
                        bank, base, size >> 20);
-               add_memory_region(base, size, BOOT_MEM_RAM);
+               memblock_add(base, size);
        }
 }
 
 
                        if (initrd_start) {
                                if ((initrd_pstart > addr) &&
                                    (initrd_pstart < (addr + size))) {
-                                       add_memory_region(addr,
-                                                         initrd_pstart - addr,
-                                                         BOOT_MEM_RAM);
+                                       memblock_add(addr,
+                                                    initrd_pstart - addr);
                                        rd_flag = 1;
                                }
                                if ((initrd_pend > addr) &&
                                    (initrd_pend < (addr + size))) {
-                                       add_memory_region(initrd_pend,
-                                               (addr + size) - initrd_pend,
-                                                BOOT_MEM_RAM);
+                                       memblock_add(initrd_pend,
+                                               (addr + size) - initrd_pend);
                                        rd_flag = 1;
                                }
                        }
                                 */
                                if (size > 512)
                                        size -= 512;
-                               add_memory_region(addr, size, BOOT_MEM_RAM);
+                               memblock_add(addr, size);
                        }
                        board_mem_region_addrs[board_mem_region_count] = addr;
                        board_mem_region_sizes[board_mem_region_count] = size;
        }
 #ifdef CONFIG_BLK_DEV_INITRD
        if (initrd_start) {
-               add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
-                                 BOOT_MEM_RESERVED);
+               memblock_add(initrd_pstart, initrd_pend - initrd_pstart);
+               memblock_reserve(initrd_pstart, initrd_pend - initrd_pstart);
        }
 #endif
 }
 
  */
 #include <linux/init.h>
 #include <linux/kernel.h>
-#include <asm/bootinfo.h>
+#include <linux/memblock.h>
 #include <asm/txx9/generic.h>
 #include <asm/txx9/jmr3927.h>
 
        if ((tx3927_ccfgptr->ccfg & TX3927_CCFG_TLBOFF) == 0)
                pr_err("TX3927 TLB off\n");
 
-       add_memory_region(0, JMR3927_SDRAM_SIZE, BOOT_MEM_RAM);
+       memblock_add(0, JMR3927_SDRAM_SIZE);
        txx9_sio_putchar_init(TX3927_SIO_REG(1));
 }
 
  *  with this program; if not, write to the Free Software Foundation, Inc.,
  *  675 Mass Ave, Cambridge, MA 02139, USA.
  */
+
 #include <linux/init.h>
-#include <asm/bootinfo.h>
+#include <linux/memblock.h>
 #include <asm/txx9/generic.h>
 #include <asm/txx9/rbtx4927.h>
 
 void __init rbtx4927_prom_init(void)
 {
-       add_memory_region(0, tx4927_get_mem_size(), BOOT_MEM_RAM);
+       memblock_add(0, tx4927_get_mem_size());
        txx9_sio_putchar_init(TX4927_SIO_REG(0) & 0xfffffffffULL);
 }
 
 
 #include <linux/init.h>
 #include <linux/memblock.h>
-#include <asm/bootinfo.h>
 #include <asm/txx9/generic.h>
 #include <asm/txx9/rbtx4938.h>
 
 void __init rbtx4938_prom_init(void)
 {
-       add_memory_region(0, tx4938_get_mem_size(), BOOT_MEM_RAM);
+       memblock_add(0, tx4938_get_mem_size());
        txx9_sio_putchar_init(TX4938_SIO_REG(0) & 0xfffffffffULL);
 }
 
  */
 
 #include <linux/init.h>
-#include <asm/bootinfo.h>
+#include <linux/memblock.h>
 #include <asm/txx9/generic.h>
 #include <asm/txx9/rbtx4939.h>
 
                win = ____raw_readq(&tx4939_ddrcptr->win[i]);
                start = (unsigned long)(win >> 48);
                size = (((unsigned long)(win >> 32) & 0xffff) + 1) - start;
-               add_memory_region(start << 20, size << 20, BOOT_MEM_RAM);
+               memblock_add(start << 20, size << 20);
        }
        txx9_sio_putchar_init(TX4939_SIO_REG(0) & 0xfffffffffULL);
 }