From nobody Mon Feb 9 16:50:49 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 360312C11EB for ; Wed, 29 Oct 2025 14:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761748643; cv=none; b=TTbERPjek2T72CiGKlkP9S4chVP/fMYRH73p+k0wJbyjD0Xgce5UJb/qJHstio7HJWT5j9/t/wy6Z/GRYORtAvqecdV7kIDDsELm5tWXUGqYEPyrPOehApIWFk+euHrmidx3sztvGGqp+XKFKeeBbr29rnCYlRs5nhWs9nAJwKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761748643; c=relaxed/simple; bh=rcbzjgVxA4Jez3zrGuCjbePTCA++bw2wssPuLSi1PnU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cRlNRnPQHT/VIWO1Vx8u3ea+hreMG543s9sUhkZ9NjXIu61gYrpIpje0uuhfcRH2MqEFMb5jNZjGKlPhNRZzNo+w1lTz0X2OTDimQQZ6O9flShbsmGfpa4tXvbgfetASLOXq01Oodvq3VKTo3Nnr9J4hecY4qF83dxHlGChXNTk= 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=bfh+dNc8; arc=none smtp.client-ip=185.246.85.4 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="bfh+dNc8" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id A45CE4E413CF; Wed, 29 Oct 2025 14:37:19 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 77408606E8; Wed, 29 Oct 2025 14:37:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 762DB117F81A9; Wed, 29 Oct 2025 15:37:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1761748638; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=bJvliQF2se397IGqvdiAT2buACguHu4DPZiFQtOO7UQ=; b=bfh+dNc8cm8UySa+3QZyRMKtxBtRH6k6EmP4S08H2LndswWSo9DcPFwQwlPnIU7aycof4L uM3NO4+HXCDqgiiJn5+idzhCeIAxulqCLy8Ztvo7cx86yxOUOStliNoEXNsKQs8YKfXrGI xR9WgNZORQmlTcBqJyIFTz905P1FA50W7OXLM2itFGI+oC3WxDwgwmQBZesmTtZHr3UEue shPKdyjYosFRXbUpo7spL22CRkY7PB7QzKXaswr/5fxsjCORj9LqqhjVXYnVReTyGQdken +GTclJQDO6y0QxCVT26wSqYNEKeBH07PFE8Czz1heVenu5za7T4tEXmPEhhg+w== From: Louis Chauvet Date: Wed, 29 Oct 2025 15:36:53 +0100 Subject: [PATCH RESEND 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-a49a2d4cba26@bootlin.com> References: <20251029-vkms-all-config-v2-0-a49a2d4cba26@bootlin.com> In-Reply-To: <20251029-vkms-all-config-v2-0-a49a2d4cba26@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/ZANAwAKASCtLsZbECziAcsmYgBpAiZ8MT44yWYn64FGiGv8rHYve/ewVgnOLywTf JLsv2PiN8GJAjMEAAEKAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCaQImfAAKCRAgrS7GWxAs 4sXRD/9zHIbpRiKVZSH+jPZF2vsWeIqT3nQZx0zd0EHy+IDfwnOUZj2OZ1UUk8wvt4RIHigBFHu CrL99A7Fxq5Nx2L/ZtlwtMfUL4hbhQ6imsGNuo5KnwXMnzHqnpIn+5T6/iBDUfqX2B1jTtFYXVP 2jguOPvxBPJ5XYcg7U3GNve70djL2G38F2KC5wlT3f0+69IifV6cN59FUTxADFVkrfrLyfr7VtH HyfqZN2+Bwe2vKmDtMS8CpnYYr55jINQpFJ+CISfDyfD+zDefN6sfeGDA4o+ihE/eMXiDA9sWUW I6ZmpJmo4zD/qzHTHJlnfoZPBctQjQXHyaKi2djjPotT4wYutibX950QTI9GG33dxayWseWTWDU VaPwEQ9pBhVLyY0kiEWqNz05e8i05wBlVj8Yg3zu/AxRjEL8ORCtsLJS3iuVPmyxMkrGPTF/yqw +8OjZqlVsnq9UtbKrkwUeIUw7r+9xuA/l0eVYUVgDmbTD0AzO6+tudf+u+p94CivjkNCd6ctfNA fAUnLao7QGoQMJaKbG5kBq7qwY9Gmb0ioDj5vlqRS+6+3+kCuFLKiai9RlhojFlzbyWIpuktfiZ /RdqYuqz5iTErXaep/SCC50KuRCTq7WtwIM4ElFHIUaVZrnRk6H1+kLOBzO0AZ4qLiWp/gzu7qw W5oO/yoPxh1A5Fw== 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