Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1# SPDX-License-Identifier: GPL-2.0-or-later
2
3readonly DEVICES_DIR="${TMPDIR:-/tmp}/vfio-selftests-devices"
4
5function write_to() {
6 # Unfortunately set -x does not show redirects so use echo to manually
7 # tell the user what commands are being run.
8 echo "+ echo \"${2}\" > ${1}"
9 echo "${2}" > ${1}
10}
11
12function get_driver() {
13 if [ -L /sys/bus/pci/devices/${1}/driver ]; then
14 basename $(readlink -m /sys/bus/pci/devices/${1}/driver)
15 fi
16}
17
18function bind() {
19 write_to /sys/bus/pci/drivers/${2}/bind ${1}
20}
21
22function unbind() {
23 write_to /sys/bus/pci/drivers/${2}/unbind ${1}
24}
25
26function set_sriov_numvfs() {
27 write_to /sys/bus/pci/devices/${1}/sriov_numvfs ${2}
28}
29
30function get_sriov_numvfs() {
31 if [ -f /sys/bus/pci/devices/${1}/sriov_numvfs ]; then
32 cat /sys/bus/pci/devices/${1}/sriov_numvfs
33 fi
34}
35
36function set_driver_override() {
37 write_to /sys/bus/pci/devices/${1}/driver_override ${2}
38}
39
40function clear_driver_override() {
41 set_driver_override ${1} ""
42}