<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 09-04-2020 11:09, Anshuman Gupta
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:20200409053951.26929-3-anshuman.gupta@intel.com">
      <pre class="moz-quote-pre" wrap="">This lib function evaluate the lpsp capability from
the connector specific debugfs attribute i915_lpsp_info.

v2:
- changed the lib function prefix igt_output_is_lpsp_capable
  to i915_output_is_lpsp_capable. [Martin]
v3:
- early return for the connector which doesn't support
  lpsp on any platform.
v4:
- debugfs entry changed from i915_lpsp_info to i915_lpsp_capability.

Signed-off-by: Anshuman Gupta <a class="moz-txt-link-rfc2396E" href="mailto:anshuman.gupta@intel.com"><anshuman.gupta@intel.com></a>
---
 lib/igt_pm.c | 37 +++++++++++++++++++++++++++++++++++++
 lib/igt_pm.h |  1 +
 2 files changed, 38 insertions(+)

diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 9d441e1b..3418b69a 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -37,6 +37,7 @@
 #include <dirent.h>
 
 #include "drmtest.h"
+#include "igt_kms.h"
 #include "igt_pm.h"
 #include "igt_aux.h"
 #include "igt_sysfs.h"
@@ -827,3 +828,39 @@ bool igt_pm_pc8_plus_residencies_enabled(int msr_fd)
 
        return true;
 }
+
+/**
+ * i915_output_is_lpsp_capable:
+ * @drm_fd: fd to drm device
+ * @output: igt output for which lpsp capability need to be evaluated
+ * Check lpsp capability for a given output.
+ *
+ * Returns:
+ * True if given output is lpsp capable otherwise false.
+ */
+bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output)
+{
+       drmModeConnectorPtr c = output->config.connector;
+       char buf[256];
+       int fd, len;
+
+       /* only eDP/DP/DSI/HDMI can support LPSP */
+       if (c->connector_type != DRM_MODE_CONNECTOR_eDP &&
+           c->connector_type != DRM_MODE_CONNECTOR_DSI &&
+           c->connector_type != DRM_MODE_CONNECTOR_DisplayPort &&
+           c->connector_type != DRM_MODE_CONNECTOR_HDMIA &&
+           c->connector_type != DRM_MODE_CONNECTOR_HDMIB)
+               return false;</pre>
    </blockquote>
    <pre>We can avoid check for Connector type as already taken care in kernel... rt?

Regards,
Animesh
</pre>
    <blockquote type="cite"
      cite="mid:20200409053951.26929-3-anshuman.gupta@intel.com">
      <pre class="moz-quote-pre" wrap="">
+
+       fd = igt_debugfs_connector_dir(drm_fd, output->name, O_RDONLY);
+       igt_require(fd >= 0);
+       len = igt_debugfs_simple_read(fd, "i915_lpsp_capability",
+                                     buf, sizeof(buf));
+
+       if (len < 0)
+               igt_assert_eq(len, -ENODEV);
+
+       close(fd);
+
+       return strstr(buf, "LPSP: capable");
+}
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index 5e438452..162d3ca3 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -53,5 +53,6 @@ enum igt_runtime_pm_status igt_get_runtime_pm_status(void);
 bool igt_wait_for_pm_status(enum igt_runtime_pm_status status);
 bool igt_pm_dmc_loaded(int debugfs);
 bool igt_pm_pc8_plus_residencies_enabled(int msr_fd);
+bool i915_output_is_lpsp_capable(int drm_fd, igt_output_t *output);
 
 #endif /* IGT_PM_H */
</pre>
    </blockquote>
  </body>
</html>