mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
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>
This commit is contained in:
parent
d5598cfa9b
commit
4bf88ba76a
6 changed files with 18 additions and 11 deletions
|
@ -128,7 +128,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node)
|
||||||
struct fdt_memory fb;
|
struct fdt_memory fb;
|
||||||
int err;
|
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 < 0) {
|
||||||
if (err != -FDT_ERR_NOTFOUND)
|
if (err != -FDT_ERR_NOTFOUND)
|
||||||
printf("failed to get carveout for %s: %d\n", node,
|
printf("failed to get carveout for %s: %d\n", node,
|
||||||
|
|
|
@ -104,7 +104,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node)
|
||||||
struct fdt_memory fb;
|
struct fdt_memory fb;
|
||||||
int err;
|
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 < 0) {
|
||||||
if (err != -FDT_ERR_NOTFOUND)
|
if (err != -FDT_ERR_NOTFOUND)
|
||||||
printf("failed to get carveout for %s: %d\n", node,
|
printf("failed to get carveout for %s: %d\n", node,
|
||||||
|
|
|
@ -127,7 +127,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node)
|
||||||
struct fdt_memory fb;
|
struct fdt_memory fb;
|
||||||
int err;
|
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 < 0) {
|
||||||
if (err != -FDT_ERR_NOTFOUND)
|
if (err != -FDT_ERR_NOTFOUND)
|
||||||
printf("failed to get carveout for %s: %d\n", node,
|
printf("failed to get carveout for %s: %d\n", node,
|
||||||
|
|
|
@ -1038,14 +1038,16 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
|
||||||
*
|
*
|
||||||
* @param blob FDT blob
|
* @param blob FDT blob
|
||||||
* @param node name of a node
|
* @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
|
* the phandle for the carveout
|
||||||
* @param index index of the phandle for which to read the carveout
|
* @param index index of the phandle for which to read the carveout
|
||||||
* @param carveout return location for the carveout information
|
* @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
|
* @return 0 on success or a negative error code on failure
|
||||||
*/
|
*/
|
||||||
int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
|
int fdtdec_get_carveout(const void *blob, const char *node,
|
||||||
unsigned int index, struct fdt_memory *carveout);
|
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
|
* fdtdec_set_carveout() - sets a carveout region for a given node
|
||||||
|
|
12
lib/fdtdec.c
12
lib/fdtdec.c
|
@ -1406,8 +1406,9 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
|
int fdtdec_get_carveout(const void *blob, const char *node,
|
||||||
unsigned int index, struct fdt_memory *carveout)
|
const char *prop_name, unsigned int index,
|
||||||
|
struct fdt_memory *carveout, const char **name)
|
||||||
{
|
{
|
||||||
const fdt32_t *prop;
|
const fdt32_t *prop;
|
||||||
uint32_t phandle;
|
uint32_t phandle;
|
||||||
|
@ -1418,9 +1419,9 @@ int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return offset;
|
return offset;
|
||||||
|
|
||||||
prop = fdt_getprop(blob, offset, name, &len);
|
prop = fdt_getprop(blob, offset, prop_name, &len);
|
||||||
if (!prop) {
|
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;
|
return -FDT_ERR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1442,6 +1443,9 @@ int fdtdec_get_carveout(const void *blob, const char *node, const char *name,
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
*name = fdt_get_name(blob, offset, NULL);
|
||||||
|
|
||||||
carveout->start = fdtdec_get_addr_size_auto_noparent(blob, offset,
|
carveout->start = fdtdec_get_addr_size_auto_noparent(blob, offset,
|
||||||
"reg", 0, &size,
|
"reg", 0, &size,
|
||||||
true);
|
true);
|
||||||
|
|
|
@ -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,
|
printf("carveout: %pap-%pap na=%u ns=%u: ", &expected.start,
|
||||||
&expected.end, address_cells, size_cells);
|
&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) ||
|
if ((carveout.start != expected.start) ||
|
||||||
(carveout.end != expected.end)) {
|
(carveout.end != expected.end)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue