summaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/cpu/intel_pconfig.c
blob: 0771a905b2868085028747572c066c2d99df36a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-License-Identifier: GPL-2.0
/*
 * Intel PCONFIG instruction support.
 *
 * Copyright (C) 2017 Intel Corporation
 *
 * Author:
 *	Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
 */

#include <asm/cpufeature.h>
#include <asm/intel_pconfig.h>

#define	PCONFIG_CPUID			0x1b

#define PCONFIG_CPUID_SUBLEAF_MASK	((1 << 12) - 1)

/* Subleaf type (EAX) for PCONFIG CPUID leaf (0x1B) */
enum {
	PCONFIG_CPUID_SUBLEAF_INVALID	= 0,
	PCONFIG_CPUID_SUBLEAF_TARGETID	= 1,
};

/* Bitmask of supported targets */
static u64 targets_supported __read_mostly;

int pconfig_target_supported(enum pconfig_target target)
{
	/*
	 * We would need to re-think the implementation once we get > 64
	 * PCONFIG targets. Spec allows up to 2^32 targets.
	 */
	BUILD_BUG_ON(PCONFIG_TARGET_NR >= 64);

	if (WARN_ON_ONCE(target >= 64))
		return 0;
	return targets_supported & (1ULL << target);
}

static int __init intel_pconfig_init(void)
{
	int subleaf;

	if (!boot_cpu_has(X86_FEATURE_PCONFIG))
		return 0;

	/*
	 * Scan subleafs of PCONFIG CPUID leaf.
	 *
	 * Subleafs of the same type need not to be consecutive.
	 *
	 * Stop on the first invalid subleaf type. All subleafs after the first
	 * invalid are invalid too.
	 */
	for (subleaf = 0; subleaf < INT_MAX; subleaf++) {
		struct cpuid_regs regs;

		cpuid_count(PCONFIG_CPUID, subleaf,
				&regs.eax, &regs.ebx, &regs.ecx, &regs.edx);

		switch (regs.eax & PCONFIG_CPUID_SUBLEAF_MASK) {
		case PCONFIG_CPUID_SUBLEAF_INVALID:
			/* Stop on the first invalid subleaf */
			goto out;
		case PCONFIG_CPUID_SUBLEAF_TARGETID:
			/* Mark supported PCONFIG targets */
			if (regs.ebx < 64)
				targets_supported |= (1ULL << regs.ebx);
			if (regs.ecx < 64)
				targets_supported |= (1ULL << regs.ecx);
			if (regs.edx < 64)
				targets_supported |= (1ULL << regs.edx);
			break;
		default:
			/* Unknown CPUID.PCONFIG subleaf: ignore */
			break;
		}
	}
out:
	return 0;
}
arch_initcall(intel_pconfig_init);