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>
15 #include <asm/fw/fw.h>
17 #include <asm/mips-boards/generic.h>
19 const char *get_system_type(void)
24 static uint32_t get_memsize_from_cmdline(void)
27 char *p
= arcs_cmdline
;
33 memsize
= memparse(p
, NULL
);
39 static uint32_t get_memsize_from_env(void)
44 p
= fw_getenv("memsize");
46 memsize
= memparse(p
, NULL
);
51 static uint32_t get_memsize(void)
55 memsize
= get_memsize_from_cmdline();
59 return get_memsize_from_env();
62 static void __init
parse_memsize_param(void)
65 const uint64_t *prop_value
;
67 uint32_t memsize
= get_memsize();
72 offset
= fdt_path_offset(__dtb_start
, "/memory");
76 * reg contains 2 32-bits BE values, offset and size. We just
77 * want to replace the size value without affecting the offset
79 prop_value
= fdt_getprop(__dtb_start
, offset
, "reg", &prop_len
);
80 new_value
= be64_to_cpu(*prop_value
);
81 new_value
= (new_value
& ~0xffffffffllu
) | memsize
;
82 fdt_setprop_inplace_u64(__dtb_start
, offset
, "reg", new_value
);
86 void __init
plat_mem_setup(void)
88 /* allow command line/bootloader env to override memory size in DT */
89 parse_memsize_param();
92 * Load the builtin devicetree. This causes the chosen node to be
93 * parsed resulting in our memory appearing
95 __dt_setup_arch(__dtb_start
);
98 void __init
device_tree_init(void)
100 if (!initial_boot_params
)
103 unflatten_and_copy_device_tree();
106 static int __init
customize_machine(void)
108 of_platform_populate(NULL
, of_default_bus_match_table
, NULL
, NULL
);
111 arch_initcall(customize_machine
);