[Intel-gfx] [PATCH v4 2/8] drm/i915/selftests: Add mock selftest for remapped vmas

2019-05-09 Thread Ville Syrjala
From: Ville Syrjälä 

Extend the rotated vma mock selftest to cover remapped vmas as
well.

TODO: reindent the loops I guess? Left like this for now to
ease review

v2: Include the vma type in the error message (Chris)
v3: Deal with trimmed sg
v4: Drop leftover debugs

Cc: Chris Wilson 
Reviewed-by: Chris Wilson 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/selftests/i915_vma.c | 98 +--
 1 file changed, 90 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c 
b/drivers/gpu/drm/i915/selftests/i915_vma.c
index 18dc221cb22b..89f6ef945c1b 100644
--- a/drivers/gpu/drm/i915/selftests/i915_vma.c
+++ b/drivers/gpu/drm/i915/selftests/i915_vma.c
@@ -59,7 +59,7 @@ static bool assert_vma(struct i915_vma *vma,
 static struct i915_vma *
 checked_vma_instance(struct drm_i915_gem_object *obj,
 struct i915_address_space *vm,
-struct i915_ggtt_view *view)
+const struct i915_ggtt_view *view)
 {
struct i915_vma *vma;
bool ok = true;
@@ -397,13 +397,74 @@ assert_rotated(struct drm_i915_gem_object *obj,
return sg;
 }
 
+static unsigned long remapped_index(const struct intel_remapped_info *r,
+   unsigned int n,
+   unsigned int x,
+   unsigned int y)
+{
+   return (r->plane[n].stride * y +
+   r->plane[n].offset + x);
+}
+
+static struct scatterlist *
+assert_remapped(struct drm_i915_gem_object *obj,
+   const struct intel_remapped_info *r, unsigned int n,
+   struct scatterlist *sg)
+{
+   unsigned int x, y;
+   unsigned int left = 0;
+   unsigned int offset;
+
+   for (y = 0; y < r->plane[n].height; y++) {
+   for (x = 0; x < r->plane[n].width; x++) {
+   unsigned long src_idx;
+   dma_addr_t src;
+
+   if (!sg) {
+   pr_err("Invalid sg table: too short at plane 
%d, (%d, %d)!\n",
+  n, x, y);
+   return ERR_PTR(-EINVAL);
+   }
+   if (!left) {
+   offset = 0;
+   left = sg_dma_len(sg);
+   }
+
+   src_idx = remapped_index(r, n, x, y);
+   src = i915_gem_object_get_dma_address(obj, src_idx);
+
+   if (left < PAGE_SIZE || left & (PAGE_SIZE-1)) {
+   pr_err("Invalid sg.length, found %d, expected 
%lu for remapped page (%d, %d) [src index %lu]\n",
+  sg_dma_len(sg), PAGE_SIZE,
+  x, y, src_idx);
+   return ERR_PTR(-EINVAL);
+   }
+
+   if (sg_dma_address(sg) + offset != src) {
+   pr_err("Invalid address for remapped page (%d, 
%d) [src index %lu]\n",
+  x, y, src_idx);
+   return ERR_PTR(-EINVAL);
+   }
+
+   left -= PAGE_SIZE;
+   offset += PAGE_SIZE;
+
+
+   if (!left)
+   sg = sg_next(sg);
+   }
+   }
+
+   return sg;
+}
+
 static unsigned int rotated_size(const struct intel_remapped_plane_info *a,
 const struct intel_remapped_plane_info *b)
 {
return a->width * a->height + b->width * b->height;
 }
 
-static int igt_vma_rotate(void *arg)
+static int igt_vma_rotate_remap(void *arg)
 {
struct i915_ggtt *ggtt = arg;
struct i915_address_space *vm = >vm;
@@ -426,6 +487,11 @@ static int igt_vma_rotate(void *arg)
{ .width = 6, .height = 4, .stride = 6 },
{ }
}, *a, *b;
+   enum i915_ggtt_view_type types[] = {
+   I915_GGTT_VIEW_ROTATED,
+   I915_GGTT_VIEW_REMAPPED,
+   0,
+   }, *t;
const unsigned int max_pages = 64;
int err = -ENOMEM;
 
@@ -437,6 +503,7 @@ static int igt_vma_rotate(void *arg)
if (IS_ERR(obj))
goto out;
 
+   for (t = types; *t; t++) {
for (a = planes; a->width; a++) {
for (b = planes + ARRAY_SIZE(planes); b-- != planes; ) {
struct i915_ggtt_view view;
@@ -447,7 +514,7 @@ static int igt_vma_rotate(void *arg)
GEM_BUG_ON(max_offset > max_pages);
max_offset = max_pages - max_offset;
 
-   view.type = I915_GGTT_VIEW_ROTATED;
+   view.type = *t;
view.rotated.plane[0] = *a;
view.rotated.plane[1] = *b;
 
@@ -468,14 +535,23 @@ static int 

Re: [Intel-gfx] [PATCH v4 2/8] drm/i915/selftests: Add mock selftest for remapped vmas

2019-01-24 Thread Chris Wilson
Quoting Ville Syrjala (2019-01-24 18:58:02)
> From: Ville Syrjälä 
> 
> Extend the rotated vma mock selftest to cover remapped vmas as
> well.
> 
> TODO: reindent the loops I guess? Left like this for now to
> ease review

Probably leave it as is for the moment. Looks like we need to split the
loops up into their functions for us to be able to recover enough
columns.

Not a task worth holding up this series for.
 
> v2: Include the vma type in the error message (Chris)
> v3: Deal with trimmed sg
> v4: Drop leftover debugs
> 
> Cc: Chris Wilson 
> Signed-off-by: Ville Syrjälä 
Reviewed-by: Chris Wilson 
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 2/8] drm/i915/selftests: Add mock selftest for remapped vmas

2019-01-24 Thread Ville Syrjala
From: Ville Syrjälä 

Extend the rotated vma mock selftest to cover remapped vmas as
well.

TODO: reindent the loops I guess? Left like this for now to
ease review

v2: Include the vma type in the error message (Chris)
v3: Deal with trimmed sg
v4: Drop leftover debugs

Cc: Chris Wilson 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/selftests/i915_vma.c | 98 +--
 1 file changed, 90 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c 
b/drivers/gpu/drm/i915/selftests/i915_vma.c
index 06bbed7920b9..653a9b6c514e 100644
--- a/drivers/gpu/drm/i915/selftests/i915_vma.c
+++ b/drivers/gpu/drm/i915/selftests/i915_vma.c
@@ -59,7 +59,7 @@ static bool assert_vma(struct i915_vma *vma,
 static struct i915_vma *
 checked_vma_instance(struct drm_i915_gem_object *obj,
 struct i915_address_space *vm,
-struct i915_ggtt_view *view)
+const struct i915_ggtt_view *view)
 {
struct i915_vma *vma;
bool ok = true;
@@ -397,13 +397,74 @@ assert_rotated(struct drm_i915_gem_object *obj,
return sg;
 }
 
+static unsigned long remapped_index(const struct intel_remapped_info *r,
+   unsigned int n,
+   unsigned int x,
+   unsigned int y)
+{
+   return (r->plane[n].stride * y +
+   r->plane[n].offset + x);
+}
+
+static struct scatterlist *
+assert_remapped(struct drm_i915_gem_object *obj,
+   const struct intel_remapped_info *r, unsigned int n,
+   struct scatterlist *sg)
+{
+   unsigned int x, y;
+   unsigned int left = 0;
+   unsigned int offset;
+
+   for (y = 0; y < r->plane[n].height; y++) {
+   for (x = 0; x < r->plane[n].width; x++) {
+   unsigned long src_idx;
+   dma_addr_t src;
+
+   if (!sg) {
+   pr_err("Invalid sg table: too short at plane 
%d, (%d, %d)!\n",
+  n, x, y);
+   return ERR_PTR(-EINVAL);
+   }
+   if (!left) {
+   offset = 0;
+   left = sg_dma_len(sg);
+   }
+
+   src_idx = remapped_index(r, n, x, y);
+   src = i915_gem_object_get_dma_address(obj, src_idx);
+
+   if (left < PAGE_SIZE || left & (PAGE_SIZE-1)) {
+   pr_err("Invalid sg.length, found %d, expected 
%lu for remapped page (%d, %d) [src index %lu]\n",
+  sg_dma_len(sg), PAGE_SIZE,
+  x, y, src_idx);
+   return ERR_PTR(-EINVAL);
+   }
+
+   if (sg_dma_address(sg) + offset != src) {
+   pr_err("Invalid address for remapped page (%d, 
%d) [src index %lu]\n",
+  x, y, src_idx);
+   return ERR_PTR(-EINVAL);
+   }
+
+   left -= PAGE_SIZE;
+   offset += PAGE_SIZE;
+
+
+   if (!left)
+   sg = sg_next(sg);
+   }
+   }
+
+   return sg;
+}
+
 static unsigned int rotated_size(const struct intel_remapped_plane_info *a,
 const struct intel_remapped_plane_info *b)
 {
return a->width * a->height + b->width * b->height;
 }
 
-static int igt_vma_rotate(void *arg)
+static int igt_vma_rotate_remap(void *arg)
 {
struct i915_ggtt *ggtt = arg;
struct i915_address_space *vm = >vm;
@@ -426,6 +487,11 @@ static int igt_vma_rotate(void *arg)
{ .width = 6, .height = 4, .stride = 6 },
{ }
}, *a, *b;
+   enum i915_ggtt_view_type types[] = {
+   I915_GGTT_VIEW_ROTATED,
+   I915_GGTT_VIEW_REMAPPED,
+   0,
+   }, *t;
const unsigned int max_pages = 64;
int err = -ENOMEM;
 
@@ -437,6 +503,7 @@ static int igt_vma_rotate(void *arg)
if (IS_ERR(obj))
goto out;
 
+   for (t = types; *t; t++) {
for (a = planes; a->width; a++) {
for (b = planes + ARRAY_SIZE(planes); b-- != planes; ) {
struct i915_ggtt_view view;
@@ -447,7 +514,7 @@ static int igt_vma_rotate(void *arg)
GEM_BUG_ON(max_offset > max_pages);
max_offset = max_pages - max_offset;
 
-   view.type = I915_GGTT_VIEW_ROTATED;
+   view.type = *t;
view.rotated.plane[0] = *a;
view.rotated.plane[1] = *b;
 
@@ -468,14 +535,23 @@ static int igt_vma_rotate(void *arg)