cpuinfo.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (C) 2013 Altera Corporation
  3. * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
  4. *
  5. * Based on cpuinfo.c from microblaze
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/string.h>
  26. #include <linux/of.h>
  27. #include <asm/cpuinfo.h>
  28. struct cpuinfo cpuinfo;
  29. #define err_cpu(x) \
  30. pr_err("ERROR: Nios II " x " different for kernel and DTS\n")
  31. static inline u32 fcpu(struct device_node *cpu, const char *n)
  32. {
  33. u32 val = 0;
  34. of_property_read_u32(cpu, n, &val);
  35. return val;
  36. }
  37. void __init setup_cpuinfo(void)
  38. {
  39. struct device_node *cpu;
  40. const char *str;
  41. int len;
  42. cpu = of_find_node_by_type(NULL, "cpu");
  43. if (!cpu)
  44. panic("%s: No CPU found in devicetree!\n", __func__);
  45. if (!of_property_read_bool(cpu, "altr,has-initda"))
  46. panic("initda instruction is unimplemented. Please update your "
  47. "hardware system to have more than 4-byte line data "
  48. "cache\n");
  49. cpuinfo.cpu_clock_freq = fcpu(cpu, "clock-frequency");
  50. str = of_get_property(cpu, "altr,implementation", &len);
  51. if (str)
  52. strlcpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
  53. else
  54. strcpy(cpuinfo.cpu_impl, "<unknown>");
  55. cpuinfo.has_div = of_property_read_bool(cpu, "altr,has-div");
  56. cpuinfo.has_mul = of_property_read_bool(cpu, "altr,has-mul");
  57. cpuinfo.has_mulx = of_property_read_bool(cpu, "altr,has-mulx");
  58. cpuinfo.mmu = of_property_read_bool(cpu, "altr,has-mmu");
  59. if (IS_ENABLED(CONFIG_NIOS2_HW_DIV_SUPPORT) && !cpuinfo.has_div)
  60. err_cpu("DIV");
  61. if (IS_ENABLED(CONFIG_NIOS2_HW_MUL_SUPPORT) && !cpuinfo.has_mul)
  62. err_cpu("MUL");
  63. if (IS_ENABLED(CONFIG_NIOS2_HW_MULX_SUPPORT) && !cpuinfo.has_mulx)
  64. err_cpu("MULX");
  65. cpuinfo.tlb_num_ways = fcpu(cpu, "altr,tlb-num-ways");
  66. if (!cpuinfo.tlb_num_ways)
  67. panic("altr,tlb-num-ways can't be 0. Please check your hardware "
  68. "system\n");
  69. cpuinfo.icache_line_size = fcpu(cpu, "icache-line-size");
  70. cpuinfo.icache_size = fcpu(cpu, "icache-size");
  71. if (CONFIG_NIOS2_ICACHE_SIZE != cpuinfo.icache_size)
  72. pr_warn("Warning: icache size configuration mismatch "
  73. "(0x%x vs 0x%x) of CONFIG_NIOS2_ICACHE_SIZE vs "
  74. "device tree icache-size\n",
  75. CONFIG_NIOS2_ICACHE_SIZE, cpuinfo.icache_size);
  76. cpuinfo.dcache_line_size = fcpu(cpu, "dcache-line-size");
  77. if (CONFIG_NIOS2_DCACHE_LINE_SIZE != cpuinfo.dcache_line_size)
  78. pr_warn("Warning: dcache line size configuration mismatch "
  79. "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_LINE_SIZE vs "
  80. "device tree dcache-line-size\n",
  81. CONFIG_NIOS2_DCACHE_LINE_SIZE, cpuinfo.dcache_line_size);
  82. cpuinfo.dcache_size = fcpu(cpu, "dcache-size");
  83. if (CONFIG_NIOS2_DCACHE_SIZE != cpuinfo.dcache_size)
  84. pr_warn("Warning: dcache size configuration mismatch "
  85. "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_SIZE vs "
  86. "device tree dcache-size\n",
  87. CONFIG_NIOS2_DCACHE_SIZE, cpuinfo.dcache_size);
  88. cpuinfo.tlb_pid_num_bits = fcpu(cpu, "altr,pid-num-bits");
  89. cpuinfo.tlb_num_ways_log2 = ilog2(cpuinfo.tlb_num_ways);
  90. cpuinfo.tlb_num_entries = fcpu(cpu, "altr,tlb-num-entries");
  91. cpuinfo.tlb_num_lines = cpuinfo.tlb_num_entries / cpuinfo.tlb_num_ways;
  92. cpuinfo.tlb_ptr_sz = fcpu(cpu, "altr,tlb-ptr-sz");
  93. cpuinfo.reset_addr = fcpu(cpu, "altr,reset-addr");
  94. cpuinfo.exception_addr = fcpu(cpu, "altr,exception-addr");
  95. cpuinfo.fast_tlb_miss_exc_addr = fcpu(cpu, "altr,fast-tlb-miss-addr");
  96. }
  97. #ifdef CONFIG_PROC_FS
  98. /*
  99. * Get CPU information for use by the procfs.
  100. */
  101. static int show_cpuinfo(struct seq_file *m, void *v)
  102. {
  103. const u32 clockfreq = cpuinfo.cpu_clock_freq;
  104. seq_printf(m,
  105. "CPU:\t\tNios II/%s\n"
  106. "MMU:\t\t%s\n"
  107. "FPU:\t\tnone\n"
  108. "Clocking:\t%u.%02u MHz\n"
  109. "BogoMips:\t%lu.%02lu\n"
  110. "Calibration:\t%lu loops\n",
  111. cpuinfo.cpu_impl,
  112. cpuinfo.mmu ? "present" : "none",
  113. clockfreq / 1000000, (clockfreq / 100000) % 10,
  114. (loops_per_jiffy * HZ) / 500000,
  115. ((loops_per_jiffy * HZ) / 5000) % 100,
  116. (loops_per_jiffy * HZ));
  117. seq_printf(m,
  118. "HW:\n"
  119. " MUL:\t\t%s\n"
  120. " MULX:\t\t%s\n"
  121. " DIV:\t\t%s\n",
  122. cpuinfo.has_mul ? "yes" : "no",
  123. cpuinfo.has_mulx ? "yes" : "no",
  124. cpuinfo.has_div ? "yes" : "no");
  125. seq_printf(m,
  126. "Icache:\t\t%ukB, line length: %u\n",
  127. cpuinfo.icache_size >> 10,
  128. cpuinfo.icache_line_size);
  129. seq_printf(m,
  130. "Dcache:\t\t%ukB, line length: %u\n",
  131. cpuinfo.dcache_size >> 10,
  132. cpuinfo.dcache_line_size);
  133. seq_printf(m,
  134. "TLB:\t\t%u ways, %u entries, %u PID bits\n",
  135. cpuinfo.tlb_num_ways,
  136. cpuinfo.tlb_num_entries,
  137. cpuinfo.tlb_pid_num_bits);
  138. return 0;
  139. }
  140. static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
  141. {
  142. unsigned long i = *pos;
  143. return i < num_possible_cpus() ? (void *) (i + 1) : NULL;
  144. }
  145. static void *cpuinfo_next(struct seq_file *m, void *v, loff_t *pos)
  146. {
  147. ++*pos;
  148. return cpuinfo_start(m, pos);
  149. }
  150. static void cpuinfo_stop(struct seq_file *m, void *v)
  151. {
  152. }
  153. const struct seq_operations cpuinfo_op = {
  154. .start = cpuinfo_start,
  155. .next = cpuinfo_next,
  156. .stop = cpuinfo_stop,
  157. .show = show_cpuinfo
  158. };
  159. #endif /* CONFIG_PROC_FS */