[Intel-gfx] [PATCH 1/4] drm/i915: Clearing buffer objects via CPU/GTT
Tvrtko Ursulin
tvrtko.ursulin at linux.intel.com
Tue Sep 15 07:00:52 PDT 2015
On 09/15/2015 09:33 AM, ankitprasad.r.sharma at intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
>
> This patch adds support for clearing buffer objects via CPU/GTT. This
> is particularly useful for clearing out the non shmem backed objects.
> Currently intend to use this only for buffers allocated from stolen
> region.
>
> v2: Added kernel doc for i915_gem_clear_object(), corrected/removed
> variable assignments (Tvrtko)
>
> Testcase: igt/gem_stolen
>
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
> ---
> drivers/gpu/drm/i915/i915_drv.h | 1 +
> drivers/gpu/drm/i915/i915_gem.c | 39 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 40 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index e0f3f05..8db905a 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2820,6 +2820,7 @@ int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
> int *needs_clflush);
>
> int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
> +int i915_gem_clear_object(struct drm_i915_gem_object *obj);
>
> static inline int __sg_page_count(struct scatterlist *sg)
> {
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 1ac57ec..94533bf 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -5139,3 +5139,42 @@ fail:
> drm_gem_object_unreference(&obj->base);
> return ERR_PTR(ret);
> }
> +
> +/**
> + * i915_gem_clear_object() - Clear buffer object via CPU/GTT
> + * @obj: Buffer object to be cleared
> + *
> + * Return: 0 - success, non-zero - failure
> + */
> +int i915_gem_clear_object(struct drm_i915_gem_object *obj)
> +{
> + int ret;
> + char __iomem *base;
> + size_t size = obj->base.size;
> + struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
> +
> + WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
> + ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_MAPPABLE);
> + if (ret)
> + return ret;
> +
> + ret = i915_gem_object_put_fence(obj);
> + if (ret)
> + goto unpin;
> +
> + /* Get the CPU virtual address of the buffer */
> + base = ioremap_wc(dev_priv->gtt.mappable_base +
> + i915_gem_obj_ggtt_offset(obj), size);
> + if (base == NULL) {
> + DRM_ERROR("Mapping of gem object to CPU failed!\n");
> + ret = -ENOSPC;
> + goto unpin;
> + }
> +
> + memset_io(base, 0, size);
> +
> + iounmap(base);
> +unpin:
> + i915_gem_object_ggtt_unpin(obj);
> + return ret;
> +}
>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Regards,
Tvrtko
More information about the Intel-gfx
mailing list