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