From patchwork Wed Aug 17 16:12:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9286119 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 10B1660574 for ; Wed, 17 Aug 2016 16:13:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 038C929614 for ; Wed, 17 Aug 2016 16:13:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC61629680; Wed, 17 Aug 2016 16:13:42 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C31E29614 for ; Wed, 17 Aug 2016 16:13:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE6A56E117; Wed, 17 Aug 2016 16:13:41 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE02D6E8D6 for ; Wed, 17 Aug 2016 16:13:39 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id q128so25681862wma.1 for ; Wed, 17 Aug 2016 09:13:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=64VFRwU4TtnetAWWFluVQT7sxDwMlPCkbSS8qoi09NY=; b=uCEPo7ml3VS2WvtK1GIGo3pS1Y8z+0DTt1g2rhXnNuGI9VnMEaFjJ4xIH8gJozPNx4 U7Z20cDni4xXC+7Ntu2ALYLcYMb8i6VFMOV2Oz/Wraajp5BCT9to32JkAX9XH9uiXH8s naQdl/Jra0AOwbd3PCn3LOetPFnVolJ8NY/vz7s1rOmgE7SGIj3j8JWWFTapZxWnNHEY wJs++f9XKUvKZEsvx7jx2KQ9foKVqTM2kgff8qy+7FeUm15YpNeSpbl7AlbusFIqau3m D7q96TSgaHPQoNM4Ua1T0uLTv/tjlaErS6w3lvfezTPAD/OGBnA8vO+14wlftnusGRLk CtwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=64VFRwU4TtnetAWWFluVQT7sxDwMlPCkbSS8qoi09NY=; b=B3QmJfKsHun5lLCRbx3A8fY7Dz+Pm8Oo4PkuIU4bnERnCyCL3sKHa0SHuZuspBZnt7 XqtyDYZzbetGbwDnotgVbU/fB7HF1fIyY2BL7Genx4TQ27TXcPnHvZSQmIP+F7rgVJNW x0yLB+eXBfJBsMNVnCtXcDbmmyF2//KGME17BJKKc7VR73RZUZ/MjBpT69qIeWfZ3crL qZmOGusbuYQqqCEppFf8h2ccVuJYlqN1O0nSTRg8MRXRk7L/wNZt7uIlOju1F5FpZBVL 7EKwPk8ZGMMkVYCxiMDWcd0DSgfCzvWCgab/BSloL5yE0JWgnuYleAhJduLk/kh2rSil nBlQ== X-Gm-Message-State: AEkoouuHgr2ZgkPM1YS/p1zuGU00CoyB9yrhSD511RKDWc9QDEE/5XzX5AOeAr5OthXCzQ== X-Received: by 10.28.27.143 with SMTP id b137mr28875782wmb.12.1471450418382; Wed, 17 Aug 2016 09:13:38 -0700 (PDT) Received: from twisty.fritz.box (x5f70102d.dyn.telefonica.de. [95.112.16.45]) by smtp.gmail.com with ESMTPSA id g67sm27369623wme.5.2016.08.17.09.13.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Aug 2016 09:13:37 -0700 (PDT) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/radeon: Fix pageflipping of PRIME imported scanout bo's. Date: Wed, 17 Aug 2016 18:12:57 +0200 Message-Id: <1471450377-12274-3-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1471450377-12274-1-git-send-email-mario.kleiner.de@gmail.com> References: <1471450377-12274-1-git-send-email-mario.kleiner.de@gmail.com> Cc: michel.daenzer@amd.com, jglisse@redhat.com, bskeggs@redhat.com, alexander.deucher@amd.com, airlied@redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Scanout bo's which are dmabuf backed in RAM and imported via prime will not update their content with new rendering from the renderoffload gpu once they've been flipped onto the scanout once. The reason is that at preparation of first flip they get pinned into VRAM, then unpinned at some later point, but they stay in the VRAM memory domain, so updates to the system RAM dmabuf object by the exporting render offload gpu don't lead to updates of the content in VRAM - it becomes stale. For prime imported dmabufs we solve this by first pinning the bo into GTT, which will reset the bos domain back to GTT, then unpinning again, so the followup pinning into VRAM will actually upload an up to date display buffer from dmabuf GTT backing store. During the pinning into GTT, we skip the actual data move from VRAM to GTT to avoid a needless bo copy of stale image data. Signed-off-by: Mario Kleiner --- drivers/gpu/drm/radeon/radeon.h | 1 + drivers/gpu/drm/radeon/radeon_display.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_prime.c | 1 + drivers/gpu/drm/radeon/radeon_ttm.c | 14 ++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 5633ee3..c200e8a 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -508,6 +508,7 @@ struct radeon_bo { struct drm_gem_object gem_base; struct ttm_bo_kmap_obj dma_buf_vmap; + bool prime_imported; pid_t pid; struct radeon_mn *mn; diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c index c3206fb..1082267 100644 --- a/drivers/gpu/drm/radeon/radeon_display.c +++ b/drivers/gpu/drm/radeon/radeon_display.c @@ -550,6 +550,34 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc, DRM_ERROR("failed to reserve new rbo buffer before flip\n"); goto cleanup; } + + /* + * Repin into GTT in case of imported prime dmabuf, + * then unpin again. Restores source dmabuf location + * to GTT, where the actual dmabuf backing store gets + * updated by the exporting render offload gpu at swap. + */ + if (new_rbo->prime_imported) { + DRM_DEBUG_PRIME("Flip to prime imported dmabuf %p\n", new_rbo); + + r = radeon_bo_pin(new_rbo, RADEON_GEM_DOMAIN_GTT, NULL); + if (unlikely(r != 0)) { + DRM_ERROR("failed to gtt pin buffer %p before flip\n", + new_rbo); + } + else { + r = radeon_bo_unpin(new_rbo); + } + + if (unlikely(r != 0)) { + radeon_bo_unreserve(new_rbo); + r = -EINVAL; + DRM_ERROR("failed to gtt unpin buffer %p before flip\n", + new_rbo); + goto cleanup; + } + } + /* Only 27 bit offset for legacy CRTC */ r = radeon_bo_pin_restricted(new_rbo, RADEON_GEM_DOMAIN_VRAM, ASIC_IS_AVIVO(rdev) ? 0 : 1 << 27, &base); diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c index f3609c9..693c362 100644 --- a/drivers/gpu/drm/radeon/radeon_prime.c +++ b/drivers/gpu/drm/radeon/radeon_prime.c @@ -69,6 +69,7 @@ struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev, ww_mutex_lock(&resv->lock, NULL); ret = radeon_bo_create(rdev, attach->dmabuf->size, PAGE_SIZE, false, RADEON_GEM_DOMAIN_GTT, 0, sg, resv, &bo); + bo->prime_imported = true; ww_mutex_unlock(&resv->lock); if (ret) return ERR_PTR(ret); diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 0c00e19..87b3f59 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -256,6 +256,7 @@ static int radeon_move_blit(struct ttm_buffer_object *bo, struct ttm_mem_reg *old_mem) { struct radeon_device *rdev; + struct radeon_bo *rbo; uint64_t old_start, new_start; struct radeon_fence *fence; unsigned num_pages; @@ -296,6 +297,19 @@ static int radeon_move_blit(struct ttm_buffer_object *bo, BUILD_BUG_ON((PAGE_SIZE % RADEON_GPU_PAGE_SIZE) != 0); num_pages = new_mem->num_pages * (PAGE_SIZE / RADEON_GPU_PAGE_SIZE); + + /* + * Prime imported dmabuf, previously used as scanout buffer in a page + * flip? If so, skip actual data move back from VRAM into GTT, as this + * would only copy back stale image data. + */ + rbo = container_of(bo, struct radeon_bo, tbo); + if (rbo->prime_imported && old_mem->mem_type == TTM_PL_VRAM && + new_mem->mem_type == TTM_PL_TT) { + DRM_DEBUG_PRIME("Skip for dmabuf back-move %p.\n", rbo); + num_pages = 0; + } + fence = radeon_copy(rdev, old_start, new_start, num_pages, bo->resv); if (IS_ERR(fence)) return PTR_ERR(fence);