From patchwork Tue Dec 4 14:26:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathyush K X-Patchwork-Id: 1837901 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 683C6DF230 for ; Tue, 4 Dec 2012 14:12:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 491E3E6397 for ; Tue, 4 Dec 2012 06:12:17 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id E5D54E637B for ; Tue, 4 Dec 2012 06:04:48 -0800 (PST) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MEI00ATGF3VRBM0@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 04 Dec 2012 23:04:47 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.123]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 83.BF.12699.FF20EB05; Tue, 04 Dec 2012 23:04:47 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-65-50be02ff7d65 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 53.BF.12699.FF20EB05; Tue, 04 Dec 2012 23:04:47 +0900 (KST) Received: from localhost.localdomain ([107.108.73.106]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MEI00F96F2AW000@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 04 Dec 2012 23:04:47 +0900 (KST) From: Prathyush K To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm/exynos: modify wait for vsync functions to use wait queues Date: Tue, 04 Dec 2012 19:56:49 +0530 Message-id: <1354631211-30346-1-git-send-email-prathyush.k@samsung.com> X-Mailer: git-send-email 1.7.0.4 DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKLMWRmVeSWpSXmKPExsWyRsSkWvc/074Agx2vlS2ufH3P5sDocb/7 OFMAYxSXTUpqTmZZapG+XQJXxrNNlxkLzmhU/Li9mrWBcbNiFyMnh4SAicTUXYuZIWwxiQv3 1rN1MXJxCAksZZT4OXEnO0zRkndHGSES0xkljt8/yg7hrGaSOH97FhNIFZuAtsSvOXdZQWwR AWWJvxNXMYLYzAISEkfaz7KB2MICoRLXJ90Hi7MIqEp8fP8JrJ5XwF3i6caHbBDbFCRalx1i h6gRkPg2+RBLFyMHUFxWYtMBZpC9EgJ72CQ6rp5khaiXlDi44gbLBEbBBYwMqxhFUwuSC4qT 0nON9IoTc4tL89L1kvNzNzECw+r0v2fSOxhXNVgcYhTgYFTi4V3wYk+AEGtiWXFl7iFGCQ5m JRFehQ97A4R4UxIrq1KL8uOLSnNSiw8x+gBdMpFZSjQ5HxjyeSXxhsYm5qbGppZGRmampjiE lcR5mz1SAoQE0hNLUrNTUwtSi2DGMXFwSjUwxklcm9okfvUXE7PUd1eBXF7GkDWci4w9Pi2S XzFN/9nkKscvVXyno3cu5FfcuYd5yoHbxxgUK7UPN7TETt7Mb8te8YXx7M3mgE77VdpPy6+o RCz34TR9Hu0dq8qiYhg/eWt1Ds+iFu9VDVUVZy59v/ShY8PP3dum9azMqntoc1ZL61zUsptT lFiKMxINtZiLihMBo1IIcFgCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCLMWRmVeSWpSXmKPExsVy+t9jQd3/TPsCDGbelba48vU9mwOjx/3u 40wBjFENjDYZqYkpqUUKqXnJ+SmZeem2St7B8c7xpmYGhrqGlhbmSgp5ibmptkouPgG6bpk5 QGOVFMoSc0qBQgGJxcVK+naYJoSGuOlawDRG6PqGBMH1GBmggYQ1jBnPNl1mLDijUfHj9mrW BsbNil2MnBwSAiYSS94dZYSwxSQu3FvP1sXIxSEkMJ1R4vj9o+wQzmomifO3ZzGBVLEJaEv8 mnOXFcQWEVCW+DtxFVg3s4CExJH2s2wgtrBAqMT1SffB4iwCqhIf338Cq+cVcJd4uvEhG8Q2 BYnWZYfYJzByL2BkWMUomlqQXFCclJ5rpFecmFtcmpeul5yfu4kRHLTPpHcwrmqwOMQowMGo xMO74MWeACHWxLLiytxDjBIczEoivAof9gYI8aYkVlalFuXHF5XmpBYfYvQB2j6RWUo0OR8Y UXkl8YbGJuamxqaWJhYmZpY4hJXEeZs9UgKEBNITS1KzU1MLUotgxjFxcEo1ME5bkBUX2BN6 yLUjsVDMWtj/V0vWpUmf3+845PZ9bUGia+mzpZ9eXz6/5Nvv19/7m9I0bn358sj8yRun7O9l R7UK1DbEx3EZ1hUVHmqNsvNzm+v9J0Yh4tf/E4I23Xp3rzJeYdudkMS+b9W+u0+r7v7fZNjw 7R3/nftGTva6eg2Ktzmif3S8iVViKc5INNRiLipOBABaXJSuhwIAAA== X-CFilter-Loop: Reflected X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org It is more optimium to use wait queues while waiting for vsync so that the current task is put to sleep. This way, the task wont hog the CPU while waiting. We use wait_event_timeout and not an interruptible function since we dont want the function to exit when a signal is pending (e.g. drm release). This patch modifies the wait for vblank functions of both fimd and mixer. Also, the current fimd wait_for_vblank did not work in exynos5 since VIDCON1 has to be used in addition to timing base offset (0x20000). This patch also eliminates this problem. Signed-off-by: Prathyush K --- drivers/gpu/drm/exynos/exynos_drm_drv.h | 14 -------------- drivers/gpu/drm/exynos/exynos_drm_fimd.c | 21 +++++++++++++++++---- drivers/gpu/drm/exynos/exynos_mixer.c | 21 ++++++++++++++++----- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h b/drivers/gpu/drm/exynos/exynos_drm_drv.h index a4702a8..6bb8644 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.h +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h @@ -36,20 +36,6 @@ #define MAX_FB_BUFFER 4 #define DEFAULT_ZPOS -1 -#define _wait_for(COND, MS) ({ \ - unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \ - int ret__ = 0; \ - while (!(COND)) { \ - if (time_after(jiffies, timeout__)) { \ - ret__ = -ETIMEDOUT; \ - break; \ - } \ - } \ - ret__; \ -}) - -#define wait_for(COND, MS) _wait_for(COND, MS) - struct drm_device; struct exynos_drm_overlay; struct drm_connector; diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c index e2abae6..63f0d0f 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c +++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c @@ -101,6 +101,8 @@ struct fimd_context { u32 vidcon1; bool suspended; struct mutex lock; + wait_queue_head_t wait_vsync_queue; + atomic_t wait_vsync_event; struct exynos_drm_panel_info *panel; }; @@ -606,11 +608,16 @@ static void fimd_win_disable(struct device *dev, int zpos) static void fimd_wait_for_vblank(struct device *dev) { struct fimd_context *ctx = get_fimd_context(dev); - int ret; - ret = wait_for((__raw_readl(ctx->regs + VIDCON1) & - VIDCON1_VSTATUS_VSYNC), 50); - if (ret < 0) + atomic_set(&ctx->wait_vsync_event, 1); + + /* + * wait for FIMD to signal VSYNC interrupt or return after + * timeout which is set to 50ms (refresh rate of 20). + */ + if (!wait_event_timeout(ctx->wait_vsync_queue, + !atomic_read(&ctx->wait_vsync_event), + DRM_HZ/20)) DRM_DEBUG_KMS("vblank wait timed out.\n"); } @@ -677,6 +684,10 @@ static irqreturn_t fimd_irq_handler(int irq, void *dev_id) drm_handle_vblank(drm_dev, manager->pipe); fimd_finish_pageflip(drm_dev, manager->pipe); + /* set wait vsync event to zero and wake up queue. */ + atomic_set(&ctx->wait_vsync_event, 0); + DRM_WAKEUP(&ctx->wait_vsync_queue); + out: return IRQ_HANDLED; } @@ -967,6 +978,8 @@ static int __devinit fimd_probe(struct platform_device *pdev) ctx->vidcon1 = pdata->vidcon1; ctx->default_win = pdata->default_win; ctx->panel = panel; + DRM_INIT_WAITQUEUE(&ctx->wait_vsync_queue); + atomic_set(&ctx->wait_vsync_event, 0); subdrv = &ctx->subdrv; diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c index 50100cf..972281e 100644 --- a/drivers/gpu/drm/exynos/exynos_mixer.c +++ b/drivers/gpu/drm/exynos/exynos_mixer.c @@ -93,6 +93,8 @@ struct mixer_context { struct hdmi_win_data win_data[MIXER_WIN_NR]; enum mixer_version_id mxr_ver; void *parent_ctx; + wait_queue_head_t wait_vsync_queue; + atomic_t wait_vsync_event; }; struct mixer_drv_data { @@ -791,12 +793,16 @@ static void mixer_dpms(void *ctx, int mode) static void mixer_wait_for_vblank(void *ctx) { struct mixer_context *mixer_ctx = ctx; - struct mixer_resources *res = &mixer_ctx->mixer_res; - int ret; - ret = wait_for((mixer_reg_read(res, MXR_INT_STATUS) & - MXR_INT_STATUS_VSYNC), 50); - if (ret < 0) + atomic_set(&mixer_ctx->wait_vsync_event, 1); + + /* + * wait for MIXER to signal VSYNC interrupt or return after + * timeout which is set to 50ms (refresh rate of 20). + */ + if (!wait_event_timeout(mixer_ctx->wait_vsync_queue, + !atomic_read(&mixer_ctx->wait_vsync_event), + DRM_HZ/20)) DRM_DEBUG_KMS("vblank wait timed out.\n"); } @@ -957,6 +963,9 @@ static irqreturn_t mixer_irq_handler(int irq, void *arg) drm_handle_vblank(drm_hdmi_ctx->drm_dev, ctx->pipe); mixer_finish_pageflip(drm_hdmi_ctx->drm_dev, ctx->pipe); + + atomic_set(&ctx->wait_vsync_event, 0); + DRM_WAKEUP(&ctx->wait_vsync_queue); } out: @@ -1166,6 +1175,8 @@ static int __devinit mixer_probe(struct platform_device *pdev) drm_hdmi_ctx->ctx = (void *)ctx; ctx->vp_enabled = drv->is_vp_enabled; ctx->mxr_ver = drv->version; + DRM_INIT_WAITQUEUE(&ctx->wait_vsync_queue); + atomic_set(&ctx->wait_vsync_event, 0); platform_set_drvdata(pdev, drm_hdmi_ctx);