make generating the module list its own function and fix minor things
This commit is contained in:
parent
8312d8853c
commit
e93d215669
5 changed files with 47 additions and 25 deletions
|
@ -1,6 +1,9 @@
|
||||||
package configs
|
package configs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/command"
|
"github.com/HikariKnight/quickpassthrough/pkg/command"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
"github.com/klauspost/cpuid/v2"
|
"github.com/klauspost/cpuid/v2"
|
||||||
|
@ -34,7 +37,7 @@ func getBootloader(config *Config) {
|
||||||
// This function adds the default kernel arguments we want to the config/cmdline file
|
// This function adds the default kernel arguments we want to the config/cmdline file
|
||||||
// This gives us a file we can read all the kernel arguments this system needs
|
// This gives us a file we can read all the kernel arguments this system needs
|
||||||
// in case of an unknown bootloader
|
// in case of an unknown bootloader
|
||||||
func set_Cmdline() {
|
func Set_Cmdline(gpu_IDs []string) {
|
||||||
// Get the system info
|
// Get the system info
|
||||||
cpuinfo := cpuid.CPU
|
cpuinfo := cpuid.CPU
|
||||||
|
|
||||||
|
@ -52,6 +55,9 @@ func set_Cmdline() {
|
||||||
fileio.AppendContent(" intel_iommu=on", config.Path.CMDLINE)
|
fileio.AppendContent(" intel_iommu=on", config.Path.CMDLINE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the GPU ids for vfio to the kernel arguments
|
||||||
|
fileio.AppendContent(fmt.Sprintf(" vfio_pci.ids=%s", strings.Join(gpu_IDs, ",")), config.Path.CMDLINE)
|
||||||
|
|
||||||
// If the config folder for dracut exists in our configs
|
// If the config folder for dracut exists in our configs
|
||||||
if fileio.FileExist(config.Path.DRACUT) {
|
if fileio.FileExist(config.Path.DRACUT) {
|
||||||
// Add an extra kernel argument needed for dracut users
|
// Add an extra kernel argument needed for dracut users
|
||||||
|
|
|
@ -2,6 +2,7 @@ package configs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
)
|
)
|
||||||
|
@ -10,7 +11,7 @@ func Set_Dracut() {
|
||||||
config := GetConfig()
|
config := GetConfig()
|
||||||
|
|
||||||
// Write the dracut config file
|
// 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))
|
fileio.AppendContent(fmt.Sprintf("add_drivers+=\" %s \"\n", strings.Join(vfio_modules(), " ")), 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)
|
// 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)
|
fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE)
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/uname"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Special function to read the header of a file (reads the first N lines)
|
// Special function to read the header of a file (reads the first N lines)
|
||||||
|
@ -64,25 +63,15 @@ func initramfs_addModules(conffile string) {
|
||||||
fileio.AppendContent(
|
fileio.AppendContent(
|
||||||
fmt.Sprint(
|
fmt.Sprint(
|
||||||
"# Added by quickpassthrough #\n",
|
"# Added by quickpassthrough #\n",
|
||||||
"vfio\n",
|
fmt.Sprintf(
|
||||||
"vfio_iommu_type1\n",
|
"%s\n",
|
||||||
"vfio_pci\n",
|
strings.Join(vfio_modules(), "\n"),
|
||||||
|
),
|
||||||
|
"#############################\n",
|
||||||
),
|
),
|
||||||
conffile,
|
conffile,
|
||||||
)
|
)
|
||||||
|
|
||||||
// If we are on a kernel older than 6.2
|
|
||||||
sysinfo := uname.New()
|
|
||||||
kernel_re := regexp.MustCompile(`^(6\.1|6\.0|[1-5]\.)`)
|
|
||||||
if kernel_re.MatchString(sysinfo.Kernel) {
|
|
||||||
// Include the vfio_virqfd module
|
|
||||||
// NOTE: this driver was merged into the vfio module in 6.2
|
|
||||||
fileio.AppendContent("vfio_virqfd\n", conffile)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the footer
|
|
||||||
fileio.AppendContent("#############################", conffile)
|
|
||||||
|
|
||||||
// Scan the system file line by line
|
// Scan the system file line by line
|
||||||
scanner := bufio.NewScanner(sysfile)
|
scanner := bufio.NewScanner(sysfile)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package configs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
|
@ -21,6 +22,15 @@ func Set_Modprobe(gpu_IDs []string) {
|
||||||
vfio_pci_options = append(vfio_pci_options, "disable_vga=1")
|
vfio_pci_options = append(vfio_pci_options, "disable_vga=1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put our config file path into a string
|
||||||
|
conffile := fmt.Sprintf("%s/vfio.conf", config.Path.MODPROBE)
|
||||||
|
|
||||||
|
// If the file exists
|
||||||
|
if fileio.FileExist(conffile) {
|
||||||
|
// Delete the old file
|
||||||
|
os.Remove(conffile)
|
||||||
|
}
|
||||||
|
|
||||||
// Write the vfio.conf file to our modprobe config
|
// Write the vfio.conf file to our modprobe config
|
||||||
fileio.AppendContent(
|
fileio.AppendContent(
|
||||||
fmt.Sprint(
|
fmt.Sprint(
|
||||||
|
@ -39,9 +49,6 @@ func Set_Modprobe(gpu_IDs []string) {
|
||||||
"softdep amdgpu pre: vfio vfio_pci\n",
|
"softdep amdgpu pre: vfio vfio_pci\n",
|
||||||
"softdep radeon pre: vfio vfio_pci\n",
|
"softdep radeon pre: vfio vfio_pci\n",
|
||||||
),
|
),
|
||||||
fmt.Sprintf(
|
conffile,
|
||||||
"%s/vfio.conf",
|
|
||||||
config.Path.MODPROBE,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
|
"github.com/HikariKnight/quickpassthrough/pkg/uname"
|
||||||
"github.com/klauspost/cpuid/v2"
|
"github.com/klauspost/cpuid/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -129,7 +130,25 @@ func InitConfigs() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Generate the kernel arguments
|
|
||||||
set_Cmdline()
|
func vfio_modules() []string {
|
||||||
|
// Make the list of modules
|
||||||
|
modules := []string{
|
||||||
|
"vfio_pci",
|
||||||
|
"vfio",
|
||||||
|
"vfio_iommu_type1",
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are on a kernel older than 6.2
|
||||||
|
sysinfo := uname.New()
|
||||||
|
kernel_re := regexp.MustCompile(`^(6\.1|6\.0|[1-5]\.)`)
|
||||||
|
if kernel_re.MatchString(sysinfo.Kernel) {
|
||||||
|
// Include the vfio_virqfd module
|
||||||
|
// NOTE: this driver was merged into the vfio module in 6.2
|
||||||
|
modules = append(modules, "vfio_virqfd")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the modules
|
||||||
|
return modules
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue