From nobody Sat Feb 7 05:01:57 2026 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 C69FF3A0E9A for ; Wed, 4 Feb 2026 20:10:36 +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=1770235837; cv=none; b=eB9St+BHnjy9QtToEu6QkhMmU+U3i6RhyHK6qLyUnT6IfnazwOWm+LBIk+EwE3P/44Ufzg3sxQYA7FN9km0RxmPRSnObgrL+ZqfPQ7jaP1t6HihkYsElJpCZIJgzzqVxTbAE7P8ctv3rE0NLJvY5XDcmGHRir3kPWGm5g3VFEs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770235837; c=relaxed/simple; bh=xeVIe8cmrntR0enuK392UB2SXROYBNmtYamPiBlWwyw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DnXqk0zuj9IDrSAtdqxfdNjC9FtieQd4VrNmm+31osO/Cjz3rH9ntTFcPgqzx2c0VSpfT6f5OOwhw58jghtMm8mjqbjifTY78gdqaXECSt73ps+n7t1aVKReebzFFr29k8rtB8+A8HPthdS9AwKUOV3V+qz21LGCIFOryr7zwDE= 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=IR2U3YZ9; 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="IR2U3YZ9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1770235360; bh=xeVIe8cmrntR0enuK392UB2SXROYBNmtYamPiBlWwyw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IR2U3YZ9XeUWH2ccVQaIHAil82kaplR8ZdUbQIp3gsKJHSJoihkRV+aBQphygD6r9 RXvrVP5R3+d0ayg2mWnrgtooW8OyAR9CZmoL+0HqtQU6IzdXEN8wyL1t4PWQj845JZ KZo4Fkt/3/hgWDf7cNxfu7hKwd29jCQumr4zSwA3tkMeZca8g764if0L3OJ1l3zGZM YAGx9C4L9DNZzqr5HJVRPopap5Ri/AbuMGqTnLenH53fnpVTsrsyYfv69gi/g+Mwo4 tgXOD/7jUzy35naUJAlOtTo9ysqbB3VTX7QlAYl94kNL/DZtzYf9hxX1K9tjP6dsdl SULP+VjTxB2Fg== Received: from localhost (unknown [82.79.138.145]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id CB79A17E13D3; Wed, 4 Feb 2026 21:02:40 +0100 (CET) From: Cristian Ciocaltea Date: Wed, 04 Feb 2026 22:02:28 +0200 Subject: [PATCH v7 1/4] uapi: Provide DIV_ROUND_CLOSEST() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-rk3588-bgcolor-v7-1-78d1d01c5ca1@collabora.com> References: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> In-Reply-To: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Louis Chauvet , Haneen Mohammed , Melissa Wen , Jani Nikula , Andy Shevchenko Cc: Robert Mader , kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= , Diederik de Haas , AngeloGioacchino Del Regno X-Mailer: b4 0.14.3 Currently DIV_ROUND_CLOSEST() is only available for the kernel via include/linux/math.h. Expose it to userland as well by adding __KERNEL_DIV_ROUND_CLOSEST() as a common definition in uapi. Additionally, ensure it allows building ISO C applications by switching from the 'typeof' GNU extension to the ISO-friendly __typeof__. Reviewed-by: N=C3=ADcolas F. R. A. Prado Tested-by: Diederik de Haas Acked-by: Andy Shevchenko Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Cristian Ciocaltea --- include/linux/math.h | 18 +----------------- include/uapi/linux/const.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/linux/math.h b/include/linux/math.h index 6dc1d1d32fbc..1e8fb3efbc8c 100644 --- a/include/linux/math.h +++ b/include/linux/math.h @@ -89,23 +89,7 @@ } \ ) =20 -/* - * Divide positive or negative dividend by positive or negative divisor - * and round to closest integer. Result is undefined for negative - * divisors if the dividend variable type is unsigned and for negative - * dividends if the divisor variable type is unsigned. - */ -#define DIV_ROUND_CLOSEST(x, divisor)( \ -{ \ - typeof(x) __x =3D x; \ - typeof(divisor) __d =3D divisor; \ - (((typeof(x))-1) > 0 || \ - ((typeof(divisor))-1) > 0 || \ - (((__x) > 0) =3D=3D ((__d) > 0))) ? \ - (((__x) + ((__d) / 2)) / (__d)) : \ - (((__x) - ((__d) / 2)) / (__d)); \ -} \ -) +#define DIV_ROUND_CLOSEST __KERNEL_DIV_ROUND_CLOSEST /* * Same as above but for u64 dividends. divisor must be a 32-bit * number. diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h index b8f629ef135f..565f309b9df8 100644 --- a/include/uapi/linux/const.h +++ b/include/uapi/linux/const.h @@ -50,4 +50,22 @@ =20 #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) =20 +/* + * Divide positive or negative dividend by positive or negative divisor + * and round to closest integer. Result is undefined for negative + * divisors if the dividend variable type is unsigned and for negative + * dividends if the divisor variable type is unsigned. + */ +#define __KERNEL_DIV_ROUND_CLOSEST(x, divisor) \ +({ \ + __typeof__(x) __x =3D x; \ + __typeof__(divisor) __d =3D divisor; \ + \ + (((__typeof__(x))-1) > 0 || \ + ((__typeof__(divisor))-1) > 0 || \ + (((__x) > 0) =3D=3D ((__d) > 0))) ? \ + (((__x) + ((__d) / 2)) / (__d)) : \ + (((__x) - ((__d) / 2)) / (__d)); \ +}) + #endif /* _UAPI_LINUX_CONST_H */ --=20 2.52.0 From nobody Sat Feb 7 05:01:57 2026 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 C698132860C for ; Wed, 4 Feb 2026 20:10:36 +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=1770235837; cv=none; b=kwl80pPx8DSTbh24M5bpz3kyOrUKgsNxOCQFa3K7VLr6FDWgEe+3JgdyOkTYOjmAoxP/w+ummXA5D0L/6fegvyvPjmljp8Dq9PlIYeeXoo+cq03F1Gmx18JGpU8ztveHSLVf6R8KsUoET8F2Xm8FRL/U9dzL1BHvjk04KPtCKdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770235837; c=relaxed/simple; bh=Al+IbduDoznaQ+DuAWwkIEZt/3e0W4FxunJtTBZquXU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bGtAl5nFgvtr2u+gLJp0P3/VGguLiVF7vSAaz3C5bu6D8G5PKF0uEdlyVVqF28azjx3f681nVtzWzmm5fMvUJelhMjkag52IM8JQgzEmdpa3CEEb+lQDjlVS38lypazl5hlhv2I8WAshJMolLEGlj2EHeiZNj6/VEadjuB8vZa0= 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=gY16mB7M; 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="gY16mB7M" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1770235361; bh=Al+IbduDoznaQ+DuAWwkIEZt/3e0W4FxunJtTBZquXU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gY16mB7MuwmuJhss3aDdRiWjtlrDMo4wBSn5gF9FKMLBRnLdiHMk4YWz3+MLzoqai ctRH2UfBk9DaTBojyFC87h5I543qhK4gHp6AxoianIVtCtQ5emlIb3u9LgJFZbObNz mWasX3MNEq5+whAH8WfhOrmDkbycqh9fTiGwYO3y7gBw93dHJmGuTaEXv6xg4m3beX J4hC8Af61GUt+PqAfiXF0LM7NbzfdsRalHF64KxBoi00seqDVbcd6CtWJitP/Om3rQ rMDpmAsvBL9DsNbBTUyUXY764mIlP+h2LrAv8j+wzR4imYgKY7l4wnu8O3WZM/zFO9 J9Re07YbBwKaw== Received: from localhost (unknown [82.79.138.145]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id 9DD3317E150C; Wed, 4 Feb 2026 21:02:41 +0100 (CET) From: Cristian Ciocaltea Date: Wed, 04 Feb 2026 22:02:29 +0200 Subject: [PATCH v7 2/4] drm: Add CRTC background color property Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-rk3588-bgcolor-v7-2-78d1d01c5ca1@collabora.com> References: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> In-Reply-To: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Louis Chauvet , Haneen Mohammed , Melissa Wen , Jani Nikula , Andy Shevchenko Cc: Robert Mader , kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, Matt Roper , =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= , Diederik de Haas X-Mailer: b4 0.14.3 Some display controllers can be hardware programmed to show non-black colors for pixels that are either not covered by any plane or are exposed through transparent regions of higher planes. This feature can help reduce memory bandwidth usage, e.g. in compositors managing a UI with a solid background color while using smaller planes to render the remaining content. To support this capability, introduce the BACKGROUND_COLOR standard DRM mode property, which can be attached to a CRTC through the drm_crtc_attach_background_color_property() helper function. Additionally, define a 64-bit ARGB format value to be built with the help of a couple of dedicated DRM_ARGB64_PREP*() helpers. Individual color components can be extracted with desired precision using the corresponding DRM_ARGB64_GET*() macros. Co-developed-by: Matt Roper Signed-off-by: Matt Roper Reviewed-by: N=C3=ADcolas F. R. A. Prado Tested-by: Diederik de Haas Signed-off-by: Cristian Ciocaltea --- drivers/gpu/drm/drm_atomic.c | 1 + drivers/gpu/drm/drm_atomic_state_helper.c | 1 + drivers/gpu/drm/drm_atomic_uapi.c | 4 ++ drivers/gpu/drm/drm_blend.c | 39 +++++++++++++-- drivers/gpu/drm/drm_mode_config.c | 6 +++ include/drm/drm_blend.h | 4 +- include/drm/drm_crtc.h | 12 +++++ include/drm/drm_mode_config.h | 5 ++ include/uapi/drm/drm_mode.h | 80 +++++++++++++++++++++++++++= ++++ 9 files changed, 147 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 52738b80ddbe..c489c7c26396 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -476,6 +476,7 @@ static void drm_atomic_crtc_print_state(struct drm_prin= ter *p, drm_printf(p, "\tconnector_mask=3D%x\n", state->connector_mask); drm_printf(p, "\tencoder_mask=3D%x\n", state->encoder_mask); drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode)); + drm_printf(p, "\tbackground_color=3D%llx\n", state->background_color); =20 if (crtc->funcs->atomic_print_state) crtc->funcs->atomic_print_state(p, state); diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/dr= m_atomic_state_helper.c index cee6d8fc44ad..57668f1c9460 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -75,6 +75,7 @@ __drm_atomic_helper_crtc_state_reset(struct drm_crtc_stat= e *crtc_state, struct drm_crtc *crtc) { crtc_state->crtc =3D crtc; + crtc_state->background_color =3D DRM_ARGB64_PREP(0xffff, 0, 0, 0); } EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset); =20 diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic= _uapi.c index dc013a22bf26..20f59a9a7ebc 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -454,6 +454,8 @@ static int drm_atomic_crtc_set_property(struct drm_crtc= *crtc, &replaced); state->color_mgmt_changed |=3D replaced; return ret; + } else if (property =3D=3D config->background_color_property) { + state->background_color =3D val; } else if (property =3D=3D config->prop_out_fence_ptr) { s32 __user *fence_ptr =3D u64_to_user_ptr(val); =20 @@ -501,6 +503,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, *val =3D (state->ctm) ? state->ctm->base.id : 0; else if (property =3D=3D config->gamma_lut_property) *val =3D (state->gamma_lut) ? state->gamma_lut->base.id : 0; + else if (property =3D=3D config->background_color_property) + *val =3D state->background_color; else if (property =3D=3D config->prop_out_fence_ptr) *val =3D 0; else if (property =3D=3D crtc->scaling_filter_property) diff --git a/drivers/gpu/drm/drm_blend.c b/drivers/gpu/drm/drm_blend.c index 6852d73c931c..f249af2a11af 100644 --- a/drivers/gpu/drm/drm_blend.c +++ b/drivers/gpu/drm/drm_blend.c @@ -191,10 +191,6 @@ * plane does not expose the "alpha" property, then this is * assumed to be 1.0 * - * Note that all the property extensions described here apply either to the - * plane or the CRTC (e.g. for the background color, which currently is not - * exposed and assumed to be black). - * * SCALING_FILTER: * Indicates scaling filter to be used for plane scaler * @@ -207,6 +203,25 @@ * * Drivers can set up this property for a plane by calling * drm_plane_create_scaling_filter_property + * + * The property extensions described above all apply to the plane. Drivers + * may also expose the following crtc property extension: + * + * BACKGROUND_COLOR: + * Background color is set up with drm_crtc_attach_background_color_proper= ty(), + * and expects a 64-bit ARGB value following DRM_FORMAT_ARGB16161616, as + * generated by the DRM_ARGB64_PREP*() helpers. It controls the color of a + * full-screen layer that exists below all planes. This color will be used + * for pixels not covered by any plane and may also be blended with plane + * contents as allowed by a plane's alpha values. + * The background color defaults to black, and is assumed to be black for + * drivers that do not expose this property. Although background color + * isn't a plane, it is assumed that the color provided here undergoes the + * CRTC degamma/CSC/gamma transformations applied after the planes blendin= g. + * Note that the color value includes an alpha channel, hence non-opaque + * background color values are allowed, but since physically transparent + * monitors do not (yet) exists, the final alpha value may not reach the + * video sink or it may simply ignore it. */ =20 /** @@ -621,3 +636,19 @@ int drm_plane_create_blend_mode_property(struct drm_pl= ane *plane, return 0; } EXPORT_SYMBOL(drm_plane_create_blend_mode_property); + +/** + * drm_crtc_attach_background_color_property - attach background color pro= perty + * @crtc: drm crtc + * + * Attaches the background color property to @crtc. The property defaults= to + * solid black and will accept 64-bit ARGB values in the format generated = by + * DRM_ARGB64_PREP*() helpers. + */ +void drm_crtc_attach_background_color_property(struct drm_crtc *crtc) +{ + drm_object_attach_property(&crtc->base, + crtc->dev->mode_config.background_color_property, + DRM_ARGB64_PREP(0xffff, 0, 0, 0)); +} +EXPORT_SYMBOL(drm_crtc_attach_background_color_property); diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_c= onfig.c index d12db9b0bab8..dba7aa871246 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -380,6 +380,12 @@ static int drm_mode_create_standard_properties(struct = drm_device *dev) return -ENOMEM; dev->mode_config.gamma_lut_size_property =3D prop; =20 + prop =3D drm_property_create_range(dev, 0, + "BACKGROUND_COLOR", 0, U64_MAX); + if (!prop) + return -ENOMEM; + dev->mode_config.background_color_property =3D prop; + prop =3D drm_property_create(dev, DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB, "IN_FORMATS", 0); diff --git a/include/drm/drm_blend.h b/include/drm/drm_blend.h index 88bdfec3bd88..c7e888767c81 100644 --- a/include/drm/drm_blend.h +++ b/include/drm/drm_blend.h @@ -31,8 +31,9 @@ #define DRM_MODE_BLEND_COVERAGE 1 #define DRM_MODE_BLEND_PIXEL_NONE 2 =20 -struct drm_device; struct drm_atomic_state; +struct drm_crtc; +struct drm_device; struct drm_plane; =20 static inline bool drm_rotation_90_or_270(unsigned int rotation) @@ -58,4 +59,5 @@ int drm_atomic_normalize_zpos(struct drm_device *dev, struct drm_atomic_state *state); int drm_plane_create_blend_mode_property(struct drm_plane *plane, unsigned int supported_modes); +void drm_crtc_attach_background_color_property(struct drm_crtc *crtc); #endif diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 66278ffeebd6..312fc1e745d2 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -274,6 +274,18 @@ struct drm_crtc_state { */ struct drm_property_blob *gamma_lut; =20 + /** + * @background_color: + * + * RGB value representing the CRTC's background color. The background + * color (aka "canvas color") of a CRTC is the color that will be used + * for pixels not covered by a plane, or covered by transparent pixels + * of a plane. The value here should be built using DRM_ARGB64_PREP*() + * helpers, while the individual color components can be extracted with + * desired precision via the DRM_ARGB64_GET*() macros. + */ + u64 background_color; + /** * @target_vblank: * diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index 5e1dd0cfccde..687c0ee163d2 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -836,6 +836,11 @@ struct drm_mode_config { * gamma LUT as supported by the driver (read-only). */ struct drm_property *gamma_lut_size_property; + /** + * @background_color_property: Optional CRTC property to set the + * background color. + */ + struct drm_property *background_color_property; =20 /** * @suggested_x_property: Optional connector property with a hint for diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index 3693d82b5279..a4bdc4bd11bc 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -27,6 +27,9 @@ #ifndef _DRM_MODE_H #define _DRM_MODE_H =20 +#include +#include + #include "drm.h" =20 #if defined(__cplusplus) @@ -1549,6 +1552,83 @@ struct drm_mode_closefb { __u32 pad; }; =20 +/* + * Put 16-bit ARGB values into a standard 64-bit representation that can be + * used for ioctl parameters, inter-driver communication, etc. + * + * If the component values being provided contain less than 16 bits of + * precision, use a conversion ratio to get a better color approximation. + * The ratio is computed as (2^16 - 1) / (2^bpc - 1), where bpc and 16 are + * the input and output precision, respectively. + * Also note bpc must be greater than 0. + */ +#define __DRM_ARGB64_PREP(c, shift) \ + (((__u64)(c) & __GENMASK(15, 0)) << (shift)) + +#define __DRM_ARGB64_PREP_BPC(c, shift, bpc) \ +({ \ + __u16 mask =3D __GENMASK((bpc) - 1, 0); \ + __u16 conv =3D __KERNEL_DIV_ROUND_CLOSEST((mask & (c)) * \ + __GENMASK(15, 0), mask);\ + __DRM_ARGB64_PREP(conv, shift); \ +}) + +#define DRM_ARGB64_PREP(alpha, red, green, blue) \ +( \ + __DRM_ARGB64_PREP(alpha, 48) | \ + __DRM_ARGB64_PREP(red, 32) | \ + __DRM_ARGB64_PREP(green, 16) | \ + __DRM_ARGB64_PREP(blue, 0) \ +) + +#define DRM_ARGB64_PREP_BPC(alpha, red, green, blue, bpc) \ +({ \ + __typeof__(bpc) __bpc =3D bpc; \ + __DRM_ARGB64_PREP_BPC(alpha, 48, __bpc) | \ + __DRM_ARGB64_PREP_BPC(red, 32, __bpc) | \ + __DRM_ARGB64_PREP_BPC(green, 16, __bpc) | \ + __DRM_ARGB64_PREP_BPC(blue, 0, __bpc); \ +}) + +/* + * Extract the specified color component from a standard 64-bit ARGB value. + * + * If the requested precision is less than 16 bits, make use of a conversi= on + * ratio calculated as (2^bpc - 1) / (2^16 - 1), where bpc and 16 are the + * output and input precision, respectively. + * + * If speed is more important than accuracy, use DRM_ARGB64_GET*_BPCS() + * instead of DRM_ARGB64_GET*_BPC() in order to replace the expensive + * division with a simple bit right-shift operation. + */ +#define __DRM_ARGB64_GET(c, shift) \ + ((__u16)(((__u64)(c) >> (shift)) & __GENMASK(15, 0))) + +#define __DRM_ARGB64_GET_BPC(c, shift, bpc) \ +({ \ + __u16 comp =3D __DRM_ARGB64_GET(c, shift); \ + __KERNEL_DIV_ROUND_CLOSEST(comp * __GENMASK((bpc) - 1, 0), \ + __GENMASK(15, 0)); \ +}) + +#define __DRM_ARGB64_GET_BPCS(c, shift, bpc) \ + (__DRM_ARGB64_GET(c, shift) >> (16 - (bpc))) + +#define DRM_ARGB64_GETA(c) __DRM_ARGB64_GET(c, 48) +#define DRM_ARGB64_GETR(c) __DRM_ARGB64_GET(c, 32) +#define DRM_ARGB64_GETG(c) __DRM_ARGB64_GET(c, 16) +#define DRM_ARGB64_GETB(c) __DRM_ARGB64_GET(c, 0) + +#define DRM_ARGB64_GETA_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 48, bpc) +#define DRM_ARGB64_GETR_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 32, bpc) +#define DRM_ARGB64_GETG_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 16, bpc) +#define DRM_ARGB64_GETB_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 0, bpc) + +#define DRM_ARGB64_GETA_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 48, bpc) +#define DRM_ARGB64_GETR_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 32, bpc) +#define DRM_ARGB64_GETG_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 16, bpc) +#define DRM_ARGB64_GETB_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 0, bpc) + #if defined(__cplusplus) } #endif --=20 2.52.0 From nobody Sat Feb 7 05:01:57 2026 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 F119317DFE7 for ; Wed, 4 Feb 2026 20:15:36 +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=1770236137; cv=none; b=FNqQK5Z2xV7SGYmdHhii6O0ldwtLeCFMJnpcpsPSQv3k5ZLxpxgorihRwmN//hf5BiPg2jcv3Yvzbz33pEaLWDXw4U3iSclytWNqk3GFJn+JEqpV8mCX7eCws+V57KYJyMyYER10PR4yi2uT+5ie3NL2xSuKHFc759EdtGML848= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770236137; c=relaxed/simple; bh=/L0lTmhcZkxDMMrnCZSUmTG7CK9mTVDRkVjSQ2g9G1Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JTH5NrHdc1fBQFkUh/Yi0/akNBPWgezKXDJClivFh+Ww+vCzsI0ZnLsa9jQAvXxD5ePhuIKo3L0qcwJPgTJbaHpKaLdf+ZH1mDN3Bh9r8fFTzWY9iMnW3YgW3FyXMr8NG5oAcYey3FBXH/emmVx3WSkCruT4yMHS0XabAzUUMzk= 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=JtU1hes2; 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="JtU1hes2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1770235362; bh=/L0lTmhcZkxDMMrnCZSUmTG7CK9mTVDRkVjSQ2g9G1Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JtU1hes2FpXEaCG7KUee9M5k2UnwWvCa5oUd07aUPvZY8KvFsktKSzJt1Qvu4GodK Kpfac9bLI1UX3uzei4drWyl/c0v4pS6QebKkt6KPvSjpZciZ5TaaNjnZrUalXFQ3x4 0ab88dKIpwRON7cd8W7Y9l1vCEtJ6bJSbe5qKdwp2YrbxOAWreRVAyryW5AsO+Wrcm SY6v3Vp4n556jG3PvTW8gNDnE8lkTlQncAzul5J0H0qKDub+yzE3nhWVHph5JgK0ox qwqcmk7/iL1k8/0/2KUMPKhdju5cpDpoIOopG94yjvJ/Fm4Bgn+CIouzzctfFTJUyr C8vsFKcnQMTcQ== Received: from localhost (unknown [82.79.138.145]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id 69DD617E1582; Wed, 4 Feb 2026 21:02:42 +0100 (CET) From: Cristian Ciocaltea Date: Wed, 04 Feb 2026 22:02:30 +0200 Subject: [PATCH v7 3/4] drm/vkms: Support setting custom background color Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-rk3588-bgcolor-v7-3-78d1d01c5ca1@collabora.com> References: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> In-Reply-To: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Louis Chauvet , Haneen Mohammed , Melissa Wen , Jani Nikula , Andy Shevchenko Cc: Robert Mader , kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, =?utf-8?q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= , Diederik de Haas X-Mailer: b4 0.14.3 Make use of the BACKGROUND_COLOR CRTC property when filling the background during blending. It already defaults to solid black. Since the internal representation of the pixel color in VKMS relies on 16 bits of precision, use the newly introduced DRM_ARGB64_GET{R|G|B}() helpers to access the individual components of the background color property, which is compliant with DRM_FORMAT_ARGB16161616. It's worth noting the alpha component is ignored, hence non-opaque background colors are not supported. Reviewed-by: N=C3=ADcolas F. R. A. Prado Tested-by: Diederik de Haas Signed-off-by: Cristian Ciocaltea Reviewed-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_composer.c | 10 ++++++++-- drivers/gpu/drm/vkms/vkms_crtc.c | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vk= ms_composer.c index cd85de4ffd03..83d217085ad0 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -475,8 +475,14 @@ static void blend(struct vkms_writeback_job *wb, { struct vkms_plane_state **plane =3D crtc_state->active_planes; u32 n_active_planes =3D crtc_state->num_active_planes; - - const struct pixel_argb_u16 background_color =3D { .a =3D 0xffff }; + u64 bgcolor =3D crtc_state->base.background_color; + + const struct pixel_argb_u16 background_color =3D { + .a =3D 0xffff, + .r =3D DRM_ARGB64_GETR(bgcolor), + .g =3D DRM_ARGB64_GETG(bgcolor), + .b =3D DRM_ARGB64_GETB(bgcolor), + }; =20 int crtc_y_limit =3D crtc_state->base.mode.vdisplay; int crtc_x_limit =3D crtc_state->base.mode.hdisplay; diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_c= rtc.c index 9a7db1d51022..2514c367f710 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -4,6 +4,7 @@ =20 #include #include +#include #include #include #include @@ -228,6 +229,8 @@ struct vkms_output *vkms_crtc_init(struct drm_device *d= ev, struct drm_plane *pri =20 drm_crtc_enable_color_mgmt(crtc, 0, false, VKMS_LUT_SIZE); =20 + drm_crtc_attach_background_color_property(crtc); + spin_lock_init(&vkms_out->lock); spin_lock_init(&vkms_out->composer_lock); =20 --=20 2.52.0 From nobody Sat Feb 7 05:01:57 2026 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 C6A7F3A1E96 for ; Wed, 4 Feb 2026 20:10:36 +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=1770235837; cv=none; b=B3MNr/MkQDRThxbAeDlBmnPhOFAYUr04MkX5Ie9lK8ybwtu+fqO1OzueKpjwSLtZDFEmCkF6SGq/2+n1mhVKzZWB16NvuloWWytWI0yEcAduaxlAzHv0exf9r+PM9UaGKkQXKtvQf3ByjXtnaaTrJBJh5LmXepoc3nRSbJIF0p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770235837; c=relaxed/simple; bh=amFnri11i2h/V8EBwlIzxK8P0NaPKaUHqPlVcDaTJYc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O7EeTvA6Z6ePD/tw6aO0vkXmyU6N3EU8/iP1NlmRc80YY6iGCEPFel1lIdlvEbACWoHORoRp5N6VnXN5S3JFoBt+gMo1V42sDwW7szxWy2en4yqw7mCkSJ6xns0zF6awp0rz3OXyhZ1LnKh4a64HaRqsY2kFLDIpe0WosiUZR5E= 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=oc+R7ikQ; 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="oc+R7ikQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1770235363; bh=amFnri11i2h/V8EBwlIzxK8P0NaPKaUHqPlVcDaTJYc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oc+R7ikQR6NfwwpzhIqOw3389KhKicKGuDNPDXsxrvedHYWzWiQf6eppZv0tgM7Rj n3/uJNyOn9YQh670wasFQ9qu9mvfEqHkpFnylIZBG2CcznWc3mGkF5I+U2O2GZEmvY L/fyHzH9coTxeMKrNAE0t4c0yuL0aWyCZ8HeE2T2UPBCMlElJdY9yZUHsOm3ZBZEFM BB6gTVmAjTmNo1IZBwl5nQvCNxeLJO5/6Jz53WOa+u7ZmSFtAjT7kzsXaUyonCg1Ua jrGhW04yWjzs9+BrADBGtr3jSpY5u+CchSZbN9w5tFFAcfhPQ3laU/d/R7gHDryFCf 9hx29Arxn+IAQ== Received: from localhost (unknown [82.79.138.145]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id 364DC17E15F5; Wed, 4 Feb 2026 21:02:43 +0100 (CET) From: Cristian Ciocaltea Date: Wed, 04 Feb 2026 22:02:31 +0200 Subject: [PATCH v7 4/4] drm/rockchip: vop2: Support setting custom background color Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-rk3588-bgcolor-v7-4-78d1d01c5ca1@collabora.com> References: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> In-Reply-To: <20260204-rk3588-bgcolor-v7-0-78d1d01c5ca1@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Louis Chauvet , Haneen Mohammed , Melissa Wen , Jani Nikula , Andy Shevchenko Cc: Robert Mader , kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, Diederik de Haas X-Mailer: b4 0.14.3 The Rockchip VOP2 display controller allows configuring the background color of each video output port. Since a previous patch introduced the BACKGROUND_COLOR CRTC property, which defaults to solid black, make use of it when programming the hardware. Note the maximum precision allowed by the display controller is 10bpc, while the alpha component is not supported, hence ignored. Tested-by: Diederik de Haas Signed-off-by: Cristian Ciocaltea --- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 17 ++++++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index ec3b4fde10db..8f22e90a23dd 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -1552,6 +1552,7 @@ static void vop2_post_config(struct drm_crtc *crtc) struct vop2_video_port *vp =3D to_vop2_video_port(crtc); struct vop2 *vop2 =3D vp->vop2; struct drm_display_mode *mode =3D &crtc->state->adjusted_mode; + u64 bgcolor =3D crtc->state->background_color; u16 vtotal =3D mode->crtc_vtotal; u16 hdisplay =3D mode->crtc_hdisplay; u16 hact_st =3D mode->crtc_htotal - mode->crtc_hsync_start; @@ -1597,7 +1598,15 @@ static void vop2_post_config(struct drm_crtc *crtc) vop2_vp_write(vp, RK3568_VP_POST_DSP_VACT_INFO_F1, val); } =20 - vop2_vp_write(vp, RK3568_VP_DSP_BG, 0); + /* + * Background color is programmed with 10 bits of precision. + * Since performance is more important than accuracy here, + * make use of the DRM_ARGB64_GET*_BPCS() helpers. + */ + val =3D FIELD_PREP(RK3568_VP_DSP_BG__DSP_BG_RED, DRM_ARGB64_GETR_BPCS(bgc= olor, 10)); + FIELD_MODIFY(RK3568_VP_DSP_BG__DSP_BG_GREEN, &val, DRM_ARGB64_GETG_BPCS(b= gcolor, 10)); + FIELD_MODIFY(RK3568_VP_DSP_BG__DSP_BG_BLUE, &val, DRM_ARGB64_GETB_BPCS(bg= color, 10)); + vop2_vp_write(vp, RK3568_VP_DSP_BG, val); } =20 static int us_to_vertical_line(struct drm_display_mode *mode, int us) @@ -1983,6 +1992,10 @@ static int vop2_crtc_state_dump(struct drm_crtc *crt= c, struct seq_file *s) drm_get_bus_format_name(vcstate->bus_format)); seq_printf(s, "\toutput_mode[%x]", vcstate->output_mode); seq_printf(s, " color_space[%d]\n", vcstate->color_space); + seq_printf(s, "\tbackground color (10bpc): r=3D0x%x g=3D0x%x b=3D0x%x\n", + DRM_ARGB64_GETR_BPCS(cstate->background_color, 10), + DRM_ARGB64_GETG_BPCS(cstate->background_color, 10), + DRM_ARGB64_GETB_BPCS(cstate->background_color, 10)); seq_printf(s, " Display mode: %dx%d%s%d\n", mode->hdisplay, mode->vdisplay, interlaced ? "i" : "p", drm_mode_vrefresh(mode)); @@ -2472,6 +2485,8 @@ static int vop2_create_crtcs(struct vop2 *vop2) return dev_err_probe(drm->dev, ret, "crtc init for video_port%d failed\n", i); =20 + drm_crtc_attach_background_color_property(&vp->crtc); + drm_crtc_helper_add(&vp->crtc, &vop2_crtc_helper_funcs); if (vop2->lut_regs) { const struct vop2_video_port_data *vp_data =3D &vop2_data->vp[vp->id]; diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index 9124191899ba..37722652844a 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -658,6 +658,10 @@ enum dst_factor_mode { #define RK3588_VP_CLK_CTRL__DCLK_OUT_DIV GENMASK(3, 2) #define RK3588_VP_CLK_CTRL__DCLK_CORE_DIV GENMASK(1, 0) =20 +#define RK3568_VP_DSP_BG__DSP_BG_RED GENMASK(29, 20) +#define RK3568_VP_DSP_BG__DSP_BG_GREEN GENMASK(19, 10) +#define RK3568_VP_DSP_BG__DSP_BG_BLUE GENMASK(9, 0) + #define RK3568_VP_POST_SCL_CTRL__VSCALEDOWN BIT(1) #define RK3568_VP_POST_SCL_CTRL__HSCALEDOWN BIT(0) =20 --=20 2.52.0