x86/intel_rdt: Make rdt_resources_all more readable
[linux-2.6-block.git] / arch / x86 / kernel / cpu / intel_rdt.h
CommitLineData
113c6097
FY
1#ifndef _ASM_X86_INTEL_RDT_H
2#define _ASM_X86_INTEL_RDT_H
3
5b825c3a 4#include <linux/sched.h>
8ff42c02 5#include <linux/kernfs.h>
5ff193fb
FY
6#include <linux/jump_label.h>
7
8#define IA32_L3_QOS_CFG 0xc81
113c6097 9#define IA32_L3_CBM_BASE 0xc90
c1c7c3f9 10#define IA32_L2_CBM_BASE 0xd10
05b93417 11#define IA32_MBA_THRTL_BASE 0xd50
113c6097 12
5ff193fb
FY
13#define L3_QOS_CDP_ENABLE 0x01ULL
14
15/**
16 * struct rdtgroup - store rdtgroup's data in resctrl file system.
17 * @kn: kernfs node
18 * @rdtgroup_list: linked list for all rdtgroups
19 * @closid: closid for this rdtgroup
12e0110c 20 * @cpu_mask: CPUs assigned to this rdtgroup
60cf5e10
FY
21 * @flags: status bits
22 * @waitcount: how many cpus expect to find this
12e0110c 23 * group when they acquire rdtgroup_mutex
5ff193fb
FY
24 */
25struct rdtgroup {
26 struct kernfs_node *kn;
27 struct list_head rdtgroup_list;
28 int closid;
12e0110c 29 struct cpumask cpu_mask;
60cf5e10
FY
30 int flags;
31 atomic_t waitcount;
5ff193fb
FY
32};
33
60cf5e10
FY
34/* rdtgroup.flags */
35#define RDT_DELETED 1
36
4ffa3c97
JO
37/* rftype.flags */
38#define RFTYPE_FLAGS_CPUS_LIST 1
39
5ff193fb
FY
40/* List of all resource groups */
41extern struct list_head rdt_all_groups;
42
de016df8
VS
43extern int max_name_width, max_data_width;
44
5ff193fb
FY
45int __init rdtgroup_init(void);
46
4e978d06
FY
47/**
48 * struct rftype - describe each file in the resctrl file system
17f8ba1d
TG
49 * @name: File name
50 * @mode: Access mode
51 * @kf_ops: File operations
4ffa3c97 52 * @flags: File specific RFTYPE_FLAGS_* flags
17f8ba1d
TG
53 * @seq_show: Show content of the file
54 * @write: Write to the file
4e978d06
FY
55 */
56struct rftype {
57 char *name;
58 umode_t mode;
59 struct kernfs_ops *kf_ops;
4ffa3c97 60 unsigned long flags;
4e978d06
FY
61
62 int (*seq_show)(struct kernfs_open_file *of,
63 struct seq_file *sf, void *v);
64 /*
65 * write() is the generic write callback which maps directly to
66 * kernfs write operation and overrides all other operations.
67 * Maximum write size is determined by ->max_write_len.
68 */
69 ssize_t (*write)(struct kernfs_open_file *of,
70 char *buf, size_t nbytes, loff_t off);
71};
72
0921c547
TG
73/**
74 * struct rdt_domain - group of cpus sharing an RDT resource
75 * @list: all instances of this resource
76 * @id: unique id for this instance
77 * @cpu_mask: which cpus share this resource
78 * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID)
79 * @new_ctrl: new ctrl value to be loaded
80 * @have_new_ctrl: did user provide new_ctrl for this domain
81 */
82struct rdt_domain {
83 struct list_head list;
84 int id;
85 struct cpumask cpu_mask;
86 u32 *ctrl_val;
87 u32 new_ctrl;
88 bool have_new_ctrl;
89};
90
91/**
92 * struct msr_param - set a range of MSRs from a domain
93 * @res: The resource to use
94 * @low: Beginning index from base MSR
95 * @high: End index
96 */
97struct msr_param {
98 struct rdt_resource *res;
99 int low;
100 int high;
101};
102
d3e11b4d
TG
103/**
104 * struct rdt_cache - Cache allocation related data
105 * @cbm_len: Length of the cache bit mask
106 * @min_cbm_bits: Minimum number of consecutive bits to be set
107 * @cbm_idx_mult: Multiplier of CBM index
108 * @cbm_idx_offset: Offset of CBM index. CBM index is computed by:
109 * closid * cbm_idx_multi + cbm_idx_offset
110 * in a cache bit mask
111 */
112struct rdt_cache {
113 unsigned int cbm_len;
114 unsigned int min_cbm_bits;
115 unsigned int cbm_idx_mult;
116 unsigned int cbm_idx_offset;
117};
118
05b93417
VS
119/**
120 * struct rdt_membw - Memory bandwidth allocation related data
121 * @max_delay: Max throttle delay. Delay is the hardware
122 * representation for memory bandwidth.
123 * @min_bw: Minimum memory bandwidth percentage user can request
124 * @bw_gran: Granularity at which the memory bandwidth is allocated
125 * @delay_linear: True if memory B/W delay is in linear scale
126 * @mb_map: Mapping of memory B/W percentage to memory B/W delay
127 */
128struct rdt_membw {
129 u32 max_delay;
130 u32 min_bw;
131 u32 bw_gran;
132 u32 delay_linear;
133 u32 *mb_map;
134};
135
c1c7c3f9
FY
136/**
137 * struct rdt_resource - attributes of an RDT resource
1b5c0b75
VS
138 * @alloc_enabled: Is allocation enabled on this machine
139 * @alloc_capable: Is allocation available on this machine
d3e11b4d
TG
140 * @name: Name to use in "schemata" file
141 * @num_closid: Number of CLOSIDs available
142 * @cache_level: Which cache level defines scope of this resource
143 * @default_ctrl: Specifies default cache cbm or memory B/W percent.
144 * @msr_base: Base MSR address for CBMs
0921c547 145 * @msr_update: Function pointer to update QOS MSRs
d3e11b4d
TG
146 * @data_width: Character width of data when displaying
147 * @domains: All domains for this resource
148 * @cache: Cache allocation related data
6a507a6a
VS
149 * @info_files: resctrl info files for the resource
150 * @nr_info_files: Number of info files
c6ea67de
VS
151 * @format_str: Per resource format string to show domain value
152 * @parse_ctrlval: Per resource function pointer to parse control values
c1c7c3f9
FY
153 */
154struct rdt_resource {
1b5c0b75
VS
155 bool alloc_enabled;
156 bool alloc_capable;
c1c7c3f9
FY
157 char *name;
158 int num_closid;
d3e11b4d 159 int cache_level;
2545e9f5 160 u32 default_ctrl;
d3e11b4d 161 unsigned int msr_base;
0921c547
TG
162 void (*msr_update) (struct rdt_domain *d, struct msr_param *m,
163 struct rdt_resource *r);
de016df8 164 int data_width;
c1c7c3f9 165 struct list_head domains;
a83827d0
TG
166 struct rdt_cache cache;
167 struct rdt_membw membw;
6a507a6a
VS
168 struct rftype *info_files;
169 int nr_info_files;
c6ea67de
VS
170 const char *format_str;
171 int (*parse_ctrlval) (char *buf, struct rdt_resource *r,
172 struct rdt_domain *d);
c1c7c3f9
FY
173};
174
6a507a6a 175void rdt_get_cache_infofile(struct rdt_resource *r);
db69ef65 176void rdt_get_mba_infofile(struct rdt_resource *r);
c6ea67de 177int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d);
64e8ed3d 178int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d);
6a507a6a 179
2264d9c7
TL
180extern struct mutex rdtgroup_mutex;
181
c1c7c3f9 182extern struct rdt_resource rdt_resources_all[];
5ff193fb 183extern struct rdtgroup rdtgroup_default;
1b5c0b75 184DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
5ff193fb
FY
185
186int __init rdtgroup_init(void);
c1c7c3f9
FY
187
188enum {
189 RDT_RESOURCE_L3,
190 RDT_RESOURCE_L3DATA,
191 RDT_RESOURCE_L3CODE,
192 RDT_RESOURCE_L2,
05b93417 193 RDT_RESOURCE_MBA,
c1c7c3f9
FY
194
195 /* Must be the last */
196 RDT_NUM_RESOURCES,
197};
198
1b5c0b75 199#define for_each_alloc_capable_rdt_resource(r) \
c1c7c3f9 200 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
17f8ba1d 201 r++) \
1b5c0b75 202 if (r->alloc_capable)
c1c7c3f9 203
1b5c0b75 204#define for_each_alloc_enabled_rdt_resource(r) \
2264d9c7
TL
205 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
206 r++) \
1b5c0b75 207 if (r->alloc_enabled)
2264d9c7 208
c1c7c3f9
FY
209/* CPUID.(EAX=10H, ECX=ResID=1).EAX */
210union cpuid_0x10_1_eax {
211 struct {
212 unsigned int cbm_len:5;
213 } split;
214 unsigned int full;
215};
216
ab66a33b
VS
217/* CPUID.(EAX=10H, ECX=ResID=3).EAX */
218union cpuid_0x10_3_eax {
219 struct {
220 unsigned int max_delay:12;
221 } split;
222 unsigned int full;
223};
224
2545e9f5
VS
225/* CPUID.(EAX=10H, ECX=ResID).EDX */
226union cpuid_0x10_x_edx {
c1c7c3f9
FY
227 struct {
228 unsigned int cos_max:16;
229 } split;
230 unsigned int full;
231};
2264d9c7 232
12e0110c
TL
233DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid);
234
2545e9f5 235void rdt_ctrl_update(void *arg);
60cf5e10
FY
236struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
237void rdtgroup_kn_unlock(struct kernfs_node *kn);
60ec2440
TL
238ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
239 char *buf, size_t nbytes, loff_t off);
240int rdtgroup_schemata_show(struct kernfs_open_file *of,
241 struct seq_file *s, void *v);
4f341a5e 242
113c6097 243#endif /* _ASM_X86_INTEL_RDT_H */