Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1470741

[PATCH v2 13/19] MIPS: SEAD3: Parse memsize in DT shim

From Paul Burton <paul.burton@imgtec.com>
Newsgroups linux.kernel
Subject [PATCH v2 13/19] MIPS: SEAD3: Parse memsize in DT shim
Date 2016-08-26 16:30 +0200
Message-ID <saqiR-8az-7@gated-at.bofh.it> (permalink)
References <saq9c-879-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 00/19] MIPS: SEAD3 device tree conversion Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:20 +0200
  [PATCH v2 13/19] MIPS: SEAD3: Parse memsize in DT shim Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 16/19] dt-bindings: img-ascii-lcd: Document a binding for simple ASCII LCDs Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
    Re: [PATCH v2 16/19] dt-bindings: img-ascii-lcd: Document a binding  for simple ASCII LCDs Rob Herring <robh@kernel.org> - 2016-08-31 18:20 +0200
  [PATCH v2 14/19] MIPS: SEAD3: Drop use of cobalt fbdev driver Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 08/19] SEAD3: Probe parallel flash via DT Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 06/19] MIPS: SEAD3: Probe EHCI controller using DT Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 15/19] fbdev: cobalt_lcdfb: Drop SEAD3 support Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 11/19] MIPS: SEAD3: Reset via generic syscon-reboot driver & DT Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 02/19] MIPS: SEAD3: Probe interrupt controllers using DT Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 09/19] MIPS: SEAD3: Use register-bit-led driver via DT for LEDs Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 04/19] MIPS: SEAD3: Use generic ns16550a earlycon support Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 03/19] MIPS: SEAD3: Probe UARTs using DT Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 07/19] usb: host: ehci-sead3: Remove SEAD-3 EHCI code Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
    Re: [PATCH v2 07/19] usb: host: ehci-sead3: Remove SEAD-3 EHCI code Alan Stern <stern@rowland.harvard.edu> - 2016-08-26 18:00 +0200
  [PATCH v2 12/19] MIPS: SEAD3: Use generic restart-poweroff driver Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 18/19] MIPS: SEAD3: Use img-ascii-lcd driver Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 10/19] leds: Remove SEAD3 driver Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
    Re: [PATCH v2 10/19] leds: Remove SEAD3 driver Jacek Anaszewski <j.anaszewski@samsung.com> - 2016-08-29 11:00 +0200
      Re: [PATCH v2 10/19] leds: Remove SEAD3 driver Paul Burton <paul.burton@imgtec.com> - 2016-08-30 16:50 +0200
  [PATCH v2 05/19] MIPS: SEAD3: Probe ethernet controller using DT Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 17/19] auxdisplay: img-ascii-lcd: driver for simple ASCII LCD displays Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:30 +0200
  [PATCH v2 01/19] MIPS: SEAD3: Split obj-y entries across lines Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:40 +0200
  [PATCH v2 19/19] MIPS: SEAD3: Remove custom read_persistent_clock Paul Burton <paul.burton@imgtec.com> - 2016-08-26 16:50 +0200

csiph-web