1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2017 Mellanox Technologies, Ltd 3 */ 4 5 #include "rte_hypervisor.h" 6 7 #include <stdint.h> 8 #include <string.h> 9 10 #include "rte_cpuflags.h" 11 #include "rte_cpuid.h" 12 13 /* See http://lwn.net/Articles/301888/ */ 14 #define HYPERVISOR_INFO_LEAF 0x40000000 15 16 enum rte_hypervisor 17 rte_hypervisor_get(void) 18 { 19 cpuid_registers_t regs; 20 int reg; 21 char name[13]; 22 23 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_HYPERVISOR)) 24 return RTE_HYPERVISOR_NONE; 25 26 __cpuid(HYPERVISOR_INFO_LEAF, 27 regs[RTE_REG_EAX], regs[RTE_REG_EBX], 28 regs[RTE_REG_ECX], regs[RTE_REG_EDX]); 29 for (reg = 1; reg < 4; reg++) 30 memcpy(name + (reg - 1) * 4, ®s[reg], 4); 31 name[12] = '\0'; 32 33 if (strcmp("KVMKVMKVM", name) == 0) 34 return RTE_HYPERVISOR_KVM; 35 if (strcmp("Microsoft Hv", name) == 0) 36 return RTE_HYPERVISOR_HYPERV; 37 if (strcmp("VMwareVMware", name) == 0) 38 return RTE_HYPERVISOR_VMWARE; 39 return RTE_HYPERVISOR_UNKNOWN; 40 } 41