From 46cb067803bef50cb8a1334a56897d05b5f85e02 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Fri, 3 Sep 2021 15:16:19 +0200 Subject: 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 Reviewed-by: Simon Glass Signed-off-by: Tom Warren --- arch/arm/cpu/armv8/fsl-layerscape/soc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/arm') diff --git a/arch/arm/cpu/armv8/fsl-layerscape/soc.c b/arch/arm/cpu/armv8/fsl-layerscape/soc.c index 41f3e95019b..4f17c327af7 100644 --- a/arch/arm/cpu/armv8/fsl-layerscape/soc.c +++ b/arch/arm/cpu/armv8/fsl-layerscape/soc.c @@ -54,7 +54,8 @@ int ls_gic_rd_tables_init(void *blob) lpi_base.start = addr; lpi_base.end = addr + size - 1; - ret = fdtdec_add_reserved_memory(blob, "lpi_rd_table", &lpi_base, NULL, false); + ret = fdtdec_add_reserved_memory(blob, "lpi_rd_table", &lpi_base, NULL, + NULL, 0, false); if (ret) { debug("%s: failed to add reserved memory\n", __func__); return ret; -- cgit v1.2.3 From b9aad375917d4ae0dec5aedcdfa79929e1dbb730 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Fri, 3 Sep 2021 15:16:21 +0200 Subject: 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 Reviewed-by: Simon Glass Signed-off-by: Tom Warren --- arch/arm/cpu/armv8/fsl-layerscape/soc.c | 2 +- arch/riscv/lib/fdt_fixup.c | 2 +- board/nvidia/p2371-2180/p2371-2180.c | 4 ++-- board/nvidia/p2771-0000/p2771-0000.c | 4 ++-- board/nvidia/p3450-0000/p3450-0000.c | 4 ++-- include/fdtdec.h | 20 +++++++++++++------- lib/fdtdec.c | 28 ++++++++++++++++++---------- lib/fdtdec_test.c | 4 ++-- lib/optee/optee.c | 3 ++- test/dm/fdtdec.c | 13 +++++++------ 10 files changed, 50 insertions(+), 34 deletions(-) (limited to 'arch/arm') diff --git a/arch/arm/cpu/armv8/fsl-layerscape/soc.c b/arch/arm/cpu/armv8/fsl-layerscape/soc.c index 4f17c327af7..adf3b4eea56 100644 --- a/arch/arm/cpu/armv8/fsl-layerscape/soc.c +++ b/arch/arm/cpu/armv8/fsl-layerscape/soc.c @@ -55,7 +55,7 @@ int ls_gic_rd_tables_init(void *blob) lpi_base.start = addr; lpi_base.end = addr + size - 1; ret = fdtdec_add_reserved_memory(blob, "lpi_rd_table", &lpi_base, NULL, - NULL, 0, false); + NULL, 0, 0); if (ret) { debug("%s: failed to add reserved memory\n", __func__); return ret; diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c index 7ac30a4f7c9..36c16e9be2a 100644 --- a/arch/riscv/lib/fdt_fixup.c +++ b/arch/riscv/lib/fdt_fixup.c @@ -75,7 +75,7 @@ int riscv_fdt_copy_resv_mem_node(const void *src, void *dst) pmp_mem.start = addr; pmp_mem.end = addr + size - 1; err = fdtdec_add_reserved_memory(dst, basename, &pmp_mem, - NULL, 0, &phandle, false); + NULL, 0, &phandle, 0); if (err < 0 && err != -FDT_ERR_EXISTS) { log_err("failed to add reserved memory: %d\n", err); return err; diff --git a/board/nvidia/p2371-2180/p2371-2180.c b/board/nvidia/p2371-2180/p2371-2180.c index bc0a133725e..137c7d3b12c 100644 --- a/board/nvidia/p2371-2180/p2371-2180.c +++ b/board/nvidia/p2371-2180/p2371-2180.c @@ -129,7 +129,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) int err; err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL, - NULL, NULL); + NULL, NULL, NULL); if (err < 0) { if (err != -FDT_ERR_NOTFOUND) printf("failed to get carveout for %s: %d\n", node, @@ -139,7 +139,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) } err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb, - "framebuffer", NULL, 0); + "framebuffer", NULL, 0, 0); if (err < 0) { printf("failed to set carveout for %s: %d\n", node, err); return err; diff --git a/board/nvidia/p2771-0000/p2771-0000.c b/board/nvidia/p2771-0000/p2771-0000.c index cde5eff02f2..3d2653d1f07 100644 --- a/board/nvidia/p2771-0000/p2771-0000.c +++ b/board/nvidia/p2771-0000/p2771-0000.c @@ -105,7 +105,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) int err; err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL, - NULL, NULL); + NULL, NULL, NULL); if (err < 0) { if (err != -FDT_ERR_NOTFOUND) printf("failed to get carveout for %s: %d\n", node, @@ -115,7 +115,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) } err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb, - "framebuffer", NULL, 0); + "framebuffer", NULL, 0, 0); if (err < 0) { printf("failed to set carveout for %s: %d\n", node, err); return err; diff --git a/board/nvidia/p3450-0000/p3450-0000.c b/board/nvidia/p3450-0000/p3450-0000.c index e737fc1dab8..2770862a495 100644 --- a/board/nvidia/p3450-0000/p3450-0000.c +++ b/board/nvidia/p3450-0000/p3450-0000.c @@ -128,7 +128,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) int err; err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb, NULL, - NULL, NULL); + NULL, NULL, NULL); if (err < 0) { if (err != -FDT_ERR_NOTFOUND) printf("failed to get carveout for %s: %d\n", node, @@ -138,7 +138,7 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) } err = fdtdec_set_carveout(dst, node, "memory-region", 0, &fb, - "framebuffer", NULL, 0); + "framebuffer", NULL, 0, 0); if (err < 0) { printf("failed to set carveout for %s: %d\n", node, err); return err; diff --git a/include/fdtdec.h b/include/fdtdec.h index d360d7bce4e..f94d1f4f3ab 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -977,6 +977,9 @@ static inline int fdtdec_set_phandle(void *blob, int node, uint32_t phandle) return fdt_setprop_u32(blob, node, "phandle", phandle); } +/* add "no-map" property */ +#define FDTDEC_RESERVED_MEMORY_NO_MAP (1 << 0) + /** * fdtdec_add_reserved_memory() - add or find a reserved-memory node * @@ -996,7 +999,7 @@ static inline int fdtdec_set_phandle(void *blob, int node, uint32_t phandle) * uint32_t phandle; * * fdtdec_add_reserved_memory(fdt, "framebuffer", &fb, NULL, 0, &phandle, - * false); + * 0); * * This results in the following subnode being added to the top-level * /reserved-memory node: @@ -1025,13 +1028,13 @@ static inline int fdtdec_set_phandle(void *blob, int node, uint32_t phandle) * @param count number of compatible strings for the carveout region * @param phandlep return location for the phandle of the carveout region * can be NULL if no phandle should be added - * @param no_map add "no-map" property if true + * @param flags bitmask of flags to set for the carveout region * @return 0 on success or a negative error code on failure */ 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); /** * fdtdec_get_carveout() - reads a carveout from an FDT @@ -1048,13 +1051,15 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename, * @param carveout return location for the carveout information * @param name return location for the carveout name * @param compatiblesp return location for compatible strings - * @param countp return location for the number of compatible strings + * @param countp return location for the number of compatible strings + * @param flags return location for the flags of the carveout * @return 0 on success or a negative error code on failure */ 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); /** * fdtdec_set_carveout() - sets a carveout region for a given node @@ -1073,7 +1078,7 @@ int fdtdec_get_carveout(const void *blob, const char *node, * }; * * fdtdec_set_carveout(fdt, node, "memory-region", 0, "framebuffer", NULL, - * 0, &fb); + * 0, &fb, 0); * * dc@54200000 is a display controller and was set up by the bootloader to * scan out the framebuffer specified by "fb". This would cause the following @@ -1114,12 +1119,13 @@ int fdtdec_get_carveout(const void *blob, const char *node, * @param name base name of the reserved-memory node to create * @param compatibles compatible strings to set for the carveout * @param count number of compatible strings + * @param flags bitmask of flags to set for the carveout * @return 0 on success or a negative error code on failure */ 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); /** * Set up the device tree ready for use 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) diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c index 385aa77a686..087d4846da8 100644 --- a/test/dm/fdtdec.c +++ b/test/dm/fdtdec.c @@ -29,17 +29,17 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts) resv.start = 0x1000; resv.end = 0x2000; ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 2, - &resv, "test_resv1", NULL, 0)); + &resv, "test_resv1", NULL, 0, 0)); resv.start = 0x10000; resv.end = 0x20000; ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 1, - &resv, "test_resv2", NULL, 0)); + &resv, "test_resv2", NULL, 0, 0)); resv.start = 0x100000; resv.end = 0x200000; ut_assertok(fdtdec_set_carveout(blob, "/a-test", "memory-region", 0, - &resv, "test_resv3", NULL, 0)); + &resv, "test_resv3", NULL, 0, 0)); offset = fdt_path_offset(blob, "/a-test"); ut_assert(offset > 0); @@ -64,6 +64,7 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts) fdt_addr_t addr; fdt_size_t size; void *blob; + unsigned long flags = FDTDEC_RESERVED_MEMORY_NO_MAP; int blob_sz, parent, subnode; uint32_t phandle, phandle1; @@ -78,7 +79,7 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts) resv.start = 0x1000; resv.end = 0x1fff; ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region", &resv, - NULL, 0, &phandle, false)); + NULL, 0, &phandle, 0)); /* Test /reserve-memory and its subnode should exist */ parent = fdt_path_offset(blob, "/reserved-memory"); @@ -99,7 +100,7 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts) resv.start = 0x2000; resv.end = 0x2fff; ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region1", &resv, - NULL, 0, &phandle1, true)); + NULL, 0, &phandle1, flags)); subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1"); ut_assert(subnode > 0); @@ -116,7 +117,7 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts) resv.start = 0x1000; resv.end = 0x1fff; ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region2", &resv, - NULL, 0, &phandle1, false)); + NULL, 0, &phandle1, 0)); subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region2"); ut_assert(subnode < 0); -- cgit v1.2.3 From 77409c7f83622a71060bf78142149d39540ba405 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Fri, 3 Sep 2021 15:16:24 +0200 Subject: ARM: tegra: Refactor DT update helpers Rather than duplicate the Ethernet MAC address and carveout updating code for each board, move it to a common location and make it more reusable. Signed-off-by: Thierry Reding Reviewed-by: Simon Glass Signed-off-by: Tom Warren --- arch/arm/include/asm/arch-tegra/board.h | 10 +++ arch/arm/mach-tegra/dt-setup.c | 118 +++++++++++++++++++++++++++++ board/nvidia/p2371-2180/p2371-2180.c | 123 ++----------------------------- board/nvidia/p2771-0000/p2771-0000.c | 126 ++----------------------------- board/nvidia/p3450-0000/p3450-0000.c | 127 ++------------------------------ 5 files changed, 149 insertions(+), 355 deletions(-) (limited to 'arch/arm') diff --git a/arch/arm/include/asm/arch-tegra/board.h b/arch/arm/include/asm/arch-tegra/board.h index 24d0db8ced8..cd4d0ee3c95 100644 --- a/arch/arm/include/asm/arch-tegra/board.h +++ b/arch/arm/include/asm/arch-tegra/board.h @@ -30,4 +30,14 @@ void pin_mux_nand(void); /* overridable NAND pinmux setup */ void pin_mux_mmc(void); /* overridable mmc pinmux setup */ void pin_mux_display(void); /* overridable DISPLAY pinmux setup */ +/* + * Helpers for various standard DT update mechanisms. + */ + +#if defined(CONFIG_ARM64) +void ft_mac_address_setup(void *fdt); +void ft_carveout_setup(void *fdt, const char *const *nodes, + unsigned int count); +#endif + #endif diff --git a/arch/arm/mach-tegra/dt-setup.c b/arch/arm/mach-tegra/dt-setup.c index 602b20e6b7e..894a6358a2c 100644 --- a/arch/arm/mach-tegra/dt-setup.c +++ b/arch/arm/mach-tegra/dt-setup.c @@ -4,6 +4,9 @@ */ #include +#include +#include +#include #include /* @@ -31,3 +34,118 @@ int ft_system_setup(void *blob, struct bd_info *bd) return 0; } + +#if defined(CONFIG_ARM64) +void ft_mac_address_setup(void *fdt) +{ + const void *cboot_fdt = (const void *)cboot_boot_x0; + uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; + const char *path; + int offset, err; + + err = cboot_get_ethaddr(cboot_fdt, local_mac); + if (err < 0) + memset(local_mac, 0, ETH_ALEN); + + path = fdt_get_alias(fdt, "ethernet"); + if (!path) + return; + + debug("ethernet alias found: %s\n", path); + + offset = fdt_path_offset(fdt, path); + if (offset < 0) { + printf("ethernet alias points to absent node %s\n", path); + return; + } + + if (is_valid_ethaddr(local_mac)) { + err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, + ETH_ALEN); + if (!err) + debug("Local MAC address set: %pM\n", local_mac); + } + + if (eth_env_get_enetaddr("ethaddr", mac)) { + if (memcmp(local_mac, mac, ETH_ALEN) != 0) { + err = fdt_setprop(fdt, offset, "mac-address", mac, + ETH_ALEN); + if (!err) + debug("MAC address set: %pM\n", mac); + } + } +} + +static int ft_copy_carveout(void *dst, const void *src, const char *node) +{ + struct fdt_memory carveout; + unsigned int index = 0; + int err; + + while (true) { + const char **compatibles = NULL; + unsigned int num_compatibles; + unsigned long flags; + char *copy = NULL; + const char *name; + + err = fdtdec_get_carveout(src, node, "memory-region", index, + &carveout, &name, &compatibles, + &num_compatibles, &flags); + if (err < 0) { + if (err != -FDT_ERR_NOTFOUND) + printf("failed to get carveout for %s: %d\n", + node, err); + + return err; + } + + if (name) { + const char *ptr = strchr(name, '@'); + + if (ptr) { + copy = strndup(name, ptr - name); + name = copy; + } + } else { + name = "carveout"; + } + + err = fdtdec_set_carveout(dst, node, "memory-region", index, + &carveout, name, compatibles, + num_compatibles, flags); + if (err < 0) { + printf("failed to set carveout for %s: %d\n", node, + err); + return err; + } + + if (copy) + free(copy); + + index++; + } + + return 0; +} + +void ft_carveout_setup(void *fdt, const char * const *nodes, unsigned int count) +{ + const void *cboot_fdt = (const void *)cboot_boot_x0; + unsigned int i; + int err; + + for (i = 0; i < count; i++) { + printf("copying carveout for %s...\n", nodes[i]); + + err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); + if (err < 0) { + if (err != -FDT_ERR_NOTFOUND) + printf("failed to copy carveout for %s: %d\n", + nodes[i], err); + + continue; + } + } +} +#endif diff --git a/board/nvidia/p2371-2180/p2371-2180.c b/board/nvidia/p2371-2180/p2371-2180.c index cd5dc2de629..816c7bec6ae 100644 --- a/board/nvidia/p2371-2180/p2371-2180.c +++ b/board/nvidia/p2371-2180/p2371-2180.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include "../p2571/max77620_init.h" void pin_mux_mmc(void) @@ -84,125 +84,16 @@ int tegra_pcie_board_init(void) } #endif /* PCI */ -static void ft_mac_address_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; - const char *path; - int offset, err; - - err = cboot_get_ethaddr(cboot_fdt, local_mac); - if (err < 0) - memset(local_mac, 0, ETH_ALEN); - - path = fdt_get_alias(fdt, "ethernet"); - if (!path) - return; - - debug("ethernet alias found: %s\n", path); - - offset = fdt_path_offset(fdt, path); - if (offset < 0) { - printf("ethernet alias points to absent node %s\n", path); - return; - } - - if (is_valid_ethaddr(local_mac)) { - err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, - ETH_ALEN); - if (!err) - debug("Local MAC address set: %pM\n", local_mac); - } - - if (eth_env_get_enetaddr("ethaddr", mac)) { - if (memcmp(local_mac, mac, ETH_ALEN) != 0) { - err = fdt_setprop(fdt, offset, "mac-address", mac, - ETH_ALEN); - if (!err) - debug("MAC address set: %pM\n", mac); - } - } -} - -static int ft_copy_carveout(void *dst, const void *src, const char *node) -{ - unsigned int index = 0; - int err; - - while (true) { - const char **compatibles = NULL; - unsigned int num_compatibles; - struct fdt_memory carveout; - unsigned long flags; - char *copy = NULL; - const char *name; - - err = fdtdec_get_carveout(src, node, "memory-region", index, - &carveout, &name, &compatibles, - &num_compatibles, &flags); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to get carveout for %s: %d\n", - node, err); - - return err; - } - - if (name) { - const char *ptr = strchr(name, '@'); - - if (ptr) { - copy = strndup(name, ptr - name); - name = copy; - } - } else { - name = "carveout"; - } - - err = fdtdec_set_carveout(dst, node, "memory-region", index, - &carveout, name, compatibles, - num_compatibles, flags); - if (err < 0) { - printf("failed to set carveout for %s: %d\n", node, - err); - return err; - } - - if (copy) - free(copy); - - index++; - } - - return 0; -} - -static void ft_carveout_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - static const char * const nodes[] = { - "/host1x@50000000/dc@54200000", - "/host1x@50000000/dc@54240000", - "/external-memory-controller@7001b000", - }; - unsigned int i; - int err; - - for (i = 0; i < ARRAY_SIZE(nodes); i++) { - err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to copy carveout for %s: %d\n", - nodes[i], err); - continue; - } - } -} +static const char * const nodes[] = { + "/host1x@50000000/dc@54200000", + "/host1x@50000000/dc@54240000", + "/external-memory-controller@7001b000", +}; int ft_board_setup(void *fdt, struct bd_info *bd) { ft_mac_address_setup(fdt); - ft_carveout_setup(fdt); + ft_carveout_setup(fdt, nodes, ARRAY_SIZE(nodes)); return 0; } diff --git a/board/nvidia/p2771-0000/p2771-0000.c b/board/nvidia/p2771-0000/p2771-0000.c index 46c36a22db5..5ff89c45423 100644 --- a/board/nvidia/p2771-0000/p2771-0000.c +++ b/board/nvidia/p2771-0000/p2771-0000.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include "../p2571/max77620_init.h" void pin_mux_mmc(void) @@ -60,128 +60,16 @@ int tegra_pcie_board_init(void) } #endif -static void ft_mac_address_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; - const char *path; - int offset, err; - - err = cboot_get_ethaddr(cboot_fdt, local_mac); - if (err < 0) - memset(local_mac, 0, ETH_ALEN); - - path = fdt_get_alias(fdt, "ethernet"); - if (!path) - return; - - debug("ethernet alias found: %s\n", path); - - offset = fdt_path_offset(fdt, path); - if (offset < 0) { - printf("ethernet alias points to absent node %s\n", path); - return; - } - - if (is_valid_ethaddr(local_mac)) { - err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, - ETH_ALEN); - if (!err) - debug("Local MAC address set: %pM\n", local_mac); - } - - if (eth_env_get_enetaddr("ethaddr", mac)) { - if (memcmp(local_mac, mac, ETH_ALEN) != 0) { - err = fdt_setprop(fdt, offset, "mac-address", mac, - ETH_ALEN); - if (!err) - debug("MAC address set: %pM\n", mac); - } - } -} - -static int ft_copy_carveout(void *dst, const void *src, const char *node) -{ - unsigned int index = 0; - int err; - - while (true) { - const char **compatibles = NULL; - unsigned int num_compatibles; - struct fdt_memory carveout; - unsigned long flags; - char *copy = NULL; - const char *name; - - err = fdtdec_get_carveout(src, node, "memory-region", index, - &carveout, &name, &compatibles, - &num_compatibles, &flags); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to get carveout for %s: %d\n", - node, err); - - return err; - } - - if (name) { - const char *ptr = strchr(name, '@'); - - if (ptr) { - copy = strndup(name, ptr - name); - name = copy; - } - } else { - name = "carveout"; - } - - err = fdtdec_set_carveout(dst, node, "memory-region", index, - &carveout, name, compatibles, - num_compatibles, flags); - if (err < 0) { - printf("failed to set carveout for %s: %d\n", node, - err); - return err; - } - - if (copy) - free(copy); - - index++; - } - - return 0; -} - -static void ft_carveout_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - static const char * const nodes[] = { - "/host1x@13e00000/display-hub@15200000/display@15200000", - "/host1x@13e00000/display-hub@15200000/display@15210000", - "/host1x@13e00000/display-hub@15200000/display@15220000", - }; - unsigned int i; - int err; - - for (i = 0; i < ARRAY_SIZE(nodes); i++) { - printf("copying carveout for %s...\n", nodes[i]); - - err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to copy carveout for %s: %d\n", - nodes[i], err); - - continue; - } - } -} +static const char * const nodes[] = { + "/host1x@13e00000/display-hub@15200000/display@15200000", + "/host1x@13e00000/display-hub@15200000/display@15210000", + "/host1x@13e00000/display-hub@15200000/display@15220000", +}; int ft_board_setup(void *fdt, struct bd_info *bd) { ft_mac_address_setup(fdt); - ft_carveout_setup(fdt); + ft_carveout_setup(fdt, nodes, ARRAY_SIZE(nodes)); return 0; } diff --git a/board/nvidia/p3450-0000/p3450-0000.c b/board/nvidia/p3450-0000/p3450-0000.c index ba575282658..fb1a224daa7 100644 --- a/board/nvidia/p3450-0000/p3450-0000.c +++ b/board/nvidia/p3450-0000/p3450-0000.c @@ -11,10 +11,9 @@ #include #include #include -#include -#include #include #include +#include #include "../p2571/max77620_init.h" void pin_mux_mmc(void) @@ -83,128 +82,16 @@ int tegra_pcie_board_init(void) } #endif /* PCI */ -static void ft_mac_address_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; - const char *path; - int offset, err; - - err = cboot_get_ethaddr(cboot_fdt, local_mac); - if (err < 0) - memset(local_mac, 0, ETH_ALEN); - - path = fdt_get_alias(fdt, "ethernet"); - if (!path) - return; - - debug("ethernet alias found: %s\n", path); - - offset = fdt_path_offset(fdt, path); - if (offset < 0) { - printf("ethernet alias points to absent node %s\n", path); - return; - } - - if (is_valid_ethaddr(local_mac)) { - err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, - ETH_ALEN); - if (!err) - debug("Local MAC address set: %pM\n", local_mac); - } - - if (eth_env_get_enetaddr("ethaddr", mac)) { - if (memcmp(local_mac, mac, ETH_ALEN) != 0) { - err = fdt_setprop(fdt, offset, "mac-address", mac, - ETH_ALEN); - if (!err) - debug("MAC address set: %pM\n", mac); - } - } -} - -static int ft_copy_carveout(void *dst, const void *src, const char *node) -{ - unsigned int index = 0; - int err; - - while (true) { - const char **compatibles = NULL; - unsigned int num_compatibles; - struct fdt_memory carveout; - unsigned long flags; - char *copy = NULL; - const char *name; - - err = fdtdec_get_carveout(src, node, "memory-region", index, - &carveout, &name, &compatibles, - &num_compatibles, &flags); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to get carveout for %s: %d\n", - node, err); - - return err; - } - - if (name) { - const char *ptr = strchr(name, '@'); - - if (ptr) { - copy = strndup(name, ptr - name); - name = copy; - } - } else { - name = "carveout"; - } - - err = fdtdec_set_carveout(dst, node, "memory-region", index, - &carveout, name, compatibles, - num_compatibles, flags); - if (err < 0) { - printf("failed to set carveout for %s: %d\n", node, - err); - return err; - } - - if (copy) - free(copy); - - index++; - } - - return 0; -} - -static void ft_carveout_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - static const char * const nodes[] = { - "/host1x@50000000/dc@54200000", - "/host1x@50000000/dc@54240000", - "/external-memory-controller@7001b000", - }; - unsigned int i; - int err; - - for (i = 0; i < ARRAY_SIZE(nodes); i++) { - printf("copying carveout for %s...\n", nodes[i]); - - err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to copy carveout for %s: %d\n", - nodes[i], err); - - continue; - } - } -} +static const char * const nodes[] = { + "/host1x@50000000/dc@54200000", + "/host1x@50000000/dc@54240000", + "/external-memory-controller@7001b000", +}; int ft_board_setup(void *fdt, struct bd_info *bd) { ft_mac_address_setup(fdt); - ft_carveout_setup(fdt); + ft_carveout_setup(fdt, nodes, ARRAY_SIZE(nodes)); return 0; } -- cgit v1.2.3 From a0ba216ed420a8953f57f777256f310370b95338 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Fri, 3 Sep 2021 15:16:25 +0200 Subject: ARM: tegra: Copy memory-region-names property If multiple entries are present in the memory-region property, this new memory-region-names property can be used to specify names for each of them so that they can be more easily distinguished. Signed-off-by: Thierry Reding Reviewed-by: Simon Glass Signed-off-by: Tom Warren --- arch/arm/mach-tegra/dt-setup.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'arch/arm') diff --git a/arch/arm/mach-tegra/dt-setup.c b/arch/arm/mach-tegra/dt-setup.c index 894a6358a2c..c11494722bc 100644 --- a/arch/arm/mach-tegra/dt-setup.c +++ b/arch/arm/mach-tegra/dt-setup.c @@ -78,9 +78,11 @@ void ft_mac_address_setup(void *fdt) static int ft_copy_carveout(void *dst, const void *src, const char *node) { + const char *names = "memory-region-names"; struct fdt_memory carveout; unsigned int index = 0; - int err; + int err, offset, len; + const void *prop; while (true) { const char **compatibles = NULL; @@ -96,6 +98,8 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) if (err != -FDT_ERR_NOTFOUND) printf("failed to get carveout for %s: %d\n", node, err); + else + break; return err; } @@ -126,6 +130,31 @@ static int ft_copy_carveout(void *dst, const void *src, const char *node) index++; } + offset = fdt_path_offset(src, node); + if (offset < 0) { + debug("failed to find source offset for %s: %s\n", node, + fdt_strerror(err)); + return err; + } + + prop = fdt_getprop(src, offset, names, &len); + if (prop) { + offset = fdt_path_offset(dst, node); + if (offset < 0) { + debug("failed to find destination offset for %s: %s\n", + node, fdt_strerror(err)); + return err; + } + + err = fdt_setprop(dst, offset, "memory-region-names", prop, + len); + if (err < 0) { + debug("failed to copy \"%s\" property: %s\n", names, + fdt_strerror(err)); + return err; + } + } + return 0; } -- cgit v1.2.3