Hi,

On 27/11/2026 11:52, Maxime Ripard wrote:
In order to make the implementation of atomic_sro_compare_state easier
and reduce the boilerplate, introduce a set of STATE_CHECK_* macros to
compare state field values depending on their type.

Reviewed-by: Maarten Lankhorst <[email protected]>
Signed-off-by: Maxime Ripard <[email protected]>
---
  drivers/gpu/drm/drm_atomic_state_readout_helper.c |  30 +++
  include/drm/drm_atomic_state_readout_helper.h     | 220 ++++++++++++++++++++++
  2 files changed, 250 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_state_readout_helper.c 
b/drivers/gpu/drm/drm_atomic_state_readout_helper.c
index c2bb7b47126c..f9808c8271a5 100644
--- a/drivers/gpu/drm/drm_atomic_state_readout_helper.c
+++ b/drivers/gpu/drm/drm_atomic_state_readout_helper.c
@@ -1069,5 +1069,35 @@ void drm_atomic_helper_sro_install_state(struct 
drm_atomic_sro_state *state)
                state->private_objs[i].state = NULL;
                state->private_objs[i].ptr = NULL;
        }
  }
  EXPORT_SYMBOL(drm_atomic_helper_sro_install_state);
+
+/**
+ * drm_atomic_helper_print_state_mismatch - report a state comparison mismatch
+ * @p: printer to report through
+ * @name: human-readable name of the object (e.g. plane or CRTC name)
+ * @field: name of the mismatching field
+ * @format: printf-style format string describing the mismatch
+ *
+ * Helper used by atomic_sro_compare_state implementations and the
+ * STATE_CHECK_* macros to report a field-level mismatch between the
+ * committed state and the state read back from hardware.
+ */
+void __printf(4, 5)
+drm_atomic_helper_print_state_mismatch(struct drm_printer *p,
+                                      const char *name,
+                                      const char *field,
+                                      const char *format, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       va_start(args, format);
+       vaf.fmt = format;
+       vaf.va = &args;
+
+       drm_printf(p, "%s configuration mismatch in %s %pV\n", name, field, 
&vaf);
+
+       va_end(args);
+}
+EXPORT_SYMBOL(drm_atomic_helper_print_state_mismatch);
diff --git a/include/drm/drm_atomic_state_readout_helper.h 
b/include/drm/drm_atomic_state_readout_helper.h
index 315a54141249..c4111fd825f0 100644
--- a/include/drm/drm_atomic_state_readout_helper.h
+++ b/include/drm/drm_atomic_state_readout_helper.h
@@ -1,14 +1,17 @@
  /* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef DRM_ATOMIC_SRO_HELPER_H_
  #define DRM_ATOMIC_SRO_HELPER_H_
+#include <linux/string_choices.h>
+
  struct drm_atomic_commit;
  struct drm_atomic_sro_state;
  struct drm_device;
  struct drm_gem_dma_object;
+struct drm_printer;
struct drm_gem_dma_object *
  drm_atomic_helper_sro_create_gem_dma_object(struct drm_device *dev,
                                            dma_addr_t dma_addr, size_t size);
@@ -36,6 +39,223 @@ struct drm_atomic_sro_state *
  drm_atomic_helper_sro_build_state(struct drm_device *dev,
                                  struct drm_atomic_commit *commit);
  int drm_atomic_helper_sro_readout_state(struct drm_device *dev);
  void drm_atomic_helper_sro_install_state(struct drm_atomic_sro_state *state);
+void __printf(4, 5)
+drm_atomic_helper_print_state_mismatch(struct drm_printer *p,
+                                      const char *name,
+                                      const char *field,
+                                      const char *format, ...);
+
+#define STATE_CHECK_BOOL(r, p, n, sa, sb, f)                           \
+       do {                                                            \
+               static_assert(__same_type(sa->f, sb->f),          \
+                             __stringify(f) " field types don't match"); \
+               static_assert(__same_type(sa->f, bool),                      \
+                             __stringify(f) " is not a bool");               \
+               if (sa->f != sb->f) {                                     \
+                       drm_atomic_helper_print_state_mismatch(p,       \
+                                                              n,       \
+                                                              __stringify(f), \
+                                                              "expected %s, got 
%s", \
+                                                              
str_yes_no(sa->f), \
+                                                              
str_yes_no(sb->f)); \
+                       r = false;                                      \
+               }                                                       \
+       } while (0)
+
+#define STATE_CHECK_DISPLAY_MODE(r, p, n, sa, sb, f)                   \
+       do {                                                            \
+               static_assert(__same_type(sa->f, sb->f),          \
+                             __stringify(f) " field types don't match"); \
+               static_assert(__same_type(sa->f, struct drm_display_mode), \
+                             __stringify(f) " is not a drm_display_mode 
structure"); \
+               if (!drm_mode_equal(&sa->f, &sb->f)) {                    \

This has the problem that we can't recreate the state from HW fully, and picture_aspect_ratio causes a check failure (so I saw a failure when setting mode with HDMI_PICTURE_ASPECT_4_3). I'm not sure if flags might also cause failures.

 Tomi

Reply via email to