<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div dir="ltr">
<div dir="ltr" style="">
<div></div>
<div style="">
<div dir="ltr">Acked-by: Mikita Lipski <Mikita.Lipski@amd.com></div>
<div id="ms-outlook-mobile-signature">
<div><br>
</div>
<div style="direction:ltr">Thanks,</div>
<div style="direction:ltr">Mikita </div>
</div>
</div>
</div>
<div id="id-0e073774-24b9-4cff-aee5-2e0f95645a6f" class="ms-outlook-mobile-reference-message">
<hr style="display: inline-block; width: 98%; font-family: -webkit-standard; font-size: 12pt; color: rgb(0, 0, 0);" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif"><b>From:</b> Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com><br>
<b>Sent:</b> Monday, November 29, 2021 2:39 PM<br>
<b>To:</b> Wentland, Harry; markyacoub@google.com; Lipski, Mikita; Pillai, Aurabindo; Choi, Nicholas; Goodfellow, Hayden<br>
<b>Cc:</b> igt-dev@lists.freedesktop.org<br>
<b>Subject:</b> [PATCH i-g-t] tests/amdgpu: add test for panel self refresh
<div> </div>
</font></div>
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><font size="2"><span style="font-size:11pt;">
<div class="PlainText">From: Aurabindo Pillai <aurabindo.pillai@amd.com><br>
<br>
[Why&How]<br>
Test for PSR functionality. With an eDP connected, it tests whether PSR<br>
is enabled by commiting a static framebuffer<br>
<br>
hardware requirements:<br>
1. eDP panel that supports PSR (multiple panel can be connected at the<br>
same time)<br>
2. Optional DP display for testing a regression condition (setting crtc<br>
to null)<br>
<br>
Signed-off-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com><br>
Signed-off-by: Aurabindo Pillai <aurabindo.pillai@amd.com><br>
---<br>
tests/amdgpu/amd_psr.c | 221 +++++++++++++++++++++++++++++++++++++++<br>
tests/amdgpu/meson.build | 1 +<br>
2 files changed, 222 insertions(+)<br>
create mode 100644 tests/amdgpu/amd_psr.c<br>
<br>
diff --git a/tests/amdgpu/amd_psr.c b/tests/amdgpu/amd_psr.c<br>
new file mode 100644<br>
index 00000000..732eab25<br>
--- /dev/null<br>
+++ b/tests/amdgpu/amd_psr.c<br>
@@ -0,0 +1,221 @@<br>
+/*<br>
+ * Copyright 2021 Advanced Micro Devices, Inc.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
+ * OTHER DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "drm_mode.h"<br>
+#include "igt.h"<br>
+#include "igt_core.h"<br>
+#include "igt_kms.h"<br>
+#include <stdint.h><br>
+#include <fcntl.h><br>
+#include <xf86drmMode.h><br>
+<br>
+/* hardware requirements:<br>
+ * 1. eDP panel that supports PSR (multiple panel can be connected at the same time)<br>
+ * 2. Optional DP display for testing a regression condition (setting crtc to null)<br>
+ */<br>
+IGT_TEST_DESCRIPTION("Basic test for enabling Panel Self Refresh for eDP displays");<br>
+<br>
+#define DEBUGFS_PSR_STATE "psr_state"<br>
+/* After a full update, a few fast updates are necessary for PSR to be enabled */<br>
+#define N_FLIPS 6<br>
+/* DMCUB takes some time to actually enable PSR. Worst case delay is 4 seconds */<br>
+#define PSR_SETTLE_DELAY 4<br>
+<br>
+/* Common test data. */<br>
+typedef struct data {<br>
+ igt_display_t display;<br>
+ igt_plane_t *primary;<br>
+ igt_plane_t *cursor;<br>
+ igt_output_t *output;<br>
+ igt_pipe_t *pipe;<br>
+ igt_pipe_crc_t *pipe_crc;<br>
+ drmModeModeInfo *mode;<br>
+ enum pipe pipe_id;<br>
+ int fd;<br>
+ int w;<br>
+ int h;<br>
+} data_t;<br>
+<br>
+/* Common test setup. */<br>
+static void test_init(data_t *data)<br>
+{<br>
+ igt_display_t *display = &data->display;<br>
+<br>
+ /* It doesn't matter which pipe we choose on amdpgu. */<br>
+ data->pipe_id = PIPE_A;<br>
+ data->pipe = &data->display.pipes[data->pipe_id];<br>
+<br>
+ igt_display_reset(display);<br>
+<br>
+ data->output = igt_get_single_output_for_pipe(display, data->pipe_id);<br>
+ igt_require(data->output);<br>
+<br>
+ data->mode = igt_output_get_mode(data->output);<br>
+ igt_assert(data->mode);<br>
+<br>
+ data->primary =<br>
+ igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);<br>
+<br>
+ data->cursor =<br>
+ igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_CURSOR);<br>
+<br>
+ data->pipe_crc = igt_pipe_crc_new(data->fd, data->pipe_id, "auto");<br>
+<br>
+ igt_output_set_pipe(data->output, data->pipe_id);<br>
+<br>
+ data->w = data->mode->hdisplay;<br>
+ data->h = data->mode->vdisplay;<br>
+}<br>
+/* Common test cleanup. */<br>
+static void test_fini(data_t *data)<br>
+{<br>
+ igt_display_t *display = &data->display;<br>
+<br>
+ igt_pipe_crc_free(data->pipe_crc);<br>
+ igt_display_reset(display);<br>
+ igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, 0);<br>
+}<br>
+<br>
+static int check_conn_type(data_t *data, uint32_t type) {<br>
+ int i;<br>
+<br>
+ for (i = 0; i < data->display.n_outputs; i++) {<br>
+ uint32_t conn_type = data->display.outputs[i].config.connector->connector_type;<br>
+ if (conn_type == type)<br>
+ return i;<br>
+ }<br>
+<br>
+ return -1;<br>
+}<br>
+<br>
+static void run_check_psr(data_t *data, bool test_null_crtc) {<br>
+ char buf[8];<br>
+ char *connector_name;<br>
+ int fd, edp_idx, dp_idx, ret, i, psr_state;<br>
+ igt_fb_t ref_fb, ref_fb2;<br>
+ igt_fb_t *flip_fb;<br>
+ enum pipe pipe;<br>
+ igt_output_t *output;<br>
+<br>
+ test_init(data);<br>
+<br>
+ edp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_eDP);<br>
+ dp_idx = check_conn_type(data, DRM_MODE_CONNECTOR_DisplayPort);<br>
+ igt_skip_on_f(edp_idx == -1, "no eDP connector found\n");<br>
+<br>
+ for_each_pipe_with_single_output(&data->display, pipe, output) {<br>
+ if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_eDP)<br>
+ continue;<br>
+<br>
+ igt_create_color_fb(data->fd, data->mode->hdisplay,<br>
+ data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 1.0,<br>
+ 0.0, 0.0, &ref_fb);<br>
+ igt_create_color_fb(data->fd, data->mode->hdisplay,<br>
+ data->mode->vdisplay, DRM_FORMAT_XRGB8888, 0, 0.0,<br>
+ 1.0, 0.0, &ref_fb2);<br>
+<br>
+ igt_plane_set_fb(data->primary, &ref_fb);<br>
+ igt_output_set_pipe(output, pipe);<br>
+ igt_display_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, 0);<br>
+<br>
+ for (i = 0; i < N_FLIPS; i++) {<br>
+ if (i % 2 == 0)<br>
+ flip_fb = &ref_fb2;<br>
+ else<br>
+ flip_fb = &ref_fb;<br>
+<br>
+ ret = drmModePageFlip(data->fd, output->config.crtc->crtc_id,<br>
+ flip_fb->fb_id, DRM_MODE_PAGE_FLIP_EVENT, NULL);<br>
+ igt_require(ret == 0);<br>
+ kmstest_wait_for_pageflip(data->fd);<br>
+ }<br>
+ }<br>
+<br>
+ /* PSR state takes some time to settle its value on static screen */<br>
+ sleep(PSR_SETTLE_DELAY);<br>
+<br>
+ for_each_pipe_with_single_output(&data->display, pipe, output) {<br>
+ if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_eDP)<br>
+ continue;<br>
+<br>
+ connector_name = output->name;<br>
+ fd = igt_debugfs_connector_dir(data->fd, connector_name, O_RDONLY);<br>
+ igt_assert(fd >= 0);<br>
+<br>
+ ret = igt_debugfs_simple_read(fd, DEBUGFS_PSR_STATE, buf, sizeof(buf));<br>
+ igt_require(ret > 0);<br>
+<br>
+ psr_state = (int) strtol(buf, NULL, 10);<br>
+ igt_fail_on_f(psr_state < 1, "PSR was not enabled for connector %s\n", output->name);<br>
+ igt_fail_on_f(psr_state == 0xff, "PSR is invalid for connector %s\n", output->name);<br>
+ igt_fail_on_f(psr_state != 5, "PSR state is expected to be at 5 on a "<br>
+ "static screen for connector %s\n", output->name);<br>
+ }<br>
+<br>
+ if (test_null_crtc) {<br>
+ /* check whether settings crtc to null generated any warning (eDP+DP) */<br>
+ igt_skip_on_f(dp_idx == -1, "no DP connector found\n");<br>
+<br>
+ for_each_pipe_with_single_output(&data->display, pipe, output) {<br>
+ if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)<br>
+ continue;<br>
+<br>
+ igt_output_set_pipe(output, PIPE_NONE);<br>
+ igt_display_commit2(&data->display, COMMIT_ATOMIC);<br>
+ }<br>
+ }<br>
+<br>
+ igt_remove_fb(data->fd, &ref_fb);<br>
+ igt_remove_fb(data->fd, &ref_fb2);<br>
+ close(fd);<br>
+ test_fini(data);<br>
+}<br>
+<br>
+igt_main<br>
+{<br>
+ data_t data;<br>
+<br>
+ igt_skip_on_simulation();<br>
+ memset(&data, 0, sizeof(data));<br>
+<br>
+ igt_fixture<br>
+ {<br>
+ data.fd = drm_open_driver_master(DRIVER_AMDGPU);<br>
+<br>
+ kmstest_set_vt_graphics_mode();<br>
+<br>
+ igt_display_require(&data.display, data.fd);<br>
+ igt_require(&data.display.is_atomic);<br>
+ igt_display_require_output(&data.display);<br>
+ }<br>
+<br>
+ igt_describe("Test whether PSR can be enabled with static screen");<br>
+ igt_subtest("psr_enable") run_check_psr(&data, false);<br>
+<br>
+ igt_describe("Test whether setting CRTC to null triggers any warning with PSR enabled");<br>
+ igt_subtest("psr_enable_null_crtc") run_check_psr(&data, true);<br>
+<br>
+ igt_fixture<br>
+ {<br>
+ igt_display_fini(&data.display);<br>
+ }<br>
+}<br>
diff --git a/tests/amdgpu/meson.build b/tests/amdgpu/meson.build<br>
index 5216e194..2bd25ad6 100644<br>
--- a/tests/amdgpu/meson.build<br>
+++ b/tests/amdgpu/meson.build<br>
@@ -17,6 +17,7 @@ if libdrm_amdgpu.found()<br>
'amd_link_settings',<br>
'amd_vrr_range',<br>
'amd_mode_switch',<br>
+ 'amd_psr',<br>
]<br>
amdgpu_deps += libdrm_amdgpu<br>
endif<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>