[PATCH RFC v2 05/16] drm/vkms: Introduce configfs for plane rotation
Louis Chauvet
louis.chauvet at bootlin.com
Fri Nov 22 17:38:31 UTC 2024
To 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
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
drivers/gpu/drm/vkms/vkms_configfs.c | 102 +++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c
index ee64243396b3e586f76ff0671441c172da022421..d121cf54e75238bdb582362596a353682cceebd3 100644
--- a/drivers/gpu/drm/vkms/vkms_configfs.c
+++ b/drivers/gpu/drm/vkms/vkms_configfs.c
@@ -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,
};
--
2.47.0
More information about the dri-devel
mailing list