Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6035126rdb; Thu, 14 Dec 2023 06:49:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKO+OJ/YBxLh9DhFx9bXlrPcgi6nC1Y0rIT2pnOvE8up0cOfMT8Rlaw9wuMm1D89QqQHxa X-Received: by 2002:a17:90a:2a41:b0:28a:f1fc:d1f4 with SMTP id d1-20020a17090a2a4100b0028af1fcd1f4mr1060663pjg.31.1702565366536; Thu, 14 Dec 2023 06:49:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702565366; cv=none; d=google.com; s=arc-20160816; b=fIPdDZ16SMw9Y4hjAbXM3J1GNaOOu42kb0qB1X6Wv/KvqNu9HDSEDkqmOsGYSUMAI1 lBuuGCs8swA7MCl5BS8V+2LdFL8gngmeVbbrIZQ14RMUnSQBTBFLO7jNyINQsDH6BA/m g6BKtmMMlsR09PlDsncdm4z3bwkNaSRnrP80g5g/Th4/uERihjACn8kbo9AzXJySIkII jY3W43b8B6Zar1sad9x3OaLrtIH96IyACq/IJKrB4oWTTWnDCfPedeQ0voP5E0JsYwqt QguAHxp93obnpeZpXFuGapSYOZ5A0tbTYX7HnE9ofA4k1bhVlDukv3MwLO/ElZzVp7AA PX5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=G5JzwHRVEypCqvTdcDRtZJZR/2+LpfKoxII+LKxkCRY=; fh=zQ9/wNmcVHWu4SuPOylBxCR7EoDQI9lVwbYU0s8q4Hc=; b=e3klB5AL7ZAL+YOFT0WZW7jW7dXhwJz3kosV0B/ZllbhqCkWaDWSmdc3mB0hlRCotX SLw7UE0a8JZ55FPad6cACxc4ZMsK/dHn8apR12VaTmR0Etxq6nCUEe6sTleaobeiVXaA ChejRwv7X0xMwJC/NRzx7AKV/Oirw0PZD5KNocJi8ny3PTmNViX3Pays5/2aFjnNaBTA GsPrs8yZUepwL3PvkkVGmvQdpXDBmZIwvYWudkXHVh+l8c/RZsciUyQAdwOBoXRiUUqC Te6nfnucmE5rlpURHw/qtlQvEPUuC3AEk4jPUtf8DjWSxARDuD5JGHZ7IUiIVAEW3IvF 1mow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=qP+z72M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id g8-20020a17090a708800b002839be230b2si12650076pjk.44.2023.12.14.06.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 06:49:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=qP+z72M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D70128242F7B; Thu, 14 Dec 2023 06:49:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573388AbjLNOs6 (ORCPT + 99 others); Thu, 14 Dec 2023 09:48:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbjLNOs5 (ORCPT ); Thu, 14 Dec 2023 09:48:57 -0500 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE7BC120 for ; Thu, 14 Dec 2023 06:49:01 -0800 (PST) Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-dbcc9d4b1aeso2098403276.2 for ; Thu, 14 Dec 2023 06:49:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1702565341; x=1703170141; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=G5JzwHRVEypCqvTdcDRtZJZR/2+LpfKoxII+LKxkCRY=; b=qP+z72M41runOlX+k3FzAK8KEalJdGhAJ+8Ld7Ol3sBMSn9dg6NHF6lYGZIUA7eP9x dYaqfxFItWdgf4Mnb0KP/klfx8iSl2tM8oShQQYg/KGVYhQ3LdJKdnsDdWMqQesgfCIG v2vqpjr//+xfEQatHMGs12XZbsVU9+HsDTSs8oMItl4esj9I7zQeyEOfM3p04LlHb3XI htqvA9uXi3QBb/QvyLqPs1rD6CfvLIw/WIJr7vKq6+dOH4jd4YvUMj4l9S9ZH4H++4JM zfsSoBAeYbRlZiLGoWGjgNBoyLTGp9ULpQ734q/xe8BAHvOqqiW1SDbjMwiFo/rD9669 rBRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702565341; x=1703170141; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=G5JzwHRVEypCqvTdcDRtZJZR/2+LpfKoxII+LKxkCRY=; b=qFGu6B09bHw0/t/71zjz0a65kqfDNCtTrlz5oUYqp/wAiNdtWY3Lhtyo5DIo84xlOT OScxiCtDSwkZ/xyzsNmafkLvLAnXW0BupgSaJdcGMwzinX1/e71dHcC9YAkNWOpvhaXM 6Pm5BILje18w2juV9w68SSB4dsgp2+19lsRtzyRsGVKmgLKuOHj7KKtMF1dZ/f18ZEmq LK+j13LgQK7VrIfTdFUZ2nINtz1LbpzRncdQLngTHEv9h0WxYOg9FDzp95yQuQW7Qpky tOhPVzASco94NQpslcRQo0PXiOCDr7JFdCslnOBolyJx8B7OxFAwwE3BmaM2JAsGeyL+ u6TQ== X-Gm-Message-State: AOJu0YwHj011UzrUhfy7kyu+i8B1+BDZFBtLBJJ/fDsdLnx51kBNwTdG p9Wn0fccpu3gL5w6HgE1NXT3+fARlX4W4RZ1LFL16A== X-Received: by 2002:a25:8452:0:b0:dbc:d9a9:90cb with SMTP id r18-20020a258452000000b00dbcd9a990cbmr1383166ybm.125.1702565340852; Thu, 14 Dec 2023 06:49:00 -0800 (PST) MIME-Version: 1.0 References: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@kernel.org> <20231207-kms-hdmi-connector-state-v5-10-6538e19d634d@kernel.org> In-Reply-To: <20231207-kms-hdmi-connector-state-v5-10-6538e19d634d@kernel.org> From: Dave Stevenson Date: Thu, 14 Dec 2023 14:48:44 +0000 Message-ID: Subject: Re: [PATCH v5 10/44] drm/connector: hdmi: Add output BPC to the connector state To: Maxime Ripard Cc: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?UTF-8?Q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Hans Verkuil , linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 14 Dec 2023 06:49:22 -0800 (PST) On Thu, 7 Dec 2023 at 15:50, Maxime Ripard wrote: > > We'll add automatic selection of the output BPC in a following patch, > but let's add it to the HDMI connector state already. > > Signed-off-by: Maxime Ripard Reviewed-by: Dave Stevenson > --- > drivers/gpu/drm/drm_atomic.c | 1 + > drivers/gpu/drm/drm_atomic_state_helper.c | 7 +- > drivers/gpu/drm/drm_connector.c | 20 +- > .../gpu/drm/tests/drm_atomic_state_helper_test.c | 227 ++++++++++++++++++++- > drivers/gpu/drm/tests/drm_connector_test.c | 153 +++++++++++++- > include/drm/drm_connector.h | 13 +- > 6 files changed, 402 insertions(+), 19 deletions(-) > > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c > index e4ad53e64e07..76c63ed04af4 100644 > --- a/drivers/gpu/drm/drm_atomic.c > +++ b/drivers/gpu/drm/drm_atomic.c > @@ -1147,6 +1147,7 @@ static void drm_atomic_connector_print_state(struct drm_printer *p, > drm_printf(p, "\tbroadcast_rgb=%s\n", > drm_hdmi_connector_get_broadcast_rgb_name(state->hdmi.broadcast_rgb)); > drm_printf(p, "\tis_full_range=%c\n", state->hdmi.is_full_range ? 'y' : 'n'); > + drm_printf(p, "\toutput_bpc=%u\n", state->hdmi.output_bpc); > } > > if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) > diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c > index 4a7114978c47..883bdc0349c0 100644 > --- a/drivers/gpu/drm/drm_atomic_state_helper.c > +++ b/drivers/gpu/drm/drm_atomic_state_helper.c > @@ -584,6 +584,10 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_tv_reset); > void __drm_atomic_helper_connector_hdmi_reset(struct drm_connector *connector, > struct drm_connector_state *new_state) > { > + unsigned int max_bpc = connector->max_bpc; > + > + new_state->max_bpc = max_bpc; > + new_state->max_requested_bpc = max_bpc; > new_state->hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO; > } > EXPORT_SYMBOL(__drm_atomic_helper_connector_hdmi_reset); > @@ -700,7 +704,8 @@ int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector, > > new_state->hdmi.is_full_range = hdmi_is_full_range(connector, new_state); > > - if (old_state->hdmi.broadcast_rgb != new_state->hdmi.broadcast_rgb) { > + if (old_state->hdmi.broadcast_rgb != new_state->hdmi.broadcast_rgb || > + old_state->hdmi.output_bpc != new_state->hdmi.output_bpc) { > struct drm_crtc *crtc = new_state->crtc; > struct drm_crtc_state *crtc_state; > > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c > index 929b0a911f62..139ac3d8160c 100644 > --- a/drivers/gpu/drm/drm_connector.c > +++ b/drivers/gpu/drm/drm_connector.c > @@ -459,6 +459,7 @@ EXPORT_SYMBOL(drmm_connector_init); > * @funcs: callbacks for this connector > * @connector_type: user visible type of the connector > * @ddc: optional pointer to the associated ddc adapter > + * @max_bpc: Maximum bits per char the HDMI connector supports > * > * Initialises a preallocated HDMI connector. Connectors can be > * subclassed as part of driver connector objects. > @@ -475,7 +476,8 @@ int drmm_connector_hdmi_init(struct drm_device *dev, > struct drm_connector *connector, > const struct drm_connector_funcs *funcs, > int connector_type, > - struct i2c_adapter *ddc) > + struct i2c_adapter *ddc, > + unsigned int max_bpc) > { > int ret; > > @@ -483,10 +485,26 @@ int drmm_connector_hdmi_init(struct drm_device *dev, > connector_type == DRM_MODE_CONNECTOR_HDMIB)) > return -EINVAL; > > + if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12)) > + return -EINVAL; > + > ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); > if (ret) > return ret; > > + /* > + * drm_connector_attach_max_bpc_property() requires the > + * connector to have a state. > + */ > + if (connector->funcs->reset) > + connector->funcs->reset(connector); > + > + drm_connector_attach_max_bpc_property(connector, 8, max_bpc); > + connector->max_bpc = max_bpc; > + > + if (max_bpc > 8) > + drm_connector_attach_hdr_output_metadata_property(connector); > + > return 0; > } > EXPORT_SYMBOL(drmm_connector_hdmi_init); > diff --git a/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c b/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c > index 7750c3d214a4..a1b0e6914cf8 100644 > --- a/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c > +++ b/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c > @@ -146,7 +146,8 @@ static const struct drm_connector_funcs dummy_connector_funcs = { > > static > struct drm_atomic_helper_connector_hdmi_priv * > -drm_atomic_helper_connector_hdmi_init(struct kunit *test) > +drm_atomic_helper_connector_hdmi_init(struct kunit *test, > + unsigned int max_bpc) > { > struct drm_atomic_helper_connector_hdmi_priv *priv; > struct drm_connector *conn; > @@ -188,7 +189,8 @@ drm_atomic_helper_connector_hdmi_init(struct kunit *test) > ret = drmm_connector_hdmi_init(drm, conn, > &dummy_connector_funcs, > DRM_MODE_CONNECTOR_HDMIA, > - NULL); > + NULL, > + max_bpc); > KUNIT_ASSERT_EQ(test, ret, 0); > > drm_connector_helper_add(conn, &dummy_connector_helper_funcs); > @@ -223,7 +225,7 @@ static void drm_test_check_broadcast_rgb_crtc_mode_changed(struct kunit *test) > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > ctx = drm_kunit_helper_acquire_ctx_alloc(test); > @@ -284,7 +286,7 @@ static void drm_test_check_broadcast_rgb_crtc_mode_not_changed(struct kunit *tes > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > ctx = drm_kunit_helper_acquire_ctx_alloc(test); > @@ -345,7 +347,7 @@ static void drm_test_check_broadcast_rgb_auto_cea_mode(struct kunit *test) > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > conn = &priv->connector; > @@ -399,7 +401,7 @@ static void drm_test_check_broadcast_rgb_auto_cea_mode_vic_1(struct kunit *test) > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > conn = &priv->connector; > @@ -452,7 +454,7 @@ static void drm_test_check_broadcast_rgb_full_cea_mode(struct kunit *test) > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > conn = &priv->connector; > @@ -508,7 +510,7 @@ static void drm_test_check_broadcast_rgb_full_cea_mode_vic_1(struct kunit *test) > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > conn = &priv->connector; > @@ -563,7 +565,7 @@ static void drm_test_check_broadcast_rgb_limited_cea_mode(struct kunit *test) > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > conn = &priv->connector; > @@ -619,7 +621,7 @@ static void drm_test_check_broadcast_rgb_limited_cea_mode_vic_1(struct kunit *te > struct drm_crtc *crtc; > int ret; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > conn = &priv->connector; > @@ -657,6 +659,138 @@ static void drm_test_check_broadcast_rgb_limited_cea_mode_vic_1(struct kunit *te > KUNIT_EXPECT_FALSE(test, conn_state->hdmi.is_full_range); > } > > +/* > + * Test that if we change the maximum bpc property to a different value, > + * we trigger a mode change on the connector's CRTC, which will in turn > + * disable/enable the connector. > + */ > +static void drm_test_check_output_bpc_crtc_mode_changed(struct kunit *test) > +{ > + struct drm_atomic_helper_connector_hdmi_priv *priv; > + struct drm_modeset_acquire_ctx *ctx; > + struct drm_connector_state *old_conn_state; > + struct drm_connector_state *new_conn_state; > + struct drm_crtc_state *crtc_state; > + struct drm_atomic_state *state; > + struct drm_display_mode *preferred; > + struct drm_connector *conn; > + struct drm_device *drm; > + struct drm_crtc *crtc; > + int ret; > + > + priv = drm_atomic_helper_connector_hdmi_init(test, 10); > + KUNIT_ASSERT_NOT_NULL(test, priv); > + > + ctx = drm_kunit_helper_acquire_ctx_alloc(test); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); > + > + conn = &priv->connector; > + preferred = find_preferred_mode(conn); > + KUNIT_ASSERT_NOT_NULL(test, preferred); > + > + drm = &priv->drm; > + crtc = priv->crtc; > + ret = light_up_connector(test, drm, crtc, conn, preferred, ctx); > + KUNIT_ASSERT_EQ(test, ret, 0); > + > + state = drm_kunit_helper_atomic_state_alloc(test, drm, ctx); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state); > + > + new_conn_state = drm_atomic_get_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_conn_state); > + > + old_conn_state = drm_atomic_get_old_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, old_conn_state); > + > + new_conn_state->hdmi.output_bpc = 8; > + > + KUNIT_ASSERT_NE(test, > + old_conn_state->hdmi.output_bpc, > + new_conn_state->hdmi.output_bpc); > + > + ret = drm_atomic_check_only(state); > + KUNIT_ASSERT_EQ(test, ret, 0); > + > + old_conn_state = drm_atomic_get_old_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, old_conn_state); > + > + new_conn_state = drm_atomic_get_new_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_conn_state); > + > + KUNIT_ASSERT_NE(test, > + old_conn_state->hdmi.output_bpc, > + new_conn_state->hdmi.output_bpc); > + > + crtc_state = drm_atomic_get_new_crtc_state(state, crtc); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc_state); > + KUNIT_EXPECT_TRUE(test, crtc_state->mode_changed); > +} > + > +/* > + * Test that if we set the output bpc property to the same value, we > + * don't trigger a mode change on the connector's CRTC and leave the > + * connector unaffected. > + */ > +static void drm_test_check_output_bpc_crtc_mode_not_changed(struct kunit *test) > +{ > + struct drm_atomic_helper_connector_hdmi_priv *priv; > + struct drm_modeset_acquire_ctx *ctx; > + struct drm_connector_state *old_conn_state; > + struct drm_connector_state *new_conn_state; > + struct drm_crtc_state *crtc_state; > + struct drm_atomic_state *state; > + struct drm_display_mode *preferred; > + struct drm_connector *conn; > + struct drm_device *drm; > + struct drm_crtc *crtc; > + int ret; > + > + priv = drm_atomic_helper_connector_hdmi_init(test, 10); > + KUNIT_ASSERT_NOT_NULL(test, priv); > + > + ctx = drm_kunit_helper_acquire_ctx_alloc(test); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); > + > + conn = &priv->connector; > + preferred = find_preferred_mode(conn); > + KUNIT_ASSERT_NOT_NULL(test, preferred); > + > + drm = &priv->drm; > + crtc = priv->crtc; > + ret = light_up_connector(test, drm, crtc, conn, preferred, ctx); > + KUNIT_ASSERT_EQ(test, ret, 0); > + > + state = drm_kunit_helper_atomic_state_alloc(test, drm, ctx); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state); > + > + new_conn_state = drm_atomic_get_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_conn_state); > + > + old_conn_state = drm_atomic_get_old_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, old_conn_state); > + > + KUNIT_ASSERT_EQ(test, > + new_conn_state->hdmi.output_bpc, > + old_conn_state->hdmi.output_bpc); > + > + ret = drm_atomic_check_only(state); > + KUNIT_ASSERT_EQ(test, ret, 0); > + > + old_conn_state = drm_atomic_get_old_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, old_conn_state); > + > + new_conn_state = drm_atomic_get_new_connector_state(state, conn); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_conn_state); > + > + KUNIT_EXPECT_EQ(test, > + old_conn_state->hdmi.output_bpc, > + new_conn_state->hdmi.output_bpc); > + > + crtc_state = drm_atomic_get_new_crtc_state(state, crtc); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc_state); > + KUNIT_EXPECT_FALSE(test, crtc_state->mode_changed); > +} > + > static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = { > KUNIT_CASE(drm_test_check_broadcast_rgb_auto_cea_mode), > KUNIT_CASE(drm_test_check_broadcast_rgb_auto_cea_mode_vic_1), > @@ -666,6 +800,8 @@ static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = { > KUNIT_CASE(drm_test_check_broadcast_rgb_limited_cea_mode_vic_1), > KUNIT_CASE(drm_test_check_broadcast_rgb_crtc_mode_changed), > KUNIT_CASE(drm_test_check_broadcast_rgb_crtc_mode_not_changed), > + KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_changed), > + KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_not_changed), > { } > }; > > @@ -684,7 +820,7 @@ static void drm_test_check_broadcast_rgb_value(struct kunit *test) > struct drm_connector_state *conn_state; > struct drm_connector *conn; > > - priv = drm_atomic_helper_connector_hdmi_init(test); > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > KUNIT_ASSERT_NOT_NULL(test, priv); > > conn = &priv->connector; > @@ -692,8 +828,77 @@ static void drm_test_check_broadcast_rgb_value(struct kunit *test) > KUNIT_EXPECT_EQ(test, conn_state->hdmi.broadcast_rgb, DRM_HDMI_BROADCAST_RGB_AUTO); > } > > +/* > + * Test that if the connector was initialised with a maximum bpc of 8, > + * the value of the max_bpc and max_requested_bpc properties out of > + * reset are also set to 8, and output_bpc is set to 0 and will be > + * filled at atomic_check time. > + */ > +static void drm_test_check_bpc_8_value(struct kunit *test) > +{ > + struct drm_atomic_helper_connector_hdmi_priv *priv; > + struct drm_connector_state *conn_state; > + struct drm_connector *conn; > + > + priv = drm_atomic_helper_connector_hdmi_init(test, 8); > + KUNIT_ASSERT_NOT_NULL(test, priv); > + > + conn = &priv->connector; > + conn_state = conn->state; > + KUNIT_EXPECT_EQ(test, conn_state->max_bpc, 8); > + KUNIT_EXPECT_EQ(test, conn_state->max_requested_bpc, 8); > + KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 0); > +} > + > +/* > + * Test that if the connector was initialised with a maximum bpc of 10, > + * the value of the max_bpc and max_requested_bpc properties out of > + * reset are also set to 10, and output_bpc is set to 0 and will be > + * filled at atomic_check time. > + */ > +static void drm_test_check_bpc_10_value(struct kunit *test) > +{ > + struct drm_atomic_helper_connector_hdmi_priv *priv; > + struct drm_connector_state *conn_state; > + struct drm_connector *conn; > + > + priv = drm_atomic_helper_connector_hdmi_init(test, 10); > + KUNIT_ASSERT_NOT_NULL(test, priv); > + > + conn = &priv->connector; > + conn_state = conn->state; > + KUNIT_EXPECT_EQ(test, conn_state->max_bpc, 10); > + KUNIT_EXPECT_EQ(test, conn_state->max_requested_bpc, 10); > + KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 0); > +} > + > +/* > + * Test that if the connector was initialised with a maximum bpc of 12, > + * the value of the max_bpc and max_requested_bpc properties out of > + * reset are also set to 12, and output_bpc is set to 0 and will be > + * filled at atomic_check time. > + */ > +static void drm_test_check_bpc_12_value(struct kunit *test) > +{ > + struct drm_atomic_helper_connector_hdmi_priv *priv; > + struct drm_connector_state *conn_state; > + struct drm_connector *conn; > + > + priv = drm_atomic_helper_connector_hdmi_init(test, 12); > + KUNIT_ASSERT_NOT_NULL(test, priv); > + > + conn = &priv->connector; > + conn_state = conn->state; > + KUNIT_EXPECT_EQ(test, conn_state->max_bpc, 12); > + KUNIT_EXPECT_EQ(test, conn_state->max_requested_bpc, 12); > + KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 0); > +} > + > static struct kunit_case drm_atomic_helper_connector_hdmi_reset_tests[] = { > KUNIT_CASE(drm_test_check_broadcast_rgb_value), > + KUNIT_CASE(drm_test_check_bpc_8_value), > + KUNIT_CASE(drm_test_check_bpc_10_value), > + KUNIT_CASE(drm_test_check_bpc_12_value), > { } > }; > > diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c > index 41d33dea30af..fef7d53d34d4 100644 > --- a/drivers/gpu/drm/tests/drm_connector_test.c > +++ b/drivers/gpu/drm/tests/drm_connector_test.c > @@ -186,7 +186,8 @@ static void drm_test_connector_hdmi_init_valid(struct kunit *test) > ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, > &dummy_funcs, > DRM_MODE_CONNECTOR_HDMIA, > - &priv->ddc); > + &priv->ddc, > + 8); > KUNIT_EXPECT_EQ(test, ret, 0); > } > > @@ -202,10 +203,144 @@ static void drm_test_connector_hdmi_init_null_ddc(struct kunit *test) > ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, > &dummy_funcs, > DRM_MODE_CONNECTOR_HDMIA, > - NULL); > + NULL, > + 8); > KUNIT_EXPECT_EQ(test, ret, 0); > } > > +/* > + * Test that the registration of a connector with an invalid maximum bpc > + * count fails. > + */ > +static void drm_test_connector_hdmi_init_bpc_invalid(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + int ret; > + > + ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, > + &dummy_funcs, > + DRM_MODE_CONNECTOR_HDMIA, > + &priv->ddc, > + 9); > + KUNIT_EXPECT_LT(test, ret, 0); > +} > + > +/* > + * Test that the registration of a connector with a null maximum bpc > + * count fails. > + */ > +static void drm_test_connector_hdmi_init_bpc_null(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + int ret; > + > + ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, > + &dummy_funcs, > + DRM_MODE_CONNECTOR_HDMIA, > + &priv->ddc, > + 0); > + KUNIT_EXPECT_LT(test, ret, 0); > +} > + > +/* > + * Test that the registration of a connector with a maximum bpc count of > + * 8 succeeds, registers the max bpc property, but doesn't register the > + * HDR output metadata one. > + */ > +static void drm_test_connector_hdmi_init_bpc_8(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + struct drm_connector *connector = &priv->connector; > + struct drm_property *prop; > + uint64_t val; > + int ret; > + > + ret = drmm_connector_hdmi_init(&priv->drm, connector, > + &dummy_funcs, > + DRM_MODE_CONNECTOR_HDMIA, > + &priv->ddc, > + 8); > + KUNIT_EXPECT_EQ(test, ret, 0); > + > + prop = connector->max_bpc_property; > + KUNIT_ASSERT_NOT_NULL(test, prop); > + KUNIT_EXPECT_NOT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id)); > + > + ret = drm_object_property_get_value(&connector->base, prop, &val); > + KUNIT_EXPECT_EQ(test, ret, 0); > + KUNIT_EXPECT_EQ(test, val, 8); > + > + prop = priv->drm.mode_config.hdr_output_metadata_property; > + KUNIT_ASSERT_NOT_NULL(test, prop); > + KUNIT_EXPECT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id)); > +} > + > +/* > + * Test that the registration of a connector with a maximum bpc count of > + * 10 succeeds and registers the max bpc and HDR output metadata > + * properties. > + */ > +static void drm_test_connector_hdmi_init_bpc_10(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + struct drm_connector *connector = &priv->connector; > + struct drm_property *prop; > + uint64_t val; > + int ret; > + > + ret = drmm_connector_hdmi_init(&priv->drm, connector, > + &dummy_funcs, > + DRM_MODE_CONNECTOR_HDMIA, > + &priv->ddc, > + 10); > + KUNIT_EXPECT_EQ(test, ret, 0); > + > + prop = connector->max_bpc_property; > + KUNIT_ASSERT_NOT_NULL(test, prop); > + KUNIT_EXPECT_NOT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id)); > + > + ret = drm_object_property_get_value(&connector->base, prop, &val); > + KUNIT_EXPECT_EQ(test, ret, 0); > + KUNIT_EXPECT_EQ(test, val, 10); > + > + prop = priv->drm.mode_config.hdr_output_metadata_property; > + KUNIT_ASSERT_NOT_NULL(test, prop); > + KUNIT_EXPECT_NOT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id)); > +} > + > +/* > + * Test that the registration of a connector with a maximum bpc count of > + * 12 succeeds and registers the max bpc and HDR output metadata > + * properties. > + */ > +static void drm_test_connector_hdmi_init_bpc_12(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + struct drm_connector *connector = &priv->connector; > + struct drm_property *prop; > + uint64_t val; > + int ret; > + > + ret = drmm_connector_hdmi_init(&priv->drm, connector, > + &dummy_funcs, > + DRM_MODE_CONNECTOR_HDMIA, > + &priv->ddc, > + 12); > + KUNIT_EXPECT_EQ(test, ret, 0); > + > + prop = connector->max_bpc_property; > + KUNIT_ASSERT_NOT_NULL(test, prop); > + KUNIT_EXPECT_NOT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id)); > + > + ret = drm_object_property_get_value(&connector->base, prop, &val); > + KUNIT_EXPECT_EQ(test, ret, 0); > + KUNIT_EXPECT_EQ(test, val, 12); > + > + prop = priv->drm.mode_config.hdr_output_metadata_property; > + KUNIT_ASSERT_NOT_NULL(test, prop); > + KUNIT_EXPECT_NOT_NULL(test, drm_mode_obj_find_prop_id(&connector->base, prop->base.id)); > +} > + > /* > * Test that the registration of an HDMI connector with an HDMI > * connector type succeeds. > @@ -219,7 +354,8 @@ static void drm_test_connector_hdmi_init_type_valid(struct kunit *test) > ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, > &dummy_funcs, > connector_type, > - &priv->ddc); > + &priv->ddc, > + 8); > KUNIT_EXPECT_EQ(test, ret, 0); > } > > @@ -250,7 +386,8 @@ static void drm_test_connector_hdmi_init_type_invalid(struct kunit *test) > ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, > &dummy_funcs, > connector_type, > - &priv->ddc); > + &priv->ddc, > + 8); > KUNIT_EXPECT_LT(test, ret, 0); > } > > @@ -282,6 +419,11 @@ KUNIT_ARRAY_PARAM(drm_connector_hdmi_init_type_invalid, > > static struct kunit_case drmm_connector_hdmi_init_tests[] = { > KUNIT_CASE(drm_test_connector_hdmi_init_valid), > + KUNIT_CASE(drm_test_connector_hdmi_init_bpc_8), > + KUNIT_CASE(drm_test_connector_hdmi_init_bpc_10), > + KUNIT_CASE(drm_test_connector_hdmi_init_bpc_12), > + KUNIT_CASE(drm_test_connector_hdmi_init_bpc_invalid), > + KUNIT_CASE(drm_test_connector_hdmi_init_bpc_null), > KUNIT_CASE(drm_test_connector_hdmi_init_null_ddc), > KUNIT_CASE_PARAM(drm_test_connector_hdmi_init_type_valid, > drm_connector_hdmi_init_type_valid_gen_params), > @@ -447,7 +589,8 @@ static void drm_test_drm_connector_attach_broadcast_rgb_property_hdmi_connector( > ret = drmm_connector_hdmi_init(&priv->drm, connector, > &dummy_funcs, > DRM_MODE_CONNECTOR_HDMIA, > - &priv->ddc); > + &priv->ddc, > + 8); > KUNIT_EXPECT_EQ(test, ret, 0); > > ret = drm_connector_attach_broadcast_rgb_property(connector); > diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h > index 76eecd449fb8..1b1b6aed04ee 100644 > --- a/include/drm/drm_connector.h > +++ b/include/drm/drm_connector.h > @@ -1072,6 +1072,11 @@ struct drm_connector_state { > * RGB Quantization Range or not? > */ > bool is_full_range; > + > + /** > + * @output_bpc: Bits per color channel to output. > + */ > + unsigned int output_bpc; > } hdmi; > }; > > @@ -1717,6 +1722,11 @@ struct drm_connector { > */ > struct drm_property_blob *path_blob_ptr; > > + /** > + * @max_bpc: Maximum bits per color channel the connector supports. > + */ > + unsigned int max_bpc; > + > /** > * @max_bpc_property: Default connector property for the max bpc to be > * driven out of the connector. > @@ -1956,7 +1966,8 @@ int drmm_connector_hdmi_init(struct drm_device *dev, > struct drm_connector *connector, > const struct drm_connector_funcs *funcs, > int connector_type, > - struct i2c_adapter *ddc); > + struct i2c_adapter *ddc, > + unsigned int max_bpc); > void drm_connector_attach_edid_property(struct drm_connector *connector); > int drm_connector_register(struct drm_connector *connector); > void drm_connector_unregister(struct drm_connector *connector); > > -- > 2.43.0 >