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