Skip to contentSkip to conversation

drm/nouveau: add NVC57D output CSC and clamp range methods

PATCH In review Daniel Campos Ramos 2 participants 12 messages Sep 22 – Sep 23 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

cover drm/nouveau: HDMI output colour format and quantization range

Nouveau only ever outputs full-range RGB on HDMI. This series adds the standard "Broadcast RGB" and "color format" connector properties on Turing to Ada heads and selects the pixel encoding together with the link depth: limited or full range RGB, and YCbCr 4:4:4, 4:2:2 and 4:2:0. It applies on top of the HDMI Deep Color series v2 (base and prerequisite ids below).

The hardware stage was already there. On NVC57D-class heads the final colour conversion is HEAD_SET_PROCAMP plus the OCSC1 matrix and the output clamp ranges; nouveau only wrote PROCAMP, hardcoded to RGB/VESA under a TODO. The programming follows NVIDIA's open NVKMS on the same classes (EvoSetProcAmpC5, EvoSetOCsc1C5, the YUV420PACKER head control). The OCSC1 matrices are the ITU-R BT.601, BT.709 and BT.2020 coefficients at limited-range scale; re-derived independently, they match NVIDIA's register values to within 4 in the last place, and the patch uses NVIDIA's values so the output is bit-identical to the proprietary driver on the same hardware.

Selection policy follows drm_hdmi_state_helper.c, with amdgpu as the reference consumer of the "color format" property: sink rules per format (RGB/4:4:4 Deep Color bits, 4:2:2 up to 12 bpc in the 24-bit container, 4:2:0 through its own bits), TMDS character rates from drm_hdmi_compute_mode_clock(), "Automatic" picking RGB and falling back to 4:2:0, explicit requests honoured or refused. YCbCr is limited range with the CTA-861 default colorimetry (BT.709 above 576 lines, BT.601 below), declared in the AVI InfoFrame together with the pixel encoding.

One default changes: "Broadcast RGB" Automatic selects limited range for CE video formats, as i915 and the HDMI helpers do. Today nouveau sends full-range pixels there and can only declare that to sinks with a Video Capability Data Block, so sinks without one apply their default limited range to full-range data. "Full" restores the previous output.

1: NVC57D output CSC and clamp methods (class header)
2: program PROCAMP/OCSC1/clamps from head state (no functional change) 3: Broadcast RGB
4: color format with YCbCr 4:4:4 and 4:2:2
5: YCbCr 4:2:0 on GA102+, gated per head on the capability notifier 6: the same properties on DVI connectors, which carry HDMI to HDMI
sinks through passive adapters (reported by the automated review of the Deep Color series v1)

Tested on a GA106 (RTX 3060) driving a Sony KDL-46HX855 (HDMI 1.4, YCbCr 4:4:4 and 4:2:2, DC_30/DC_36/DC_Y444, 225 MHz, no VCDB), 25 configurations in two runs: RGB full, limited and automatic at 8/10/12 bpc; YCbCr 4:4:4 and 4:2:2 at 8/10/12 bpc; BT.601 at 576p/480p and BT.709 from 720p; 640x480 held at 8 bpc; and side-by-side, top-and- bottom and frame-packed 3D at 12 bpc with YCbCr 4:4:4, limited RGB and YCbCr 4:2:2. Every frame carried colour bars over near-black and near-white steps; the sink accepted each signal and displayed correct colours and levels, and the driver's selection was logged per step.

Not tested here: 4:2:0 (the sink declares none) and DVI (the board has no DVI port); both reuse the paths exercised above. Volta keeps its current behaviour (NVKMS has no Volta display code to compare against) and Blackwell (NVCA7D, same methods at a different stride) is left for a follow-up. The class header additions are verbatim subsets of NVIDIA's headers and carry their usual checkpatch style findings.

Normative chain: HDMI 1.4b section 6.5 (pixel encodings, General Control Packet), HDMI 2.0 section 7.1 (YCbCr 4:2:0), CTA-861 (AVI InfoFrame Y/C/Q/YQ fields, default colorimetry, the QS rule), ITU-R BT.601, BT.709 and BT.2020. Bench harness and logs:
https://github.com/danielcamposramos/sony-bravia-linux (tools/stereo-modeset, run27 and run28); curated public indexes:
https://github.com/danielcamposramos/awesome-linux-hdr and
https://github.com/danielcamposramos/awesome-stereoscopy.

AI partners were leveraged in the production of this work.

Daniel Campos Ramos (6):
drm/nouveau: add NVC57D output CSC and clamp range methods drm/nouveau: program head output conversion for limited range and
YCbCr
drm/nouveau: add the Broadcast RGB property for HDMI drm/nouveau: add HDMI YCbCr 4:4:4 and 4:2:2 output drm/nouveau: add HDMI YCbCr 4:2:0 output on GA102 and later drm/nouveau: expose HDMI output properties on DVI connectors

 drivers/gpu/drm/nouveau/dispnv50/atom.h       |  11 +
 drivers/gpu/drm/nouveau/dispnv50/disp.c       | 305 +++++++++++++++---
 drivers/gpu/drm/nouveau/dispnv50/head.c       |  19 ++
 drivers/gpu/drm/nouveau/dispnv50/head.h       |   3 +
 drivers/gpu/drm/nouveau/dispnv50/headc57d.c   | 112 +++++--
 .../drm/nouveau/include/nvhw/class/clc57d.h   |  34 ++
 .../drm/nouveau/include/nvhw/class/clc673.h   |  17 +
 .../drm/nouveau/include/nvhw/class/clc67d.h   |  16 +
 drivers/gpu/drm/nouveau/nouveau_connector.c   |  48 ++-
 9 files changed, 488 insertions(+), 77 deletions(-)
 create mode 100644 drivers/gpu/drm/nouveau/include/nvhw/class/clc673.h
 create mode 100644 drivers/gpu/drm/nouveau/include/nvhw/class/clc67d.h

base-commit: 73ef663c75688168e31dbe9c585b939be410a945
prerequisite-patch-id: 6bd193908862475dd809b40037984747467236d6
prerequisite-patch-id: bf3b51b5393ef1c612930f4c474e6852372ca7db
prerequisite-patch-id: 22c3f84b6576853e9d3053d4e5a15a4bd37e6dcd

Signature · 1 line
2.53.0
#2 lore raw

PATCH 1/6 drm/nouveau: add NVC57D output CSC and clamp range methods

Import the HEAD_SET_CLAMP_RANGE_{GREEN,RED_BLUE} and HEAD_SET_OCSC1* method definitions from NVIDIA's open-gpu-kernel-modules clc57d.h.

These program the head's final colour conversion stage on Turing and later display classes: OCSC1 converts the RGB pipeline output into limited-range RGB or YCbCr, and the clamp ranges bound the resulting codes. They are needed to output anything other than full-range RGB.

No functional change.

---
 .../drm/nouveau/include/nvhw/class/clc57d.h   | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/gpu/drm/nouveau/include/nvhw/class/clc57d.h +34 -0
index d4bad2da3e56..ed9de61c5655 100644
@@ -334,6 +334,12 @@
 #define NVC57D_HEAD_SET_CRC_CONTROL_CRC_DURING_SNOOZE                           9:9
 #define NVC57D_HEAD_SET_CRC_CONTROL_CRC_DURING_SNOOZE_DISABLE                   (0x00000000)
 #define NVC57D_HEAD_SET_CRC_CONTROL_CRC_DURING_SNOOZE_ENABLE                    (0x00000001)
+#define NVC57D_HEAD_SET_CLAMP_RANGE_GREEN(a)                                    (0x00002238 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_CLAMP_RANGE_GREEN_LOW                                   11:0
+#define NVC57D_HEAD_SET_CLAMP_RANGE_GREEN_HIGH                                  27:16
+#define NVC57D_HEAD_SET_CLAMP_RANGE_RED_BLUE(a)                                 (0x0000223C + (a)*0x00000400)
+#define NVC57D_HEAD_SET_CLAMP_RANGE_RED_BLUE_LOW                                11:0
+#define NVC57D_HEAD_SET_CLAMP_RANGE_RED_BLUE_HIGH                               27:16
 #define NVC57D_HEAD_SET_OLUT_CONTROL(a)                                         (0x00002280 + (a)*0x00000400)
 #define NVC57D_HEAD_SET_OLUT_CONTROL_INTERPOLATE                                0:0
 #define NVC57D_HEAD_SET_OLUT_CONTROL_INTERPOLATE_DISABLE                        (0x00000000)
@@ -352,4 +358,32 @@
 #define NVC57D_HEAD_SET_CONTEXT_DMA_OLUT_HANDLE                                 31:0
 #define NVC57D_HEAD_SET_OFFSET_OLUT(a)                                          (0x0000228C + (a)*0x00000400)
 #define NVC57D_HEAD_SET_OFFSET_OLUT_ORIGIN                                      31:0
+#define NVC57D_HEAD_SET_OCSC1CONTROL(a)                                         (0x0000229C + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1CONTROL_ENABLE                                     0:0
+#define NVC57D_HEAD_SET_OCSC1CONTROL_ENABLE_DISABLE                             (0x00000000)
+#define NVC57D_HEAD_SET_OCSC1CONTROL_ENABLE_ENABLE                              (0x00000001)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C00(a)                                 (0x000022A0 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C00_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C01(a)                                 (0x000022A4 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C01_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C02(a)                                 (0x000022A8 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C02_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C03(a)                                 (0x000022AC + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C03_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C10(a)                                 (0x000022B0 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C10_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C11(a)                                 (0x000022B4 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C11_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C12(a)                                 (0x000022B8 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C12_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C13(a)                                 (0x000022BC + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C13_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C20(a)                                 (0x000022C0 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C20_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C21(a)                                 (0x000022C4 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C21_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C22(a)                                 (0x000022C8 + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C22_VALUE                              20:0
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C23(a)                                 (0x000022CC + (a)*0x00000400)
+#define NVC57D_HEAD_SET_OCSC1COEFFICIENT_C23_VALUE                              20:0
 #endif // _clC57d_h
Signature · 1 line
2.53.0
#3 lore raw

PATCH 2/6 drm/nouveau: program head output conversion for limited range and YCbCr

In reply to Daniel Campos Ramos

On Turing and later display classes the final head colour stage is programmed through HEAD_SET_PROCAMP, the OCSC1 matrix and the output clamp ranges. Nouveau only wrote PROCAMP, hardcoded to full-range RGB, and left OCSC1 and the clamps untouched, so the head could only ever emit full-range RGB.

Carry an output colour space and a limited-range flag in the head atom and program all three from it in headc57d_procamp(): full-range RGB disables OCSC1 and opens the clamps, limited-range RGB and YCbCr load the matching BT.601/BT.709/BT.2020 limited-range matrix and clamp to 16-235 (16-240 for chroma). The matrices are the ITU-R coefficients scaled to limited range, with the register values NVIDIA's open NVKMS uses on the same classes.

Re-send procamp whenever the output conversion changes on an active head, and reset it to full-range RGB when the encoder state is recomputed. Nothing selects anything else yet, so there is no functional change.

---
 drivers/gpu/drm/nouveau/dispnv50/atom.h     |  2 +
 drivers/gpu/drm/nouveau/dispnv50/disp.c     |  5 +-
 drivers/gpu/drm/nouveau/dispnv50/head.c     |  3 +
 drivers/gpu/drm/nouveau/dispnv50/headc57d.c | 74 +++++++++++++++++++--
 4 files changed, 79 insertions(+), 5 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/atom.h +2 -0
index c34a42ea9ac4..64be784be335 100644
@@ -112,6 +112,8 @@ struct nv50_head_atom {
 			u16 cos:12;
 			u16 sin:12;
 		} sat;
+		u8 colorspace:2;	/* HEAD_SET_PROCAMP_COLOR_SPACE */
+		bool limited:1;		/* limited quantization range */
 	} procamp;
 
 	struct {
drivers/gpu/drm/nouveau/dispnv50/disp.c +4 -1
index b183e1865bf5..b216db61330c 100644
@@ -463,8 +463,11 @@ nv50_outp_atomic_check(struct drm_encoder *encoder,
 	if (ret)
 		return ret;
 
-	if (crtc_state->mode_changed || crtc_state->connectors_changed)
+	if (crtc_state->mode_changed || crtc_state->connectors_changed) {
 		asyh->or.bpc = connector->display_info.bpc;
+		asyh->procamp.colorspace = 0; /* RGB */
+		asyh->procamp.limited = false;
+	}
 
 	/* We might have to reduce the bpc */
 	nv50_outp_atomic_fix_depth(encoder, crtc_state, conn_state);
drivers/gpu/drm/nouveau/dispnv50/head.c +3 -0
index 6a3a93de0cbf..7b94c881e8bb 100644
@@ -370,6 +370,9 @@ nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state)
 				if (armh->base.depth != asyh->base.depth)
 					asyc->set.dither = true;
 			}
+			if (armh->procamp.colorspace != asyh->procamp.colorspace ||
+			    armh->procamp.limited != asyh->procamp.limited)
+				asyh->set.procamp = true;
 		} else {
 			if (asyc)
 				asyc->set.mask = ~0;
drivers/gpu/drm/nouveau/dispnv50/headc57d.c +70 -4

91 lines not on this page · raw message

Signature · 1 line
2.53.0
#4 lore raw

PATCH 3/6 drm/nouveau: add the Broadcast RGB property for HDMI

In reply to Daniel Campos Ramos

Nouveau always scans out full-range RGB, and asks the AVI InfoFrame to declare full range. drm_hdmi_avi_infoframe_quant_range() may only send a non-default Q when the sink sets QS in its Video Capability Data Block, so a sink without one is told nothing and, for CE video formats such as 1920x1080p60, applies its default limited range to full-range
pixels: black levels are crushed and highlights clipped.

Attach the standard "Broadcast RGB" property to HDMI connectors on heads with an output CSC (Turing to Ada), and select limited range the same way drm_hdmi_state_helper.c does: "Full" and "Limited 16:235" are honoured, and "Automatic" follows drm_default_rgb_quant_range(), i.e. limited for CE video formats and full otherwise. The head's output CSC performs the compression and the AVI InfoFrame declares the range that is actually sent. A change of the property forces a modeset, as the range is selected in the encoder's atomic check.

This changes the default for CE video formats on those heads from full-range pixels to limited range, matching i915 and the HDMI state helpers. "Full" restores the previous output.

---
 drivers/gpu/drm/nouveau/dispnv50/disp.c     | 24 +++++++++++++++++++--
 drivers/gpu/drm/nouveau/nouveau_connector.c | 24 ++++++++++++++++++++-
 2 files changed, 45 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/disp.c +22 -2
index b216db61330c..54ed903644bf 100644
@@ -387,6 +387,14 @@ nv50_outp_link_clock(const struct drm_display_mode *mode)
 	return mode->clock;
 }
 
+static bool
+nv50_outp_has_output_csc(struct drm_encoder *encoder)
+{
+	const s32 oclass = nv50_disp(encoder->dev)->disp->object.oclass;
+
+	return oclass >= TU102_DISP && oclass < GB202_DISP;
+}
+
 static void
 nv50_outp_atomic_fix_depth(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state,
 			   struct drm_connector_state *conn_state)
@@ -442,6 +450,15 @@ nv50_outp_atomic_fix_depth(struct drm_encoder *encoder, struct drm_crtc_state *c
 		}
 
 		conn_state->max_bpc = asyh->or.bpc;
+
+		/* Broadcast RGB, as in drm_hdmi_state_helper.c: automatic
+		 * selects limited range for CE video formats.
+		 */
+		if (nv50_outp_has_output_csc(encoder) &&
+		    (conn_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_LIMITED ||
+		     (conn_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_AUTO &&
+		      drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_LIMITED)))
+			asyh->procamp.limited = true;
 		break;
 	default:
 		break;
@@ -825,8 +842,9 @@ nv50_audio_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,
 static void
 nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,
 		 struct nouveau_connector *nv_connector, struct drm_atomic_commit *state,
-		 struct drm_display_mode *mode, bool hda, u8 bpc)
+		 struct drm_display_mode *mode, bool hda, struct nv50_head_atom *asyh)
 {
+	const u8 bpc = asyh->or.bpc;
 	struct nouveau_drm *drm = nouveau_drm(encoder->dev);
 	struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
 	struct drm_hdmi_info *hdmi = &nv_connector->base.display_info.hdmi;
@@ -905,6 +923,8 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,
 
 	if (!drm_hdmi_avi_infoframe_from_display_mode(&infoframe.avi, &nv_connector->base, mode)) {
 		drm_hdmi_avi_infoframe_quant_range(&infoframe.avi, &nv_connector->base, mode,
+						   asyh->procamp.limited ?
+						   HDMI_QUANTIZATION_RANGE_LIMITED :
 						   HDMI_QUANTIZATION_RANGE_FULL);
 
 		size = hdmi_infoframe_pack(&infoframe, args->data, data_len);
@@ -1877,7 +1897,7 @@ nv50_sor_atomic_enable(struct drm_encoder *encoder, struct drm_atomic_commit *st
 		if (disp->disp->object.oclass != NV50_DISP &&
 		    nv_connector->base.display_info.is_hdmi)
 			nv50_hdmi_enable(encoder, nv_crtc, nv_connector, state, mode, hda,
-					 asyh->or.bpc);
+					 asyh);
 
 		if (nv_encoder->outp.or.link & 1) {
 			proto = NV507D_SOR_SET_CONTROL_PROTOCOL_SINGLE_TMDS_A;
drivers/gpu/drm/nouveau/nouveau_connector.c +23 -1
index b452e73f03f1..748c2f29d5d1 100644
@@ -298,9 +298,15 @@ nouveau_conn_attach_properties(struct drm_connector *connector)
 		drm_object_attach_property(&connector->base, dev->mode_config.
 					   dvi_i_subconnector_property, 0);
 
-	if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA)
+	if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) {
 		drm_connector_attach_max_bpc_property(connector, 8, 16);
 
+		/* Only heads with an output CSC can emit limited range. */
+		if (disp->disp.object.oclass >= TU102_DISP &&
+		    disp->disp.object.oclass < GB202_DISP)
+			drm_connector_attach_broadcast_rgb_property(connector);
+	}
+
 	/* Add overscan compensation options to digital outputs. */
 	if (disp->underscan_property &&
 	    (connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
@@ -1213,9 +1219,25 @@ static int
 nouveau_connector_atomic_check(struct drm_connector *connector, struct drm_atomic_commit *state)
 {
 	struct nouveau_connector *nv_conn = nouveau_connector(connector);
+	struct drm_connector_state *old_conn_state =
+		drm_atomic_get_old_connector_state(state, connector);
 	struct drm_connector_state *conn_state =
 		drm_atomic_get_new_connector_state(state, connector);
 
+	/* The quantization range is selected during the encoder's atomic
+	 * check, which only runs on a modeset.
+	 */
+	if (conn_state->crtc &&
+	    old_conn_state->hdmi.broadcast_rgb != conn_state->hdmi.broadcast_rgb) {
+		struct drm_crtc_state *crtc_state;
+
+		crtc_state = drm_atomic_get_crtc_state(state, conn_state->crtc);
+		if (IS_ERR(crtc_state))
+			return PTR_ERR(crtc_state);
+
+		crtc_state->mode_changed = true;
+	}
+
 	if (!nv_conn->dp_encoder || !nv_conn->dp_encoder->dp.mstm)
 		return 0;
 
Signature · 1 line
2.53.0
#5 lore raw

PATCH 4/6 drm/nouveau: add HDMI YCbCr 4:4:4 and 4:2:2 output

In reply to Daniel Campos Ramos

Attach the "color format" connector property to HDMI connectors on heads with an output CSC (Turing to Ada), offering RGB, YCbCr 4:4:4 and YCbCr 4:2:2, and select the pixel encoding together with the link depth.

The selection follows drm_hdmi_state_helper.c: RGB and 4:4:4 need the sink's Deep Color bits for the chosen depth (4:4:4 through DC_Y444), 4:2:2 needs none but is limited to 12 bpc, and the TMDS character rate comes from drm_hdmi_compute_mode_clock(), which carries 4:2:2 at the 8-bpc rate. "Automatic" keeps RGB. An explicit YCbCr request is either honoured at the deepest depth that fits, or the commit is rejected.

YCbCr output is limited range. Its colorimetry follows the CTA-861 default, BT.709 above 576 active lines and BT.601 otherwise, and the head's output CSC applies the matching matrix. The AVI InfoFrame now declares the pixel encoding, that colorimetry and limited YCC range. 4:2:2 uses the 16/20/24-bpp 4:2:2 pixel depths and leaves the GCP colour depth at its default, as HDMI 1.3 section 6.5 carries up to 12 bpc 4:2:2 in the 24-bit container; 4:4:4 uses the same GCP encodings as RGB. The SCDC scrambling threshold uses the same character rate.

The head pixel depth mapping in headc57d_or() becomes the offset it always was between the NV837D SOR codes and the head codes, which also covers the 4:2:2 depths.

---
 drivers/gpu/drm/nouveau/dispnv50/atom.h     |  11 +-
 drivers/gpu/drm/nouveau/dispnv50/disp.c     | 228 +++++++++++++++-----
 drivers/gpu/drm/nouveau/dispnv50/headc57d.c |  25 +--
 drivers/gpu/drm/nouveau/nouveau_connector.c |  13 +-
 4 files changed, 203 insertions(+), 74 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/atom.h +10 -1
index 64be784be335..f85e80eb8f8e 100644
@@ -16,6 +16,14 @@ struct nv50_atom {
 
 #define nv50_head_atom(p) container_of((p), struct nv50_head_atom, state)
 
+/* Output colour space, numbered as every class's HEAD_SET_PROCAMP_COLOR_SPACE. */
+enum nv50_head_colorspace {
+	NV50_HEAD_COLORSPACE_RGB = 0,
+	NV50_HEAD_COLORSPACE_YUV_601 = 1,
+	NV50_HEAD_COLORSPACE_YUV_709 = 2,
+	NV50_HEAD_COLORSPACE_YUV_2020 = 3,
+};
+
 struct nv50_head_atom {
 	struct drm_crtc_state state;
 
@@ -112,7 +120,7 @@ struct nv50_head_atom {
 			u16 cos:12;
 			u16 sin:12;
 		} sat;
-		u8 colorspace:2;	/* HEAD_SET_PROCAMP_COLOR_SPACE */
+		u8 colorspace:2;	/* enum nv50_head_colorspace */
 		bool limited:1;		/* limited quantization range */
 	} procamp;
 
@@ -122,6 +130,7 @@ struct nv50_head_atom {
 		u8 depth:4;
 		u8 crc_raster:2;
 		u8 bpc;
+		u8 format;	/* enum drm_output_color_format */
 	} or;
 
 	struct nv50_crc_atom crc;
drivers/gpu/drm/nouveau/dispnv50/disp.c +175 -53

307 lines not on this page · raw message

drivers/gpu/drm/nouveau/dispnv50/headc57d.c +7 -18
index 9b5c02c86fc9..937f71f264db 100644
@@ -48,25 +48,14 @@ headc57d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
 	u8 depth;
 	int ret;
 
-	/*XXX: This is a dirty hack until OR depth handling is
-	 *     improved later for deep colour etc.
+	/* or.depth holds an NV837D SOR_SET_CONTROL_PIXEL_DEPTH code: those
+	 * number the same depths one higher, with 0 meaning the default.
 	 */
-	switch (asyh->or.depth) {
-	case 9:
-		depth = 8;
-		break;
-	case 8:
-		depth = 7;
-		break;
-	case 6: depth = 5; break;
-	case 5: depth = 4; break;
-	case 2: depth = 1; break;
-	case 0:	depth = 4; break;
-	default:
-		depth = asyh->or.depth;
-		WARN_ON(1);
-		break;
-	}
+	if (asyh->or.depth)
+		depth = asyh->or.depth - 1;
+	else
+		depth = NVC57D_HEAD_SET_CONTROL_OUTPUT_RESOURCE_PIXEL_DEPTH_BPP_24_444;
+	WARN_ON(depth > NVC57D_HEAD_SET_CONTROL_OUTPUT_RESOURCE_PIXEL_DEPTH_BPP_48_444);
 
 	if ((ret = PUSH_WAIT(push, 2)))
 		return ret;
drivers/gpu/drm/nouveau/nouveau_connector.c +11 -2
index 748c2f29d5d1..2a9782d6c382 100644
@@ -301,10 +301,19 @@ nouveau_conn_attach_properties(struct drm_connector *connector)
 	if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) {
 		drm_connector_attach_max_bpc_property(connector, 8, 16);
 
-		/* Only heads with an output CSC can emit limited range. */
+		/* Only heads with an output CSC can emit limited range
+		 * or YCbCr.
+		 */
 		if (disp->disp.object.oclass >= TU102_DISP &&
-		    disp->disp.object.oclass < GB202_DISP)
+		    disp->disp.object.oclass < GB202_DISP) {
+			const unsigned long formats =
+				BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) |
+				BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444) |
+				BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422);
+
 			drm_connector_attach_broadcast_rgb_property(connector);
+			drm_connector_attach_color_format_property(connector, formats);
+		}
 	}
 
 	/* Add overscan compensation options to digital outputs. */
Signature · 1 line
2.53.0
#6 lore raw

PATCH 5/6 drm/nouveau: add HDMI YCbCr 4:2:0 output on GA102 and later

In reply to Daniel Campos Ramos

GA102 and later heads can pack YCbCr 4:2:0 in hardware when the capability notifier reports the horizontal chroma low-pass and vertical filters (POSTCOMP_HEAD_HDR_CAPA HCLPF/VFILTER), which is how NVIDIA's open NVKMS enables it. Read that per head, and on such heads offer YCbCr 4:2:0 through the "color format" property and allow 4:2:0 modes.

4:2:0 enables the head's YUV420PACKER, CHROMA_LPF and CHROMA_DOWN_V, reuses the 4:4:4 pixel depths and GCP encodings, is BT.709 limited range, and is declared in the AVI InfoFrame. The sink rules follow drm_hdmi_state_helper.c: the mode must support 4:2:0 and deep colour uses the 4:2:0 Deep Color bits; the TMDS character rate is half the pixel clock. "Automatic" falls back to 4:2:0 when RGB cannot carry the mode, a 4:2:0-only mode is rejected on a head that cannot pack it, and mode validation accounts for the halved rate as drm_hdmi_connector_mode_valid() does.

The class definitions are subsets of NVIDIA's open-gpu-kernel-modules clc67d.h and clc673.h.

Not tested on hardware: the only sink available here declares no 4:2:0 support. The head programming, pixel depths and packets are the ones exercised by the 4:4:4 and 4:2:2 paths, which were.

---
 drivers/gpu/drm/nouveau/dispnv50/disp.c       | 83 +++++++++++++++----
 drivers/gpu/drm/nouveau/dispnv50/head.c       | 18 +++-
 drivers/gpu/drm/nouveau/dispnv50/head.h       |  3 +
 drivers/gpu/drm/nouveau/dispnv50/headc57d.c   | 13 ++-
 .../drm/nouveau/include/nvhw/class/clc673.h   | 17 ++++
 .../drm/nouveau/include/nvhw/class/clc67d.h   | 16 ++++
 drivers/gpu/drm/nouveau/nouveau_connector.c   | 12 ++-
 7 files changed, 142 insertions(+), 20 deletions(-)
 create mode 100644 drivers/gpu/drm/nouveau/include/nvhw/class/clc673.h
 create mode 100644 drivers/gpu/drm/nouveau/include/nvhw/class/clc67d.h
drivers/gpu/drm/nouveau/dispnv50/disp.c +67 -16
index ad8952dfcd71..c52629eaf786 100644
@@ -423,6 +423,22 @@ nv50_hdmi_sink_supports(const struct drm_display_info *info,
 		 * which carries up to 12 bpc in the 24-bit container.
 		 */
 		return (info->color_formats & BIT(fmt)) && bpc <= 12;
+	case DRM_OUTPUT_COLOR_FORMAT_YCBCR420:
+		/* 4:2:0 has its own Deep Color bits (HF-VSDB / Y420CMDB). */
+		if (!drm_mode_is_420(info, mode))
+			return false;
+		switch (bpc) {
+		case 8:
+			return true;
+		case 10:
+			return info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_30;
+		case 12:
+			return info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_36;
+		case 16:
+			return info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_48;
+		default:
+			return false;
+		}
 	default:
 		return false;
 	}
@@ -456,10 +472,37 @@ nv50_hdmi_char_rate(const struct drm_display_mode *mode, unsigned int bpc,
 	return rate;
 }
 
+/* Deepest depth the sink declares for the format, the user allows and the
+ * TMDS link carries, or 0.
+ */
+static unsigned int
+nv50_hdmi_pick_bpc(const struct drm_connector_state *conn_state,
+		   const struct drm_display_mode *mode,
+		   enum drm_output_color_format fmt, unsigned int max_rate)
+{
+	const struct drm_display_info *info = &conn_state->connector->display_info;
+	unsigned int bpc;
+
+	for (bpc = 16; bpc >= 8; bpc -= 2) {
+		unsigned long long rate;
+
+		if (bpc > conn_state->max_requested_bpc ||
+		    !nv50_hdmi_sink_supports(info, mode, fmt, bpc))
+			continue;
+
+		rate = nv50_hdmi_char_rate(mode, bpc, fmt);
+		if (rate && rate <= max_rate * 1000ULL)
+			return bpc;
+	}
+
+	return 0;
+}
+
 static int
 nv50_outp_atomic_fix_depth(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state,
 			   struct drm_connector_state *conn_state)
 {
+	struct nv50_head *head = nv50_head(crtc_state->crtc);
 	struct nv50_head_atom *asyh = nv50_head_atom(crtc_state);
 	struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
 	struct drm_connector *connector = conn_state->connector;
@@ -497,29 +540,34 @@ nv50_outp_atomic_fix_depth(struct drm_encoder *encoder, struct drm_crtc_state *c
 		case DRM_CONNECTOR_COLOR_FORMAT_YCBCR422:
 			fmt = DRM_OUTPUT_COLOR_FORMAT_YCBCR422;
 			break;
+		case DRM_CONNECTOR_COLOR_FORMAT_YCBCR420:
+			if (!head->yuv420)
+				return -EINVAL;
+			fmt = DRM_OUTPUT_COLOR_FORMAT_YCBCR420;
+			break;
 		default:
 			break;
 		}
 
-		/* Deepest depth the sink declares for the format, the user
-		 * allows and the TMDS link carries.
-		 */
 		max_rate = nouveau_connector_get_tmds_link_bandwidth(connector);
-		for (bpc = 16; bpc >= 8; bpc -= 2) {
-			unsigned long long rate;
-
-			if (bpc > conn_state->max_requested_bpc ||
-			    !nv50_hdmi_sink_supports(info, mode, fmt, bpc))
-				continue;
+		bpc = nv50_hdmi_pick_bpc(conn_state, mode, fmt, max_rate);
 
-			rate = nv50_hdmi_char_rate(mode, bpc, fmt);
-			if (rate && rate <= max_rate * 1000ULL)
-				break;
+		/* "Automatic" falls back to 4:2:0 when RGB cannot carry the
+		 * mode, as in drm_hdmi_state_helper.c.
+		 */
+		if (bpc < 8 && fmt == DRM_OUTPUT_COLOR_FORMAT_RGB444 &&
+		    drm_connector_get_color_format(conn_state) == DRM_CONNECTOR_COLOR_FORMAT_AUTO &&
+		    head->yuv420 && drm_mode_is_420(info, mode)) {
+			fmt = DRM_OUTPUT_COLOR_FORMAT_YCBCR420;
+			bpc = nv50_hdmi_pick_bpc(conn_state, mode, fmt, max_rate);
 		}
 
 		if (bpc < 8) {
-			/* An explicit format request is honoured or refused. */
-			if (fmt != DRM_OUTPUT_COLOR_FORMAT_RGB444)
+			/* An explicit format request is honoured or refused,
+			 * and a 4:2:0-only mode cannot fall back to RGB.
+			 */
+			if (fmt != DRM_OUTPUT_COLOR_FORMAT_RGB444 ||
+			    drm_mode_is_420_only(info, mode))
 				return -EINVAL;
 			bpc = 8;
 		}
@@ -532,7 +580,8 @@ nv50_outp_atomic_fix_depth(struct drm_encoder *encoder, struct drm_crtc_state *c
 			/* YCbCr is limited range; CTA-861 colorimetry
 			 * defaults to BT.709 above 576 lines, BT.601 below.
 			 */
-			asyh->procamp.colorspace = mode->vdisplay > 576 ?
+			asyh->procamp.colorspace = mode->vdisplay > 576 ||
+						   fmt == DRM_OUTPUT_COLOR_FORMAT_YCBCR420 ?
 						   NV50_HEAD_COLORSPACE_YUV_709 :
 						   NV50_HEAD_COLORSPACE_YUV_601;
 			asyh->procamp.limited = true;
@@ -1027,7 +1076,9 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc,
 							   HDMI_QUANTIZATION_RANGE_FULL);
 		} else {
 			/* Declare the matrix the head's output CSC applies. */
-			avi->colorspace = fmt == DRM_OUTPUT_COLOR_FORMAT_YCBCR422 ?
+			avi->colorspace = fmt == DRM_OUTPUT_COLOR_FORMAT_YCBCR420 ?
+					  HDMI_COLORSPACE_YUV420 :
+					  fmt == DRM_OUTPUT_COLOR_FORMAT_YCBCR422 ?
 					  HDMI_COLORSPACE_YUV422 : HDMI_COLORSPACE_YUV444;
 			avi->colorimetry = asyh->procamp.colorspace ==
 					   NV50_HEAD_COLORSPACE_YUV_709 ?
drivers/gpu/drm/nouveau/dispnv50/head.c +17 -1
index 7b94c881e8bb..ca48bedbdbe2 100644
@@ -30,6 +30,8 @@
 #include <nvif/event.h>
 #include <nvif/cl0046.h>
 
+#include <nvhw/class/clc673.h>
+
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_edid.h>
@@ -371,7 +373,8 @@ nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state)
 					asyc->set.dither = true;
 			}
 			if (armh->procamp.colorspace != asyh->procamp.colorspace ||
-			    armh->procamp.limited != asyh->procamp.limited)
+			    armh->procamp.limited != asyh->procamp.limited ||
+			    armh->or.format != asyh->or.format)
 				asyh->set.procamp = true;
 		} else {
 			if (asyc)
@@ -586,6 +589,19 @@ nv50_head_create(struct drm_device *dev, int index)
 	head->disp = disp;
 	head->base.index = index;
 
+	/* GA102 and later heads pack YCbCr 4:2:0 in hardware when they have
+	 * the horizontal chroma low-pass and vertical filters.
+	 */
+	if (disp->disp->object.oclass >= GA102_DISP &&
+	    disp->disp->object.oclass < GB202_DISP) {
+		const u32 capa = nvif_rd32(&disp->caps,
+					   NVC673_POSTCOMP_HEAD_HDR_CAPA(index));
+
+		head->yuv420 =
+			NVDEF_TEST(capa, NVC673, POSTCOMP_HEAD_HDR_CAPA, HCLPF_PRESENT, ==, TRUE) &&
+			NVDEF_TEST(capa, NVC673, POSTCOMP_HEAD_HDR_CAPA, VFILTER_PRESENT, ==, TRUE);
+	}
+
 	if (disp->disp->object.oclass < GF110_DISP)
 		funcs = &nv50_head_func;
 	else
drivers/gpu/drm/nouveau/dispnv50/head.h +3 -0
index 8bd2fcb1eff5..db4a50a85e79 100644
@@ -19,6 +19,9 @@ struct nv50_head {
 	struct nv50_crc crc;
 	struct nv50_lut olut;
 	struct nv50_msto *msto;
+
+	/* The head can pack YCbCr 4:2:0 in hardware. */
+	bool yuv420;
 };
 
 struct nv50_head *nv50_head_create(struct drm_device *, int index);
drivers/gpu/drm/nouveau/dispnv50/headc57d.c +11 -2
index 937f71f264db..9e152daefc58 100644
@@ -26,6 +26,7 @@
 #include <nvif/pushc37b.h>
 
 #include <nvhw/class/clc57d.h>
+#include <nvhw/class/clc67d.h>
 
 static int
 headc57d_display_id(struct nv50_head *head, u32 display_id)
@@ -111,6 +112,7 @@ headc57d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
 	struct nvif_push *push = &nv50_disp(head->base.base.dev)->core->chan.push;
 	const u8 colorspace = asyh->procamp.colorspace;
 	const bool limited = asyh->procamp.limited;
+	const bool yuv420 = asyh->or.format == DRM_OUTPUT_COLOR_FORMAT_YCBCR420;
 	const int i = head->base.index;
 	u32 lo = 0x000, y_hi = 0xfff, c_hi = 0xfff;
 	int ret;
@@ -126,9 +128,14 @@ headc57d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
 	if (ret)
 		return ret;
 
+	/* 4:2:0 filters chroma horizontally and vertically.  CHROMA_DOWN_V
+	 * is an NVC67D field and an unused bit on NVC57D; 4:2:0 is only
+	 * selected on GA102 and later heads.
+	 */
 	PUSH_MTHD(push, NVC57D, HEAD_SET_PROCAMP(i),
 		  NVVAL(NVC57D, HEAD_SET_PROCAMP, COLOR_SPACE, colorspace) |
-		  NVDEF(NVC57D, HEAD_SET_PROCAMP, CHROMA_LPF, DISABLE) |
+		  NVVAL(NVC57D, HEAD_SET_PROCAMP, CHROMA_LPF, yuv420) |
+		  NVVAL(NVC67D, HEAD_SET_PROCAMP, CHROMA_DOWN_V, yuv420) |
 		  NVVAL(NVC57D, HEAD_SET_PROCAMP, DYNAMIC_RANGE,
 			limited ? NVC57D_HEAD_SET_PROCAMP_DYNAMIC_RANGE_CEA :
 				  NVC57D_HEAD_SET_PROCAMP_DYNAMIC_RANGE_VESA));
@@ -288,7 +295,9 @@ headc57d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
 
 	//XXX:
 	PUSH_NVSQ(push, NVC57D, 0x2074 + (i * 0x400), m->v.blank2e << 16 | m->v.blank2s);
-	PUSH_NVSQ(push, NVC57D, 0x2008 + (i * 0x400), m->interlace);
+	PUSH_NVSQ(push, NVC57D, 0x2008 + (i * 0x400), m->interlace |
+		  NVVAL(NVC67D, HEAD_SET_CONTROL, YUV420PACKER,
+			asyh->or.format == DRM_OUTPUT_COLOR_FORMAT_YCBCR420));
 
 	PUSH_MTHD(push, NVC57D, HEAD_SET_PIXEL_CLOCK_FREQUENCY(i),
 		  NVVAL(NVC57D, HEAD_SET_PIXEL_CLOCK_FREQUENCY, HERTZ, m->clock * 1000));
drivers/gpu/drm/nouveau/include/nvhw/class/clc673.h new file +17 -0
new file mode 100644
index 000000000000..ba901cf7ac28
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2003-2021, NVIDIA CORPORATION. All rights reserved.
+ */
+#ifndef _clc673_h_
+#define _clc673_h_
+
+/* Subset: the per-head post-composition capabilities used by nouveau. */
+#define NVC673_POSTCOMP_HEAD_HDR_CAPA(i)                                      (0x680+(i)*32) /* RW-4A */
+#define NVC673_POSTCOMP_HEAD_HDR_CAPA_HCLPF_PRESENT                                         19:19 /* RWIVF */
+#define NVC673_POSTCOMP_HEAD_HDR_CAPA_HCLPF_PRESENT_TRUE                               0x00000001 /* RW--V */
+#define NVC673_POSTCOMP_HEAD_HDR_CAPA_HCLPF_PRESENT_FALSE                              0x00000000 /* RW--V */
+#define NVC673_POSTCOMP_HEAD_HDR_CAPA_VFILTER_PRESENT                                       23:23 /* RWIVF */
+#define NVC673_POSTCOMP_HEAD_HDR_CAPA_VFILTER_PRESENT_TRUE                             0x00000001 /* RW--V */
+#define NVC673_POSTCOMP_HEAD_HDR_CAPA_VFILTER_PRESENT_FALSE                            0x00000000 /* RW--V */
+
+#endif // _clc673_h_
drivers/gpu/drm/nouveau/include/nvhw/class/clc67d.h new file +16 -0
new file mode 100644
index 000000000000..a659f1f2121c
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
+ */
+#ifndef _clC67d_h_
+#define _clC67d_h_
+
+/* Subset: the NVC67D additions to NVC57D head methods used by nouveau. */
+#define NVC67D_HEAD_SET_PROCAMP_CHROMA_DOWN_V                                   4:4
+#define NVC67D_HEAD_SET_PROCAMP_CHROMA_DOWN_V_DISABLE                           (0x00000000)
+#define NVC67D_HEAD_SET_PROCAMP_CHROMA_DOWN_V_ENABLE                            (0x00000001)
+#define NVC67D_HEAD_SET_CONTROL_YUV420PACKER                                    3:3
+#define NVC67D_HEAD_SET_CONTROL_YUV420PACKER_DISABLE                            (0x00000000)
+#define NVC67D_HEAD_SET_CONTROL_YUV420PACKER_ENABLE                             (0x00000001)
+
+#endif // _clC67d_h_
drivers/gpu/drm/nouveau/nouveau_connector.c +11 -1
index 2a9782d6c382..e274251adbb2 100644
@@ -306,12 +306,17 @@ nouveau_conn_attach_properties(struct drm_connector *connector)
 		 */
 		if (disp->disp.object.oclass >= TU102_DISP &&
 		    disp->disp.object.oclass < GB202_DISP) {
-			const unsigned long formats =
+			unsigned long formats =
 				BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) |
 				BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444) |
 				BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422);
 
 			drm_connector_attach_broadcast_rgb_property(connector);
+			if (disp->disp.object.oclass >= GA102_DISP) {
+				/* 4:2:0 is further gated on each head's filters. */
+				formats |= BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420);
+				connector->ycbcr_420_allowed = true;
+			}
 			drm_connector_attach_color_format_property(connector, formats);
 		}
 	}
@@ -1205,6 +1210,11 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
 	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
 		clock *= 2;
 
+	/* YCbCr 4:2:0 halves the TMDS character rate. */
+	if (clock > max_clock && connector->ycbcr_420_allowed &&
+	    drm_mode_is_420(&connector->display_info, mode))
+		clock /= 2;
+
 	if (clock < min_clock)
 		return MODE_CLOCK_LOW;
 	if (clock > max_clock)
Signature · 1 line
2.53.0
#7 lore raw

PATCH 6/6 drm/nouveau: expose HDMI output properties on DVI connectors

In reply to Daniel Campos Ramos

DVI and HDMI share the TMDS link, and a DVI connector drives an HDMI sink through a passive adapter. Nouveau already decides HDMI operation from the sink's EDID rather than the connector type, so InfoFrames, 3D and the Deep Color GCP reach HDMI sinks on DVI connectors, but "max bpc", "Broadcast RGB" and "color format" were only attached to HDMI-A connectors, leaving those sinks at 8-bpc full-range RGB.

Attach the same properties to DVI-D and DVI-I connectors. The selection is unchanged: it still follows the sink's EDID, a DVI sink stays at 8-bpc RGB, and an explicit YCbCr request for a DVI sink is rejected, as in drm_hdmi_state_helper.c.

---
 drivers/gpu/drm/nouveau/dispnv50/disp.c     | 7 ++++++-
 drivers/gpu/drm/nouveau/nouveau_connector.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/dispnv50/disp.c +6 -1
index c52629eaf786..1ec33bb6ad50 100644
@@ -530,8 +530,13 @@ nv50_outp_atomic_fix_depth(struct drm_encoder *encoder, struct drm_crtc_state *c
 		enum drm_output_color_format fmt = DRM_OUTPUT_COLOR_FORMAT_RGB444;
 		unsigned int bpc;
 
-		if (!info->is_hdmi)
+		if (!info->is_hdmi) {
+			/* DVI sinks take RGB only. */
+			if (drm_connector_get_color_format(conn_state) >
+			    DRM_CONNECTOR_COLOR_FORMAT_RGB444)
+				return -EINVAL;
 			break;
+		}
 
 		switch (drm_connector_get_color_format(conn_state)) {
 		case DRM_CONNECTOR_COLOR_FORMAT_YCBCR444:
drivers/gpu/drm/nouveau/nouveau_connector.c +6 -1
index e274251adbb2..fe4248dd39e3 100644
@@ -298,7 +298,12 @@ nouveau_conn_attach_properties(struct drm_connector *connector)
 		drm_object_attach_property(&connector->base, dev->mode_config.
 					   dvi_i_subconnector_property, 0);
 
-	if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) {
+	/* DVI connectors carry HDMI to HDMI sinks through passive adapters;
+	 * the output is selected from the sink's EDID, not the connector.
+	 */
+	if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
+	    connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
+	    connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
 		drm_connector_attach_max_bpc_property(connector, 8, 16);
 
 		/* Only heads with an output CSC can emit limited range
Signature · 1 line
2.53.0
#8 lore raw

Re: [PATCH 0/6] drm/nouveau: HDMI output colour format and quantization range

In reply to Daniel Campos Ramos
Quoted 91 lines · Daniel Campos Ramos

Nouveau only ever outputs full-range RGB on HDMI.  This series adds the
standard "Broadcast RGB" and "color format" connector properties on Turing to Ada heads and selects the pixel encoding together with the link depth: limited or full range RGB, and YCbCr 4:4:4, 4:2:2 and 4:2:0.
It applies on top of the HDMI Deep Color series v2 (base and prerequisite ids below).

The hardware stage was already there.  On NVC57D-class heads the final
colour conversion is HEAD_SET_PROCAMP plus the OCSC1 matrix and the output clamp ranges; nouveau only wrote PROCAMP, hardcoded to RGB/VESA
under a TODO.  The programming follows NVIDIA's open NVKMS on the same
classes (EvoSetProcAmpC5, EvoSetOCsc1C5, the YUV420PACKER head control).
The OCSC1 matrices are the ITU-R BT.601, BT.709 and BT.2020 coefficients
at limited-range scale; re-derived independently, they match NVIDIA's register values to within 4 in the last place, and the patch uses NVIDIA's values so the output is bit-identical to the proprietary driver
on the same hardware.

Selection policy follows drm_hdmi_state_helper.c, with amdgpu as the reference consumer of the "color format" property: sink rules per format (RGB/4:4:4 Deep Color bits, 4:2:2 up to 12 bpc in the 24-bit container, 4:2:0 through its own bits), TMDS character rates from drm_hdmi_compute_mode_clock(), "Automatic" picking RGB and falling back
to 4:2:0, explicit requests honoured or refused.  YCbCr is limited range
with the CTA-861 default colorimetry (BT.709 above 576 lines, BT.601 below), declared in the AVI InfoFrame together with the pixel encoding.

One default changes: "Broadcast RGB" Automatic selects limited range for
CE video formats, as i915 and the HDMI helpers do.  Today nouveau sends
full-range pixels there and can only declare that to sinks with a Video
Capability Data Block, so sinks without one apply their default limited
range to full-range data.  "Full" restores the previous output.

  1: NVC57D output CSC and clamp methods (class header)
  2: program PROCAMP/OCSC1/clamps from head state (no functional change)
  3: Broadcast RGB
  4: color format with YCbCr 4:4:4 and 4:2:2
  5: YCbCr 4:2:0 on GA102+, gated per head on the capability notifier 6: the same properties on DVI connectors, which carry HDMI to HDMI sinks through passive adapters (reported by the automated review of the Deep Color series v1)

Tested on a GA106 (RTX 3060) driving a Sony KDL-46HX855 (HDMI 1.4, YCbCr 4:4:4 and 4:2:2, DC_30/DC_36/DC_Y444, 225 MHz, no VCDB), 25 configurations in two runs: RGB full, limited and automatic at 8/10/12
bpc; YCbCr 4:4:4 and 4:2:2 at 8/10/12 bpc; BT.601 at 576p/480p and BT.709 from 720p; 640x480 held at 8 bpc; and side-by-side, top-and- bottom and frame-packed 3D at 12 bpc with YCbCr 4:4:4, limited RGB and
YCbCr 4:2:2.  Every frame carried colour bars over near-black and near-white steps; the sink accepted each signal and displayed correct colours and levels, and the driver's selection was logged per step.

Not tested here: 4:2:0 (the sink declares none) and DVI (the board has
no DVI port); both reuse the paths exercised above.  Volta keeps its current behaviour (NVKMS has no Volta display code to compare against)
and Blackwell (NVCA7D, same methods at a different stride) is left for
a follow-up.  The class header additions are verbatim subsets of NVIDIA's headers and carry their usual checkpatch style findings.

Normative chain: HDMI 1.4b section 6.5 (pixel encodings, General Control
Packet), HDMI 2.0 section 7.1 (YCbCr 4:2:0), CTA-861 (AVI InfoFrame Y/C/Q/YQ fields, default colorimetry, the QS rule), ITU-R BT.601, BT.709 and BT.2020.  Bench harness and logs:
https://github.com/danielcamposramos/sony-bravia-linux (tools/stereo-
modeset,
run27 and run28); curated public indexes:
https://github.com/danielcamposramos/awesome-linux-hdr and
https://github.com/danielcamposramos/awesome-stereoscopy.

Quoted 1 line

AI partners were leveraged in the production of this work.

You need to either tag your work with Assisted-by: if it is generated by an LLM. If you did the right thing and wrote it by hand and just used these tools for analysis, that's fine.

FWIW, If this was entirely generated by an LLM, then this is quite a lot of work and I'm very hesitant to review this. Going off:

https://github.com/danielcamposramos/awesome-linux-hdr

I am very concerned just about all of the results here came out of an LLM, according to the LLM generated provenance file, which means an actual real person with experience working on this needs to go back and verify that all of this is correct. That is a lot of work, and the idea that my review comments are just going to get fed back into an LLM are not remotely encouraging to the effort of having to go through and have a real person look this over.

Quoted 31 lines

Daniel Campos Ramos (6):
  drm/nouveau: add NVC57D output CSC and clamp range methods drm/nouveau: program head output conversion for limited range and YCbCr
  drm/nouveau: add the Broadcast RGB property for HDMI drm/nouveau: add HDMI YCbCr 4:4:4 and 4:2:2 output drm/nouveau: add HDMI YCbCr 4:2:0 output on GA102 and later drm/nouveau: expose HDMI output properties on DVI connectors

 drivers/gpu/drm/nouveau/dispnv50/atom.h       |  11 + drivers/gpu/drm/nouveau/dispnv50/disp.c       | 305 +++++++++++++++- --
 drivers/gpu/drm/nouveau/dispnv50/head.c       |  19 ++ drivers/gpu/drm/nouveau/dispnv50/head.h       |   3 +

 drivers/gpu/drm/nouveau/dispnv50/headc57d.c   | 112 +++++--
 .../drm/nouveau/include/nvhw/class/clc57d.h   |  34 ++
 .../drm/nouveau/include/nvhw/class/clc673.h   |  17 +
 .../drm/nouveau/include/nvhw/class/clc67d.h   |  16 +
 drivers/gpu/drm/nouveau/nouveau_connector.c   |  48 ++-
 9 files changed, 488 insertions(+), 77 deletions(-)

 create mode 100644 drivers/gpu/drm/nouveau/include/nvhw/class/clc673.h create mode 100644 drivers/gpu/drm/nouveau/include/nvhw/class/clc67d.h

base-commit: 73ef663c75688168e31dbe9c585b939be410a945
prerequisite-patch-id: 6bd193908862475dd809b40037984747467236d6
prerequisite-patch-id: bf3b51b5393ef1c612930f4c474e6852372ca7db
prerequisite-patch-id: 22c3f84b6576853e9d3053d4e5a15a4bd37e6dcd

#9 lore raw

Re: [PATCH 0/6] drm/nouveau: HDMI output colour format and quantization range

Quoted 9 lines · On Wed, 2026-09-23 at 12:13 -0400, [email protected] wrote:

You need to either tag your work with Assisted-by: if it is generated by an LLM. If you did the right thing and wrote it by hand and just used these tools for analysis, that's fine.

FWIW, If this was entirely generated by an LLM, then this is quite a lot of work and I'm very hesitant to review this. Going off:

https://github.com/danielcamposramos/awesome-linux-hdr

Quoted 7 lines

I am very concerned just about all of the results here came out of an LLM, according to the LLM generated provenance file, which means an actual real person with experience working on this needs to go back and verify that all of this is correct. That is a lot of work, and the idea that my review comments are just going to get fed back into an LLM are not remotely encouraging to the effort of having to go through and have a real person look this over.

Thank you, Lyude, both points are fair.

The code was not written by hand: an AI partner wrote it under my direction, and I left out the Assisted-by tag the kernel documentation asks for. I will resend with it on every patch, and the Deep Color series gets the same. Sorry for that detail: I disclosed it in the cover letter body, but the tag belongs on each patch.
For the record, the tools: both series were worked on inside Claude Code CLI and Codex CLI by several AI partners, Moonshot's Kimi, Zhipu's GLM, Anthropic's Claude, and OpenAI's GPT Astra and GPT Sol.

What was mine: I found the problem on my own bench (full-range pixels to a Sony without a VCDB), set the design rules (follow drm_hdmi_state_helper.c, use NVIDIA's open NVKMS as the hardware reference), and ran every hardware test myself, 25 configurations, checking bars and levels on the set.

The OCSC1 values were checked against NVKMS, not taken from the model's memory; the BT.601/709/2020 re-derivation was also done with the AI.

On awesome-linux-hdr: it is an index of links, not the evidence for this series.
Its provenance file names the AI partners for the source surveys; the hardware results are my bench measurements, and the logs for these patches are run27 and run28 in sony-bravia-linux (tools/stereo-modeset).

I read review comments and answer them myself.

Fixes will again be written with AI help, declared in each version, and tested on the same bench before they go out.

To make review cheaper, I can resend only patches 1 to 3 first (the header, the head programming, and Broadcast RGB, which fixes the visible range problem), or wait for whatever priority suits you or suites better. Feel free to also include it, if you want.

Daniel

#10 lore raw

Re: [PATCH 0/6] drm/nouveau: HDMI output colour format and quantization range

Responses below:

Quoted 47 lines · Daniel Campos Ramos
Quoted 11 lines · On Wed, 2026-09-23 at 12:13 -0400, [email protected] wrote:

You need to either tag your work with Assisted-by: if it is generated
by an LLM. If you did the right thing and wrote it by hand and just used these tools for analysis, that's fine.

FWIW, If this was entirely generated by an LLM, then this is quite a
lot of work and I'm very hesitant to review this. Going off:

https://github.com/danielcamposramos/awesome-linux-hdr

Quoted 12 lines

I am very concerned just about all of the results here came out of an
LLM, according to the LLM generated provenance file, which means an actual real person with experience working on this needs to go back and
verify that all of this is correct. That is a lot of work, and the idea
that my review comments are just going to get fed back into an LLM are
not remotely encouraging to the effort of having to go through and have
a real person look this over.

Thank you, Lyude, both points are fair.

The code was not written by hand: an AI partner wrote it under my direction, and I left out the Assisted-by tag the kernel documentation asks for. I will resend with it on every patch, and the Deep Color series gets the same.
Sorry for that detail: I disclosed it in the cover letter body, but the tag belongs on each patch.
For the record, the tools: both series were worked on inside Claude Code CLI and Codex CLI by several AI partners, Moonshot's Kimi, Zhipu's GLM, Anthropic's Claude, and OpenAI's GPT Astra and GPT Sol.

What was mine: I found the problem on my own bench (full-range pixels to a Sony without a VCDB), set the design rules (follow drm_hdmi_state_helper.c, use NVIDIA's open NVKMS as the hardware reference), and ran every hardware test myself, 25 configurations, checking bars and levels on the set.

The OCSC1 values were checked against NVKMS, not taken from the model's memory; the BT.601/709/2020 re-derivation was also done with the AI.

Quoted 6 lines

On awesome-linux-hdr: it is an index of links, not the evidence for this series.
Its provenance file names the AI partners for the source surveys; the hardware results are my bench measurements, and the logs for these patches are run27 and run28 in sony-bravia-linux (tools/stereo- modeset).

I'm happy to look at logs if I have something specifically I would like to verify, but verifying the entirety of how this works from a bunch of logs and measurements along with knowing whether we're missing anything from this implementation that would lead to regressions (I already know we are missing some things, which I will mention below) is more or less the same as having to go and just do the work by hand myself. At which point, I would strongly prefer someone to just implement the findings of those results by hand.

We also have someone who has been working on these features on nouveau's side already without the help of an LLM, and their work is pretty much almost complete already and handles the missing bits properly including:

* Implementing IMP both for atomic checking and for tile allocation on some tegra platforms
* Implementing display bandwidth allocation. This is needed for deep color with higher resolution displays, which will crash the GPU otherwise upon trying to set them (which I think would be the case with this patch series).
* Enabling DSC and FRL on HDMI (also needed for higher res HDMI displays)

We've already merged some of their work for this, in particular some of the work for fixing up blackwell and also reading HDR information from EDIDs. So I'm not really sure we want to use this work anyway, sorry about that!

One last thing though: it's somewhat of a moot point now, but in the
future: please consider just limiting your usage of LLM tooling for actually figuring out the details of how things work and then handle writing the code yourself after you go through the various openrm sources it points you to. If I had accepted this work, it would have taken a lot more time for me to actually get across the finish line and be comfortable with merging it then is really needed. There's a very hard limit as to the level of confidence anyone can have with LLM generated code without spending more time reviewing it then you would have if you wrote the code yourself, because you're now approaching your own code submissions from the narrow perspective of a reviewer and not its author.

We do require people take responsibility for LLM submissions. It's easy to you take responsibility, but this is more complicated then just "yeah I'll try looking at it again if something breaks". To me, if the code is LLM generated, then the work in it's entirety needs to be of a size where the author can reasonably have the exact level of understanding they would have had if they wrote the code line by line themselves and also trudged through the actual OpenRM code they were looking at themselves. Otherwise, I have to be the one to do it in some form. And that means me taking responsibility for the possible fallout, and spending a _lot_ time then I would with a normal submission to get as close to the level of understanding as an author as I can and then take on the responsibility of dealing with the potential fallout of the changes myself, quite possibly on my own.

FWIW: I think the approach that was taken recently with reverse- engineering how ray tracing/BVHs work on nvidia hardare is a great example of how these tools can be used without creating friction for maintainers. There was plenty of AI generated code there, but it was only given to us as a proof of concept with the expectation we might not actually use any of the code. Which meant we could try implementing it by hand and learn everything we can about the subject matter throughout that journey instead of trying to trudge through the LLM's code and hope very hope we don't miss or glance over anything. Just approaching stuff this way does genuinely provide a lot more confidence to maintainers, and does help to reduce the workload we have to deal with by making sure there's always a person reasonably in the loop. Otherwise we're struggling to make sure that's the case a lot more then before.

Quoted 12 lines

I read review comments and answer them myself.

Fixes will again be written with AI help, declared in each version, and tested on the same bench before they go out.

To make review cheaper, I can resend only patches 1 to 3 first (the header, the head programming, and Broadcast RGB, which fixes the visible range problem), or wait for whatever priority suits you or suites better. Feel free to also include it, if you want.

Daniel

#11 lore raw

Re: [PATCH 0/6] drm/nouveau: HDMI output colour format and quantization range

Thank you, Lyude, for the detailed answer; it makes sense.

The bandwidth point is fair: my sink tops out at 225 MHz, so deep colour at higher resolutions was never exercised here. I withdraw both series, this one and the HDMI Deep Color series v2.
Please treat them as a proof of concept, in the spirit of the ray tracing work, if any of it is useful.

Where can I find the other developer's work?
I would be glad to test it on my bench and report back with a Tested-by: a GA106 driving a Sony KDL-46HX855 (HDMI 1.4, Deep Color 30/36, no VCDB), including 12-bit frame-packed 3D at 222.75 MHz and full against limited range on a sink without a VCDB.

Daniel

#12 lore raw

Re: [PATCH 0/6] drm/nouveau: HDMI output colour format and quantization range

https://gitlab.freedesktop.org/mohamexiety/nouveau/-/commits/nouveau-imp-upstr-v120

From Mohamed: "the old one. new stuff still not pushed anywhere yet as i am still hunting down some bugs. works ok as long as usage bounds dont move in different directions"

Quoted 15 lines · Daniel Campos Ramos

Thank you, Lyude, for the detailed answer; it makes sense.

The bandwidth point is fair: my sink tops out at 225 MHz, so deep colour at higher resolutions was never exercised here.
I withdraw both series, this one and the HDMI Deep Color series v2. Please treat them as a proof of concept, in the spirit of the ray tracing work, if any of it is useful.

Where can I find the other developer's work?
I would be glad to test it on my bench and report back with a Tested-
by: a GA106 driving a Sony KDL-46HX855 (HDMI 1.4, Deep Color 30/36, no VCDB), including 12-bit frame-packed 3D at 222.75 MHz and full against limited range on a sink without a VCDB.

Daniel