[v3] drm/i915/gvt: Deliver guest cursor hotspot info

Submitted by Zhang, Tina on April 16, 2018, 3:45 a.m.

Details

Message ID 1523850328-6044-1-git-send-email-tina.zhang@intel.com
State New
Headers show
Series "drm/i915/gvt: Deliver guest cursor hotspot info" ( rev: 2 ) in Intel GVT devel

Not browsing as part of any series.

Commit Message

Zhang, Tina April 16, 2018, 3:45 a.m.
Guest OS driver uses PV info registers to deliver cursor hotspot info
to host. This patch is used to get cursor hotspot info from virtual
registers and deliver it to host userspace.

v2->v3:
- add validate_hotspot(). (Zhenyu)

v1->v2:
- name as cursor_x_hot/cursor_y_hot. (Zhenyu)
- use i915_reg_t definition instead of magic numbers. (Zhenyu)

Signed-off-by: Tina Zhang <tina.zhang@intel.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/i915/gvt/dmabuf.c     | 19 +++++++++++++------
 drivers/gpu/drm/i915/gvt/fb_decoder.c |  3 +++
 drivers/gpu/drm/i915/gvt/handlers.c   |  4 ++--
 drivers/gpu/drm/i915/gvt/vgpu.c       |  3 +++
 drivers/gpu/drm/i915/i915_pvinfo.h    |  5 ++++-
 5 files changed, 25 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 6f4f8e9..46be026 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -192,6 +192,14 @@  static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev,
 	return obj;
 }
 
+static bool validate_hotspot(struct intel_vgpu_cursor_plane_format *c)
+{
+	if (c && (c->x_hot <= c->width) && (c->y_hot <= c->height))
+		return true;
+	else
+		return false;
+}
+
 static int vgpu_get_plane_info(struct drm_device *dev,
 		struct intel_vgpu *vgpu,
 		struct intel_vgpu_fb_info *info,
@@ -229,12 +237,11 @@  static int vgpu_get_plane_info(struct drm_device *dev,
 		info->x_pos = c.x_pos;
 		info->y_pos = c.y_pos;
 
-		/* The invalid cursor hotspot value is delivered to host
-		 * until we find a way to get the cursor hotspot info of
-		 * guest OS.
-		 */
-		info->x_hot = UINT_MAX;
-		info->y_hot = UINT_MAX;
+		if (validate_hotspot(&c)) {
+			info->x_hot = c.x_hot;
+			info->y_hot = c.y_hot;
+		}
+
 		info->size = (((info->stride * c.height * c.bpp) / 8)
 				+ (PAGE_SIZE - 1)) >> PAGE_SHIFT;
 	} else {
diff --git a/drivers/gpu/drm/i915/gvt/fb_decoder.c b/drivers/gpu/drm/i915/gvt/fb_decoder.c
index 1c12068..5e7468b 100644
--- a/drivers/gpu/drm/i915/gvt/fb_decoder.c
+++ b/drivers/gpu/drm/i915/gvt/fb_decoder.c
@@ -36,6 +36,7 @@ 
 #include <uapi/drm/drm_fourcc.h>
 #include "i915_drv.h"
 #include "gvt.h"
+#include "i915_pvinfo.h"
 
 #define PRIMARY_FORMAT_NUM	16
 struct pixel_format {
@@ -384,6 +385,8 @@  int intel_vgpu_decode_cursor_plane(struct intel_vgpu *vgpu,
 	plane->y_pos = (val & _CURSOR_POS_Y_MASK) >> _CURSOR_POS_Y_SHIFT;
 	plane->y_sign = (val & _CURSOR_SIGN_Y_MASK) >> _CURSOR_SIGN_Y_SHIFT;
 
+	plane->x_hot = vgpu_vreg_t(vgpu, vgtif_reg(cursor_x_hot));
+	plane->y_hot = vgpu_vreg_t(vgpu, vgtif_reg(cursor_y_hot));
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c
index a33c1c3e..2c824a9 100644
--- a/drivers/gpu/drm/i915/gvt/handlers.c
+++ b/drivers/gpu/drm/i915/gvt/handlers.c
@@ -1201,8 +1201,8 @@  static int pvinfo_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
 		ret = handle_g2v_notification(vgpu, data);
 		break;
 	/* add xhot and yhot to handled list to avoid error log */
-	case 0x78830:
-	case 0x78834:
+	case _vgtif_reg(cursor_x_hot):
+	case _vgtif_reg(cursor_y_hot):
 	case _vgtif_reg(pdp[0].lo):
 	case _vgtif_reg(pdp[0].hi):
 	case _vgtif_reg(pdp[1].lo):
diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
index 2e0a02a..bf75300 100644
--- a/drivers/gpu/drm/i915/gvt/vgpu.c
+++ b/drivers/gpu/drm/i915/gvt/vgpu.c
@@ -58,6 +58,9 @@  void populate_pvinfo_page(struct intel_vgpu *vgpu)
 
 	vgpu_vreg_t(vgpu, vgtif_reg(avail_rs.fence_num)) = vgpu_fence_sz(vgpu);
 
+	vgpu_vreg_t(vgpu, vgtif_reg(cursor_x_hot)) = UINT_MAX;
+	vgpu_vreg_t(vgpu, vgtif_reg(cursor_y_hot)) = UINT_MAX;
+
 	gvt_dbg_core("Populate PVINFO PAGE for vGPU %d\n", vgpu->id);
 	gvt_dbg_core("aperture base [GMADR] 0x%llx size 0x%llx\n",
 		vgpu_aperture_gmadr_base(vgpu), vgpu_aperture_sz(vgpu));
diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i915_pvinfo.h
index 195203f..d61914a 100644
--- a/drivers/gpu/drm/i915/i915_pvinfo.h
+++ b/drivers/gpu/drm/i915/i915_pvinfo.h
@@ -93,7 +93,10 @@  struct vgt_if {
 	u32 rsv5[4];
 
 	u32 g2v_notify;
-	u32 rsv6[7];
+	u32 rsv6[5];
+
+	u32 cursor_x_hot;
+	u32 cursor_y_hot;
 
 	struct {
 		u32 lo;

Comments

On 2018.04.16 11:45:28 +0800, Tina Zhang wrote:
> Guest OS driver uses PV info registers to deliver cursor hotspot info
> to host. This patch is used to get cursor hotspot info from virtual
> registers and deliver it to host userspace.
> 
> v2->v3:
> - add validate_hotspot(). (Zhenyu)
> 
> v1->v2:
> - name as cursor_x_hot/cursor_y_hot. (Zhenyu)
> - use i915_reg_t definition instead of magic numbers. (Zhenyu)
> 
> Signed-off-by: Tina Zhang <tina.zhang@intel.com>
> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> Cc: Zhi Wang <zhi.a.wang@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  drivers/gpu/drm/i915/gvt/dmabuf.c     | 19 +++++++++++++------
>  drivers/gpu/drm/i915/gvt/fb_decoder.c |  3 +++
>  drivers/gpu/drm/i915/gvt/handlers.c   |  4 ++--
>  drivers/gpu/drm/i915/gvt/vgpu.c       |  3 +++
>  drivers/gpu/drm/i915/i915_pvinfo.h    |  5 ++++-
>  5 files changed, 25 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
> index 6f4f8e9..46be026 100644
> --- a/drivers/gpu/drm/i915/gvt/dmabuf.c
> +++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
> @@ -192,6 +192,14 @@ static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev,
>  	return obj;
>  }
>  
> +static bool validate_hotspot(struct intel_vgpu_cursor_plane_format *c)
> +{
> +	if (c && (c->x_hot <= c->width) && (c->y_hot <= c->height))
> +		return true;
> +	else
> +		return false;
> +}
> +
>  static int vgpu_get_plane_info(struct drm_device *dev,
>  		struct intel_vgpu *vgpu,
>  		struct intel_vgpu_fb_info *info,
> @@ -229,12 +237,11 @@ static int vgpu_get_plane_info(struct drm_device *dev,
>  		info->x_pos = c.x_pos;
>  		info->y_pos = c.y_pos;
>  
> -		/* The invalid cursor hotspot value is delivered to host
> -		 * until we find a way to get the cursor hotspot info of
> -		 * guest OS.
> -		 */
> -		info->x_hot = UINT_MAX;
> -		info->y_hot = UINT_MAX;
> +		if (validate_hotspot(&c)) {
> +			info->x_hot = c.x_hot;
> +			info->y_hot = c.y_hot;
> +		}

This should ensure info always got hotspot set, either valid value
from guest or fallback to invalid.

> +
>  		info->size = (((info->stride * c.height * c.bpp) / 8)
>  				+ (PAGE_SIZE - 1)) >> PAGE_SHIFT;
>  	} else {
> diff --git a/drivers/gpu/drm/i915/gvt/fb_decoder.c b/drivers/gpu/drm/i915/gvt/fb_decoder.c
> index 1c12068..5e7468b 100644
> --- a/drivers/gpu/drm/i915/gvt/fb_decoder.c
> +++ b/drivers/gpu/drm/i915/gvt/fb_decoder.c
> @@ -36,6 +36,7 @@
>  #include <uapi/drm/drm_fourcc.h>
>  #include "i915_drv.h"
>  #include "gvt.h"
> +#include "i915_pvinfo.h"
>  
>  #define PRIMARY_FORMAT_NUM	16
>  struct pixel_format {
> @@ -384,6 +385,8 @@ int intel_vgpu_decode_cursor_plane(struct intel_vgpu *vgpu,
>  	plane->y_pos = (val & _CURSOR_POS_Y_MASK) >> _CURSOR_POS_Y_SHIFT;
>  	plane->y_sign = (val & _CURSOR_SIGN_Y_MASK) >> _CURSOR_SIGN_Y_SHIFT;
>  
> +	plane->x_hot = vgpu_vreg_t(vgpu, vgtif_reg(cursor_x_hot));
> +	plane->y_hot = vgpu_vreg_t(vgpu, vgtif_reg(cursor_y_hot));
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c
> index a33c1c3e..2c824a9 100644
> --- a/drivers/gpu/drm/i915/gvt/handlers.c
> +++ b/drivers/gpu/drm/i915/gvt/handlers.c
> @@ -1201,8 +1201,8 @@ static int pvinfo_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
>  		ret = handle_g2v_notification(vgpu, data);
>  		break;
>  	/* add xhot and yhot to handled list to avoid error log */
> -	case 0x78830:
> -	case 0x78834:
> +	case _vgtif_reg(cursor_x_hot):
> +	case _vgtif_reg(cursor_y_hot):
>  	case _vgtif_reg(pdp[0].lo):
>  	case _vgtif_reg(pdp[0].hi):
>  	case _vgtif_reg(pdp[1].lo):
> diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
> index 2e0a02a..bf75300 100644
> --- a/drivers/gpu/drm/i915/gvt/vgpu.c
> +++ b/drivers/gpu/drm/i915/gvt/vgpu.c
> @@ -58,6 +58,9 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu)
>  
>  	vgpu_vreg_t(vgpu, vgtif_reg(avail_rs.fence_num)) = vgpu_fence_sz(vgpu);
>  
> +	vgpu_vreg_t(vgpu, vgtif_reg(cursor_x_hot)) = UINT_MAX;
> +	vgpu_vreg_t(vgpu, vgtif_reg(cursor_y_hot)) = UINT_MAX;
> +
>  	gvt_dbg_core("Populate PVINFO PAGE for vGPU %d\n", vgpu->id);
>  	gvt_dbg_core("aperture base [GMADR] 0x%llx size 0x%llx\n",
>  		vgpu_aperture_gmadr_base(vgpu), vgpu_aperture_sz(vgpu));
> diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i915_pvinfo.h
> index 195203f..d61914a 100644
> --- a/drivers/gpu/drm/i915/i915_pvinfo.h
> +++ b/drivers/gpu/drm/i915/i915_pvinfo.h
> @@ -93,7 +93,10 @@ struct vgt_if {
>  	u32 rsv5[4];
>  
>  	u32 g2v_notify;
> -	u32 rsv6[7];
> +	u32 rsv6[5];
> +
> +	u32 cursor_x_hot;
> +	u32 cursor_y_hot;
>  
>  	struct {
>  		u32 lo;
> -- 
> 2.7.4
>