implement set_Modprobe

This commit is contained in:
HikariKnight 2023-04-09 19:05:49 +02:00
parent ca1eedad1c
commit 9d131fa566
2 changed files with 49 additions and 2 deletions

View file

@ -1,5 +1,47 @@
package configs
func Set_Modprobe() {
import (
"fmt"
"strings"
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
)
func Set_Modprobe(gpu_IDs []string) {
// Get the config
config := GetConfig()
// Read our current kernel arguments
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
var vfio_pci_options []string
vfio_pci_options = append(vfio_pci_options, strings.Join(gpu_IDs, ","))
if strings.Contains(kernel_args, "vfio_pci.disable_vga=1") {
vfio_pci_options = append(vfio_pci_options, "disable_vga=1")
}
// Write the vfio.conf file to our modprobe config
fileio.AppendContent(
fmt.Sprint(
"## This is an autogenerated file that stubs your graphic card for use with vfio\n",
"## This file should be placed inside /etc/modprobe.d/\n",
"# Uncomment the line below to \"hardcode\" your graphic card to be bound to the vfio-pci driver.\n",
"# In most cases this should not be neccessary, it will also prevent you from turning off vfio in the bootloader.\n",
fmt.Sprintf(
"#options vfio_pci ids=%s\n",
strings.Join(vfio_pci_options, " "),
),
"\n",
"# Make sure vfio_pci is loaded before these modules: nvidia, nouveau, amdgpu and radeon\n",
"softdep nvidia pre: vfio vfio_pci\n",
"softdep nouveau pre: vfio vfio_pci\n",
"softdep amdgpu pre: vfio vfio_pci\n",
"softdep radeon pre: vfio vfio_pci\n",
),
fmt.Sprintf(
"%s/vfio.conf",
config.Path.MODPROBE,
),
)
}

View file

@ -33,6 +33,8 @@ func (m *model) processSelection() bool {
case GPU_GROUP:
// Generate the VBIOS dumper script once the user has selected a GPU
generateVBIOSDumper(*m)
// Change focus to the next view
m.focused++
case USB:
@ -70,8 +72,11 @@ func (m *model) processSelection() bool {
m.disableVFIOVideo()
}
// 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()
configs.Set_Modprobe(gpu_IDs)
// Go to the next view
m.focused++