From patchwork Fri Jun 10 08:53:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ankitprasad.r.sharma@intel.com X-Patchwork-Id: 9169111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 42ED96048F for ; Fri, 10 Jun 2016 09:18:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3336F28325 for ; Fri, 10 Jun 2016 09:18:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2811A2835D; Fri, 10 Jun 2016 09:18:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEF7A28325 for ; Fri, 10 Jun 2016 09:18:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8032F6ECC6; Fri, 10 Jun 2016 09:18:55 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id D295F6ECC3 for ; Fri, 10 Jun 2016 09:18:50 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 10 Jun 2016 02:18:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,449,1459839600"; d="scan'208";a="972871369" Received: from ankitprasad-desktop.iind.intel.com ([10.223.82.74]) by orsmga001.jf.intel.com with ESMTP; 10 Jun 2016 02:18:49 -0700 From: ankitprasad.r.sharma@intel.com To: intel-gfx@lists.freedesktop.org Date: Fri, 10 Jun 2016 14:23:02 +0530 Message-Id: <1465548783-19712-4-git-send-email-ankitprasad.r.sharma@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465548783-19712-1-git-send-email-ankitprasad.r.sharma@intel.com> References: <1465548783-19712-1-git-send-email-ankitprasad.r.sharma@intel.com> Cc: akash.goel@intel.com, Ankitprasad Sharma Subject: [Intel-gfx] [PATCH 4/5] drm/i915: Clearing buffer objects via CPU/GTT X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ankitprasad Sharma 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) v3: Map object page by page to the gtt if the pinning of the whole object to the ggtt fails, Corrected function name (Chris) v4: Clear the buffer page by page, and not map the whole object in the gtt aperture. Use i915 wrapper function in place of drm_mm_insert_node_in_range. v5: Use renamed wrapper function for drm_mm_insert_node_in_range, updated barrier positioning (Chris) v6: Use PAGE_SIZE instead of 4096, use get_pages call before pinning pages (Tvrtko) v7: Fixed the onion (undo operation in reverse order) (Chris) v8: Rebase (Ankit) Testcase: igt/gem_stolen Signed-off-by: Ankitprasad Sharma Reviewed-by: Tvrtko Ursulin Reviewed-by: Chris Wilson --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem.c | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 0349c5f..e72e6af 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -3109,6 +3109,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_object_clear(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 452178c..d658d46 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -5418,3 +5418,48 @@ fail: drm_gem_object_unreference(&obj->base); return ERR_PTR(ret); } + +/** + * i915_gem_object_clear() - Clear buffer object via CPU/GTT + * @obj: Buffer object to be cleared + * + * Return: 0 - success, non-zero - failure + */ +int i915_gem_object_clear(struct drm_i915_gem_object *obj) +{ + struct drm_i915_private *i915 = to_i915(obj->base.dev); + struct i915_ggtt *ggtt = &i915->ggtt; + struct drm_mm_node node; + char __iomem *base; + uint64_t size = obj->base.size; + int ret, i; + + lockdep_assert_held(&obj->base.dev->struct_mutex); + ret = insert_mappable_node(i915, &node, PAGE_SIZE); + if (ret) + return ret; + + ret = i915_gem_object_get_pages(obj); + if (ret) + goto err_remove_node; + + i915_gem_object_pin_pages(obj); + base = io_mapping_map_wc(ggtt->mappable, node.start, PAGE_SIZE); + + for (i = 0; i < size/PAGE_SIZE; i++) { + ggtt->base.insert_page(&ggtt->base, + i915_gem_object_get_dma_address(obj, i), + node.start, I915_CACHE_NONE, 0); + wmb(); /* flush modifications to the GGTT (insert_page) */ + memset_io(base, 0, PAGE_SIZE); + wmb(); /* flush the write before we modify the GGTT */ + } + + io_mapping_unmap(base); + ggtt->base.clear_range(&ggtt->base, node.start, node.size, true); + i915_gem_object_unpin_pages(obj); + +err_remove_node: + remove_mappable_node(&node); + return ret; +}