diff mbox

drm/i915: Compare GGTT view structs instead of types

Message ID 1426588111.30454.1.camel@jlahtine-mobl1 (mailing list archive)
State New, archived
Headers show

Commit Message

Joonas Lahtinen March 17, 2015, 10:28 a.m. UTC
To allow for views where the view type is not defined by the view type only,
like it is in stereo or rotated 90 degree view, change the semantic to require
the whole view structure for comparison. This allows including parameters like
offset to be included in the view which is useful for eg. partial views.

Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h     |  8 ++++----
 drivers/gpu/drm/i915/i915_gem.c     | 34 ++++++++++++++++++----------------
 drivers/gpu/drm/i915/i915_gem_gtt.c | 12 ++++++------
 drivers/gpu/drm/i915/i915_gem_gtt.h | 11 ++++++++++-
 4 files changed, 38 insertions(+), 27 deletions(-)

Comments

Shuang He March 18, 2015, 11:20 a.m. UTC | #1
Tested-By: PRC QA PRTS (Patch Regression Test System Contact: shuang.he@intel.com)
Task id: 5981
-------------------------------------Summary-------------------------------------
Platform          Delta          drm-intel-nightly          Series Applied
PNV                 -1              268/268              267/268
ILK                                  303/303              303/303
SNB                                  283/283              283/283
IVB                                  343/343              343/343
BYT                                  287/287              287/287
HSW                 -1              363/363              362/363
BDW                                  308/308              308/308
-------------------------------------Detailed-------------------------------------
Platform  Test                                drm-intel-nightly          Series Applied
*PNV  igt_gem_userptr_blits_minor-normal-sync      PASS(3)      DMESG_WARN(1)PASS(1)
*HSW  igt_gem_storedw_loop_blt      PASS(2)      DMESG_WARN(1)PASS(1)
Note: You need to pay more attention to line start with '*'
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 81f60b4..3f8d7ed 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2798,19 +2798,19 @@  void i915_gem_restore_fences(struct drm_device *dev);
 
 unsigned long
 i915_gem_obj_ggtt_offset_view(struct drm_i915_gem_object *o,
-			      enum i915_ggtt_view_type view);
+			      const struct i915_ggtt_view *view);
 unsigned long
 i915_gem_obj_offset(struct drm_i915_gem_object *o,
 		    struct i915_address_space *vm);
 static inline unsigned long
 i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *o)
 {
-	return i915_gem_obj_ggtt_offset_view(o, I915_GGTT_VIEW_NORMAL);
+	return i915_gem_obj_ggtt_offset_view(o, &i915_ggtt_view_normal);
 }
 
 bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o);
 bool i915_gem_obj_ggtt_bound_view(struct drm_i915_gem_object *o,
-				  enum i915_ggtt_view_type view);
+				  const struct i915_ggtt_view *view);
 bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
 			struct i915_address_space *vm);
 
@@ -2858,7 +2858,7 @@  i915_vm_to_ppgtt(struct i915_address_space *vm)
 
 static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
 {
-	return i915_gem_obj_ggtt_bound_view(obj, I915_GGTT_VIEW_NORMAL);
+	return i915_gem_obj_ggtt_bound_view(obj, &i915_ggtt_view_normal);
 }
 
 static inline unsigned long
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index e2876bf..41d3c2c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3073,7 +3073,7 @@  int i915_vma_unbind(struct i915_vma *vma)
 	 */
 
 	if (i915_is_ggtt(vma->vm) &&
-	    vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
+	    i915_ggtt_view_equal(&vma->ggtt_view, &i915_ggtt_view_normal)) {
 		i915_gem_object_finish_gtt(obj);
 
 		/* release the fence reg _after_ flushing */
@@ -3090,10 +3090,10 @@  int i915_vma_unbind(struct i915_vma *vma)
 	if (i915_is_ggtt(vma->vm)) {
 		if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) {
 			obj->map_and_fenceable = false;
-		} else if (vma->ggtt_view.pages) {
-			sg_free_table(vma->ggtt_view.pages);
-			kfree(vma->ggtt_view.pages);
-			vma->ggtt_view.pages = NULL;
+		} else if (vma->ggtt_view.private.pages) {
+			sg_free_table(vma->ggtt_view.private.pages);
+			kfree(vma->ggtt_view.private.pages);
+			vma->ggtt_view.private.pages = NULL;
 		}
 	}
 
@@ -4208,7 +4208,7 @@  i915_gem_object_do_pin(struct drm_i915_gem_object *obj,
 
 		if (i915_vma_misplaced(vma, alignment, flags)) {
 			unsigned long offset;
-			offset = ggtt_view ? i915_gem_obj_ggtt_offset_view(obj, ggtt_view->type) :
+			offset = ggtt_view ? i915_gem_obj_ggtt_offset_view(obj, ggtt_view) :
 					     i915_gem_obj_offset(obj, vm);
 			WARN(vma->pin_count,
 			     "bo is already pinned in %s with incorrect alignment:"
@@ -4606,7 +4606,7 @@  struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
 	struct i915_vma *vma;
 	list_for_each_entry(vma, &obj->vma_list, vma_link) {
 		if (i915_is_ggtt(vma->vm) &&
-		    vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
+		    !i915_ggtt_view_equal(&vma->ggtt_view, &i915_ggtt_view_normal))
 			continue;
 		if (vma->vm == vm)
 			return vma;
@@ -4624,7 +4624,8 @@  struct i915_vma *i915_gem_obj_to_ggtt_view(struct drm_i915_gem_object *obj,
 		return ERR_PTR(-EINVAL);
 
 	list_for_each_entry(vma, &obj->vma_list, vma_link)
-		if (vma->vm == ggtt && vma->ggtt_view.type == view->type)
+		if (vma->vm == ggtt &&
+		    i915_ggtt_view_equal(&vma->ggtt_view, view))
 			return vma;
 	return NULL;
 }
@@ -5245,7 +5246,7 @@  i915_gem_obj_offset(struct drm_i915_gem_object *o,
 
 	list_for_each_entry(vma, &o->vma_list, vma_link) {
 		if (i915_is_ggtt(vma->vm) &&
-		    vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
+		    !i915_ggtt_view_equal(&vma->ggtt_view, &i915_ggtt_view_normal))
 			continue;
 		if (vma->vm == vm)
 			return vma->node.start;
@@ -5258,14 +5259,15 @@  i915_gem_obj_offset(struct drm_i915_gem_object *o,
 
 unsigned long
 i915_gem_obj_ggtt_offset_view(struct drm_i915_gem_object *o,
-			      enum i915_ggtt_view_type view)
+			      const struct i915_ggtt_view *view)
 {
 	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
 	struct i915_address_space *ggtt = i915_obj_to_ggtt(o);
 	struct i915_vma *vma;
 
 	list_for_each_entry(vma, &o->vma_list, vma_link)
-		if (vma->vm == ggtt && vma->ggtt_view.type == view)
+		if (vma->vm == ggtt &&
+		    i915_ggtt_view_equal(&vma->ggtt_view, view))
 			return vma->node.start;
 
 	WARN(1, "global vma for this object not found.\n");
@@ -5279,7 +5281,7 @@  bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
 
 	list_for_each_entry(vma, &o->vma_list, vma_link) {
 		if (i915_is_ggtt(vma->vm) &&
-		    vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
+		    !i915_ggtt_view_equal(&vma->ggtt_view, &i915_ggtt_view_normal))
 			continue;
 		if (vma->vm == vm && drm_mm_node_allocated(&vma->node))
 			return true;
@@ -5289,14 +5291,14 @@  bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
 }
 
 bool i915_gem_obj_ggtt_bound_view(struct drm_i915_gem_object *o,
-				  enum i915_ggtt_view_type view)
+				  const struct i915_ggtt_view *view)
 {
 	struct i915_address_space *ggtt = i915_obj_to_ggtt(o);
 	struct i915_vma *vma;
 
 	list_for_each_entry(vma, &o->vma_list, vma_link)
 		if (vma->vm == ggtt &&
-		    vma->ggtt_view.type == view &&
+		    i915_ggtt_view_equal(&vma->ggtt_view, view) &&
 		    drm_mm_node_allocated(&vma->node))
 			return true;
 
@@ -5326,7 +5328,7 @@  unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
 
 	list_for_each_entry(vma, &o->vma_list, vma_link) {
 		if (i915_is_ggtt(vma->vm) &&
-		    vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
+		    !i915_ggtt_view_equal(&vma->ggtt_view, &i915_ggtt_view_normal))
 			continue;
 		if (vma->vm == vm)
 			return vma->node.size;
@@ -5435,7 +5437,7 @@  bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj)
 	struct i915_vma *vma;
 	list_for_each_entry(vma, &obj->vma_list, vma_link) {
 		if (i915_is_ggtt(vma->vm) &&
-		    vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL)
+		    !i915_ggtt_view_equal(&vma->ggtt_view, &i915_ggtt_view_normal))
 			continue;
 		if (vma->pin_count > 0)
 			return true;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index f1b9ea6..facde66 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1696,7 +1696,7 @@  static void i915_ggtt_bind_vma(struct i915_vma *vma,
 		AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
 
 	BUG_ON(!i915_is_ggtt(vma->vm));
-	intel_gtt_insert_sg_entries(vma->ggtt_view.pages, entry, flags);
+	intel_gtt_insert_sg_entries(vma->ggtt_view.private.pages, entry, flags);
 	vma->bound = GLOBAL_BIND;
 }
 
@@ -1734,7 +1734,7 @@  static void ggtt_bind_vma(struct i915_vma *vma,
 		flags |= PTE_READ_ONLY;
 
 	if (i915_is_ggtt(vma->vm))
-		pages = vma->ggtt_view.pages;
+		pages = vma->ggtt_view.private.pages;
 
 	/* If there is no aliasing PPGTT, or the caller needs a global mapping,
 	 * or we have a global mapping already but the cacheability flags have
@@ -2417,16 +2417,16 @@  i915_gem_obj_lookup_or_create_ggtt_vma(struct drm_i915_gem_object *obj,
 static inline
 int i915_get_ggtt_vma_pages(struct i915_vma *vma)
 {
-	if (vma->ggtt_view.pages)
+	if (vma->ggtt_view.private.pages)
 		return 0;
 
-	if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL)
-		vma->ggtt_view.pages = vma->obj->pages;
+	if (i915_ggtt_view_equal(&vma->ggtt_view, &i915_ggtt_view_normal))
+		vma->ggtt_view.private.pages = vma->obj->pages;
 	else
 		WARN_ONCE(1, "GGTT view %u not implemented!\n",
 			  vma->ggtt_view.type);
 
-	if (!vma->ggtt_view.pages) {
+	if (!vma->ggtt_view.private.pages) {
 		DRM_ERROR("Failed to get pages for GGTT view type %u!\n",
 			  vma->ggtt_view.type);
 		return -EINVAL;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index c9e93f5..8dc8099 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -116,7 +116,9 @@  enum i915_ggtt_view_type {
 struct i915_ggtt_view {
 	enum i915_ggtt_view_type type;
 
-	struct sg_table *pages;
+	union {
+		struct sg_table *pages;
+	} private;
 };
 
 extern const struct i915_ggtt_view i915_ggtt_view_normal;
@@ -304,6 +306,13 @@  struct i915_hw_ppgtt {
 	void (*debug_dump)(struct i915_hw_ppgtt *ppgtt, struct seq_file *m);
 };
 
+static inline
+bool i915_ggtt_view_equal(const struct i915_ggtt_view *a,
+			  const struct i915_ggtt_view *b)
+{
+	return !memcmp(a, b, offsetof(struct i915_ggtt_view, private));
+}
+
 int i915_gem_gtt_init(struct drm_device *dev);
 void i915_gem_init_global_gtt(struct drm_device *dev);
 void i915_global_gtt_cleanup(struct drm_device *dev);