diff options
author | Thierry Reding <treding@nvidia.com> | 2021-09-03 15:16:19 +0200 |
---|---|---|
committer | Tom Warren <twarren@nvidia.com> | 2021-10-13 14:18:30 -0700 |
commit | 46cb067803bef50cb8a1334a56897d05b5f85e02 (patch) | |
tree | faafb8dd57963a9cb6359ccd7cd9f2beee04af84 /lib | |
parent | 4bf88ba76abb224b3ca258a2f502384ec6c86bd6 (diff) | |
download | u-boot-46cb067803bef50cb8a1334a56897d05b5f85e02.zip u-boot-46cb067803bef50cb8a1334a56897d05b5f85e02.tar.gz u-boot-46cb067803bef50cb8a1334a56897d05b5f85e02.tar.bz2 |
fdtdec: Support compatible string list for reserved memory
Reserved memory nodes can have a compatible string list to identify the
type of reserved memory that they represent. Support specifying an
optional compatible string list when creating these nodes.
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.c | 69 | ||||
-rw-r--r-- | lib/fdtdec_test.c | 4 | ||||
-rw-r--r-- | lib/optee/optee.c | 1 |
3 files changed, 70 insertions, 4 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 3ada77d..f124f05 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1293,6 +1293,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) { fdt32_t cells[4] = {}, *ptr = cells; @@ -1399,6 +1400,28 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename, return err; } + if (compatibles && count > 0) { + size_t length = 0, len = 0; + unsigned int i; + char *buffer; + + for (i = 0; i < count; i++) + length += strlen(compatibles[i]) + 1; + + buffer = malloc(length); + if (!buffer) + return -FDT_ERR_INTERNAL; + + for (i = 0; i < count; i++) + len += strlcpy(buffer + len, compatibles[i], + length - len) + 1; + + err = fdt_setprop(blob, node, "compatible", buffer, length); + free(buffer); + if (err < 0) + return err; + } + /* return the phandle for the new node for the caller to use */ if (phandlep) *phandlep = phandle; @@ -1408,7 +1431,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) + struct fdt_memory *carveout, const char **name, + const char ***compatiblesp, unsigned int *countp) { const fdt32_t *prop; uint32_t phandle; @@ -1446,6 +1470,45 @@ int fdtdec_get_carveout(const void *blob, const char *node, if (name) *name = fdt_get_name(blob, offset, NULL); + if (compatiblesp) { + const char **compatibles = NULL; + const char *start, *end, *ptr; + unsigned int count = 0; + + prop = fdt_getprop(blob, offset, "compatible", &len); + if (!prop) + goto skip_compat; + + start = ptr = (const char *)prop; + end = start + len; + + while (ptr < end) { + ptr = strchrnul(ptr, '\0'); + count++; + ptr++; + } + + compatibles = malloc(sizeof(ptr) * count); + if (!compatibles) + return -FDT_ERR_INTERNAL; + + ptr = start; + count = 0; + + while (ptr < end) { + compatibles[count] = ptr; + ptr = strchrnul(ptr, '\0'); + count++; + ptr++; + } + +skip_compat: + *compatiblesp = compatibles; + + if (countp) + *countp = count; + } + carveout->start = fdtdec_get_addr_size_auto_noparent(blob, offset, "reg", 0, &size, true); @@ -1461,6 +1524,7 @@ int fdtdec_get_carveout(const void *blob, const char *node, int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name, unsigned int index, const char *name, + const char **compatibles, unsigned int count, const struct fdt_memory *carveout) { uint32_t phandle; @@ -1468,7 +1532,8 @@ int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name, fdt32_t value; void *prop; - err = fdtdec_add_reserved_memory(blob, name, carveout, &phandle, false); + err = fdtdec_add_reserved_memory(blob, name, carveout, compatibles, + count, &phandle, false); 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 760aca2..72c3001 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, - "framebuffer", &carveout); + "framebuffer", NULL, 0, &carveout); } 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)); if ((carveout.start != expected.start) || (carveout.end != expected.end)) { diff --git a/lib/optee/optee.c b/lib/optee/optee.c index 766d0d9..3fbde93 100644 --- a/lib/optee/optee.c +++ b/lib/optee/optee.c @@ -177,6 +177,7 @@ int optee_copy_fdt_nodes(void *new_blob) ret = fdtdec_add_reserved_memory(new_blob, nodename, &carveout, + NULL, 0, NULL, true); free(oldname); |