Repository navigation
Expand file tree
/
Copy path004-add-pxvirt-pciprobe-and-pcitool-and-show-driver-in-lspci.patch
More file actions
99 lines (93 loc) · 3.11 KB
/
Copy path004-add-pxvirt-pciprobe-and-pcitool-and-show-driver-in-lspci.patch
File metadata and controls
99 lines (93 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
diff --git a/src/PVE/SysFSTools.pm b/src/PVE/SysFSTools.pm
index cf9854b..669d2ed 100644
--- a/src/PVE/SysFSTools.pm
+++ b/src/PVE/SysFSTools.pm
@@ -4,6 +4,8 @@ use strict;
use warnings;
use IO::File;
+use File::Basename;
+use Cwd 'realpath';
use PVE::Tools qw(file_read_firstline dir_glob_foreach);
@@ -91,6 +93,8 @@ sub lspci {
my $vendor = file_read_firstline("$devdir/vendor");
my $device = file_read_firstline("$devdir/device");
my $class = file_read_firstline("$devdir/class");
+ my $driver_inuse = basename(realpath("$devdir/driver"));
+
my $res = {
id => $id,
@@ -134,6 +138,7 @@ sub lspci {
$res->{subsystem_device} = $sub_device if defined($sub_device);
$res->{subsystem_vendor_name} = $sub_vendor_name if defined($sub_vendor_name);
$res->{subsystem_device_name} = $sub_device_name if defined($sub_device_name);
+ $res->{driver_inuse} = $driver_inuse;
}
push @$devices, $res;
@@ -461,4 +466,68 @@ sub scan_usb {
return $devlist;
}
+sub pcitool {
+ my ($pciid,$options,$driver) = @_;
+
+ my $basedir = "$pcisysfs/devices/$pciid";
+
+ die "Cannot find $pciid device!\n" if ! -d $basedir;
+
+ if ( $options eq 'bind' ){
+ if (!defined $driver) {
+ $driver = 'vfio-pci';
+ }
+ if (! -d "/sys/bus/pci/drivers/$driver") {
+ system("/bin/modprobe $driver >/dev/null 2>/dev/null");
+ }
+ die "Cannot find $driver module!\n" if ! -d "/sys/bus/pci/drivers/$driver";
+ die "Cannot bind $driver when device is bind\n" if -d "/sys/bus/pci/device/$pciid/driver";
+ file_write("/sys/bus/pci/drivers/$driver/bind",$pciid);
+ } elsif ( $options eq 'unbind' ){
+ file_write("$basedir/driver/unbind",$pciid);
+ } elsif ( $options eq 'reset' ){
+ file_write("$basedir/remove","1");
+ if ( -f "/sys/bus/pci/device/$pciid/reset" ){
+ file_write("/sys/bus/pci/device/$pciid/reset","1");
+ }else{
+ file_write("/sys/bus/pci/rescan","1");
+ }
+ }
+}
+
+sub pciprobe {
+ my ($pciid,$blacklist,$driver,$clean) = @_;
+
+ $blacklist = 0 if ! defined $blacklist;
+
+ my $basedir = "/etc/modules-load.d/";
+ my $blacklistdir = "/etc/modprobe.d/";
+
+ die "OS ERROR!\n" if ! -d $basedir;
+ die "OS ERROR!\n" if ! -d $blacklistdir;
+
+ if (defined $clean && $clean ){
+ system("rm -rf $blacklistdir/$pciid*.conf");
+ system("rm -rf $basedir/$pciid*.conf");
+ return "ok";
+ }
+
+ if (! $blacklist ) {
+
+ if (! -d "/sys/bus/pci/drivers/$driver") {
+ system("/bin/modprobe $driver >/dev/null 2>/dev/null");
+ }
+ die "Cannot find $driver module!\n" if ! -d "/sys/bus/pci/drivers/$driver";
+ system("rm $basedir/$pciid.conf") if -f "$basedir/$pciid.conf";
+ my $str = "options vfio-pci ids=$pciid";
+ file_write("$basedir/$pciid.conf",$str);
+ } else {
+ system("rm $blacklistdir/$pciid-$driver-blacklist.conf") if -f "$blacklistdir/$pciid-$driver-blacklist.conf";
+ my $str = "blacklist $driver";
+ file_write("/etc/modprobe.d/$pciid-$driver-blacklist.conf",$str);
+ }
+
+}
+
+
1;