xref: /linux/arch/loongarch/kernel/proc.c (revision 127fa2ae9e2b1f9b9d876dfaa39fe3640cec5764)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #include <linux/delay.h>
6 #include <linux/kernel.h>
7 #include <linux/sched.h>
8 #include <linux/seq_file.h>
9 #include <asm/bootinfo.h>
10 #include <asm/cpu.h>
11 #include <asm/cpu-features.h>
12 #include <asm/idle.h>
13 #include <asm/processor.h>
14 #include <asm/time.h>
15 
16 static int show_cpuinfo(struct seq_file *m, void *v)
17 {
18 	unsigned long n = (unsigned long) v - 1;
19 	unsigned int isa = cpu_data[n].isa_level;
20 	unsigned int prid = cpu_data[n].processor_id;
21 	unsigned int version = cpu_data[n].processor_id & 0xff;
22 	unsigned int fp_version = cpu_data[n].fpu_vers;
23 
24 #ifdef CONFIG_SMP
25 	if (!cpu_online(n))
26 		return 0;
27 #endif
28 
29 	/*
30 	 * For the first processor also print the system type
31 	 */
32 	if (n == 0)
33 		seq_printf(m, "system type\t\t: %s\n\n", get_system_type());
34 
35 	seq_printf(m, "processor\t\t: %ld\n", n);
36 	seq_printf(m, "package\t\t\t: %d\n", cpu_data[n].package);
37 	seq_printf(m, "core\t\t\t: %d\n", cpu_data[n].core);
38 	seq_printf(m, "global_id\t\t: %d\n", cpu_data[n].global_id);
39 	seq_printf(m, "CPU Family\t\t: %s\n", __cpu_family[n]);
40 	seq_printf(m, "Model Name\t\t: %s\n", __cpu_full_name[n]);
41 	seq_printf(m, "PRID\t\t\t: %s (%08x)\n", id_to_core_name(prid), prid);
42 	seq_printf(m, "CPU Revision\t\t: 0x%02x\n", version);
43 	seq_printf(m, "FPU Revision\t\t: 0x%02x\n", fp_version);
44 	seq_printf(m, "CPU MHz\t\t\t: %llu.%02llu\n",
45 		      cpu_clock_freq / 1000000, (cpu_clock_freq / 10000) % 100);
46 	seq_printf(m, "BogoMIPS\t\t: %llu.%02llu\n",
47 		      (lpj_fine * cpu_clock_freq / const_clock_freq) / (500000/HZ),
48 		      ((lpj_fine * cpu_clock_freq / const_clock_freq) / (5000/HZ)) % 100);
49 	seq_printf(m, "TLB Entries\t\t: %d\n", cpu_data[n].tlbsize);
50 	seq_printf(m, "Address Sizes\t\t: %d bits physical, %d bits virtual\n",
51 		      cpu_pabits + 1, cpu_vabits + 1);
52 
53 	seq_printf(m, "ISA\t\t\t:");
54 	if (isa & LOONGARCH_CPU_ISA_LA32R)
55 		seq_printf(m, " loongarch32r");
56 	if (isa & LOONGARCH_CPU_ISA_LA32S)
57 		seq_printf(m, " loongarch32s");
58 	if (isa & LOONGARCH_CPU_ISA_LA64)
59 		seq_printf(m, " loongarch64");
60 	seq_printf(m, "\n");
61 
62 	seq_printf(m, "Features\t\t:");
63 	if (cpu_has_cpucfg)	seq_printf(m, " cpucfg");
64 	if (cpu_has_lam)	seq_printf(m, " lam");
65 	if (cpu_has_ual)	seq_printf(m, " ual");
66 	if (cpu_has_fpu)	seq_printf(m, " fpu");
67 	if (cpu_has_lsx)	seq_printf(m, " lsx");
68 	if (cpu_has_lasx)	seq_printf(m, " lasx");
69 	if (cpu_has_crc32)	seq_printf(m, " crc32");
70 	if (cpu_has_complex)	seq_printf(m, " complex");
71 	if (cpu_has_crypto)	seq_printf(m, " crypto");
72 	if (cpu_has_ptw)	seq_printf(m, " ptw");
73 	if (cpu_has_lspw)	seq_printf(m, " lspw");
74 	if (cpu_has_lvz)	seq_printf(m, " lvz");
75 	if (cpu_has_lbt_x86)	seq_printf(m, " lbt_x86");
76 	if (cpu_has_lbt_arm)	seq_printf(m, " lbt_arm");
77 	if (cpu_has_lbt_mips)	seq_printf(m, " lbt_mips");
78 	seq_printf(m, "\n");
79 
80 	seq_printf(m, "Hardware Watchpoint\t: %s", str_yes_no(cpu_has_watch));
81 	if (cpu_has_watch) {
82 		seq_printf(m, ", iwatch count: %d, dwatch count: %d",
83 		      cpu_data[n].watch_ireg_count, cpu_data[n].watch_dreg_count);
84 	}
85 
86 	seq_printf(m, "\n\n");
87 
88 	return 0;
89 }
90 
91 static void *c_start(struct seq_file *m, loff_t *pos)
92 {
93 	unsigned long i = *pos;
94 
95 	return i < nr_cpu_ids ? (void *)(i + 1) : NULL;
96 }
97 
98 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
99 {
100 	++*pos;
101 	return c_start(m, pos);
102 }
103 
104 static void c_stop(struct seq_file *m, void *v)
105 {
106 }
107 
108 const struct seq_operations cpuinfo_op = {
109 	.start	= c_start,
110 	.next	= c_next,
111 	.stop	= c_stop,
112 	.show	= show_cpuinfo,
113 };
114