[RFC PATCH 15/17] drm/vkms: Allow to configure multiple planes via configfs
Louis Chauvet
louis.chauvet at bootlin.com
Tue Aug 13 17:59:00 UTC 2024
Le 13/08/24 - 12:44, José Expósito a écrit :
> Create a default subgroup at /config/vkms/planes to allow to create as
> many overlay planes as required. When the plane is created the
> possible_crtcs subgroup is created allowing to link planes and CRTCs.
I think my comment about updating possible_crtc and indexes is very
important here as the userspace can create and delete crtcs. I don't have
the time to test today, but there is probably issues again with crtc
creation/deletion.
> Signed-off-by: José Expósito <jose.exposito89 at gmail.com>
> ---
> Documentation/gpu/vkms.rst | 13 ++-
> drivers/gpu/drm/vkms/vkms_config.h | 3 +
> drivers/gpu/drm/vkms/vkms_configfs.c | 121 +++++++++++++++++++++++++++
> 3 files changed, 136 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
> index b6ceb8c48310..ee71d1a569dd 100644
> --- a/Documentation/gpu/vkms.rst
> +++ b/Documentation/gpu/vkms.rst
> @@ -78,7 +78,8 @@ And directories are created for each configurable item of the display pipeline::
> ├── connectors
> ├── crtcs
> ├── enabled
> - └── encoders
> + ├── encoders
> + └── planes
>
> To add items to the display pipeline, create one or more directories under the
> available paths.
> @@ -111,6 +112,14 @@ linked to encoders by creating a symbolic link under ``possible_encoders``::
>
> sudo ln -s /config/vkms/my-vkms/encoders/encoder0 /config/vkms/my-vkms/connectors/connector0/possible_encoders
>
> +Finally, create zero or more overlay planes::
> +
> + sudo mkdir /config/vkms/my-vkms/planes/plane0
> +
> +And link them with their ``possible_crtcs``::
> +
> + sudo ln -s /config/vkms/my-vkms/crtcs/crtc0 /config/vkms/my-vkms/planes/plane0/possible_crtcs
> +
> Once you are done configuring the VKMS instance, enable it::
>
> echo "1" | sudo tee /config/vkms/my-vkms/enabled
> @@ -128,6 +137,8 @@ Or removing the top level directory and its subdirectories::
> sudo rmdir /config/vkms/my-vkms/connectors/*
> sudo rm /config/vkms/my-vkms/encoders/*/possible_crtcs/*
> sudo rmdir /config/vkms/my-vkms/encoders/*
> + sudo rm /config/vkms/my-vkms/planes/*/possible_crtcs/*
> + sudo rmdir /config/vkms/my-vkms/planes/*
> sudo rmdir /config/vkms/my-vkms/crtcs/*
> sudo rmdir /config/vkms/my-vkms
>
> diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
> index cf45e3f6ae92..2ec08bb58ec4 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.h
> +++ b/drivers/gpu/drm/vkms/vkms_config.h
> @@ -14,6 +14,9 @@ struct vkms_device;
> struct vkms_config_plane {
> struct list_head list;
> uint32_t possible_crtcs;
> + /* only used if created from configfs */
> + struct config_group plane_group;
> + struct config_group possible_crtcs_group;
> };
>
> struct vkms_config_crtc {
> diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c
> index d2369f53e2d8..0b5ac0767da0 100644
> --- a/drivers/gpu/drm/vkms/vkms_configfs.c
> +++ b/drivers/gpu/drm/vkms/vkms_configfs.c
> @@ -23,6 +23,8 @@ static bool is_configfs_registered;
> * "/config/vkms/encoders". Each of its items represent a encoder
> * @connectors_group: Default subgroup of @device_group at
> * "/config/vkms/connectors". Each of its items represent a connector
> + * @planes_group: Default subgroup of @device_group at "/config/vkms/planes".
> + * Each of its items represent an overlay plane
> * @lock: Lock used to project concurrent access to the configuration attributes
> * @enabled: Protected by @lock. The device is created or destroyed when this
> * option changes
> @@ -33,6 +35,7 @@ struct vkms_configfs {
> struct config_group crtcs_group;
> struct config_group encoders_group;
> struct config_group connectors_group;
> + struct config_group planes_group;
>
> /* protected by @lock */
> struct mutex lock;
> @@ -72,6 +75,15 @@ struct vkms_configfs {
> #define connector_possible_encoders_item_to_vkms_config_connector(item) \
> container_of(to_config_group(item), struct vkms_config_connector, possible_encoders_group)
>
> +#define planes_group_to_vkms_configfs(group) \
> + container_of(group, struct vkms_configfs, planes_group)
> +
> +#define planes_item_to_vkms_config_plane(item) \
> + container_of(to_config_group(item), struct vkms_config_plane, plane_group)
> +
> +#define plane_possible_crtcs_item_to_vkms_config_plane(item) \
> + container_of(to_config_group(item), struct vkms_config_plane, possible_crtcs_group)
> +
> static ssize_t crtc_cursor_show(struct config_item *item, char *page)
> {
> struct vkms_config_crtc *crtc_cfg = crtcs_item_to_vkms_config_crtc(item);
> @@ -450,6 +462,110 @@ static struct config_item_type connectors_group_type = {
> .ct_owner = THIS_MODULE,
> };
>
> +static int plane_possible_crtcs_allow_link(struct config_item *src,
> + struct config_item *target)
> +{
> + struct vkms_config_plane *plane_cfg;
> + struct vkms_config_crtc *crtc_cfg;
> +
> + if (target->ci_type != &crtc_group_type)
> + return -EINVAL;
> +
> + plane_cfg = plane_possible_crtcs_item_to_vkms_config_plane(src);
> + crtc_cfg = crtcs_item_to_vkms_config_crtc(target);
> +
> + if (plane_cfg->possible_crtcs & BIT(crtc_cfg->index))
> + return -EINVAL;
> +
> + plane_cfg->possible_crtcs |= BIT(crtc_cfg->index);
> +
> + return 0;
> +}
> +
> +static void plane_possible_crtcs_drop_link(struct config_item *src,
> + struct config_item *target)
> +{
> + struct vkms_config_plane *plane_cfg;
> + struct vkms_config_crtc *crtc_cfg;
> +
> + plane_cfg = plane_possible_crtcs_item_to_vkms_config_plane(src);
> + crtc_cfg = crtcs_item_to_vkms_config_crtc(target);
> +
> + plane_cfg->possible_crtcs &= ~BIT(crtc_cfg->index);
> +}
> +
> +static struct configfs_item_operations plane_possible_crtcs_item_ops = {
> + .allow_link = &plane_possible_crtcs_allow_link,
> + .drop_link = &plane_possible_crtcs_drop_link,
> +};
> +
> +static struct config_item_type plane_possible_crtcs_group_type = {
> + .ct_item_ops = &plane_possible_crtcs_item_ops,
> + .ct_owner = THIS_MODULE,
> +};
> +
> +static const struct config_item_type plane_group_type = {
> + .ct_owner = THIS_MODULE,
> +};
> +
> +static struct config_group *make_planes_group(struct config_group *group,
> + const char *name)
> +{
> + struct vkms_configfs *configfs = planes_group_to_vkms_configfs(group);
> + struct vkms_config_plane *plane_cfg;
> + int ret;
> +
> + mutex_lock(&configfs->lock);
> +
> + if (configfs->enabled) {
> + ret = -EINVAL;
> + goto err_unlock;
> + }
> +
> + plane_cfg = vkms_config_add_overlay_plane(configfs->vkms_config, 0);
> + if (IS_ERR(plane_cfg)) {
> + ret = PTR_ERR(plane_cfg);
> + goto err_unlock;
> + }
> +
> + config_group_init_type_name(&plane_cfg->plane_group, name,
> + &plane_group_type);
> +
> + config_group_init_type_name(&plane_cfg->possible_crtcs_group,
> + "possible_crtcs",
> + &plane_possible_crtcs_group_type);
> + configfs_add_default_group(&plane_cfg->possible_crtcs_group,
> + &plane_cfg->plane_group);
> +
> + mutex_unlock(&configfs->lock);
> +
> + return &plane_cfg->plane_group;
> +
> +err_unlock:
> + mutex_unlock(&configfs->lock);
> + return ERR_PTR(ret);
> +}
If I understand properly your code, there is no way to configure primary
and cursor planes? If we want to introduce it later, I think we will break
the uAPI, so it will be difficult.
> +
> +static void drop_planes_group(struct config_group *group,
> + struct config_item *item)
> +{
> + struct vkms_configfs *configfs = planes_group_to_vkms_configfs(group);
> + struct vkms_config_plane *plane_cfg =
> + planes_item_to_vkms_config_plane(item);
> +
> + vkms_config_destroy_overlay_plane(configfs->vkms_config, plane_cfg);
> +}
> +
> +static struct configfs_group_operations planes_group_ops = {
> + .make_group = &make_planes_group,
> + .drop_item = &drop_planes_group,
> +};
> +
> +static struct config_item_type planes_group_type = {
> + .ct_group_ops = &planes_group_ops,
> + .ct_owner = THIS_MODULE,
> +};
> +
> static ssize_t device_enabled_show(struct config_item *item, char *page)
> {
> struct vkms_configfs *configfs = config_item_to_vkms_configfs(item);
> @@ -538,6 +654,11 @@ static struct config_group *make_device_group(struct config_group *group,
> configfs_add_default_group(&configfs->connectors_group,
> &configfs->device_group);
>
> + config_group_init_type_name(&configfs->planes_group, "planes",
> + &planes_group_type);
> + configfs_add_default_group(&configfs->planes_group,
> + &configfs->device_group);
> +
> return &configfs->device_group;
> }
>
> --
> 2.46.0
>
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
More information about the dri-devel
mailing list