drm/i915/gvt: allow several MPT methods to be NULL
authorJike Song <jike.song@intel.com>
Thu, 3 Nov 2016 10:38:34 +0000 (18:38 +0800)
committerZhenyu Wang <zhenyuw@linux.intel.com>
Thu, 10 Nov 2016 07:45:14 +0000 (15:45 +0800)
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 <jike.song@intel.com>
Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
drivers/gpu/drm/i915/gvt/mpt.h

index 93649b3..1af5830 100644 (file)
@@ -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);
 }