From patchwork Sun Jun 28 12:54:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 6686111 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8D429C05AC for ; Sun, 28 Jun 2015 12:54:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AAA1B203EC for ; Sun, 28 Jun 2015 12:54:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7BC88203E9 for ; Sun, 28 Jun 2015 12:54:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E50356E3BE; Sun, 28 Jun 2015 05:54:26 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [87.106.93.118]) by gabe.freedesktop.org (Postfix) with ESMTP id 5B34A6E32D for ; Sun, 28 Jun 2015 05:54:25 -0700 (PDT) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 41596660-1500048 for multiple; Sun, 28 Jun 2015 13:54:22 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Sun, 28 Jun 2015 13:54:19 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Sun, 28 Jun 2015 13:54:18 +0100 Message-Id: <1435496058-5280-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.1.4 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH] intel: Check the physical swizzle mode for the object 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-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The existing GET_TILING ABI tells white lies. It tries to hide bit17 swizzling from userspace (because then swizzling depends upon the physical address of the individual pages for an object). This of course means that all swizzling to such objects is incorrect (at least half of the time!). The GET_TILING interface was then extended to supply this information, so make use of it! Signed-off-by: Chris Wilson --- intel/intel_bufmgr_gem.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c index b0544af..3ea78c2 100644 --- a/intel/intel_bufmgr_gem.c +++ b/intel/intel_bufmgr_gem.c @@ -1008,6 +1008,29 @@ check_bo_alloc_userptr(drm_intel_bufmgr *bufmgr, tiling_mode, stride, size, flags); } +static int +__drm_intel_bo_gem_get_tiling(drm_intel_bo_gem *bo_gem) +{ + drm_intel_bufmgr_gem *bufmgr_gem = + (drm_intel_bufmgr_gem *) bo_gem->bo.bufmgr; + struct drm_i915_gem_get_tiling get_tiling; + + memclear(get_tiling); + get_tiling.handle = bo_gem->gem_handle; + if (drmIoctl(bufmgr_gem->fd, + DRM_IOCTL_I915_GEM_GET_TILING, + &get_tiling)) + return -errno; + + bo_gem->tiling_mode = get_tiling.tiling_mode; + if (get_tiling.phys_swizzle_mode == get_tiling.swizzle_mode) + bo_gem->swizzle_mode = get_tiling.swizzle_mode; + else + bo_gem->swizzle_mode = I915_BIT_6_SWIZZLE_UNKNOWN; + + return 0; +} + /** * Returns a drm_intel_bo wrapping the given buffer object handle. * @@ -1023,7 +1046,6 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr, drm_intel_bo_gem *bo_gem; int ret; struct drm_gem_open open_arg; - struct drm_i915_gem_get_tiling get_tiling; drmMMListHead *list; /* At the moment most applications only have a few named bo. @@ -1089,18 +1111,12 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr, bo_gem->global_name = handle; bo_gem->reusable = false; - memclear(get_tiling); - get_tiling.handle = bo_gem->gem_handle; - ret = drmIoctl(bufmgr_gem->fd, - DRM_IOCTL_I915_GEM_GET_TILING, - &get_tiling); + ret = __drm_intel_bo_gem_get_tiling(bo_gem); if (ret != 0) { drm_intel_gem_bo_unreference(&bo_gem->bo); pthread_mutex_unlock(&bufmgr_gem->lock); return NULL; } - bo_gem->tiling_mode = get_tiling.tiling_mode; - bo_gem->swizzle_mode = get_tiling.swizzle_mode; /* XXX stride is unknown */ drm_intel_bo_gem_set_in_aperture_size(bufmgr_gem, bo_gem); @@ -2716,10 +2732,8 @@ drm_intel_gem_bo_set_tiling_internal(drm_intel_bo *bo, if (ret == -1) return -errno; - bo_gem->tiling_mode = set_tiling.tiling_mode; - bo_gem->swizzle_mode = set_tiling.swizzle_mode; bo_gem->stride = set_tiling.stride; - return 0; + return __drm_intel_bo_gem_get_tiling(bo_gem); } static int @@ -2768,7 +2782,6 @@ drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int s int ret; uint32_t handle; drm_intel_bo_gem *bo_gem; - struct drm_i915_gem_get_tiling get_tiling; drmMMListHead *list; ret = drmPrimeFDToHandle(bufmgr_gem->fd, prime_fd, &handle); @@ -2830,17 +2843,11 @@ drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int s DRMLISTADDTAIL(&bo_gem->name_list, &bufmgr_gem->named); pthread_mutex_unlock(&bufmgr_gem->lock); - memclear(get_tiling); - get_tiling.handle = bo_gem->gem_handle; - ret = drmIoctl(bufmgr_gem->fd, - DRM_IOCTL_I915_GEM_GET_TILING, - &get_tiling); - if (ret != 0) { + ret = __drm_intel_bo_gem_get_tiling(bo_gem); + if (ret) { drm_intel_gem_bo_unreference(&bo_gem->bo); return NULL; } - bo_gem->tiling_mode = get_tiling.tiling_mode; - bo_gem->swizzle_mode = get_tiling.swizzle_mode; /* XXX stride is unknown */ drm_intel_bo_gem_set_in_aperture_size(bufmgr_gem, bo_gem);