From nobody Mon Feb 9 09:32:25 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 205DB347FC6; Wed, 29 Oct 2025 13:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761744656; cv=none; b=OG4CNZBTmUWxOrnzNwYox/MRlApougsVIY25Qp/W7cZYHfLMpqfa/p7ZoP0+gmFYeTAv6A08/7RawASvJF6enr1Y4ZRVA2D5tMGOUoYhJWucdZNfxG3LUjp0K7TNSTa1Au5RvWeS5NKf8OLbeOkOQLSaDTXKzCj3xo/jTK83p1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761744656; c=relaxed/simple; bh=rcbzjgVxA4Jez3zrGuCjbePTCA++bw2wssPuLSi1PnU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DeLQmymCUelovU+qwt4gywz+SfQevzL78rPwA0UwWVk+61albMqNRNN6d7BPXFGv+EDFte93WGmtTBS+eWkG0HLrnnimQrgLtHEyT9d+1qdfPHuvI86UkbjTjp4DjFkGZiLpg+POKvCgNcaoBEami23rNf8ZnJCwlZPb/5PWVeE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Qajpg7MZ; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Qajpg7MZ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 5B09DC0DB00; Wed, 29 Oct 2025 13:30:32 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id B0EE8606E8; Wed, 29 Oct 2025 13:30:52 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 77D28117F8098; Wed, 29 Oct 2025 14:30:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1761744651; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=bJvliQF2se397IGqvdiAT2buACguHu4DPZiFQtOO7UQ=; b=Qajpg7MZkaXjLnbysXK7vt6IBC+mZ0AoSSOaUfQxe/4tsJSdUCR8RyyrScgPOrTUGfkXH2 F+IlFHSgApAar8wWO2u9PTv3LMqR9H2ct1m2qELBxtDTxjjt557TiwDJShdMub7Kb+XTM7 +qaqI9y2mTSsr8Ob9EC7lIKH+i941cwTAOQ7xmqQCZr4xlov+A3gBYhR2igOc2UiFlkleM lIsXRxslzbKg6ElS4qTRbcoH0luaITNwRZbAL2AdfEGdHZNK8vem96F+HDiwG4Q//8+ZsJ DM5ihynCI2tfM35fwnnoV6ASz2yVKeecDzjijv7WGaUbA+HcRA4IFfhE4xRozg== From: Louis Chauvet Date: Wed, 29 Oct 2025 14:30:26 +0100 Subject: [PATCH v2 16/32] drm/vkms: Introduce config for plane format 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: <20251029-vkms-all-config-v2-16-be20b9bf146e@bootlin.com> References: <20251029-vkms-all-config-v2-0-be20b9bf146e@bootlin.com> In-Reply-To: <20251029-vkms-all-config-v2-0-be20b9bf146e@bootlin.com> To: Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , jose.exposito89@gmail.com, Jonathan Corbet Cc: victoria@system76.com, sebastian.wick@redhat.com, victoria@system76.com, airlied@gmail.com, thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Louis Chauvet X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=9903; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=rcbzjgVxA4Jez3zrGuCjbePTCA++bw2wssPuLSi1PnU=; b=owEBbQKS/ZANAwAKASCtLsZbECziAcsmYgBpAhbr4+hcWmPaXzfzsaRYh9tvgpthWQrw517st GaCaNSkqHmJAjMEAAEKAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCaQIW6wAKCRAgrS7GWxAs 4vp6D/0ecB6iQ8qeVkw3nmtCZIyPNke/0X1d+SOm6VzxChjihgEqSX8yrc5QqBLesKQ1cNM9KzZ R1316qv/c9UZep8jUozlnijBb869m9bTp1C9pNgXXZISGXemMnUdFqn2Y0cg1bQMXIJAlBaoV4z uBGmBKe2dtY2u/XpX+UcKQdBBpu8xZ/EXizL0lB+ZwPZ6c4BbGPKfRJkQ5s6wCRL8MGhUt0ypXP x7Zk93kCI5BWq9ZzQv6ct7ePTf14YTBJwk+09U1eh1oOXjlva6gJu2s/F9OHoEElO3DTVKFxaAh JIZN6ijnz+iv00tECw7YAXvOdsr2J3xB4hlteyZ3I0LjzMsUAaZiTsj+rW0tEuCLz9J1XrjmY4t 9YBEccBcGzM31rvpU5i7ZgIWoBhttuSapBye+u7xCk7pcK4GsupVo088jkdQM+CgXOt5mIwYCqJ KAXX7uRFwD6yyZgYAtSjLOXVJu2aFkeCEo3JEhtjjc0xn+YeRiV9Q2v7nqVrg6qhut44GDX04he Bn2bKX1s3aPB5RrZlDYsULWf7wDaz+3IsOzmoE9vJLdMOwdtUcWiRaYWP4VNKb1NOTwedsfmTFq kSN7peEq0hByuRmu5RlvXE8acmzHzi8TlwV5iW27vKxpu8GAubFWnqNIo8Xm+zEAqaEslhanllX FXcMHsU6YWmsT9w== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-Last-TLS-Session-Version: TLSv1.3 VKMS driver supports all the pixel formats for planes, but for testing it can be useful to only advertise few of them. This new configuration interface will allow configuring the pixel format per planes. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 114 +++++++++++++++++++++++++++++++++= ++++ drivers/gpu/drm/vkms/vkms_config.h | 51 +++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 39 +------------ 3 files changed, 167 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms= _config.c index 823039fb4145..a3fb80451b30 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -12,6 +12,42 @@ =20 #include "vkms_config.h" =20 +static const u32 vkms_supported_plane_formats[] =3D { + DRM_FORMAT_ARGB8888, + DRM_FORMAT_ABGR8888, + DRM_FORMAT_BGRA8888, + DRM_FORMAT_RGBA8888, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_XBGR8888, + DRM_FORMAT_RGB888, + DRM_FORMAT_BGR888, + DRM_FORMAT_XRGB16161616, + DRM_FORMAT_XBGR16161616, + DRM_FORMAT_ARGB16161616, + DRM_FORMAT_ABGR16161616, + DRM_FORMAT_RGB565, + DRM_FORMAT_BGR565, + DRM_FORMAT_NV12, + DRM_FORMAT_NV16, + DRM_FORMAT_NV24, + DRM_FORMAT_NV21, + DRM_FORMAT_NV61, + DRM_FORMAT_NV42, + DRM_FORMAT_YUV420, + DRM_FORMAT_YUV422, + DRM_FORMAT_YUV444, + DRM_FORMAT_YVU420, + DRM_FORMAT_YVU422, + DRM_FORMAT_YVU444, + DRM_FORMAT_P010, + DRM_FORMAT_P012, + DRM_FORMAT_P016, + DRM_FORMAT_R1, + DRM_FORMAT_R2, + DRM_FORMAT_R4, + DRM_FORMAT_R8, +}; + struct vkms_config *vkms_config_create(const char *dev_name) { struct vkms_config *config; @@ -437,6 +473,15 @@ static void show_bitfield(struct seq_file *m, uint32_t= value, const char *callba } } =20 +static void show_formats(struct seq_file *m, u32 *formats, size_t formats_= count) +{ + for (int i =3D 0; i < formats_count; i++) { + seq_printf(m, "%p4cc", &formats[i]); + if (i !=3D formats_count - 1) + seq_puts(m, ", "); + } +} + static int vkms_config_show(struct seq_file *m, void *data) { struct drm_debugfs_entry *entry =3D m->private; @@ -477,6 +522,10 @@ static int vkms_config_show(struct seq_file *m, void *= data) seq_puts(m, "\n"); seq_printf(m, "\tdefault color range=3D%s\n", drm_get_color_range_name(vkms_config_plane_get_default_color_range(p= lane_cfg))); + seq_puts(m, "\tsupported formats=3D"); + show_formats(m, vkms_config_plane_get_supported_formats(plane_cfg), + vkms_config_plane_get_supported_formats_count(plane_cfg)); + seq_puts(m, "\n"); } =20 vkms_config_for_each_crtc(vkmsdev->config, crtc_cfg) { @@ -515,6 +564,11 @@ struct vkms_config_plane *vkms_config_create_plane(str= uct vkms_config *config) if (!plane_cfg) return ERR_PTR(-ENOMEM); =20 + if (vkms_config_plane_add_all_formats(plane_cfg)) { + kfree(plane_cfg); + return ERR_PTR(-ENOMEM); + } + plane_cfg->config =3D config; vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_OVERLAY); vkms_config_plane_set_name(plane_cfg, NULL); @@ -644,6 +698,66 @@ static struct vkms_config_plane *vkms_config_crtc_get_= plane(const struct vkms_co return NULL; } =20 +int __must_check vkms_config_plane_add_all_formats(struct vkms_config_plan= e *plane_cfg) +{ + u32 *ret =3D krealloc_array(plane_cfg->supported_formats, + ARRAY_SIZE(vkms_supported_plane_formats), + sizeof(uint32_t), GFP_KERNEL); + if (!ret) + return -ENOMEM; + plane_cfg->supported_formats =3D ret; + + memcpy(plane_cfg->supported_formats, vkms_supported_plane_formats, + sizeof(vkms_supported_plane_formats)); + plane_cfg->supported_formats_count =3D ARRAY_SIZE(vkms_supported_plane_fo= rmats); + return 0; +} + +int __must_check vkms_config_plane_add_format(struct vkms_config_plane *pl= ane_cfg, u32 drm_format) +{ + bool found =3D false; + + for (int i =3D 0; i < ARRAY_SIZE(vkms_supported_plane_formats); i++) { + if (vkms_supported_plane_formats[i] =3D=3D drm_format) { + found =3D true; + break; + } + } + + if (!found) + return -EINVAL; + for (unsigned int i =3D 0; i < plane_cfg->supported_formats_count; i++) { + if (plane_cfg->supported_formats[i] =3D=3D drm_format) + return 0; + } + u32 *new_ptr =3D krealloc_array(plane_cfg->supported_formats, + plane_cfg->supported_formats_count + 1, + sizeof(*plane_cfg->supported_formats), GFP_KERNEL); + if (!new_ptr) + return -ENOMEM; + + plane_cfg->supported_formats =3D new_ptr; + plane_cfg->supported_formats[plane_cfg->supported_formats_count] =3D drm_= format; + plane_cfg->supported_formats_count++; + + return 0; +} + +void vkms_config_plane_remove_all_formats(struct vkms_config_plane *plane_= cfg) +{ + plane_cfg->supported_formats_count =3D 0; +} + +void vkms_config_plane_remove_format(struct vkms_config_plane *plane_cfg, = u32 drm_format) +{ + for (unsigned int i =3D 0; i < plane_cfg->supported_formats_count; i++) { + if (plane_cfg->supported_formats[i] =3D=3D drm_format) { + plane_cfg->supported_formats[i] =3D plane_cfg->supported_formats[plane_= cfg->supported_formats_count - 1]; + plane_cfg->supported_formats_count--; + } + } +} + struct vkms_config_plane *vkms_config_crtc_primary_plane(const struct vkms= _config *config, struct vkms_config_crtc *crtc_cfg) { diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms= _config.h index d8648bf844d4..2d9e35b7caad 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -49,6 +49,8 @@ struct vkms_config { * @supported_color_encodings: Color encoding that this plane will support * @default_color_range: Default color range that should be used by this p= lane * @supported_color_ranges: Color range that this plane will support + * @supported_formats: List of supported formats + * @supported_formats_count: Length of @supported_formats */ struct vkms_config_plane { struct list_head link; @@ -62,6 +64,8 @@ struct vkms_config_plane { unsigned int supported_color_encodings; enum drm_color_range default_color_range; unsigned int supported_color_ranges; + u32 *supported_formats; + unsigned int supported_formats_count; struct xarray possible_crtcs; =20 /* Internal usage */ @@ -448,6 +452,53 @@ bool vkms_config_valid_plane_color_range(const struct = vkms_config *config, const struct vkms_config_plane *plane_cfg); #endif =20 +static inline u32 * +vkms_config_plane_get_supported_formats(const struct vkms_config_plane *pl= ane_cfg) +{ + return plane_cfg->supported_formats; +} + +static inline unsigned int +vkms_config_plane_get_supported_formats_count(struct vkms_config_plane *pl= ane_cfg) +{ + return plane_cfg->supported_formats_count; +} + +/** vkms_config_plane_add_format - Add a format to the list of supported f= ormat of a plane + * + * The passed drm_format can already be present in the list. This may fail= if the allocation of a + * bigger array fails. + * + * @plane_cfg: Plane to add the format to + * @drm_format: Format to add to this plane + * + * Returns: 0 on success, -ENOMEM if array allocation fails, -EINVAL if th= e format is not supported + * by VKMS + */ +int __must_check vkms_config_plane_add_format(struct vkms_config_plane *pl= ane_cfg, u32 drm_format); + +/** + * vkms_config_plane_add_all_formats - Helper to quickly add all the suppo= rted formats + * @plane_cfg: Plane to add the formats to + * + * Returns: 0 on success, -ENOMEM if array allocation fails, -EINVAL if th= e format is not supported + * by VKMS + */ +int __must_check vkms_config_plane_add_all_formats(struct vkms_config_plan= e *plane_cfg); + +/** + * vkms_config_plane_remove_format - Remove a specific format from a plane + * @plane_cfg: Plane to remove the format to + * @drm_format: Format to remove + */ +void vkms_config_plane_remove_format(struct vkms_config_plane *plane_cfg, = u32 drm_format); + +/** + * vkms_config_plane_remove_all_formats - Remove all formast from a plane + * @plane_cfg: Plane to remove the formats from + */ +void vkms_config_plane_remove_all_formats(struct vkms_config_plane *plane_= cfg); + /** * vkms_config_plane_set_name() - Set the plane name * @plane_cfg: Plane to set the name to diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 5dbc7c67de1d..945abbbeac99 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -14,42 +14,6 @@ #include "vkms_drv.h" #include "vkms_formats.h" =20 -static const u32 vkms_formats[] =3D { - DRM_FORMAT_ARGB8888, - DRM_FORMAT_ABGR8888, - DRM_FORMAT_BGRA8888, - DRM_FORMAT_RGBA8888, - DRM_FORMAT_XRGB8888, - DRM_FORMAT_XBGR8888, - DRM_FORMAT_RGB888, - DRM_FORMAT_BGR888, - DRM_FORMAT_XRGB16161616, - DRM_FORMAT_XBGR16161616, - DRM_FORMAT_ARGB16161616, - DRM_FORMAT_ABGR16161616, - DRM_FORMAT_RGB565, - DRM_FORMAT_BGR565, - DRM_FORMAT_NV12, - DRM_FORMAT_NV16, - DRM_FORMAT_NV24, - DRM_FORMAT_NV21, - DRM_FORMAT_NV61, - DRM_FORMAT_NV42, - DRM_FORMAT_YUV420, - DRM_FORMAT_YUV422, - DRM_FORMAT_YUV444, - DRM_FORMAT_YVU420, - DRM_FORMAT_YVU422, - DRM_FORMAT_YVU444, - DRM_FORMAT_P010, - DRM_FORMAT_P012, - DRM_FORMAT_P016, - DRM_FORMAT_R1, - DRM_FORMAT_R2, - DRM_FORMAT_R4, - DRM_FORMAT_R8, -}; - static struct drm_plane_state * vkms_plane_duplicate_state(struct drm_plane *plane) { @@ -226,7 +190,8 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *= vkmsdev, =20 plane =3D drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, - vkms_formats, ARRAY_SIZE(vkms_formats), + vkms_config_plane_get_supported_formats(config), + vkms_config_plane_get_supported_formats_count(config), NULL, vkms_config_plane_get_type(config), vkms_config_plane_get_name(config)); if (IS_ERR(plane)) --=20 2.51.0