x86/intel_rdt: Add basic resctrl filesystem support
[linux-2.6-microblaze.git] / arch / x86 / include / asm / intel_rdt.h
1 #ifndef _ASM_X86_INTEL_RDT_H
2 #define _ASM_X86_INTEL_RDT_H
3
4 #include <linux/jump_label.h>
5
6 #define IA32_L3_QOS_CFG         0xc81
7 #define IA32_L3_CBM_BASE        0xc90
8 #define IA32_L2_CBM_BASE        0xd10
9
10 #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  */
18 struct rdtgroup {
19         struct kernfs_node      *kn;
20         struct list_head        rdtgroup_list;
21         int                     closid;
22 };
23
24 /* List of all resource groups */
25 extern struct list_head rdt_all_groups;
26
27 int __init rdtgroup_init(void);
28
29 /**
30  * struct rdt_resource - attributes of an RDT resource
31  * @enabled:                    Is this feature enabled on this machine
32  * @capable:                    Is this feature available on this machine
33  * @name:                       Name to use in "schemata" file
34  * @num_closid:                 Number of CLOSIDs available
35  * @max_cbm:                    Largest Cache Bit Mask allowed
36  * @min_cbm_bits:               Minimum number of consecutive bits to be set
37  *                              in a cache bit mask
38  * @domains:                    All domains for this resource
39  * @num_domains:                Number of domains active
40  * @msr_base:                   Base MSR address for CBMs
41  * @tmp_cbms:                   Scratch space when updating schemata
42  * @cache_level:                Which cache level defines scope of this domain
43  * @cbm_idx_multi:              Multiplier of CBM index
44  * @cbm_idx_offset:             Offset of CBM index. CBM index is computed by:
45  *                              closid * cbm_idx_multi + cbm_idx_offset
46  */
47 struct rdt_resource {
48         bool                    enabled;
49         bool                    capable;
50         char                    *name;
51         int                     num_closid;
52         int                     cbm_len;
53         int                     min_cbm_bits;
54         u32                     max_cbm;
55         struct list_head        domains;
56         int                     num_domains;
57         int                     msr_base;
58         u32                     *tmp_cbms;
59         int                     cache_level;
60         int                     cbm_idx_multi;
61         int                     cbm_idx_offset;
62 };
63
64 /**
65  * struct rdt_domain - group of cpus sharing an RDT resource
66  * @list:       all instances of this resource
67  * @id:         unique id for this instance
68  * @cpu_mask:   which cpus share this resource
69  * @cbm:        array of cache bit masks (indexed by CLOSID)
70  */
71 struct rdt_domain {
72         struct list_head        list;
73         int                     id;
74         struct cpumask          cpu_mask;
75         u32                     *cbm;
76 };
77
78 /**
79  * struct msr_param - set a range of MSRs from a domain
80  * @res:       The resource to use
81  * @low:       Beginning index from base MSR
82  * @high:      End index
83  */
84 struct msr_param {
85         struct rdt_resource     *res;
86         int                     low;
87         int                     high;
88 };
89
90 extern struct mutex rdtgroup_mutex;
91
92 extern struct rdt_resource rdt_resources_all[];
93 extern struct rdtgroup rdtgroup_default;
94 DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
95
96 int __init rdtgroup_init(void);
97
98 enum {
99         RDT_RESOURCE_L3,
100         RDT_RESOURCE_L3DATA,
101         RDT_RESOURCE_L3CODE,
102         RDT_RESOURCE_L2,
103
104         /* Must be the last */
105         RDT_NUM_RESOURCES,
106 };
107
108 #define for_each_capable_rdt_resource(r)                                      \
109         for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
110              r++)                                                             \
111                 if (r->capable)
112
113 #define for_each_enabled_rdt_resource(r)                                      \
114         for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
115              r++)                                                             \
116                 if (r->enabled)
117
118 /* CPUID.(EAX=10H, ECX=ResID=1).EAX */
119 union cpuid_0x10_1_eax {
120         struct {
121                 unsigned int cbm_len:5;
122         } split;
123         unsigned int full;
124 };
125
126 /* CPUID.(EAX=10H, ECX=ResID=1).EDX */
127 union cpuid_0x10_1_edx {
128         struct {
129                 unsigned int cos_max:16;
130         } split;
131         unsigned int full;
132 };
133
134 void rdt_cbm_update(void *arg);
135 #endif /* _ASM_X86_INTEL_RDT_H */