blob: c3b7b419999598d669a715ea3add65af3419d2aa (
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
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
|
# pass module name(s) relative path in /lib/modules with .ko extension, or special like @nvidia or @amd
load_gfx () {
local MOD FILES OFFSET RETVAL
RETVAL=1 # default: failure
while [ $# -gt 0 ]; do
MOD=$(echo $1) # trim :)
shift
[ -z "$MOD" ] && continue
if [ "x${MOD}" != "x${MOD#@}" ]; then
# starts with '@' - special
OFFSET=$(( ${#MOD} + 2 ))
FILES=$( grep "^$MOD\s" "/drm.cfg" | cut -c ${OFFSET}- )
[ -z "$FILES" ] && drop_shell "Could not find entry for special $MOD"
if load_gfx $FILES; then
RETVAL=0
else
# loading special case failed, try fallback if found
MOD="${MOD}_fallback"
OFFSET=$(( ${#MOD} + 2 ))
FILES=$( grep "^$MOD\s" "/drm.cfg" | cut -c ${OFFSET}- )
[ -n "$FILES" ] && load_gfx $FILES && RETVAL=0
fi
else # regular module name or filename
if [ "x${MOD%.ko}" == "x${MOD}" ]; then
# regular module name
modprobe "$MOD" && RETVAL=0
else
# a .ko file
insmod "/lib/modules/$MOD" && RETVAL=0
fi
fi
done
return $RETVAL
}
setup_gfx () {
local KERN RETVAL CARD CARDS SUCCESS FILES DRM
# check if forced by KCL
if [ "x$GFX" == "xnvidia" ]; then
load_gfx @nvidia
return
fi
if [ "x$GFX" == "xamd" ]; then
load_gfx @amd
return
fi
# not forced - check which driver to load
CARDS=$(lspci | grep 'Class 0300' | awk '{print $4}')
if [ -e "/drm.cfg" ] && [ -n "$CARDS" ]; then
SUCCESS="yes"
for CARD in $CARDS; do
# look up exact pci id of this card
echo Trying exact matching for drm drivers for $CARD
FILES=$(grep "^$CARD\s" "/drm.cfg" | cut -c 11-)
load_gfx $FILES && continue
# failed... try vendor id only
CARD=$(echo $CARD | cut -c 1-4)
echo Trying vendor matching for drm drivers for $CARD
FILES=$(grep "^$CARD\s" "/drm.cfg" | cut -c 6-)
load_gfx $FILES && continue
# everything failed for this card
echo Unknown PCI vendor id: $CARD
SUCCESS="no"
done
[ "x$SUCCESS" == "xyes" ] && return 0
fi
# braindead fallback
echo "At least one gfx card has no known drm drivers.... will load them all :/"
KERN=$(uname -r)
RETVAL=1
[ -z "$KERN" ] && KERN=$(ls '/lib/modules' | grep '\.' | tail -n 1)
for DRM in $(find "/lib/modules/$KERN/kernel/drivers/gpu/drm" -name "*.ko"); do
DRM="$(basename "$DRM")"
DRM="${DRM%.ko}"
modprobe "$DRM" && RETVAL=0
done
return $RETVAL
}
|