From 2e802b6954f44b89d103f23cc55f02a3957a124a Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Mon, 9 Jan 2017 17:41:14 +0000
Subject: LinHES-config: xconfig.sh: check for nvidia cards that need MSI
 disabled. refs #1006

xconfig.sh: use tee to output to console and logfile
---
 abs/core/LinHES-config/PKGBUILD   |   4 +-
 abs/core/LinHES-config/xconfig.sh | 115 +++++++++++++++++++-------------------
 2 files changed, 58 insertions(+), 61 deletions(-)

diff --git a/abs/core/LinHES-config/PKGBUILD b/abs/core/LinHES-config/PKGBUILD
index 7ecd615..f67f84d 100755
--- a/abs/core/LinHES-config/PKGBUILD
+++ b/abs/core/LinHES-config/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-config
 pkgver=8.4.2
-pkgrel=4
+pkgrel=5
 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev LinHes-config )
 pkgdesc="Install and configure your system"
 depends=('bc' 'libstatgrab' 'mysql-python' 'expect' 'curl' 'dnsutils' 'parted'
@@ -152,7 +152,7 @@ md5sums=('97b810ddc35d1f441dbe8cdd6886e2af'
          '27e4fcacca9b9662dd782fbdc92fceea'
          '2a7f3b34e522acfd08283b86c8926aba'
          'b596d2e3779a434435bc0f0277b1ba3e'
-         'fe80b54657f456e5f3d55f4bd5f5f768'
+         'f0fb2ec7bcfa827686f590db8890d87a'
          'f0376c98a7986897406d393186c0365e'
          '157e73d0f90d7b306aba8f5921aeedd3'
          '1f58c0393a131f4a8f9a84b3fe08a7e4'
diff --git a/abs/core/LinHES-config/xconfig.sh b/abs/core/LinHES-config/xconfig.sh
index 3f0a0d2..be01857 100755
--- a/abs/core/LinHES-config/xconfig.sh
+++ b/abs/core/LinHES-config/xconfig.sh
@@ -10,6 +10,9 @@
     #VGACARDTYPE="vesa" xconfig.sh
 
 LOGFILE=/tmp/xconfig.log
+echo -e "\n\n--------------------------------------------------------------------------------" >> $LOGFILE 2>&1
+echo -e `date`"\n" >> $LOGFILE 2>&1
+
 for i in ati intel mga savage sis unichrome
 do
     templist=`echo $i-dri xf86-video-$i`
@@ -23,6 +26,8 @@ MYTH_RUN_STATUS="1"
 NVIDIA_304xx="$TEMPLATES/xorg/304xx_supported.txt"
 NVIDIA_340xx="$TEMPLATES/xorg/340xx_supported.txt"
 NVIDIA_SUPPORTED="$TEMPLATES/xorg/nvidia_supported.txt"
+NVIDIA_DISABLE_MSI="$TEMPLATES/xorg/nvidia_disable_msi.txt"
+NVIDIA_MSI_MODPROBE="$BASE/etc/modprobe.d/nvidia_msi.conf"
 
 . /usr/MythVantage/bin/install_functions.sh
 home_check
@@ -36,7 +41,7 @@ function Xvalues {
         echo "$CMDLINE" | grep -q forceXvesa
         if [ $? = 0  ]
         then
-            echo "Forcing driver to vesa from kernel cmdline"
+            echo "Forcing driver to vesa from kernel cmdline" | tee -a $LOGFILE
             VGACARDTYPE=vesa
             Xcardtype=$VGACARDTYPE
         else
@@ -44,10 +49,10 @@ function Xvalues {
             VGAPCIID=`lspci | grep -i vga |grep -vi non-vga| sort -r | head -n 1 | cut -d" " -f1`
             CARDID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f2`
             VENDORID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f1`
-            echo "Detected $VGACARDTYPE as the video card type"
+            echo "Detected $VGACARDTYPE as the video card type" | tee -a $LOGFILE
         fi
     else
-        echo "Video card type forced to $VGACARDTYPE"
+        echo "Video card type forced to $VGACARDTYPE" | tee -a $LOGFILE
         VGAFORCED=1
         CARDID="NOT_DETECTED"
     fi
@@ -57,12 +62,12 @@ function Xvalues {
 function presetupX {
     if [ "$XIgnoreConfig" = 1 ]
     then
-        echo "Using User Supplied X"
+        echo "Using User Supplied X" | tee -a $LOGFILE
         if [ -f "$MYTHHOME/templates/xorg.user" ]
         then
             cp -f "$MYTHHOME/templates/xorg.user" "$XORG_CONF"
         else
-            echo "Didn't find the file"
+            echo "Didn't find the file" | tee -a $LOGFILE
             echo "Copy your config file to $MYTHHOME/templates/xorg.user" > "$XORG_CONF"
         fi
     else
@@ -71,6 +76,7 @@ function presetupX {
 }
 
 function nvidia_prepare {
+    [[ -f "$NVIDIA_MSI_MODPROBE" ]] && rm -f "$NVIDIA_MSI_MODPROBE"
     for i in libva-intel-driver mesa-libgl nvidia nvidia-utils nvidia-libgl opencl-nvidia nvidia-settings libglvnd nvidia-304xx nvidia-304xx-utils nvidia-304xx-libgl opencl-nvidia-304xx nvidia-340xx nvidia-340xx-utils nvidia-340xx-libgl opencl-nvidia-340xx
     do
         pacman --noconfirm -Rdd $i >> $LOGFILE 2>&1
@@ -83,13 +89,12 @@ function nvidia_prepare {
 }
 
 function pkg_check () {
-    echo "  Checking for $1 in cache or online"
+    echo "  Checking for $1 in cache or online" | tee -a $LOGFILE
     pacman --noconfirm -Sw $1 >> $LOGFILE 2>&1
     rc=$?
     if [ $rc != 0 ]
     then
-        echo "  Couldn't find $1 for install, aborting"
-        echo "  Couldn't find $1 for install, aborting" >> $LOGFILE 2>&1
+        echo "  Couldn't find $1 for install, aborting" | tee -a $LOGFILE
         exit 1
     fi
 }
@@ -99,22 +104,21 @@ function nvidia_driver_install {
 
     INSTALLED=0
 
-    grep -qi "$CARDID" "$NVIDIA_SUPPORTED"
+    CARDNAME=`grep -i "$CARDID" "$NVIDIA_SUPPORTED"`
     if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia" ]]
     then
+        echo "$CARDNAME" | tee -a $LOGFILE
         LIST="nvidia nvidia-libgl nvidia-utils opencl-nvidia nvidia-settings"
         for i in `echo ${LIST}`
         do
             pkg_check $i
         done
-        echo "Installing current nvidia driver"
-        echo "Installing current nvidia driver" >> $LOGFILE 2>&1
+        echo "Installing current nvidia driver" | tee -a $LOGFILE
         nvidia_prepare
         pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
         if [[ $? != 0 ]]
         then
-            echo "ERROR: Unable to install current nvidia driver"
-            echo "ERROR: Unable to install current nvidia driver" >> $LOGFILE 2>&1
+            echo "ERROR: Unable to install current nvidia driver" | tee -a $LOGFILE
         else
             INSTALLED=1
         fi
@@ -122,22 +126,21 @@ function nvidia_driver_install {
 
     if [ $INSTALLED -eq 0 ]
     then
-        grep -qi "$CARDID" "$NVIDIA_340xx"
+        CARDNAME=`grep -i "$CARDID" "$NVIDIA_340xx"`
         if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia-340xx" ]]
         then
+            echo "$CARDNAME" | tee -a $LOGFILE
             LIST="nvidia-340xx nvidia-340xx-libgl nvidia-340xx-utils opencl-nvidia-340xx"
             for i in `echo ${LIST}`
             do
                 pkg_check $i
             done
-            echo "Installing nvidia-340xx driver"
-            echo "Installing nvidia-340xx driver" >> $LOGFILE 2>&1
+            echo "Installing nvidia-340xx driver" | tee -a $LOGFILE
             nvidia_prepare
             pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
             if [[ $? != 0 ]]
             then
-                echo "ERROR: Unable to install nvidia-340xx driver"
-                echo "ERROR: Unable to install nvidia-340xx driver" >> $LOGFILE 2>&1
+                echo "ERROR: Unable to install nvidia-340xx driver" | tee -a $LOGFILE
             else
                 INSTALLED=1
             fi
@@ -146,22 +149,21 @@ function nvidia_driver_install {
 
     if [ $INSTALLED -eq 0 ]
     then
-        grep -qi "$CARDID" "$NVIDIA_304xx"
+        CARDNAME=`grep -i "$CARDID" "$NVIDIA_304xx"`
         if [[ $? = 0 || $VGAFORCED -eq 1 && $VGACARDTYPE == "nvidia-304xx" ]]
         then
+            echo "$CARDNAME" | tee -a $LOGFILE
             LIST="nvidia-304xx nvidia-304xx-libgl nvidia-304xx-utils opencl-nvidia-304xx"
             for i in `echo ${LIST}`
             do
                 pkg_check $i
             done
-            echo "Installing nvidia-304xx driver"
-            echo "Installing nvidia-304xx driver" >> $LOGFILE 2>&1
+            echo "Installing nvidia-304xx driver" | tee -a $LOGFILE
             nvidia_prepare
             pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
             if [[ $? != 0 ]]
             then
-                echo "ERROR: Unable to install nvidia-304xx driver"
-                echo "ERROR: Unable to install nvidia-304xx driver" >> $LOGFILE 2>&1
+                echo "ERROR: Unable to install nvidia-304xx driver" | tee -a $LOGFILE
             else
                 INSTALLED=1
             fi
@@ -171,27 +173,34 @@ function nvidia_driver_install {
     if [ $INSTALLED -eq 0 ]
     then
         #this is a failsafe, can't find the right driver, then use the latest'
-        echo "  Couldn't find the card id in any list"
-        echo "  Couldn't find the card id in any list" >> $LOGFILE 2>&1
+        echo "  Couldn't find the card id in any list" | tee -a $LOGFILE
         LIST="nvidia nvidia-libgl nvidia-utils opencl-nvidia nvidia-settings"
         for i in `echo ${LIST}`
         do
             pkg_check $i
         done
-        echo "Installing current nvidia driver"
-        echo "Installing current nvidia driver" >> $LOGFILE 2>&1
+        echo "Installing current nvidia driver" | tee -a $LOGFILE
         nvidia_prepare
         pacman --noconfirm -S ${LIST} >> $LOGFILE 2>&1
         if [[ $? != 0 ]]
         then
-            echo "ERROR: Unable to install current nvidia driver"
-            echo "ERROR: Unable to install current nvidia driver" >> $LOGFILE 2>&1
+            echo "ERROR: Unable to install current nvidia driver" | tee -a $LOGFILE
         else
             INSTALLED=1
         fi
     fi
 
     echo "/usr/lib/libXvMCNVIDIA_dynamic.so.1" > "$XVMC_CONFIG"
+
+    if [ $INSTALLED -eq 1 ]
+    then
+        grep -qi "$CARDID" "$NVIDIA_DISABLE_MSI"
+        if [[ $? = 0 ]]
+        then
+            echo "Disabling MSI interrupts" | tee -a $LOGFILE
+            echo "options nvidia NVreg_EnableMSI=0" > "$NVIDIA_MSI_MODPROBE"
+        fi
+    fi
 }
 
 function vmware_driver_install {
@@ -200,8 +209,7 @@ function vmware_driver_install {
     do
         pkg_check $i
     done
-    echo "Installing VMware driver"
-    echo "Installing VMware driver" >> $LOGFILE 2>&1
+    echo "Installing VMware driver" | tee -a $LOGFILE
     #this is used to remove nvidia
     nvidia_prepare
     for i in `echo ${LIST}`
@@ -213,8 +221,7 @@ function vmware_driver_install {
 function vesa_driver_install {
     pkg_check xf86-video-vesa
     pkg_check mesa-libgl
-    echo "Installing Vesa driver"
-    echo "Installing Vesa driver" >> $LOGFILE 2>&1
+    echo "Installing Vesa driver" | tee -a $LOGFILE
     #this is used to remove nvidia
     nvidia_prepare
     pacman -S --noconfirm xf86-video-vesa mesa-libgl  >> $LOGFILE 2>&1
@@ -223,8 +230,7 @@ function vesa_driver_install {
 function intel_driver_install {
     pkg_check xf86-video-intel
     pkg_check mesa-libgl
-    echo "Installing Intel driver"
-    echo "Installing Intel driver" >> $LOGFILE 2>&1
+    echo "Installing Intel driver" | tee -a $LOGFILE
     #this is used to remove nvidia
     nvidia_prepare
     pacman -S --noconfirm xf86-video-intel libva-intel-driver mesa-libgl >> $LOGFILE 2>&1
@@ -232,8 +238,7 @@ function intel_driver_install {
 }
 
 function set_res {
-    echo "Setting resolution to ${Xres}"
-    echo "Setting resolution to ${Xres}" >> $LOGFILE 2>&1
+    echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
     cat > /etc/X11/xorg.conf.d/30-screen.conf <<EOF
     Section "Screen"
         Identifier             "Screen0"  #Collapse Monitor and Device section to Screen section
@@ -259,8 +264,7 @@ function setupX {
                     then
                         set_res
                     else
-                        echo "Setting resolution to ${Xres}"
-                        echo "Setting resolution to ${Xres}" >> $LOGFILE 2>&1
+                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                         rm -f /etc/X11/xorg.conf.d/30-screen.conf
                     fi
                 ;;
@@ -277,8 +281,7 @@ function setupX {
                     then
                         set_res
                     else
-                        echo "Setting resolution to ${Xres}"
-                        echo "Setting resolution to ${Xres}" >> $LOGFILE 2>&1
+                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                         rm -f /etc/X11/xorg.conf.d/30-screen.conf
                     fi
                 ;;
@@ -290,8 +293,7 @@ function setupX {
                     then
                         set_res
                     else
-                        echo "Setting resolution to ${Xres}"
-                        echo "Setting resolution to ${Xres}" >> $LOGFILE 2>&1
+                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                         rm -f /etc/X11/xorg.conf.d/30-screen.conf
                     fi
                 ;;
@@ -299,7 +301,7 @@ function setupX {
             vesa|innotek|*) #leaving this as * and vesa for no real reason other then it's explicit to catch vesa
                     if [[ $VGACARDTYPE != "vesa" && $VGACARDTYPE != "innotek" ]]
                     then
-                        echo "Unknown card type, using Vesa."
+                        echo "Unknown card type, using Vesa." | tee -a $LOGFILE
                     fi
                     vesa_driver_install
                     cp $TEMPLATES/xorg/xorg.vesa  /etc/X11/xorg.conf.d/20-automv.conf
@@ -307,8 +309,7 @@ function setupX {
                     then
                         set_res
                     else
-                        echo "Setting resolution to ${Xres}"
-                        echo "Setting resolution to ${Xres}" >> $LOGFILE 2>&1
+                        echo "Setting resolution to ${Xres}" | tee -a $LOGFILE
                         rm -f /etc/X11/xorg.conf.d/30-screen.conf
                     fi
 
@@ -318,7 +319,7 @@ function setupX {
         #configure the ramdisk for kms
         if [ x$RUNP != "x1" ]
         then
-            echo "Running plymouth_config"
+            echo "Running plymouth_config" | tee -a $LOGFILE
             plymouth_config.py >> $LOGFILE 2>&1
         fi
     fi
@@ -328,8 +329,8 @@ function setupX {
 function pacman_wait {
     if [ -f /var/lib/pacman/db.lck ]
     then
-        echo "Pacman is running and must quit before xconfig.sh can continue."
-        echo "  Waiting for pacman to quit..."
+        echo "Pacman is running and must quit before xconfig.sh can continue." | tee -a $LOGFILE
+        echo "  Waiting for pacman to quit..." | tee -a $LOGFILE
         while [ -f /var/lib/pacman/db.lck ]
         do
             sleep 5
@@ -344,13 +345,13 @@ LINE=`grep -i xorg /etc/mythvantage.cfg|grep -q False`
 rc=$?
 if [ $rc = 0 ]
 then
-    echo "**   xorg configuration disabled in /etc/mythvantage.cfg"
+    echo "**   xorg configuration disabled in /etc/mythvantage.cfg" | tee -a $LOGFILE
     exit 1
 fi
 
 if [ -f /etc/sysconfig/IGNORE_X ]
 then
-    echo "**   Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X"
+    echo "**   Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X" | tee -a $LOGFILE
     exit 1
 fi
 
@@ -358,8 +359,7 @@ if [ -f /etc/systemconfig ]
 then
     . /etc/systemconfig
 else
-    echo "    systemconfig not found."
-    echo "    systemconfig not found." >> $LOGFILE 2>&1
+    echo "    systemconfig not found." | tee -a $LOGFILE
 fi
 
 CMDLINE=$(cat /proc/cmdline)
@@ -372,20 +372,17 @@ fi
 if [ ! x$DSR = x ]
 then
     Xres=$DSR
-    echo "    Setting resolution to ${Xres} from kernel cmdline"
-    echo "    Setting resolution to ${Xres} from kernel cmdline" >> $LOGFILE 2>&1
+    echo "    Setting resolution to ${Xres} from kernel cmdline" | tee -a $LOGFILE
 fi
 if [ ! x$DISPLAYRES = x ]
 then
     Xres=$DISPLAYRES
-    echo "Resolution forced to ${Xres}"
-    echo "Resolution forced to ${Xres}" >> $LOGFILE 2>&1
+    echo "Resolution forced to ${Xres}" | tee -a $LOGFILE
 fi
 if [ x$Xres = x ]
 then
     Xres="Auto"
-    echo "Resolution not set. Setting to ${Xres}"
-    echo "Resolution not set. Setting to ${Xres}" >> $LOGFILE 2>&1
+    echo "Resolution not set. Setting to ${Xres}" | tee -a $LOGFILE
 fi
 
 
-- 
cgit v0.12

