Fenghua Yu | 78e99b4 | 2016-10-22 06:19:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Resource Director Technology(RDT) |
| 3 | * - Cache Allocation code. |
| 4 | * |
| 5 | * Copyright (C) 2016 Intel Corporation |
| 6 | * |
| 7 | * Authors: |
| 8 | * Fenghua Yu <fenghua.yu@intel.com> |
| 9 | * Tony Luck <tony.luck@intel.com> |
| 10 | * Vikas Shivappa <vikas.shivappa@intel.com> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms and conditions of the GNU General Public License, |
| 14 | * version 2, as published by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 19 | * more details. |
| 20 | * |
| 21 | * More information about RDT be found in the Intel (R) x86 Architecture |
| 22 | * Software Developer Manual June 2016, volume 3, section 17.17. |
| 23 | */ |
| 24 | |
| 25 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 26 | |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/err.h> |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 29 | #include <linux/cacheinfo.h> |
| 30 | #include <linux/cpuhotplug.h> |
Fenghua Yu | 78e99b4 | 2016-10-22 06:19:53 -0700 | [diff] [blame] | 31 | |
Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 32 | #include <asm/intel-family.h> |
| 33 | #include <asm/intel_rdt.h> |
| 34 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 35 | /* Mutex to protect rdtgroup access. */ |
| 36 | DEFINE_MUTEX(rdtgroup_mutex); |
| 37 | |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame] | 38 | DEFINE_PER_CPU_READ_MOSTLY(int, cpu_closid); |
| 39 | |
Vikas Shivappa | de016df | 2017-04-03 14:44:17 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Used to store the max resource name width and max resource data width |
| 42 | * to display the schemata in a tabular format |
| 43 | */ |
| 44 | int max_name_width, max_data_width; |
| 45 | |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 46 | #define domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].domains) |
| 47 | |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 48 | struct rdt_resource rdt_resources_all[] = { |
| 49 | { |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 50 | .name = "L3", |
| 51 | .domains = domain_init(RDT_RESOURCE_L3), |
| 52 | .msr_base = IA32_L3_CBM_BASE, |
| 53 | .cache_level = 3, |
| 54 | .cache = { |
| 55 | .min_cbm_bits = 1, |
| 56 | .cbm_idx_mult = 1, |
| 57 | .cbm_idx_offset = 0, |
| 58 | }, |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 59 | }, |
| 60 | { |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 61 | .name = "L3DATA", |
| 62 | .domains = domain_init(RDT_RESOURCE_L3DATA), |
| 63 | .msr_base = IA32_L3_CBM_BASE, |
| 64 | .cache_level = 3, |
| 65 | .cache = { |
| 66 | .min_cbm_bits = 1, |
| 67 | .cbm_idx_mult = 2, |
| 68 | .cbm_idx_offset = 0, |
| 69 | }, |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 70 | }, |
| 71 | { |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 72 | .name = "L3CODE", |
| 73 | .domains = domain_init(RDT_RESOURCE_L3CODE), |
| 74 | .msr_base = IA32_L3_CBM_BASE, |
| 75 | .cache_level = 3, |
| 76 | .cache = { |
| 77 | .min_cbm_bits = 1, |
| 78 | .cbm_idx_mult = 2, |
| 79 | .cbm_idx_offset = 1, |
| 80 | }, |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 81 | }, |
| 82 | { |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 83 | .name = "L2", |
| 84 | .domains = domain_init(RDT_RESOURCE_L2), |
| 85 | .msr_base = IA32_L2_CBM_BASE, |
| 86 | .cache_level = 2, |
| 87 | .cache = { |
| 88 | .min_cbm_bits = 1, |
| 89 | .cbm_idx_mult = 1, |
| 90 | .cbm_idx_offset = 0, |
| 91 | }, |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 92 | }, |
| 93 | }; |
| 94 | |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 95 | static unsigned int cbm_idx(struct rdt_resource *r, unsigned int closid) |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 96 | { |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 97 | return closid * r->cache.cbm_idx_mult + r->cache.cbm_idx_offset; |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 100 | /* |
| 101 | * cache_alloc_hsw_probe() - Have to probe for Intel haswell server CPUs |
| 102 | * as they do not have CPUID enumeration support for Cache allocation. |
| 103 | * The check for Vendor/Family/Model is not enough to guarantee that |
| 104 | * the MSRs won't #GP fault because only the following SKUs support |
| 105 | * CAT: |
| 106 | * Intel(R) Xeon(R) CPU E5-2658 v3 @ 2.20GHz |
| 107 | * Intel(R) Xeon(R) CPU E5-2648L v3 @ 1.80GHz |
| 108 | * Intel(R) Xeon(R) CPU E5-2628L v3 @ 2.00GHz |
| 109 | * Intel(R) Xeon(R) CPU E5-2618L v3 @ 2.30GHz |
| 110 | * Intel(R) Xeon(R) CPU E5-2608L v3 @ 2.00GHz |
| 111 | * Intel(R) Xeon(R) CPU E5-2658A v3 @ 2.20GHz |
| 112 | * |
| 113 | * Probe by trying to write the first of the L3 cach mask registers |
| 114 | * and checking that the bits stick. Max CLOSids is always 4 and max cbm length |
| 115 | * is always 20 on hsw server parts. The minimum cache bitmask length |
| 116 | * allowed for HSW server is always 2 bits. Hardcode all of them. |
| 117 | */ |
| 118 | static inline bool cache_alloc_hsw_probe(void) |
| 119 | { |
| 120 | if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && |
| 121 | boot_cpu_data.x86 == 6 && |
| 122 | boot_cpu_data.x86_model == INTEL_FAM6_HASWELL_X) { |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 123 | struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3]; |
Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 124 | u32 l, h, max_cbm = BIT_MASK(20) - 1; |
| 125 | |
| 126 | if (wrmsr_safe(IA32_L3_CBM_BASE, max_cbm, 0)) |
| 127 | return false; |
| 128 | rdmsr(IA32_L3_CBM_BASE, l, h); |
| 129 | |
| 130 | /* If all the bits were set in MSR, return success */ |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 131 | if (l != max_cbm) |
| 132 | return false; |
| 133 | |
| 134 | r->num_closid = 4; |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 135 | r->default_ctrl = max_cbm; |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 136 | r->cache.cbm_len = 20; |
| 137 | r->cache.min_cbm_bits = 2; |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 138 | r->capable = true; |
| 139 | r->enabled = true; |
| 140 | |
| 141 | return true; |
Fenghua Yu | 113c609 | 2016-10-22 06:19:54 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | return false; |
| 145 | } |
| 146 | |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 147 | static void rdt_get_cache_config(int idx, struct rdt_resource *r) |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 148 | { |
| 149 | union cpuid_0x10_1_eax eax; |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 150 | union cpuid_0x10_x_edx edx; |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 151 | u32 ebx, ecx; |
| 152 | |
| 153 | cpuid_count(0x00000010, idx, &eax.full, &ebx, &ecx, &edx.full); |
| 154 | r->num_closid = edx.split.cos_max + 1; |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 155 | r->cache.cbm_len = eax.split.cbm_len + 1; |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 156 | r->default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1; |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 157 | r->data_width = (r->cache.cbm_len + 3) / 4; |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 158 | r->capable = true; |
| 159 | r->enabled = true; |
| 160 | } |
| 161 | |
| 162 | static void rdt_get_cdp_l3_config(int type) |
| 163 | { |
| 164 | struct rdt_resource *r_l3 = &rdt_resources_all[RDT_RESOURCE_L3]; |
| 165 | struct rdt_resource *r = &rdt_resources_all[type]; |
| 166 | |
| 167 | r->num_closid = r_l3->num_closid / 2; |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 168 | r->cache.cbm_len = r_l3->cache.cbm_len; |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 169 | r->default_ctrl = r_l3->default_ctrl; |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 170 | r->data_width = (r->cache.cbm_len + 3) / 4; |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 171 | r->capable = true; |
| 172 | /* |
| 173 | * By default, CDP is disabled. CDP can be enabled by mount parameter |
| 174 | * "cdp" during resctrl file system mount time. |
| 175 | */ |
| 176 | r->enabled = false; |
| 177 | } |
| 178 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 179 | static int get_cache_id(int cpu, int level) |
| 180 | { |
| 181 | struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); |
| 182 | int i; |
| 183 | |
| 184 | for (i = 0; i < ci->num_leaves; i++) { |
| 185 | if (ci->info_list[i].level == level) |
| 186 | return ci->info_list[i].id; |
| 187 | } |
| 188 | |
| 189 | return -1; |
| 190 | } |
| 191 | |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 192 | void rdt_ctrl_update(void *arg) |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 193 | { |
| 194 | struct msr_param *m = (struct msr_param *)arg; |
| 195 | struct rdt_resource *r = m->res; |
| 196 | int i, cpu = smp_processor_id(); |
| 197 | struct rdt_domain *d; |
| 198 | |
| 199 | list_for_each_entry(d, &r->domains, list) { |
| 200 | /* Find the domain that contains this CPU */ |
| 201 | if (cpumask_test_cpu(cpu, &d->cpu_mask)) |
| 202 | goto found; |
| 203 | } |
| 204 | pr_info_once("cpu %d not found in any domain for resource %s\n", |
| 205 | cpu, r->name); |
| 206 | |
| 207 | return; |
| 208 | |
| 209 | found: |
| 210 | for (i = m->low; i < m->high; i++) { |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 211 | unsigned int idx = cbm_idx(r, i); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 212 | |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 213 | wrmsrl(r->msr_base + idx, d->ctrl_val[i]); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * rdt_find_domain - Find a domain in a resource that matches input resource id |
| 219 | * |
| 220 | * Search resource r's domain list to find the resource id. If the resource |
| 221 | * id is found in a domain, return the domain. Otherwise, if requested by |
| 222 | * caller, return the first domain whose id is bigger than the input id. |
| 223 | * The domain list is sorted by id in ascending order. |
| 224 | */ |
| 225 | static struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id, |
| 226 | struct list_head **pos) |
| 227 | { |
| 228 | struct rdt_domain *d; |
| 229 | struct list_head *l; |
| 230 | |
| 231 | if (id < 0) |
| 232 | return ERR_PTR(id); |
| 233 | |
| 234 | list_for_each(l, &r->domains) { |
| 235 | d = list_entry(l, struct rdt_domain, list); |
| 236 | /* When id is found, return its domain. */ |
| 237 | if (id == d->id) |
| 238 | return d; |
| 239 | /* Stop searching when finding id's position in sorted list. */ |
| 240 | if (id < d->id) |
| 241 | break; |
| 242 | } |
| 243 | |
| 244 | if (pos) |
| 245 | *pos = l; |
| 246 | |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * domain_add_cpu - Add a cpu to a resource's domain list. |
| 252 | * |
| 253 | * If an existing domain in the resource r's domain list matches the cpu's |
| 254 | * resource id, add the cpu in the domain. |
| 255 | * |
| 256 | * Otherwise, a new domain is allocated and inserted into the right position |
| 257 | * in the domain list sorted by id in ascending order. |
| 258 | * |
| 259 | * The order in the domain list is visible to users when we print entries |
| 260 | * in the schemata file and schemata input is validated to have the same order |
| 261 | * as this list. |
| 262 | */ |
| 263 | static void domain_add_cpu(int cpu, struct rdt_resource *r) |
| 264 | { |
| 265 | int i, id = get_cache_id(cpu, r->cache_level); |
| 266 | struct list_head *add_pos = NULL; |
| 267 | struct rdt_domain *d; |
| 268 | |
| 269 | d = rdt_find_domain(r, id, &add_pos); |
| 270 | if (IS_ERR(d)) { |
| 271 | pr_warn("Could't find cache id for cpu %d\n", cpu); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | if (d) { |
| 276 | cpumask_set_cpu(cpu, &d->cpu_mask); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | d = kzalloc_node(sizeof(*d), GFP_KERNEL, cpu_to_node(cpu)); |
| 281 | if (!d) |
| 282 | return; |
| 283 | |
| 284 | d->id = id; |
| 285 | |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 286 | d->ctrl_val = kmalloc_array(r->num_closid, sizeof(*d->ctrl_val), GFP_KERNEL); |
| 287 | if (!d->ctrl_val) { |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 288 | kfree(d); |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | for (i = 0; i < r->num_closid; i++) { |
Thomas Gleixner | d3e11b4 | 2017-04-14 13:00:36 +0200 | [diff] [blame^] | 293 | unsigned int idx = cbm_idx(r, i); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 294 | |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 295 | d->ctrl_val[i] = r->default_ctrl; |
| 296 | wrmsrl(r->msr_base + idx, d->ctrl_val[i]); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | cpumask_set_cpu(cpu, &d->cpu_mask); |
| 300 | list_add_tail(&d->list, add_pos); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static void domain_remove_cpu(int cpu, struct rdt_resource *r) |
| 304 | { |
| 305 | int id = get_cache_id(cpu, r->cache_level); |
| 306 | struct rdt_domain *d; |
| 307 | |
| 308 | d = rdt_find_domain(r, id, NULL); |
| 309 | if (IS_ERR_OR_NULL(d)) { |
| 310 | pr_warn("Could't find cache id for cpu %d\n", cpu); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | cpumask_clear_cpu(cpu, &d->cpu_mask); |
| 315 | if (cpumask_empty(&d->cpu_mask)) { |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 316 | kfree(d->ctrl_val); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 317 | list_del(&d->list); |
| 318 | kfree(d); |
| 319 | } |
| 320 | } |
| 321 | |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame] | 322 | static void clear_closid(int cpu) |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 323 | { |
| 324 | struct intel_pqr_state *state = this_cpu_ptr(&pqr_state); |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame] | 325 | |
| 326 | per_cpu(cpu_closid, cpu) = 0; |
| 327 | state->closid = 0; |
| 328 | wrmsr(MSR_IA32_PQR_ASSOC, state->rmid, 0); |
| 329 | } |
| 330 | |
| 331 | static int intel_rdt_online_cpu(unsigned int cpu) |
| 332 | { |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 333 | struct rdt_resource *r; |
| 334 | |
| 335 | mutex_lock(&rdtgroup_mutex); |
| 336 | for_each_capable_rdt_resource(r) |
| 337 | domain_add_cpu(cpu, r); |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame] | 338 | /* The cpu is set in default rdtgroup after online. */ |
| 339 | cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); |
| 340 | clear_closid(cpu); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 341 | mutex_unlock(&rdtgroup_mutex); |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static int intel_rdt_offline_cpu(unsigned int cpu) |
Fenghua Yu | 78e99b4 | 2016-10-22 06:19:53 -0700 | [diff] [blame] | 347 | { |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame] | 348 | struct rdtgroup *rdtgrp; |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 349 | struct rdt_resource *r; |
| 350 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 351 | mutex_lock(&rdtgroup_mutex); |
| 352 | for_each_capable_rdt_resource(r) |
| 353 | domain_remove_cpu(cpu, r); |
Tony Luck | 12e0110 | 2016-10-28 15:04:45 -0700 | [diff] [blame] | 354 | list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) { |
| 355 | if (cpumask_test_and_clear_cpu(cpu, &rdtgrp->cpu_mask)) |
| 356 | break; |
| 357 | } |
| 358 | clear_closid(cpu); |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 359 | mutex_unlock(&rdtgroup_mutex); |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
Thomas Gleixner | 70a1ee9 | 2017-04-14 14:07:47 +0200 | [diff] [blame] | 364 | /* |
| 365 | * Choose a width for the resource name and resource data based on the |
| 366 | * resource that has widest name and cbm. |
| 367 | */ |
| 368 | static __init void rdt_init_padding(void) |
| 369 | { |
| 370 | struct rdt_resource *r; |
| 371 | int cl; |
| 372 | |
| 373 | for_each_enabled_rdt_resource(r) { |
| 374 | cl = strlen(r->name); |
| 375 | if (cl > max_name_width) |
| 376 | max_name_width = cl; |
| 377 | |
| 378 | if (r->data_width > max_data_width) |
| 379 | max_data_width = r->data_width; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static __init bool get_rdt_resources(void) |
| 384 | { |
| 385 | bool ret = false; |
| 386 | |
| 387 | if (cache_alloc_hsw_probe()) |
| 388 | return true; |
| 389 | |
| 390 | if (!boot_cpu_has(X86_FEATURE_RDT_A)) |
| 391 | return false; |
| 392 | |
| 393 | if (boot_cpu_has(X86_FEATURE_CAT_L3)) { |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 394 | rdt_get_cache_config(1, &rdt_resources_all[RDT_RESOURCE_L3]); |
Thomas Gleixner | 70a1ee9 | 2017-04-14 14:07:47 +0200 | [diff] [blame] | 395 | if (boot_cpu_has(X86_FEATURE_CDP_L3)) { |
| 396 | rdt_get_cdp_l3_config(RDT_RESOURCE_L3DATA); |
| 397 | rdt_get_cdp_l3_config(RDT_RESOURCE_L3CODE); |
| 398 | } |
| 399 | ret = true; |
| 400 | } |
| 401 | if (boot_cpu_has(X86_FEATURE_CAT_L2)) { |
| 402 | /* CPUID 0x10.2 fields are same format at 0x10.1 */ |
Vikas Shivappa | 2545e9f | 2017-04-07 17:33:51 -0700 | [diff] [blame] | 403 | rdt_get_cache_config(2, &rdt_resources_all[RDT_RESOURCE_L2]); |
Thomas Gleixner | 70a1ee9 | 2017-04-14 14:07:47 +0200 | [diff] [blame] | 404 | ret = true; |
| 405 | } |
| 406 | return ret; |
| 407 | } |
| 408 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 409 | static int __init intel_rdt_late_init(void) |
| 410 | { |
| 411 | struct rdt_resource *r; |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 412 | int state, ret; |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 413 | |
Fenghua Yu | 78e99b4 | 2016-10-22 06:19:53 -0700 | [diff] [blame] | 414 | if (!get_rdt_resources()) |
| 415 | return -ENODEV; |
| 416 | |
Thomas Gleixner | 06b57e4 | 2017-04-14 14:06:26 +0200 | [diff] [blame] | 417 | rdt_init_padding(); |
| 418 | |
Tony Luck | 2264d9c | 2016-10-28 15:04:41 -0700 | [diff] [blame] | 419 | state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, |
| 420 | "x86/rdt/cat:online:", |
| 421 | intel_rdt_online_cpu, intel_rdt_offline_cpu); |
| 422 | if (state < 0) |
| 423 | return state; |
| 424 | |
Fenghua Yu | 5ff193f | 2016-10-28 15:04:42 -0700 | [diff] [blame] | 425 | ret = rdtgroup_init(); |
| 426 | if (ret) { |
| 427 | cpuhp_remove_state(state); |
| 428 | return ret; |
| 429 | } |
| 430 | |
Fenghua Yu | c1c7c3f | 2016-10-22 06:19:55 -0700 | [diff] [blame] | 431 | for_each_capable_rdt_resource(r) |
| 432 | pr_info("Intel RDT %s allocation detected\n", r->name); |
Fenghua Yu | 78e99b4 | 2016-10-22 06:19:53 -0700 | [diff] [blame] | 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | late_initcall(intel_rdt_late_init); |