2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7 * Copyright (C) 2013 Imagination Technologies Ltd.
9 #include <linux/init.h>
10 #include <linux/libfdt.h>
11 #include <linux/of_platform.h>
12 #include <linux/of_fdt.h>
13 #include <linux/bootmem.h>
16 #include <asm/fw/fw.h>
18 #include <asm/mips-boards/generic.h>
20 const char *get_system_type(void)
25 static uint32_t get_memsize_from_cmdline(void)
28 char *p = arcs_cmdline;
34 memsize = memparse(p, NULL);
40 static uint32_t get_memsize_from_env(void)
45 p = fw_getenv("memsize");
47 memsize = memparse(p, NULL);
52 static uint32_t get_memsize(void)
56 memsize = get_memsize_from_cmdline();
60 return get_memsize_from_env();
63 static void __init parse_memsize_param(void)
66 const uint64_t *prop_value;
68 uint32_t memsize = get_memsize();
73 offset = fdt_path_offset(&__dtb_start, "/memory");
77 * reg contains 2 32-bits BE values, offset and size. We just
78 * want to replace the size value without affecting the offset
80 prop_value = fdt_getprop(&__dtb_start, offset, "reg", &prop_len);
81 new_value = be64_to_cpu(*prop_value);
82 new_value = (new_value & ~0xffffffffllu) | memsize;
83 fdt_setprop_inplace_u64(&__dtb_start, offset, "reg", new_value);
87 void __init plat_mem_setup(void)
89 /* allow command line/bootloader env to override memory size in DT */
90 parse_memsize_param();
93 * Load the builtin devicetree. This causes the chosen node to be
94 * parsed resulting in our memory appearing
96 __dt_setup_arch(&__dtb_start);
99 void __init device_tree_init(void)
101 unsigned long base, size;
103 if (!initial_boot_params)
106 base = virt_to_phys((void *)initial_boot_params);
107 size = be32_to_cpu(initial_boot_params->totalsize);
109 /* Before we do anything, lets reserve the dt blob */
110 reserve_bootmem(base, size, BOOTMEM_DEFAULT);
112 unflatten_device_tree();