[PATCH v2 2/2] drm/nouveau/dispnv50: read back hardware mode timings on probe

From: Munique Feitoza

Date: Sun Dec 06 2026 - 03:32:14 EST


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@xxxxxxxxx>
---
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