Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5136769imu; Tue, 8 Jan 2019 12:10:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN40j9LMK2z0+UMyTP0Bdn7kma6Jsrt4waESeZoNiAS2jy/FDePQJI1MPWBpYsojPBLTUMEO X-Received: by 2002:a63:7c13:: with SMTP id x19mr2606764pgc.336.1546978227085; Tue, 08 Jan 2019 12:10:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546978227; cv=none; d=google.com; s=arc-20160816; b=z6jHR3yN7/NSCG9hf5M/NU44ya64QOd/gvizzrLqLvzKsZ6WaVVLSt4rhhbbpsqXLE dzcEdLwkSR8xsfbKXQ4m+iMectvoPSXDqJ2TyaFH+CipVO+I+sIdtuzZvAXjJe/a5gEn MEeAg2zGXop0VD1uqlha40dbYhO3ZOBK7nM1gqXClJ8rALDaT3Kfm6VcSZ/IGA9Vrb4I 4JWm0wjWV7CBIgTgW6z6t7NWyr8FaS5L+ktSZk1NTaHhes4YChuc8tZg0YWc4/VGyryr gec5TLwgEOyZEzjE9ncsTGSywWgcJKjz9D1n+0E4iQGddLJWO9t5kUzmeu0wOzMvPfWv iymg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ekHZ16iTO59ceH/FNyMe6WG4nDTPSHxD/17HXynoq1c=; b=xAMdhOd8m5J7Fq4xUK9SJcgqkdLEDUV8TjVt16QL2a75jtet+1GeksDu03YuSdgsTZ qaejdvXYAZaUqjaM0DQqcPBdE3zQpGFLkvAdXcuYXLajYpryl2D8xOPRjKknS2Nm9pNF eZ7zvkZbuz8HhPWDd2sHR0qw+y1YZAhQ+I18EI9btfah76SL9mYpp4sH4/sHscks1m2N Ahrp1mt71HIfYOcwPgpoQOUs0iVxJ3DfDS3LffMkzxNzFSBZnMGGNSmMvg+puagFVV8d nO+P5xH4hjHGUz2LWhrkRyr4RUpEpaMrBAKQUfycD8SHPZkw6q0NLfTl355Wka+ZtOE1 GYEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p6+I9fol; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s38si3640913pga.38.2019.01.08.12.10.11; Tue, 08 Jan 2019 12:10:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p6+I9fol; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729728AbfAHT1g (ORCPT + 99 others); Tue, 8 Jan 2019 14:27:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:33794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729711AbfAHT1c (ORCPT ); Tue, 8 Jan 2019 14:27:32 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5220A2173C; Tue, 8 Jan 2019 19:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975652; bh=OGaIugmgZ3J/K8vadnwfwUTqckxLGgZ8rpLqOd726cI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p6+I9folW+7FobtM6bhGkirIq/QNS27dSbY8eZGZccPb202CJVCsLRqj0q3Jsjjr6 kpGcjij1tdiZ7lv0dEMbnf/wu7FPUYrt3J6bCsbKRHjGwH2S3hAFyjQ980BiiU6LSb bFMPE7Qeh/EEuyHV9KojNZ02RWq1d+e9yJg8pw1A= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nicholas Kazlauskas , Alex Deucher , Sasha Levin , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 4.20 034/117] drm/amdgpu: Correct get_crtc_scanoutpos behavior when vpos >= vtotal Date: Tue, 8 Jan 2019 14:25:02 -0500 Message-Id: <20190108192628.121270-34-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Kazlauskas [ Upstream commit 520f08df45fbe300ed650da786a74093d658b7e1 ] When variable refresh rate is active the hardware counter can return a position >= vtotal. This results in a vpos being returned from amdgpu_display_get_crtc_scanoutpos that's a positive value. The positive value indicates to the caller that the display is currently in scanout when the display is actually still in vblank. This is because the vfront porch duration is unknown with variable refresh active and will end when either a page flip occurs or the timeout specified by the driver/display is reached. The behavior of the amdgpu_display_get_crtc_scanoutpos remains the same when the position is below vtotal. When the position is above vtotal the function will return a value that is effectively -vbl_end, the size of the vback porch. The only caller affected by this change is the DRM helper for calculating vblank timestamps. This change corrects behavior for calculating the page flip timestamp from being the previous timestamp to the calculation to the next timestamp when position >= vtotal. Signed-off-by: Nicholas Kazlauskas Reviewed-by: Harry Wentland Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c index 686a26de50f9..9c940bbed608 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c @@ -857,7 +857,12 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev, /* Inside "upper part" of vblank area? Apply corrective offset if so: */ if (in_vbl && (*vpos >= vbl_start)) { vtotal = mode->crtc_vtotal; - *vpos = *vpos - vtotal; + + /* With variable refresh rate displays the vpos can exceed + * the vtotal value. Clamp to 0 to return -vbl_end instead + * of guessing the remaining number of lines until scanout. + */ + *vpos = (*vpos < vtotal) ? (*vpos - vtotal) : 0; } /* Correct for shifted end of vbl at vbl_end. */ -- 2.19.1