refactor and start adding actual functionality

This commit is contained in:
HikariKnight 2023-11-02 16:45:50 +01:00
parent 9efa0ee226
commit 82fec3ab58
11 changed files with 158 additions and 33 deletions

View file

@ -63,7 +63,7 @@ func GenerateVBIOSDumper(vbios_path string) {
errorcheck.ErrorCheck(err, "Could not change permissions of \"utils/dump_vbios.sh\"") errorcheck.ErrorCheck(err, "Could not change permissions of \"utils/dump_vbios.sh\"")
// Write to logger // Write to logger
logger.Printf("Writing utils/dump_vbios.sh") logger.Printf("Writing utils/dump_vbios.sh\n")
// Write the script // Write the script
scriptfile.WriteString(vbios_script) scriptfile.WriteString(vbios_script)

View file

@ -17,7 +17,7 @@ func DisableVFIOVideo(i int) {
config := GetConfig() config := GetConfig()
// Write to logger // Write to logger
logger.Printf("Adding vfio_pci.disable_vga=%v to %s", i, config.Path.CMDLINE) logger.Printf("Adding vfio_pci.disable_vga=%v to %s\n", i, config.Path.CMDLINE)
// Get the current kernel arguments we have generated // Get the current kernel arguments we have generated
kernel_args := fileio.ReadFile(config.Path.CMDLINE) kernel_args := fileio.ReadFile(config.Path.CMDLINE)

View file

@ -28,6 +28,8 @@ type Config struct {
Bootloader string Bootloader string
Cpuvendor string Cpuvendor string
Path *Path Path *Path
Gpu_Group string
Gpu_IDs []string
} }
// Gets the path to all the config files // Gets the path to all the config files
@ -52,6 +54,8 @@ func GetConfig() *Config {
Bootloader: "unknown", Bootloader: "unknown",
Cpuvendor: cpuid.CPU.VendorString, Cpuvendor: cpuid.CPU.VendorString,
Path: GetConfigPaths(), Path: GetConfigPaths(),
Gpu_Group: "",
Gpu_IDs: []string{},
} }
// Detect the bootloader we are using // Detect the bootloader we are using

View file

@ -39,7 +39,8 @@ func Welcome() {
// If yes, go to next page // If yes, go to next page
if choice == "y" { if choice == "y" {
configs.InitConfigs() configs.InitConfigs()
SelectGPU() config := configs.GetConfig()
SelectGPU(config)
} else { } else {
fmt.Println("") fmt.Println("")
os.Exit(0) os.Exit(0)

View file

@ -4,13 +4,16 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
"github.com/HikariKnight/quickpassthrough/internal/configs"
lsiommu "github.com/HikariKnight/quickpassthrough/internal/lsiommu" lsiommu "github.com/HikariKnight/quickpassthrough/internal/lsiommu"
"github.com/HikariKnight/quickpassthrough/pkg/command" "github.com/HikariKnight/quickpassthrough/pkg/command"
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
"github.com/HikariKnight/quickpassthrough/pkg/menu" "github.com/HikariKnight/quickpassthrough/pkg/menu"
"github.com/gookit/color" "github.com/gookit/color"
) )
func SelectGPU() { func SelectGPU(config *configs.Config) {
// Clear the screen // Clear the screen
command.Clear() command.Clear()
@ -29,11 +32,12 @@ func SelectGPU() {
fmt.Println("") fmt.Println("")
os.Exit(0) os.Exit(0)
default: default:
viewGPU(choice) config.Gpu_Group = choice
viewGPU(config)
} }
} }
func viewGPU(id string, ext ...int) { func viewGPU(config *configs.Config, ext ...int) {
// Clear the screen // Clear the screen
command.Clear() command.Clear()
@ -46,10 +50,10 @@ func viewGPU(id string, ext ...int) {
} }
// Get the IOMMU listings for GPUs // Get the IOMMU listings for GPUs
group := lsiommu.GetIOMMU("-g", mode, "-i", id, "-F", "vendor:,prod_name,optional_revision:,device_id") group := lsiommu.GetIOMMU("-g", mode, "-i", config.Gpu_Group, "-F", "vendor:,prod_name,optional_revision:,device_id")
// Write a title // Write a title
color.Bold.Println("This list should only show devices related to your GPU") color.Bold.Println("This list should only show devices related to your GPU (usually 1 video, 1 audio device)")
// Print all the gpus // Print all the gpus
for _, v := range group { for _, v := range group {
@ -64,7 +68,7 @@ func viewGPU(id string, ext ...int) {
// Change choices depending on if we have done an extended search or not // Change choices depending on if we have done an extended search or not
if len(ext) > 0 { if len(ext) > 0 {
choice = menu.YesNo("Use this GPU (any extra devices listed may or may not be linked to it) for passthrough?") choice = menu.YesNoManual("Use this GPU (any extra devices listed may or may not be linked to it) for passthrough?")
} else { } else {
choice = menu.YesNoEXT("Use this GPU (and related devices) for passthrough?") choice = menu.YesNoEXT("Use this GPU (and related devices) for passthrough?")
} }
@ -78,15 +82,47 @@ func viewGPU(id string, ext ...int) {
case "ext": case "ext":
// Run an extended relative search // Run an extended relative search
viewGPU(id, 1) viewGPU(config, 1)
case "n": case "n":
// Go back to selecting a gpu // Go back to selecting a gpu
SelectGPU() SelectGPU(config)
case "y": case "y":
// Go to the select a usb controller // Get the device ids for the selected gpu using ls-iommu
//selectUSB() config.Gpu_IDs = lsiommu.GetIOMMU("-g", mode, "-i", config.Gpu_Group, "--id")
genVBIOS_dumper(id)
// If the kernel_args file already exists
if fileio.FileExist(config.Path.CMDLINE) {
// Delete it as we will have to make a new one anyway
err := os.Remove(config.Path.CMDLINE)
errorcheck.ErrorCheck(err, fmt.Sprintf("Could not remove %s", config.Path.CMDLINE))
}
// Write initial kernel_arg file
configs.Set_Cmdline(config.Gpu_IDs)
// Go to the vbios dumper page
genVBIOS_dumper(config)
case "manual":
config.Gpu_IDs = menu.ManualInput(
"Please manually enter the vendorID:deviceID for every device to use except PCI Express Switches\n"+
"NOTE: All devices sharing the same IOMMU group will still get pulled into the VM!",
"xxxx:yyyy,xxxx:yyyy,xxxx:yyyy",
)
// If the kernel_args file already exists
if fileio.FileExist(config.Path.CMDLINE) {
// Delete it as we will have to make a new one anyway
err := os.Remove(config.Path.CMDLINE)
errorcheck.ErrorCheck(err, fmt.Sprintf("Could not remove %s", config.Path.CMDLINE))
}
// Write initial kernel_arg file
configs.Set_Cmdline(config.Gpu_IDs)
// Go to the vbios dumper page
genVBIOS_dumper(config)
} }
} }

View file

@ -6,11 +6,13 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/HikariKnight/quickpassthrough/internal/configs"
lsiommu "github.com/HikariKnight/quickpassthrough/internal/lsiommu"
"github.com/HikariKnight/quickpassthrough/pkg/command" "github.com/HikariKnight/quickpassthrough/pkg/command"
"github.com/HikariKnight/quickpassthrough/pkg/menu" "github.com/HikariKnight/quickpassthrough/pkg/menu"
) )
func genVBIOS_dumper(id string) { func genVBIOS_dumper(config *configs.Config) {
// Clear the scren // Clear the scren
command.Clear() command.Clear()
@ -23,8 +25,9 @@ func genVBIOS_dumper(id string) {
scriptdir, _ = os.Getwd() scriptdir, _ = os.Getwd()
} }
// Get the vbios path // Get the vbios path and generate the vbios dumping script
//vbios_path := lsiommu.GetIOMMU("-g", "-i", id, "--rom")[0] vbios_path := lsiommu.GetIOMMU("-g", "-i", config.Gpu_Group, "--rom")[0]
configs.GenerateVBIOSDumper(vbios_path)
// Tell users about the VBIOS dumper script // Tell users about the VBIOS dumper script
fmt.Print( fmt.Print(
@ -38,13 +41,17 @@ func genVBIOS_dumper(id string) {
) )
// Get the OK press // Get the OK press
choice := menu.Ok("Make sure you run the script with the display-manager stopped using ssh or tty!") choice := menu.OkBack("Make sure you run the script with the display-manager stopped using ssh or tty!")
// If OK is pressed // Parse choice
if choice == "next" { switch choice {
disableVideo() case "next":
selectUSB() disableVideo(config)
} else {
case "back":
SelectGPU(config)
case "":
fmt.Println("") fmt.Println("")
os.Exit(0) os.Exit(0)
} }

View file

@ -2,13 +2,14 @@ package pages
import ( import (
"fmt" "fmt"
"os"
"github.com/HikariKnight/quickpassthrough/internal/configs" "github.com/HikariKnight/quickpassthrough/internal/configs"
"github.com/HikariKnight/quickpassthrough/pkg/command" "github.com/HikariKnight/quickpassthrough/pkg/command"
"github.com/HikariKnight/quickpassthrough/pkg/menu" "github.com/HikariKnight/quickpassthrough/pkg/menu"
) )
func disableVideo() { func disableVideo(config *configs.Config) {
// Clear the screen // Clear the screen
command.Clear() command.Clear()
@ -22,14 +23,25 @@ func disableVideo() {
) )
// Make the yesno menu // Make the yesno menu
choice := menu.YesNo("Do you want to force disable video output in linux on this card?") choice := menu.YesNoBack("Do you want to force disable video output in linux on this card?")
if choice == "Yes" { switch choice {
case "y":
// Add disable VFIO video to the config // Add disable VFIO video to the config
configs.DisableVFIOVideo(1) configs.DisableVFIOVideo(1)
} else { selectUSB(config)
case "n":
// Do not disable VFIO Video // Do not disable VFIO Video
configs.DisableVFIOVideo(0) configs.DisableVFIOVideo(0)
} selectUSB(config)
case "back":
genVBIOS_dumper(config)
case "":
// If ESC is pressed
fmt.Println("")
os.Exit(0)
}
} }

View file

@ -4,13 +4,14 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/HikariKnight/quickpassthrough/internal/configs"
lsiommu "github.com/HikariKnight/quickpassthrough/internal/lsiommu" lsiommu "github.com/HikariKnight/quickpassthrough/internal/lsiommu"
"github.com/HikariKnight/quickpassthrough/pkg/command" "github.com/HikariKnight/quickpassthrough/pkg/command"
"github.com/HikariKnight/quickpassthrough/pkg/menu" "github.com/HikariKnight/quickpassthrough/pkg/menu"
"github.com/gookit/color" "github.com/gookit/color"
) )
func selectUSB() { func selectUSB(config *configs.Config) {
// Clear the screen // Clear the screen
command.Clear() command.Clear()
@ -23,18 +24,20 @@ func selectUSB() {
// Parse the choice // Parse the choice
switch choice { switch choice {
case "back": case "back":
SelectGPU() disableVideo(config)
case "": case "":
// If ESC is pressed // If ESC is pressed
fmt.Println("") fmt.Println("")
os.Exit(0) os.Exit(0)
default: default:
// View the selected GPU // View the selected GPU
viewUSB(choice) viewUSB(choice, config)
} }
} }
func viewUSB(id string, ext ...int) { func viewUSB(id string, config *configs.Config, ext ...int) {
// Clear the screen // Clear the screen
command.Clear() command.Clear()
@ -76,9 +79,10 @@ func viewUSB(id string, ext ...int) {
// If ESC is pressed // If ESC is pressed
fmt.Println("") fmt.Println("")
os.Exit(0) os.Exit(0)
case "n": case "n":
// Go back to selecting a gpu // Go back to selecting a gpu
selectUSB() selectUSB(config)
case "y": case "y":
// Go to the select a usb controller // Go to the select a usb controller

View file

@ -0,0 +1,5 @@
package pages
func finalize() {
}

27
pkg/menu/manual.go Normal file
View file

@ -0,0 +1,27 @@
package menu
import (
"fmt"
"strings"
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
"github.com/gookit/color"
)
func ManualInput(msg string, format string) []string {
// Print the title
color.Bold.Println(msg)
// Tell user the format to use
color.Bold.Printf("The format is %s\n", format)
// Get the user input
var input string
_, err := fmt.Scan(&input)
errorcheck.ErrorCheck(err)
input_list := strings.Split(input, ",")
// Return the input
return input_list
}

View file

@ -16,6 +16,20 @@ func YesNo(msg string) string {
return choice return choice
} }
func YesNoBack(msg string) string {
// Make the menu
menu := gocliselect.NewMenu(msg)
menu.AddItem("Yes", "y")
menu.AddItem("No", "n")
menu.AddItem("Go Back", "back")
// Display the menu
choice := menu.Display()
// Return the value selected
return choice
}
func YesNoEXT(msg string) string { func YesNoEXT(msg string) string {
// Make the menu // Make the menu
menu := gocliselect.NewMenu(msg) menu := gocliselect.NewMenu(msg)
@ -29,3 +43,18 @@ func YesNoEXT(msg string) string {
// Return the value selected // Return the value selected
return choice return choice
} }
// Make a YesNo menu
func YesNoManual(msg string) string {
// Make the menu
menu := gocliselect.NewMenu(msg)
menu.AddItem("Yes", "y")
menu.AddItem("No", "n")
menu.AddItem("Manual Entry", "manual")
// Display the menu
choice := menu.Display()
// Return the value selected
return choice
}