grepmod () { local line line=$( grep -h -i -m1 "^$1\\s" /drm.cfg.d/* ) [ -z "$line" ] && return echo ${line:${#1}} } # pass module name(s) relative path in /lib/modules with .ko extension, or special like @nvidia or @amd load_gfx () { local MOD FILES 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 FILES=$( grepmod "$MOD" ) [ -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" FILES=$( grepmod "$MOD" ) [ -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" == "xamdgpu" ]; then load_gfx @amdgpu return fi if [ "x$GFX" == "xradeon" ]; then load_gfx @radeon return fi # not forced - check which driver to load CARDS=$(lspci | grep 'Class 0300' | awk '{print $4}') if [ -d "/drm.cfg.d" ] && [ -n "$CARDS" ]; then SUCCESS="yes" for CARD in $CARDS; do # look up exact pci id of this card [ $DEBUG -ge 1 ] && echo "Trying exact matching for drm drivers for $CARD" FILES=$( grepmod "$CARD" ) load_gfx $FILES && continue # failed... try vendor id only CARD=${CARD:0:4} [ $DEBUG -ge 1 ] && echo "Trying vendor matching for drm drivers for $CARD" FILES=$( grepmod "$CARD" ) 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 }