Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
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  * struct cacheinfo - represent a cache leaf node
0024  * @id: This cache's id. It is unique among caches with the same (type, level).
0025  * @type: type of the cache - data, inst or unified
0026  * @level: represents the hierarchy in the multi-level cache
0027  * @coherency_line_size: size of each cache line usually representing
0028  *  the minimum amount of data that gets transferred from memory
0029  * @number_of_sets: total number of sets, a set is a collection of cache
0030  *  lines sharing the same index
0031  * @ways_of_associativity: number of ways in which a particular memory
0032  *  block can be placed in the cache
0033  * @physical_line_partition: number of physical cache lines sharing the
0034  *  same cachetag
0035  * @size: Total size of the cache
0036  * @shared_cpu_map: logical cpumask representing all the cpus sharing
0037  *  this cache node
0038  * @attributes: bitfield representing various cache attributes
0039  * @fw_token: Unique value used to determine if different cacheinfo
0040  *  structures represent a single hardware cache instance.
0041  * @disable_sysfs: indicates whether this node is visible to the user via
0042  *  sysfs or not
0043  * @priv: pointer to any private data structure specific to particular
0044  *  cache design
0045  *
0046  * While @of_node, @disable_sysfs and @priv are used for internal book
0047  * keeping, the remaining members form the core properties of the cache
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  * acpi_find_last_cache_level is only called on ACPI enabled
0091  * platforms using the PPTT for topology. This means that if
0092  * the platform supports other firmware configuration methods
0093  * we need to stub out the call when ACPI is disabled.
0094  * ACPI enabled platforms not using PPTT won't be making calls
0095  * to this function so we need not worry about them.
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  * Get the id of the cache associated with @cpu at level @level.
0109  * cpuhp lock must be held.
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 /* _LINUX_CACHEINFO_H */