Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp406095pxv; Wed, 30 Jun 2021 08:14:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaid4Qozdz97RIqmO1s64Nb6pc2703UgVBDc7lZaKGQMlf26dnvTK5n7bfGgDdjabTcFM5 X-Received: by 2002:a5d:6502:: with SMTP id x2mr39162788wru.327.1625066045459; Wed, 30 Jun 2021 08:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625066045; cv=none; d=google.com; s=arc-20160816; b=G0P7xasSm17d9mTgGBuGawbeQkqU6hikrZ+N7ttBRHm2gAb5kBOTE3hhfGsT6zpFRO xfHCpF93PLVZSCTft9CyCmTSTDK7jgERk+puKiT7WIuMKRH05b7UpgyMRpYQ4+EVX0Pj SkDwFk+6NYH59bB0iwqSDcr5POfeQRMK7/bpWNH3QBwk+62VzcVl6s7DHY0CsBhrELFo a18XSPmBZflmuP96rzNjSlVYYAuDl1evYyRDunbAwBykLqbRCiu4FnvYxb9oPNvCKALl ceLsBeYNMX+gVF09LZYwUPDFOwATppdeqm7+wA+wX/vA3XaLmf+9I+PNwSFkpkwPIgEp dGTA== 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; bh=z0d3xYPo/ML6185Rda+AlM+cyJFjp72VQ6tY9ze+800=; b=jsesNuXoBCwegYpc2RkfcLBP3nYmoYLma6I4RBXmdX1j4dK0zzZO5C20UlTpVI0im5 ZY3X//2dlt2ZbCEiFj44BOUDuaU5b0x+cG8M3ocPJ2DlI0oRY1MbXNuImstV29tblF99 n5fCRj4mduXGECTPmIpus9S0YsCzfOL4JdgwMkGJ0WfH8wk8BvAOBD8S9GItpCfis8OG onRBx0qBHMs1FjmGQzSPCIZOmeFRXX7y45Z0xdUMEOZGz1995YZ6aJoUtOBbiTrvCVgT VbqF3nS3ngjWWHy3Bt6SfUNP3/xUs2JnYA0Ihz5D9/GIt/LdtGfUu8paFkI21RdqoATh yXzA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v24si19142538ejv.518.2021.06.30.08.13.42; Wed, 30 Jun 2021 08:14:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235893AbhF3PNa (ORCPT + 99 others); Wed, 30 Jun 2021 11:13:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235885AbhF3PNG (ORCPT ); Wed, 30 Jun 2021 11:13:06 -0400 Received: from srv6.fidu.org (srv6.fidu.org [IPv6:2a01:4f8:231:de0::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D85C4C0613A2 for ; Wed, 30 Jun 2021 08:10:30 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by srv6.fidu.org (Postfix) with ESMTP id 7EC73C80095; Wed, 30 Jun 2021 17:10:28 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at srv6.fidu.org Received: from srv6.fidu.org ([127.0.0.1]) by localhost (srv6.fidu.org [127.0.0.1]) (amavisd-new, port 10026) with LMTP id ghyRY5GYPOhw; Wed, 30 Jun 2021 17:10:28 +0200 (CEST) Received: from wsembach-tuxedo.fritz.box (p200300e37F394900095779a208783f8e.dip0.t-ipconnect.de [IPv6:2003:e3:7f39:4900:957:79a2:878:3f8e]) (Authenticated sender: wse@tuxedocomputers.com) by srv6.fidu.org (Postfix) with ESMTPA id 7A6CCC80097; Wed, 30 Jun 2021 17:10:26 +0200 (CEST) From: Werner Sembach To: harry.wentland@amd.com, sunpeng.li@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, airlied@linux.ie, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, emil.l.velikov@gmail.com Cc: Werner Sembach Subject: [PATCH v5 12/17] drm/uAPI: Add "preferred color format" drm property as setting for userspace Date: Wed, 30 Jun 2021 17:10:13 +0200 Message-Id: <20210630151018.330354-13-wse@tuxedocomputers.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210630151018.330354-1-wse@tuxedocomputers.com> References: <20210630151018.330354-1-wse@tuxedocomputers.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new general drm property "preferred color format" which can be used by userspace to tell the graphic drivers to which color format to use. Possible options are: - auto (default/current behaviour) - rgb - ycbcr444 - ycbcr422 (not supported by both amdgpu and i915) - ycbcr420 In theory the auto option should choose the best available option for the current setup, but because of bad internal conversion some monitors look better with rgb and some with ycbcr444. Also, because of bad shielded connectors and/or cables, it might be preferable to use the less bandwidth heavy ycbcr422 and ycbcr420 formats for a signal that is less deceptible to interference. In the future, automatic color calibration for screens might also depend on this option being available. Signed-off-by: Werner Sembach --- drivers/gpu/drm/drm_atomic_helper.c | 4 +++ drivers/gpu/drm/drm_atomic_uapi.c | 4 +++ drivers/gpu/drm/drm_connector.c | 50 ++++++++++++++++++++++++++++- include/drm/drm_connector.h | 17 ++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index bc3487964fb5..90d62f305257 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -687,6 +687,10 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, if (old_connector_state->max_requested_bpc != new_connector_state->max_requested_bpc) new_crtc_state->connectors_changed = true; + + if (old_connector_state->preferred_color_format != + new_connector_state->preferred_color_format) + new_crtc_state->connectors_changed = true; } if (funcs->atomic_check) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 438e9585b225..c536f5e22016 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -796,6 +796,8 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector, fence_ptr); } else if (property == connector->max_bpc_property) { state->max_requested_bpc = val; + } else if (property == connector->preferred_color_format_property) { + state->preferred_color_format = val; } else if (connector->funcs->atomic_set_property) { return connector->funcs->atomic_set_property(connector, state, property, val); @@ -873,6 +875,8 @@ drm_atomic_connector_get_property(struct drm_connector *connector, *val = 0; } else if (property == connector->max_bpc_property) { *val = state->max_requested_bpc; + } else if (property == connector->preferred_color_format_property) { + *val = state->preferred_color_format; } else if (connector->funcs->atomic_get_property) { return connector->funcs->atomic_get_property(connector, state, property, val); diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index ebfdd17a7f59..67dd59b12258 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -889,6 +889,14 @@ static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = { { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */ }; +static const struct drm_prop_enum_list drm_preferred_color_format_enum_list[] = { + { 0, "auto" }, + { DRM_COLOR_FORMAT_RGB444, "rgb" }, + { DRM_COLOR_FORMAT_YCRCB444, "ycbcr444" }, + { DRM_COLOR_FORMAT_YCRCB422, "ycbcr422" }, + { DRM_COLOR_FORMAT_YCRCB420, "ycbcr420" }, +}; + static const struct drm_prop_enum_list drm_active_color_format_enum_list[] = { { 0, "not applicable" }, { DRM_COLOR_FORMAT_RGB444, "rgb" }, @@ -1220,11 +1228,20 @@ static const struct drm_prop_enum_list dp_colorspaces[] = { * Drivers shall use drm_connector_attach_active_bpc_property() to install * this property. A value of 0 means "not applicable". * + * preferred color format: + * This property is used by userspace to change the used color format. When + * used the driver will use the selected format if valid for the hardware, + * sink, and current resolution and refresh rate combination. Drivers to + * use the function drm_connector_attach_preferred_color_format_property() + * to create and attach the property to the connector during + * initialization. Possible values are "auto", "rgb", "ycbcr444", + * "ycbcr422", and "ycbcr420". + * * active color format: * This read-only property tells userspace the color format actually used * by the hardware display engine "on the cable" on a connector. The chosen * value depends on hardware capabilities, both display engine and - * connected monitor. Drivers shall use + * connected monitor, and the "preferred color format". Drivers shall use * drm_connector_attach_active_color_format_property() to install this * property. Possible values are "not applicable", "rgb", "ycbcr444", * "ycbcr422", and "ycbcr420". @@ -2237,6 +2254,37 @@ void drm_connector_set_active_bpc_property(struct drm_connector *connector, int } EXPORT_SYMBOL(drm_connector_set_active_bpc_property); +/** + * drm_connector_attach_preferred_color_format_property - attach "preferred color format" property + * @connector: connector to attach preferred color format property on. + * + * This is used to add support for selecting a color format on a connector. + * + * Returns: + * Zero on success, negative errno on failure. + */ +int drm_connector_attach_preferred_color_format_property(struct drm_connector *connector) +{ + struct drm_device *dev = connector->dev; + struct drm_property *prop; + + if (!connector->preferred_color_format_property) { + prop = drm_property_create_enum(dev, 0, "preferred color format", + drm_preferred_color_format_enum_list, + ARRAY_SIZE(drm_preferred_color_format_enum_list)); + if (!prop) + return -ENOMEM; + + connector->preferred_color_format_property = prop; + } + + drm_object_attach_property(&connector->base, prop, 0); + connector->state->preferred_color_format = 0; + + return 0; +} +EXPORT_SYMBOL(drm_connector_attach_preferred_color_format_property); + /** * drm_connector_attach_active_color_format_property - attach "active color format" property * @connector: connector to attach active color format property on. diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 5ef4bb270f71..0dd7ece375c5 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -799,6 +799,16 @@ struct drm_connector_state { */ u8 max_bpc; + /** + * preferred_color_format: Property set by userspace to tell the GPU + * driver which color format to use. It only gets applied if hardware, + * meaning both the computer and the monitor, and the driver support the + * given format at the current resolution and refresh rate. Userspace + * can check for (un-)successful application via the "active color + * format" property. + */ + u32 preferred_color_format; + /** * @hdr_output_metadata: * DRM blob property for HDR output metadata @@ -1404,6 +1414,12 @@ struct drm_connector { */ struct drm_property *active_bpc_property; + /** + * @preferred_color_format_property: Default connector property for the + * preferred color format to be driven out of the connector. + */ + struct drm_property *preferred_color_format_property; + /** * @active_color_format_property: Default connector property for the * active color format to be driven out of the connector. @@ -1740,6 +1756,7 @@ int drm_connector_attach_max_bpc_property(struct drm_connector *connector, int min, int max); int drm_connector_attach_active_bpc_property(struct drm_connector *connector, int min, int max); void drm_connector_set_active_bpc_property(struct drm_connector *connector, int active_bpc); +int drm_connector_attach_preferred_color_format_property(struct drm_connector *connector); int drm_connector_attach_active_color_format_property(struct drm_connector *connector); void drm_connector_set_active_color_format_property(struct drm_connector *connector, u32 active_color_format); -- 2.25.1