| 1 | |
| 2 | set -e
|
| 3 |
|
| 4 | source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
|
| 5 |
|
| 6 | function main() {
|
| 7 | local device_bdf
|
| 8 | local device_dir
|
| 9 | local numvfs
|
| 10 | local driver
|
| 11 |
|
| 12 | if [ $# = 0 ]; then
|
| 13 | echo "usage: $0 segment:bus:device.function ..." >&2
|
| 14 | exit 1
|
| 15 | fi
|
| 16 |
|
| 17 | for device_bdf in "$@"; do
|
| 18 | test -d /sys/bus/pci/devices/${device_bdf}
|
| 19 |
|
| 20 | device_dir=${DEVICES_DIR}/${device_bdf}
|
| 21 | if [ -d "${device_dir}" ]; then
|
| 22 | echo "${device_bdf} has already been set up, exiting."
|
| 23 | exit 0
|
| 24 | fi
|
| 25 |
|
| 26 | mkdir -p ${device_dir}
|
| 27 |
|
| 28 | numvfs=$(get_sriov_numvfs ${device_bdf})
|
| 29 | if [ "${numvfs}" ]; then
|
| 30 | set_sriov_numvfs ${device_bdf} 0
|
| 31 | echo ${numvfs} > ${device_dir}/sriov_numvfs
|
| 32 | fi
|
| 33 |
|
| 34 | driver=$(get_driver ${device_bdf})
|
| 35 | if [ "${driver}" ]; then
|
| 36 | unbind ${device_bdf} ${driver}
|
| 37 | echo ${driver} > ${device_dir}/driver
|
| 38 | fi
|
| 39 |
|
| 40 | set_driver_override ${device_bdf} vfio-pci
|
| 41 | touch ${device_dir}/driver_override
|
| 42 |
|
| 43 | bind ${device_bdf} vfio-pci
|
| 44 | touch ${device_dir}/vfio-pci
|
| 45 | done
|
| 46 | }
|
| 47 |
|
| 48 | main "$@"
|