From patchwork Wed Dec 10 16:57:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 5470951 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D94419F30B for ; Wed, 10 Dec 2014 16:57:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D99602016C for ; Wed, 10 Dec 2014 16:57:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7794C2012B for ; Wed, 10 Dec 2014 16:57:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6B1F56E6C5; Wed, 10 Dec 2014 08:57:13 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f182.google.com (mail-qc0-f182.google.com [209.85.216.182]) by gabe.freedesktop.org (Postfix) with ESMTP id 5BCD86E6C1 for ; Wed, 10 Dec 2014 08:57:12 -0800 (PST) Received: by mail-qc0-f182.google.com with SMTP id r5so2497950qcx.27 for ; Wed, 10 Dec 2014 08:57:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id; bh=JXygnH1+vobw7FxvTSXnz4OZi/AZ7rMYEzV46mSdfng=; b=mA7baiDu65i8dBVazS+4IiTSVY7hS70X25Pq95695ODa8jq1ctqvO0grxY3VgOhyGe XmTMvZIuzjDEsuJwCoWJ4fb7qOcijzDjCyw0ynThdoq2T57qYrC6n1+VlOZcjXbMEPcH 5OKQuXFYoXMxIKIrE/9WQ5ejSdeT8Q0eq+QLD6jGSQ0Or119KQ/niTVNbnAGCFqOc33D LspWE81GOaDuvupeRiwsckYeic8f9cZdL18SmgHSWX3/wEEakO/FSQjrGCK2vzJttpFX 2nJo6o4WmyatNmvlIZJqwV8ofpIxwMJvmt0T+FevNiz3E8AofF1XI8VH0hual/myMfjZ ebEg== X-Received: by 10.224.121.142 with SMTP id h14mr10505170qar.80.1418230631520; Wed, 10 Dec 2014 08:57:11 -0800 (PST) Received: from localhost.localdomain ([191.8.83.128]) by mx.google.com with ESMTPSA id w75sm4699635qgd.14.2014.12.10.08.57.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Dec 2014 08:57:10 -0800 (PST) From: Gustavo Padovan To: linux-samsung-soc@vger.kernel.org Subject: [PATCH v2] drm/exynos/fimd: only finish pageflip if START == START_S Date: Wed, 10 Dec 2014 14:57:02 -0200 Message-Id: <1418230622-744-1-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 1.9.3 Cc: dri-devel@lists.freedesktop.org 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 From: Daniel Kurtz A framebuffer gets committed to FIMD's default window like this: exynos_drm_crtc_update() exynos_plane_commit() fimd_win_commit() fimd_win_commit() programs BUF_START[0]. At each vblank, FIMD hardware copies the value from BUF_START to BUF_START_S (BUF_START's shadow register), starts scanning out from BUF_START_S, and asserts its irq. This irq is handled by fimd_irq_handler(), which calls exynos_drm_crtc_finish_pageflip() to free the old buffer that FIMD just finished scanning out, and potentially commit the next pending flip. There is a race, however, if fimd_win_commit() programs BUF_START(0) between the actual vblank irq, and its corresponding fimd_irq_handler(). => FIMD vblank: BUF_START_S[0] := BUF_START[0], and irq asserted | => fimd_win_commit(0) writes new BUF_START[0] | exynos_drm_crtc_try_do_flip() marks exynos_fb as prepared => fimd_irq_handler() exynos_drm_crtc_finish_pageflip() sees prepared exynos_fb, and unmaps "old" fb ==> but, since BUF_START_S[0] still points to that "old" fb... ==> FIMD iommu fault This patch ensures that fimd_irq_handler() only calls exynos_drm_crtc_finish_pageflip() if any previously scheduled flip has really completed. This works because exynos_drm_crtc's flip fifo ensures that fimd_win_commit() is never called more than once per exynos_drm_crtc_finish_pageflip(). Signed-off-by: Daniel Kurtz Reviewed-by: Sean Paul Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/exynos/exynos_drm_fimd.c | 31 ++++++++++++++++++++++++------- include/video/samsung_fimd.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c index e5810d1..95bac27 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c +++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c @@ -55,6 +55,7 @@ #define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16) #define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8) +#define VIDWx_BUF_START_S(win, buf) (VIDW_BUF_START_S(buf) + (win) * 8) #define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8) #define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4) @@ -1039,6 +1040,7 @@ static irqreturn_t fimd_irq_handler(int irq, void *dev_id) { struct fimd_context *ctx = (struct fimd_context *)dev_id; u32 val, clear_bit; + u32 start, start_s; val = readl(ctx->regs + VIDINTCON1); @@ -1051,19 +1053,34 @@ static irqreturn_t fimd_irq_handler(int irq, void *dev_id) goto out; if (ctx->i80_if) { - exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe); - /* Exits triggering mode */ atomic_set(&ctx->triggering, 0); } else { drm_handle_vblank(ctx->drm_dev, ctx->pipe); + } + + /* + * Ensure finish_pageflip is called iff a pending flip has completed. + * This works around a race between a page_flip request and the latency + * between vblank interrupt and this irq_handler: + * => FIMD vblank: BUF_START_S[0] := BUF_START[0], and asserts irq + * | => fimd_win_commit(0) writes new BUF_START[0] + * | exynos_drm_crtc_try_do_flip() marks exynos_fb as prepared + * => fimd_irq_handler() + * exynos_drm_crtc_finish_pageflip() sees prepared exynos_fb, + * and unmaps "old" fb + * ==> but, since BUF_START_S[0] still points to that "old" fb... + * ==> FIMD iommu fault + */ + start = readl(ctx->regs + VIDWx_BUF_START(0, 0)); + start_s = readl(ctx->regs + VIDWx_BUF_START_S(0, 0)); + if (start == start_s) exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe); - /* set wait vsync event to zero and wake up queue. */ - if (atomic_read(&ctx->wait_vsync_event)) { - atomic_set(&ctx->wait_vsync_event, 0); - wake_up(&ctx->wait_vsync_queue); - } + /* set wait vsync event to zero and wake up queue. */ + if (atomic_read(&ctx->wait_vsync_event)) { + atomic_set(&ctx->wait_vsync_event, 0); + wake_up(&ctx->wait_vsync_queue); } out: diff --git a/include/video/samsung_fimd.h b/include/video/samsung_fimd.h index a20e4a3..f81d081 100644 --- a/include/video/samsung_fimd.h +++ b/include/video/samsung_fimd.h @@ -291,6 +291,7 @@ /* Video buffer addresses */ #define VIDW_BUF_START(_buff) (0xA0 + ((_buff) * 8)) +#define VIDW_BUF_START_S(_buff) (0x40A0 + ((_buff) * 8)) #define VIDW_BUF_START1(_buff) (0xA4 + ((_buff) * 8)) #define VIDW_BUF_END(_buff) (0xD0 + ((_buff) * 8)) #define VIDW_BUF_END1(_buff) (0xD4 + ((_buff) * 8))