* [PATCH v2 1/2] drm/nouveau/nvif: add NVIF_HEAD_V0_STATE method for head timing readback
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 ` Munique Feitoza
2026-12-06 8:31 ` [PATCH v2 2/2] drm/nouveau/dispnv50: read back hardware mode timings on probe Munique Feitoza
1 sibling, 0 replies; 4+ messages in thread
From: Munique Feitoza @ 2026-12-06 8:31 UTC (permalink / raw)
To: Lyude Paul, Danilo Krummrich
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, nouveau, dri-devel, linux-kernel,
Munique Feitoza
Add NVIF_HEAD_V0_STATE and nvif_head_state() to expose the hardware head
timings and pixel clock already read by nvkm_head_func.state() to the
DRM client layer.
Signed-off-by: Munique Feitoza <muniquefeitoz4@gmail.com>
---
drivers/gpu/drm/nouveau/include/nvif/head.h | 13 ++++++++++
drivers/gpu/drm/nouveau/include/nvif/if0013.h | 17 +++++++++++++
drivers/gpu/drm/nouveau/nvif/head.c | 24 ++++++++++++++++++
.../gpu/drm/nouveau/nvkm/engine/disp/uhead.c | 25 +++++++++++++++++++
4 files changed, 79 insertions(+)
diff --git a/drivers/gpu/drm/nouveau/include/nvif/head.h b/drivers/gpu/drm/nouveau/include/nvif/head.h
index 3ec36999e9560d..699ac6f6c316b4 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/head.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/head.h
@@ -18,6 +18,19 @@ nvif_head_id(struct nvif_head *head)
return head->object.handle;
}
+struct nvif_head_state {
+ u32 hz;
+ u16 htotal;
+ u16 hsynce;
+ u16 hblanke;
+ u16 hblanks;
+ u16 vtotal;
+ u16 vsynce;
+ u16 vblanke;
+ u16 vblanks;
+};
+
+int nvif_head_state(struct nvif_head *head, struct nvif_head_state *state);
int nvif_head_vblank_event_ctor(struct nvif_head *, const char *name, nvif_event_func, bool wait,
struct nvif_event *);
#endif
diff --git a/drivers/gpu/drm/nouveau/include/nvif/if0013.h b/drivers/gpu/drm/nouveau/include/nvif/if0013.h
index 6756c7467ae4ef..892d2347cacddd 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/if0013.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/if0013.h
@@ -16,6 +16,7 @@ union nvif_head_event_args {
};
#define NVIF_HEAD_V0_SCANOUTPOS 0x00
+#define NVIF_HEAD_V0_STATE 0x01
union nvif_head_scanoutpos_args {
struct nvif_head_scanoutpos_v0 {
@@ -32,4 +33,20 @@ union nvif_head_scanoutpos_args {
__u16 hline;
} v0;
};
+
+union nvif_head_state_args {
+ struct nvif_head_state_v0 {
+ __u8 version;
+ __u8 pad01[3];
+ __u32 hz;
+ __u16 htotal;
+ __u16 hsynce;
+ __u16 hblanke;
+ __u16 hblanks;
+ __u16 vtotal;
+ __u16 vsynce;
+ __u16 vblanke;
+ __u16 vblanks;
+ } v0;
+};
#endif
diff --git a/drivers/gpu/drm/nouveau/nvif/head.c b/drivers/gpu/drm/nouveau/nvif/head.c
index f00e01d232db43..e751f73e56f2df 100644
--- a/drivers/gpu/drm/nouveau/nvif/head.c
+++ b/drivers/gpu/drm/nouveau/nvif/head.c
@@ -26,6 +26,30 @@
#include <nvif/class.h>
#include <nvif/if0013.h>
+int
+nvif_head_state(struct nvif_head *head, struct nvif_head_state *state)
+{
+ struct nvif_head_state_v0 args;
+ int ret;
+
+ args.version = 0;
+
+ ret = nvif_object_mthd(&head->object, NVIF_HEAD_V0_STATE, &args, sizeof(args));
+ if (ret)
+ return ret;
+
+ state->hz = args.hz;
+ state->htotal = args.htotal;
+ state->hsynce = args.hsynce;
+ state->hblanke = args.hblanke;
+ state->hblanks = args.hblanks;
+ state->vtotal = args.vtotal;
+ state->vsynce = args.vsynce;
+ state->vblanke = args.vblanke;
+ state->vblanks = args.vblanks;
+ return 0;
+}
+
int
nvif_head_vblank_event_ctor(struct nvif_head *head, const char *name, nvif_event_func func,
bool wait, struct nvif_event *event)
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/uhead.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/uhead.c
index f072cec1604028..4181713fabb6f7 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/uhead.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/uhead.c
@@ -71,6 +71,30 @@ nvkm_uhead_mthd_scanoutpos(struct nvkm_head *head, void *argv, u32 argc)
return 0;
}
+static int
+nvkm_uhead_mthd_state(struct nvkm_head *head, void *argv, u32 argc)
+{
+ union nvif_head_state_args *args = argv;
+
+ if (argc != sizeof(args->v0) || args->v0.version != 0)
+ return -ENOSYS;
+
+ if (!head->func->state)
+ return -EOPNOTSUPP;
+
+ head->func->state(head, &head->arm);
+ args->v0.hz = head->arm.hz;
+ args->v0.htotal = head->arm.htotal;
+ args->v0.hsynce = head->arm.hsynce;
+ args->v0.hblanke = head->arm.hblanke;
+ args->v0.hblanks = head->arm.hblanks;
+ args->v0.vtotal = head->arm.vtotal;
+ args->v0.vsynce = head->arm.vsynce;
+ args->v0.vblanke = head->arm.vblanke;
+ args->v0.vblanks = head->arm.vblanks;
+ return 0;
+}
+
static int
nvkm_uhead_mthd(struct nvkm_object *object, u32 mthd, void *argv, u32 argc)
{
@@ -78,6 +102,7 @@ nvkm_uhead_mthd(struct nvkm_object *object, u32 mthd, void *argv, u32 argc)
switch (mthd) {
case NVIF_HEAD_V0_SCANOUTPOS: return nvkm_uhead_mthd_scanoutpos(head, argv, argc);
+ case NVIF_HEAD_V0_STATE: return nvkm_uhead_mthd_state(head, argv, argc);
default:
return -EINVAL;
}
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/2] drm/nouveau/dispnv50: read back hardware mode timings on probe
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
1 sibling, 0 replies; 4+ messages in thread
From: Munique Feitoza @ 2026-12-06 8:31 UTC (permalink / raw)
To: Lyude Paul, Danilo Krummrich
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, nouveau, dri-devel, linux-kernel,
Munique Feitoza
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
^ permalink raw reply [flat|nested] 4+ messages in thread