-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpci-bind
executable file
·43 lines (34 loc) · 1012 Bytes
/
pci-bind
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
#!/bin/fish
if test (count $argv) -ne 2
echo 'Usage: pci-bind <driver> <pciaddr>'
exit 1
end
set req_driver $argv[1]
set pci_addr $argv[2]
set dev_paths /sys/bus/pci/devices/$pci_addr.*
function extract_error
echo (string lower (string split ': ' "$argv")[-1])
end
function unbind
for dev in $dev_paths
if test -e $dev/driver
echo (basename $dev) | tee $dev/driver/unbind > /dev/null 2>| read output
if test -n "$output"
echo "$dev: error unbinding" (extract_error "$output")
end
else
echo "$dev: already unbound"
end
end
end
function bind
for dev in $dev_paths
echo (basename $dev) | tee /sys/bus/pci/drivers/$req_driver/bind > /dev/null 2>| read output
if test -n "$output"
set error_message (string split ': ' "$output")[-1]
echo "$dev: error binding" (extract_error "$output")
end
end
end
unbind $dev_paths
bind $req_driver $dev_paths