cacheinfo.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _LINUX_CACHEINFO_H
  2. #define _LINUX_CACHEINFO_H
  3. #include <linux/bitops.h>
  4. #include <linux/cpumask.h>
  5. #include <linux/smp.h>
  6. struct device_node;
  7. struct attribute;
  8. enum cache_type {
  9. CACHE_TYPE_NOCACHE = 0,
  10. CACHE_TYPE_INST = BIT(0),
  11. CACHE_TYPE_DATA = BIT(1),
  12. CACHE_TYPE_SEPARATE = CACHE_TYPE_INST | CACHE_TYPE_DATA,
  13. CACHE_TYPE_UNIFIED = BIT(2),
  14. };
  15. /**
  16. * struct cacheinfo - represent a cache leaf node
  17. * @type: type of the cache - data, inst or unified
  18. * @level: represents the hierarchy in the multi-level cache
  19. * @coherency_line_size: size of each cache line usually representing
  20. * the minimum amount of data that gets transferred from memory
  21. * @number_of_sets: total number of sets, a set is a collection of cache
  22. * lines sharing the same index
  23. * @ways_of_associativity: number of ways in which a particular memory
  24. * block can be placed in the cache
  25. * @physical_line_partition: number of physical cache lines sharing the
  26. * same cachetag
  27. * @size: Total size of the cache
  28. * @shared_cpu_map: logical cpumask representing all the cpus sharing
  29. * this cache node
  30. * @attributes: bitfield representing various cache attributes
  31. * @of_node: if devicetree is used, this represents either the cpu node in
  32. * case there's no explicit cache node or the cache node itself in the
  33. * device tree
  34. * @disable_sysfs: indicates whether this node is visible to the user via
  35. * sysfs or not
  36. * @priv: pointer to any private data structure specific to particular
  37. * cache design
  38. *
  39. * While @of_node, @disable_sysfs and @priv are used for internal book
  40. * keeping, the remaining members form the core properties of the cache
  41. */
  42. struct cacheinfo {
  43. enum cache_type type;
  44. unsigned int level;
  45. unsigned int coherency_line_size;
  46. unsigned int number_of_sets;
  47. unsigned int ways_of_associativity;
  48. unsigned int physical_line_partition;
  49. unsigned int size;
  50. cpumask_t shared_cpu_map;
  51. unsigned int attributes;
  52. #define CACHE_WRITE_THROUGH BIT(0)
  53. #define CACHE_WRITE_BACK BIT(1)
  54. #define CACHE_WRITE_POLICY_MASK \
  55. (CACHE_WRITE_THROUGH | CACHE_WRITE_BACK)
  56. #define CACHE_READ_ALLOCATE BIT(2)
  57. #define CACHE_WRITE_ALLOCATE BIT(3)
  58. #define CACHE_ALLOCATE_POLICY_MASK \
  59. (CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE)
  60. struct device_node *of_node;
  61. bool disable_sysfs;
  62. void *priv;
  63. };
  64. struct cpu_cacheinfo {
  65. struct cacheinfo *info_list;
  66. unsigned int num_levels;
  67. unsigned int num_leaves;
  68. bool cpu_map_populated;
  69. };
  70. /*
  71. * Helpers to make sure "func" is executed on the cpu whose cache
  72. * attributes are being detected
  73. */
  74. #define DEFINE_SMP_CALL_CACHE_FUNCTION(func) \
  75. static inline void _##func(void *ret) \
  76. { \
  77. int cpu = smp_processor_id(); \
  78. *(int *)ret = __##func(cpu); \
  79. } \
  80. \
  81. int func(unsigned int cpu) \
  82. { \
  83. int ret; \
  84. smp_call_function_single(cpu, _##func, &ret, true); \
  85. return ret; \
  86. }
  87. struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu);
  88. int init_cache_level(unsigned int cpu);
  89. int populate_cache_leaves(unsigned int cpu);
  90. const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
  91. #endif /* _LINUX_CACHEINFO_H */