From patchwork Wed Mar 20 08:12:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 10860973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A4F21708 for ; Wed, 20 Mar 2019 08:12:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E83ED29A88 for ; Wed, 20 Mar 2019 08:12:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCA0A29A8B; Wed, 20 Mar 2019 08:12: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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 8821629A8A for ; Wed, 20 Mar 2019 08:12:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 03A2889C2A; Wed, 20 Mar 2019 08:12:41 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id C6CD589C21; Wed, 20 Mar 2019 08:12:38 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id 4so19406270wmf.5; Wed, 20 Mar 2019 01:12:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0my3y+HKklZy6/GUVU+KNU+8gr6/pylG567bPG14gp0=; b=lLM5h8pr5yIOlCwLOCVzZsDbpVkCBFZpDQmSXg+CA1hSjrJFAJpnA+UewboY5jrP2Z 042vACU1/TtQ33ueK8tAQnkKJstW35tf8c57IQdqvZTsRC/HMMVnRWNaCjAucj8HZYX8 NWl7FQ0LCFj0X2glVT8MxNZxMLQplZG2qwC7PhanapWUvlxAroXnD/C6/6qYIMdpD+YQ G/yEBbssc8M02tBDlJPqAFhRVfYwt6u/W5ek/Gw2e9G2qOPq+sTYy83LMHvwRWRu5C/Q dpG0MSp5PNBYO5HgNf5XmK3zfYB9JzSmZA8aObKsM78aGozph21ODXjhntPImfNPXMKS TerQ== X-Gm-Message-State: APjAAAVDJGPKZZVWBKLrB1rD/ZHNZ5C2CNuL2BboAIUBTU989Xt+SA7a XEUsseGzvzQqCSicxi3Y9TA4FXO+ X-Google-Smtp-Source: APXvYqxLgTh1JXf0sQPHBqK2R+7B19i4NeDfY8ikuZFAeZDlxi8C6l943/K90zqgmSFP4tRnllv0WQ== X-Received: by 2002:a1c:5f08:: with SMTP id t8mr6802842wmb.65.1553069557339; Wed, 20 Mar 2019 01:12:37 -0700 (PDT) Received: from twisty.cin.medizin.uni-tuebingen.de (x4db928de.dyn.telefonica.de. [77.185.40.222]) by smtp.gmail.com with ESMTPSA id 132sm2227964wmd.27.2019.03.20.01.12.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 01:12:36 -0700 (PDT) From: Mario Kleiner To: amd-gfx@lists.freedesktop.org Subject: [PATCH 1/4] drm/amd/display: Prevent vblank irq disable while VRR is active. (v2) Date: Wed, 20 Mar 2019 09:12:08 +0100 Message-Id: <20190320081208.16672-1-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.17.1 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=0my3y+HKklZy6/GUVU+KNU+8gr6/pylG567bPG14gp0=; b=sme6Dtk6oeqtMjWSujV7Sc8PIoU5gYrSBb33BtT1r47eUQQATTiyi6BNvCDX35BHdN TfxyMp49+WXr5e3fWBPbgDXWKm5L15HQkigN0ztmmPmFOzLONwkfbONCMA0zEVszZBmv UVtVQGE926jU5Xh62WcXzNovLy+4fk3Twhg2HOTwQzCxEWgUO190dUC4wB/egY2e3hpd VBDMfQVyJdVqKqdwvzjx04jkoQedhacMXqVV0cqFjKU8bAXh4jW93ssBhUXMyTneH/SY ZIUll4j6wAeYNWtpbljqLXq9J+0P6soIWuI0IaIHd+b11BzkE0NtRnsn6CVmdAxKDjbk uPhg== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nicholas.kazlauskas@amd.com, dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP During VRR mode we can not allow vblank irq dis-/enable transitions, as an enable after a disable can happen at an arbitrary time during the video refresh cycle, e.g., with a high likelyhood inside vblank front-porch. An enable during front-porch would cause vblank timestamp updates/calculations which are completely bogus, given the code can't know when the vblank will end as long as we are in front-porch with no page flip completed. Hold a permanent vblank reference on the crtc while in active VRR mode to prevent a vblank disable, and drop the reference again when switching back to fixed refresh rate non-VRR mode. v2: Make sure transition is also handled if vrr is disabled and stream gets disabled in the same atomic commit. Suggested by Nicholas. Signed-off-by: Mario Kleiner --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index a718ac2..1c83e80 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -251,6 +251,12 @@ get_crtc_by_otg_inst(struct amdgpu_device *adev, return NULL; } +static inline bool amdgpu_dm_vrr_active(struct dm_crtc_state *dm_state) +{ + return dm_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE || + dm_state->freesync_config.state == VRR_STATE_ACTIVE_FIXED; +} + static void dm_pflip_high_irq(void *interrupt_params) { struct amdgpu_crtc *amdgpu_crtc; @@ -4716,6 +4722,31 @@ static void update_freesync_state_on_stream( (int)vrr_params.state); } +static void amdgpu_dm_handle_vrr_transition(struct dm_crtc_state *old_state, + struct dm_crtc_state *new_state) +{ + bool old_vrr_active = amdgpu_dm_vrr_active(old_state); + bool new_vrr_active = amdgpu_dm_vrr_active(new_state); + + if (!old_vrr_active && new_vrr_active) { + /* Transition VRR inactive -> active: + * While VRR is active, we must not disable vblank irq, as a + * reenable after disable would compute bogus vblank/pflip + * timestamps if it likely happened inside display front-porch. + */ + drm_crtc_vblank_get(new_state->base.crtc); + DRM_DEBUG_DRIVER("%s: crtc=%u VRR off->on: Get vblank ref\n", + __func__, new_state->base.crtc->base.id); + } else if (old_vrr_active && !new_vrr_active) { + /* Transition VRR active -> inactive: + * Allow vblank irq disable again for fixed refresh rate. + */ + drm_crtc_vblank_put(new_state->base.crtc); + DRM_DEBUG_DRIVER("%s: crtc=%u VRR on->off: Drop vblank ref\n", + __func__, new_state->base.crtc->base.id); + } +} + static void amdgpu_dm_commit_planes(struct drm_atomic_state *state, struct dc_state *dc_state, struct drm_device *dev, @@ -5250,6 +5281,11 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state) dm_new_crtc_state = to_dm_crtc_state(new_crtc_state); dm_old_crtc_state = to_dm_crtc_state(old_crtc_state); + + /* Handle vrr on->off / off->on transitions */ + amdgpu_dm_handle_vrr_transition(dm_old_crtc_state, + dm_new_crtc_state); + modeset_needed = modeset_required( new_crtc_state, dm_new_crtc_state->stream,