|
| 1 | +/* |
| 2 | + * Copyright (C) 2019 Intel Corporation. All rights reserved. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: BSD-3-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <types.h> |
| 8 | +#include <cpu.h> |
| 9 | +#include <cpu_caps.h> |
| 10 | +#include <cpufeatures.h> |
| 11 | +#include <cpuid.h> |
| 12 | +#include <msr.h> |
| 13 | +#include <errno.h> |
| 14 | +#include <logmsg.h> |
| 15 | +#include <cat.h> |
| 16 | +#include <board.h> |
| 17 | + |
| 18 | +struct cat_hw_info cat_cap_info; |
| 19 | + |
| 20 | +int32_t init_cat_cap_info(void) |
| 21 | +{ |
| 22 | + uint32_t eax = 0U, ebx = 0U, ecx = 0U, edx = 0U; |
| 23 | + int32_t ret = 0; |
| 24 | + |
| 25 | + if (cpu_has_cap(X86_FEATURE_CAT)) { |
| 26 | + cpuid_subleaf(CPUID_RSD_ALLOCATION, 0, &eax, &ebx, &ecx, &edx); |
| 27 | + /* If support L3 CAT, EBX[1] is set */ |
| 28 | + if ((ebx & 2U) != 0U) { |
| 29 | + cat_cap_info.res_id = CAT_RESID_L3; |
| 30 | + } |
| 31 | + |
| 32 | + /* If support L2 CAT, EBX[2] is set */ |
| 33 | + if ((ebx & 4U) != 0U) { |
| 34 | + cat_cap_info.res_id = CAT_RESID_L2; |
| 35 | + } |
| 36 | + |
| 37 | + cat_cap_info.support = true; |
| 38 | + |
| 39 | + /* CPUID.(EAX=0x10,ECX=ResID):EAX[4:0] reports the length of CBM supported |
| 40 | + * CPUID.(EAX=0x10,ECX=ResID):EBX[31:0] indicates the corresponding uints |
| 41 | + * may be used by other entities such as graphic and H/W outside processor. |
| 42 | + * CPUID.(EAX=0x10,ECX=ResID):EDX[15:0] reports the maximun CLOS supported |
| 43 | + */ |
| 44 | + cpuid_subleaf(CPUID_RSD_ALLOCATION, cat_cap_info.res_id, &eax, &ebx, &ecx, &edx); |
| 45 | + cat_cap_info.cbm_len = (uint16_t)((eax & 0xfU) + 1U); |
| 46 | + cat_cap_info.bitmask = ebx; |
| 47 | + cat_cap_info.clos_max = (uint16_t)(edx & 0xffffU); |
| 48 | + |
| 49 | + if ((platform_clos_num != 0U) && ((cat_cap_info.clos_max + 1U) != platform_clos_num)) { |
| 50 | + pr_err("%s clos_max:%hu, platform_clos_num:%u\n", __func__, cat_cap_info.clos_max, platform_clos_num); |
| 51 | + ret = -EINVAL; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + return ret; |
| 56 | +} |
0 commit comments