Skip to content

Commit

Permalink
Add support to print the path to the GPU vbios
Browse files Browse the repository at this point in the history
  • Loading branch information
HikariKnight committed Mar 16, 2023
1 parent 9323125 commit 5c28797
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/iommu/iommu.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func MatchSubclass(searchval string, pArg *params.Params) []string {
for _, device := range alldevs.Groups[id].Devices {
// If the device has a subclass matching what we are looking for
if strings.Contains(device.Subclass.Name, searchval) {
if len(pArg.IntList["iommu_group"]) == 0 {
if len(pArg.IntList["iommu_group"]) == 0 && !pArg.Flag["rom"] {
// Generate the device list with the data we want
line := generateDevList(id, device, pArg)
devs = append(devs, line)
Expand All @@ -158,6 +158,21 @@ func MatchSubclass(searchval string, pArg *params.Params) []string {
other := GetDevicesFromGroups([]int{id}, 0, pArg)
devs = append(devs, other...)
}
} else if pArg.Flag["rom"] && pArg.Flag["gpu"] {
// If we are asked to get the path to the gpu vbios
if len(pArg.IntList["iommu_group"]) > 0 {
// If we are asked to only get a specific IOMMU group
for _, group := range pArg.IntList["iommu_group"] {
// If the iommu group matches the one we are currently processing
if id == group {
// Print the GPU rom path
devs = append(devs, GetRomPath(device, pArg)...)
}
}
} else {
// Else get the vbios path for any gpu
devs = append(devs, GetRomPath(device, pArg)...)
}
} else {
for _, group := range pArg.IntList["iommu_group"] {
if id == group {
Expand Down
33 changes: 33 additions & 0 deletions lib/iommu/rom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package iommu

import (
"fmt"
"io/fs"
"path/filepath"
"strings"

"github.com/HikariKnight/ls-iommu/lib/params"
"github.com/jaypipes/ghw/pkg/pci"
)

// Function to get the vbios path for a device
func GetRomPath(device *pci.Device, pArg *params.Params) []string {
// Make a string slice to contain our paths
var roms []string

// Walk through /sys/devices/ and add all paths that has a rom file and matches the device.Address to the roms variable
err := filepath.Walk("/sys/devices/", func(path string, info fs.FileInfo, err error) error {
ErrorCheck(err)

// If the file name is "rom" and the path contains the PCI address for our device
if info.Name() == "rom" && strings.Contains(path, device.Address) {
// Add the filepath to our roms variable
roms = append(roms, fmt.Sprintf("%s\n", path))
}
return nil
})
ErrorCheck(err)

// Return all found rom files
return roms
}
6 changes: 6 additions & 0 deletions lib/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func NewParams() *Params {
Help: "Print out only the PCI Address for non bridge devices (Only works with -i)",
})

rom := parser.Flag("", "rom", &argparse.Options{
Required: false,
Help: "Print out the rom path GPUs. (must be used with -g or --gpu)",
})

// Parse arguments
err := parser.Parse(os.Args)
if err != nil {
Expand Down Expand Up @@ -123,6 +128,7 @@ func NewParams() *Params {
pArg.addFlag("legacyoutput", *legacyoutput)
pArg.addFlag("id", *id)
pArg.addFlag("pciaddr", *pciaddr)
pArg.addFlag("rom", *rom)

return pArg
}

0 comments on commit 5c28797

Please sign in to comment.