[PATCH 12/21] imx: generialize disable_cpu_nodes
Peng Fan (OSS)
peng.fan at oss.nxp.com
Tue Sep 17 05:34:04 CEST 2024
From: Peng Fan <peng.fan at nxp.com>
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 <peng.fan at nxp.com>
---
arch/arm/include/asm/mach-imx/sys_proto.h | 2 +
arch/arm/mach-imx/Makefile | 1 +
arch/arm/mach-imx/fdt.c | 87 +++++++++++++++++++++++++++
arch/arm/mach-imx/imx8m/soc.c | 99 ++++---------------------------
4 files changed, 103 insertions(+), 86 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h
index 31ae179b211..d93e095e191 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 5262dca4ffd..47e2cb8d943 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 00000000000..df6fbf51dba
--- /dev/null
+++ b/arch/arm/mach-imx/fdt.c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2024 NXP
+ */
+
+#include <errno.h>
+#include <fdtdec.h>
+#include <malloc.h>
+#include <asm/arch/sys_proto.h>
+
+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 9ed27b59303..68d5762c2ce 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -1135,79 +1135,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 at 1",
- "/cpus/cpu at 2",
- "/cpus/cpu at 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] = {
@@ -1359,6 +1286,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 at 0",
+ "/cpus/cpu at 1",
+ "/cpus/cpu at 2",
+ "/cpus/cpu at 3",
+ };
+
#ifdef CONFIG_IMX8MQ
int i = 0;
int rc;
@@ -1402,13 +1336,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 at 0",
- "/cpus/cpu at 1",
- "/cpus/cpu at 2",
- "/cpus/cpu at 3",
- };
-
for (i = 0; i < ARRAY_SIZE(nodes_path); i++) {
nodeoff = fdt_path_offset(blob, nodes_path[i]);
if (nodeoff < 0)
@@ -1440,16 +1367,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())
@@ -1466,9 +1393,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()) {
@@ -1495,7 +1422,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);
--
2.35.3
More information about the U-Boot
mailing list