proc.c 3.9 KB

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