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