linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Burton <paul.burton@imgtec.com>
To: <linux-mips@linux-mips.org>, Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paul.burton@imgtec.com>,
	Matt Redfearn <matt.redfearn@imgtec.com>,
	Rob Herring <robh@kernel.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2 13/19] MIPS: SEAD3: Parse memsize in DT shim
Date: Fri, 26 Aug 2016 15:17:45 +0100	[thread overview]
Message-ID: <20160826141751.13121-14-paul.burton@imgtec.com> (raw)
In-Reply-To: <20160826141751.13121-1-paul.burton@imgtec.com>

Parse the memsize argument provided by the bootloader in the DT shim
code, allowing the user to override it on the command line. This places
all of the DT manipulation code into sead3-dtshim.c.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

Changes in v2: None

 arch/mips/mti-sead3/sead3-dtshim.c | 71 ++++++++++++++++++++++++++++++++++++++
 arch/mips/mti-sead3/sead3-setup.c  | 66 -----------------------------------
 2 files changed, 71 insertions(+), 66 deletions(-)

diff --git a/arch/mips/mti-sead3/sead3-dtshim.c b/arch/mips/mti-sead3/sead3-dtshim.c
index 6e32ceb..d6b0708 100644
--- a/arch/mips/mti-sead3/sead3-dtshim.c
+++ b/arch/mips/mti-sead3/sead3-dtshim.c
@@ -22,6 +22,73 @@
 
 static unsigned char fdt_buf[16 << 10] __initdata;
 
+static int append_memory(void *fdt)
+{
+	unsigned long phys_memsize, memsize;
+	__be32 mem_array[2];
+	int err, mem_off;
+	char *var;
+
+	/* find memory size from the bootloader environment */
+	var = fw_getenv("memsize");
+	if (var) {
+		err = kstrtoul(var, 0, &phys_memsize);
+		if (err) {
+			pr_err("Failed to read memsize env variable '%s'\n",
+			       var);
+			return -EINVAL;
+		}
+	} else {
+		pr_warn("The bootloader didn't provide memsize: defaulting to 32MB\n");
+		phys_memsize = 32 << 20;
+	}
+
+	/* default to using all available RAM */
+	memsize = phys_memsize;
+
+	/* allow the user to override the usable memory */
+	var = strstr(arcs_cmdline, "memsize=");
+	if (var)
+		memsize = memparse(var + strlen("memsize="), NULL);
+
+	/* if the user says there's more RAM than we thought, believe them */
+	phys_memsize = max_t(unsigned long, phys_memsize, memsize);
+
+	/* find or add a memory node */
+	mem_off = fdt_path_offset(fdt, "/memory");
+	if (mem_off == -FDT_ERR_NOTFOUND)
+		mem_off = fdt_add_subnode(fdt, 0, "memory");
+	if (mem_off < 0) {
+		pr_err("Unable to find or add memory DT node: %d\n", mem_off);
+		return mem_off;
+	}
+
+	err = fdt_setprop_string(fdt, mem_off, "device_type", "memory");
+	if (err) {
+		pr_err("Unable to set memory node device_type: %d\n", err);
+		return err;
+	}
+
+	mem_array[0] = 0;
+	mem_array[1] = cpu_to_be32(phys_memsize);
+	err = fdt_setprop(fdt, mem_off, "reg", mem_array, sizeof(mem_array));
+	if (err) {
+		pr_err("Unable to set memory regs property: %d\n", err);
+		return err;
+	}
+
+	mem_array[0] = 0;
+	mem_array[1] = cpu_to_be32(memsize);
+	err = fdt_setprop(fdt, mem_off, "linux,usable-memory",
+			  mem_array, sizeof(mem_array));
+	if (err) {
+		pr_err("Unable to set linux,usable-memory property: %d\n", err);
+		return err;
+	}
+
+	return 0;
+}
+
 static int remove_gic(void *fdt)
 {
 	const unsigned int cpu_ehci_int = 2;
@@ -205,6 +272,10 @@ void __init *sead3_dt_shim(void *fdt)
 	if (err)
 		panic("Unable to open FDT: %d", err);
 
+	err = append_memory(fdt_buf);
+	if (err)
+		panic("Unable to patch FDT: %d", err);
+
 	err = remove_gic(fdt_buf);
 	if (err)
 		panic("Unable to patch FDT: %d", err);
diff --git a/arch/mips/mti-sead3/sead3-setup.c b/arch/mips/mti-sead3/sead3-setup.c
index c4fc0c6..c915e54 100644
--- a/arch/mips/mti-sead3/sead3-setup.c
+++ b/arch/mips/mti-sead3/sead3-setup.c
@@ -11,7 +11,6 @@
 #include <linux/of_fdt.h>
 
 #include <asm/prom.h>
-#include <asm/fw/fw.h>
 
 #include <asm/mach-sead3/sead3-dtshim.h>
 #include <asm/mips-boards/generic.h>
@@ -21,68 +20,6 @@ const char *get_system_type(void)
 	return "MIPS SEAD3";
 }
 
-static uint32_t get_memsize_from_cmdline(void)
-{
-	int memsize = 0;
-	char *p = arcs_cmdline;
-	char *s = "memsize=";
-
-	p = strstr(p, s);
-	if (p) {
-		p += strlen(s);
-		memsize = memparse(p, NULL);
-	}
-
-	return memsize;
-}
-
-static uint32_t get_memsize_from_env(void)
-{
-	int memsize = 0;
-	char *p;
-
-	p = fw_getenv("memsize");
-	if (p)
-		memsize = memparse(p, NULL);
-
-	return memsize;
-}
-
-static uint32_t get_memsize(void)
-{
-	uint32_t memsize;
-
-	memsize = get_memsize_from_cmdline();
-	if (memsize)
-		return memsize;
-
-	return get_memsize_from_env();
-}
-
-static void __init parse_memsize_param(void)
-{
-	int offset;
-	const uint64_t *prop_value;
-	int prop_len;
-	uint32_t memsize = get_memsize();
-
-	if (!memsize)
-		return;
-
-	offset = fdt_path_offset(__dtb_start, "/memory");
-	if (offset > 0) {
-		uint64_t new_value;
-		/*
-		 * reg contains 2 32-bits BE values, offset and size. We just
-		 * want to replace the size value without affecting the offset
-		 */
-		prop_value = fdt_getprop(__dtb_start, offset, "reg", &prop_len);
-		new_value = be64_to_cpu(*prop_value);
-		new_value =  (new_value & ~0xffffffffllu) | memsize;
-		fdt_setprop_inplace_u64(__dtb_start, offset, "reg", new_value);
-	}
-}
-
 void __init *plat_get_fdt(void)
 {
 	return (void *)__dtb_start;
@@ -92,9 +29,6 @@ void __init plat_mem_setup(void)
 {
 	void *fdt = plat_get_fdt();
 
-	/* allow command line/bootloader env to override memory size in DT */
-	parse_memsize_param();
-
 	fdt = sead3_dt_shim(fdt);
 	__dt_setup_arch(fdt);
 }
-- 
2.9.3

  parent reply	other threads:[~2016-08-26 14:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-26 14:17 [PATCH v2 00/19] MIPS: SEAD3 device tree conversion Paul Burton
2016-08-26 14:17 ` [PATCH v2 01/19] MIPS: SEAD3: Split obj-y entries across lines Paul Burton
2016-08-26 14:17 ` [PATCH v2 02/19] MIPS: SEAD3: Probe interrupt controllers using DT Paul Burton
2016-08-26 14:17 ` [PATCH v2 03/19] MIPS: SEAD3: Probe UARTs " Paul Burton
2016-08-26 14:17 ` [PATCH v2 04/19] MIPS: SEAD3: Use generic ns16550a earlycon support Paul Burton
2016-08-26 14:17 ` [PATCH v2 05/19] MIPS: SEAD3: Probe ethernet controller using DT Paul Burton
2016-08-26 14:17 ` [PATCH v2 06/19] MIPS: SEAD3: Probe EHCI " Paul Burton
2016-08-26 14:17 ` [PATCH v2 07/19] usb: host: ehci-sead3: Remove SEAD-3 EHCI code Paul Burton
2016-08-26 15:55   ` Alan Stern
2016-08-26 14:17 ` [PATCH v2 08/19] SEAD3: Probe parallel flash via DT Paul Burton
2016-08-26 14:17 ` [PATCH v2 09/19] MIPS: SEAD3: Use register-bit-led driver via DT for LEDs Paul Burton
2016-08-26 14:17 ` [PATCH v2 10/19] leds: Remove SEAD3 driver Paul Burton
2016-08-29  8:55   ` Jacek Anaszewski
2016-08-30 14:42     ` Paul Burton
2016-08-26 14:17 ` [PATCH v2 11/19] MIPS: SEAD3: Reset via generic syscon-reboot driver & DT Paul Burton
2016-08-26 14:17 ` [PATCH v2 12/19] MIPS: SEAD3: Use generic restart-poweroff driver Paul Burton
2016-08-26 14:17 ` Paul Burton [this message]
2016-08-26 14:17 ` [PATCH v2 14/19] MIPS: SEAD3: Drop use of cobalt fbdev driver Paul Burton
2016-08-26 14:17 ` [PATCH v2 15/19] fbdev: cobalt_lcdfb: Drop SEAD3 support Paul Burton
2016-08-26 14:17 ` [PATCH v2 16/19] dt-bindings: img-ascii-lcd: Document a binding for simple ASCII LCDs Paul Burton
2016-08-31 16:18   ` Rob Herring
2016-08-26 14:17 ` [PATCH v2 17/19] auxdisplay: img-ascii-lcd: driver for simple ASCII LCD displays Paul Burton
2016-09-27 18:52   ` Ralf Baechle
2016-08-26 14:17 ` [PATCH v2 18/19] MIPS: SEAD3: Use img-ascii-lcd driver Paul Burton
2016-08-26 14:17 ` [PATCH v2 19/19] MIPS: SEAD3: Remove custom read_persistent_clock Paul Burton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160826141751.13121-14-paul.burton@imgtec.com \
    --to=paul.burton@imgtec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=matt.redfearn@imgtec.com \
    --cc=ralf@linux-mips.org \
    --cc=robh@kernel.org \
    --cc=wangkefeng.wang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).