[PATCH RFC v2 06/16] drm/vkms: Introduce configfs for plane color encoding
Louis Chauvet
louis.chauvet at bootlin.com
Fri Nov 22 17:38:32 UTC 2024
To allows the userspace to test many hardware configuration, introduce a
new interface to configure the available color encoding per planes. VKMS
supports multiple color encoding, so the userspace can choose any
combination.
The supported color encoding are configured by writing a color encoding
bitmask to the file `supported_color_encoding` and the default color
encoding is chosen by writing a color encoding bitmask to
`default_color_encoding`.
The current interface is:
/config/vkms
DEVICE_1
┣━ enable
┣━ planes
┃ ┗━ PLANE_1
┃ ┣━ type
┃ ┣━ supported_rotations
┃ ┣━ supported_color_encoding
┃ ┣━ default_rotation
┃ ┗━ default_color_encoding
DEVICE_2
┗━ ditto
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
drivers/gpu/drm/vkms/vkms_configfs.c | 107 +++++++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c
index d121cf54e75238bdb582362596a353682cceebd3..a3dab59868829266adfe8192c5089cda2044c050 100644
--- a/drivers/gpu/drm/vkms/vkms_configfs.c
+++ b/drivers/gpu/drm/vkms/vkms_configfs.c
@@ -152,14 +152,121 @@ static ssize_t plane_default_rotation_store(struct config_item *item,
return count;
}
+static ssize_t plane_supported_color_encoding_show(struct config_item *item, char *page)
+{
+ struct vkms_config_plane *plane;
+ unsigned int supported_color_encoding;
+ 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;
+ supported_color_encoding = plane->supported_color_encoding;
+ mutex_unlock(&vkms_configfs->lock);
+
+ return sprintf(page, "%u", supported_color_encoding);
+}
+
+static ssize_t plane_supported_color_encoding_store(struct config_item *item,
+ const char *page, size_t count)
+{
+ struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item);
+ struct vkms_config_plane *plane;
+ int ret, val = 0;
+
+ ret = kstrtouint(page, 10, &val);
+ if (ret)
+ return ret;
+
+ /* Should be a supported value */
+ if (val & ~(BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT709) |
+ BIT(DRM_COLOR_YCBCR_BT2020)))
+ return -EINVAL;
+ /* Should at least provide one color range */
+ if ((val & (BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT709) |
+ BIT(DRM_COLOR_YCBCR_BT2020))) == 0)
+ 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_color_encoding) !=
+ plane->default_color_encoding) {
+ mutex_unlock(&vkms_configfs->lock);
+ return -EINVAL;
+ }
+ plane->supported_color_encoding = val;
+ mutex_unlock(&vkms_configfs->lock);
+
+ return count;
+}
+
+/* Plane default_color_encoding : vkms/<device>/planes/<plane>/default_color_encoding */
+
+static ssize_t plane_default_color_encoding_show(struct config_item *item, char *page)
+{
+ struct vkms_config_plane *plane;
+ unsigned int default_color_encoding;
+ 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;
+ default_color_encoding = plane->default_color_encoding;
+ mutex_unlock(&vkms_configfs->lock);
+
+ return sprintf(page, "%u", default_color_encoding);
+}
+
+static ssize_t plane_default_color_encoding_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 & ~(BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT709) |
+ BIT(DRM_COLOR_YCBCR_BT2020)))
+ return -EINVAL;
+ /* Should at least provide one color range */
+ if ((val & (BIT(DRM_COLOR_YCBCR_BT601) |
+ BIT(DRM_COLOR_YCBCR_BT709) |
+ BIT(DRM_COLOR_YCBCR_BT2020))) == 0)
+ 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_color_encoding) != val) {
+ mutex_unlock(&vkms_configfs->lock);
+ return -EINVAL;
+ }
+ plane->default_color_encoding = val;
+ mutex_unlock(&vkms_configfs->lock);
+
+ return count;
+}
+
CONFIGFS_ATTR(plane_, type);
CONFIGFS_ATTR(plane_, supported_rotations);
CONFIGFS_ATTR(plane_, default_rotation);
+CONFIGFS_ATTR(plane_, supported_color_encoding);
+CONFIGFS_ATTR(plane_, default_color_encoding);
static struct configfs_attribute *plane_attrs[] = {
&plane_attr_type,
&plane_attr_supported_rotations,
&plane_attr_default_rotation,
+ &plane_attr_supported_color_encoding,
+ &plane_attr_default_color_encoding,
NULL,
};
--
2.47.0
More information about the dri-devel
mailing list