blob: 5b7b3f6f1f96b8e9190d196593f30814affa3032 [file] [log] [blame]
Fenghua Yu113c6092016-10-22 06:19:54 -07001#ifndef _ASM_X86_INTEL_RDT_H
2#define _ASM_X86_INTEL_RDT_H
3
Fenghua Yu5ff193f2016-10-28 15:04:42 -07004#include <linux/jump_label.h>
5
6#define IA32_L3_QOS_CFG 0xc81
Fenghua Yu113c6092016-10-22 06:19:54 -07007#define IA32_L3_CBM_BASE 0xc90
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -07008#define IA32_L2_CBM_BASE 0xd10
Fenghua Yu113c6092016-10-22 06:19:54 -07009
Fenghua Yu5ff193f2016-10-28 15:04:42 -070010#define L3_QOS_CDP_ENABLE 0x01ULL
11
12/**
13 * struct rdtgroup - store rdtgroup's data in resctrl file system.
14 * @kn: kernfs node
15 * @rdtgroup_list: linked list for all rdtgroups
16 * @closid: closid for this rdtgroup
17 */
18struct rdtgroup {
19 struct kernfs_node *kn;
20 struct list_head rdtgroup_list;
21 int closid;
22};
23
24/* List of all resource groups */
25extern struct list_head rdt_all_groups;
26
27int __init rdtgroup_init(void);
28
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -070029/**
Fenghua Yu4e978d02016-10-28 15:04:43 -070030 * struct rftype - describe each file in the resctrl file system
31 * @name: file name
32 * @mode: access mode
33 * @kf_ops: operations
34 * @seq_show: show content of the file
35 * @write: write to the file
36 */
37struct rftype {
38 char *name;
39 umode_t mode;
40 struct kernfs_ops *kf_ops;
41
42 int (*seq_show)(struct kernfs_open_file *of,
43 struct seq_file *sf, void *v);
44 /*
45 * write() is the generic write callback which maps directly to
46 * kernfs write operation and overrides all other operations.
47 * Maximum write size is determined by ->max_write_len.
48 */
49 ssize_t (*write)(struct kernfs_open_file *of,
50 char *buf, size_t nbytes, loff_t off);
51};
52
53/**
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -070054 * struct rdt_resource - attributes of an RDT resource
55 * @enabled: Is this feature enabled on this machine
56 * @capable: Is this feature available on this machine
57 * @name: Name to use in "schemata" file
58 * @num_closid: Number of CLOSIDs available
59 * @max_cbm: Largest Cache Bit Mask allowed
60 * @min_cbm_bits: Minimum number of consecutive bits to be set
61 * in a cache bit mask
62 * @domains: All domains for this resource
63 * @num_domains: Number of domains active
64 * @msr_base: Base MSR address for CBMs
65 * @tmp_cbms: Scratch space when updating schemata
66 * @cache_level: Which cache level defines scope of this domain
67 * @cbm_idx_multi: Multiplier of CBM index
68 * @cbm_idx_offset: Offset of CBM index. CBM index is computed by:
69 * closid * cbm_idx_multi + cbm_idx_offset
70 */
71struct rdt_resource {
72 bool enabled;
73 bool capable;
74 char *name;
75 int num_closid;
76 int cbm_len;
77 int min_cbm_bits;
78 u32 max_cbm;
79 struct list_head domains;
80 int num_domains;
81 int msr_base;
82 u32 *tmp_cbms;
83 int cache_level;
84 int cbm_idx_multi;
85 int cbm_idx_offset;
86};
87
Tony Luck2264d9c2016-10-28 15:04:41 -070088/**
89 * struct rdt_domain - group of cpus sharing an RDT resource
90 * @list: all instances of this resource
91 * @id: unique id for this instance
92 * @cpu_mask: which cpus share this resource
93 * @cbm: array of cache bit masks (indexed by CLOSID)
94 */
95struct rdt_domain {
96 struct list_head list;
97 int id;
98 struct cpumask cpu_mask;
99 u32 *cbm;
100};
101
102/**
103 * struct msr_param - set a range of MSRs from a domain
104 * @res: The resource to use
105 * @low: Beginning index from base MSR
106 * @high: End index
107 */
108struct msr_param {
109 struct rdt_resource *res;
110 int low;
111 int high;
112};
113
114extern struct mutex rdtgroup_mutex;
115
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700116extern struct rdt_resource rdt_resources_all[];
Fenghua Yu5ff193f2016-10-28 15:04:42 -0700117extern struct rdtgroup rdtgroup_default;
118DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
119
120int __init rdtgroup_init(void);
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700121
122enum {
123 RDT_RESOURCE_L3,
124 RDT_RESOURCE_L3DATA,
125 RDT_RESOURCE_L3CODE,
126 RDT_RESOURCE_L2,
127
128 /* Must be the last */
129 RDT_NUM_RESOURCES,
130};
131
132#define for_each_capable_rdt_resource(r) \
133 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
134 r++) \
135 if (r->capable)
136
Tony Luck2264d9c2016-10-28 15:04:41 -0700137#define for_each_enabled_rdt_resource(r) \
138 for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
139 r++) \
140 if (r->enabled)
141
Fenghua Yuc1c7c3f2016-10-22 06:19:55 -0700142/* CPUID.(EAX=10H, ECX=ResID=1).EAX */
143union cpuid_0x10_1_eax {
144 struct {
145 unsigned int cbm_len:5;
146 } split;
147 unsigned int full;
148};
149
150/* CPUID.(EAX=10H, ECX=ResID=1).EDX */
151union cpuid_0x10_1_edx {
152 struct {
153 unsigned int cos_max:16;
154 } split;
155 unsigned int full;
156};
Tony Luck2264d9c2016-10-28 15:04:41 -0700157
158void rdt_cbm_update(void *arg);
Fenghua Yu113c6092016-10-22 06:19:54 -0700159#endif /* _ASM_X86_INTEL_RDT_H */