The hardware state readout is useful, but might need to be disabled
in case of bugs, or its checks relaxed during development when not
all hooks are implemented yet.

Add a module parameter to control the readout behavior: it can be
disabled entirely, or the checks for missing compare or readout hooks
can be skipped independently.

Suggested-by: Simona Vetter <[email protected]>
Reviewed-by: Simona Vetter <[email protected]>
Reviewed-by: Maarten Lankhorst <[email protected]>
Signed-off-by: Maxime Ripard <[email protected]>
---
 Documentation/admin-guide/kernel-parameters.txt | 12 ++++++++++
 drivers/gpu/drm/drm_atomic_state_readout.c      | 29 +++++++++++++++++++++++++
 include/drm/drm_atomic_state_readout.h          |  9 ++++++++
 3 files changed, 50 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 0b3c140babd9..59ff44c49f31 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1378,4 +1378,16 @@ Kernel parameters
                        any connectors not explicitly specified.
 
+       drm.atomic_readout=     [DRM]
+                       Control the KMS atomic hardware state readout
+                       (SRO), used to initialize the atomic state from
+                       the state the firmware left the hardware in at
+                       boot instead of programming a new one.
+                       0: disable the state readout entirely,
+                       1: enable it (default),
+                       2: ignore the objects missing a comparison
+                          implementation,
+                       3: ignore the objects missing a readout or
+                          comparison implementation.
+
        dscc4.setup=    [NET]
 
diff --git a/drivers/gpu/drm/drm_atomic_state_readout.c 
b/drivers/gpu/drm/drm_atomic_state_readout.c
index 0993d4cdfc2d..4ae435236f82 100644
--- a/drivers/gpu/drm/drm_atomic_state_readout.c
+++ b/drivers/gpu/drm/drm_atomic_state_readout.c
@@ -15,4 +15,33 @@
 #include "drm_crtc_internal.h"
 
+static unsigned int atomic_readout = DRM_ATOMIC_READOUT_ENABLED;
+module_param_unsafe(atomic_readout, uint, 0400);
+MODULE_PARM_DESC(atomic_readout,
+                "Enable Hardware State Readout (0 = disabled, 1 = enabled, 2 = 
ignore missing compares, 3 = ignore missing readouts and compares, default = 
1)");
+
+/**
+ * drm_atomic_sro_device_can_readout - check if a device supports hardware 
state readout
+ * @dev: DRM device to check
+ *
+ * Verifies that the device is an atomic driver, that readout is
+ * enabled, and that all KMS objects implement the relevant hooks.
+ *
+ * RETURNS:
+ *
+ * True if the device supports full hardware state readout, false
+ * otherwise.
+ */
+bool drm_atomic_sro_device_can_readout(struct drm_device *dev)
+{
+       if (!drm_drv_uses_atomic_modeset(dev))
+               return false;
+
+       if (atomic_readout == DRM_ATOMIC_READOUT_DISABLED)
+               return false;
+
+       return true;
+}
+EXPORT_SYMBOL(drm_atomic_sro_device_can_readout);
+
 struct __drm_atomic_sro_plane {
        struct drm_plane *ptr;
diff --git a/include/drm/drm_atomic_state_readout.h 
b/include/drm/drm_atomic_state_readout.h
index 5a9333a05796..955e2de9d5b1 100644
--- a/include/drm/drm_atomic_state_readout.h
+++ b/include/drm/drm_atomic_state_readout.h
@@ -16,4 +16,13 @@ struct drm_private_obj;
 struct drm_private_state;
 
+enum drm_atomic_readout_status {
+       DRM_ATOMIC_READOUT_DISABLED = 0,
+       DRM_ATOMIC_READOUT_ENABLED,
+       DRM_ATOMIC_READOUT_SKIP_MISSING_COMPARE,
+       DRM_ATOMIC_READOUT_SKIP_MISSING_READOUT,
+};
+
+bool drm_atomic_sro_device_can_readout(struct drm_device *dev);
+
 struct drm_atomic_sro_state *drm_atomic_sro_state_alloc(struct drm_device 
*dev);
 void drm_atomic_sro_state_free(struct drm_atomic_sro_state *state);

-- 
2.55.0

Reply via email to