cacheinfo.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_CACHEINFO_H
  3. #define _LINUX_CACHEINFO_H
  4. #include <linux/bitops.h>
  5. #include <linux/cpu.h>
  6. #include <linux/cpumask.h>
  7. #include <linux/smp.h>
  8. struct device_node;
  9. struct attribute;
  10. enum cache_type {
  11. CACHE_TYPE_NOCACHE = 0,
  12. CACHE_TYPE_INST = BIT(0),
  13. CACHE_TYPE_DATA = BIT(1),
  14. CACHE_TYPE_SEPARATE = CACHE_TYPE_INST | CACHE_TYPE_DATA,
  15. CACHE_TYPE_UNIFIED = BIT(2),
  16. };
  17. extern unsigned int coherency_max_size;
  18. /**
  19. * struct cacheinfo - represent a cache leaf node
  20. * @id: This cache's id. It is unique among caches with the same (type, level).
  21. * @type: type of the cache - data, inst or unified
  22. * @level: represents the hierarchy in the multi-level cache
  23. * @coherency_line_size: size of each cache line usually representing
  24. * the minimum amount of data that gets transferred from memory
  25. * @number_of_sets: total number of sets, a set is a collection of cache
  26. * lines sharing the same index
  27. * @ways_of_associativity: number of ways in which a particular memory
  28. * block can be placed in the cache
  29. * @physical_line_partition: number of physical cache lines sharing the
  30. * same cachetag
  31. * @size: Total size of the cache
  32. * @shared_cpu_map: logical cpumask representing all the cpus sharing
  33. * this cache node
  34. * @attributes: bitfield representing various cache attributes
  35. * @fw_token: Unique value used to determine if different cacheinfo
  36. * structures represent a single hardware cache instance.
  37. * @disable_sysfs: indicates whether this node is visible to the user via
  38. * sysfs or not
  39. * @priv: pointer to any private data structure specific to particular
  40. * cache design
  41. *
  42. * While @of_node, @disable_sysfs and @priv are used for internal book
  43. * keeping, the remaining members form the core properties of the cache
  44. */
  45. struct cacheinfo {
  46. unsigned int id;
  47. enum cache_type type;
  48. unsigned int level;
  49. unsigned int coherency_line_size;
  50. unsigned int number_of_sets;
  51. unsigned int ways_of_associativity;
  52. unsigned int physical_line_partition;
  53. unsigned int size;
  54. cpumask_t shared_cpu_map;
  55. unsigned int attributes;
  56. #define CACHE_WRITE_THROUGH BIT(0)
  57. #define CACHE_WRITE_BACK BIT(1)
  58. #define CACHE_WRITE_POLICY_MASK \
  59. (CACHE_WRITE_THROUGH | CACHE_WRITE_BACK)
  60. #define CACHE_READ_ALLOCATE BIT(2)
  61. #define CACHE_WRITE_ALLOCATE BIT(3)
  62. #define CACHE_ALLOCATE_POLICY_MASK \
  63. (CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE)
  64. #define CACHE_ID BIT(4)
  65. void *fw_token;
  66. bool disable_sysfs;
  67. void *priv;
  68. };
  69. struct cpu_cacheinfo {
  70. struct cacheinfo *info_list;
  71. unsigned int num_levels;
  72. unsigned int num_leaves;
  73. bool cpu_map_populated;
  74. };
  75. struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu);
  76. int init_cache_level(unsigned int cpu);
  77. int populate_cache_leaves(unsigned int cpu);
  78. int cache_setup_acpi(unsigned int cpu);
  79. #ifndef CONFIG_ACPI_PPTT
  80. /*
  81. * acpi_find_last_cache_level is only called on ACPI enabled
  82. * platforms using the PPTT for topology. This means that if
  83. * the platform supports other firmware configuration methods
  84. * we need to stub out the call when ACPI is disabled.
  85. * ACPI enabled platforms not using PPTT won't be making calls
  86. * to this function so we need not worry about them.
  87. */
  88. static inline int acpi_find_last_cache_level(unsigned int cpu)
  89. {
  90. return 0;
  91. }
  92. #else
  93. int acpi_find_last_cache_level(unsigned int cpu);
  94. #endif
  95. const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
  96. /*
  97. * Get the id of the cache associated with @cpu at level @level.
  98. * cpuhp lock must be held.
  99. */
  100. static inline int get_cpu_cacheinfo_id(int cpu, int level)
  101. {
  102. struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
  103. int i;
  104. for (i = 0; i < ci->num_leaves; i++) {
  105. if (ci->info_list[i].level == level) {
  106. if (ci->info_list[i].attributes & CACHE_ID)
  107. return ci->info_list[i].id;
  108. return -1;
  109. }
  110. }
  111. return -1;
  112. }
  113. #endif /* _LINUX_CACHEINFO_H */