From patchwork Fri Mar 29 12:00:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 10876943 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 478DF14DE for ; Fri, 29 Mar 2019 12:02:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33CC828A7C for ; Fri, 29 Mar 2019 12:02:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2856429114; Fri, 29 Mar 2019 12:02:51 +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 C723C28A7C for ; Fri, 29 Mar 2019 12:02:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8ED4C6E8D7; Fri, 29 Mar 2019 12:02:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id 60A436E8D0; Fri, 29 Mar 2019 12:02:48 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id z11so2294310wmi.0; Fri, 29 Mar 2019 05:02:48 -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:in-reply-to :references; bh=Z5ZUq7zAAwZvyoC5vLeFQ8ySX3qttA4lF1Pw5vMQ/HU=; b=jZLlgGZHw/J4H1Awds0Rvn4KAU2njEUsMluFVL0lbYy+ZOjx+dPiOQU/1rj0PHgD14 XBmhXfQCDtey1VeY75jWK7Iv24+2oeQPYSiW4tfxoCCFQ49WftTSERczcYdgtEyP0tvn UvbKbKGT7vUoX/pu/T2VGiDtKjvzR/69gBMLGoAqbWp9jEN9Po6C7Mu19f696zA7RPnu WzGJmme3GdhJbeDVNyTUysvvG2jyOz3Eo8jhuNUZDKglgx6CMyfz27rFjxC3AY1kCP4j bGSfM7EkWG3U3aslx0z9b+N+4pbuct9d2qaWeEY1MnlVL01n/khwhdqF0iBC5jEvUdlJ LV5A== X-Gm-Message-State: APjAAAW9WURG5ctTVlgzPILTilDxRzvvgOF1wJjS+naNaMSJISCjb/+U crYtBdpihMtfkD/g1pT2Wf0uPqNv X-Google-Smtp-Source: APXvYqw5zEYVMiGK05RiLiBGwqVy++JF9PaqCj7dDXMBN01ptih8Da92082F+LORQaYzMWWc63pusg== X-Received: by 2002:a1c:7706:: with SMTP id t6mr3436165wmi.141.1553860906856; Fri, 29 Mar 2019 05:01:46 -0700 (PDT) Received: from twisty.cin.medizin.uni-tuebingen.de ([2a01:c22:d02f:4b00:e9fd:d3f1:412c:598a]) by smtp.gmail.com with ESMTPSA id z8sm1839358wrh.80.2019.03.29.05.01.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 05:01:46 -0700 (PDT) From: Mario Kleiner To: amd-gfx@lists.freedesktop.org Subject: [PATCH 2/5] drm/amd/display: Prevent vblank irq disable while VRR is active. (v3) Date: Fri, 29 Mar 2019 13:00:54 +0100 Message-Id: <20190329120057.1472-3-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190329120057.1472-1-mario.kleiner.de@gmail.com> References: <20190329120057.1472-1-mario.kleiner.de@gmail.com> 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:in-reply-to:references; bh=Z5ZUq7zAAwZvyoC5vLeFQ8ySX3qttA4lF1Pw5vMQ/HU=; b=egQG8FNabotf06i2Yh2HE0DIkCpU7CCP28NOBOKx+jvsPOU3J1mk3vupPZI7P0X9AF VCQdRj0WVs4SMpmpRdyM989mBN5BfQhuP42w7/Iiez2nZrsIH/CQ8LyYEx6Kl2EMjPkb ljuskJtXq/GxG5d0eAO34zc3olNBE1mE9szW4GnECLyWvc/5MoSmZEK5rpMmhkxvTzTn 4DphBR8DM0gJgXjcWgv8hQlKXO5kSIqfhs1voZ2QfAKtUCUa3yC4WkglRUp8toMi0ycI FWTwRezPodgiRMznLEDJTKe7H1l4CUWZ89eDFFygtun4aSWQkRmDKtXOTXO3ugssuIsB OGqg== 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 by moving the call to the transition function outside of plane commit. Suggested by Nicholas. v3: Trivial rebase onto previous patch. Signed-off-by: Mario Kleiner Reviewed-by: Nicholas Kazlauskas --- .../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 6528258f8975..6c413bc012af 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; @@ -4737,6 +4743,31 @@ static void pre_update_freesync_state_on_stream( new_crtc_state->vrr_params = vrr_params; } +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, @@ -5277,6 +5308,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,