From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0D204D9907 for ; Wed, 22 Jul 2026 11:50:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784721026; cv=none; b=a3gdTYsghZkzZxhJKyOqVTl/AB0OK4WNUVCXwGYi0h4TOOhLbwkQ9a95h2LV4Bg41upKGYIY2ck1AN8tDFUTW5iAbB73K+1KcIqUQ/83b2882MzU0kskeqHE9S5x2rb7ygANFX6LwylkIJqI96Tb4Tj4bwaYBr+uEMEOvVH/Mzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784721026; c=relaxed/simple; bh=OOkAMe5UF/WOH3fkqozayM8HxNs0tFDK0/zEC/ufH8I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ygg2Dc8G371t6/OByiqzmjE/LddjWks6e/Krq79EwBO7B2u0xNn3YhVpf3+bm11YZ9ZwQ6Dcx6JNsr3idGSlx3rbA+D6oXl588pNufRrM7FdvO8EOr98GpRlxwN0urnqQmHZ6zz5BDYXTwGkMEJMeNOkIKpm10dxqod9u6DqHQU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=Z/8xhR+o; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Z/8xhR+o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1784721016; bh=OOkAMe5UF/WOH3fkqozayM8HxNs0tFDK0/zEC/ufH8I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Z/8xhR+oSr7zSuITAXdjxAA6ucyaMSQK655Uy2KZ2lT0fC0DKsqcgLdtRWLT5WjaD /VITUpAKoGI08xb/kNwMUWuuo/TiQpR9B37Bn6/typT9rk8Yr43IZr587b576iCEfu Y1bjsb+esHvnMejDUKhQkg9YqyLvTV2IaOjrwLqcWpVM4Nc/IstOAdDpr3UeJopETG J9+B5H18F4t3WMXcho2AvATzeEdgOABsFMOj1B/MsmsHc4jJAha+Jz5HV/dJrCKWR8 7Df3foPjjjpVPy3FREUXTu6mDh3olmK7tbMPRWCa+a4vhj2xWJzBVwl0WAOu5GNmcj Fm5FRP/tu2cIw== Received: from [100.64.0.241] (unknown [100.64.0.241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id 21A5A17E0177; Wed, 22 Jul 2026 13:50:16 +0200 (CEST) Message-ID: Date: Wed, 22 Jul 2026 14:50:15 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper To: Dmitry Baryshkov Cc: Maxime Ripard , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Luca Ceresoli , Sandy Huang , =?UTF-8?Q?Heiko_St=C3=BCbner?= , Andy Yan , Daniel Stone , Dave Stevenson , =?UTF-8?Q?Ma=C3=ADra_Canal?= , Raspberry Pi Kernel Maintenance , kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org References: <20260702-dw-hdmi-qp-scramb-v8-0-d79890d00b6a@collabora.com> <20260702-dw-hdmi-qp-scramb-v8-2-d79890d00b6a@collabora.com> <20260707-illegal-tuna-of-force-1c06e3@houat> <737678ab-f082-4a0e-b453-f403ba141437@collabora.com> <80374deb-3246-413f-a043-66bcdb438ab1@collabora.com> <20260715-fair-opalescent-rhino-c6407b@houat> <45113534-94ad-4a0f-8014-c04e9ab67a26@collabora.com> Content-Language: en-US From: Cristian Ciocaltea In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 7/22/26 9:46 AM, Dmitry Baryshkov wrote: > On Wed, Jul 15, 2026 at 01:34:19PM +0300, Cristian Ciocaltea wrote: >> On 7/15/26 11:50 AM, Maxime Ripard wrote: >>> On Fri, Jul 10, 2026 at 01:27:37PM +0300, Cristian Ciocaltea wrote: >>>> On 7/8/26 1:11 PM, Cristian Ciocaltea wrote: >>>>> Hi Maxime, >>>>> >>>>> On 7/7/26 7:10 PM, Maxime Ripard wrote: >>>>>> On Fri, Jul 03, 2026 at 10:31:55PM +0300, Cristian Ciocaltea wrote: >>>>>>> Hi Dmitry, >>>>>>> >>>>>>> Thanks for your quick review! >>>>>>> >>>>>>> On 7/3/26 5:05 PM, Dmitry Baryshkov wrote: >>>>>>>> On Thu, Jul 02, 2026 at 05:46:15PM +0300, Cristian Ciocaltea wrote: >>>>>>>>> In preparation for adding HDMI 2.x source capabilities, introduce struct >>>>>>>>> drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() >>>>>>>>> helper. >>>>>>>>> >>>>>>>>> The existing drmm_connector_hdmi_init() helper currently takes >>>>>>>>> individual capability arguments such as supported_formats and max_bpc. >>>>>>>>> Adding more HDMI-specific arguments to that function would not scale >>>>>>>>> well, so move those values into a dedicated capabilities structure and >>>>>>>>> implement the existing helper as a wrapper around the new caps-based >>>>>>>>> interface. >>>>>>>> >>>>>>>> I think, it was an intention of Maxime: make sure that every driver is >>>>>>>> forced to provide some values here. With the struct-based init it is >>>>>>>> easy to overlook or to ommit a value. >>>>>>> >>>>>>> Agreed that the struct-based init loses the compile-time guarantee that every >>>>>>> argument is explicitly provided - that's a real downside. >>>>>>> >>>>>>> I'd argue it's recoverable, though: the init helper validates the mandatory >>>>>>> fields, so a driver that omits a required value gets rejected at init time >>>>>>> rather than silently misconfigured. The "you must provide sane values" property >>>>>>> is expected to be preserved, just enforced at runtime instead of by the >>>>>>> compiler. >>>>>> >>>>>> Yeah, I don't think we can win with C here. Rust might, but we're >>>>>> probably a long way from that. >>>>>> >>>>>>> The main motivation for the struct is scalability/maintainability as we add HDMI >>>>>>> 2.x capabilities: new fields go into the struct rather than growing the helper's >>>>>>> argument list, so existing callers don't need churny signature updates on every >>>>>>> extension. >>>>>>> >>>>>>> FWIW, in the previous revision we discussed addressing the concern with a >>>>>>> callback instead. Sadly, I had to discard that approach, as it proved not >>>>>>> flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and >>>>>>> would have required either stateful callbacks, or storing redundant/temporary >>>>>>> cap data in driver-private structures just to satisfy the callback. >>>>>> >>>>>> I just realized something reviewing your patch: we don't necessarily >>>>>> need an extra argument or a callback, we can just put these fields into >>>>>> drm_hdmi_connector_funcs directly, and then validate them in init. >>>>> >>>>> If I understand correctly, we should drop the drm_connector_hdmi_caps struct >>>>> introduced by this patch and move all its fields into drm_hdmi_connector_funcs. >>>>> >>>>> In that case, how should we proceed with drmm_connector_hdmi_init()? >>>> >>>> Actually, this brings us to the callback issue: we cannot compute caps >>>> dynamically, as it only works with static data, since funcs is supposed to be >>>> immutable. >>> >>> Does it? The core and helpers must consider it immutable but it doesn't >>> have to. drm_bridge_connector for example could totally allocate it and >>> dynamically create it based on the bridge capabilities. >> >> If we take the VC4 case, is it fine to drop the const from the static >> drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and >> max_bpc in vc4_hdmi_connector_init()? >> >> static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = { >> .tmds_char_rate_valid = vc4_hdmi_connector_clock_valid, >> ... >> } >> >> static int vc4_hdmi_connector_init() >> { >> ... >> >> if (vc4_hdmi->variant->supports_hdr) >> vc4_hdmi_hdmi_connector_funcs.max_bpc = 12; >> >> if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ) >> vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0; >> else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ) >> vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3; >> ... >> } > > I'm sorry for the late response, I was OoO. Why do we want to put data > into the funcs part? My suggestion would be to put the data into the > drm_connector_hdmi itself. > > > Setting connector->hdmi.supported_hdmi_ver = HDMI_VERSION_1_4; is more > idiomatic than passing it through the funcs. On 7/22/26 9:46 AM, Dmitry Baryshkov wrote: > On Wed, Jul 15, 2026 at 01:34:19PM +0300, Cristian Ciocaltea wrote: >> On 7/15/26 11:50 AM, Maxime Ripard wrote: >>> On Fri, Jul 10, 2026 at 01:27:37PM +0300, Cristian Ciocaltea wrote: >>>> On 7/8/26 1:11 PM, Cristian Ciocaltea wrote: >>>>> Hi Maxime, >>>>> >>>>> On 7/7/26 7:10 PM, Maxime Ripard wrote: >>>>>> On Fri, Jul 03, 2026 at 10:31:55PM +0300, Cristian Ciocaltea wrote: >>>>>>> Hi Dmitry, >>>>>>> >>>>>>> Thanks for your quick review! >>>>>>> >>>>>>> On 7/3/26 5:05 PM, Dmitry Baryshkov wrote: >>>>>>>> On Thu, Jul 02, 2026 at 05:46:15PM +0300, Cristian Ciocaltea wrote: >>>>>>>>> In preparation for adding HDMI 2.x source capabilities, introduce struct >>>>>>>>> drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() >>>>>>>>> helper. >>>>>>>>> >>>>>>>>> The existing drmm_connector_hdmi_init() helper currently takes >>>>>>>>> individual capability arguments such as supported_formats and max_bpc. >>>>>>>>> Adding more HDMI-specific arguments to that function would not scale >>>>>>>>> well, so move those values into a dedicated capabilities structure and >>>>>>>>> implement the existing helper as a wrapper around the new caps-based >>>>>>>>> interface. >>>>>>>> >>>>>>>> I think, it was an intention of Maxime: make sure that every driver is >>>>>>>> forced to provide some values here. With the struct-based init it is >>>>>>>> easy to overlook or to ommit a value. >>>>>>> >>>>>>> Agreed that the struct-based init loses the compile-time guarantee that every >>>>>>> argument is explicitly provided - that's a real downside. >>>>>>> >>>>>>> I'd argue it's recoverable, though: the init helper validates the mandatory >>>>>>> fields, so a driver that omits a required value gets rejected at init time >>>>>>> rather than silently misconfigured. The "you must provide sane values" property >>>>>>> is expected to be preserved, just enforced at runtime instead of by the >>>>>>> compiler. >>>>>> >>>>>> Yeah, I don't think we can win with C here. Rust might, but we're >>>>>> probably a long way from that. >>>>>> >>>>>>> The main motivation for the struct is scalability/maintainability as we add HDMI >>>>>>> 2.x capabilities: new fields go into the struct rather than growing the helper's >>>>>>> argument list, so existing callers don't need churny signature updates on every >>>>>>> extension. >>>>>>> >>>>>>> FWIW, in the previous revision we discussed addressing the concern with a >>>>>>> callback instead. Sadly, I had to discard that approach, as it proved not >>>>>>> flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and >>>>>>> would have required either stateful callbacks, or storing redundant/temporary >>>>>>> cap data in driver-private structures just to satisfy the callback. >>>>>> >>>>>> I just realized something reviewing your patch: we don't necessarily >>>>>> need an extra argument or a callback, we can just put these fields into >>>>>> drm_hdmi_connector_funcs directly, and then validate them in init. >>>>> >>>>> If I understand correctly, we should drop the drm_connector_hdmi_caps struct >>>>> introduced by this patch and move all its fields into drm_hdmi_connector_funcs. >>>>> >>>>> In that case, how should we proceed with drmm_connector_hdmi_init()? >>>> >>>> Actually, this brings us to the callback issue: we cannot compute caps >>>> dynamically, as it only works with static data, since funcs is supposed to be >>>> immutable. >>> >>> Does it? The core and helpers must consider it immutable but it doesn't >>> have to. drm_bridge_connector for example could totally allocate it and >>> dynamically create it based on the bridge capabilities. >> >> If we take the VC4 case, is it fine to drop the const from the static >> drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and >> max_bpc in vc4_hdmi_connector_init()? >> >> static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = { >> .tmds_char_rate_valid = vc4_hdmi_connector_clock_valid, >> ... >> } >> >> static int vc4_hdmi_connector_init() >> { >> ... >> >> if (vc4_hdmi->variant->supports_hdr) >> vc4_hdmi_hdmi_connector_funcs.max_bpc = 12; >> >> if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ) >> vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0; >> else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ) >> vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3; >> ... >> } > > I'm sorry for the late response, I was OoO. Why do we want to put data > into the funcs part? My suggestion would be to put the data into the > drm_connector_hdmi itself. > > > Setting connector->hdmi.supported_hdmi_ver = HDMI_VERSION_1_4; is more > idiomatic than passing it through the funcs. I've already done the conversion so that vendor, product, supported_formats and max_bpc values previously passed as arguments are now provided through drm_connector_hdmi_funcs, along with the additional supported_hdmi_ver and supported_tmds_char_rate fields. In most cases it wasn't necessary to pass this data dynamically (with the exception of the bridge connector and some kunit tests), so it was just a matter of extending the immutable hdmi_funcs structs. I'll send v9 a bit later today so we can discuss directly on the code changes. FWIW, in the VC4 case, I followed Maxime's suggestion and introduced three hdmi_funcs instances (+ a macro to avoid duplication) and assigned them to the corresponding vc4_hdmi_variant entries: #define VC4_HDMI_CONNECTOR_FUNCS_COMMON \ .vendor = "Broadcom", \ .product = "Videocore", \ .supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) | \ BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422) | \ BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444), \ .tmds_char_rate_valid = vc4_hdmi_connector_clock_valid, \ .avi = { \ .clear_infoframe = vc4_hdmi_clear_avi_infoframe, \ .write_infoframe = vc4_hdmi_write_avi_infoframe, \ }, \ .hdmi = { \ .clear_infoframe = vc4_hdmi_clear_hdmi_infoframe, \ .write_infoframe = vc4_hdmi_write_hdmi_infoframe, \ }, \ ... static const struct drm_connector_hdmi_funcs vc4_hdmi_connector_funcs_hdmi14 = { VC4_HDMI_CONNECTOR_FUNCS_COMMON, .max_bpc = 12, .supported_hdmi_ver = HDMI_VERSION_1_4, }; static const struct drm_connector_hdmi_funcs vc4_hdmi_connector_funcs_hdmi20 = { VC4_HDMI_CONNECTOR_FUNCS_COMMON, .max_bpc = 12, .supported_hdmi_ver = HDMI_VERSION_2_0, .scrambler_enable = vc4_hdmi_scrambler_enable, .scrambler_disable = vc4_hdmi_scrambler_disable, }; static const struct vc4_hdmi_variant bcm2712_hdmi0_variant = { ... .hp_detect = vc5_hdmi_hp_detect, .hdmi_funcs = &vc4_hdmi_connector_funcs_hdmi20, }; vc4_hdmi_connector_init() { ... ret = drmm_connector_hdmi_init(dev, connector, &vc4_hdmi_connector_funcs, vc4_hdmi->variant->hdmi_funcs, DRM_MODE_CONNECTOR_HDMIA, vc4_hdmi->ddc); ... }