summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm
diff options
context:
space:
mode:
authorMika Kuoppala <mika.kuoppala@intel.com>2015-03-13 17:59:28 +0200
committerMika Kuoppala <mika.kuoppala@intel.com>2015-03-13 18:49:26 +0200
commit30d316ab5de5d8eae275e3cb7c3a53ec60783348 (patch)
tree51b03b5b0aa5db8c89ae0942aa87dd271dbb9f7e /drivers/gpu/drm
parentee5cd6dbe829dacc0e3e5e8b5a14854023b6dedf (diff)
drm/i915: Make macro for gem object scatterlist traversalparser_test
Simplify usage to prevent mistakes in scatter list traversal, due to mixing scatter list entity and page counts. Suggested-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
Diffstat (limited to 'drivers/gpu/drm')
-rw-r--r--drivers/gpu/drm/i915/i915_cmd_parser.c6
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h7
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c23
-rw-r--r--drivers/gpu/drm/i915/i915_gem_dmabuf.c6
-rw-r--r--drivers/gpu/drm/i915/i915_gem_tiling.c9
-rw-r--r--drivers/gpu/drm/i915/i915_gem_userptr.c7
6 files changed, 33 insertions, 25 deletions
diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c
index 61ae8ff4eaed..ab720fb3cca3 100644
--- a/drivers/gpu/drm/i915/i915_cmd_parser.c
+++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
@@ -827,7 +827,7 @@ static u32 *vmap_batch(struct drm_i915_gem_object *obj,
int first_page = start >> PAGE_SHIFT;
int last_page = (len + start + 4095) >> PAGE_SHIFT;
int npages = last_page - first_page;
- struct page **pages;
+ struct page **pages, *page;
pages = drm_malloc_ab(npages, sizeof(*pages));
if (pages == NULL) {
@@ -836,8 +836,8 @@ static u32 *vmap_batch(struct drm_i915_gem_object *obj,
}
i = 0;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, first_page) {
- pages[i++] = sg_page_iter_page(&sg_iter);
+ for_each_obj_page(obj, page, sg_iter, first_page) {
+ pages[i++] = page;
if (i == npages)
break;
}
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index a80b15f7acfa..bad8f9494a09 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2645,6 +2645,13 @@ void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
int *needs_clflush);
+/* Will iterate through object's pages, starting from page n.
+ n will be incremented for each page */
+#define for_each_obj_page(obj, page_ptr, iter, n) \
+ for (__sg_page_iter_start(&(iter), (obj)->pages->sgl, (obj)->pages->nents, (n)); \
+ __sg_page_iter_next(&sg_iter) ? ((page) = sg_page_iter_page(&(sg_iter))) : false ; \
+ (n)++)
+
int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
{
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 0fe313d0f609..3136e8ac02e8 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -632,6 +632,8 @@ i915_gem_shmem_pread(struct drm_device *dev,
int prefaulted = 0;
int needs_clflush = 0;
struct sg_page_iter sg_iter;
+ struct page *page;
+ int i;
user_data = to_user_ptr(args->data_ptr);
remain = args->size;
@@ -644,10 +646,8 @@ i915_gem_shmem_pread(struct drm_device *dev,
offset = args->offset;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents,
- offset >> PAGE_SHIFT) {
- struct page *page = sg_page_iter_page(&sg_iter);
-
+ i = offset >> PAGE_SHIFT;
+ for_each_obj_page(obj, page, sg_iter, i) {
if (remain <= 0)
break;
@@ -934,6 +934,8 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
int needs_clflush_after = 0;
int needs_clflush_before = 0;
struct sg_page_iter sg_iter;
+ struct page *page;
+ int i;
user_data = to_user_ptr(args->data_ptr);
remain = args->size;
@@ -969,9 +971,8 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
offset = args->offset;
obj->dirty = 1;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents,
- offset >> PAGE_SHIFT) {
- struct page *page = sg_page_iter_page(&sg_iter);
+ i = offset >> PAGE_SHIFT;
+ for_each_obj_page(obj, page, sg_iter, i) {
int partial_cacheline_write;
if (remain <= 0)
@@ -1984,7 +1985,8 @@ static void
i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj)
{
struct sg_page_iter sg_iter;
- int ret;
+ struct page *page;
+ int ret, i;
BUG_ON(obj->madv == __I915_MADV_PURGED);
@@ -2004,9 +2006,8 @@ i915_gem_object_put_pages_gtt(struct drm_i915_gem_object *obj)
if (obj->madv == I915_MADV_DONTNEED)
obj->dirty = 0;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, 0) {
- struct page *page = sg_page_iter_page(&sg_iter);
-
+ i = 0;
+ for_each_obj_page(obj, page, sg_iter, i) {
if (obj->dirty)
set_page_dirty(page);
diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
index 82a1f4b57778..68ccd9e153e9 100644
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
@@ -111,7 +111,7 @@ static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
struct drm_device *dev = obj->base.dev;
struct sg_page_iter sg_iter;
- struct page **pages;
+ struct page **pages, *page;
int ret, i;
ret = i915_mutex_lock_interruptible(dev);
@@ -136,8 +136,8 @@ static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
goto err_unpin;
i = 0;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, 0)
- pages[i++] = sg_page_iter_page(&sg_iter);
+ for_each_obj_page(obj, page, sg_iter, i)
+ pages[i] = page;
obj->dma_buf_vmapping = vmap(pages, i, 0, PAGE_KERNEL);
drm_free_large(pages);
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
index 6377b22269ad..a9fcf1710e97 100644
--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
+++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
@@ -503,21 +503,20 @@ void
i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj)
{
struct sg_page_iter sg_iter;
+ struct page *page;
int i;
if (obj->bit_17 == NULL)
return;
i = 0;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, 0) {
- struct page *page = sg_page_iter_page(&sg_iter);
+ for_each_obj_page(obj, page, sg_iter, i) {
char new_bit_17 = page_to_phys(page) >> 17;
if ((new_bit_17 & 0x1) !=
(test_bit(i, obj->bit_17) != 0)) {
i915_gem_swizzle_page(page);
set_page_dirty(page);
}
- i++;
}
}
@@ -525,6 +524,7 @@ void
i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj)
{
struct sg_page_iter sg_iter;
+ struct page *page;
int page_count = obj->base.size >> PAGE_SHIFT;
int i;
@@ -539,11 +539,10 @@ i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj)
}
i = 0;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, 0) {
+ for_each_obj_page(obj, page, sg_iter, i) {
if (page_to_phys(sg_page_iter_page(&sg_iter)) & (1 << 17))
__set_bit(i, obj->bit_17);
else
__clear_bit(i, obj->bit_17);
- i++;
}
}
diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
index 1719078c763a..9186f2c6125a 100644
--- a/drivers/gpu/drm/i915/i915_gem_userptr.c
+++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
@@ -706,15 +706,16 @@ static void
i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj)
{
struct sg_page_iter sg_iter;
+ struct page *page;
+ int i;
BUG_ON(obj->userptr.work != NULL);
if (obj->madv != I915_MADV_WILLNEED)
obj->dirty = 0;
- for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, 0) {
- struct page *page = sg_page_iter_page(&sg_iter);
-
+ i = 0;
+ for_each_obj_page(obj, page, sg_iter, i) {
if (obj->dirty)
set_page_dirty(page);