Skip to content

Commit 260d8af

Browse files
committed
[AArch64] Improving virtualization detection from Device Tree
1 parent 0b58936 commit 260d8af

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

aarch64/corefreqk.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6297,6 +6297,19 @@ static int CoreFreqK_Ignition_Level_Up(INIT_ARG *pArg)
62976297
StrCopy(PUBLIC(RO(Proc))->Features.Info.Brand,
62986298
Arch[PUBLIC(RO(Proc))->ArchID].Architecture.Brand[0],
62996299
BRAND_SIZE);
6300+
/* Attempt to detect virtualization from Device Tree */
6301+
#ifdef CONFIG_OF
6302+
{
6303+
const char *virtualBoard[] = DT_VIRTUAL_BOARD;
6304+
if (of_device_compatible_match(of_root, virtualBoard) > 0)
6305+
{
6306+
PUBLIC(RO(Proc))->HypervisorID = HYPERV_KVM;
6307+
PUBLIC(RO(Proc))->Features.Info.Hypervisor.CRC = CRC_KVM;
6308+
StrCopy(PUBLIC(RO(Proc))->Features.Info.Hypervisor.ID,
6309+
VENDOR_KVM, 12 + 4);
6310+
}
6311+
}
6312+
#endif /* CONFIG_OF */
63006313
/* Check if the Processor is actually virtualized ? */
63016314
#ifdef CONFIG_XEN
63026315
if (xen_pv_domain() || xen_hvm_domain())

aarch64/corefreqk.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
* Licenses: GPL2
55
*/
66

7+
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
8+
#define of_device_compatible_match(_device_, _compat_) \
9+
({ \
10+
const struct device_node *device = _device_; \
11+
const char *const *compat = _compat_; \
12+
unsigned int tmp, score = 0; \
13+
\
14+
if (compat != NULL) \
15+
while (*compat) { \
16+
tmp = of_device_is_compatible(device, *compat); \
17+
if (tmp > score) \
18+
score = tmp; \
19+
compat++; \
20+
} \
21+
score; \
22+
})
23+
#endif
24+
725
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
826
#define sys_reg(op0, op1, crn, crm, op2) ({ \
927
UNUSED(op0); \
@@ -146,6 +164,12 @@ ASM_COUNTERx3(x11, x12, x13, x14, ASM_RDTSC, mem_tsc, __VA_ARGS__)
146164
#define VENDOR_VMWARE "VMwawarereVM"
147165
#define VENDOR_HYPERV "Micrt Hvosof"
148166

167+
#define DT_VIRTUAL_BOARD { \
168+
"linux,dummy-virt", \
169+
"qemu,pseries", \
170+
NULL \
171+
}
172+
149173
#define LATCH_NONE 0b000000000000
150174
#define LATCH_TGT_RATIO_UNLOCK 0b000000000001 /* <T> TgtRatioUnlocked */
151175
#define LATCH_CLK_RATIO_UNLOCK 0b000000000010 /* <X> ClkRatioUnlocked */

0 commit comments

Comments
 (0)