lib.sh 964 B

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