From: Thierry Reding
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
---
board/nvidia/p2371-2180/p2371-2180.c | 2 +-
board/nvidia/p2771-/p2771-.c | 2 +-
board/nvidia/p3450-/p3450-.c | 2 +-
include/fdtdec.h | 8 +---
lib/fdtdec.c | 12
lib/fdtdec_test.c| 3 ++-
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 7423a97ad0e3..1f7aa0050cde 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, );
+ err = fdtdec_get_carveout(src, node, "memory-region", 0, , 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-/p2771-.c
b/board/nvidia/p2771-/p2771-.c
index 508c4d27b7fb..aca86c342680 100644
--- a/board/nvidia/p2771-/p2771-.c
+++ b/board/nvidia/p2771-/p2771-.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, );
+ err = fdtdec_get_carveout(src, node, "memory-region", 0, , 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-/p3450-.c
b/board/nvidia/p3450-/p3450-.c
index f4741cfd1e4a..132eb824c675 100644
--- a/board/nvidia/p3450-/p3450-.c
+++ b/board/nvidia/p3450-/p3450-.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, );
+ err = fdtdec_get_carveout(src, node, "memory-region", 0, , 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 8ac20c9a64f7..265ee54d41be 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -1071,14 +1071,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_namename of the property in the given node that contains
* the phandle for the carveout
* @param indexindex 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 7f6b6d523232..19b8efb0d302 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1444,8 +1444,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;
@@ -1456,9 +1457,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, );
+ prop = fdt_getprop(blob, offset, prop_name, );
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;
}
@@ -1480,6 +1481,9 @@ int fdtdec_get_carveout(const void