summaryrefslogtreecommitdiffstats
path: root/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version
blob: 0165191d69622dd09b9911700abf1ead03b7be90 (plain) (blame)
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
#!/bin/ash
# This script checks whether given VMware version supports the CPU:
# * Intel: check for "VMX Unrestricted Guest" CPU flag
# * AMD:   check if CPU family is Bulldozer or newer

export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin

VIRTTYPE=$(grep -m1 '^flags\s*:' /proc/cpuinfo | grep -wo -e svm -e vmx)

if [ -z "$VIRTTYPE" ]; then
	echo 12
	exit 0
fi

modprobe msr

VT=
if [ "$VIRTTYPE" = "vmx" ]; then    # intel
	BIT1=$(rdmsr --bitfield 0:0 0x3a 2>/dev/null || echo "fail")
	BIT2=$(rdmsr --bitfield 2:2 0x3a 2>/dev/null || echo "fail")
	if [ "$BIT1" = "0" ] || [ "$BIT2" = "1" ]; then
		VT="ENABLED"
	fi
elif [ "$VIRTTYPE" = "svm" ]; then  # amd
	BIT=$(rdmsr --bitfield 4:4 0xc0010114 2>/dev/null || echo "fail")
	if [ "$BIT" = "0" ]; then
		VT="ENABLED"
	fi
fi

if [ "$VT" != "ENABLED" ]; then
	echo 12
	exit 0
fi

version=12
if [ "$VIRTTYPE" = "vmx" ]; then
	flag="$( rdmsr --bitfield 5:5 0x485 )"
	[ "$flag" = "1" ] && version=15
elif [ "$VIRTTYPE" = "svm" ]; then
	family="$( awk '$1$2 == "cpufamily" {print $NF;exit}' /proc/cpuinfo )"
	[ "$family" -ge 21 ] && version=15
fi

echo "$version"