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