cpuinfo.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.has_bmx = of_property_read_bool(cpu, "altr,has-bmx");
  59. cpuinfo.has_cdx = of_property_read_bool(cpu, "altr,has-cdx");
  60. cpuinfo.mmu = of_property_read_bool(cpu, "altr,has-mmu");
  61. if (IS_ENABLED(CONFIG_NIOS2_HW_DIV_SUPPORT) && !cpuinfo.has_div)
  62. err_cpu("DIV");
  63. if (IS_ENABLED(CONFIG_NIOS2_HW_MUL_SUPPORT) && !cpuinfo.has_mul)
  64. err_cpu("MUL");
  65. if (IS_ENABLED(CONFIG_NIOS2_HW_MULX_SUPPORT) && !cpuinfo.has_mulx)
  66. err_cpu("MULX");
  67. if (IS_ENABLED(CONFIG_NIOS2_BMX_SUPPORT) && !cpuinfo.has_bmx)
  68. err_cpu("BMX");
  69. if (IS_ENABLED(CONFIG_NIOS2_CDX_SUPPORT) && !cpuinfo.has_cdx)
  70. err_cpu("CDX");
  71. cpuinfo.tlb_num_ways = fcpu(cpu, "altr,tlb-num-ways");
  72. if (!cpuinfo.tlb_num_ways)
  73. panic("altr,tlb-num-ways can't be 0. Please check your hardware "
  74. "system\n");
  75. cpuinfo.icache_line_size = fcpu(cpu, "icache-line-size");
  76. cpuinfo.icache_size = fcpu(cpu, "icache-size");
  77. if (CONFIG_NIOS2_ICACHE_SIZE != cpuinfo.icache_size)
  78. pr_warn("Warning: icache size configuration mismatch "
  79. "(0x%x vs 0x%x) of CONFIG_NIOS2_ICACHE_SIZE vs "
  80. "device tree icache-size\n",
  81. CONFIG_NIOS2_ICACHE_SIZE, cpuinfo.icache_size);
  82. cpuinfo.dcache_line_size = fcpu(cpu, "dcache-line-size");
  83. if (CONFIG_NIOS2_DCACHE_LINE_SIZE != cpuinfo.dcache_line_size)
  84. pr_warn("Warning: dcache line size configuration mismatch "
  85. "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_LINE_SIZE vs "
  86. "device tree dcache-line-size\n",
  87. CONFIG_NIOS2_DCACHE_LINE_SIZE, cpuinfo.dcache_line_size);
  88. cpuinfo.dcache_size = fcpu(cpu, "dcache-size");
  89. if (CONFIG_NIOS2_DCACHE_SIZE != cpuinfo.dcache_size)
  90. pr_warn("Warning: dcache size configuration mismatch "
  91. "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_SIZE vs "
  92. "device tree dcache-size\n",
  93. CONFIG_NIOS2_DCACHE_SIZE, cpuinfo.dcache_size);
  94. cpuinfo.tlb_pid_num_bits = fcpu(cpu, "altr,pid-num-bits");
  95. cpuinfo.tlb_num_ways_log2 = ilog2(cpuinfo.tlb_num_ways);
  96. cpuinfo.tlb_num_entries = fcpu(cpu, "altr,tlb-num-entries");
  97. cpuinfo.tlb_num_lines = cpuinfo.tlb_num_entries / cpuinfo.tlb_num_ways;
  98. cpuinfo.tlb_ptr_sz = fcpu(cpu, "altr,tlb-ptr-sz");
  99. cpuinfo.reset_addr = fcpu(cpu, "altr,reset-addr");
  100. cpuinfo.exception_addr = fcpu(cpu, "altr,exception-addr");
  101. cpuinfo.fast_tlb_miss_exc_addr = fcpu(cpu, "altr,fast-tlb-miss-addr");
  102. }
  103. #ifdef CONFIG_PROC_FS
  104. /*
  105. * Get CPU information for use by the procfs.
  106. */
  107. static int show_cpuinfo(struct seq_file *m, void *v)
  108. {
  109. const u32 clockfreq = cpuinfo.cpu_clock_freq;
  110. seq_printf(m,
  111. "CPU:\t\tNios II/%s\n"
  112. "REV:\t\t%i\n"
  113. "MMU:\t\t%s\n"
  114. "FPU:\t\tnone\n"
  115. "Clocking:\t%u.%02u MHz\n"
  116. "BogoMips:\t%lu.%02lu\n"
  117. "Calibration:\t%lu loops\n",
  118. cpuinfo.cpu_impl,
  119. CONFIG_NIOS2_ARCH_REVISION,
  120. cpuinfo.mmu ? "present" : "none",
  121. clockfreq / 1000000, (clockfreq / 100000) % 10,
  122. (loops_per_jiffy * HZ) / 500000,
  123. ((loops_per_jiffy * HZ) / 5000) % 100,
  124. (loops_per_jiffy * HZ));
  125. seq_printf(m,
  126. "HW:\n"
  127. " MUL:\t\t%s\n"
  128. " MULX:\t\t%s\n"
  129. " DIV:\t\t%s\n"
  130. " BMX:\t\t%s\n"
  131. " CDX:\t\t%s\n",
  132. cpuinfo.has_mul ? "yes" : "no",
  133. cpuinfo.has_mulx ? "yes" : "no",
  134. cpuinfo.has_div ? "yes" : "no",
  135. cpuinfo.has_bmx ? "yes" : "no",
  136. cpuinfo.has_cdx ? "yes" : "no");
  137. seq_printf(m,
  138. "Icache:\t\t%ukB, line length: %u\n",
  139. cpuinfo.icache_size >> 10,
  140. cpuinfo.icache_line_size);
  141. seq_printf(m,
  142. "Dcache:\t\t%ukB, line length: %u\n",
  143. cpuinfo.dcache_size >> 10,
  144. cpuinfo.dcache_line_size);
  145. seq_printf(m,
  146. "TLB:\t\t%u ways, %u entries, %u PID bits\n",
  147. cpuinfo.tlb_num_ways,
  148. cpuinfo.tlb_num_entries,
  149. cpuinfo.tlb_pid_num_bits);
  150. return 0;
  151. }
  152. static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
  153. {
  154. unsigned long i = *pos;
  155. return i < num_possible_cpus() ? (void *) (i + 1) : NULL;
  156. }
  157. static void *cpuinfo_next(struct seq_file *m, void *v, loff_t *pos)
  158. {
  159. ++*pos;
  160. return cpuinfo_start(m, pos);
  161. }
  162. static void cpuinfo_stop(struct seq_file *m, void *v)
  163. {
  164. }
  165. const struct seq_operations cpuinfo_op = {
  166. .start = cpuinfo_start,
  167. .next = cpuinfo_next,
  168. .stop = cpuinfo_stop,
  169. .show = show_cpuinfo
  170. };
  171. #endif /* CONFIG_PROC_FS */