[PATCH RESEND v2 08/32] drm/vkms: Introduce config for plane rotation

Louis Chauvet
2025-10-29T14:37:06Z

VKMS driver supports all the rotation on planes, but for testing it can be
useful to only advertise few of them. This new configuration interface
will allow configuring the rotation per planes.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
drivers/gpu/drm/vkms/tests/vkms_config_test.c | 46 +++++++++++++++++++
drivers/gpu/drm/vkms/vkms_config.c | 63 +++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_config.h | 59 +++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_plane.c | 6 ++-
4 files changed, 172 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_config_test.c b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
index d75a6252e4d2..8d805084ad96 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_config_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0+

+#include <drm/drm_mode.h>
#include <kunit/test.h>

#include "../vkms_config.h"
@@ -172,6 +173,12 @@ static void vkms_config_test_default_config(struct kunit *test)
n_possible_crtcs++;
}
KUNIT_EXPECT_EQ(test, n_possible_crtcs, 1);
+ KUNIT_EXPECT_EQ(test,
+ vkms_config_plane_get_supported_rotations(plane_cfg),
+ DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK);
+ KUNIT_EXPECT_EQ(test,
+ vkms_config_plane_get_default_rotation(plane_cfg),
+ DRM_MODE_ROTATE_0);
}

/* Encoders */
@@ -468,6 +475,44 @@ static void vkms_config_test_valid_plane_type(struct kunit *test)
vkms_config_destroy(config);
}

+static void vkms_config_test_valid_plane_rotations(struct kunit *test)
+{
+ struct vkms_config *config;
+ struct vkms_config_plane *plane_cfg;
+
+ config = vkms_config_default_create(false, false, false);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
+
+ plane_cfg = get_first_plane(config);
+
+ /* Valid, no rotation, no reflection */
+ vkms_config_plane_set_supported_rotations(plane_cfg, DRM_MODE_ROTATE_0);
+ vkms_config_plane_set_default_rotation(plane_cfg, DRM_MODE_ROTATE_0);
+ KUNIT_EXPECT_TRUE(test, vkms_config_valid_plane_rotation(config, plane_cfg));
+ KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config));
+
+ /* Invalid, default rotation is not supported */
+ vkms_config_plane_set_supported_rotations(plane_cfg, DRM_MODE_ROTATE_0);
+ vkms_config_plane_set_default_rotation(plane_cfg, DRM_MODE_ROTATE_90);
+ KUNIT_EXPECT_FALSE(test, vkms_config_valid_plane_rotation(config, plane_cfg));
+ KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
+
+ /* Invalid, supported rotations must contains at least one rotation */
+ vkms_config_plane_set_supported_rotations(plane_cfg, DRM_MODE_REFLECT_MASK);
+ vkms_config_plane_set_default_rotation(plane_cfg, DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_0);
+ KUNIT_EXPECT_FALSE(test, vkms_config_valid_plane_rotation(config, plane_cfg));
+ KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
+
+ /* Invalid, default rotation must contains at least one rotation */
+ vkms_config_plane_set_supported_rotations(plane_cfg,
+ DRM_MODE_REFLECT_MASK | DRM_MODE_ROTATE_0);
+ vkms_config_plane_set_default_rotation(plane_cfg, DRM_MODE_REFLECT_X);
+ KUNIT_EXPECT_FALSE(test, vkms_config_valid_plane_rotation(config, plane_cfg));
+ KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config));
+
+ vkms_config_destroy(config);
+}
+
static void vkms_config_test_valid_plane_possible_crtcs(struct kunit *test)
{
struct vkms_config *config;
@@ -990,6 +1035,7 @@ static struct kunit_case vkms_config_test_cases[] = {
KUNIT_CASE(vkms_config_test_get_connectors),
KUNIT_CASE(vkms_config_test_invalid_plane_number),
KUNIT_CASE(vkms_config_test_valid_plane_type),
+ KUNIT_CASE(vkms_config_test_valid_plane_rotations),
KUNIT_CASE(vkms_config_test_valid_plane_possible_crtcs),
KUNIT_CASE(vkms_config_test_invalid_crtc_number),
KUNIT_CASE(vkms_config_test_invalid_encoder_number),
diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
index bfafb5d2504d..dd951db88888 100644
--- a/drivers/gpu/drm/vkms/vkms_config.c
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -3,7 +3,9 @@
#include <linux/slab.h>
#include <linux/string_choices.h>

+#include <drm/drm_blend.h>
#include <drm/drm_connector.h>
+#include <drm/drm_mode.h>
#include <drm/drm_print.h>
#include <drm/drm_debugfs.h>
#include <kunit/visibility.h>
@@ -146,6 +148,33 @@ static bool valid_plane_number(const struct vkms_config *config)
return true;
}

+VISIBLE_IF_KUNIT
+bool vkms_config_valid_plane_rotation(const struct vkms_config *config,
+ const struct vkms_config_plane *plane_cfg)
+{
+ struct drm_device *dev = config->dev ? &config->dev->drm : NULL;
+
+ if ((vkms_config_plane_get_default_rotation(plane_cfg) &
+ vkms_config_plane_get_supported_rotations(plane_cfg)) !=
+ vkms_config_plane_get_default_rotation(plane_cfg)) {
+ drm_info(dev, "Configured default rotation is not supported by the plane\n");
+ return false;
+ }
+
+ if ((vkms_config_plane_get_default_rotation(plane_cfg) & DRM_MODE_ROTATE_MASK) == 0) {
+ drm_info(dev, "Configured default rotation must contains at least one possible rotation\n");
+ return false;
+ }
+
+ if ((vkms_config_plane_get_supported_rotations(plane_cfg) & DRM_MODE_ROTATE_MASK) == 0) {
+ drm_info(dev, "Configured supported rotations must contains at least one possible rotation\n");
+ return false;
+ }
+
+ return true;
+}
+EXPORT_SYMBOL_IF_KUNIT(vkms_config_valid_plane_rotation);
+
static bool valid_planes_for_crtc(const struct vkms_config *config,
struct vkms_config_crtc *crtc_cfg)
{
@@ -303,6 +332,12 @@ static bool valid_connector_possible_encoders(const struct vkms_config *config)
bool vkms_config_is_valid(const struct vkms_config *config)
{
struct vkms_config_crtc *crtc_cfg;
+ struct vkms_config_plane *plane_cfg;
+
+ vkms_config_for_each_plane(config, plane_cfg) {
+ if (!vkms_config_valid_plane_rotation(config, plane_cfg))
+ return false;
+ }

if (!valid_plane_number(config))
return false;
@@ -334,6 +369,22 @@ bool vkms_config_is_valid(const struct vkms_config *config)
}
EXPORT_SYMBOL_IF_KUNIT(vkms_config_is_valid);

+static void show_bitfield(struct seq_file *m, uint32_t value, const char *callback(unsigned int))
+{
+ u32 offset = 0;
+ bool first = true;
+
+ while (value >= BIT(offset) && offset < 32) {
+ if (value & BIT(offset)) {
+ if (!first)
+ seq_puts(m, ",");
+ seq_printf(m, callback(offset));
+ first = false;
+ }
+ offset += 1;
+ }
+}
+
static int vkms_config_show(struct seq_file *m, void *data)
{
struct drm_debugfs_entry *entry = m->private;
@@ -354,6 +405,14 @@ static int vkms_config_show(struct seq_file *m, void *data)
drm_get_plane_type_name(vkms_config_plane_get_type(plane_cfg)));
seq_printf(m, "\tname=%s\n",
vkms_config_plane_get_name(plane_cfg));
+ seq_puts(m, "\tsupported rotations=");
+ show_bitfield(m, vkms_config_plane_get_supported_rotations(plane_cfg),
+ drm_get_rotation_name);
+ seq_puts(m, "\n");
+ seq_puts(m, "\tdefault rotation=");
+ show_bitfield(m, vkms_config_plane_get_default_rotation(plane_cfg),
+ drm_get_rotation_name);
+ seq_puts(m, "\n");
}

vkms_config_for_each_crtc(vkmsdev->config, crtc_cfg) {
@@ -395,6 +454,10 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *config)
plane_cfg->config = config;
vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_OVERLAY);
vkms_config_plane_set_name(plane_cfg, NULL);
+ vkms_config_plane_set_supported_rotations(plane_cfg,
+ DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK);
+ vkms_config_plane_set_default_rotation(plane_cfg, DRM_MODE_ROTATE_0);
+
xa_init_flags(&plane_cfg->possible_crtcs, XA_FLAGS_ALLOC);

list_add_tail(&plane_cfg->link, &config->planes);
diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
index 57342db5795a..8d413e02180a 100644
--- a/drivers/gpu/drm/vkms/vkms_config.h
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -39,6 +39,8 @@ struct vkms_config {
* @type: Type of the plane. The creator of configuration needs to ensures that
* at least one primary plane is present.
* @possible_crtcs: Array of CRTCs that can be used with this plane
+ * @default_rotation: Default rotation that should be used by this plane
+ * @supported_rotation: Rotation that this plane will support
* @plane: Internal usage. This pointer should never be considered as valid.
* It can be used to store a temporary reference to a VKMS plane during
* device creation. This pointer is not managed by the configuration and
@@ -50,6 +52,8 @@ struct vkms_config_plane {

const char *name;
enum drm_plane_type type;
+ unsigned int default_rotation;
+ unsigned int supported_rotations;
struct xarray possible_crtcs;

/* Internal usage */
@@ -290,6 +294,61 @@ vkms_config_plane_set_type(struct vkms_config_plane *plane_cfg,
plane_cfg->type = type;
}

+/**
+ * vkms_config_plane_get_default_rotation() - Get the default rotation for a plane
+ * @plane_cfg: Plane to get the default rotation from
+ *
+ * Returns:
+ * The default rotation for the plane.
+ */
+static inline unsigned int
+vkms_config_plane_get_default_rotation(const struct vkms_config_plane *plane_cfg)
+{
+ return plane_cfg->default_rotation;
+}
+
+/**
+ * vkms_config_plane_set_default_rotation() - Set the default rotation for a plane
+ * @plane_cfg: Plane to set the default rotation to
+ * @default_rotation: New default rotation for the plane
+ */
+static inline void
+vkms_config_plane_set_default_rotation(struct vkms_config_plane *plane_cfg,
+ unsigned int default_rotation)
+{
+ plane_cfg->default_rotation = default_rotation;
+}
+
+/**
+ * vkms_config_plane_get_supported_rotations() - Get the supported rotations for a plane
+ * @plane_cfg: Plane to get the supported rotations from
+ *
+ * Returns:
+ * The supported rotations for the plane.
+ */
+static inline unsigned int
+vkms_config_plane_get_supported_rotations(const struct vkms_config_plane *plane_cfg)
+{
+ return plane_cfg->supported_rotations;
+}
+
+/**
+ * vkms_config_plane_set_supported_rotations() - Set the supported rotations for a plane
+ * @plane_cfg: Plane to set the supported rotations to
+ * @supported_rotations: New supported rotations for the plane
+ */
+static inline void
+vkms_config_plane_set_supported_rotations(struct vkms_config_plane *plane_cfg,
+ unsigned int supported_rotations)
+{
+ plane_cfg->supported_rotations = supported_rotations;
+}
+
+#if IS_ENABLED(CONFIG_KUNIT)
+bool vkms_config_valid_plane_rotation(const struct vkms_config *config,
+ const struct vkms_config_plane *plane_cfg);
+#endif
+
/**
* vkms_config_plane_set_name() - Set the plane name
* @plane_cfg: Plane to set the name to
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index 73180cbb78b1..d147b70692fa 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0+

+#include "vkms_config.h"
#include <linux/iosys-map.h>

#include <drm/drm_atomic.h>
@@ -233,8 +234,9 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,

drm_plane_helper_add(&plane->base, &vkms_plane_helper_funcs);

- drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0,
- DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK);
+ drm_plane_create_rotation_property(&plane->base,
+ vkms_config_plane_get_default_rotation(config),
+ vkms_config_plane_get_supported_rotations(config));

drm_plane_create_color_properties(&plane->base,
BIT(DRM_COLOR_YCBCR_BT601) |

--
2.51.0