Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1365872pxf; Fri, 19 Mar 2021 05:51:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUfWd2jiZHnuFHfFT3ePVlmBgnlOSvyF55E8823bB7Ho94o8NlDtG8Iqf1KHolSBQgna1t X-Received: by 2002:a05:6402:5252:: with SMTP id t18mr9595913edd.258.1616158274867; Fri, 19 Mar 2021 05:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616158274; cv=none; d=google.com; s=arc-20160816; b=aaPmFuThHgESFazeEjTJuFgoGFUiI9SJZ++x+vk0DzO+BoxraxqwCYwBKvmHwLp7dJ ti/dON9LoNxQkI0LcqB1s4GC4UmCwA3F2G/8L7nm8byCtVZ2y2mf8ux6ckba04+lldvN /Qzh+ChEVjqnrEo0Wj370BY82roT2Gr7N+0xTFonfsF/zJN/mQ/YnPEn66XQjZE6tixQ VMM5AZN5BSo8CMuEqHRES0qD1FHLiFzcTuMbqQOGjTyujBAQO1+724HNtPtRJRAW3BWg nzC8AUaj//Sp3aLF00PMjnwKSiMe/FCLma0zb/L70+FYymM3rlZmJdFEAxcdNT9E0xgS PEQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=c847Pq0vLWucLjucHu8bhUQZoFlP9PYipIboZySW8YA=; b=Km7Run6+8xtAWWr5O0NgcK8MAGH+Dii6WpzxgojqcpYpQ5mCFD1YNlyRIMHKy7trbj /u0u6/0CPosL/RzhDH5phIMIHHWB9T4gvtR4U5ZYDxAIsbOajUGmMbpz/SJR3728XtnI dGgqHA4BkJcDdmb7SLzGVqrCq+zAP7Pe+oLU/l1NzhYzgvkr7WXf42AvF/Y+NHv1Qbrr XQUtInWAjoejKokstWLrEY9TajC9jhQRk18wtyeu2Cmz9t5NsIYxWGzz4P8JLJDc7KTy skyraLeQLjxaGVMyW41onkRwd6i2v/PJNBi3r2BNdXanBiV5zmNUYCk+Hm1nrPFI3U0y upCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=jWAF4kTu; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YdYHB386; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si3925546edx.95.2021.03.19.05.50.51; Fri, 19 Mar 2021 05:51:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=jWAF4kTu; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YdYHB386; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbhCSMtq (ORCPT + 99 others); Fri, 19 Mar 2021 08:49:46 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:60201 "EHLO new1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbhCSMta (ORCPT ); Fri, 19 Mar 2021 08:49:30 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id A55F8580984; Fri, 19 Mar 2021 08:49:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 19 Mar 2021 08:49:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=c847Pq0vLWucL jucHu8bhUQZoFlP9PYipIboZySW8YA=; b=jWAF4kTuTgo9rWxNz0xBUXd9WaFz8 US6xn4N+2+CsTPCV9x69muVZFfTcq7aRNhmLRqnNraSvUqpZ0WM5mdYD10qEnuHw 2OAspz2/UqTroCCOOft0vzbdnnfs0zcEEEaYijueqwPT+7NQs+qFc1ukpBRkllFT /z1G7bqPz6rM16oZjXkc7tJRSASN0n2VmOrPpwkVT81xdfqWJwkx6x04lVKIEf/R r4T+wCwounq77YYrqLuKi4w1DQbcHW6qqpBWJQPl2AG8b87q5D5JxsAUH4n7w7a/ AmWAQcHDjoCjlnJp55fKi/TgiUPkNJoisIxrzsAtzFYW2OOjx5cwqF70A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=c847Pq0vLWucLjucHu8bhUQZoFlP9PYipIboZySW8YA=; b=YdYHB386 HJVB70an0FuXVvwJZtdvCaNCdSzf+74bTxqXKdE1fNrIzJkvZWiu2yZrkm6YO3rF RIbt/9mfDjxv4DZ/s7cJvKlauCC8el2baAcXH2ErU8CG+HzVJc+GqtkPio8kh6QQ 3GMeMgZIb6M3YI7Qr9x9KQOropYoKzF3dNzsYFq2rBma13r3N7vlJ8udN24xafse WVObDt9pcVjhDtblZkNorI5JRIcH8SJpA5cQutFwOHjIjLHc3R3BuBFosMseO1mq dXoW6CUmnwwJT0Z3P+utCyYVmtHP5O+HlVlIRCVN/EVBNPPhI4kGvWz96/Z1i/WJ 47PP7QJSu7I7Rw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefkedggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA id 244761080054; Fri, 19 Mar 2021 08:49:28 -0400 (EDT) From: Maxime Ripard To: dri-devel@lists.freedesktop.org, Daniel Vetter , David Airlie , Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard Cc: Jernej Skrabec , Joonas Lahtinen , Dave Stevenson , Phil Elwell , Tim Gover , Dom Cobley , =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter , amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Jonas Karlman , linux-kernel@vger.kernel.org, Harry Wentland , Maxime Ripard , Jani Nikula , Alex Deucher , Neil Armstrong , Eric Anholt , Rodrigo Vivi , Andrzej Hajda , Leo Li , Laurent Pinchart Subject: [PATCH 2/3] drm/connector: Add helper to compare HDR metadata Date: Fri, 19 Mar 2021 13:49:21 +0100 Message-Id: <20210319124922.144726-2-maxime@cerno.tech> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210319124922.144726-1-maxime@cerno.tech> References: <20210319124922.144726-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All the drivers that support the HDR metadata property have a similar function to compare the metadata from one connector state to the next, and force a mode change if they differ. All these functions run pretty much the same code, so let's turn it into an helper that can be shared across those drivers. Signed-off-by: Maxime Ripard --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 21 +------------- drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 17 +---------- drivers/gpu/drm/drm_connector.c | 28 +++++++++++++++++++ drivers/gpu/drm/i915/display/intel_atomic.c | 13 +-------- include/drm/drm_connector.h | 2 ++ 5 files changed, 33 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 06908a3cee0f..4eb5201e566a 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -5924,25 +5924,6 @@ static int fill_hdr_info_packet(const struct drm_connector_state *state, return 0; } -static bool -is_hdr_metadata_different(const struct drm_connector_state *old_state, - const struct drm_connector_state *new_state) -{ - struct drm_property_blob *old_blob = old_state->hdr_output_metadata; - struct drm_property_blob *new_blob = new_state->hdr_output_metadata; - - if (old_blob != new_blob) { - if (old_blob && new_blob && - old_blob->length == new_blob->length) - return memcmp(old_blob->data, new_blob->data, - old_blob->length); - - return true; - } - - return false; -} - static int amdgpu_dm_connector_atomic_check(struct drm_connector *conn, struct drm_atomic_state *state) @@ -5960,7 +5941,7 @@ amdgpu_dm_connector_atomic_check(struct drm_connector *conn, if (!crtc) return 0; - if (is_hdr_metadata_different(old_con_state, new_con_state)) { + if (!drm_connector_atomic_hdr_metadata_equal(old_con_state, new_con_state)) { struct dc_info_packet hdr_infopacket; ret = fill_hdr_info_packet(new_con_state, &hdr_infopacket); diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c index f24bbb840dbf..f871e33c2fc9 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -2395,21 +2395,6 @@ static int dw_hdmi_connector_get_modes(struct drm_connector *connector) return ret; } -static bool hdr_metadata_equal(const struct drm_connector_state *old_state, - const struct drm_connector_state *new_state) -{ - struct drm_property_blob *old_blob = old_state->hdr_output_metadata; - struct drm_property_blob *new_blob = new_state->hdr_output_metadata; - - if (!old_blob || !new_blob) - return old_blob == new_blob; - - if (old_blob->length != new_blob->length) - return false; - - return !memcmp(old_blob->data, new_blob->data, old_blob->length); -} - static int dw_hdmi_connector_atomic_check(struct drm_connector *connector, struct drm_atomic_state *state) { @@ -2423,7 +2408,7 @@ static int dw_hdmi_connector_atomic_check(struct drm_connector *connector, if (!crtc) return 0; - if (!hdr_metadata_equal(old_state, new_state)) { + if (!drm_connector_atomic_hdr_metadata_equal(old_state, new_state)) { crtc_state = drm_atomic_get_crtc_state(state, crtc); if (IS_ERR(crtc_state)) return PTR_ERR(crtc_state); diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index e25248e23e18..d781a3a1e9bf 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -2170,6 +2170,34 @@ int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *conn } EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property); +/** + * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed + * @old_state: old connector state to compare + * @new_state: new connector state to compare + * + * This is used by HDR-enabled drivers to test whether the HDR metadata + * have changed between two different connector state (and thus probably + * requires a full blown mode change). + * + * Returns: + * True if the metadata are equal, False otherwise + */ +bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state, + struct drm_connector_state *new_state) +{ + struct drm_property_blob *old_blob = old_state->hdr_output_metadata; + struct drm_property_blob *new_blob = new_state->hdr_output_metadata; + + if (!old_blob || !new_blob) + return old_blob == new_blob; + + if (old_blob->length != new_blob->length) + return false; + + return !memcmp(old_blob->data, new_blob->data, old_blob->length); +} +EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal); + /** * drm_connector_set_vrr_capable_property - sets the variable refresh rate * capable property for a connector diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c index e00fdc47c0eb..efec9454af5a 100644 --- a/drivers/gpu/drm/i915/display/intel_atomic.c +++ b/drivers/gpu/drm/i915/display/intel_atomic.c @@ -109,16 +109,6 @@ int intel_digital_connector_atomic_set_property(struct drm_connector *connector, return -EINVAL; } -static bool blob_equal(const struct drm_property_blob *a, - const struct drm_property_blob *b) -{ - if (a && b) - return a->length == b->length && - !memcmp(a->data, b->data, a->length); - - return !a == !b; -} - int intel_digital_connector_atomic_check(struct drm_connector *conn, struct drm_atomic_state *state) { @@ -149,8 +139,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn, new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio || new_conn_state->base.content_type != old_conn_state->base.content_type || new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode || - !blob_equal(new_conn_state->base.hdr_output_metadata, - old_conn_state->base.hdr_output_metadata)) + !drm_connector_atomic_hdr_metadata_equal(old_state, new_state)) crtc_state->mode_changed = true; return 0; diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 32172dab8427..1f51d73ca715 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1672,6 +1672,8 @@ int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, int drm_connector_attach_vrr_capable_property( struct drm_connector *connector); int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector); +bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state, + struct drm_connector_state *new_state); int drm_mode_create_aspect_ratio_property(struct drm_device *dev); int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector); int drm_mode_create_dp_colorspace_property(struct drm_connector *connector); -- 2.30.2