Skip to content

Commit 44a01f1

Browse files
AaronDotchenhuacai
authored andcommitted
LoongArch: Parsing CPU-related information from DTS
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>
1 parent 2905844 commit 44a01f1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

arch/loongarch/kernel/env.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
66
*/
77
#include <linux/acpi.h>
8+
#include <linux/clk.h>
89
#include <linux/efi.h>
910
#include <linux/export.h>
1011
#include <linux/memblock.h>
12+
#include <linux/of_clk.h>
1113
#include <asm/early_ioremap.h>
1214
#include <asm/bootinfo.h>
1315
#include <asm/loongson.h>
1416
#include <asm/setup.h>
17+
#include <asm/time.h>
1518

1619
u64 efi_system_table;
1720
struct loongson_system_configuration loongson_sysconf;
@@ -36,7 +39,16 @@ void __init init_environ(void)
3639

3740
static int __init init_cpu_fullname(void)
3841
{
39-
int cpu;
42+
struct device_node *root;
43+
int cpu, ret;
44+
char *model;
45+
46+
/* Parsing cpuname from DTS model property */
47+
root = of_find_node_by_path("/");
48+
ret = of_property_read_string(root, "model", (const char **)&model);
49+
of_node_put(root);
50+
if (ret == 0)
51+
loongson_sysconf.cpuname = strsep(&model, " ");
4052

4153
if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
4254
for (cpu = 0; cpu < NR_CPUS; cpu++)
@@ -46,6 +58,26 @@ static int __init init_cpu_fullname(void)
4658
}
4759
arch_initcall(init_cpu_fullname);
4860

61+
static int __init fdt_cpu_clk_init(void)
62+
{
63+
struct clk *clk;
64+
struct device_node *np;
65+
66+
np = of_get_cpu_node(0, NULL);
67+
if (!np)
68+
return -ENODEV;
69+
70+
clk = of_clk_get(np, 0);
71+
if (IS_ERR(clk))
72+
return -ENODEV;
73+
74+
cpu_clock_freq = clk_get_rate(clk);
75+
clk_put(clk);
76+
77+
return 0;
78+
}
79+
late_initcall(fdt_cpu_clk_init);
80+
4981
static ssize_t boardinfo_show(struct kobject *kobj,
5082
struct kobj_attribute *attr, char *buf)
5183
{

arch/loongarch/kernel/smp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ void __init loongson_smp_setup(void)
216216
{
217217
fdt_smp_setup();
218218

219+
if (loongson_sysconf.cores_per_package == 0)
220+
loongson_sysconf.cores_per_package = num_processors;
221+
219222
cpu_data[0].core = cpu_logical_map(0) % loongson_sysconf.cores_per_package;
220223
cpu_data[0].package = cpu_logical_map(0) / loongson_sysconf.cores_per_package;
221224

0 commit comments

Comments
 (0)