Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp942543imu; Wed, 9 Jan 2019 08:54:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN4s3t83CtzajC0eNHApgxNYwzK1/tw1wG+7EJJQ4nMhYT0skSoMrRqugxa9Fio8PffSiRRT X-Received: by 2002:a17:902:2f03:: with SMTP id s3mr6601305plb.277.1547052844676; Wed, 09 Jan 2019 08:54:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547052844; cv=none; d=google.com; s=arc-20160816; b=gqxaib2y2kE8eswOc0ifq56mJ8H9bSDPknPoUgIUzE6AWsgx1fufMXOj85ynYcRPBt 5LQ6f0Kq/z3AKhmnkUFnmJIaUlX2EN/wairiKlRaS52VQXYHAd1KC2aKCH652qw1bges VmntDnrGA/JHEK6By+apYz5ulN88mr41+0NHrYXLM9g/YLo7sTYMFdNJdL5Q0bxFmCHt E4qw1ACfRLx5TINzycUnryxegjf+cKFOJf2xmisN+1H+MM54AqK6Kagf+Kue6X4tbM6Z WxUAbVlVOsQR4vSPexyDDZ+0j1ZHr5hQLx+e2vfiQRhmELrmohuRyxEzvIFUz65SUeSO LmGw== 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 :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=pP92ldl0oDIMbsyzw88vSBnylK/+/0k+bD8NIiyGgvQ=; b=UX4zsuLCO8y054hNsnRA9tIT3N2+t1wKco4K3xNNfOT8s2LUzAY41rQazhG3suONIL h9/2ta6eO5C7yYXyZZsj+Pbu39mt7h2Tj6us02f++Qiqj/yXysOD7y6gvWEOH05/SvlN 4+JJcCgIhZMskrw+nVbP1W0TtK8uG0VzSDYacT6U2QxaQIfFoStsB6q2CfVPFX1i7575 FNbXTbF1jdMtj7cRmrEO60YJuTFJ9a+4xXo+ubWCd3JzkaeBh6vaTfuB/lMB5YCxMoBP uxmA5oU1XCtZQnKmOqOEbZvOXafmXy/qzYceYEiaLaLT8ea6jhlOxpoFwwqMm9bnP5K+ 8Ezg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m30si7976552pff.158.2019.01.09.08.53.48; Wed, 09 Jan 2019 08:54:04 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726438AbfAIQwX (ORCPT + 99 others); Wed, 9 Jan 2019 11:52:23 -0500 Received: from mail.bootlin.com ([62.4.15.54]:49068 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfAIQwX (ORCPT ); Wed, 9 Jan 2019 11:52:23 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id 2C39A20750; Wed, 9 Jan 2019 17:52:21 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.2 Received: from aptenodytes (aaubervilliers-681-1-45-241.w90-88.abo.wanadoo.fr [90.88.163.241]) by mail.bootlin.com (Postfix) with ESMTPSA id B7B2F20712; Wed, 9 Jan 2019 17:52:20 +0100 (CET) Message-ID: Subject: Re: [PATCH v3 1/4] drm/vc4: Wait for display list synchronization when completing commit From: Paul Kocialkowski To: Daniel Vetter Cc: dri-devel , Linux Kernel Mailing List , Eric Anholt , David Airlie , Maxime Ripard , Thomas Petazzoni , Eben Upton , Boris Brezillon Date: Wed, 09 Jan 2019 17:52:20 +0100 In-Reply-To: References: <20190108145056.2276-1-paul.kocialkowski@bootlin.com> <20190108145056.2276-2-paul.kocialkowski@bootlin.com> Organization: Bootlin Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, On Tue, 2019-01-08 at 19:21 +0100, Daniel Vetter wrote: > On Tue, Jan 8, 2019 at 3:51 PM Paul Kocialkowski > wrote: > > During an atomic commit, the HVS is configured with a display list > > for the channel matching the associated CRTC. The Pixel Valve (CRTC) > > and encoder are also configured for the new setup at that time. > > While the Pixel Valve and encoder are reconfigured synchronously, the > > HVS is only reconfigured after the display list address (DISPLIST) has > > been updated to the current display list address (DISPLACTX), which is > > the responsibility of the hardware. > > > > The time frame during which the HVS is still running on its previous > > configuration but the CRTC and encoder have been reconfigured already > > can lead to a number of synchronization issues. They will eventually > > cause errors reported on the FIFOs, such as underruns. > > > > With underrun detection enabled (from Boris Brezillon's series), this > > leads to unreliable underrun detection with random false positives. > > > > To ensure a coherent state, wait for each enabled channel of the HVS > > to synchronize its current display list address. This fixes the issue > > of random underrun reporting on commits. > > > > Signed-off-by: Paul Kocialkowski > > --- > > drivers/gpu/drm/vc4/vc4_drv.h | 1 + > > drivers/gpu/drm/vc4/vc4_hvs.c | 17 +++++++++++++++++ > > drivers/gpu/drm/vc4/vc4_kms.c | 2 ++ > > drivers/gpu/drm/vc4/vc4_regs.h | 2 ++ > > 4 files changed, 22 insertions(+) > > > > diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h > > index c24b078f0593..955f157f5ad0 100644 > > --- a/drivers/gpu/drm/vc4/vc4_drv.h > > +++ b/drivers/gpu/drm/vc4/vc4_drv.h > > @@ -772,6 +772,7 @@ void vc4_irq_reset(struct drm_device *dev); > > extern struct platform_driver vc4_hvs_driver; > > void vc4_hvs_dump_state(struct drm_device *dev); > > int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused); > > +void vc4_hvs_sync_dlist(struct drm_device *dev); > > > > /* vc4_kms.c */ > > int vc4_kms_load(struct drm_device *dev); > > diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c > > index 5d8c749c9749..1ba60b8e0c2d 100644 > > --- a/drivers/gpu/drm/vc4/vc4_hvs.c > > +++ b/drivers/gpu/drm/vc4/vc4_hvs.c > > @@ -166,6 +166,23 @@ static int vc4_hvs_upload_linear_kernel(struct vc4_hvs *hvs, > > return 0; > > } > > > > +void vc4_hvs_sync_dlist(struct drm_device *dev) > > +{ > > + struct vc4_dev *vc4 = to_vc4_dev(dev); > > + unsigned int i; > > + int ret; > > + > > + for (i = 0; i < SCALER_CHANNELS_COUNT; i++) { > > + if (!(HVS_READ(SCALER_DISPCTRLX(i)) & SCALER_DISPCTRLX_ENABLE)) > > + continue; > > + > > + ret = wait_for(HVS_READ(SCALER_DISPLACTX(i)) == > > + HVS_READ(SCALER_DISPLISTX(i)), 1000); > > + WARN(ret, "Timeout waiting for channel %d display list sync\n", > > + i); > > + } > > +} > > + > > static int vc4_hvs_bind(struct device *dev, struct device *master, void *data) > > { > > struct platform_device *pdev = to_platform_device(dev); > > diff --git a/drivers/gpu/drm/vc4/vc4_kms.c b/drivers/gpu/drm/vc4/vc4_kms.c > > index 0490edb192a1..2d66a2b57a91 100644 > > --- a/drivers/gpu/drm/vc4/vc4_kms.c > > +++ b/drivers/gpu/drm/vc4/vc4_kms.c > > @@ -155,6 +155,8 @@ vc4_atomic_complete_commit(struct drm_atomic_state *state) > > > > drm_atomic_helper_commit_hw_done(state); > > > > + vc4_hvs_sync_dlist(dev); > > From your description I'd have guessed you want this between when you > update the planes and the crtc, so somewhere between commit_planes() > and commit_modeset_enables(). At least I have no idea how waiting here > can prevent underruns, by this point there's no further hw programming > happening. One thing that I did not mention is that the display list (that configures the planes) is only set at crtc_enable time (and taken into account by the hardware later). However, even calling vc4_hvs_sync_dlist right at the end of crtc_enable doesn't do either (the old display list just sticks). It only seems to work after the HDMI encoder enable step and I don't know any good reason why. I didn't find any description of when that dlist sync mechanism is supposed to take place and what particular event triggers it. Perhaps it is triggered by a signal originating from the encoder? If anyone has insight on the hardware, feel free to shed some light here :) Cheers and thanks for the review, Paul > Only exception is if you have an IOMMU which can fault, in > which case the cleanup_planes might remove the buffers prematurely. > But if that's the problem, then your semantics of the flip_done event > are wrong - when flip_done is signalled, the hw must have stopped > scanning out the old planes, since userspace expects to be able to > start overwriting/reusing them. > -Daniel > > > + > > drm_atomic_helper_wait_for_flip_done(dev, state); > > > > drm_atomic_helper_cleanup_planes(dev, state); > > diff --git a/drivers/gpu/drm/vc4/vc4_regs.h b/drivers/gpu/drm/vc4/vc4_regs.h > > index 931088014272..50c653309aec 100644 > > --- a/drivers/gpu/drm/vc4/vc4_regs.h > > +++ b/drivers/gpu/drm/vc4/vc4_regs.h > > @@ -212,6 +212,8 @@ > > > > #define PV_HACT_ACT 0x30 > > > > +#define SCALER_CHANNELS_COUNT 3 > > + > > #define SCALER_DISPCTRL 0x00000000 > > /* Global register for clock gating the HVS */ > > # define SCALER_DISPCTRL_ENABLE BIT(31) > > -- > > 2.20.1 > > > > -- Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com