All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory
@ 2020-07-10 12:40 Michal Simek
  2020-07-10 12:40 ` [PATCH v2 1/3] lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest() Michal Simek
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Michal Simek @ 2020-07-10 12:40 UTC (permalink / raw)
  To: u-boot

Hi,

Generated DTS files don't need to have memory nodes sorted out that's why
it can happen that the first memory node is not pointing to lowest DDR
which is normally used for system boot. That's why new function was
introduced which finds out the lowest memory available and use it for
u-boot and later can be also used for OS.

The series is based on
https://lists.denx.de/pipermail/u-boot/2020-July/419656.html
which simplified conversion to livetree API which was asked by Simon.

And also I keep conversion to livetree in separate patch on the top of v1
which shouldn't be a problem.

The series is still missing tests which Simon asked for but I would like to
get feedback about these patches. If they are fine I would like to have
discussion how/where to write little test for it.

Thanks,
Michal

Changes in v2:
- Separate Xilinx change from generic patch
- new patch asked by Simon
- split from generic patch sent in v1

Michal Simek (3):
  lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest()
  lib: fdt: Convert fdtdes_setup_mem..() to livetree API
  xilinx: versal: Use lowest memory for U-Boot

 board/xilinx/versal/board.c |  2 +-
 include/fdtdec.h            | 17 +++++++
 lib/fdtdec.c                | 90 ++++++++++++++++++++++++++++---------
 3 files changed, 87 insertions(+), 22 deletions(-)

-- 
2.27.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/3] lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest()
  2020-07-10 12:40 [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek
@ 2020-07-10 12:40 ` Michal Simek
  2020-07-15  1:05   ` Simon Glass
  2020-07-10 12:40 ` [PATCH v2 2/3] lib: fdt: Convert fdtdes_setup_mem..() to livetree API Michal Simek
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Michal Simek @ 2020-07-10 12:40 UTC (permalink / raw)
  To: u-boot

New function should be called from board dram_init() because it initialized
gd->ram_base/ram_size. It finds the lowest available memory.

On systems with multiple memory nodes finding out the first memory node by
fdtdec_setup_mem_size_base() is not enough because this memory can be above
actual U-Boot VA mapping. Currently only mapping till 39bit is supported
(Full 44bit mapping was removed by commit 7985cdf74b28 ("arm64: Remove
non-full-va map code")).
If DT starts with the first memory node above 39bit address then system can
be unpredictable.

The function is available only when multiple memory bank support is
enabled.

Calling fdtdec_setup_memory_banksize() from dram_init() is not possible
because fdtdec_setup_memory_banksize() is saving dram information to bd
structure which is placed on stack but not initialized at this time. Also
stack is placed at location setup in dram_init().

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v2:
- Separate Xilinx change from generic patch

 include/fdtdec.h | 17 +++++++++++++++++
 lib/fdtdec.c     | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 760b392bdfbc..bc79389260ab 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -926,6 +926,23 @@ int fdtdec_decode_display_timing(const void *blob, int node, int index,
  */
 int fdtdec_setup_mem_size_base(void);
 
+/**
+ * fdtdec_setup_mem_size_base_lowest() - decode and setup gd->ram_size and
+ * gd->ram_start by lowest available memory base
+ *
+ * Decode the /memory 'reg' property to determine the lowest start of the memory
+ * bank bank and populate the global data with it.
+ *
+ * This function should be called from a boards dram_init(). This helper
+ * function allows for boards to query the device tree for DRAM size and start
+ * address instead of hard coding the value in the case where the memory size
+ * and start address cannot be detected automatically.
+ *
+ * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or
+ * invalid
+ */
+int fdtdec_setup_mem_size_base_lowest(void);
+
 /**
  * fdtdec_setup_memory_banksize() - decode and populate gd->bd->bi_dram
  *
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index fa523ce2e908..a10120baa895 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1106,6 +1106,51 @@ int fdtdec_setup_memory_banksize(void)
 
 	return 0;
 }
+
+int fdtdec_setup_mem_size_base_lowest(void)
+{
+	int bank, ret, mem, reg = 0;
+	struct fdt_resource res;
+	unsigned long base;
+	phys_size_t size;
+	const void *blob = gd->fdt_blob;
+
+	gd->ram_base = (unsigned long)~0;
+
+	mem = get_next_memory_node(blob, -1);
+	if (mem < 0) {
+		debug("%s: Missing /memory node\n", __func__);
+		return -EINVAL;
+	}
+
+	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+		ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
+		if (ret == -FDT_ERR_NOTFOUND) {
+			reg = 0;
+			mem = get_next_memory_node(blob, mem);
+			if (mem == -FDT_ERR_NOTFOUND)
+				break;
+
+			ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
+			if (ret == -FDT_ERR_NOTFOUND)
+				break;
+		}
+		if (ret != 0)
+			return -EINVAL;
+
+		base = (unsigned long)res.start;
+		size = (phys_size_t)(res.end - res.start + 1);
+
+		if (gd->ram_base > base && size) {
+			gd->ram_base = base;
+			gd->ram_size = size;
+			debug("%s: Initial DRAM base %lx size %lx\n",
+			      __func__, base, (unsigned long)size);
+		}
+	}
+
+	return 0;
+}
 #endif
 
 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] lib: fdt: Convert fdtdes_setup_mem..() to livetree API
  2020-07-10 12:40 [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek
  2020-07-10 12:40 ` [PATCH v2 1/3] lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest() Michal Simek
@ 2020-07-10 12:40 ` Michal Simek
  2020-07-15  1:05   ` Simon Glass
  2020-07-10 12:40 ` [PATCH v2 3/3] xilinx: versal: Use lowest memory for U-Boot Michal Simek
  2020-07-24 12:17 ` [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek
  3 siblings, 1 reply; 7+ messages in thread
From: Michal Simek @ 2020-07-10 12:40 UTC (permalink / raw)
  To: u-boot

Convert fdtdec_setup_mem_size_base(), get_next_memory_node(),
fdtdec_setup_memory_banksize() and fdtdec_setup_mem_size_base_lowest() to
livetree API.

Tested on ZynqMP zcu104 board.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v2:
- new patch asked by Simon

 lib/fdtdec.c | 67 +++++++++++++++++++++++++++-------------------------
 1 file changed, 35 insertions(+), 32 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index a10120baa895..39d73006e131 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -24,6 +24,7 @@
 #include <asm/sections.h>
 #include <linux/ctype.h>
 #include <linux/lzo.h>
+#include <linux/ioport.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -1032,16 +1033,17 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index,
 
 int fdtdec_setup_mem_size_base(void)
 {
-	int ret, mem;
-	struct fdt_resource res;
+	int ret;
+	ofnode mem;
+	struct resource res;
 
-	mem = fdt_path_offset(gd->fdt_blob, "/memory");
-	if (mem < 0) {
+	mem = ofnode_path("/memory");
+	if (!ofnode_valid(mem)) {
 		debug("%s: Missing /memory node\n", __func__);
 		return -EINVAL;
 	}
 
-	ret = fdt_get_resource(gd->fdt_blob, mem, "reg", 0, &res);
+	ret = ofnode_read_resource(mem, 0, &res);
 	if (ret != 0) {
 		debug("%s: Unable to decode first memory bank\n", __func__);
 		return -EINVAL;
@@ -1057,42 +1059,42 @@ int fdtdec_setup_mem_size_base(void)
 
 #if defined(CONFIG_NR_DRAM_BANKS)
 
-static int get_next_memory_node(const void *blob, int mem)
+ofnode get_next_memory_node(ofnode mem)
 {
 	do {
-		mem = fdt_node_offset_by_prop_value(gd->fdt_blob, mem,
-						    "device_type", "memory", 7);
-	} while (!fdtdec_get_is_enabled(blob, mem));
+		mem = ofnode_by_prop_value(mem, "device_type", "memory", 7);
+	} while (!ofnode_is_available(mem));
 
 	return mem;
 }
 
 int fdtdec_setup_memory_banksize(void)
 {
-	int bank, ret, mem, reg = 0;
-	struct fdt_resource res;
+	int bank, ret, reg = 0;
+	struct resource res;
+	ofnode mem = ofnode_null();
 
-	mem = get_next_memory_node(gd->fdt_blob, -1);
-	if (mem < 0) {
+	mem = get_next_memory_node(mem);
+	if (!ofnode_valid(mem)) {
 		debug("%s: Missing /memory node\n", __func__);
 		return -EINVAL;
 	}
 
 	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-		ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res);
-		if (ret == -FDT_ERR_NOTFOUND) {
+		ret = ofnode_read_resource(mem, reg++, &res);
+		if (ret < 0) {
 			reg = 0;
-			mem = get_next_memory_node(gd->fdt_blob, mem);
-			if (mem == -FDT_ERR_NOTFOUND)
+			mem = get_next_memory_node(mem);
+			if (ofnode_valid(mem))
 				break;
 
-			ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res);
-			if (ret == -FDT_ERR_NOTFOUND)
+			ret = ofnode_read_resource(mem, reg++, &res);
+			if (ret < 0)
 				break;
 		}
-		if (ret != 0) {
+
+		if (ret != 0)
 			return -EINVAL;
-		}
 
 		gd->bd->bi_dram[bank].start = (phys_addr_t)res.start;
 		gd->bd->bi_dram[bank].size =
@@ -1109,32 +1111,33 @@ int fdtdec_setup_memory_banksize(void)
 
 int fdtdec_setup_mem_size_base_lowest(void)
 {
-	int bank, ret, mem, reg = 0;
-	struct fdt_resource res;
+	int bank, ret, reg = 0;
+	struct resource res;
 	unsigned long base;
 	phys_size_t size;
-	const void *blob = gd->fdt_blob;
+	ofnode mem = ofnode_null();
 
 	gd->ram_base = (unsigned long)~0;
 
-	mem = get_next_memory_node(blob, -1);
-	if (mem < 0) {
+	mem = get_next_memory_node(mem);
+	if (!ofnode_valid(mem)) {
 		debug("%s: Missing /memory node\n", __func__);
 		return -EINVAL;
 	}
 
 	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-		ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
-		if (ret == -FDT_ERR_NOTFOUND) {
+		ret = ofnode_read_resource(mem, reg++, &res);
+		if (ret < 0) {
 			reg = 0;
-			mem = get_next_memory_node(blob, mem);
-			if (mem == -FDT_ERR_NOTFOUND)
+			mem = get_next_memory_node(mem);
+			if (ofnode_valid(mem))
 				break;
 
-			ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
-			if (ret == -FDT_ERR_NOTFOUND)
+			ret = ofnode_read_resource(mem, reg++, &res);
+			if (ret < 0)
 				break;
 		}
+
 		if (ret != 0)
 			return -EINVAL;
 
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/3] xilinx: versal: Use lowest memory for U-Boot
  2020-07-10 12:40 [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek
  2020-07-10 12:40 ` [PATCH v2 1/3] lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest() Michal Simek
  2020-07-10 12:40 ` [PATCH v2 2/3] lib: fdt: Convert fdtdes_setup_mem..() to livetree API Michal Simek
@ 2020-07-10 12:40 ` Michal Simek
  2020-07-24 12:17 ` [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek
  3 siblings, 0 replies; 7+ messages in thread
From: Michal Simek @ 2020-07-10 12:40 UTC (permalink / raw)
  To: u-boot

Find and use the lowest memory for Versal to make sure that we keep u-boot
as low as possible and never use memory above u-boot's maximum VA mapping.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v2:
- split from generic patch sent in v1

 board/xilinx/versal/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 45cf1d2d0cad..3dc7044b213e 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -229,7 +229,7 @@ int dram_init_banksize(void)
 
 int dram_init(void)
 {
-	if (fdtdec_setup_mem_size_base() != 0)
+	if (fdtdec_setup_mem_size_base_lowest() != 0)
 		return -EINVAL;
 
 	return 0;
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 1/3] lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest()
  2020-07-10 12:40 ` [PATCH v2 1/3] lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest() Michal Simek
@ 2020-07-15  1:05   ` Simon Glass
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Glass @ 2020-07-15  1:05 UTC (permalink / raw)
  To: u-boot

On Fri, 10 Jul 2020 at 06:41, Michal Simek <michal.simek@xilinx.com> wrote:
>
> New function should be called from board dram_init() because it initialized
> gd->ram_base/ram_size. It finds the lowest available memory.
>
> On systems with multiple memory nodes finding out the first memory node by
> fdtdec_setup_mem_size_base() is not enough because this memory can be above
> actual U-Boot VA mapping. Currently only mapping till 39bit is supported
> (Full 44bit mapping was removed by commit 7985cdf74b28 ("arm64: Remove
> non-full-va map code")).
> If DT starts with the first memory node above 39bit address then system can
> be unpredictable.
>
> The function is available only when multiple memory bank support is
> enabled.
>
> Calling fdtdec_setup_memory_banksize() from dram_init() is not possible
> because fdtdec_setup_memory_banksize() is saving dram information to bd
> structure which is placed on stack but not initialized at this time. Also
> stack is placed at location setup in dram_init().
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> Changes in v2:
> - Separate Xilinx change from generic patch
>
>  include/fdtdec.h | 17 +++++++++++++++++
>  lib/fdtdec.c     | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 62 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] lib: fdt: Convert fdtdes_setup_mem..() to livetree API
  2020-07-10 12:40 ` [PATCH v2 2/3] lib: fdt: Convert fdtdes_setup_mem..() to livetree API Michal Simek
@ 2020-07-15  1:05   ` Simon Glass
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Glass @ 2020-07-15  1:05 UTC (permalink / raw)
  To: u-boot

On Fri, 10 Jul 2020 at 06:41, Michal Simek <michal.simek@xilinx.com> wrote:
>
> Convert fdtdec_setup_mem_size_base(), get_next_memory_node(),
> fdtdec_setup_memory_banksize() and fdtdec_setup_mem_size_base_lowest() to
> livetree API.
>
> Tested on ZynqMP zcu104 board.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> Changes in v2:
> - new patch asked by Simon
>
>  lib/fdtdec.c | 67 +++++++++++++++++++++++++++-------------------------
>  1 file changed, 35 insertions(+), 32 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory
  2020-07-10 12:40 [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek
                   ` (2 preceding siblings ...)
  2020-07-10 12:40 ` [PATCH v2 3/3] xilinx: versal: Use lowest memory for U-Boot Michal Simek
@ 2020-07-24 12:17 ` Michal Simek
  3 siblings, 0 replies; 7+ messages in thread
From: Michal Simek @ 2020-07-24 12:17 UTC (permalink / raw)
  To: u-boot

p? 10. 7. 2020 v 14:40 odes?latel Michal Simek <michal.simek@xilinx.com> napsal:
>
> Hi,
>
> Generated DTS files don't need to have memory nodes sorted out that's why
> it can happen that the first memory node is not pointing to lowest DDR
> which is normally used for system boot. That's why new function was
> introduced which finds out the lowest memory available and use it for
> u-boot and later can be also used for OS.
>
> The series is based on
> https://lists.denx.de/pipermail/u-boot/2020-July/419656.html
> which simplified conversion to livetree API which was asked by Simon.
>
> And also I keep conversion to livetree in separate patch on the top of v1
> which shouldn't be a problem.
>
> The series is still missing tests which Simon asked for but I would like to
> get feedback about these patches. If they are fine I would like to have
> discussion how/where to write little test for it.
>
> Thanks,
> Michal
>
> Changes in v2:
> - Separate Xilinx change from generic patch
> - new patch asked by Simon
> - split from generic patch sent in v1
>
> Michal Simek (3):
>   lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest()
>   lib: fdt: Convert fdtdes_setup_mem..() to livetree API
>   xilinx: versal: Use lowest memory for U-Boot
>
>  board/xilinx/versal/board.c |  2 +-
>  include/fdtdec.h            | 17 +++++++
>  lib/fdtdec.c                | 90 ++++++++++++++++++++++++++++---------
>  3 files changed, 87 insertions(+), 22 deletions(-)
>
> --
> 2.27.0
>

Applied all.
M

-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-24 12:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 12:40 [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek
2020-07-10 12:40 ` [PATCH v2 1/3] lib: fdt: Introduce fdtdec_setup_mem_size_base_lowest() Michal Simek
2020-07-15  1:05   ` Simon Glass
2020-07-10 12:40 ` [PATCH v2 2/3] lib: fdt: Convert fdtdes_setup_mem..() to livetree API Michal Simek
2020-07-15  1:05   ` Simon Glass
2020-07-10 12:40 ` [PATCH v2 3/3] xilinx: versal: Use lowest memory for U-Boot Michal Simek
2020-07-24 12:17 ` [PATCH v2 0/3] xilinx: Enable Versal allocation from low memory Michal Simek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.