cacheinfo.h 3.7 KB

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