| 1 | |
| 2 |
|
| 3 | readonly DEVICES_DIR="${TMPDIR:-/tmp}/vfio-selftests-devices"
|
| 4 |
|
| 5 | function write_to() {
|
| 6 | |
| 7 | |
| 8 | echo "+ echo \"${2}\" > ${1}"
|
| 9 | echo "${2}" > ${1}
|
| 10 | }
|
| 11 |
|
| 12 | function 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 |
|
| 18 | function bind() {
|
| 19 | write_to /sys/bus/pci/drivers/${2}/bind ${1}
|
| 20 | }
|
| 21 |
|
| 22 | function unbind() {
|
| 23 | write_to /sys/bus/pci/drivers/${2}/unbind ${1}
|
| 24 | }
|
| 25 |
|
| 26 | function set_sriov_numvfs() {
|
| 27 | write_to /sys/bus/pci/devices/${1}/sriov_numvfs ${2}
|
| 28 | }
|
| 29 |
|
| 30 | function 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 |
|
| 36 | function set_driver_override() {
|
| 37 | write_to /sys/bus/pci/devices/${1}/driver_override ${2}
|
| 38 | }
|
| 39 |
|
| 40 | function clear_driver_override() {
|
| 41 | set_driver_override ${1} ""
|
| 42 | }
|