0001
0002 #ifndef _LINUX_CACHEINFO_H
0003 #define _LINUX_CACHEINFO_H
0004
0005 #include <linux/bitops.h>
0006 #include <linux/cpumask.h>
0007 #include <linux/smp.h>
0008
0009 struct device_node;
0010 struct attribute;
0011
0012 enum cache_type {
0013 CACHE_TYPE_NOCACHE = 0,
0014 CACHE_TYPE_INST = BIT(0),
0015 CACHE_TYPE_DATA = BIT(1),
0016 CACHE_TYPE_SEPARATE = CACHE_TYPE_INST | CACHE_TYPE_DATA,
0017 CACHE_TYPE_UNIFIED = BIT(2),
0018 };
0019
0020 extern unsigned int coherency_max_size;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 struct cacheinfo {
0050 unsigned int id;
0051 enum cache_type type;
0052 unsigned int level;
0053 unsigned int coherency_line_size;
0054 unsigned int number_of_sets;
0055 unsigned int ways_of_associativity;
0056 unsigned int physical_line_partition;
0057 unsigned int size;
0058 cpumask_t shared_cpu_map;
0059 unsigned int attributes;
0060 #define CACHE_WRITE_THROUGH BIT(0)
0061 #define CACHE_WRITE_BACK BIT(1)
0062 #define CACHE_WRITE_POLICY_MASK \
0063 (CACHE_WRITE_THROUGH | CACHE_WRITE_BACK)
0064 #define CACHE_READ_ALLOCATE BIT(2)
0065 #define CACHE_WRITE_ALLOCATE BIT(3)
0066 #define CACHE_ALLOCATE_POLICY_MASK \
0067 (CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE)
0068 #define CACHE_ID BIT(4)
0069 void *fw_token;
0070 bool disable_sysfs;
0071 void *priv;
0072 };
0073
0074 struct cpu_cacheinfo {
0075 struct cacheinfo *info_list;
0076 unsigned int num_levels;
0077 unsigned int num_leaves;
0078 bool cpu_map_populated;
0079 };
0080
0081 struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu);
0082 int init_cache_level(unsigned int cpu);
0083 int populate_cache_leaves(unsigned int cpu);
0084 int cache_setup_acpi(unsigned int cpu);
0085 bool last_level_cache_is_valid(unsigned int cpu);
0086 bool last_level_cache_is_shared(unsigned int cpu_x, unsigned int cpu_y);
0087 int detect_cache_attributes(unsigned int cpu);
0088 #ifndef CONFIG_ACPI_PPTT
0089
0090
0091
0092
0093
0094
0095
0096
0097 static inline int acpi_find_last_cache_level(unsigned int cpu)
0098 {
0099 return 0;
0100 }
0101 #else
0102 int acpi_find_last_cache_level(unsigned int cpu);
0103 #endif
0104
0105 const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
0106
0107
0108
0109
0110
0111 static inline int get_cpu_cacheinfo_id(int cpu, int level)
0112 {
0113 struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
0114 int i;
0115
0116 for (i = 0; i < ci->num_leaves; i++) {
0117 if (ci->info_list[i].level == level) {
0118 if (ci->info_list[i].attributes & CACHE_ID)
0119 return ci->info_list[i].id;
0120 return -1;
0121 }
0122 }
0123
0124 return -1;
0125 }
0126
0127 #endif