aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThierry Reding2021-09-03 15:16:21 +0200
committerTom Warren2021-10-13 14:18:30 -0700
commitb9aad375917d4ae0dec5aedcdfa79929e1dbb730 (patch)
tree6b5ae83f42b3d4c77d3f7a84f37a488393f4e269 /lib
parent9019487608c8afe7d3fc34cb5192df064b60cdb7 (diff)
fdtdec: Support reserved-memory flags
Reserved memory nodes can have additional flags. Support reading and writing these flags to ensure that reserved memory nodes can be properly parsed and emitted. This converts support for the existing "no-map" flag to avoid extending the argument list for fdtdec_add_reserved_memory() to excessive length. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Warren <twarren@nvidia.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fdtdec.c28
-rw-r--r--lib/fdtdec_test.c4
-rw-r--r--lib/optee/optee.c3
3 files changed, 22 insertions, 13 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index a0ecc72b6cb..ad090ea51eb 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1294,7 +1294,7 @@ static int fdtdec_init_reserved_memory(void *blob)
int fdtdec_add_reserved_memory(void *blob, const char *basename,
const struct fdt_memory *carveout,
const char **compatibles, unsigned int count,
- uint32_t *phandlep, bool no_map)
+ uint32_t *phandlep, unsigned long flags)
{
fdt32_t cells[4] = {}, *ptr = cells;
uint32_t upper, lower, phandle;
@@ -1364,6 +1364,12 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
if (node < 0)
return node;
+ if (flags & FDTDEC_RESERVED_MEMORY_NO_MAP) {
+ err = fdt_setprop(blob, node, "no-map", NULL, 0);
+ if (err < 0)
+ return err;
+ }
+
if (phandlep) {
err = fdt_generate_phandle(blob, &phandle);
if (err < 0)
@@ -1394,12 +1400,6 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
if (err < 0)
return err;
- if (no_map) {
- err = fdt_setprop(blob, node, "no-map", NULL, 0);
- if (err < 0)
- return err;
- }
-
if (compatibles && count > 0) {
size_t length = 0, len = 0;
unsigned int i;
@@ -1432,7 +1432,8 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
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 char ***compatiblesp, unsigned int *countp)
+ const char ***compatiblesp, unsigned int *countp,
+ unsigned long *flags)
{
const fdt32_t *prop;
uint32_t phandle;
@@ -1519,13 +1520,20 @@ skip_compat:
carveout->end = carveout->start + size - 1;
+ if (flags) {
+ *flags = 0;
+
+ if (fdtdec_get_bool(blob, offset, "no-map"))
+ *flags |= FDTDEC_RESERVED_MEMORY_NO_MAP;
+ }
+
return 0;
}
int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
unsigned int index, const struct fdt_memory *carveout,
const char *name, const char **compatibles,
- unsigned int count)
+ unsigned int count, unsigned long flags)
{
uint32_t phandle;
int err, offset, len;
@@ -1533,7 +1541,7 @@ int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
void *prop;
err = fdtdec_add_reserved_memory(blob, name, carveout, compatibles,
- count, &phandle, false);
+ count, &phandle, flags);
if (err < 0) {
debug("failed to add reserved memory: %d\n", err);
return err;
diff --git a/lib/fdtdec_test.c b/lib/fdtdec_test.c
index 3af9fb5da60..85351c75ca2 100644
--- a/lib/fdtdec_test.c
+++ b/lib/fdtdec_test.c
@@ -190,7 +190,7 @@ static int make_fdt_carveout_device(void *fdt, uint32_t na, uint32_t ns)
CHECK(fdt_setprop(fdt, offset, "reg", cells, (na + ns) * sizeof(*cells)));
return fdtdec_set_carveout(fdt, name, "memory-region", 0, &carveout,
- "framebuffer", NULL, 0);
+ "framebuffer", NULL, 0, 0);
}
static int check_fdt_carveout(void *fdt, uint32_t address_cells,
@@ -215,7 +215,7 @@ static int check_fdt_carveout(void *fdt, uint32_t address_cells,
&expected.end, address_cells, size_cells);
CHECK(fdtdec_get_carveout(fdt, name, "memory-region", 0, &carveout,
- NULL, NULL, NULL));
+ NULL, NULL, NULL, NULL));
if ((carveout.start != expected.start) ||
(carveout.end != expected.end)) {
diff --git a/lib/optee/optee.c b/lib/optee/optee.c
index 3fbde934fb1..b0362240446 100644
--- a/lib/optee/optee.c
+++ b/lib/optee/optee.c
@@ -161,6 +161,7 @@ int optee_copy_fdt_nodes(void *new_blob)
.start = res.start,
.end = res.end,
};
+ unsigned long flags = FDTDEC_RESERVED_MEMORY_NO_MAP;
char *oldname, *nodename, *tmp;
oldname = strdup(name);
@@ -178,7 +179,7 @@ int optee_copy_fdt_nodes(void *new_blob)
nodename,
&carveout,
NULL, 0,
- NULL, true);
+ NULL, flags);
free(oldname);
if (ret < 0)