From: Peng Fan Date: Thu, 19 Sep 2024 04:01:31 +0000 (+0800) Subject: imx: Generalize disable_cpu_nodes X-Git-Url: http://git.dujemihanovic.xyz/%7B%7B%20%24style.Permalink%20%7D%7D?a=commitdiff_plain;h=cd9b3de763563f628a2aaedc4b19841970035a21;p=u-boot.git imx: Generalize disable_cpu_nodes disable_cpu_nodes could be reused by i.MX9, so move disable_cpu_nodes out from mach-imx/imx8m/soc.c to mach-imx/fdt.c and update disable_cpu_nodes to make it easy to support different socs. Signed-off-by: Peng Fan --- diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index 31ae179b21..d93e095e19 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -275,4 +275,6 @@ void enable_ca7_smp(void); enum boot_device get_boot_device(void); +int disable_cpu_nodes(void *blob, const char * const *nodes_path, + u32 num_disabled_cores, u32 max_cores); #endif diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 5262dca4ff..47e2cb8d94 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -12,6 +12,7 @@ endif ifeq ($(SOC),$(filter $(SOC),imx8m)) ifneq ($(CONFIG_SPL_BUILD),y) obj-$(CONFIG_IMX_BOOTAUX) += imx_bootaux.o +obj-y += fdt.o endif obj-$(CONFIG_ENV_IS_IN_MMC) += mmc_env.o obj-$(CONFIG_FEC_MXC) += mac.o diff --git a/arch/arm/mach-imx/fdt.c b/arch/arm/mach-imx/fdt.c new file mode 100644 index 0000000000..df6fbf51db --- /dev/null +++ b/arch/arm/mach-imx/fdt.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include +#include +#include +#include + +static void disable_thermal_cpu_nodes(void *blob, u32 num_disabled_cores, u32 max_cores) +{ + static const char * const thermal_path[] = { + "/thermal-zones/cpu-thermal/cooling-maps/map0" + }; + + int nodeoff, cnt, i, ret, j; + u32 num_le32 = max_cores * 3; + u32 *cooling_dev = (u32 *)malloc(num_le32 * sizeof(__le32)); + + if (!cooling_dev) { + printf("failed to alloc cooling dev\n"); + return; + } + + for (i = 0; i < ARRAY_SIZE(thermal_path); i++) { + nodeoff = fdt_path_offset(blob, thermal_path[i]); + if (nodeoff < 0) + continue; /* Not found, skip it */ + + cnt = fdtdec_get_int_array_count(blob, nodeoff, "cooling-device", + cooling_dev, num_le32); + if (cnt < 0) + continue; + + if (cnt != num_le32) + printf("Warning: %s, cooling-device count %d\n", thermal_path[i], cnt); + + for (j = 0; j < cnt; j++) + cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]); + + ret = fdt_setprop(blob, nodeoff, "cooling-device", &cooling_dev, + sizeof(__le32) * (num_le32 - num_disabled_cores * 3)); + if (ret < 0) { + printf("Warning: %s, cooling-device setprop failed %d\n", + thermal_path[i], ret); + continue; + } + + printf("Update node %s, cooling-device prop\n", thermal_path[i]); + } + + free(cooling_dev); +} + +int disable_cpu_nodes(void *blob, const char * const *nodes_path, u32 num_disabled_cores, + u32 max_cores) +{ + u32 i = 0; + int rc; + int nodeoff; + + if (max_cores == 0 || (num_disabled_cores > (max_cores - 1))) + return -EINVAL; + + i = max_cores - num_disabled_cores; + + for (; i < max_cores; i++) { + nodeoff = fdt_path_offset(blob, nodes_path[i]); + if (nodeoff < 0) + continue; /* Not found, skip it */ + + debug("Found %s node\n", nodes_path[i]); + + rc = fdt_del_node(blob, nodeoff); + if (rc < 0) { + printf("Unable to delete node %s, err=%s\n", + nodes_path[i], fdt_strerror(rc)); + } else { + printf("Delete node %s\n", nodes_path[i]); + } + } + + disable_thermal_cpu_nodes(blob, num_disabled_cores, max_cores); + + return 0; +} diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c index 3a582cb43b..b8a026fb84 100644 --- a/arch/arm/mach-imx/imx8m/soc.c +++ b/arch/arm/mach-imx/imx8m/soc.c @@ -1184,79 +1184,6 @@ int disable_dsp_nodes(void *blob) return disable_fdt_nodes(blob, nodes_path_8mp, ARRAY_SIZE(nodes_path_8mp)); } -static void disable_thermal_cpu_nodes(void *blob, u32 disabled_cores) -{ - static const char * const thermal_path[] = { - "/thermal-zones/cpu-thermal/cooling-maps/map0" - }; - - int nodeoff, cnt, i, ret, j; - u32 cooling_dev[12]; - - for (i = 0; i < ARRAY_SIZE(thermal_path); i++) { - nodeoff = fdt_path_offset(blob, thermal_path[i]); - if (nodeoff < 0) - continue; /* Not found, skip it */ - - cnt = fdtdec_get_int_array_count(blob, nodeoff, "cooling-device", cooling_dev, 12); - if (cnt < 0) - continue; - - if (cnt != 12) - printf("Warning: %s, cooling-device count %d\n", thermal_path[i], cnt); - - for (j = 0; j < cnt; j++) - cooling_dev[j] = cpu_to_fdt32(cooling_dev[j]); - - ret = fdt_setprop(blob, nodeoff, "cooling-device", &cooling_dev, - sizeof(u32) * (12 - disabled_cores * 3)); - if (ret < 0) { - printf("Warning: %s, cooling-device setprop failed %d\n", - thermal_path[i], ret); - continue; - } - - printf("Update node %s, cooling-device prop\n", thermal_path[i]); - } -} - -static int disable_cpu_nodes(void *blob, u32 disabled_cores) -{ - static const char * const nodes_path[] = { - "/cpus/cpu@1", - "/cpus/cpu@2", - "/cpus/cpu@3", - }; - u32 i = 0; - int rc; - int nodeoff; - - if (disabled_cores > 3) - return -EINVAL; - - i = 3 - disabled_cores; - - for (; i < 3; i++) { - nodeoff = fdt_path_offset(blob, nodes_path[i]); - if (nodeoff < 0) - continue; /* Not found, skip it */ - - debug("Found %s node\n", nodes_path[i]); - - rc = fdt_del_node(blob, nodeoff); - if (rc < 0) { - printf("Unable to delete node %s, err=%s\n", - nodes_path[i], fdt_strerror(rc)); - } else { - printf("Delete node %s\n", nodes_path[i]); - } - } - - disable_thermal_cpu_nodes(blob, disabled_cores); - - return 0; -} - static int cleanup_nodes_for_efi(void *blob) { static const char * const path[][2] = { @@ -1408,6 +1335,13 @@ static int ft_add_optee_node(void *fdt, struct bd_info *bd) int ft_system_setup(void *blob, struct bd_info *bd) { + static const char * const nodes_path[] = { + "/cpus/cpu@0", + "/cpus/cpu@1", + "/cpus/cpu@2", + "/cpus/cpu@3", + }; + #ifdef CONFIG_IMX8MQ int i = 0; int rc; @@ -1451,13 +1385,6 @@ usb_modify_speed: /* Disable the CPU idle for A0 chip since the HW does not support it */ if (is_soc_rev(CHIP_REV_1_0)) { - static const char * const nodes_path[] = { - "/cpus/cpu@0", - "/cpus/cpu@1", - "/cpus/cpu@2", - "/cpus/cpu@3", - }; - for (i = 0; i < ARRAY_SIZE(nodes_path); i++) { nodeoff = fdt_path_offset(blob, nodes_path[i]); if (nodeoff < 0) @@ -1489,16 +1416,16 @@ usb_modify_speed: } if (is_imx8md()) - disable_cpu_nodes(blob, 2); + disable_cpu_nodes(blob, nodes_path, 2, 4); #elif defined(CONFIG_IMX8MM) if (is_imx8mml() || is_imx8mmdl() || is_imx8mmsl()) disable_vpu_nodes(blob); if (is_imx8mmd() || is_imx8mmdl()) - disable_cpu_nodes(blob, 2); + disable_cpu_nodes(blob, nodes_path, 2, 4); else if (is_imx8mms() || is_imx8mmsl()) - disable_cpu_nodes(blob, 3); + disable_cpu_nodes(blob, nodes_path, 3, 4); #elif defined(CONFIG_IMX8MN) if (is_imx8mnl() || is_imx8mndl() || is_imx8mnsl()) @@ -1515,9 +1442,9 @@ usb_modify_speed: #endif if (is_imx8mnd() || is_imx8mndl() || is_imx8mnud()) - disable_cpu_nodes(blob, 2); + disable_cpu_nodes(blob, nodes_path, 2, 4); else if (is_imx8mns() || is_imx8mnsl() || is_imx8mnus()) - disable_cpu_nodes(blob, 3); + disable_cpu_nodes(blob, nodes_path, 3, 4); #elif defined(CONFIG_IMX8MP) if (is_imx8mpul()) { @@ -1544,7 +1471,7 @@ usb_modify_speed: disable_dsp_nodes(blob); if (is_imx8mpd()) - disable_cpu_nodes(blob, 2); + disable_cpu_nodes(blob, nodes_path, 2, 4); #endif cleanup_nodes_for_efi(blob);