Re: [PATCH v6 05/43] drm/blend: Get a rotation name from its bitfield

From: Oarora Etimis

Date: Tue Nov 24 2026 - 05:48:59 EST


On Fri, Nov 20, 2026 at 06:58:47PM +0100, Louis Chauvet wrote:
> Extract the rotation/reflection name table and expose the
> DRM_ROTATION_FMT()/DRM_ROTATION_FMT_ARGS() helpers to print a
> human-readable rotation mask.
>
> Signed-off-by: Louis Chauvet <louis.chauvet@xxxxxxxxxxx>
> ---
> drivers/gpu/drm/drm_blend.c | 19 ++++++++++---------
> include/drm/drm_blend.h | 34 ++++++++++++++++++++++++++++++++++
> 2 files changed, 44 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_blend.c b/drivers/gpu/drm/drm_blend.c
> index d17ae964fb21..b62f1db9c311 100644
> --- a/drivers/gpu/drm/drm_blend.c
> +++ b/drivers/gpu/drm/drm_blend.c
> @@ -256,6 +256,15 @@ int drm_plane_create_alpha_property(struct drm_plane *plane)
> }
> EXPORT_SYMBOL(drm_plane_create_alpha_property);
>
> +static const struct drm_prop_enum_list rotation_props[] = {
> + { __builtin_ffs(DRM_MODE_ROTATE_0) - 1, "rotate-0" },
> + { __builtin_ffs(DRM_MODE_ROTATE_90) - 1, "rotate-90" },
> + { __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" },
> + { __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" },
> + { __builtin_ffs(DRM_MODE_REFLECT_X) - 1, "reflect-x" },
> + { __builtin_ffs(DRM_MODE_REFLECT_Y) - 1, "reflect-y" },
> +};
> +
> /**
> * drm_plane_create_rotation_property - create a new rotation property
> * @plane: drm plane
> @@ -294,14 +303,6 @@ int drm_plane_create_rotation_property(struct drm_plane *plane,
> unsigned int rotation,
> unsigned int supported_rotations)
> {
> - static const struct drm_prop_enum_list props[] = {
> - { __builtin_ffs(DRM_MODE_ROTATE_0) - 1, "rotate-0" },
> - { __builtin_ffs(DRM_MODE_ROTATE_90) - 1, "rotate-90" },
> - { __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" },
> - { __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" },
> - { __builtin_ffs(DRM_MODE_REFLECT_X) - 1, "reflect-x" },
> - { __builtin_ffs(DRM_MODE_REFLECT_Y) - 1, "reflect-y" },
> - };
> struct drm_property *prop;
>
> WARN_ON((supported_rotations & DRM_MODE_ROTATE_MASK) == 0);
> @@ -309,7 +310,7 @@ int drm_plane_create_rotation_property(struct drm_plane *plane,
> WARN_ON(rotation & ~supported_rotations);
>
> prop = drm_property_create_bitmask(plane->dev, 0, "rotation",
> - props, ARRAY_SIZE(props),
> + rotation_props, ARRAY_SIZE(rotation_props),
> supported_rotations);
> if (!prop)
> return -ENOMEM;
> diff --git a/include/drm/drm_blend.h b/include/drm/drm_blend.h
> index bebbb77a8f21..f000b10a16e7 100644
> --- a/include/drm/drm_blend.h
> +++ b/include/drm/drm_blend.h
> @@ -43,6 +43,40 @@ static inline bool drm_rotation_90_or_270(unsigned int rotation)
>
> #define DRM_BLEND_ALPHA_OPAQUE 0xffff
>
> +/**
> + * DRM_ROTATION_FMT - printf format string describing a rotation bitmask
> + *
> + * To be used together with DRM_ROTATION_FMT_ARGS(), e.g.:
> + *
> + * seq_printf(m, "rotation=" DRM_ROTATION_FMT "\n",
> + * DRM_ROTATION_FMT_ARGS(state->rotation));
> + *
> + * The result names every set bit, separated by single spaces, and ends
> + * with the raw value in parentheses, e.g.:
> + *
> + * rotate-90 reflect-x (0x00000012)
> + *
> + * The trailing raw value ensures the output is never empty and never
> + * ends with a space, even when no bit is set.
> + */
> +#define DRM_ROTATION_FMT "%s%s%s%s%s%s(0x%08x)"
> +
> +/**
> + * DRM_ROTATION_FMT_ARGS - printf arguments for DRM_ROTATION_FMT
> + * @rot: rotation bitmask (DRM_MODE_ROTATE_* | DRM_MODE_REFLECT_*)
> + *
> + * Evaluates @rot several times: only pass a variable or an expression
> + * without side effects.
> + */
> +#define DRM_ROTATION_FMT_ARGS(rot) \
> + ((rot) & DRM_MODE_ROTATE_0) ? "rotate-0 " : "", \
> + ((rot) & DRM_MODE_ROTATE_90) ? "rotate-90 " : "", \
> + ((rot) & DRM_MODE_ROTATE_180) ? "rotate-180 " : "", \
> + ((rot) & DRM_MODE_ROTATE_270) ? "rotate-270 " : "", \
> + ((rot) & DRM_MODE_REFLECT_X) ? "reflect-x " : "", \
> + ((rot) & DRM_MODE_REFLECT_Y) ? "reflect-y " : "", \
> + (rot)
> +
> int drm_plane_create_alpha_property(struct drm_plane *plane);
> int drm_plane_create_rotation_property(struct drm_plane *plane,
> unsigned int rotation,
>
> --
> 2.56.0
>

Reviewed-by: Oarora Etimis <oaroraetimis@xxxxxxxxx>