aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2021-09-03 15:16:18 +0200
committerTom Warren <twarren@nvidia.com>2021-10-13 14:18:30 -0700
commit4bf88ba76abb224b3ca258a2f502384ec6c86bd6 (patch)
tree74ac3ca45b7a69addd61faf887b20a175e92aa16
parentd5598cfa9bcab50812b2b416af91c2a37be67531 (diff)
downloadu-boot-4bf88ba76abb224b3ca258a2f502384ec6c86bd6.zip
u-boot-4bf88ba76abb224b3ca258a2f502384ec6c86bd6.tar.gz
u-boot-4bf88ba76abb224b3ca258a2f502384ec6c86bd6.tar.bz2
fdtdec: Support retrieving the name of a carveout
When retrieving a given carveout for a device, allow callers to query the name. This helps differentiating between carveouts when there are more than one. This is also useful when copying carveouts to help assign a meaningful name that cannot always be guessed. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Warren <twarren@nvidia.com>
-rw-r--r--board/nvidia/p2371-2180/p2371-2180.c2
-rw-r--r--board/nvidia/p2771-0000/p2771-0000.c2
-rw-r--r--board/nvidia/p3450-0000/p3450-0000.c2
-rw-r--r--include/fdtdec.h8
-rw-r--r--lib/fdtdec.c12
-rw-r--r--lib/fdtdec_test.c3
6 files changed, 18 insertions, 11 deletions
diff --git a/board/nvidia/p2371-2180/p2371-2180.c b/board/nvidia/p2371-2180/p2371-2180.c
index 7423a97..1f7aa00 100644
--- a/board/nvidia/p2371-2180/p2371-2180.c
+++ b/board/nvidia/p2371-2180/p2371-2180.c
@@ -128,7 +128,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node)
struct fdt_memory fb;
int err;
- err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb);
+ err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL);
if (err < 0) {
if (err != -FDT_ERR_NOTFOUND)
printf("failed to get carveout for %s: %d\n", node,
diff --git a/board/nvidia/p2771-0000/p2771-0000.c b/board/nvidia/p2771-0000/p2771-0000.c
index 508c4d2..aca86c3 100644
--- a/board/nvidia/p2771-0000/p2771-0000.c
+++ b/board/nvidia/p2771-0000/p2771-0000.c
@@ -104,7 +104,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node)
struct fdt_memory fb;
int err;
- err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb);
+ err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL);
if (err < 0) {
if (err != -FDT_ERR_NOTFOUND)
printf("failed to get carveout for %s: %d\n", node,
diff --git a/board/nvidia/p3450-0000/p3450-0000.c b/board/nvidia/p3450-0000/p3450-0000.c
index e6b6696..7c1e753 100644
--- a/board/nvidia/p3450-0000/p3450-0000.c
+++ b/board/nvidia/p3450-0000/p3450-0000.c
@@ -127,7 +127,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node)
struct fdt_memory fb;
int err;
- err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb);
+ err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL);
if (err < 0) {
if (err != -FDT_ERR_NOTFOUND)
printf("failed to get carveout for %s: %d\n", node,
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 23efbe7..f961f03 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -1038,14 +1038,16 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
*
* @param blob FDT blob
* @param node name of a node
- * @param name name of the property in the given node that contains
+ * @param prop_name name of the property in the given node that contains
* the phandle for the carveout
* @param index index of the phandle for which to read the carveout
* @param carveout return location for the carveout information
+ * @param name return location for the carveout name
* @return 0 on success or a negative error code on failure
*/
-int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
- unsigned int index, struct fdt_memory *carveout);
+int fdtdec_get_carveout(const void *blob, const char *node,
+ const char *prop_name, unsigned int index,
+ struct fdt_memory *carveout, const char **name);
/**
* fdtdec_set_carveout() - sets a carveout region for a given node
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index f2861eb..3ada77d 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1406,8 +1406,9 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
return 0;
}
-int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
- unsigned int index, struct fdt_memory *carveout)
+int fdtdec_get_carveout(const void *blob, const char *node,
+ const char *prop_name, unsigned int index,
+ struct fdt_memory *carveout, const char **name)
{
const fdt32_t *prop;
uint32_t phandle;
@@ -1418,9 +1419,9 @@ int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
if (offset < 0)
return offset;
- prop = fdt_getprop(blob, offset, name, &len);
+ prop = fdt_getprop(blob, offset, prop_name, &len);
if (!prop) {
- debug("failed to get %s for %s\n", name, node);
+ debug("failed to get %s for %s\n", prop_name, node);
return -FDT_ERR_NOTFOUND;
}
@@ -1442,6 +1443,9 @@ int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
return offset;
}
+ if (name)
+ *name = fdt_get_name(blob, offset, NULL);
+
carveout->start = fdtdec_get_addr_size_auto_noparent(blob, offset,
"reg", 0, &size,
true);
diff --git a/lib/fdtdec_test.c b/lib/fdtdec_test.c
index e0c6e09..760aca2 100644
--- a/lib/fdtdec_test.c
+++ b/lib/fdtdec_test.c
@@ -214,7 +214,8 @@ static int check_fdt_carveout(void *fdt, uint32_t address_cells,
printf("carveout: %pap-%pap na=%u ns=%u: ", &expected.start,
&expected.end, address_cells, size_cells);
- CHECK(fdtdec_get_carveout(fdt, name, "memory-region", 0, &carveout));
+ CHECK(fdtdec_get_carveout(fdt, name, "memory-region", 0, &carveout,
+ NULL));
if ((carveout.start != expected.start) ||
(carveout.end != expected.end)) {