From 18d9d928e5a7d61cb98698e03dde05d3dfaef8a0 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:48:49 +0200 Subject: [PATCH] add dracut support and make it possible to change your video disable choice --- internal/configs/config_dracut.go | 17 +++++++++++++++++ internal/configs/config_vfio_video.go | 15 ++++++++++++--- internal/ui_main_functions.go | 26 +++++++++++++++++++++----- 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 internal/configs/config_dracut.go diff --git a/internal/configs/config_dracut.go b/internal/configs/config_dracut.go new file mode 100644 index 0000000..fce039f --- /dev/null +++ b/internal/configs/config_dracut.go @@ -0,0 +1,17 @@ +package configs + +import ( + "fmt" + + "github.com/HikariKnight/quickpassthrough/pkg/fileio" +) + +func Set_Dracut() { + config := GetConfig() + + // Write the dracut config file + fileio.AppendContent("add_drivers+=\" vfio_pci vfio vfio_iommu_type1 vfio_virqfd \"\n", fmt.Sprintf("%s/vfio.conf", config.Path.DRACUT)) + + // Add to our kernel arguments file that vfio_pci should load early (dracut does this using kernel arguments) + fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE) +} diff --git a/internal/configs/config_vfio_video.go b/internal/configs/config_vfio_video.go index f99f04b..5dd976f 100644 --- a/internal/configs/config_vfio_video.go +++ b/internal/configs/config_vfio_video.go @@ -1,11 +1,20 @@ package configs -import "github.com/HikariKnight/quickpassthrough/pkg/fileio" +import ( + "fmt" -func DisableVFIOVideo() { + "github.com/HikariKnight/quickpassthrough/pkg/fileio" +) + +func DisableVFIOVideo(i int) { // Get the config config := GetConfig() // Add to the kernel arguments that we want to disable VFIO video output on the host - fileio.AppendContent(" vfio_pci.disable_vga=1", config.Path.CMDLINE) + fileio.AppendContent( + fmt.Sprintf( + " vfio_pci.disable_vga=%v", i, + ), + config.Path.CMDLINE, + ) } diff --git a/internal/ui_main_functions.go b/internal/ui_main_functions.go index 9438859..60750d6 100644 --- a/internal/ui_main_functions.go +++ b/internal/ui_main_functions.go @@ -4,6 +4,7 @@ import ( "regexp" "github.com/HikariKnight/quickpassthrough/internal/configs" + "github.com/HikariKnight/quickpassthrough/pkg/fileio" ) // This function processes the enter event @@ -68,14 +69,29 @@ func (m *model) processSelection() bool { // If user selected yes then if selectedItem.(item).title == "YES" { // Add disable VFIO video to the config - configs.DisableVFIOVideo() + configs.DisableVFIOVideo(1) + } else { + // Add disable VFIO video to the config + configs.DisableVFIOVideo(0) } - // Get the device ids for the selected gpu using ls-iommu - gpu_IDs := getIOMMU("-gr", "-i", m.gpu_group, "--id") + // Get our config struct + config := configs.GetConfig() - // Configure modprobe - configs.Set_Modprobe(gpu_IDs) + // If we have files for modprobe + if fileio.FileExist(config.Path.MODPROBE) { + // Get the device ids for the selected gpu using ls-iommu + gpu_IDs := getIOMMU("-gr", "-i", m.gpu_group, "--id") + + // Configure modprobe + configs.Set_Modprobe(gpu_IDs) + } + + // If we have a folder for dracut + if fileio.FileExist(config.Path.DRACUT) { + // Configure dracut + configs.Set_Dracut() + } // Go to the next view //m.focused++