]> git.proxmox.com Git - pve-common.git/commitdiff
SysFSTools: add verbose flag to pci_device_info
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 21 Jun 2021 13:55:15 +0000 (15:55 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 21 Jun 2021 15:24:06 +0000 (17:24 +0200)
to also get the subsystem_vendor and device, as well as the
iommu group and mediated device support

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/SysFSTools.pm

index a8d9a7f0e24fc3fd014c140b594d7d5da982128f..7875b269bb40fb720766ddb8e2585c7c308aee2f 100644 (file)
@@ -197,20 +197,22 @@ sub file_write {
 }
 
 sub pci_device_info {
-    my ($name) = @_;
+    my ($name, $verbose) = @_;
 
     my $res;
 
     return undef if $name !~ m/^${pciregex}$/;
     my ($domain, $bus, $slot, $func) = ($1, $2, $3, $4);
 
-    my $irq = file_read_firstline("$pcisysfs/devices/$name/irq");
+    my $devdir = "$pcisysfs/devices/$name";
+
+    my $irq = file_read_firstline("$devdir/irq");
     return undef if !defined($irq) || $irq !~ m/^\d+$/;
 
-    my $vendor = file_read_firstline("$pcisysfs/devices/$name/vendor");
+    my $vendor = file_read_firstline("$devdir/vendor");
     return undef if !defined($vendor) || $vendor !~ s/^0x//;
 
-    my $product = file_read_firstline("$pcisysfs/devices/$name/device");
+    my $product = file_read_firstline("$devdir/device");
     return undef if !defined($product) || $product !~ s/^0x//;
 
     $res = {
@@ -225,6 +227,25 @@ sub pci_device_info {
        has_fl_reset => -f "$pcisysfs/devices/$name/reset" || 0,
     };
 
+    if ($verbose) {
+       my $sub_vendor = file_read_firstline("$devdir/subsystem_vendor");
+       $sub_vendor =~ s/^0x// if defined($sub_vendor);
+       my $sub_device = file_read_firstline("$devdir/subsystem_device");
+       $sub_device =~ s/^0x// if defined($sub_device);
+
+       $res->{subsystem_vendor} = $sub_vendor if defined($sub_vendor);
+       $res->{subsystem_device} = $sub_device if defined($sub_device);
+
+       if (-e "$devdir/iommu_group") {
+           my ($iommugroup) = (readlink("$devdir/iommu_group") =~ m/\/(\d+)$/);
+           $res->{iommugroup} = int($iommugroup);
+       }
+
+       if (-d "$devdir/mdev_supported_types") {
+           $res->{mdev} = 1;
+       }
+    }
+
     return $res;
 }