From 7b3343b7e804bb89ad24a0a8c4e8e1010a418f14 Mon Sep 17 00:00:00 2001 From: Jike Song Date: Thu, 3 Nov 2016 18:38:34 +0800 Subject: [PATCH] drm/i915/gvt: allow several MPT methods to be NULL Hypervisors are different, the MPT ops is a only superset of all possibly supported hypervisors. There might be other way out of the MPT to achieve same target. e.g. vfio-based kvmgt won't provide map_gfn_to_mfn method to establish guest EPT mapping for aperture, since it will be done in QEMU/KVM, MMIO is also trapped elsewhere, etc. Signed-off-by: Jike Song Signed-off-by: Zhenyu Wang --- drivers/gpu/drm/i915/gvt/mpt.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/gpu/drm/i915/gvt/mpt.h b/drivers/gpu/drm/i915/gvt/mpt.h index 93649b34798b..1af5830c0a56 100644 --- a/drivers/gpu/drm/i915/gvt/mpt.h +++ b/drivers/gpu/drm/i915/gvt/mpt.h @@ -64,6 +64,10 @@ static inline int intel_gvt_hypervisor_detect_host(void) static inline int intel_gvt_hypervisor_host_init(struct device *dev, void *gvt, const void *ops) { + /* optional to provide */ + if (!intel_gvt_host.mpt->host_init) + return 0; + return intel_gvt_host.mpt->host_init(dev, gvt, ops); } @@ -73,6 +77,10 @@ static inline int intel_gvt_hypervisor_host_init(struct device *dev, static inline void intel_gvt_hypervisor_host_exit(struct device *dev, void *gvt) { + /* optional to provide */ + if (!intel_gvt_host.mpt->host_exit) + return; + intel_gvt_host.mpt->host_exit(dev, gvt); } @@ -85,6 +93,10 @@ static inline void intel_gvt_hypervisor_host_exit(struct device *dev, */ static inline int intel_gvt_hypervisor_attach_vgpu(struct intel_vgpu *vgpu) { + /* optional to provide */ + if (!intel_gvt_host.mpt->attach_vgpu) + return 0; + return intel_gvt_host.mpt->attach_vgpu(vgpu, &vgpu->handle); } @@ -97,6 +109,10 @@ static inline int intel_gvt_hypervisor_attach_vgpu(struct intel_vgpu *vgpu) */ static inline void intel_gvt_hypervisor_detach_vgpu(struct intel_vgpu *vgpu) { + /* optional to provide */ + if (!intel_gvt_host.mpt->detach_vgpu) + return; + intel_gvt_host.mpt->detach_vgpu(vgpu->handle); } @@ -261,6 +277,10 @@ static inline int intel_gvt_hypervisor_map_gfn_to_mfn( unsigned long mfn, unsigned int nr, bool map) { + /* a MPT implementation could have MMIO mapped elsewhere */ + if (!intel_gvt_host.mpt->map_gfn_to_mfn) + return 0; + return intel_gvt_host.mpt->map_gfn_to_mfn(vgpu->handle, gfn, mfn, nr, map); } @@ -278,6 +298,10 @@ static inline int intel_gvt_hypervisor_map_gfn_to_mfn( static inline int intel_gvt_hypervisor_set_trap_area( struct intel_vgpu *vgpu, u64 start, u64 end, bool map) { + /* a MPT implementation could have MMIO trapped elsewhere */ + if (!intel_gvt_host.mpt->set_trap_area) + return 0; + return intel_gvt_host.mpt->set_trap_area(vgpu->handle, start, end, map); } -- 2.30.2