LoongArch: Parsing CPU-related information from DTS
authorBinbin Zhou <zhoubinbin@loongson.cn>
Wed, 17 Jan 2024 04:43:08 +0000 (12:43 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Wed, 17 Jan 2024 04:43:08 +0000 (12:43 +0800)
Generally, we can get cpu-related information, such as model name, from
/proc/cpuinfo. For FDT-based systems, we need to parse the relevant
information from DTS.

BTW, set loongson_sysconf.cores_per_package to num_processors if SMBIOS
doesn't provide a valid number (usually FDT-based systems).

Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: Hongliang Wang <wanghongliang@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kernel/env.c
arch/loongarch/kernel/smp.c

index 6b3bfb0092e60b34946490415ff7cd2a51287886..2f1f5b08638f818c2abb7a617b3b79250812b3b8 100644 (file)
@@ -5,13 +5,16 @@
  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  */
 #include <linux/acpi.h>
+#include <linux/clk.h>
 #include <linux/efi.h>
 #include <linux/export.h>
 #include <linux/memblock.h>
+#include <linux/of_clk.h>
 #include <asm/early_ioremap.h>
 #include <asm/bootinfo.h>
 #include <asm/loongson.h>
 #include <asm/setup.h>
+#include <asm/time.h>
 
 u64 efi_system_table;
 struct loongson_system_configuration loongson_sysconf;
@@ -36,7 +39,16 @@ void __init init_environ(void)
 
 static int __init init_cpu_fullname(void)
 {
-       int cpu;
+       struct device_node *root;
+       int cpu, ret;
+       char *model;
+
+       /* Parsing cpuname from DTS model property */
+       root = of_find_node_by_path("/");
+       ret = of_property_read_string(root, "model", (const char **)&model);
+       of_node_put(root);
+       if (ret == 0)
+               loongson_sysconf.cpuname = strsep(&model, " ");
 
        if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
                for (cpu = 0; cpu < NR_CPUS; cpu++)
@@ -46,6 +58,26 @@ static int __init init_cpu_fullname(void)
 }
 arch_initcall(init_cpu_fullname);
 
+static int __init fdt_cpu_clk_init(void)
+{
+       struct clk *clk;
+       struct device_node *np;
+
+       np = of_get_cpu_node(0, NULL);
+       if (!np)
+               return -ENODEV;
+
+       clk = of_clk_get(np, 0);
+       if (IS_ERR(clk))
+               return -ENODEV;
+
+       cpu_clock_freq = clk_get_rate(clk);
+       clk_put(clk);
+
+       return 0;
+}
+late_initcall(fdt_cpu_clk_init);
+
 static ssize_t boardinfo_show(struct kobject *kobj,
                              struct kobj_attribute *attr, char *buf)
 {
index 5bca12d16e0691c8e9511f6043a7a5af9655af20..9e33b5e36122556a71252184b3899e105ee12530 100644 (file)
@@ -216,6 +216,9 @@ void __init loongson_smp_setup(void)
 {
        fdt_smp_setup();
 
+       if (loongson_sysconf.cores_per_package == 0)
+               loongson_sysconf.cores_per_package = num_processors;
+
        cpu_data[0].core = cpu_logical_map(0) % loongson_sysconf.cores_per_package;
        cpu_data[0].package = cpu_logical_map(0) / loongson_sysconf.cores_per_package;