drm/vkms: ConfigFS interface
Louis Chauvet
maintainerv3 cover drm/vkms: ConfigFS interface
VKMS is manly used to test userspace program and its behavior. The current implementation is not very configurable as you can only have one device, with few specific planes.
This series aims to introduce a new interface, using ConfigFS, to create and configure more devices. This will introduce:
- Device creation
- Plane creation
- Plane configuration (type, color encoding, color range, rotations)
- Encoder creation
- CRTC creation
- Linking between CRTC and planes/encoders
The proposition is:
/config/vkms
DEVICE_1
┣━ enable
┣━ writeback
┣━ planes
┃ ┣━ PLANE_1
┃ ┃ ┣━ type
┃ ┃ ┣━ supported_rotations
┃ ┃ ┣━ default_rotations
┃ ┃ ┣━ supported_formats
┃ ┃ ┗━ possible_crtcs
┃ ┃ ┗━ >> /config/vkms/DEVICE_1/crtc/CRTC_1
┃ ┣━ PLANE_2
┃ ┃ ┗━ ditto
┃ ┗━ PLANE_3
┃ ┗━ ditto
┃
┣━ encoders
┃ ┣━ ENCODER_1
┃ ┃ ┗━ possible_crtcs
┃ ┃ ┗━ >> /config/vkms/DEVICE_1/crtc/CRTC_1
┃ ┗━ ENCODER_2
┃ ┗━ ditto
┃
┗━ crtc
┗━ CRTC_1
This interface aims to be extendable (new property can easly be added in objects) and easy to use (objects are created simply by creating folders, and configured by writing files).
This series depends on
https://lore.kernel.org/all/20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com/
---
Changes in v3:
- Rebased on drm-misc-next and
https://lore.kernel.org/all/20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com/
- Remove color encoding and color range configuration
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Added many new configuration (mainly connector)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Louis Chauvet (14):
drm/vkms: Add vkms_delete/create_device helper drm/vkms: Cleanup configuration field on device destroy drm/vkms: Introduce ConfigFS interface drm/vkms: Introduce configfs for plane drm/vkms: Introduce configfs for plane rotation drm/vkms: Introduce configfs for crtc and encoder drm/vkms: Introduce configfs for connectors drm/vkms: Introduce configfs for connector type drm/vkms: Introduce configfs for plane format drm/vkms: Introduce configfs for device name drm/vkms: Introduce configfs for connector status drm/vkms: Introduce configfs for connector id drm/vkms: Introduce configfs for connector EDID drm/vkms: Introduce configfs for encoder type
drivers/gpu/drm/vkms/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_config.c | 36 + drivers/gpu/drm/vkms/vkms_config.h | 6 +- drivers/gpu/drm/vkms/vkms_configfs.c | 1194 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_configfs.h | 128 ++++ drivers/gpu/drm/vkms/vkms_drv.c | 21 +- drivers/gpu/drm/vkms/vkms_drv.h | 3 + 8 files changed, 1384 insertions(+), 6 deletions(-)
---
base-commit: 49a167c393b0ceb592b9d2e65cc4f46bcc707108
change-id: 20240521-google-config-fs-b935b66b8d7b
prerequisite-message-id: 20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com
prerequisite-patch-id: f4e26c103417f44bb47682d43e6550299e58b857
prerequisite-patch-id: aefc656e8bc9edfd5527971231b7db23b416a19a
prerequisite-patch-id: 5d4cef18db0f817bc0e9074987c725a9b7739ab0
prerequisite-patch-id: a74401787cc57fd29164dcea46aca9cee3ac50f8
prerequisite-patch-id: f0d5640738b5947ab84272c458a2f729a611ab0f
prerequisite-patch-id: 91ba55d575e4d85500c713079455b112695abecc
prerequisite-patch-id: d8210f842130e4d0b47ef25b4aa1ec41a7e53db3
prerequisite-patch-id: 83a4752516471b5152d5e2cb6b56d7ecaae70f66
prerequisite-patch-id: 5b6aaa13b3e61cee85de8739cc9fa9f0d86e4ac0
prerequisite-patch-id: a65a919c52e47b81af3adaf660f18b4a6f107492
prerequisite-patch-id: d85cd3d48810fa53bda9e97928249c1899898b24
prerequisite-patch-id: c47a619ac3b9b244375776aa03b6c19c32108cca
prerequisite-patch-id: ef3b0b41bcf9e770319b72d866cef880088bdff0
prerequisite-patch-id: d1d7c3323f1a0690f94220e9eb9cc4d6a28df112
prerequisite-patch-id: c87e20092e0a2f6d657837dbf1611b9dbf100b2c
prerequisite-patch-id: c12f46d01d578587d93d20e9d987394ab63a65ab
Best regards,
Signature · 1 line
Louis Chauvet <[email protected]>
Louis Chauvet
maintainerRFC PATCH v3 1/14 drm/vkms: Add vkms_delete/create_device helper
In preparation for introduction of ConfigFS support, expose the vkms_destroy/create helper to remove a vkms device.
--- drivers/gpu/drm/vkms/vkms_drv.c | 4 ++-- drivers/gpu/drm/vkms/vkms_drv.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +2 -2
@@ -150,7 +150,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)return vkms_output_init (vkmsdev); } -static int vkms_create (struct vkms_config *config) +int vkms_create (struct vkms_config *config) {int ret;struct platform_device *pdev;
@@ -224,7 +224,7 @@ static int __init vkms_init(void)return ret; } -static void vkms_destroy (struct vkms_config *config) +void vkms_destroy (struct vkms_config *config) {struct platform_device *pdev;
drivers/gpu/drm/vkms/vkms_drv.h +3 -0
@@ -208,6 +208,9 @@ struct vkms_device {const struct vkms_config *config; }; +int vkms_create (struct vkms_config *config); +void vkms_destroy (struct vkms_config *config); +/* * The following helpers are used to convert a member of a struct into its parent. */
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 2/14 drm/vkms: Cleanup configuration field on device destroy
In reply to Louis ChauvetTo avoid having dangling pointers in struct vkms_config, remove all of them when the device is destroyed.
--- drivers/gpu/drm/vkms/vkms_config.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 3 ++- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-)
drivers/gpu/drm/vkms/vkms_config.c +23 -0
@@ -167,6 +167,29 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *vreturn vkms_config_connector; } +void vkms_config_disconnect_dev (struct vkms_config *vkms_config) +{ +struct vkms_config_connector *connector, *tmp_connector; +struct vkms_config_encoder *encoder, *tmp_encoder; +struct vkms_config_plane *plane, *tmp_plane; +struct vkms_config_crtc *crtc, *tmp_crtc; + + vkms_config->dev =NULL ; + +list_for_each_entry_safe (connector, tmp_connector, &vkms_config->connectors, link) { + connector->connector =NULL ; + } +list_for_each_entry_safe (encoder, tmp_encoder, &vkms_config->encoders, link) { + encoder->encoder =NULL ; + } +list_for_each_entry_safe (plane, tmp_plane, &vkms_config->planes, link) { + plane->plane =NULL ; + } +list_for_each_entry_safe (crtc, tmp_crtc, &vkms_config->crtcs, link) { + crtc->output =NULL ; + } +} +void vkms_config_connector_update_status (struct vkms_config_connector *vkms_config_connector,enum drm_connector_status status) {
drivers/gpu/drm/vkms/vkms_config.h +2 -1
@@ -109,10 +109,11 @@ struct vkms_config_connector {char edid_blob[PAGE_SIZE ];int edid_blob_len; -/* Internal usage */ +/* Set only when the device is enabled */ struct drm_connector *connector; }; +void vkms_config_disconnect_dev (struct vkms_config *vkms_config);void vkms_config_connector_update_status (struct vkms_config_connector *vkms_config_connector,enum drm_connector_status status);
drivers/gpu/drm/vkms/vkms_drv.c +1 -1
@@ -240,7 +240,7 @@ void vkms_destroy(struct vkms_config *config)devres_release_group (&pdev->dev,NULL );platform_device_unregister (pdev); - config->dev =NULL ; +vkms_config_disconnect_dev (config); } static void __exit vkms_exit(void)
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 3/14 drm/vkms: Introduce ConfigFS interface
In reply to Louis ChauvetVKMS is manly used to test userspace program and its behavior. The current implementation is not very configurable as you can only have one device, with few specific planes.
This is the introduction of a basic interface to dynamically create new devices.
The new interface is:
/config/vkms
DEVICE_1
┗━ enable
DEVICE_2
┗━ enable
--- drivers/gpu/drm/vkms/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_configfs.c | 144 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_configfs.h | 35 +++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 15 +++- 5 files changed, 194 insertions(+), 2 deletions(-)
drivers/gpu/drm/vkms/Kconfig +1 -0
@@ -6,6 +6,7 @@ config DRM_VKMS select DRM_CLIENT_SELECTION select DRM_KMS_HELPER select DRM_GEM_SHMEM_HELPER + select CONFIGFS_FS select CRC32 default n help
drivers/gpu/drm/vkms/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only vkms-y := \ + vkms_configfs.o \ vkms_drv.o \ vkms_plane.o \ vkms_output.o \
drivers/gpu/drm/vkms/vkms_configfs.c new file +144 -0
144 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_configfs.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include <linux/configfs.h> +#include <linux/mutex.h> + +#ifndef _VKMS_CONFIGFS_H +#define _VKMS_CONFIGFS_H + +/** +* struct vkms_configfs_device - Internal object to manage all the configfs items related to one +* device +* +* @group: Main configfs group for a device +* @platform_device: If a device was created (@enabled = true), stores a pointer to it +* @lock: Mutex used to avoid conflicting edition of @vkms_config +* @enabled: Store if the device was created or not +* @vkms_config: Current vkms configuration, protected by @lock +*/ +struct vkms_configfs_device { +struct config_group group; + +struct mutex lock; +bool enabled; + +struct vkms_config *vkms_config; +}; + +#define config_item_to_vkms_configfs_device (item) \ + container_of(to_config_group((item)), struct vkms_configfs_device, group) + +/* ConfigFS Support */ +int vkms_init_configfs (void ); +void vkms_unregister_configfs (void ); + +#endif /* _VKMS_CONFIGFS_H */
drivers/gpu/drm/vkms/vkms_drv.c +13 -2
@@ -29,6 +29,7 @@#include "vkms_drv.h" #include "vkms_config.h" +#include "vkms_configfs.h" #include <drm/drm_print.h> #include <drm/drm_debugfs.h>
@@ -156,7 +157,7 @@ int vkms_create(struct vkms_config *config)struct platform_device *pdev;struct vkms_device *vkms_device; - pdev =platform_device_register_simple (DRIVER_NAME ,-1 ,NULL ,0 ); + pdev =platform_device_register_simple (DRIVER_NAME ,PLATFORM_DEVID_AUTO ,NULL ,0 );if (IS_ERR (pdev))return PTR_ERR (pdev);
@@ -217,9 +218,17 @@ static int __init vkms_init(void)if (IS_ERR (default_config))return PTR_ERR (default_config); + ret =vkms_init_configfs (); +if (ret) { +DRM_ERROR ("Unable to initialize configfs\n" ); +vkms_config_destroy (default_config); + } + ret =vkms_create (default_config); -if (ret) +if (ret) { +vkms_unregister_configfs ();vkms_config_destroy (default_config); + }return ret; }
@@ -249,6 +258,8 @@ static void __exit vkms_exit(void)vkms_destroy (default_config);vkms_config_destroy (default_config); + +vkms_unregister_configfs (); }module_init (vkms_init);
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 4/14 drm/vkms: Introduce configfs for plane
In reply to Louis ChauvetTo allows the userspace to test many hardware configuration, introduce a new interface to create and configure planes.
The planes are created by creating a directory in the planes directory. The type of plane is configured by writing 0 (Overlay), 1 (primary) or 2 (cursor) in the file type.
As the CRTCs and encoders can't be configured yet, the planes are all atteched to the same CRTC and encoder.
The current interface is:
/config/vkms
DEVICE_1
┣━ enable
┣━ planes
┃ ┣━ PLANE_1
┃ ┃ ┣━ type
┃ ┣━ PLANE_2
┃ ┃ ┗━ type
┃ ┗━ PLANE_3
┃ ┗━ type
DEVICE_2
┗━ ditto
--- drivers/gpu/drm/vkms/vkms_configfs.c | 149 ++++++++++++++++++++++++++++++++--- drivers/gpu/drm/vkms/vkms_configfs.h | 20 +++++ 2 files changed, 160 insertions(+), 9 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +140 -9
@@ -10,6 +10,138 @@#include "vkms_drv.h" #include "vkms_config.h" +static ssize_t plane_type_show (struct config_item *item,char *page) +{ +struct vkms_config_plane *plane; +enum drm_plane_type plane_type; +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); + +mutex_lock (&vkms_configfs->lock); + plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; + plane_type = plane->type; +mutex_unlock (&vkms_configfs->lock); + +return sprintf (page,"%u" , plane_type); +} + +static ssize_t plane_type_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); +enum drm_plane_type val =DRM_PLANE_TYPE_OVERLAY ; +struct vkms_config_plane *plane; +int ret; + + ret =kstrtouint (page,10 , &val); +if (ret) +return ret; + +if (val !=DRM_PLANE_TYPE_PRIMARY && val !=DRM_PLANE_TYPE_CURSOR && + val !=DRM_PLANE_TYPE_OVERLAY ) +return -EINVAL ; + +mutex_lock (&vkms_configfs->lock); +if (vkms_configfs->enabled) { +mutex_unlock (&vkms_configfs->lock); +return -EINVAL ; + } + + plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; + plane->type = val; + +mutex_unlock (&vkms_configfs->lock); + +return count; +} + +CONFIGFS_ATTR (plane_, type); + +static struct configfs_attribute *plane_attrs[] = { + &plane_attr_type, +NULL , +}; + +static void plane_release (struct config_item *item) +{ +struct vkms_configfs_plane *vkms_configfs_plane =plane_item_to_vkms_configfs_plane (item); + +mutex_lock (&vkms_configfs_plane->vkms_configfs_device->lock); +vkms_config_delete_plane (vkms_configfs_plane->vkms_config_plane, + vkms_configfs_plane->vkms_configfs_device->vkms_config); +mutex_unlock (&vkms_configfs_plane->vkms_configfs_device->lock); + +kfree (vkms_configfs_plane); +} + +static struct configfs_item_operations plane_item_operations = { + .release = plane_release, +}; + +static const struct config_item_type subgroup_plane = { + .ct_attrs = plane_attrs, + .ct_item_ops = &plane_item_operations, + .ct_owner =THIS_MODULE , +}; + +static struct config_group *planes_make_group (struct config_group *config_group, +const char *name) +{ +struct vkms_configfs_device *vkms_configfs; +struct vkms_configfs_plane *vkms_configfs_plane; + + vkms_configfs =planes_item_to_vkms_configfs_device (&config_group->cg_item); + vkms_configfs_plane =kzalloc (sizeof (*vkms_configfs_plane),GFP_KERNEL ); + +if (!vkms_configfs_plane) +return ERR_PTR (-ENOMEM ); + +mutex_lock (&vkms_configfs->lock); + +if (vkms_configfs->enabled) { +kfree (vkms_configfs_plane); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-EINVAL ); + } + + vkms_configfs_plane->vkms_config_plane =vkms_config_create_plane (vkms_configfs->vkms_config); + +if (list_count_nodes (&vkms_configfs->vkms_config->planes) ==1 ) + vkms_configfs_plane->vkms_config_plane->type =DRM_PLANE_TYPE_PRIMARY ; + +if (!vkms_configfs_plane->vkms_config_plane || +vkms_config_plane_attach_crtc (vkms_configfs_plane->vkms_config_plane, + vkms_configfs->vkms_config_crtc)) { +kfree (vkms_configfs_plane); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-ENOMEM ); + } + + vkms_configfs_plane->vkms_config_plane->name =kzalloc (strlen (name) +1 ,GFP_KERNEL ); +if (!vkms_configfs_plane->vkms_config_plane->name) { +kfree (vkms_configfs_plane->vkms_config_plane); +kfree (vkms_configfs_plane); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-ENOMEM ); + } +strscpy (vkms_configfs_plane->vkms_config_plane->name, name,strlen (name) +1 ); + +config_group_init_type_name (&vkms_configfs_plane->group, name, &subgroup_plane); + + vkms_configfs_plane->vkms_configfs_device = vkms_configfs; +mutex_unlock (&vkms_configfs->lock); + +return &vkms_configfs_plane->group; +} + +static struct configfs_group_operations planes_group_operations = { + .make_group = &planes_make_group, +}; + +static const struct config_item_type planes_item_type = { + .ct_group_ops = &planes_group_operations, + .ct_owner =THIS_MODULE , +}; +static ssize_t device_enable_show (struct config_item *item,char *page) { return sprintf(page, "%d\n",
@@ -92,23 +224,22 @@ static struct config_group *root_make_group(struct config_group *group,return ERR_PTR (-ENOMEM ); } - plane =vkms_config_create_plane (configfs->vkms_config); - crtc =vkms_config_create_crtc (configfs->vkms_config); - encoder =vkms_config_create_encoder (configfs->vkms_config); - -if (!plane || !crtc || !encoder || -vkms_config_plane_attach_crtc (plane, crtc) || -vkms_config_encoder_attach_crtc (encoder, crtc)) { + configfs->vkms_config_crtc =vkms_config_create_crtc (configfs->vkms_config); + configfs->vkms_config_encoder =vkms_config_create_encoder (configfs->vkms_config); +if (!configfs->vkms_config_crtc || !configfs->vkms_config_encoder || +vkms_config_encoder_attach_crtc (configfs->vkms_config_encoder, + configfs->vkms_config_crtc)) {vkms_config_destroy (configfs->vkms_config);kfree (configfs);return ERR_PTR (-ENOMEM ); } - plane->type =DRM_PLANE_TYPE_PRIMARY ; -config_group_init_type_name (&configfs->group, name, &device_item_type); +config_group_init_type_name (&configfs->plane_group,"planes" , &planes_item_type); +configfs_add_default_group (&configfs->plane_group, &configfs->group); +return &configfs->group; }
drivers/gpu/drm/vkms/vkms_configfs.h +20 -0
@@ -19,15 +19,35 @@struct vkms_configfs_device {struct config_group group; +struct config_group plane_group; +struct mutex lock;bool enabled;struct vkms_config *vkms_config; +struct vkms_config_crtc *vkms_config_crtc; +struct vkms_config_encoder *vkms_config_encoder; +}; + +struct vkms_configfs_plane { +struct config_group group; + +struct vkms_configfs_device *vkms_configfs_device; +struct vkms_config_plane *vkms_config_plane; };#define config_item_to_vkms_configfs_device (item) \ container_of(to_config_group((item)), struct vkms_configfs_device, group) +#define planes_item_to_vkms_configfs_device (item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_item_to_vkms_configfs_device (item) \ + planes_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_item_to_vkms_configfs_plane (item) \ + container_of(to_config_group((item)), struct vkms_configfs_plane, group) +/* ConfigFS Support */ int vkms_init_configfs (void );void vkms_unregister_configfs (void );
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 5/14 drm/vkms: Introduce configfs for plane rotation
In reply to Louis ChauvetTo allows the userspace to test many hardware configuration, introduce a new interface to configure the available rotation per planes. VKMS supports any rotation and reflection, so the userspace can choose any combination.
The supported rotations are configured by writing a rotation bitmask to the file supported_rotations and the default rotation is chosen by writing a rotation bitmask to default_rotation.
The current interface is:
/config/vkms
DEVICE_1
┣━ enable
┣━ planes
┃ ┗━ PLANE_1
┃ ┣━ type
┃ ┣━ supported_rotations
┃ ┗━ default_rotation
DEVICE_2
┗━ ditto
--- drivers/gpu/drm/vkms/vkms_configfs.c | 102 +++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +102 -0
@@ -54,10 +54,112 @@ static ssize_t plane_type_store(struct config_item *item,return count; } +static ssize_t plane_supported_rotations_show (struct config_item *item,char *page) +{ +struct vkms_config_plane *plane; +unsigned int plane_type; +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); + +mutex_lock (&vkms_configfs->lock); + plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; + plane_type = plane->supported_rotations; +mutex_unlock (&vkms_configfs->lock); + +return sprintf (page,"%u" , plane_type); +} + +static ssize_t plane_supported_rotations_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_config_plane *plane; +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); +int ret, val =0 ; + + ret =kstrtouint (page,0 , &val); +if (ret) +return ret; + +/* Should be a supported value */ +if (val & ~(DRM_MODE_ROTATE_MASK |DRM_MODE_REFLECT_MASK )) +return -EINVAL ; +/* Should at least provide one rotation */ +if (!(val &DRM_MODE_ROTATE_MASK )) +return -EINVAL ; + +mutex_lock (&vkms_configfs->lock); + + plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; + +/* Ensures that the default rotation is included in supported rotation */ +if (vkms_configfs->enabled || (val & plane->default_rotation) != plane->default_rotation) { +mutex_unlock (&vkms_configfs->lock); +return -EINVAL ; + } + + plane->supported_rotations = val; +mutex_unlock (&vkms_configfs->lock); + +return count; +} + +static ssize_t plane_default_rotation_show (struct config_item *item,char *page) +{ +unsigned int plane_type; +struct vkms_config_plane *plane; +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); + +mutex_lock (&vkms_configfs->lock); + plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; + plane_type = plane->default_rotation; +mutex_unlock (&vkms_configfs->lock); + +return sprintf (page,"%u" , plane_type); +} + +static ssize_t plane_default_rotation_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_config_plane *plane; +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); +int ret, val =0 ; + + ret =kstrtouint (page,10 , &val); +if (ret) +return ret; + +/* Should be a supported value */ +if (val & ~(DRM_MODE_ROTATE_MASK |DRM_MODE_REFLECT_MASK )) +return -EINVAL ; +/* Should at least provide one rotation */ +if ((val &DRM_MODE_ROTATE_MASK ) ==0 ) +return -EINVAL ; +/* Should contains only one rotation */ +if (!is_power_of_2 (val &DRM_MODE_ROTATE_MASK )) +return -EINVAL ; +mutex_lock (&vkms_configfs->lock); + + plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; + +/* Ensures that the default rotation is included in supported rotation */ +if (vkms_configfs->enabled || + (val & plane->supported_rotations) != val) { +mutex_unlock (&vkms_configfs->lock); +return -EINVAL ; + } + plane->default_rotation = val; +mutex_unlock (&vkms_configfs->lock); + +return count; +} +CONFIGFS_ATTR (plane_, type); +CONFIGFS_ATTR (plane_, supported_rotations); +CONFIGFS_ATTR (plane_, default_rotation);static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, + &plane_attr_supported_rotations, + &plane_attr_default_rotation,NULL , };
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 6/14 drm/vkms: Introduce configfs for crtc and encoder
In reply to Louis ChauvetTo allows the userspace to test many hardware configuration, introduce a new interface to configure CRTCs and encoders.
The CRTCs and encoders are created in their own directory. To link the CRTC, symlinks are used in the possible_crtcs folders.
The current interface is:
/config/vkms
DEVICE_1
┣━ enable
┣━ planes
┃ ┗━ PLANE_1
┃ ┣━ type
┃ ┣━ supported_rotations
┃ ┣━ supported_color_encoding
┃ ┣━ supported_color_ranges
┃ ┣━ default_rotation
┃ ┣━ default_color_encoding
┃ ┣━ default_color_range
┃ ┗━ possible_crtcs
┃ ┗━ >> /config/vkms/DEVICE_1/crtcs/CRTC_1
┣━ encoders
┃ ┗━ ENCODER_1
┃ ┗━ possible_crtcs
┃ ┗━ >> /config/vkms/DEVICE_1/crtcs/CRTC_1
┣━ crtcs
┃ ┗━ CRTC_1
DEVICE_2
┗━ ditto
--- drivers/gpu/drm/vkms/vkms_configfs.c | 401 +++++++++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_configfs.h | 54 ++++- 2 files changed, 434 insertions(+), 21 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +382 -19
@@ -5,6 +5,7 @@#include <drm/drm_print.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include <linux/generic-radix-tree.h> #include "vkms_configfs.h" #include "vkms_drv.h"
@@ -185,6 +186,84 @@ static const struct config_item_type subgroup_plane = { .ct_owner = THIS_MODULE, }; +static const struct config_item_type crtc_item_type; +static const struct config_item_type planes_item_type; + +static int possible_crtcs_allow_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_configfs_device *vkms_configfs =plane_possible_crtc_src_item_to_vkms_configfs_device (src); +struct vkms_config_crtc *crtc; + +mutex_lock (&vkms_configfs->lock); + +if (target->ci_type != &crtc_item_type) { +mutex_unlock (&vkms_configfs->lock); +return -EINVAL ; + } + + crtc =crtc_item_to_vkms_configfs_crtc (target)->vkms_config_crtc; +struct vkms_config_plane *plane =plane_possible_crtc_src_item_to_vkms_configfs_plane (src)->vkms_config_plane; + +struct vkms_config_crtc *crtc_entry; +unsigned long idx =0 ; + +xa_for_each (&plane->possible_crtcs, idx, crtc_entry) { +if (crtc_entry == crtc) { +mutex_unlock (&vkms_configfs->lock); +return -EINVAL ; + } + } + +if (vkms_config_plane_attach_crtc (plane, crtc)) +return -EINVAL ; + +mutex_unlock (&vkms_configfs->lock); + +return 0 ; +} + +static void possible_crtcs_drop_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_config_crtc *crtc; +struct vkms_configfs_device *vkms_configfs =plane_possible_crtc_src_item_to_vkms_configfs_device (src); + +mutex_lock (&vkms_configfs->lock); + + crtc =crtc_item_to_vkms_configfs_crtc (target)->vkms_config_crtc; +struct vkms_config_plane *plane =plane_possible_crtc_src_item_to_vkms_configfs_plane (src)->vkms_config_plane; + +struct vkms_config_crtc *crtc_entry; +struct vkms_config_plane *plane_entry; +unsigned long crtc_idx =-1 ; + +xa_for_each (&plane->possible_crtcs, crtc_idx, crtc_entry) { +if (crtc_entry == crtc) +break ; + } +unsigned long plane_idx =-1 ; + +xa_erase (&plane->possible_crtcs, crtc_idx); +xa_for_each (&crtc->possible_planes, plane_idx, plane_entry) { +if (plane_entry == plane) +break ; + } +xa_erase (&crtc->possible_planes, plane_idx); + +mutex_unlock (&vkms_configfs->lock); +} + +static struct configfs_item_operations plane_possible_crtcs_item_ops = { + .allow_link = &possible_crtcs_allow_link, + .drop_link = &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 struct config_group *planes_make_group (struct config_group *config_group,const char *name) {
@@ -209,10 +288,7 @@ static struct config_group *planes_make_group(struct config_group *config_group,if (list_count_nodes (&vkms_configfs->vkms_config->planes) ==1 ) vkms_configfs_plane->vkms_config_plane->type =DRM_PLANE_TYPE_PRIMARY ; - -if (!vkms_configfs_plane->vkms_config_plane || -vkms_config_plane_attach_crtc (vkms_configfs_plane->vkms_config_plane, - vkms_configfs->vkms_config_crtc)) { +if (!vkms_configfs_plane->vkms_config_plane) {kfree (vkms_configfs_plane);mutex_unlock (&vkms_configfs->lock);return ERR_PTR (-ENOMEM );
@@ -229,7 +305,12 @@ static struct config_group *planes_make_group(struct config_group *config_group,config_group_init_type_name (&vkms_configfs_plane->group, name, &subgroup_plane); +config_group_init_type_name (&vkms_configfs_plane->possible_crtc_group,"possible_crtcs" , + &plane_possible_crtcs_group_type); +configfs_add_default_group (&vkms_configfs_plane->possible_crtc_group, + &vkms_configfs_plane->group); vkms_configfs_plane->vkms_configfs_device = vkms_configfs; +mutex_unlock (&vkms_configfs->lock);return &vkms_configfs_plane->group;
@@ -244,6 +325,283 @@ static const struct config_item_type planes_item_type = { .ct_owner = THIS_MODULE, }; +static void crtc_release (struct config_item *item) +{ +struct vkms_configfs_crtc *vkms_configfs_crtc =crtc_item_to_vkms_configfs_crtc (item); + +mutex_lock (&vkms_configfs_crtc->vkms_configfs_device->lock); +vkms_config_delete_crtc (vkms_configfs_crtc->vkms_config_crtc, + vkms_configfs_crtc->vkms_configfs_device->vkms_config); +mutex_unlock (&vkms_configfs_crtc->vkms_configfs_device->lock); + +kfree (vkms_configfs_crtc); +} + +static struct configfs_item_operations crtc_item_operations = { + .release = crtc_release, +}; + +static const struct config_item_type crtc_item_type = { + .ct_owner =THIS_MODULE , + .ct_item_ops = &crtc_item_operations, +}; + +static struct config_group *crtcs_make_group (struct config_group *config_group, +const char *name) +{ +struct config_item *root_item = config_group->cg_item.ci_parent; +struct vkms_configfs_device *vkms_configfs =config_item_to_vkms_configfs_device (root_item); +struct vkms_configfs_crtc *vkms_configfs_crtc; + + vkms_configfs_crtc =kzalloc (sizeof (*vkms_configfs_crtc),GFP_KERNEL ); + +if (!vkms_configfs_crtc) +return ERR_PTR (-ENOMEM ); + +mutex_lock (&vkms_configfs->lock); + vkms_configfs_crtc->vkms_configfs_device = vkms_configfs; + +if (vkms_configfs->enabled) { +kfree (vkms_configfs_crtc); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-EINVAL ); + } + + vkms_configfs_crtc->vkms_config_crtc =vkms_config_create_crtc (vkms_configfs->vkms_config); + +if (!vkms_configfs_crtc->vkms_config_crtc) { +kfree (vkms_configfs_crtc); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-ENOMEM ); + } + + vkms_configfs_crtc->vkms_config_crtc->name =kzalloc (strlen (name) +1 ,GFP_KERNEL ); +if (!vkms_configfs_crtc->vkms_config_crtc->name) { +kfree (vkms_configfs_crtc->vkms_config_crtc); +kfree (vkms_configfs_crtc); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-ENOMEM ); + } + + vkms_configfs_crtc->vkms_configfs_device = vkms_configfs; + +strscpy (vkms_configfs_crtc->vkms_config_crtc->name, name,strlen (name) +1 ); +config_group_init_type_name (&vkms_configfs_crtc->group, name, + &crtc_item_type); + +mutex_unlock (&vkms_configfs->lock); + +return &vkms_configfs_crtc->group; +} + +static struct configfs_group_operations crtcs_group_operations = { + .make_group = &crtcs_make_group, +}; + +static const struct config_item_type crtcs_item_type = { + .ct_group_ops = &crtcs_group_operations, + .ct_owner =THIS_MODULE , +}; + +static int encoder_possible_crtcs_allow_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_config_crtc *crtc; +struct vkms_configfs_device *vkms_configfs =encoder_possible_crtc_src_item_to_vkms_configfs_device (src); + +mutex_lock (&vkms_configfs->lock); + +if (target->ci_type != &crtc_item_type) { +DRM_ERROR ("Unable to link non-CRTCs.\n" ); +mutex_unlock (&vkms_configfs->lock); +return -EINVAL ; + } + + crtc =crtc_item_to_vkms_configfs_crtc (target)->vkms_config_crtc; +struct vkms_config_encoder *encoder =encoder_possible_crtc_src_item_to_vkms_configfs_encoder (src)->vkms_config_encoder; + +struct vkms_config_crtc *crtc_entry; +unsigned long idx =0 ; + +xa_for_each (&encoder->possible_crtcs, idx, crtc_entry) { +if (crtc_entry == crtc) { +pr_err ("Tried to add two symlinks to the same CRTC from the same object.\n" ); +mutex_unlock (&vkms_configfs->lock); +return -EINVAL ; + } + } + +if (vkms_config_encoder_attach_crtc (encoder, crtc)) +return -EINVAL ; + +mutex_unlock (&vkms_configfs->lock); + +return 0 ; +} + +static void encoder_possible_crtcs_drop_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_config_crtc *crtc; +struct vkms_configfs_device *vkms_configfs =encoder_possible_crtc_src_item_to_vkms_configfs_device (src); + +mutex_lock (&vkms_configfs->lock); + + crtc =crtc_item_to_vkms_configfs_crtc (target)->vkms_config_crtc; +struct vkms_config_encoder *encoder =encoder_possible_crtc_src_item_to_vkms_configfs_encoder (src)->vkms_config_encoder; + +struct vkms_config_encoder *encoder_entry; +struct vkms_config_crtc *crtc_entry; +unsigned long encoder_idx =-1 ; +unsigned long crtc_idx =-1 ; + +xa_for_each (&encoder->possible_crtcs, crtc_idx, crtc_entry) { +if (crtc_entry == crtc) +break ; + } +xa_erase (&encoder->possible_crtcs, crtc_idx); +xa_for_each (&crtc->possible_encoders, encoder_idx, encoder_entry) { +if (encoder_entry == encoder) +break ; + } +xa_erase (&crtc->possible_encoders, encoder_idx); + +mutex_unlock (&vkms_configfs->lock); +} + +static struct configfs_item_operations encoder_possible_crtcs_item_operations = { + .allow_link = &encoder_possible_crtcs_allow_link, + .drop_link = &encoder_possible_crtcs_drop_link, +}; + +static struct config_item_type encoder_possible_crtcs_item_type = { + .ct_item_ops = &encoder_possible_crtcs_item_operations, + .ct_owner =THIS_MODULE , +}; + +static void encoder_release (struct config_item *item) +{ +struct vkms_configfs_encoder *vkms_configfs_encoder =encoder_item_to_vkms_configfs_encoder (item); + +mutex_lock (&vkms_configfs_encoder->vkms_configfs_device->lock); +vkms_config_delete_encoder (vkms_configfs_encoder->vkms_config_encoder, + vkms_configfs_encoder->vkms_configfs_device->vkms_config); +mutex_unlock (&vkms_configfs_encoder->vkms_configfs_device->lock); + +kfree (vkms_configfs_encoder); +} + +static struct configfs_item_operations encoder_item_operations = { + .release = encoder_release, +}; + +static const struct config_item_type encoder_item_type = { + .ct_item_ops = &encoder_item_operations, + .ct_owner =THIS_MODULE , +}; + +static struct config_group *encoder_make_group (struct config_group *config_group, +const char *name) +{ +struct vkms_configfs_device *vkms_configfs =encoder_item_to_vkms_configfs_device (&config_group->cg_item); +struct vkms_configfs_encoder *vkms_configfs_encoder; + + vkms_configfs_encoder =kzalloc (sizeof (*vkms_configfs_encoder),GFP_KERNEL ); + +if (!vkms_configfs_encoder) +return ERR_PTR (-ENOMEM ); + +mutex_lock (&vkms_configfs->lock); + +if (vkms_configfs->enabled) { +kfree (vkms_configfs_encoder); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-EINVAL ); + } + + vkms_configfs_encoder->vkms_config_encoder =vkms_config_create_encoder (vkms_configfs->vkms_config); + +if (!vkms_configfs_encoder->vkms_config_encoder) { +kfree (vkms_configfs_encoder); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-ENOMEM ); + } + + vkms_configfs_encoder->vkms_config_encoder->name =kzalloc (strlen (name) +1 ,GFP_KERNEL ); +if (!vkms_configfs_encoder->vkms_config_encoder->name) { +kfree (vkms_configfs_encoder->vkms_config_encoder); +kfree (vkms_configfs_encoder); +mutex_unlock (&vkms_configfs->lock); +return ERR_PTR (-ENOMEM ); + } + +strscpy (vkms_configfs_encoder->vkms_config_encoder->name, name,strlen (name) +1 ); +config_group_init_type_name (&vkms_configfs_encoder->group, name, + &encoder_item_type); + +config_group_init_type_name (&vkms_configfs_encoder->possible_crtc_group,"possible_crtcs" , + &encoder_possible_crtcs_item_type); +configfs_add_default_group (&vkms_configfs_encoder->possible_crtc_group, + &vkms_configfs_encoder->group); + vkms_configfs_encoder->vkms_configfs_device = vkms_configfs; + +mutex_unlock (&vkms_configfs->lock); + +return &vkms_configfs_encoder->group; +} + +static struct configfs_group_operations encoder_group_operations = { + .make_group = &encoder_make_group, +}; + +static const struct config_item_type encoders_item_type = { + .ct_group_ops = &encoder_group_operations, + .ct_owner =THIS_MODULE , +}; + +/** +* configfs_lock_dependencies() - In order to forbid the userspace to delete items when the +* device is enabled, mark all configfs items as dependent +* +* @vkms_configfs_device: Device to lock +*/ +static void configfs_lock_dependencies (struct vkms_configfs_device *vkms_configfs_device) +{ +/* Lock the group itself */ +configfs_depend_item_unlocked (vkms_configfs_device->group.cg_subsys, + &vkms_configfs_device->group.cg_item); +/* Lock the planes elements */ +struct config_item *item; + +list_for_each_entry (item, &vkms_configfs_device->plane_group.cg_children, ci_entry) { +configfs_depend_item_unlocked (vkms_configfs_device->plane_group.cg_subsys, + item); + } +list_for_each_entry (item, &vkms_configfs_device->crtc_group.cg_children, ci_entry) { +configfs_depend_item_unlocked (vkms_configfs_device->crtc_group.cg_subsys, + item); + } +} + +/** +* configfs_unlock_dependencies() - Once the device is disable, its configuration can be modified. +* +* @vkms_configfs_device: Device to unlock +*/ +static void configfs_unlock_dependencies (struct vkms_configfs_device *vkms_configfs_device) +{ +struct config_item *item; + +configfs_undepend_item_unlocked (&vkms_configfs_device->group.cg_item); + +list_for_each_entry (item, &vkms_configfs_device->plane_group.cg_children, ci_entry) { +configfs_undepend_item_unlocked (item); + } +list_for_each_entry (item, &vkms_configfs_device->crtc_group.cg_children, ci_entry) { +configfs_undepend_item_unlocked (item); + } +} +static ssize_t device_enable_show (struct config_item *item,char *page) { return sprintf(page, "%d\n",
@@ -264,13 +622,25 @@ static ssize_t device_enable_store(struct config_item *item,return -EINVAL ;mutex_lock (&vkms_configfs_device->lock); +if (vkms_configfs_device->enabled == value) { +mutex_unlock (&vkms_configfs_device->lock); +return (ssize_t )count; + } + +if (value && !vkms_config_is_valid (vkms_configfs_device->vkms_config)) { +mutex_unlock (&vkms_configfs_device->lock); +return -EINVAL ; + } vkms_configfs_device->enabled = value; -if (value) +if (value) { +configfs_lock_dependencies (vkms_configfs_device);vkms_create (vkms_configfs_device->vkms_config); -else + }else { +configfs_unlock_dependencies (vkms_configfs_device);vkms_destroy (vkms_configfs_device->vkms_config); + }mutex_unlock (&vkms_configfs_device->lock);
@@ -309,9 +679,6 @@ static const struct config_item_type device_item_type = {static struct config_group *root_make_group (struct config_group *group,const char *name) { -struct vkms_config_plane *plane; -struct vkms_config_crtc *crtc; -struct vkms_config_encoder *encoder;struct vkms_configfs_device *configfs =kzalloc (sizeof (*configfs),GFP_KERNEL );if (!configfs)
@@ -326,22 +693,18 @@ static struct config_group *root_make_group(struct config_group *group,return ERR_PTR (-ENOMEM ); } - configfs->vkms_config_crtc =vkms_config_create_crtc (configfs->vkms_config); - configfs->vkms_config_encoder =vkms_config_create_encoder (configfs->vkms_config); -if (!configfs->vkms_config_crtc || !configfs->vkms_config_encoder || -vkms_config_encoder_attach_crtc (configfs->vkms_config_encoder, - configfs->vkms_config_crtc)) { -vkms_config_destroy (configfs->vkms_config); -kfree (configfs); -return ERR_PTR (-ENOMEM ); - } -config_group_init_type_name (&configfs->group, name, &device_item_type);config_group_init_type_name (&configfs->plane_group,"planes" , &planes_item_type);configfs_add_default_group (&configfs->plane_group, &configfs->group); +config_group_init_type_name (&configfs->crtc_group,"crtcs" , &crtcs_item_type); +configfs_add_default_group (&configfs->crtc_group, &configfs->group); + +config_group_init_type_name (&configfs->encoder_group,"encoders" , &encoders_item_type); +configfs_add_default_group (&configfs->encoder_group, &configfs->group); +return &configfs->group; }
drivers/gpu/drm/vkms/vkms_configfs.h +52 -2
86 lines not on this page · raw message
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 7/14 drm/vkms: Introduce configfs for connectors
In reply to Louis ChauvetTo allows the userspace to test many hardware configuration, introduce a new interface to create and configure connectors.
The connectors are created by creating a directory in the connectors directory.
Connectors and encoders can be linked by creating a symlink in the possible_encoders directory.
The current interface is:
/config/vkms
DEVICE_1
┣━ enable
┣━ planes
┃ ┗━ [...]
┣━ connectors
┃ ┗━ CONNECTOR_1
┃ ┗━ possible_encoders
┃ ┗━ >> DEVICE_1/encoders/ENCODER_1
┗━ encoders
┗━ ENCODER_1
--- drivers/gpu/drm/vkms/vkms_config.c | 13 ++++ drivers/gpu/drm/vkms/vkms_config.h | 3 + drivers/gpu/drm/vkms/vkms_configfs.c | 138 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_configfs.h | 23 ++++++ 4 files changed, 177 insertions(+)
drivers/gpu/drm/vkms/vkms_config.c +13 -0
@@ -479,6 +479,19 @@ vkms_config_connector_attach_encoder(struct vkms_config_connector *vkms_config_creturn ret; } +void vkms_config_connector_detach_encoder (struct vkms_config_connector *vkms_config_connector, +struct vkms_config_encoder *vkms_config_encoder) +{ +struct vkms_config_encoder *encoder_entry; +unsigned long encoder_idx; + +xa_for_each (&vkms_config_connector->possible_encoders, encoder_idx, encoder_entry) { +if (encoder_entry == vkms_config_encoder) +break ; + } +xa_erase (&vkms_config_connector->possible_encoders, encoder_idx); +} +bool vkms_config_is_valid (struct vkms_config *config) {struct vkms_config_plane *config_plane;
drivers/gpu/drm/vkms/vkms_config.h +3 -0
@@ -189,6 +189,9 @@ int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *vkmint __must_check vkms_config_connector_attach_encoder (struct vkms_config_connector *vkms_config_connector,struct vkms_config_encoder *vkms_config_encoder); +void vkms_config_connector_detach_encoder (struct vkms_config_connector *vkms_config_connector, +struct vkms_config_encoder *vkms_config_encoder); +/** * vkms_config_delete_plane() - Remove a plane configuration and frees its memory *
drivers/gpu/drm/vkms/vkms_configfs.c +138 -0
156 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_configfs.h +23 -0
@@ -22,6 +22,7 @@ struct vkms_configfs_device {struct config_group plane_group;struct config_group crtc_group;struct config_group encoder_group; +struct config_group connector_group;struct mutex lock;bool enabled;
@@ -53,6 +54,14 @@ struct vkms_configfs_encoder {struct vkms_config_encoder *vkms_config_encoder; }; +struct vkms_configfs_connector { +struct config_group group; + +struct config_group possible_encoder_group; +struct vkms_configfs_device *vkms_configfs_device; +struct vkms_config_connector *vkms_config_connector; +}; +#define config_item_to_vkms_configfs_device (item) \ container_of(to_config_group((item)), struct vkms_configfs_device, group)
@@ -68,6 +77,9 @@ struct vkms_configfs_encoder {#define encoder_item_to_vkms_configfs_encoder (item) \ container_of(to_config_group((item)), struct vkms_configfs_encoder, group) +#define connector_item_to_vkms_configfs_connector (item) \ + container_of(to_config_group((item)), struct vkms_configfs_connector, group) +#define plane_item_to_vkms_configfs_device (item) \ planes_item_to_vkms_configfs_device((item)->ci_parent)
@@ -89,14 +101,25 @@ struct vkms_configfs_encoder {#define encoder_item_to_vkms_configfs_device (item) \ config_item_to_vkms_configfs_device((item)->ci_parent) +#define connector_item_to_vkms_configfs_device (item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) +#define encoder_child_item_to_vkms_configfs_device (item) \ encoder_item_to_vkms_configfs_device((item)->ci_parent)#define encoder_possible_crtc_src_item_to_vkms_configfs_device (item) \ encoder_child_item_to_vkms_configfs_device((item)->ci_parent) +#define connector_child_item_to_vkms_configfs_device (item) \ + connector_item_to_vkms_configfs_device((item)->ci_parent) + +#define connector_possible_encoder_src_item_to_vkms_configfs_device (item) \ + connector_child_item_to_vkms_configfs_device((item)->ci_parent) +#define encoder_possible_crtc_src_item_to_vkms_configfs_encoder (item) \ encoder_item_to_vkms_configfs_encoder((item)->ci_parent) +#define connector_possible_encoder_src_item_to_vkms_configfs_connector (item) \ + connector_item_to_vkms_configfs_connector((item)->ci_parent)/* ConfigFS Support */ int vkms_init_configfs (void );
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 8/14 drm/vkms: Introduce configfs for connector type
In reply to Louis ChauvetTo allows the userspace to test many hardware configuration, introduce a new interface to change a connector type.
The type of a connector can be changed by editing the file type and by writing the connector type number.
The current interface is:
/config/vkms
DEVICE_1
┣━ enable
┣━ planes
┃ ┗━ [...]
┣━ connectors
┃ ┗━ CONNECTOR_1
┃ ┣━ possible_encoders
┃ ┗━ type
┗━ encoders
┗━ [...]
--- drivers/gpu/drm/vkms/vkms_configfs.c | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +71 -0
@@ -633,12 +633,83 @@ static void connector_release(struct config_item *item)kfree (vkms_configfs_connector); } +static ssize_t connector_type_show (struct config_item *item,char *page) +{ +struct vkms_config_connector *connector; +int connector_type; +struct vkms_configfs_device *vkms_configfs =connector_child_item_to_vkms_configfs_device (item); + +mutex_lock (&vkms_configfs->lock); + connector =connector_item_to_vkms_configfs_connector (item)->vkms_config_connector; + connector_type = connector->type; +mutex_unlock (&vkms_configfs->lock); + +return sprintf (page,"%u" , connector_type); +} + +static ssize_t connector_type_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_config_connector *connector; +int val =DRM_MODE_CONNECTOR_VIRTUAL ; +struct vkms_configfs_device *vkms_configfs =connector_child_item_to_vkms_configfs_device (item); +int ret; + + ret =kstrtouint (page,10 , &val); +if (ret) +return ret; + +switch (val) { +case DRM_MODE_CONNECTOR_Unknown: +case DRM_MODE_CONNECTOR_VGA : +case DRM_MODE_CONNECTOR_DVII : +case DRM_MODE_CONNECTOR_DVID : +case DRM_MODE_CONNECTOR_DVIA : +case DRM_MODE_CONNECTOR_Composite: +case DRM_MODE_CONNECTOR_SVIDEO : +case DRM_MODE_CONNECTOR_LVDS : +case DRM_MODE_CONNECTOR_Component: +case DRM_MODE_CONNECTOR_9PinDIN: +case DRM_MODE_CONNECTOR_DisplayPort: +case DRM_MODE_CONNECTOR_HDMIA : +case DRM_MODE_CONNECTOR_HDMIB : +case DRM_MODE_CONNECTOR_TV : +case DRM_MODE_CONNECTOR_eDP: +case DRM_MODE_CONNECTOR_VIRTUAL : +case DRM_MODE_CONNECTOR_DSI : +case DRM_MODE_CONNECTOR_DPI : +case DRM_MODE_CONNECTOR_SPI : +case DRM_MODE_CONNECTOR_USB : +break ; +default : +return -EINVAL ; + } + + scoped_guard(mutex, &vkms_configfs->lock) { +if (vkms_configfs->enabled) +return -EINVAL ; + + connector =connector_item_to_vkms_configfs_connector (item)->vkms_config_connector; + connector->type = val; + } + +return count; +} + +CONFIGFS_ATTR (connector_, type); + +static struct configfs_attribute *connector_attrs[] = { + &connector_attr_type, +NULL , +}; +static struct configfs_item_operations connector_item_operations = { .release = connector_release, };static const struct config_item_type connector_item_type = { .ct_item_ops = &connector_item_operations, + .ct_attrs = connector_attrs, .ct_owner =THIS_MODULE , };
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 9/14 drm/vkms: Introduce configfs for plane format
In reply to Louis ChauvetTo allows the userspace to test many hardware configuration, introduce a new interface to configure the available formats per planes. VKMS supports many formats, so the userspace can choose any combination of them.
The supported formats are configured by writing in the file supported_formats:
- +* - Add all available formats
- -* - Remove all formats
- +<fourcc> - Add the format (for example +AR24 to add ARGB8888 format)
- -<FOURCC> - Remove the format
The current interface is:
/config/vkms
DEVICE_1
┣━ enable
┗━ planes
┗━ PLANE_1
┗━ supported_formats
--- drivers/gpu/drm/vkms/vkms_configfs.c | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +75 -0
@@ -153,14 +153,89 @@ static ssize_t plane_default_rotation_store(struct config_item *item,return count; } +static ssize_t plane_supported_formats_show (struct config_item *item,char *page) +{ +struct vkms_config_plane *plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); + + page[0 ] ='\0' ; + + scoped_guard(mutex, &vkms_configfs->lock) + { +for (int i =0 ; i < plane->supported_formats_count; i++) { +char tmp[6 ] = {0 }; +const ssize_t ret =snprintf (tmp,ARRAY_SIZE (tmp),"%.*s\n" , + (int )sizeof (plane->supported_formats[i]), + (char *)&plane->supported_formats[i]); +if (ret <0 ) +return ret; +/* Limitation of ConfigFS attributes, an attribute can't be bigger than PAGE_SIZE */ +if (ret +strlen (page) >PAGE_SIZE -1 ) +return -ENOMEM ; +strncat (page, tmp,ARRAY_SIZE (tmp)); + } + } + +return strlen (page); +} + +static ssize_t plane_supported_formats_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_config_plane *plane =plane_item_to_vkms_configfs_plane (item)->vkms_config_plane; +struct vkms_configfs_device *vkms_configfs =plane_item_to_vkms_configfs_device (item); +int ret =0 ; +int ptr =0 ; + + scoped_guard(mutex, &vkms_configfs->lock) + { +while (ptr < count) { +if (page[ptr] =='+' ) { +char tmp[4 ] = {' ' ,' ' ,' ' ,' ' }; + +memcpy (tmp, &page[ptr +1 ],min (sizeof (tmp), count - (ptr +1 ))); +if (tmp[0 ] =='*' ) { + ret =vkms_config_plane_add_all_formats (plane); +if (ret) +return ret; + ptr +=1 ; + }else { + ret =vkms_config_plane_add_format (plane, *(int *)tmp); +if (ret) +return ret; + ptr +=4 ; + } + }else if (page[ptr] =='-' ) { +char tmp[4 ] = {' ' ,' ' ,' ' ,' ' }; + +memcpy (tmp, &page[ptr +1 ],min (sizeof (tmp), count - (ptr +1 ))); +if (tmp[0 ] =='*' ) { +vkms_config_plane_remove_all_formats (plane); + ptr +=1 ; + }else { +vkms_config_plane_remove_format (plane, *(int *)tmp); + + ptr +=4 ; + } + } +/* Skip anything that is not a + or a - */ + ptr +=1 ; + } + } + +return count; +} +CONFIGFS_ATTR (plane_, type);CONFIGFS_ATTR (plane_, supported_rotations);CONFIGFS_ATTR (plane_, default_rotation); +CONFIGFS_ATTR (plane_, supported_formats);static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, &plane_attr_supported_rotations, &plane_attr_default_rotation, + &plane_attr_supported_formats,NULL , };
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 10/14 drm/vkms: Introduce configfs for device name
In reply to Louis ChauvetTo allows the userspace to identify the device once it is enabled, create a file to fetch it.
This file can only be read once the device is enabled, and will return the device name, which can later be used to use it.
--- drivers/gpu/drm/vkms/vkms_configfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +16 -0
@@ -927,10 +927,26 @@ static ssize_t device_enable_store(struct config_item *item,return (ssize_t )count; } +static ssize_t device_device_name_show (struct config_item *item,char *page) +{ +struct vkms_configfs_device *configfs_device =config_item_to_vkms_configfs_device (item); + + scoped_guard(mutex, &configfs_device->lock) + { +if (configfs_device->enabled) +return sprintf (page,"%s\n" , +dev_name (configfs_device->vkms_config->dev->drm.dev)); +return -EINVAL ; + } +return -EINVAL ; +} +CONFIGFS_ATTR (device_, enable); +CONFIGFS_ATTR_RO (device_, device_name);static struct configfs_attribute *device_attrs[] = { &device_attr_enable, + &device_attr_device_name,NULL , };
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 11/14 drm/vkms: Introduce configfs for connector status
In reply to Louis ChauvetAs a connector can be connected and disconnected once a device is created, create a file to allow changing this status.
--- drivers/gpu/drm/vkms/vkms_configfs.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +45 -0
@@ -771,10 +771,55 @@ static ssize_t connector_type_store(struct config_item *item,return count; } +static ssize_t connector_status_show (struct config_item *item,char *page) +{ +struct vkms_config_connector *connector; +enum drm_connector_status status; +struct vkms_configfs_device *vkms_configfs =connector_child_item_to_vkms_configfs_device (item); + +mutex_lock (&vkms_configfs->lock); + connector =connector_item_to_vkms_configfs_connector (item)->vkms_config_connector; + status = connector->status; +mutex_unlock (&vkms_configfs->lock); + +return sprintf (page,"%u" , status); +} + +static ssize_t connector_status_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_config_connector *connector; +enum drm_connector_status status = connector_status_unknown; +struct vkms_configfs_device *vkms_configfs =connector_child_item_to_vkms_configfs_device (item); +int ret; + + ret =kstrtouint (page,10 , &status); +if (ret) +return ret; + +switch (status) { +case connector_status_unknown: +case connector_status_connected: +case connector_status_disconnected: +break ; +default : +return -EINVAL ; + } + + scoped_guard(mutex, &vkms_configfs->lock) { + connector =connector_item_to_vkms_configfs_connector (item)->vkms_config_connector; +vkms_config_connector_update_status (connector, status); + } + +return count; +} +CONFIGFS_ATTR (connector_, type); +CONFIGFS_ATTR (connector_, status);static struct configfs_attribute *connector_attrs[] = { &connector_attr_type, + &connector_attr_status,NULL , };
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 12/14 drm/vkms: Introduce configfs for connector id
In reply to Louis ChauvetA connector can't be identified by a name, so add a configfs file to retrieve its id.
--- drivers/gpu/drm/vkms/vkms_configfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +19 -0
@@ -814,12 +814,31 @@ static ssize_t connector_status_store(struct config_item *item,return count; } +static ssize_t connector_id_show (struct config_item *item,char *page) +{ +struct vkms_configfs_device *vkms_configfs = +connector_child_item_to_vkms_configfs_device (item); +struct vkms_config_connector *connector; + + scoped_guard(mutex, &vkms_configfs->lock) + { + connector =connector_item_to_vkms_configfs_connector (item)->vkms_config_connector; +if (vkms_configfs->enabled) +return sprintf (page,"%d\n" , + connector->connector->base.id); +return -EINVAL ; + } +return -EINVAL ; +} +CONFIGFS_ATTR (connector_, type);CONFIGFS_ATTR (connector_, status); +CONFIGFS_ATTR_RO (connector_, id);static struct configfs_attribute *connector_attrs[] = { &connector_attr_type, &connector_attr_status, + &connector_attr_id,NULL , };
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 13/14 drm/vkms: Introduce configfs for connector EDID
In reply to Louis ChauvetDue to limitation of ConfigFS, the max len of EDID is PAGE_SIZE (4kB on x86), it should be sufficient for many tests. One possible evolution is using a ConfigFS blob to allow bigger EDID.
The EDID can be changed at any time. As for physical display, you need to trigger an HPD event to refresh the modes.
--- drivers/gpu/drm/vkms/vkms_configfs.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +33 -0
@@ -814,6 +814,37 @@ static ssize_t connector_status_store(struct config_item *item,return count; } +static ssize_t connector_edid_show (struct config_item *item,char *page) +{ +struct vkms_config_connector *connector; +struct vkms_configfs_device *vkms_configfs =connector_child_item_to_vkms_configfs_device (item); + + scoped_guard(mutex, &vkms_configfs->lock) + { + connector =connector_item_to_vkms_configfs_connector (item)->vkms_config_connector; +memcpy (page, &connector->edid_blob, connector->edid_blob_len); +return connector->edid_blob_len; + } + +return -EINVAL ; +} + +static ssize_t connector_edid_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_configfs_device *vkms_configfs =connector_child_item_to_vkms_configfs_device (item); + + scoped_guard(mutex, &vkms_configfs->lock) + { +struct vkms_config_connector *connector = +connector_item_to_vkms_configfs_connector (item)->vkms_config_connector; +memcpy (&connector->edid_blob, page, count); + connector->edid_blob_len = count; + } + +return count; +} +static ssize_t connector_id_show (struct config_item *item,char *page) { struct vkms_configfs_device *vkms_configfs =
@@ -833,12 +864,14 @@ static ssize_t connector_id_show(struct config_item *item, char *page)CONFIGFS_ATTR (connector_, type);CONFIGFS_ATTR (connector_, status); +CONFIGFS_ATTR (connector_, edid);CONFIGFS_ATTR_RO (connector_, id);static struct configfs_attribute *connector_attrs[] = { &connector_attr_type, &connector_attr_status, &connector_attr_id, + &connector_attr_edid,NULL , };
Signature · 1 line
2.47.1
Louis Chauvet
maintainerRFC PATCH v3 14/14 drm/vkms: Introduce configfs for encoder type
In reply to Louis ChauvetIn order to support multiple configuration, add the possibility to change the encoder type.
--- drivers/gpu/drm/vkms/vkms_configfs.c | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
drivers/gpu/drm/vkms/vkms_configfs.c +57 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0+ +#include "drm/drm_mode.h" #include <linux/configfs.h> #include <linux/mutex.h> #include <drm/drm_print.h>
@@ -544,6 +545,61 @@ static void encoder_possible_crtcs_drop_link(struct config_item *src,mutex_unlock (&vkms_configfs->lock); } +static ssize_t encoder_type_show (struct config_item *item,char *page) +{ +struct vkms_config_encoder *encoder; +char encoder_type =DRM_MODE_ENCODER_NONE ; +struct vkms_configfs_device *vkms_configfs =encoder_item_to_vkms_configfs_device (item); + + scoped_guard(mutex, &vkms_configfs->lock) + { + encoder =encoder_item_to_vkms_configfs_encoder (item)->vkms_config_encoder; + encoder_type = encoder->type; + } + +return sprintf (page,"%u" , encoder_type); +} + +static ssize_t encoder_type_store (struct config_item *item, +const char *page,size_t count) +{ +struct vkms_configfs_device *vkms_configfs =encoder_item_to_vkms_configfs_device (item); +int val =DRM_MODE_ENCODER_VIRTUAL ; +struct vkms_config_encoder *encoder; +int ret; + + ret =kstrtouint (page,10 , &val); +if (ret) +return ret; + +if (val !=DRM_MODE_ENCODER_DAC && + val !=DRM_MODE_ENCODER_DPI && + val !=DRM_MODE_ENCODER_DSI && + val !=DRM_MODE_ENCODER_LVDS && + val !=DRM_MODE_ENCODER_NONE && + val !=DRM_MODE_ENCODER_TMDS && + val !=DRM_MODE_ENCODER_TVDAC && + val !=DRM_MODE_ENCODER_VIRTUAL ) +return -EINVAL ; + + scoped_guard(mutex, &vkms_configfs->lock) { +if (vkms_configfs->enabled) +return -EINVAL ; + + encoder =encoder_item_to_vkms_configfs_encoder (item)->vkms_config_encoder; + encoder->type = val; + } + +return count; +} + +CONFIGFS_ATTR (encoder_, type); + +static struct configfs_attribute *encoder_attrs[] = { + &encoder_attr_type, +NULL , +}; +static struct configfs_item_operations encoder_possible_crtcs_item_operations = { .allow_link = &encoder_possible_crtcs_allow_link, .drop_link = &encoder_possible_crtcs_drop_link,
@@ -572,6 +628,7 @@ static struct configfs_item_operations encoder_item_operations = {static const struct config_item_type encoder_item_type = { .ct_item_ops = &encoder_item_operations, + .ct_attrs = encoder_attrs, .ct_owner =THIS_MODULE , };
Signature · 1 line
2.47.1