This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvgt_mgr
executable file
·218 lines (191 loc) · 5.86 KB
/
vgt_mgr
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
connector_lookup() {
lookup_return=unknown
if [ x"$1" == x"${connector_count[1]}" ]; then
lookup_return=PORT_B
elif [ x"$1" == x"${connector_count[2]}" ]; then
lookup_return=PORT_C
elif [ x"$1" == x"${connector_count[3]}" ]; then
lookup_return=PORT_D
fi
}
get_port_name() {
port_name=unknown
check_connector_table=0
if [ x"$1" == x"card0-eDP-1" ]; then
port_name=PORT_A
elif [ x"$1" == x"card0-VGA-1" ]; then
port_name=PORT_E
elif [ x"$1" == x"card0-DP-1" ]; then
check_connector_table=1
elif [ x"$1" == x"card0-DP-2" ]; then
check_connector_table=1
elif [ x"$1" == x"card0-DP-3" ]; then
check_connector_table=1
elif [ x"$1" == x"card0-HDMI-A-1" ]; then
check_connector_table=1
elif [ x"$1" == x"card0-HDMI-A-2" ]; then
check_connector_table=1
elif [ x"$1" == x"card0-HDMI-A-3" ]; then
check_connector_table=1
fi
if [ x"$check_connector_table" == x"1" ]; then
last_index=$((${#1}-1))
connector_lookup ${1:$last_index:1}
port_name=$lookup_return
fi
}
get_drm_name () {
drm_name=unknown
if [ x"$1" == x"PORT_A" ] && [ x"$2" == x"eDP" ] && [ x"${connector_count[0]}" != x"0" ]; then
drm_name=card0-eDP-1
elif [ x"$1" == x"PORT_B" ] && [ x"$2" == x"DP" ] && [ x"${connector_count[1]}" != x"0" ]; then
drm_name=card0-DP-${connector_count[1]}
elif [ x"$1" == x"PORT_B" ] && [ x"$2" == x"HDMI" ] && [ x"${connector_count[1]}" != x"0" ]; then
drm_name=card0-HDMI-A-${connector_count[1]}
elif [ x"$1" == x"PORT_C" ] && [ x"$2" == x"DP" ] && [ x"${connector_count[2]}" != x"0" ]; then
drm_name=card0-DP-${connector_count[2]}
elif [ x"$1" == x"PORT_C" ] && [ x"$2" == x"HDMI" ] && [ x"${connector_count[2]}" != x"0" ]; then
drm_name=card0-HDMI-A-${connector_count[2]}
elif [ x"$1" == x"PORT_D" ] && [ x"$2" == x"DP" ] && [ x"${connector_count[3]}" != x"0" ]; then
drm_name=card0-DP-${connector_count[3]}
elif [ x"$1" == x"PORT_D" ] && [ x"$2" == x"HDMI" ] && [ x"${connector_count[3]}" != x"0" ]; then
drm_name=card0-HDMI-A-${connector_count[3]}
elif [ x"$1" == x"PORT_E" ] && [ x"$2" == x"VGA" ] && [ x"${connector_count[4]}" != x"0" ]; then
drm_name=card0-VGA-1
fi
}
wait_for_edid () {
EDID=""
for try in 1 2 3 4 5 6 7 8 9 10
do
EDID=`cat $1`
if [ -z "$EDID" ]; then
sleep 1;
else
break;
fi
done
if [ -z "$EDID" ]; then
echo "Did not get EDID for a connected monitor from $1! Hotplug may not work properly!"
fi
}
count=0
connector_count[0]=1
connector_count[1]=0
connector_count[2]=0
connector_count[3]=0
connector_count[4]=1
vgt_dir=/sys/kernel/vgt
if [ x"`cat $vgt_dir/control/PORT_B/presence`" == x"present" ]; then
count=`expr $count + 1`
connector_count[1]=$count
fi
if [ x"`cat $vgt_dir/control/PORT_C/presence`" == x"present" ]; then
count=`expr $count + 1`
connector_count[2]=$count
fi
if [ x"`cat $vgt_dir/control/PORT_D/presence`" == x"present" ]; then
count=`expr $count + 1`
connector_count[3]=$count
fi
#######################################################################
############################ --help ###################################
#######################################################################
if [ x"$1" == x"--help" ]; then
echo Usage: vgt_mgr --command param1 param2
exit 0
fi
#######################################################################
############################ --version ################################
#######################################################################
if [ x"$1" == x"--version" ]; then
echo 1.0
exit 0
fi
#######################################################################
############################ --get port name ##########################
#######################################################################
if [ x"$1" == x"--get-port-name" ]; then
get_port_name $2
echo $port_name
exit 0
fi
#######################################################################
############################ --get drm name ###########################
#######################################################################
if [ x"$1" == x"--get-drm-name" ]; then
get_drm_name $2 $3
echo $drm_name
exit 0
fi
#######################################################################
############################ --detect display #########################
#######################################################################
if [ x"$1" == x"--detect-display" ]; then
check_src2=0
type=0
connect=0
filelist=`ls $vgt_dir`
for guest in $filelist
do
if [ x"${guest:0:2}" != x"vm" ]; then
continue
fi
if [ x"$2" == x"PORT_A" ]; then
src1=/sys/class/drm/card0-eDP-1
target=$vgt_dir/$guest/PORT_A
type=1
elif [ x"$2" == x"PORT_B" ]; then
get_drm_name $2 DP
src1=/sys/class/drm/$drm_name
get_drm_name $2 HDMI
src2=/sys/class/drm/$drm_name
target=$vgt_dir/$guest/PORT_B
check_src2=1
type=2
elif [ x"$2" == x"PORT_C" ]; then
get_drm_name $2 DP
src1=/sys/class/drm/$drm_name
get_drm_name $2 HDMI
src2=/sys/class/drm/$drm_name
target=$vgt_dir/$guest/PORT_C
check_src2=1
type=3
elif [ x"$2" == x"PORT_D" ]; then
get_drm_name $2 DP
src1=/sys/class/drm/$drm_name
get_drm_name $2 HDMI
src2=/sys/class/drm/$drm_name
target=$vgt_dir/$guest/PORT_D
check_src2=1
type=4
elif [ x"$2" == x"PORT_E" ]; then
src1=/sys/class/drm/card0-VGA-1
target=$vgt_dir/$guest/PORT_E
type=0
fi
if [ ! -d $target ]; then
continue
fi
if [ -d $src1 ] && [ `cat $src1/status` == "connected" ]; then
wait_for_edid $src1/edid
dd if=$src1/edid of=$target/edid bs=128 count=1
echo $type > $target/type
connect=1
fi
if [ -d $src2 ] && [ $check_src2 -eq 1 ] && [ `cat $src2/status` == "connected" ]; then
wait_for_edid $src2/edid
dd if=$src2/edid of=$target/edid bs=128 count=1
type=`expr $type + 3`
echo $type > $target/type
connect=1
fi
if [ $connect -eq 1 ]; then
echo "connect" > $target/connection
else
echo "disconnect" > $target/connection
fi
done
exit 0
fi