blob: 362c8fe695f3e7df4875edff238994242835220c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Fenghua Yu113c6092016-10-22 06:19:54 -07002#ifndef _ASM_X86_INTEL_RDT_H
3#define _ASM_X86_INTEL_RDT_H
4
Ingo Molnar5b825c32017-02-02 17:54:15 +01005#include <linux/sched.h>
Borislav Petkov8ff42c022016-11-02 17:51:17 +01006#include <linux/kernfs.h>
Fenghua Yu5ff193f2016-10-28 15:04:42 -07007#include <linux/jump_label.h>
8
9#define IA32_L3_QOS_CFG 0xc81
Fenghua Yu99adde92017-12-20 14:57:23 -080010#define IA32_L2_QOS_CFG 0xc82
Fenghua Yu113c6092016-10-22 06:19:54 -070011#define IA32_L3_CBM_BASE 0xc90
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -070012#define IA32_L2_CBM_BASE 0xd10
Vikas Shivappa05b93412017-04-07 17:33:53 -070013#define IA32_MBA_THRTL_BASE 0xd50
Fenghua Yu113c6092016-10-22 06:19:54 -070014
Fenghua Yu5ff193f2016-10-28 15:04:42 -070015#define L3_QOS_CDP_ENABLE 0x01ULL
16
Fenghua Yu99adde92017-12-20 14:57:23 -080017#define L2_QOS_CDP_ENABLE 0x01ULL
18
Vikas Shivappa6a445ed2017-07-25 14:14:27 -070019/*
20 * Event IDs are used to program IA32_QM_EVTSEL before reading event
21 * counter from IA32_QM_CTR
22 */
23#define QOS_L3_OCCUP_EVENT_ID 0x01
24#define QOS_L3_MBM_TOTAL_EVENT_ID 0x02
25#define QOS_L3_MBM_LOCAL_EVENT_ID 0x03
Tony Luck9f524252017-07-25 14:14:45 -070026
Vikas Shivappa24247ae2017-08-15 18:00:43 -070027#define CQM_LIMBOCHECK_INTERVAL 1000
28
Tony Luck9f524252017-07-25 14:14:45 -070029#define MBM_CNTR_WIDTH 24
Vikas Shivappae3302682017-07-25 14:14:47 -070030#define MBM_OVERFLOW_INTERVAL 1000
Vikas Shivappade73f382018-04-20 15:36:21 -070031#define MAX_MBA_BW 100u
Tony Luck9f524252017-07-25 14:14:45 -070032
Vikas Shivappaedf6fa12017-07-25 14:14:28 -070033#define RMID_VAL_ERROR BIT_ULL(63)
34#define RMID_VAL_UNAVAIL BIT_ULL(62)
Vikas Shivappa6a445ed2017-07-25 14:14:27 -070035
Vikas Shivappae3302682017-07-25 14:14:47 -070036DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
37
Vikas Shivappa6a445ed2017-07-25 14:14:27 -070038/**
39 * struct mon_evt - Entry in the event list of a resource
40 * @evtid: event id
41 * @name: name of the event
42 */
43struct mon_evt {
44 u32 evtid;
45 char *name;
46 struct list_head list;
47};
48
Vikas Shivappad89b7372017-07-25 14:14:38 -070049/**
50 * struct mon_data_bits - Monitoring details for each event file
51 * @rid: Resource id associated with the event file.
52 * @evtid: Event id associated with the event file
53 * @domid: The domain to which the event file belongs
54 */
55union mon_data_bits {
56 void *priv;
57 struct {
58 unsigned int rid : 10;
59 unsigned int evtid : 8;
60 unsigned int domid : 14;
61 } u;
62};
63
64struct rmid_read {
65 struct rdtgroup *rgrp;
Tony Luck9f524252017-07-25 14:14:45 -070066 struct rdt_domain *d;
Vikas Shivappad89b7372017-07-25 14:14:38 -070067 int evtid;
Vikas Shivappaa4de1df2017-07-25 14:14:46 -070068 bool first;
Vikas Shivappad89b7372017-07-25 14:14:38 -070069 u64 val;
70};
71
Vikas Shivappa6a445ed2017-07-25 14:14:27 -070072extern unsigned int intel_cqm_threshold;
73extern bool rdt_alloc_capable;
74extern bool rdt_mon_capable;
75extern unsigned int rdt_mon_features;
Vikas Shivappac7d9aac2017-07-25 14:14:32 -070076
77enum rdt_group_type {
78 RDTCTRL_GROUP = 0,
79 RDTMON_GROUP,
80 RDT_NUM_GROUP,
81};
82
83/**
Reinette Chatreeb956a62018-06-22 15:41:54 -070084 * enum rdtgrp_mode - Mode of a RDT resource group
85 * @RDT_MODE_SHAREABLE: This resource group allows sharing of its allocations
Reinette Chatre414dd2b2018-06-22 15:42:00 -070086 * @RDT_MODE_EXCLUSIVE: No sharing of this resource group's allocations allowed
Reinette Chatreeb956a62018-06-22 15:41:54 -070087 *
88 * The mode of a resource group enables control over the allowed overlap
89 * between allocations associated with different resource groups (classes
90 * of service). User is able to modify the mode of a resource group by
91 * writing to the "mode" resctrl file associated with the resource group.
92 */
93enum rdtgrp_mode {
94 RDT_MODE_SHAREABLE = 0,
Reinette Chatre414dd2b2018-06-22 15:42:00 -070095 RDT_MODE_EXCLUSIVE,
Reinette Chatreeb956a62018-06-22 15:41:54 -070096
97 /* Must be last */
98 RDT_NUM_MODES,
99};
100
101/**
Vikas Shivappac7d9aac2017-07-25 14:14:32 -0700102 * struct mongroup - store mon group's data in resctrl fs.
Vikas Shivappad89b7372017-07-25 14:14:38 -0700103 * @mon_data_kn kernlfs node for the mon_data directory
Vikas Shivappac7d9aac2017-07-25 14:14:32 -0700104 * @parent: parent rdtgrp
105 * @crdtgrp_list: child rdtgroup node list
106 * @rmid: rmid for this rdtgroup
107 */
108struct mongroup {
Vikas Shivappad89b7372017-07-25 14:14:38 -0700109 struct kernfs_node *mon_data_kn;
Vikas Shivappac7d9aac2017-07-25 14:14:32 -0700110 struct rdtgroup *parent;
111 struct list_head crdtgrp_list;
112 u32 rmid;
113};
114
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700115/**
116 * struct rdtgroup - store rdtgroup's data in resctrl file system.
117 * @kn: kernfs node
118 * @rdtgroup_list: linked list for all rdtgroups
119 * @closid: closid for this rdtgroup
Tony Luck12e01102016-10-28 15:04:45 -0700120 * @cpu_mask: CPUs assigned to this rdtgroup
Fenghua Yu60cf5e12016-10-28 15:04:44 -0700121 * @flags: status bits
122 * @waitcount: how many cpus expect to find this
Tony Luck12e01102016-10-28 15:04:45 -0700123 * group when they acquire rdtgroup_mutex
Vikas Shivappac7d9aac2017-07-25 14:14:32 -0700124 * @type: indicates type of this rdtgroup - either
125 * monitor only or ctrl_mon group
126 * @mon: mongroup related data
Reinette Chatre472ef09b2018-06-22 15:41:55 -0700127 * @mode: mode of resource group
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700128 */
129struct rdtgroup {
130 struct kernfs_node *kn;
131 struct list_head rdtgroup_list;
Vikas Shivappa0734ded2017-07-25 14:14:33 -0700132 u32 closid;
Tony Luck12e01102016-10-28 15:04:45 -0700133 struct cpumask cpu_mask;
Fenghua Yu60cf5e12016-10-28 15:04:44 -0700134 int flags;
135 atomic_t waitcount;
Vikas Shivappac7d9aac2017-07-25 14:14:32 -0700136 enum rdt_group_type type;
137 struct mongroup mon;
Reinette Chatre472ef09b2018-06-22 15:41:55 -0700138 enum rdtgrp_mode mode;
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700139};
140
Fenghua Yu60cf5e12016-10-28 15:04:44 -0700141/* rdtgroup.flags */
142#define RDT_DELETED 1
143
Jiri Olsa4ffa3c92017-04-10 16:52:32 +0200144/* rftype.flags */
145#define RFTYPE_FLAGS_CPUS_LIST 1
146
Tony luck5dc1d5c2017-07-25 14:14:29 -0700147/*
148 * Define the file type flags for base and info directories.
149 */
150#define RFTYPE_INFO BIT(0)
151#define RFTYPE_BASE BIT(1)
152#define RF_CTRLSHIFT 4
Vikas Shivappad4ab3322017-07-25 14:14:30 -0700153#define RF_MONSHIFT 5
Tony Luck9b3a7fd2017-09-25 16:39:33 -0700154#define RF_TOPSHIFT 6
Tony luck5dc1d5c2017-07-25 14:14:29 -0700155#define RFTYPE_CTRL BIT(RF_CTRLSHIFT)
Vikas Shivappad4ab3322017-07-25 14:14:30 -0700156#define RFTYPE_MON BIT(RF_MONSHIFT)
Tony Luck9b3a7fd2017-09-25 16:39:33 -0700157#define RFTYPE_TOP BIT(RF_TOPSHIFT)
Tony luck5dc1d5c2017-07-25 14:14:29 -0700158#define RFTYPE_RES_CACHE BIT(8)
159#define RFTYPE_RES_MB BIT(9)
160#define RF_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL)
Vikas Shivappad4ab3322017-07-25 14:14:30 -0700161#define RF_MON_INFO (RFTYPE_INFO | RFTYPE_MON)
Tony Luck9b3a7fd2017-09-25 16:39:33 -0700162#define RF_TOP_INFO (RFTYPE_INFO | RFTYPE_TOP)
Tony luck5dc1d5c2017-07-25 14:14:29 -0700163#define RF_CTRL_BASE (RFTYPE_BASE | RFTYPE_CTRL)
164
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700165/* List of all resource groups */
166extern struct list_head rdt_all_groups;
167
Vikas Shivappade016df2017-04-03 14:44:17 -0700168extern int max_name_width, max_data_width;
169
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700170int __init rdtgroup_init(void);
171
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700172/**
Fenghua Yu4e978d02016-10-28 15:04:43 -0700173 * struct rftype - describe each file in the resctrl file system
Thomas Gleixner17f8ba12017-04-10 11:50:11 +0200174 * @name: File name
175 * @mode: Access mode
176 * @kf_ops: File operations
Jiri Olsa4ffa3c92017-04-10 16:52:32 +0200177 * @flags: File specific RFTYPE_FLAGS_* flags
Tony luck5dc1d5c2017-07-25 14:14:29 -0700178 * @fflags: File specific RF_* or RFTYPE_* flags
Thomas Gleixner17f8ba12017-04-10 11:50:11 +0200179 * @seq_show: Show content of the file
180 * @write: Write to the file
Fenghua Yu4e978d02016-10-28 15:04:43 -0700181 */
182struct rftype {
183 char *name;
184 umode_t mode;
185 struct kernfs_ops *kf_ops;
Jiri Olsa4ffa3c92017-04-10 16:52:32 +0200186 unsigned long flags;
Tony luck5dc1d5c2017-07-25 14:14:29 -0700187 unsigned long fflags;
Fenghua Yu4e978d02016-10-28 15:04:43 -0700188
189 int (*seq_show)(struct kernfs_open_file *of,
190 struct seq_file *sf, void *v);
191 /*
192 * write() is the generic write callback which maps directly to
193 * kernfs write operation and overrides all other operations.
194 * Maximum write size is determined by ->max_write_len.
195 */
196 ssize_t (*write)(struct kernfs_open_file *of,
197 char *buf, size_t nbytes, loff_t off);
198};
199
200/**
Tony Luck9f524252017-07-25 14:14:45 -0700201 * struct mbm_state - status for each MBM counter in each domain
202 * @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes)
203 * @prev_msr Value of IA32_QM_CTR for this RMID last time we read it
Vikas Shivappaba0f26d2018-04-20 15:36:20 -0700204 * @chunks_bw Total local data moved. Used for bandwidth calculation
205 * @prev_bw_msr:Value of previous IA32_QM_CTR for bandwidth counting
206 * @prev_bw The most recent bandwidth in MBps
207 * @delta_bw Difference between the current and previous bandwidth
208 * @delta_comp Indicates whether to compute the delta_bw
Tony Luck9f524252017-07-25 14:14:45 -0700209 */
210struct mbm_state {
211 u64 chunks;
212 u64 prev_msr;
Vikas Shivappaba0f26d2018-04-20 15:36:20 -0700213 u64 chunks_bw;
214 u64 prev_bw_msr;
215 u32 prev_bw;
216 u32 delta_bw;
217 bool delta_comp;
Tony Luck9f524252017-07-25 14:14:45 -0700218};
219
220/**
Tony Luck2264d9c2016-10-28 15:04:41 -0700221 * struct rdt_domain - group of cpus sharing an RDT resource
222 * @list: all instances of this resource
223 * @id: unique id for this instance
224 * @cpu_mask: which cpus share this resource
Vikas Shivappaedf6fa12017-07-25 14:14:28 -0700225 * @rmid_busy_llc:
226 * bitmap of which limbo RMIDs are above threshold
Tony Luck9f524252017-07-25 14:14:45 -0700227 * @mbm_total: saved state for MBM total bandwidth
228 * @mbm_local: saved state for MBM local bandwidth
Vikas Shivappae3302682017-07-25 14:14:47 -0700229 * @mbm_over: worker to periodically read MBM h/w counters
Vikas Shivappa24247ae2017-08-15 18:00:43 -0700230 * @cqm_limbo: worker to periodically read CQM h/w counters
Vikas Shivappae3302682017-07-25 14:14:47 -0700231 * @mbm_work_cpu:
232 * worker cpu for MBM h/w counters
Vikas Shivappa24247ae2017-08-15 18:00:43 -0700233 * @cqm_work_cpu:
234 * worker cpu for CQM h/w counters
Vikas Shivappa2545e9f2017-04-07 17:33:51 -0700235 * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID)
Vikas Shivappa1bd2a632018-04-20 15:36:18 -0700236 * @mbps_val: When mba_sc is enabled, this holds the bandwidth in MBps
Vikas Shivappa2545e9f2017-04-07 17:33:51 -0700237 * @new_ctrl: new ctrl value to be loaded
238 * @have_new_ctrl: did user provide new_ctrl for this domain
Tony Luck2264d9c2016-10-28 15:04:41 -0700239 */
240struct rdt_domain {
241 struct list_head list;
242 int id;
243 struct cpumask cpu_mask;
Vikas Shivappaedf6fa12017-07-25 14:14:28 -0700244 unsigned long *rmid_busy_llc;
Tony Luck9f524252017-07-25 14:14:45 -0700245 struct mbm_state *mbm_total;
246 struct mbm_state *mbm_local;
Vikas Shivappae3302682017-07-25 14:14:47 -0700247 struct delayed_work mbm_over;
Vikas Shivappa24247ae2017-08-15 18:00:43 -0700248 struct delayed_work cqm_limbo;
Vikas Shivappae3302682017-07-25 14:14:47 -0700249 int mbm_work_cpu;
Vikas Shivappa24247ae2017-08-15 18:00:43 -0700250 int cqm_work_cpu;
Vikas Shivappa2545e9f2017-04-07 17:33:51 -0700251 u32 *ctrl_val;
Vikas Shivappa1bd2a632018-04-20 15:36:18 -0700252 u32 *mbps_val;
Vikas Shivappa2545e9f2017-04-07 17:33:51 -0700253 u32 new_ctrl;
254 bool have_new_ctrl;
Tony Luck2264d9c2016-10-28 15:04:41 -0700255};
256
257/**
258 * struct msr_param - set a range of MSRs from a domain
259 * @res: The resource to use
260 * @low: Beginning index from base MSR
261 * @high: End index
262 */
263struct msr_param {
264 struct rdt_resource *res;
265 int low;
266 int high;
267};
268
Thomas Gleixner0921c542017-04-14 14:14:31 +0200269/**
270 * struct rdt_cache - Cache allocation related data
271 * @cbm_len: Length of the cache bit mask
272 * @min_cbm_bits: Minimum number of consecutive bits to be set
273 * @cbm_idx_mult: Multiplier of CBM index
274 * @cbm_idx_offset: Offset of CBM index. CBM index is computed by:
275 * closid * cbm_idx_multi + cbm_idx_offset
276 * in a cache bit mask
Fenghua Yu0dd2d742017-07-25 15:39:04 -0700277 * @shareable_bits: Bitmask of shareable resource with other
278 * executing entities
Thomas Gleixner0921c542017-04-14 14:14:31 +0200279 */
280struct rdt_cache {
281 unsigned int cbm_len;
282 unsigned int min_cbm_bits;
283 unsigned int cbm_idx_mult;
284 unsigned int cbm_idx_offset;
Fenghua Yu0dd2d742017-07-25 15:39:04 -0700285 unsigned int shareable_bits;
Thomas Gleixner0921c542017-04-14 14:14:31 +0200286};
287
288/**
Vikas Shivappa05b93412017-04-07 17:33:53 -0700289 * struct rdt_membw - Memory bandwidth allocation related data
290 * @max_delay: Max throttle delay. Delay is the hardware
291 * representation for memory bandwidth.
292 * @min_bw: Minimum memory bandwidth percentage user can request
293 * @bw_gran: Granularity at which the memory bandwidth is allocated
294 * @delay_linear: True if memory B/W delay is in linear scale
Vikas Shivappa19c635a2018-04-20 15:36:17 -0700295 * @mba_sc: True if MBA software controller(mba_sc) is enabled
Vikas Shivappa05b93412017-04-07 17:33:53 -0700296 * @mb_map: Mapping of memory B/W percentage to memory B/W delay
297 */
298struct rdt_membw {
299 u32 max_delay;
300 u32 min_bw;
301 u32 bw_gran;
302 u32 delay_linear;
Vikas Shivappa19c635a2018-04-20 15:36:17 -0700303 bool mba_sc;
Vikas Shivappa05b93412017-04-07 17:33:53 -0700304 u32 *mb_map;
305};
306
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700307static inline bool is_llc_occupancy_enabled(void)
308{
309 return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID));
310}
311
Tony Luck9f524252017-07-25 14:14:45 -0700312static inline bool is_mbm_total_enabled(void)
313{
314 return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID));
315}
316
317static inline bool is_mbm_local_enabled(void)
318{
319 return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID));
320}
321
322static inline bool is_mbm_enabled(void)
323{
324 return (is_mbm_total_enabled() || is_mbm_local_enabled());
325}
326
Vikas Shivappaa4de1df2017-07-25 14:14:46 -0700327static inline bool is_mbm_event(int e)
328{
329 return (e >= QOS_L3_MBM_TOTAL_EVENT_ID &&
330 e <= QOS_L3_MBM_LOCAL_EVENT_ID);
331}
332
Vikas Shivappa05b93412017-04-07 17:33:53 -0700333/**
Thomas Gleixner0921c542017-04-14 14:14:31 +0200334 * struct rdt_resource - attributes of an RDT resource
Vikas Shivappad89b7372017-07-25 14:14:38 -0700335 * @rid: The index of the resource
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700336 * @alloc_enabled: Is allocation enabled on this machine
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700337 * @mon_enabled: Is monitoring enabled for this feature
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700338 * @alloc_capable: Is allocation available on this machine
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700339 * @mon_capable: Is monitor feature available on this machine
Thomas Gleixner0921c542017-04-14 14:14:31 +0200340 * @name: Name to use in "schemata" file
341 * @num_closid: Number of CLOSIDs available
342 * @cache_level: Which cache level defines scope of this resource
343 * @default_ctrl: Specifies default cache cbm or memory B/W percent.
344 * @msr_base: Base MSR address for CBMs
345 * @msr_update: Function pointer to update QOS MSRs
346 * @data_width: Character width of data when displaying
347 * @domains: All domains for this resource
348 * @cache: Cache allocation related data
Vikas Shivappac6ea67d2017-04-07 17:33:56 -0700349 * @format_str: Per resource format string to show domain value
350 * @parse_ctrlval: Per resource function pointer to parse control values
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700351 * @evt_list: List of monitoring events
352 * @num_rmid: Number of RMIDs available
353 * @mon_scale: cqm counter * mon_scale = occupancy in bytes
Tony luck5dc1d5c2017-07-25 14:14:29 -0700354 * @fflags: flags to choose base and info files
Thomas Gleixner0921c542017-04-14 14:14:31 +0200355 */
356struct rdt_resource {
Vikas Shivappad89b7372017-07-25 14:14:38 -0700357 int rid;
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700358 bool alloc_enabled;
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700359 bool mon_enabled;
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700360 bool alloc_capable;
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700361 bool mon_capable;
Thomas Gleixner0921c542017-04-14 14:14:31 +0200362 char *name;
363 int num_closid;
364 int cache_level;
365 u32 default_ctrl;
366 unsigned int msr_base;
367 void (*msr_update) (struct rdt_domain *d, struct msr_param *m,
368 struct rdt_resource *r);
369 int data_width;
370 struct list_head domains;
Thomas Gleixnera83827d2017-04-17 09:57:10 +0200371 struct rdt_cache cache;
372 struct rdt_membw membw;
Vikas Shivappac6ea67d2017-04-07 17:33:56 -0700373 const char *format_str;
Reinette Chatre7604df62018-06-22 15:42:03 -0700374 int (*parse_ctrlval) (void *data, struct rdt_resource *r,
Vikas Shivappac6ea67d2017-04-07 17:33:56 -0700375 struct rdt_domain *d);
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700376 struct list_head evt_list;
377 int num_rmid;
378 unsigned int mon_scale;
Tony luck5dc1d5c2017-07-25 14:14:29 -0700379 unsigned long fflags;
Thomas Gleixner0921c542017-04-14 14:14:31 +0200380};
381
Reinette Chatre7604df62018-06-22 15:42:03 -0700382int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d);
383int parse_bw(void *_buf, struct rdt_resource *r, struct rdt_domain *d);
Vikas Shivappa6a507a62017-04-07 17:33:54 -0700384
Tony Luck2264d9c2016-10-28 15:04:41 -0700385extern struct mutex rdtgroup_mutex;
386
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700387extern struct rdt_resource rdt_resources_all[];
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700388extern struct rdtgroup rdtgroup_default;
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700389DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700390
391int __init rdtgroup_init(void);
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700392
393enum {
394 RDT_RESOURCE_L3,
395 RDT_RESOURCE_L3DATA,
396 RDT_RESOURCE_L3CODE,
397 RDT_RESOURCE_L2,
Fenghua Yudef10852017-12-20 14:57:22 -0800398 RDT_RESOURCE_L2DATA,
399 RDT_RESOURCE_L2CODE,
Vikas Shivappa05b93412017-04-07 17:33:53 -0700400 RDT_RESOURCE_MBA,
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700401
402 /* Must be the last */
403 RDT_NUM_RESOURCES,
404};
405
Vikas Shivappa895c6632017-07-25 14:14:44 -0700406#define for_each_capable_rdt_resource(r) \
407 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
408 r++) \
409 if (r->alloc_capable || r->mon_capable)
410
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700411#define for_each_alloc_capable_rdt_resource(r) \
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700412 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
Thomas Gleixner17f8ba12017-04-10 11:50:11 +0200413 r++) \
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700414 if (r->alloc_capable)
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700415
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700416#define for_each_mon_capable_rdt_resource(r) \
417 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
418 r++) \
419 if (r->mon_capable)
420
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700421#define for_each_alloc_enabled_rdt_resource(r) \
Tony Luck2264d9c2016-10-28 15:04:41 -0700422 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
423 r++) \
Vikas Shivappa1b5c0b72017-07-25 14:14:25 -0700424 if (r->alloc_enabled)
Tony Luck2264d9c2016-10-28 15:04:41 -0700425
Vikas Shivappad4ab3322017-07-25 14:14:30 -0700426#define for_each_mon_enabled_rdt_resource(r) \
427 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
428 r++) \
429 if (r->mon_enabled)
430
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700431/* CPUID.(EAX=10H, ECX=ResID=1).EAX */
432union cpuid_0x10_1_eax {
433 struct {
434 unsigned int cbm_len:5;
435 } split;
436 unsigned int full;
437};
438
Vikas Shivappaab66a332017-04-07 17:33:52 -0700439/* CPUID.(EAX=10H, ECX=ResID=3).EAX */
440union cpuid_0x10_3_eax {
441 struct {
442 unsigned int max_delay:12;
443 } split;
444 unsigned int full;
445};
446
Vikas Shivappa2545e9f2017-04-07 17:33:51 -0700447/* CPUID.(EAX=10H, ECX=ResID).EDX */
448union cpuid_0x10_x_edx {
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700449 struct {
450 unsigned int cos_max:16;
451 } split;
452 unsigned int full;
453};
Tony Luck2264d9c2016-10-28 15:04:41 -0700454
Tony Luck9b3a7fd2017-09-25 16:39:33 -0700455void rdt_last_cmd_clear(void);
456void rdt_last_cmd_puts(const char *s);
457void rdt_last_cmd_printf(const char *fmt, ...);
458
Vikas Shivappa2545e9f2017-04-07 17:33:51 -0700459void rdt_ctrl_update(void *arg);
Fenghua Yu60cf5e12016-10-28 15:04:44 -0700460struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
461void rdtgroup_kn_unlock(struct kernfs_node *kn);
Vikas Shivappad89b7372017-07-25 14:14:38 -0700462struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
463 struct list_head **pos);
Tony Luck60ec2442016-10-28 15:04:47 -0700464ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
465 char *buf, size_t nbytes, loff_t off);
466int rdtgroup_schemata_show(struct kernfs_open_file *of,
467 struct seq_file *s, void *v);
Reinette Chatre9ab9aa12018-06-22 15:42:04 -0700468bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
469 u32 _cbm, int closid, bool exclusive);
Reinette Chatre472ef09b2018-06-22 15:41:55 -0700470enum rdtgrp_mode rdtgroup_mode_by_closid(int closid);
Vikas Shivappaedf6fa12017-07-25 14:14:28 -0700471struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r);
Reinette Chatre024d15b2018-06-22 15:41:58 -0700472int update_domains(struct rdt_resource *r, int closid);
473void closid_free(int closid);
Vikas Shivappac7d9aac2017-07-25 14:14:32 -0700474int alloc_rmid(void);
475void free_rmid(u32 rmid);
Vikas Shivappa6a445ed2017-07-25 14:14:27 -0700476int rdt_get_mon_l3_config(struct rdt_resource *r);
Vikas Shivappad89b7372017-07-25 14:14:38 -0700477void mon_event_count(void *info);
478int rdtgroup_mondata_show(struct seq_file *m, void *arg);
Vikas Shivappa895c6632017-07-25 14:14:44 -0700479void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
480 unsigned int dom_id);
481void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
482 struct rdt_domain *d);
Vikas Shivappaa4de1df2017-07-25 14:14:46 -0700483void mon_event_read(struct rmid_read *rr, struct rdt_domain *d,
484 struct rdtgroup *rdtgrp, int evtid, int first);
Vikas Shivappa24247ae2017-08-15 18:00:43 -0700485void mbm_setup_overflow_handler(struct rdt_domain *dom,
486 unsigned long delay_ms);
Vikas Shivappae3302682017-07-25 14:14:47 -0700487void mbm_handle_overflow(struct work_struct *work);
Vikas Shivappa19c635a2018-04-20 15:36:17 -0700488bool is_mba_sc(struct rdt_resource *r);
Vikas Shivappa1bd2a632018-04-20 15:36:18 -0700489void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm);
Vikas Shivappade73f382018-04-20 15:36:21 -0700490u32 delay_bw_map(unsigned long bw, struct rdt_resource *r);
Vikas Shivappa24247ae2017-08-15 18:00:43 -0700491void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms);
492void cqm_handle_limbo(struct work_struct *work);
493bool has_busy_rmid(struct rdt_resource *r, struct rdt_domain *d);
494void __check_limbo(struct rdt_domain *d, bool force_free);
Fenghua Yu4f341a52016-10-28 15:04:48 -0700495
Reinette Chatre32206ab2018-06-22 15:41:52 -0700496/*
497 * Define the hooks for Cache Pseudo-Locking to use within rdt_mount().
498 * These are no-ops provided for the new kernfs changes to use as a
499 * baseline in preparation for a conflict-free merge between it
500 * (kernfs changes) and the Cache Pseudo-Locking enabling.
501 */
502static inline int rdt_pseudo_lock_init(void) { return 0; }
503static inline void rdt_pseudo_lock_release(void) { }
504
Fenghua Yu113c6092016-10-22 06:19:54 -0700505#endif /* _ASM_X86_INTEL_RDT_H */