mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Munique Feitoza <muniquefeitoz4@gmail.com>
To: Lyude Paul <lyude.paul@maintainer.cc>,
	Danilo Krummrich <dakr@kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org,
	Munique Feitoza <muniquefeitoz4@gmail.com>
Subject: [PATCH v2 2/2] drm/nouveau/dispnv50: read back hardware mode timings on probe
Date: Sun,  6 Dec 2026 05:31:34 -0300	[thread overview]
Message-ID: <20261206083134.6503-3-muniquefeitoz4@gmail.com> (raw)
In-Reply-To: <20261206083134.6503-1-muniquefeitoz4@gmail.com>

When inheriting an active firmware display output in
nv50_display_read_hw_or_state(), reconstruct the CRTC's mode and
adjusted_mode from the hardware head timings via nvif_head_state(),
initialize timestamping constants, and enable vblank state.

This prevents non-modeset atomic commits (such as
drm_mode_gamma_set_ioctl() from plymouthd) before the first modeset
from seeing adjusted_mode.crtc_clock == 0 and triggering dotclock = 0
errors, drm_vblank.c warnings, and vblank refcount mismatches.

Tested on NVIDIA GF108 (Fermi, dispnv50).

Fixes: 1b477f42285e ("drm/nouveau/kms: Add INHERIT ioctl to nvkm/nvif for reading IOR state")
Signed-off-by: Munique Feitoza <muniquefeitoz4@gmail.com>
---
 drivers/gpu/drm/nouveau/dispnv50/disp.c | 45 +++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c b/drivers/gpu/drm/nouveau/dispnv50/disp.c
index e91130f93db670..671a77166abdd5 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
@@ -2685,6 +2685,50 @@ nv50_display_fini(struct drm_device *dev, bool runtime, bool suspend)
 		cancel_work_sync(&drm->hpd_work);
 }
 
+static void
+nv50_head_read_hw_mode(struct drm_crtc *crtc, struct nv50_head_atom *armh)
+{
+	struct drm_display_mode *mode = &armh->state.mode;
+	struct nvif_head_state hw;
+	u16 hsync_start, hsync_end, vsync_start, vsync_end;
+	int ret;
+
+	ret = nvif_head_state(&nv50_head(crtc)->base.head, &hw);
+	if (ret)
+		return;
+
+	if (!hw.htotal || !hw.vtotal || !hw.hz ||
+	    hw.hblanks <= hw.hblanke || hw.vblanks <= hw.vblanke ||
+	    hw.hblanke + 1 >= hw.htotal || hw.vblanke + 1 >= hw.vtotal)
+		return;
+
+	hsync_start = hw.htotal - hw.hblanke - 1;
+	hsync_end = hsync_start + hw.hsynce + 1;
+	vsync_start = hw.vtotal - hw.vblanke - 1;
+	vsync_end = vsync_start + hw.vsynce + 1;
+
+	if (hsync_end > hw.htotal || vsync_end > hw.vtotal)
+		return;
+
+	mode->hdisplay = hw.hblanks - hw.hblanke;
+	mode->hsync_start = hsync_start;
+	mode->hsync_end = hsync_end;
+	mode->htotal = hw.htotal;
+
+	mode->vdisplay = hw.vblanks - hw.vblanke;
+	mode->vsync_start = vsync_start;
+	mode->vsync_end = vsync_end;
+	mode->vtotal = hw.vtotal;
+
+	mode->clock = DIV_ROUND_CLOSEST(hw.hz, 1000);
+	mode->type = DRM_MODE_TYPE_DRIVER;
+	drm_mode_set_name(mode);
+	drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V | CRTC_STEREO_DOUBLE);
+	drm_mode_copy(&armh->state.adjusted_mode, mode);
+	drm_calc_timestamping_constants(crtc, &armh->state.adjusted_mode);
+	drm_crtc_vblank_on(crtc);
+}
+
 static inline void
 nv50_display_read_hw_or_state(struct drm_device *dev, struct nv50_disp *disp,
 			      struct nouveau_encoder *outp)
@@ -2751,6 +2795,7 @@ nv50_display_read_hw_or_state(struct drm_device *dev, struct nv50_disp *disp,
 	armh->state.connector_mask = drm_connector_mask(conn);
 	armh->state.active = true;
 	armh->state.enable = true;
+	nv50_head_read_hw_mode(crtc, armh);
 	pm_runtime_get_noresume(dev->dev);
 
 	outp->crtc = crtc;
-- 
2.56.1


      parent reply	other threads:[~2026-12-06  8:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 17:25 [PATCH] drm/nouveau/dispnv50: skip vblank and timestamp constants when dotclock is 0 Munique Feitoza
2026-12-06  8:31 ` [PATCH v2 0/2] drm/nouveau/dispnv50: read back inherited firmware head mode timings Munique Feitoza
2026-12-06  8:31   ` [PATCH v2 1/2] drm/nouveau/nvif: add NVIF_HEAD_V0_STATE method for head timing readback Munique Feitoza
2026-12-06  8:31   ` Munique Feitoza [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206083134.6503-3-muniquefeitoz4@gmail.com \
    --to=muniquefeitoz4@gmail.com \
    --cc=airlied@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude.paul@maintainer.cc \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®