[PATCH v4 06/16] drm/vkms: Allow to configure CRTC writeback support via configfs

José Expósito posted 16 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH v4 06/16] drm/vkms: Allow to configure CRTC writeback support via configfs
Posted by José Expósito 10 months, 1 week ago
From: Louis Chauvet <louis.chauvet@bootlin.com>

When a CRTC is created, add a `writeback` file to allow to enable or
disable writeback connector support

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
Co-developed-by: José Expósito <jose.exposito89@gmail.com>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 Documentation/gpu/vkms.rst           |  4 +++
 drivers/gpu/drm/vkms/vkms_configfs.c | 42 ++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
index e0699603ef53..abe7a0f5a4ab 100644
--- a/Documentation/gpu/vkms.rst
+++ b/Documentation/gpu/vkms.rst
@@ -94,6 +94,10 @@ Continue by creating one or more CRTCs::
 
   sudo mkdir /config/vkms/my-vkms/crtcs/crtc0
 
+CRTCs have 1 configurable attribute:
+
+- writeback: Enable or disable writeback connector support by writing 1 or 0
+
 Once you are done configuring the VKMS instance, enable it::
 
   echo "1" | sudo tee /config/vkms/my-vkms/enabled
diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c
index 62a82366791d..e9f445043268 100644
--- a/drivers/gpu/drm/vkms/vkms_configfs.c
+++ b/drivers/gpu/drm/vkms/vkms_configfs.c
@@ -74,6 +74,47 @@ struct vkms_configfs_crtc {
 #define crtc_item_to_vkms_configfs_crtc(item) \
 	container_of(to_config_group((item)), struct vkms_configfs_crtc, group)
 
+static ssize_t crtc_writeback_show(struct config_item *item, char *page)
+{
+	struct vkms_configfs_crtc *crtc;
+	bool writeback;
+
+	crtc = crtc_item_to_vkms_configfs_crtc(item);
+
+	scoped_guard(mutex, &crtc->dev->lock)
+		writeback = vkms_config_crtc_get_writeback(crtc->config);
+
+	return sprintf(page, "%d\n", writeback);
+}
+
+static ssize_t crtc_writeback_store(struct config_item *item, const char *page,
+				    size_t count)
+{
+	struct vkms_configfs_crtc *crtc;
+	bool writeback;
+
+	crtc = crtc_item_to_vkms_configfs_crtc(item);
+
+	if (kstrtobool(page, &writeback))
+		return -EINVAL;
+
+	scoped_guard(mutex, &crtc->dev->lock) {
+		if (crtc->dev->enabled)
+			return -EBUSY;
+
+		vkms_config_crtc_set_writeback(crtc->config, writeback);
+	}
+
+	return (ssize_t)count;
+}
+
+CONFIGFS_ATTR(crtc_, writeback);
+
+static struct configfs_attribute *crtc_item_attrs[] = {
+	&crtc_attr_writeback,
+	NULL,
+};
+
 static void crtc_release(struct config_item *item)
 {
 	struct vkms_configfs_crtc *crtc;
@@ -93,6 +134,7 @@ static struct configfs_item_operations crtc_item_operations = {
 };
 
 static const struct config_item_type crtc_item_type = {
+	.ct_attrs	= crtc_item_attrs,
 	.ct_item_ops	= &crtc_item_operations,
 	.ct_owner	= THIS_MODULE,
 };
-- 
2.48.1

Re: [PATCH v4 06/16] drm/vkms: Allow to configure CRTC writeback support via configfs
Posted by Louis Chauvet 9 months, 4 weeks ago

Le 07/04/2025 à 10:14, José Expósito a écrit :
> From: Louis Chauvet <louis.chauvet@bootlin.com>
> 
> When a CRTC is created, add a `writeback` file to allow to enable or
> disable writeback connector support

Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>

> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
> Co-developed-by: José Expósito <jose.exposito89@gmail.com>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> ---
>   Documentation/gpu/vkms.rst           |  4 +++
>   drivers/gpu/drm/vkms/vkms_configfs.c | 42 ++++++++++++++++++++++++++++
>   2 files changed, 46 insertions(+)
> 
> diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst
> index e0699603ef53..abe7a0f5a4ab 100644
> --- a/Documentation/gpu/vkms.rst
> +++ b/Documentation/gpu/vkms.rst
> @@ -94,6 +94,10 @@ Continue by creating one or more CRTCs::
>   
>     sudo mkdir /config/vkms/my-vkms/crtcs/crtc0
>   
> +CRTCs have 1 configurable attribute:
> +
> +- writeback: Enable or disable writeback connector support by writing 1 or 0
> +
>   Once you are done configuring the VKMS instance, enable it::
>   
>     echo "1" | sudo tee /config/vkms/my-vkms/enabled
> diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c
> index 62a82366791d..e9f445043268 100644
> --- a/drivers/gpu/drm/vkms/vkms_configfs.c
> +++ b/drivers/gpu/drm/vkms/vkms_configfs.c
> @@ -74,6 +74,47 @@ struct vkms_configfs_crtc {
>   #define crtc_item_to_vkms_configfs_crtc(item) \
>   	container_of(to_config_group((item)), struct vkms_configfs_crtc, group)
>   
> +static ssize_t crtc_writeback_show(struct config_item *item, char *page)
> +{
> +	struct vkms_configfs_crtc *crtc;
> +	bool writeback;
> +
> +	crtc = crtc_item_to_vkms_configfs_crtc(item);
> +
> +	scoped_guard(mutex, &crtc->dev->lock)
> +		writeback = vkms_config_crtc_get_writeback(crtc->config);
> +
> +	return sprintf(page, "%d\n", writeback);
> +}
> +
> +static ssize_t crtc_writeback_store(struct config_item *item, const char *page,
> +				    size_t count)
> +{
> +	struct vkms_configfs_crtc *crtc;
> +	bool writeback;
> +
> +	crtc = crtc_item_to_vkms_configfs_crtc(item);
> +
> +	if (kstrtobool(page, &writeback))
> +		return -EINVAL;
> +
> +	scoped_guard(mutex, &crtc->dev->lock) {
> +		if (crtc->dev->enabled)
> +			return -EBUSY;
> +
> +		vkms_config_crtc_set_writeback(crtc->config, writeback);
> +	}
> +
> +	return (ssize_t)count;
> +}
> +
> +CONFIGFS_ATTR(crtc_, writeback);
> +
> +static struct configfs_attribute *crtc_item_attrs[] = {
> +	&crtc_attr_writeback,
> +	NULL,
> +};
> +
>   static void crtc_release(struct config_item *item)
>   {
>   	struct vkms_configfs_crtc *crtc;
> @@ -93,6 +134,7 @@ static struct configfs_item_operations crtc_item_operations = {
>   };
>   
>   static const struct config_item_type crtc_item_type = {
> +	.ct_attrs	= crtc_item_attrs,
>   	.ct_item_ops	= &crtc_item_operations,
>   	.ct_owner	= THIS_MODULE,
>   };

-- 
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com