-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhot_reset.sh
More file actions
executable file
·59 lines (42 loc) · 1.11 KB
/
hot_reset.sh
File metadata and controls
executable file
·59 lines (42 loc) · 1.11 KB
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
#!/bin/bash
dev=$1
if [ -z "$dev" ]; then
echo "Error: no device specified"
exit 1
fi
if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
dev="0000:$dev"
fi
if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "Error: device $dev not found"
exit 1
fi
port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))
if [ ! -e "/sys/bus/pci/devices/$port" ]; then
echo "Error: device $port not found"
exit 1
fi
echo "Removing $dev..."
echo 1 > "/sys/bus/pci/devices/$dev/remove"
echo "Performing hot reset of port $port..."
bc=$(setpci -s $port BRIDGE_CONTROL)
echo "Bridge control:" $bc
setpci -s $port BRIDGE_CONTROL=$(printf "%04x" $(("0x$bc" | 0x40)))
sleep 0.01
setpci -s $port BRIDGE_CONTROL=$bc
sleep 0.5
echo "Rescanning bus..."
echo 1 > "/sys/bus/pci/devices/$port/rescan"
sleep 5
if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "First try was not successful. Starting stand-by."
rtcwake -u -s 5 -m mem
echo 1 > "/sys/bus/pci/devices/$port/rescan"
sleep 5
fi
if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
echo "We were not successful"
exit 1
else
echo "Happy gaming"
fi