aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips
diff options
context:
space:
mode:
authorQais Yousef <qais.yousef@imgtec.com>2013-12-06 06:00:42 -0500
committerRalf Baechle <ralf@linux-mips.org>2014-01-23 07:02:36 -0500
commit44327236c3bfb83e3b4ce36e2a0d61569bb19330 (patch)
tree76e87d019bfd1670671fed35f385b7a47a5a836d /arch/mips
parente95acd3d0d3a7bac9bca50c51a1d86777b6334eb (diff)
MIPS: sead3: allow cmdline/env to change memory size using memsize param
if the user sets memsize parameter in commandline or bootloader environment, we use it to modify the built-in dtb memory size Signed-off-by: Qais Yousef <qais.yousef@imgtec.com> Reviewed-by: Paul Burton <paul.burton@imgtec.com> Reviewed-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: John Crispin <blogic@openwrt.org> Patchwork: http://patchwork.linux-mips.org/patch/6207/
Diffstat (limited to 'arch/mips')
-rw-r--r--arch/mips/Kconfig1
-rw-r--r--arch/mips/mti-sead3/Makefile2
-rw-r--r--arch/mips/mti-sead3/sead3-setup.c68
3 files changed, 71 insertions, 0 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 517748eb1229..b79b5388857f 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -344,6 +344,7 @@ config MIPS_SEAD3
344 select DMA_NONCOHERENT 344 select DMA_NONCOHERENT
345 select IRQ_CPU 345 select IRQ_CPU
346 select IRQ_GIC 346 select IRQ_GIC
347 select LIBFDT
347 select MIPS_MSC 348 select MIPS_MSC
348 select SYS_HAS_CPU_MIPS32_R1 349 select SYS_HAS_CPU_MIPS32_R1
349 select SYS_HAS_CPU_MIPS32_R2 350 select SYS_HAS_CPU_MIPS32_R2
diff --git a/arch/mips/mti-sead3/Makefile b/arch/mips/mti-sead3/Makefile
index be114209217c..071786fa234b 100644
--- a/arch/mips/mti-sead3/Makefile
+++ b/arch/mips/mti-sead3/Makefile
@@ -21,5 +21,7 @@ obj-$(CONFIG_EARLY_PRINTK) += sead3-console.o
21obj-$(CONFIG_USB_EHCI_HCD) += sead3-ehci.o 21obj-$(CONFIG_USB_EHCI_HCD) += sead3-ehci.o
22obj-$(CONFIG_OF) += sead3.dtb.o 22obj-$(CONFIG_OF) += sead3.dtb.o
23 23
24CFLAGS_sead3-setup.o = -I$(src)/../../../scripts/dtc/libfdt
25
24$(obj)/%.dtb: $(obj)/%.dts 26$(obj)/%.dtb: $(obj)/%.dts
25 $(call if_changed,dtc) 27 $(call if_changed,dtc)
diff --git a/arch/mips/mti-sead3/sead3-setup.c b/arch/mips/mti-sead3/sead3-setup.c
index 928ba84c8a78..a499f9940fd7 100644
--- a/arch/mips/mti-sead3/sead3-setup.c
+++ b/arch/mips/mti-sead3/sead3-setup.c
@@ -4,13 +4,16 @@
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7 * Copyright (C) 2013 Imagination Technologies Ltd.
7 */ 8 */
8#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/libfdt.h>
9#include <linux/of_platform.h> 11#include <linux/of_platform.h>
10#include <linux/of_fdt.h> 12#include <linux/of_fdt.h>
11#include <linux/bootmem.h> 13#include <linux/bootmem.h>
12 14
13#include <asm/prom.h> 15#include <asm/prom.h>
16#include <asm/fw/fw.h>
14 17
15#include <asm/mips-boards/generic.h> 18#include <asm/mips-boards/generic.h>
16 19
@@ -19,8 +22,73 @@ const char *get_system_type(void)
19 return "MIPS SEAD3"; 22 return "MIPS SEAD3";
20} 23}
21 24
25static uint32_t get_memsize_from_cmdline(void)
26{
27 int memsize = 0;
28 char *p = arcs_cmdline;
29 char *s = "memsize=";
30
31 p = strstr(p, s);
32 if (p) {
33 p += strlen(s);
34 memsize = memparse(p, NULL);
35 }
36
37 return memsize;
38}
39
40static uint32_t get_memsize_from_env(void)
41{
42 int memsize = 0;
43 char *p;
44
45 p = fw_getenv("memsize");
46 if (p)
47 memsize = memparse(p, NULL);
48
49 return memsize;
50}
51
52static uint32_t get_memsize(void)
53{
54 uint32_t memsize;
55
56 memsize = get_memsize_from_cmdline();
57 if (memsize)
58 return memsize;
59
60 return get_memsize_from_env();
61}
62
63static void __init parse_memsize_param(void)
64{
65 int offset;
66 const uint64_t *prop_value;
67 int prop_len;
68 uint32_t memsize = get_memsize();
69
70 if (!memsize)
71 return;
72
73 offset = fdt_path_offset(&__dtb_start, "/memory");
74 if (offset > 0) {
75 uint64_t new_value;
76 /*
77 * reg contains 2 32-bits BE values, offset and size. We just
78 * want to replace the size value without affecting the offset
79 */
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);
84 }
85}
86
22void __init plat_mem_setup(void) 87void __init plat_mem_setup(void)
23{ 88{
89 /* allow command line/bootloader env to override memory size in DT */
90 parse_memsize_param();
91
24 /* 92 /*
25 * Load the builtin devicetree. This causes the chosen node to be 93 * Load the builtin devicetree. This causes the chosen node to be
26 * parsed resulting in our memory appearing 94 * parsed resulting in our memory appearing