cacheinfo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * MIPS cacheinfo support
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/cacheinfo.h>
  17. /* Populates leaf and increments to next leaf */
  18. #define populate_cache(cache, leaf, c_level, c_type) \
  19. do { \
  20. leaf->type = c_type; \
  21. leaf->level = c_level; \
  22. leaf->coherency_line_size = c->cache.linesz; \
  23. leaf->number_of_sets = c->cache.sets; \
  24. leaf->ways_of_associativity = c->cache.ways; \
  25. leaf->size = c->cache.linesz * c->cache.sets * \
  26. c->cache.ways; \
  27. leaf++; \
  28. } while (0)
  29. static int __init_cache_level(unsigned int cpu)
  30. {
  31. struct cpuinfo_mips *c = &current_cpu_data;
  32. struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
  33. int levels = 0, leaves = 0;
  34. /*
  35. * If Dcache is not set, we assume the cache structures
  36. * are not properly initialized.
  37. */
  38. if (c->dcache.waysize)
  39. levels += 1;
  40. else
  41. return -ENOENT;
  42. leaves += (c->icache.waysize) ? 2 : 1;
  43. if (c->scache.waysize) {
  44. levels++;
  45. leaves++;
  46. }
  47. if (c->tcache.waysize) {
  48. levels++;
  49. leaves++;
  50. }
  51. this_cpu_ci->num_levels = levels;
  52. this_cpu_ci->num_leaves = leaves;
  53. return 0;
  54. }
  55. static void fill_cpumask_siblings(int cpu, cpumask_t *cpu_map)
  56. {
  57. int cpu1;
  58. for_each_possible_cpu(cpu1)
  59. if (cpus_are_siblings(cpu, cpu1))
  60. cpumask_set_cpu(cpu1, cpu_map);
  61. }
  62. static void fill_cpumask_cluster(int cpu, cpumask_t *cpu_map)
  63. {
  64. int cpu1;
  65. int cluster = cpu_cluster(&cpu_data[cpu]);
  66. for_each_possible_cpu(cpu1)
  67. if (cpu_cluster(&cpu_data[cpu1]) == cluster)
  68. cpumask_set_cpu(cpu1, cpu_map);
  69. }
  70. static int __populate_cache_leaves(unsigned int cpu)
  71. {
  72. struct cpuinfo_mips *c = &current_cpu_data;
  73. struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
  74. struct cacheinfo *this_leaf = this_cpu_ci->info_list;
  75. if (c->icache.waysize) {
  76. /* L1 caches are per core */
  77. fill_cpumask_siblings(cpu, &this_leaf->shared_cpu_map);
  78. populate_cache(dcache, this_leaf, 1, CACHE_TYPE_DATA);
  79. fill_cpumask_siblings(cpu, &this_leaf->shared_cpu_map);
  80. populate_cache(icache, this_leaf, 1, CACHE_TYPE_INST);
  81. } else {
  82. populate_cache(dcache, this_leaf, 1, CACHE_TYPE_UNIFIED);
  83. }
  84. if (c->scache.waysize) {
  85. /* L2 cache is per cluster */
  86. fill_cpumask_cluster(cpu, &this_leaf->shared_cpu_map);
  87. populate_cache(scache, this_leaf, 2, CACHE_TYPE_UNIFIED);
  88. }
  89. if (c->tcache.waysize)
  90. populate_cache(tcache, this_leaf, 3, CACHE_TYPE_UNIFIED);
  91. this_cpu_ci->cpu_map_populated = true;
  92. return 0;
  93. }
  94. DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
  95. DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)