From patchwork Fri Aug 12 00:47:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 1059242 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7C0nFBR024573 for ; Fri, 12 Aug 2011 00:49:36 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D5D8E9EFBF for ; Thu, 11 Aug 2011 17:49:15 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from cloud01.chad-versace.us (184-106-247-128.static.cloud-ips.com [184.106.247.128]) by gabe.freedesktop.org (Postfix) with ESMTP id 65CBAA01E4 for ; Thu, 11 Aug 2011 17:47:23 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by cloud01.chad-versace.us (Postfix) with ESMTP id D819E1D408E; Fri, 12 Aug 2011 00:50:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at static.cloud-ips.com X-Spam-Flag: NO X-Spam-Score: -1 X-Spam-Level: X-Spam-Status: No, score=-1 tagged_above=-100 required=3 tests=[ALL_TRUSTED=-1] autolearn=ham Received: from cloud01.chad-versace.us ([127.0.0.1]) by localhost (cloud01.static.cloud-ips.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wu33TZI-mJYy; Fri, 12 Aug 2011 00:50:12 +0000 (UTC) Received: from localhost.localdomain (unknown [216.251.138.90]) by cloud01.chad-versace.us (Postfix) with ESMTPSA id 31CA41D424F; Fri, 12 Aug 2011 00:50:08 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Thu, 11 Aug 2011 17:47:27 -0700 Message-Id: <1313110048-2971-4-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1313110048-2971-1-git-send-email-ben@bwidawsk.net> References: <1313110048-2971-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH] intel: hack to allow WO mappings X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 12 Aug 2011 00:49:36 +0000 (UTC) Signed-off-by: Ben Widawsky --- intel/intel_bufmgr_gem.c | 49 +++++++++++++++++++++++++++++++++++++++------ 1 files changed, 42 insertions(+), 7 deletions(-) diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c index 4f4de92..7431ed9 100644 --- a/intel/intel_bufmgr_gem.c +++ b/intel/intel_bufmgr_gem.c @@ -195,6 +195,11 @@ struct _drm_intel_bo_gem { * relocations. */ int reloc_tree_fences; + + /** + * CPU write only buffer. + */ + char cpu_mapping; }; static unsigned int @@ -998,15 +1003,12 @@ static void drm_intel_gem_bo_unreference(drm_intel_bo *bo) } } -static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) +static int do_gem_bo_map(drm_intel_bo *bo, int write_enable) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; - struct drm_i915_gem_set_domain set_domain; int ret; - pthread_mutex_lock(&bufmgr_gem->lock); - /* Allow recursive mapping. Mesa may recursively map buffers with * nested display loops. */ @@ -1018,6 +1020,8 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) memset(&mmap_arg, 0, sizeof(mmap_arg)); mmap_arg.handle = bo_gem->gem_handle; mmap_arg.offset = 0; + if (write_enable == 27) + mmap_arg.offset |= 1 ; mmap_arg.size = bo->size; ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_MMAP, @@ -1027,7 +1031,6 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) DBG("%s:%d: Error mapping buffer %d (%s): %s .\n", __FILE__, __LINE__, bo_gem->gem_handle, bo_gem->name, strerror(errno)); - pthread_mutex_unlock(&bufmgr_gem->lock); return ret; } bo_gem->mem_virtual = (void *)(uintptr_t) mmap_arg.addr_ptr; @@ -1036,6 +1039,39 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) bo_gem->mem_virtual); bo->virtual = bo_gem->mem_virtual; + return 0; +} + +static int drm_intel_gem_bo_map_wo(drm_intel_bo *bo) +{ + drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; + drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; + int wo_mapping_change; + int ret; + + wo_mapping_change = ((bo_gem->cpu_mapping) != 0); + assert(!bo_gem->mem_virtual || !wo_mapping_change); + + pthread_mutex_lock(&bufmgr_gem->lock); + ret = do_gem_bo_map(bo, 27); + if (ret == 0) + bo_gem->cpu_mapping = 1; + pthread_mutex_unlock(&bufmgr_gem->lock); + return ret; +} + +static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) +{ + drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; + drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; + struct drm_i915_gem_set_domain set_domain; + int ret; + + if (write_enable == 27) + return drm_intel_gem_bo_map_wo(bo); + + pthread_mutex_lock(&bufmgr_gem->lock); + ret = do_gem_bo_map(bo, write_enable); set_domain.handle = bo_gem->gem_handle; set_domain.read_domains = I915_GEM_DOMAIN_CPU; if (write_enable) @@ -1052,8 +1088,7 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable) } pthread_mutex_unlock(&bufmgr_gem->lock); - - return 0; + return ret; } int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo)