-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoweroff-nvidia
executable file
·68 lines (54 loc) · 1.15 KB
/
poweroff-nvidia
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
#!/bin/sh
# should run with dash, /usr/lib/klibc/bin/sh.shared, and busybox sh
PREREQS=""
prereqs() { echo "$PREREQS"; }
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
devices=/sys/bus/pci/devices/
for d in $devices*
do if [ -f $d/boot_vga ] \
&& [ "$(cat $d/boot_vga)" = "0" ] \
&& [ "$(cat $d/vendor)" = "0x10de" ]
then # gotcha!
nvidia=$d
fi
done
if [ -z "$nvidia" ]
then echo "Didn't find an nVidia chip"
exit 1
fi
nvpath=${nvidia#$devices}
bye() {
d="$devices$1"
echo "Attempting to set $1 to D3 powerdown..."
setpci -v -s $1 60+4.B=03:03 \
&& echo "Done." \
|| echo "Failed."
# echo "Attempting to remove $d..."
# echo 1 >>$d/remove \
# && echo "Removed." \
# || echo "Failed."
}
for d in $devices*
do if [ -d $d ] && [ -d $d/$nvpath ]
then bridge=$d
fi
done
bye "$nvpath"
exit 0 # don't shut down the bridge. it's too dangerous
if [ -z "$bridge" ]
then echo "Didn't find the PCI port/slot connected to the nVidia chip?"
exit 2
fi
bridgepath=${bridge#$devices}
for d in $bridge/0*
do if [ "$(cat $d/vendor)" != "0x10de" ]
then echo "PCI port/slot $bridge has non-nvidia things on it o_O"
exit 3
fi
done
bye "$bridgepath"