162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci===================
462306a36Sopenharmony_ciVFIO virtual device
562306a36Sopenharmony_ci===================
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciDevice types supported:
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci  - KVM_DEV_TYPE_VFIO
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciOnly one VFIO instance may be created per VM.  The created device
1262306a36Sopenharmony_citracks VFIO files (group or device) in use by the VM and features
1362306a36Sopenharmony_ciof those groups/devices important to the correctness and acceleration
1462306a36Sopenharmony_ciof the VM.  As groups/devices are enabled and disabled for use by the
1562306a36Sopenharmony_ciVM, KVM should be updated about their presence.  When registered with
1662306a36Sopenharmony_ciKVM, a reference to the VFIO file is held by KVM.
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciGroups:
1962306a36Sopenharmony_ci  KVM_DEV_VFIO_FILE
2062306a36Sopenharmony_ci	alias: KVM_DEV_VFIO_GROUP
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciKVM_DEV_VFIO_FILE attributes:
2362306a36Sopenharmony_ci  KVM_DEV_VFIO_FILE_ADD: Add a VFIO file (group/device) to VFIO-KVM device
2462306a36Sopenharmony_ci	tracking
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci	kvm_device_attr.addr points to an int32_t file descriptor for the
2762306a36Sopenharmony_ci	VFIO file.
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci  KVM_DEV_VFIO_FILE_DEL: Remove a VFIO file (group/device) from VFIO-KVM
3062306a36Sopenharmony_ci	device tracking
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci	kvm_device_attr.addr points to an int32_t file descriptor for the
3362306a36Sopenharmony_ci	VFIO file.
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciKVM_DEV_VFIO_GROUP (legacy kvm device group restricted to the handling of VFIO group fd):
3662306a36Sopenharmony_ci  KVM_DEV_VFIO_GROUP_ADD: same as KVM_DEV_VFIO_FILE_ADD for group fd only
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci  KVM_DEV_VFIO_GROUP_DEL: same as KVM_DEV_VFIO_FILE_DEL for group fd only
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci  KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE: attaches a guest visible TCE table
4162306a36Sopenharmony_ci	allocated by sPAPR KVM.
4262306a36Sopenharmony_ci	kvm_device_attr.addr points to a struct::
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci		struct kvm_vfio_spapr_tce {
4562306a36Sopenharmony_ci			__s32	groupfd;
4662306a36Sopenharmony_ci			__s32	tablefd;
4762306a36Sopenharmony_ci		};
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	where:
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	- @groupfd is a file descriptor for a VFIO group;
5262306a36Sopenharmony_ci	- @tablefd is a file descriptor for a TCE table allocated via
5362306a36Sopenharmony_ci	  KVM_CREATE_SPAPR_TCE.
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciThe FILE/GROUP_ADD operation above should be invoked prior to accessing the
5662306a36Sopenharmony_cidevice file descriptor via VFIO_GROUP_GET_DEVICE_FD in order to support
5762306a36Sopenharmony_cidrivers which require a kvm pointer to be set in their .open_device()
5862306a36Sopenharmony_cicallback.  It is the same for device file descriptor via character device
5962306a36Sopenharmony_ciopen which gets device access via VFIO_DEVICE_BIND_IOMMUFD.  For such file
6062306a36Sopenharmony_cidescriptors, FILE_ADD should be invoked before VFIO_DEVICE_BIND_IOMMUFD
6162306a36Sopenharmony_cito support the drivers mentioned in prior sentence as well.
62