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 /* 17 * No lock; only written during early bootup by CPU 0. 18 */ 19 static RAW_NOTIFIER_HEAD(proc_cpuinfo_chain); 20 21 int __ref register_proc_cpuinfo_notifier(struct notifier_block *nb) 22 { 23 return raw_notifier_chain_register(&proc_cpuinfo_chain, nb); 24 } 25 26 int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v) 27 { 28 return raw_notifier_call_chain(&proc_cpuinfo_chain, val, v); 29 } 30 31 static int show_cpuinfo(struct seq_file *m, void *v) 32 { 33 unsigned long n = (unsigned long) v - 1; 34 unsigned int isa = cpu_data[n].isa_level; 35 unsigned int version = cpu_data[n].processor_id & 0xff; 36 unsigned int fp_version = cpu_data[n].fpu_vers; 37 struct proc_cpuinfo_notifier_args proc_cpuinfo_notifier_args; 38 39 #ifdef CONFIG_SMP 40 if (!cpu_online(n)) 41 return 0; 42 #endif 43 44 /* 45 * For the first processor also print the system type 46 */ 47 if (n == 0) 48 seq_printf(m, "system type\t\t: %s\n\n", get_system_type()); 49 50 seq_printf(m, "processor\t\t: %ld\n", n); 51 seq_printf(m, "package\t\t\t: %d\n", cpu_data[n].package); 52 seq_printf(m, "core\t\t\t: %d\n", cpu_data[n].core); 53 seq_printf(m, "global_id\t\t: %d\n", cpu_data[n].global_id); 54 seq_printf(m, "CPU Family\t\t: %s\n", __cpu_family[n]); 55 seq_printf(m, "Model Name\t\t: %s\n", __cpu_full_name[n]); 56 seq_printf(m, "CPU Revision\t\t: 0x%02x\n", version); 57 seq_printf(m, "FPU Revision\t\t: 0x%02x\n", fp_version); 58 seq_printf(m, "CPU MHz\t\t\t: %llu.%02llu\n", 59 cpu_clock_freq / 1000000, (cpu_clock_freq / 10000) % 100); 60 seq_printf(m, "BogoMIPS\t\t: %llu.%02llu\n", 61 (lpj_fine * cpu_clock_freq / const_clock_freq) / (500000/HZ), 62 ((lpj_fine * cpu_clock_freq / const_clock_freq) / (5000/HZ)) % 100); 63 seq_printf(m, "TLB Entries\t\t: %d\n", cpu_data[n].tlbsize); 64 seq_printf(m, "Address Sizes\t\t: %d bits physical, %d bits virtual\n", 65 cpu_pabits + 1, cpu_vabits + 1); 66 67 seq_printf(m, "ISA\t\t\t:"); 68 if (isa & LOONGARCH_CPU_ISA_LA32R) 69 seq_printf(m, " loongarch32r"); 70 if (isa & LOONGARCH_CPU_ISA_LA32S) 71 seq_printf(m, " loongarch32s"); 72 if (isa & LOONGARCH_CPU_ISA_LA64) 73 seq_printf(m, " loongarch64"); 74 seq_printf(m, "\n"); 75 76 seq_printf(m, "Features\t\t:"); 77 if (cpu_has_cpucfg) seq_printf(m, " cpucfg"); 78 if (cpu_has_lam) seq_printf(m, " lam"); 79 if (cpu_has_ual) seq_printf(m, " ual"); 80 if (cpu_has_fpu) seq_printf(m, " fpu"); 81 if (cpu_has_lsx) seq_printf(m, " lsx"); 82 if (cpu_has_lasx) seq_printf(m, " lasx"); 83 if (cpu_has_crc32) seq_printf(m, " crc32"); 84 if (cpu_has_complex) seq_printf(m, " complex"); 85 if (cpu_has_crypto) seq_printf(m, " crypto"); 86 if (cpu_has_ptw) seq_printf(m, " ptw"); 87 if (cpu_has_lspw) seq_printf(m, " lspw"); 88 if (cpu_has_lvz) seq_printf(m, " lvz"); 89 if (cpu_has_lbt_x86) seq_printf(m, " lbt_x86"); 90 if (cpu_has_lbt_arm) seq_printf(m, " lbt_arm"); 91 if (cpu_has_lbt_mips) seq_printf(m, " lbt_mips"); 92 seq_printf(m, "\n"); 93 94 seq_printf(m, "Hardware Watchpoint\t: %s", 95 cpu_has_watch ? "yes, " : "no\n"); 96 if (cpu_has_watch) { 97 seq_printf(m, "iwatch count: %d, dwatch count: %d\n", 98 cpu_data[n].watch_ireg_count, cpu_data[n].watch_dreg_count); 99 } 100 101 proc_cpuinfo_notifier_args.m = m; 102 proc_cpuinfo_notifier_args.n = n; 103 104 raw_notifier_call_chain(&proc_cpuinfo_chain, 0, 105 &proc_cpuinfo_notifier_args); 106 107 seq_printf(m, "\n"); 108 109 return 0; 110 } 111 112 static void *c_start(struct seq_file *m, loff_t *pos) 113 { 114 unsigned long i = *pos; 115 116 return i < nr_cpu_ids ? (void *)(i + 1) : NULL; 117 } 118 119 static void *c_next(struct seq_file *m, void *v, loff_t *pos) 120 { 121 ++*pos; 122 return c_start(m, pos); 123 } 124 125 static void c_stop(struct seq_file *m, void *v) 126 { 127 } 128 129 const struct seq_operations cpuinfo_op = { 130 .start = c_start, 131 .next = c_next, 132 .stop = c_stop, 133 .show = show_cpuinfo, 134 }; 135