[PATCH 03/12] arch_topology: Make it avilable for MIPS

Jiaxun Yang <[email protected]> Wed, 8 Apr 2020 19:34:13 +0800
Newsgroups gmane.linux.ports.mips,gmane.linux.kernel,gmane.linux.oprofile
Message-ID <[email protected]>
Simply drop unnecessary archtecture limitions and add dummy
function for platforms without OF/COMMON_CLK support.
Also exclude functions for arm that existed in platform code.

Signed-off-by: Jiaxun Yang <[email protected]>
---
 drivers/base/arch_topology.c | 121 +++++++++++++++++++----------------
 1 file changed, 66 insertions(+), 55 deletions(-)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 4d0a0038b476..9c2405d08dae 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -143,57 +143,6 @@ void topology_normalize_cpu_scale(void)
 	}
 }
 
-bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
-{
-	struct clk *cpu_clk;
-	static bool cap_parsing_failed;
-	int ret;
-	u32 cpu_capacity;
-
-	if (cap_parsing_failed)
-		return false;
-
-	ret = of_property_read_u32(cpu_node, "capacity-dmips-mhz",
-				   &cpu_capacity);
-	if (!ret) {
-		if (!raw_capacity) {
-			raw_capacity = kcalloc(num_possible_cpus(),
-					       sizeof(*raw_capacity),
-					       GFP_KERNEL);
-			if (!raw_capacity) {
-				cap_parsing_failed = true;
-				return false;
-			}
-		}
-		raw_capacity[cpu] = cpu_capacity;
-		pr_debug("cpu_capacity: %pOF cpu_capacity=%u (raw)\n",
-			cpu_node, raw_capacity[cpu]);
-
-		/*
-		 * Update freq_factor for calculating early boot cpu capacities.
-		 * For non-clk CPU DVFS mechanism, there's no way to get the
-		 * frequency value now, assuming they are running at the same
-		 * frequency (by keeping the initial freq_factor value).
-		 */
-		cpu_clk = of_clk_get(cpu_node, 0);
-		if (!PTR_ERR_OR_ZERO(cpu_clk)) {
-			per_cpu(freq_factor, cpu) =
-				clk_get_rate(cpu_clk) / 1000;
-			clk_put(cpu_clk);
-		}
-	} else {
-		if (raw_capacity) {
-			pr_err("cpu_capacity: missing %pOF raw capacity\n",
-				cpu_node);
-			pr_err("cpu_capacity: partial information: fallback to 1024 for all CPUs\n");
-		}
-		cap_parsing_failed = true;
-		free_raw_capacity();
-	}
-
-	return !ret;
-}
-
 #ifdef CONFIG_CPU_FREQ
 static cpumask_var_t cpus_to_visit;
 static void parsing_done_workfn(struct work_struct *work);
@@ -275,7 +224,64 @@ static void parsing_done_workfn(struct work_struct *work)
 core_initcall(free_raw_capacity);
 #endif
 
-#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
+#if defined(CONFIG_OF) && !defined(CONFIG_ARM)
+#if defined(CONFIG_COMMON_CLK)
+bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
+{
+	struct clk *cpu_clk;
+	static bool cap_parsing_failed;
+	int ret;
+	u32 cpu_capacity;
+
+	if (cap_parsing_failed)
+		return false;
+
+	ret = of_property_read_u32(cpu_node, "capacity-dmips-mhz",
+				   &cpu_capacity);
+	if (!ret) {
+		if (!raw_capacity) {
+			raw_capacity = kcalloc(num_possible_cpus(),
+					       sizeof(*raw_capacity),
+					       GFP_KERNEL);
+			if (!raw_capacity) {
+				cap_parsing_failed = true;
+				return false;
+			}
+		}
+		raw_capacity[cpu] = cpu_capacity;
+		pr_debug("cpu_capacity: %pOF cpu_capacity=%u (raw)\n",
+			cpu_node, raw_capacity[cpu]);
+
+		/*
+		 * Update freq_factor for calculating early boot cpu capacities.
+		 * For non-clk CPU DVFS mechanism, there's no way to get the
+		 * frequency value now, assuming they are running at the same
+		 * frequency (by keeping the initial freq_factor value).
+		 */
+		cpu_clk = of_clk_get(cpu_node, 0);
+		if (!PTR_ERR_OR_ZERO(cpu_clk)) {
+			per_cpu(freq_factor, cpu) =
+				clk_get_rate(cpu_clk) / 1000;
+			clk_put(cpu_clk);
+		}
+	} else {
+		if (raw_capacity) {
+			pr_err("cpu_capacity: missing %pOF raw capacity\n",
+				cpu_node);
+			pr_err("cpu_capacity: partial information: fallback to 1024 for all CPUs\n");
+		}
+		cap_parsing_failed = true;
+		free_raw_capacity();
+	}
+
+	return !ret;
+}
+#else
+bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
+{
+		return false;
+}
+#endif /* CONFIG_COMMON_CLK */
 /*
  * This function returns the logic cpu number of the node.
  * There are basically three kinds of return values:
@@ -461,7 +467,12 @@ static int __init parse_dt_topology(void)
 	of_node_put(cn);
 	return ret;
 }
-#endif
+#else
+static int __init parse_dt_topology(void)
+{
+	return 0;
+}
+#endif /* CONFIG_OF & !CONFIG_ARM */
 
 /*
  * cpu topology table
@@ -562,7 +573,7 @@ __weak int __init parse_acpi_topology(void)
 	return 0;
 }
 
-#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
+#if !defined(CONFIG_ARM)
 void __init init_cpu_topology(void)
 {
 	reset_cpu_topology();
@@ -576,4 +587,4 @@ void __init init_cpu_topology(void)
 	else if (of_have_populated_dt() && parse_dt_topology())
 		reset_cpu_topology();
 }
-#endif
+#endif /* !CONFIG_ARM */
-- 
2.26.0.rc2