From 829a4ddc2fbc542e0e6bb895f7de4b2d58e9a772 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Thu, 23 Jul 2020 22:48:14 -0500 Subject: [PATCH] Initial commit --- README.md | 3 + bind | 15 ++ bumblebee/bumblebee.conf | 71 +++++++++ bumblebee/bumblebee.conf.pacsave | 69 ++++++++ bumblebee/xorg.conf.d/10-dummy.conf | 0 bumblebee/xorg.conf.nouveau | 18 +++ bumblebee/xorg.conf.nvidia | 40 +++++ clrgpu | 2 + modprobe.d/g14-bbswitch.conf | 1 + modprobe.d/g14-block.conf | 5 + modprobe.d/g14-nvidia.conf | 2 + startvm | 8 + unbind | 18 +++ vm | 32 ++++ which-driver-for-gpu | 2 + win10.xml | 238 ++++++++++++++++++++++++++++ xorg.conf.d/99-g14-display.conf | 21 +++ xorg.conf.d/99-g14-touchpad.conf | 9 ++ 18 files changed, 554 insertions(+) create mode 100644 README.md create mode 100755 bind create mode 100644 bumblebee/bumblebee.conf create mode 100644 bumblebee/bumblebee.conf.pacsave create mode 100644 bumblebee/xorg.conf.d/10-dummy.conf create mode 100644 bumblebee/xorg.conf.nouveau create mode 100644 bumblebee/xorg.conf.nvidia create mode 100755 clrgpu create mode 100644 modprobe.d/g14-bbswitch.conf create mode 100644 modprobe.d/g14-block.conf create mode 100644 modprobe.d/g14-nvidia.conf create mode 100755 startvm create mode 100755 unbind create mode 100755 vm create mode 100755 which-driver-for-gpu create mode 100755 win10.xml create mode 100644 xorg.conf.d/99-g14-display.conf create mode 100644 xorg.conf.d/99-g14-touchpad.conf diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea369c0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +This is a collection of scripts for managing the GPU in the Asus Zephyrus G14. + +The setup involves using bumblebee, bbswitch, and GPU passthrough to a Windows 10 vm. bbswitch is unable to wake the GPU up at this time. diff --git a/bind b/bind new file mode 100755 index 0000000..16599bb --- /dev/null +++ b/bind @@ -0,0 +1,15 @@ +#!/bin/bash +modprobe vfio-pci +for dev in "$@"; do + vendor=$(cat /sys/bus/pci/devices/$dev/vendor) + device=$(cat /sys/bus/pci/devices/$dev/device) + if [ -e /sys/bus/pci/devices/$dev/driver ]; then + #echo $dev > /sys/bus/pci/devices/$dev/driver/unbind + rmmod nvidia_drm + rmmod nvidia_modeset + rmmod nvidia + echo "Unbound old driver" + fi + echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id + echo "Bound VFIO driver" +done diff --git a/bumblebee/bumblebee.conf b/bumblebee/bumblebee.conf new file mode 100644 index 0000000..dc8b02e --- /dev/null +++ b/bumblebee/bumblebee.conf @@ -0,0 +1,71 @@ +# Configuration file for Bumblebee. Values should **not** be put between quotes + +## Server options. Any change made in this section will need a server restart +# to take effect. +[bumblebeed] +# The secondary Xorg server DISPLAY number +VirtualDisplay=:8 +# Should the unused Xorg server be kept running? Set this to true if waiting +# for X to be ready is too long and don't need power management at all. +KeepUnusedXServer=true +# The name of the Bumbleblee server group name (GID name) +ServerGroup=bumblebee +# Card power state at exit. Set to false if the card shoud be ON when Bumblebee +# server exits. +TurnCardOffAtExit=false +# The default behavior of '-f' option on optirun. If set to "true", '-f' will +# be ignored. +NoEcoModeOverride=false +# The Driver used by Bumblebee server. If this value is not set (or empty), +# auto-detection is performed. The available drivers are nvidia and nouveau +# (See also the driver-specific sections below) +Driver=nvidia +# Directory with a dummy config file to pass as a -configdir to secondary X +XorgConfDir=/etc/bumblebee/xorg.conf.d +# PCI Vendor ID of integrated card, empty defaults to INTEL (0x8086) +IGCPCIVendorId=0x1002 + +## Client options. Will take effect on the next optirun executed. +[optirun] +# Acceleration/ rendering bridge, possible values are auto, virtualgl and +# primus. +Bridge=primus +# The method used for VirtualGL to transport frames between X servers. +# Possible values are proxy, jpeg, rgb, xv and yuv. +VGLTransport=proxy +# List of paths which are searched for the primus libGL.so.1 when using +# the primus bridge +PrimusLibraryPath=/usr/lib/primus:/usr/lib32/primus +# Should the program run under optirun even if Bumblebee server or nvidia card +# is not available? +AllowFallbackToIGC=false + + +# Driver-specific settings are grouped under [driver-NAME]. The sections are +# parsed if the Driver setting in [bumblebeed] is set to NAME (or if auto- +# detection resolves to NAME). +# PMMethod: method to use for saving power by disabling the nvidia card, valid +# values are: auto - automatically detect which PM method to use +# bbswitch - new in BB 3, recommended if available +# switcheroo - vga_switcheroo method, use at your own risk +# none - disable PM completely +# https://github.com/Bumblebee-Project/Bumblebee/wiki/Comparison-of-PM-methods + +## Section with nvidia driver specific options, only parsed if Driver=nvidia +[driver-nvidia] +# Module name to load, defaults to Driver if empty or unset +KernelDriver=nvidia +PMMethod=none +# colon-separated path to the nvidia libraries +LibraryPath=/usr/lib/nvidia:/usr/lib32/nvidia:/usr/lib:/usr/lib32 +# comma-separated path of the directory containing nvidia_drv.so and the +# default Xorg modules path +XorgModulePath=/usr/lib/nvidia/xorg/,/usr/lib/xorg/modules +XorgConfFile=/etc/bumblebee/xorg.conf.nvidia + +## Section with nouveau driver specific options, only parsed if Driver=nouveau +[driver-nouveau] +KernelDriver=nouveau +PMMethod=auto +XorgConfFile=/etc/bumblebee/xorg.conf.nouveau + diff --git a/bumblebee/bumblebee.conf.pacsave b/bumblebee/bumblebee.conf.pacsave new file mode 100644 index 0000000..0fefb14 --- /dev/null +++ b/bumblebee/bumblebee.conf.pacsave @@ -0,0 +1,69 @@ +# Configuration file for Bumblebee. Values should **not** be put between quotes + +## Server options. Any change made in this section will need a server restart +# to take effect. +[bumblebeed] +# The secondary Xorg server DISPLAY number +VirtualDisplay=:8 +# Should the unused Xorg server be kept running? Set this to true if waiting +# for X to be ready is too long and don't need power management at all. +KeepUnusedXServer=false +# The name of the Bumbleblee server group name (GID name) +ServerGroup=bumblebee +# Card power state at exit. Set to false if the card shoud be ON when Bumblebee +# server exits. +TurnCardOffAtExit=true +# The default behavior of '-f' option on optirun. If set to "true", '-f' will +# be ignored. +NoEcoModeOverride=false +# The Driver used by Bumblebee server. If this value is not set (or empty), +# auto-detection is performed. The available drivers are nvidia and nouveau +# (See also the driver-specific sections below) +Driver=nvidia +# Directory with a dummy config file to pass as a -configdir to secondary X +XorgConfDir=/etc/bumblebee/xorg.conf.d + +## Client options. Will take effect on the next optirun executed. +[optirun] +# Acceleration/ rendering bridge, possible values are auto, virtualgl and +# primus. +Bridge=auto +# The method used for VirtualGL to transport frames between X servers. +# Possible values are proxy, jpeg, rgb, xv and yuv. +VGLTransport=proxy +# List of paths which are searched for the primus libGL.so.1 when using +# the primus bridge +PrimusLibraryPath=/usr/lib/primus:/usr/lib32/primus +# Should the program run under optirun even if Bumblebee server or nvidia card +# is not available? +AllowFallbackToIGC=false + + +# Driver-specific settings are grouped under [driver-NAME]. The sections are +# parsed if the Driver setting in [bumblebeed] is set to NAME (or if auto- +# detection resolves to NAME). +# PMMethod: method to use for saving power by disabling the nvidia card, valid +# values are: auto - automatically detect which PM method to use +# bbswitch - new in BB 3, recommended if available +# switcheroo - vga_switcheroo method, use at your own risk +# none - disable PM completely +# https://github.com/Bumblebee-Project/Bumblebee/wiki/Comparison-of-PM-methods + +## Section with nvidia driver specific options, only parsed if Driver=nvidia +[driver-nvidia] +# Module name to load, defaults to Driver if empty or unset +KernelDriver=nvidia +PMMethod=bbswitch +# colon-separated path to the nvidia libraries +LibraryPath=/usr/lib/nvidia:/usr/lib32/nvidia:/usr/lib:/usr/lib32 +# comma-separated path of the directory containing nvidia_drv.so and the +# default Xorg modules path +XorgModulePath=/usr/lib/nvidia/xorg,/usr/lib/xorg/modules +XorgConfFile=/etc/bumblebee/xorg.conf.nvidia + +## Section with nouveau driver specific options, only parsed if Driver=nouveau +[driver-nouveau] +KernelDriver=nouveau +PMMethod=auto +XorgConfFile=/etc/bumblebee/xorg.conf.nouveau + diff --git a/bumblebee/xorg.conf.d/10-dummy.conf b/bumblebee/xorg.conf.d/10-dummy.conf new file mode 100644 index 0000000..e69de29 diff --git a/bumblebee/xorg.conf.nouveau b/bumblebee/xorg.conf.nouveau new file mode 100644 index 0000000..87e48cb --- /dev/null +++ b/bumblebee/xorg.conf.nouveau @@ -0,0 +1,18 @@ +Section "ServerLayout" + Identifier "Layout0" + Option "AutoAddDevices" "false" + Option "AutoAddGPU" "false" +EndSection + +Section "Device" + Identifier "DiscreteNvidia" + Driver "nouveau" + +# If the X server does not automatically detect your VGA device, +# you can manually set it here. +# To get the BusID prop, run `lspci | egrep 'VGA|3D'` and input the data +# as you see in the commented example. +# This Setting is needed on Ubuntu 13.04. +# BusID "PCI:01:00:0" + +EndSection diff --git a/bumblebee/xorg.conf.nvidia b/bumblebee/xorg.conf.nvidia new file mode 100644 index 0000000..243c971 --- /dev/null +++ b/bumblebee/xorg.conf.nvidia @@ -0,0 +1,40 @@ +Section "ServerLayout" + Identifier "Layout0" + Option "AutoAddDevices" "false" + Option "AutoAddGPU" "false" +EndSection + +Section "Device" + Identifier "DiscreteNvidia" + Driver "nvidia" + VendorName "NVIDIA Corporation" + +# If the X server does not automatically detect your VGA device, +# you can manually set it here. +# To get the BusID prop, run `lspci | egrep 'VGA|3D'` and input the data +# as you see in the commented example. +# This Setting may be needed in some platforms with more than one +# nvidia card, which may confuse the proprietary driver (e.g., +# trying to take ownership of the wrong device). Also needed on Ubuntu 13.04. +# BusID "PCI:01:00:0" + +# Setting ProbeAllGpus to false prevents the new proprietary driver +# instance spawned to try to control the integrated graphics card, +# which is already being managed outside bumblebee. +# This option doesn't hurt and it is required on platforms running +# more than one nvidia graphics card with the proprietary driver. +# (E.g. Macbook Pro pre-2010 with nVidia 9400M + 9600M GT). +# If this option is not set, the new Xorg may blacken the screen and +# render it unusable (unless you have some way to run killall Xorg). + Option "ProbeAllGpus" "false" + + Option "NoLogo" "true" + Option "UseEDID" "false" + Option "UseDisplayDevice" "none" + + Option "NVreg_DynamicPowerManagement=0x02" +EndSection + +Section "ServerFlags" + Option "IgnoreABI" "1" +EndSection diff --git a/clrgpu b/clrgpu new file mode 100755 index 0000000..2cd6608 --- /dev/null +++ b/clrgpu @@ -0,0 +1,2 @@ +#!/bin/bash +optiprime glxinfo diff --git a/modprobe.d/g14-bbswitch.conf b/modprobe.d/g14-bbswitch.conf new file mode 100644 index 0000000..96b0493 --- /dev/null +++ b/modprobe.d/g14-bbswitch.conf @@ -0,0 +1 @@ +#options bbswitch load_state=1 unload_state=1 diff --git a/modprobe.d/g14-block.conf b/modprobe.d/g14-block.conf new file mode 100644 index 0000000..d2260e6 --- /dev/null +++ b/modprobe.d/g14-block.conf @@ -0,0 +1,5 @@ +blacklist nouveau +blacklist nvidiafb +blacklist rivafb +blacklist i2c_nvidia_gpu + diff --git a/modprobe.d/g14-nvidia.conf b/modprobe.d/g14-nvidia.conf new file mode 100644 index 0000000..63a4f13 --- /dev/null +++ b/modprobe.d/g14-nvidia.conf @@ -0,0 +1,2 @@ +options nvidia_drm modeset=1 +options nvidia NVreg_DynamicPowerManagement=0x02 diff --git a/startvm b/startvm new file mode 100755 index 0000000..694e069 --- /dev/null +++ b/startvm @@ -0,0 +1,8 @@ +#!/bin/bash +if [ `which-driver-for-gpu` == "nvidia" ]; then + sudo systemctl stop bumblebeed + sleep 1 + sudo bind 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 +fi +vm +#sudo unbind 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 diff --git a/unbind b/unbind new file mode 100755 index 0000000..0913655 --- /dev/null +++ b/unbind @@ -0,0 +1,18 @@ +#!/bin/bash +for dev in "$@"; do + vendor=$(cat /sys/bus/pci/devices/$dev/vendor) + device=$(cat /sys/bus/pci/devices/$dev/device) + echo "Removing ${dev} from vfio-pci id list" + echo "${vendor} ${device}" > /sys/bus/pci/drivers/vfio-pci/remove_id + sleep 0.1 + echo "Remove PCI device" + echo 1 > /sys/bus/pci/devices/${dev}/remove + while [[ -e "/sys/bus/pci/devices/${dev}" ]]; do + sleep 0.1 + done + echo "Rescanning..." + echo 1 > /sys/bus/pci/rescan + while [[ ! -e "/sys/bus/pci/devices/${dev}" ]]; do + sleep 0.1 + done +done diff --git a/vm b/vm new file mode 100755 index 0000000..270fca0 --- /dev/null +++ b/vm @@ -0,0 +1,32 @@ +#!/bin/bash +echo "Starting Network" +virsh --connect=qemu:///system net-start default +echo "Starting VM" +virsh --connect=qemu:///system start win10 +echo "Starting Scream" +scream -o pulse -i virbr0 & +echo "Starting Looking Glass" +looking-glass-client -s no -K 120 -d yes -g egl -a -M no & +while [ "$command" != "stop" ]; do + read command +done +echo "Stopping VM..." +#stop +virsh --connect=qemu:///system shutdown win10 +echo "Killing Looking Glass and Scream..." +kill -9 $(jobs -p) +vmstate=$(virsh --connect=qemu:///system domstate win10) +echo "Waiting for shutdown..." +while [ "$vmstate" != "shut off" ]; do + sleep 1 + vmstate=$(virsh --connect=qemu:///system domstate win10) +done +sleep 1 +echo "VM is off, unbinding from vfio-pci" +sudo unbind 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 +sleep 1 +sudo modprobe nvidia NVreg_DynamicPowerManagement=0x02 +sleep 2 +sudo systemctl start bumblebeed +sleep 1 +clrgpu diff --git a/which-driver-for-gpu b/which-driver-for-gpu new file mode 100755 index 0000000..ff85c33 --- /dev/null +++ b/which-driver-for-gpu @@ -0,0 +1,2 @@ +#!/bin/bash +lspci -k -s 01:00.0 | sed -n "s/\s*Kernel driver in use: \(\w*\)/\1/p" diff --git a/win10.xml b/win10.xml new file mode 100755 index 0000000..07f34d8 --- /dev/null +++ b/win10.xml @@ -0,0 +1,238 @@ + + + + win10 + eaaf91f7-9c28-4c33-93c0-9e48a1195983 + + + + + + 20280320 + 20280320 + 12 + 1 + + + + + + + + + + + + + + + + + + hvm + /usr/share/edk2-ovmf/x64/OVMF_CODE.fd + /var/lib/libvirt/qemu/nvram/win10_VARS.fd + + + + + + + + + + + + + + + + + + + + + + + + + + + + + destroy + restart + destroy + + + + + + /usr/bin/qemu-system-x86_64 + + + + +
+ + + + + + +
+ + + + + + +
+ + +
+ + +
+ + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + +
+ + + +
+ + + + + + +
+ + + + + + + + + + + +
+ + +
+ + + + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + +
+ + +
+ + +
+ + + + 32 +
+ + + + + + + + + + + + + diff --git a/xorg.conf.d/99-g14-display.conf b/xorg.conf.d/99-g14-display.conf new file mode 100644 index 0000000..a422485 --- /dev/null +++ b/xorg.conf.d/99-g14-display.conf @@ -0,0 +1,21 @@ +Section "Device" + Identifier "iGPU" + Driver "amdgpu" +EndSection + +Section "Screen" + Identifier "iGPU" + Device "iGPU" +EndSection + +#Section "Device" +# Identifier "dGPU" +# Driver "nvidia" +# Option "AllowEmptyInitialConfiguration" +# Option "NVreg_DynamicPowerManagement=0x02" +#EndSection + +#Section "ServerLayout" +# Identifier "layout" +# Option "AllowNVIDIAGPUScreens" +#EndSection diff --git a/xorg.conf.d/99-g14-touchpad.conf b/xorg.conf.d/99-g14-touchpad.conf new file mode 100644 index 0000000..afa52ed --- /dev/null +++ b/xorg.conf.d/99-g14-touchpad.conf @@ -0,0 +1,9 @@ +Section "InputClass" + Identifier "touchpad overrides" + MatchDriver "synaptics" + MatchIsTouchpad "on" + Option "TapButton1" "1" + Option "TapButton2" "3" + Option "VertEdgeScroll" "1" + Option "RBCornerButton" "3" +EndSection