[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aPueydZ1bdmEQ8VE@fedora>
Date: Fri, 24 Oct 2025 17:44:09 +0200
From: José Expósito <jose.exposito89@...il.com>
To: Louis Chauvet <louis.chauvet@...tlin.com>
Cc: Haneen Mohammed <hamohammed.sa@...il.com>,
Simona Vetter <simona@...ll.ch>,
Melissa Wen <melissa.srw@...il.com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>, Jonathan Corbet <corbet@....net>,
victoria@...tem76.com, sebastian.wick@...hat.com,
thomas.petazzoni@...tlin.com, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org
Subject: Re: [PATCH 09/22] drm/vkms: Introduce config for plane format
On Sat, Oct 18, 2025 at 04:01:09AM +0200, Louis Chauvet wrote:
> 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 <louis.chauvet@...tlin.com>
> ---
> drivers/gpu/drm/vkms/vkms_config.c | 99 ++++++++++++++++++++++++++++++++++++++
> drivers/gpu/drm/vkms/vkms_config.h | 49 +++++++++++++++++++
> drivers/gpu/drm/vkms/vkms_plane.c | 39 +--------------
> 3 files changed, 150 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
> index 8f00ca21ed6e..0b975a0d47aa 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.c
> +++ b/drivers/gpu/drm/vkms/vkms_config.c
> @@ -8,6 +8,42 @@
>
> #include "vkms_config.h"
>
> +static const u32 vkms_supported_plane_formats[] = {
> + 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;
> @@ -435,6 +471,11 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *config)
> if (!plane_cfg)
> return ERR_PTR(-ENOMEM);
>
> + if (vkms_config_plane_add_all_formats(plane_cfg)) {
> + kfree(plane_cfg);
> + return ERR_PTR(-ENOMEM);
> + }
> +
> plane_cfg->config = config;
> vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_OVERLAY);
> vkms_config_plane_set_name(plane_cfg, NULL);
> @@ -563,6 +604,64 @@ static struct vkms_config_plane *vkms_config_crtc_get_plane(const struct vkms_co
> return NULL;
> }
>
> +int __must_check vkms_config_plane_add_all_formats(struct vkms_config_plane *plane_cfg)
> +{
> + u32 *ret = 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 = ret;
> +
> + memcpy(plane_cfg->supported_formats, vkms_supported_plane_formats,
> + sizeof(vkms_supported_plane_formats));
> + plane_cfg->supported_formats_count = ARRAY_SIZE(vkms_supported_plane_formats);
> + return 0;
> +}
> +
> +int __must_check vkms_config_plane_add_format(struct vkms_config_plane *plane_cfg, u32 drm_format)
> +{
> + bool found = false;
> +
> + for (int i = 0; i < ARRAY_SIZE(vkms_supported_plane_formats); i++) {
> + if (vkms_supported_plane_formats[i] == drm_format)
> + found = true;
Missing break?
> + }
> +
> + if (!found)
> + return -EINVAL;
> + for (unsigned int i = 0; i < plane_cfg->supported_formats_count; i++) {
> + if (plane_cfg->supported_formats[i] == drm_format)
> + return 0;
> + }
> + u32 *new_ptr = 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 = new_ptr;
> + plane_cfg->supported_formats[plane_cfg->supported_formats_count] = 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 = 0;
> +}
> +
> +void vkms_config_plane_remove_format(struct vkms_config_plane *plane_cfg, u32 drm_format)
> +{
> + for (unsigned int i = 0; i < plane_cfg->supported_formats_count; i++) {
> + if (plane_cfg->supported_formats[i] == drm_format) {
> + plane_cfg->supported_formats[i] = 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 8127e12f00dc..0b7067508e5f 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.h
> +++ b/drivers/gpu/drm/vkms/vkms_config.h
> @@ -62,6 +62,8 @@ struct vkms_config_plane {
> unsigned int supported_color_encoding;
> enum drm_color_range default_color_range;
> unsigned int supported_color_range;
> + u32 *supported_formats;
> + unsigned int supported_formats_count;
> struct xarray possible_crtcs;
>
> /* Internal usage */
> @@ -404,6 +406,53 @@ vkms_config_plane_set_supported_color_range(struct vkms_config_plane *plane_cfg,
> plane_cfg->supported_color_range = supported_color_range;
> }
>
> +static inline u32 *
> +vkms_config_plane_get_supported_formats(struct vkms_config_plane *plane_cfg)
> +{
> + return plane_cfg->supported_formats;
> +}
> +
> +static inline unsigned int
> +vkms_config_plane_get_supported_formats_count(struct vkms_config_plane *plane_cfg)
> +{
> + return plane_cfg->supported_formats_count;
> +}
> +
> +/** vkms_config_plane_add_format - Add a format to the list of supported format 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 the format is not supported
> + * by VKMS
> + */
> +int __must_check vkms_config_plane_add_format(struct vkms_config_plane *plane_cfg, u32 drm_format);
> +
> +/**
> + * vkms_config_plane_add_all_formats - Helper to quickly add all the supported formats
> + * @plane_cfg: Plane to add the formats to
> + *
> + * Returns: 0 on success, -ENOMEM if array allocation fails, -EINVAL if the format is not supported
> + * by VKMS
> + */
> +int __must_check vkms_config_plane_add_all_formats(struct vkms_config_plane *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 ab719da2ca0b..0414865915d8 100644
> --- a/drivers/gpu/drm/vkms/vkms_plane.c
> +++ b/drivers/gpu/drm/vkms/vkms_plane.c
> @@ -14,42 +14,6 @@
> #include "vkms_formats.h"
> #include "vkms_config.h"
>
> -static const u32 vkms_formats[] = {
> - 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,
>
> plane = 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))
>
> --
> 2.51.0
>
Powered by blists - more mailing lists