mirror of
https://github.com/cyring/CoreFreq.git
synced 2025-07-23 12:13:07 +02:00
[aarch64][riscv64][ppc64] Improving DT integration to detect VM
This commit is contained in:
7
Makefile
7
Makefile
@@ -96,6 +96,13 @@ ifneq ($(HWM_CHIPSET),)
|
||||
ccflags-y += -D HWM_CHIPSET=$(HWM_CHIPSET)
|
||||
endif
|
||||
|
||||
ccflags-y += -D DT_VIRTUAL_BOARD='{ \
|
||||
"linux,dummy-virt", \
|
||||
"riscv-virtio", \
|
||||
"qemu,pseries", \
|
||||
NULL \
|
||||
}'
|
||||
|
||||
ifneq ($(NO_HEADER),)
|
||||
LAYOUT += -D NO_HEADER=$(NO_HEADER)
|
||||
endif
|
||||
|
@@ -4,7 +4,22 @@
|
||||
* Licenses: GPL2
|
||||
*/
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
|
||||
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
|
||||
#define of_cpu_device_node_get(cpu) \
|
||||
({ \
|
||||
struct device_node *cpu_node; \
|
||||
struct device *cpu_dev; \
|
||||
cpu_dev = get_cpu_device(cpu); \
|
||||
if (!cpu_dev) { \
|
||||
cpu_node = of_get_cpu_node(cpu, NULL); \
|
||||
} else { \
|
||||
cpu_node = of_node_get(cpu_dev->of_node); \
|
||||
} \
|
||||
cpu_node; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
|
||||
#define of_device_compatible_match(_device_, _compat_) \
|
||||
({ \
|
||||
const struct device_node *device = _device_; \
|
||||
@@ -164,12 +179,6 @@ ASM_COUNTERx3(x11, x12, x13, x14, ASM_RDTSC, mem_tsc, __VA_ARGS__)
|
||||
#define VENDOR_VMWARE "VMwawarereVM"
|
||||
#define VENDOR_HYPERV "Micrt Hvosof"
|
||||
|
||||
#define DT_VIRTUAL_BOARD { \
|
||||
"linux,dummy-virt", \
|
||||
"qemu,pseries", \
|
||||
NULL \
|
||||
}
|
||||
|
||||
#define LATCH_NONE 0b000000000000
|
||||
#define LATCH_TGT_RATIO_UNLOCK 0b000000000001 /* <T> TgtRatioUnlocked */
|
||||
#define LATCH_CLK_RATIO_UNLOCK 0b000000000010 /* <X> ClkRatioUnlocked */
|
||||
|
@@ -4667,7 +4667,19 @@ static int CoreFreqK_Ignition_Level_Up(INIT_ARG *pArg)
|
||||
StrCopy(PUBLIC(RO(Proc))->Features.Info.Vendor.ID,
|
||||
PUBLIC(RO(Proc))->Architecture,
|
||||
12 + 4);
|
||||
|
||||
/* Attempt to detect virtualization from Device Tree */
|
||||
#ifdef CONFIG_OF
|
||||
{
|
||||
const char *virtualBoard[] = DT_VIRTUAL_BOARD;
|
||||
if (of_device_compatible_match(of_root, virtualBoard) > 0)
|
||||
{
|
||||
PUBLIC(RO(Proc))->HypervisorID = HYPERV_KVM;
|
||||
PUBLIC(RO(Proc))->Features.Info.Hypervisor.CRC = CRC_KVM;
|
||||
StrCopy(PUBLIC(RO(Proc))->Features.Info.Hypervisor.ID,
|
||||
VENDOR_KVM, 12 + 4);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_OF */
|
||||
/* Check if the Processor is actually virtualized ? */
|
||||
#ifdef CONFIG_XEN
|
||||
if (xen_pv_domain() || xen_hvm_domain())
|
||||
|
@@ -4,7 +4,7 @@
|
||||
* Licenses: GPL2
|
||||
*/
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
|
||||
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
|
||||
#define of_cpu_device_node_get(cpu) \
|
||||
({ \
|
||||
struct device_node *cpu_node; \
|
||||
@@ -19,6 +19,24 @@
|
||||
})
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
|
||||
#define of_device_compatible_match(_device_, _compat_) \
|
||||
({ \
|
||||
const struct device_node *device = _device_; \
|
||||
const char *const *compat = _compat_; \
|
||||
unsigned int tmp, score = 0; \
|
||||
\
|
||||
if (compat != NULL) \
|
||||
while (*compat) { \
|
||||
tmp = of_device_is_compatible(device, *compat); \
|
||||
if (tmp > score) \
|
||||
score = tmp; \
|
||||
compat++; \
|
||||
} \
|
||||
score; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#define Atomic_Read_VPMC(_lock, _dest, _src) \
|
||||
{ \
|
||||
/* __asm__ volatile \
|
||||
|
@@ -4661,7 +4661,19 @@ static int CoreFreqK_Ignition_Level_Up(INIT_ARG *pArg)
|
||||
StrCopy(PUBLIC(RO(Proc))->Features.Info.Vendor.ID,
|
||||
PUBLIC(RO(Proc))->Architecture,
|
||||
12 + 4);
|
||||
|
||||
/* Attempt to detect virtualization from Device Tree */
|
||||
#ifdef CONFIG_OF
|
||||
{
|
||||
const char *virtualBoard[] = DT_VIRTUAL_BOARD;
|
||||
if (of_device_compatible_match(of_root, virtualBoard) > 0)
|
||||
{
|
||||
PUBLIC(RO(Proc))->HypervisorID = HYPERV_KVM;
|
||||
PUBLIC(RO(Proc))->Features.Info.Hypervisor.CRC = CRC_KVM;
|
||||
StrCopy(PUBLIC(RO(Proc))->Features.Info.Hypervisor.ID,
|
||||
VENDOR_KVM, 12 + 4);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_OF */
|
||||
/* Check if the Processor is actually virtualized ? */
|
||||
#ifdef CONFIG_XEN
|
||||
if (xen_pv_domain() || xen_hvm_domain())
|
||||
|
@@ -4,7 +4,7 @@
|
||||
* Licenses: GPL2
|
||||
*/
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
|
||||
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
|
||||
#define of_cpu_device_node_get(cpu) \
|
||||
({ \
|
||||
struct device_node *cpu_node; \
|
||||
@@ -19,6 +19,24 @@
|
||||
})
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
|
||||
#define of_device_compatible_match(_device_, _compat_) \
|
||||
({ \
|
||||
const struct device_node *device = _device_; \
|
||||
const char *const *compat = _compat_; \
|
||||
unsigned int tmp, score = 0; \
|
||||
\
|
||||
if (compat != NULL) \
|
||||
while (*compat) { \
|
||||
tmp = of_device_is_compatible(device, *compat); \
|
||||
if (tmp > score) \
|
||||
score = tmp; \
|
||||
compat++; \
|
||||
} \
|
||||
score; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
|
||||
#define sys_reg(op0, op1, crn, crm, op2) ({ \
|
||||
UNUSED(op0); \
|
||||
|
Reference in New Issue
Block a user