All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Tom Warren <twarren@nvidia.com>
Cc: Simon Glass <sjg@chromium.org>, u-boot@lists.denx.de
Subject: [PATCH 6/9] ARM: tegra: Support multiple reserved memory regions
Date: Fri,  3 Sep 2021 15:16:22 +0200	[thread overview]
Message-ID: <20210903131625.2153838-7-thierry.reding@gmail.com> (raw)
In-Reply-To: <20210903131625.2153838-1-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

Support multiple reserved memory regions per device to support platforms
that use both a framebuffer and color conversion lookup table for early
boot display splash.

While at it, also pass along the name, compatible strings and flags of
the carveouts.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 board/nvidia/p2371-2180/p2371-2180.c | 55 +++++++++++++++++++++-------
 board/nvidia/p2771-0000/p2771-0000.c | 55 +++++++++++++++++++++-------
 board/nvidia/p3450-0000/p3450-0000.c | 55 +++++++++++++++++++++-------
 3 files changed, 126 insertions(+), 39 deletions(-)

diff --git a/board/nvidia/p2371-2180/p2371-2180.c b/board/nvidia/p2371-2180/p2371-2180.c
index 137c7d3b12c3..f5126c552b00 100644
--- a/board/nvidia/p2371-2180/p2371-2180.c
+++ b/board/nvidia/p2371-2180/p2371-2180.c
@@ -10,6 +10,7 @@
 #include <i2c.h>
 #include <log.h>
 #include <net.h>
+#include <stdlib.h>
 #include <linux/bitops.h>
 #include <linux/libfdt.h>
 #include <asm/arch/gpio.h>
@@ -125,24 +126,52 @@ static void ft_mac_address_setup(void *fdt)
 
 static int ft_copy_carveout(void *dst, const void *src, const char *node)
 {
-	struct fdt_memory fb;
+	unsigned int index = 0;
 	int err;
 
-	err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL,
-				  NULL, NULL, NULL);
-	if (err < 0) {
-		if (err != -FDT_ERR_NOTFOUND)
-			printf("failed to get carveout for %s: %d\n", node,
+	while (true) {
+		const char **compatibles = NULL;
+		unsigned int num_compatibles;
+		struct fdt_memory carveout;
+		unsigned long flags;
+		char *copy = NULL;
+		const char *name;
+
+		err = fdtdec_get_carveout(src, node, "memory-region", index,
+					  &carveout, &name, &compatibles,
+					  &num_compatibles, &flags);
+		if (err < 0) {
+			if (err != -FDT_ERR_NOTFOUND)
+				printf("failed to get carveout for %s: %d\n",
+				       node, err);
+
+			return err;
+		}
+
+		if (name) {
+			const char *ptr = strchr(name, '@');
+
+			if (ptr) {
+				copy = strndup(name, ptr - name);
+				name = copy;
+			}
+		} else {
+			name = "carveout";
+		}
+
+		err = fdtdec_set_carveout(dst, node, "memory-region", index,
+					  &carveout, name, compatibles,
+					  num_compatibles, flags);
+		if (err < 0) {
+			printf("failed to set carveout for %s: %d\n", node,
 			       err);
+			return err;
+		}
 
-		return err;
-	}
+		if (copy)
+			free(copy);
 
-	err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb,
-				  "framebuffer", NULL, 0, 0);
-	if (err < 0) {
-		printf("failed to set carveout for %s: %d\n", node, err);
-		return err;
+		index++;
 	}
 
 	return 0;
diff --git a/board/nvidia/p2771-0000/p2771-0000.c b/board/nvidia/p2771-0000/p2771-0000.c
index 3d2653d1f075..46c36a22db5e 100644
--- a/board/nvidia/p2771-0000/p2771-0000.c
+++ b/board/nvidia/p2771-0000/p2771-0000.c
@@ -9,6 +9,7 @@
 #include <i2c.h>
 #include <log.h>
 #include <net.h>
+#include <stdlib.h>
 #include <linux/libfdt.h>
 #include <asm/arch-tegra/cboot.h>
 #include "../p2571/max77620_init.h"
@@ -101,24 +102,52 @@ static void ft_mac_address_setup(void *fdt)
 
 static int ft_copy_carveout(void *dst, const void *src, const char *node)
 {
-	struct fdt_memory fb;
+	unsigned int index = 0;
 	int err;
 
-	err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL,
-				  NULL, NULL, NULL);
-	if (err < 0) {
-		if (err != -FDT_ERR_NOTFOUND)
-			printf("failed to get carveout for %s: %d\n", node,
+	while (true) {
+		const char **compatibles = NULL;
+		unsigned int num_compatibles;
+		struct fdt_memory carveout;
+		unsigned long flags;
+		char *copy = NULL;
+		const char *name;
+
+		err = fdtdec_get_carveout(src, node, "memory-region", index,
+					  &carveout, &name, &compatibles,
+					  &num_compatibles, &flags);
+		if (err < 0) {
+			if (err != -FDT_ERR_NOTFOUND)
+				printf("failed to get carveout for %s: %d\n",
+				       node, err);
+
+			return err;
+		}
+
+		if (name) {
+			const char *ptr = strchr(name, '@');
+
+			if (ptr) {
+				copy = strndup(name, ptr - name);
+				name = copy;
+			}
+		} else {
+			name = "carveout";
+		}
+
+		err = fdtdec_set_carveout(dst, node, "memory-region", index,
+					  &carveout, name, compatibles,
+					  num_compatibles, flags);
+		if (err < 0) {
+			printf("failed to set carveout for %s: %d\n", node,
 			       err);
+			return err;
+		}
 
-		return err;
-	}
+		if (copy)
+			free(copy);
 
-	err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb,
-				  "framebuffer", NULL, 0, 0);
-	if (err < 0) {
-		printf("failed to set carveout for %s: %d\n", node, err);
-		return err;
+		index++;
 	}
 
 	return 0;
diff --git a/board/nvidia/p3450-0000/p3450-0000.c b/board/nvidia/p3450-0000/p3450-0000.c
index cdedea18a176..2c709d9b8117 100644
--- a/board/nvidia/p3450-0000/p3450-0000.c
+++ b/board/nvidia/p3450-0000/p3450-0000.c
@@ -12,6 +12,7 @@
 #include <linux/bitops.h>
 #include <linux/libfdt.h>
 #include <pca953x.h>
+#include <stdlib.h>
 #include <asm/arch-tegra/cboot.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/pinmux.h>
@@ -125,24 +126,52 @@ static void ft_mac_address_setup(void *fdt)
 
 static int ft_copy_carveout(void *dst, const void *src, const char *node)
 {
-	struct fdt_memory fb;
+	unsigned int index = 0;
 	int err;
 
-	err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL,
-				  NULL, NULL, NULL);
-	if (err < 0) {
-		if (err != -FDT_ERR_NOTFOUND)
-			printf("failed to get carveout for %s: %d\n", node,
+	while (true) {
+		const char **compatibles = NULL;
+		unsigned int num_compatibles;
+		struct fdt_memory carveout;
+		unsigned long flags;
+		char *copy = NULL;
+		const char *name;
+
+		err = fdtdec_get_carveout(src, node, "memory-region", index,
+					  &carveout, &name, &compatibles,
+					  &num_compatibles, &flags);
+		if (err < 0) {
+			if (err != -FDT_ERR_NOTFOUND)
+				printf("failed to get carveout for %s: %d\n",
+				       node, err);
+
+			return err;
+		}
+
+		if (name) {
+			const char *ptr = strchr(name, '@');
+
+			if (ptr) {
+				copy = strndup(name, ptr - name);
+				name = copy;
+			}
+		} else {
+			name = "carveout";
+		}
+
+		err = fdtdec_set_carveout(dst, node, "memory-region", index,
+					  &carveout, name, compatibles,
+					  num_compatibles, flags);
+		if (err < 0) {
+			printf("failed to set carveout for %s: %d\n", node,
 			       err);
+			return err;
+		}
 
-		return err;
-	}
+		if (copy)
+			free(copy);
 
-	err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb,
-				  "framebuffer", NULL, 0, 0);
-	if (err < 0) {
-		printf("failed to set carveout for %s: %d\n", node, err);
-		return err;
+		index++;
 	}
 
 	return 0;
-- 
2.33.0


  parent reply	other threads:[~2021-09-03 13:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 13:16 [PATCH 0/9] ARM: tegra: Support EMC frequency tables on Tegra210 Thierry Reding
2021-09-03 13:16 ` [PATCH 1/9] fdtdec: Allow using fdtdec_get_carveout() in loops Thierry Reding
2021-09-30  4:09   ` Simon Glass
2021-09-03 13:16 ` [PATCH 2/9] fdtdec: Support retrieving the name of a carveout Thierry Reding
2021-09-30  4:09   ` Simon Glass
2021-09-03 13:16 ` [PATCH 3/9] fdtdec: Support compatible string list for reserved memory Thierry Reding
2021-09-30  4:09   ` Simon Glass
2021-09-03 13:16 ` [PATCH 4/9] fdtdec: Reorder fdtdec_set_carveout() parameters for consistency Thierry Reding
2021-09-30  4:09   ` Simon Glass
2021-09-03 13:16 ` [PATCH 5/9] fdtdec: Support reserved-memory flags Thierry Reding
2021-09-30  4:09   ` Simon Glass
2021-09-03 13:16 ` Thierry Reding [this message]
2021-09-30  4:08   ` [PATCH 6/9] ARM: tegra: Support multiple reserved memory regions Simon Glass
2021-09-03 13:16 ` [PATCH 7/9] ARM: tegra: Support EMC frequency tables on Tegra210 Thierry Reding
2021-09-30  4:08   ` Simon Glass
2021-09-03 13:16 ` [PATCH 8/9] ARM: tegra: Refactor DT update helpers Thierry Reding
2021-09-30  4:08   ` Simon Glass
2021-09-03 13:16 ` [PATCH 9/9] ARM: tegra: Copy memory-region-names property Thierry Reding
2021-09-30  4:08   ` Simon Glass

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=20210903131625.2153838-7-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=sjg@chromium.org \
    --cc=twarren@nvidia.com \
    --cc=u-boot@lists.denx.de \
    /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 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.