2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/string_helpers.h>
27 #include <linux/uaccess.h>
31 #include "amdgpu_dm.h"
32 #include "amdgpu_dm_debugfs.h"
33 #include "dm_helpers.h"
34 #include "dmub/dmub_srv.h"
37 #include "dc_link_dp.h"
38 #include "link_hwss.h"
39 #include "dc/dc_dmub_srv.h"
41 struct dmub_debugfs_trace_header {
46 struct dmub_debugfs_trace_entry {
53 static const char *const mst_progress_status[] = {
56 "allocate_new_payload",
57 "clear_allocated_payload",
60 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
62 * Function takes in attributes passed to debugfs write entry
63 * and writes into param array.
64 * The user passes max_param_num to identify maximum number of
65 * parameters that could be parsed.
68 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
69 long *param, const char __user *buf,
73 char *wr_buf_ptr = NULL;
74 uint32_t wr_buf_count = 0;
77 const char delimiter[3] = {' ', '\n', '\0'};
78 uint8_t param_index = 0;
84 /* r is bytes not be copied */
85 if (copy_from_user(wr_buf_ptr, buf, wr_buf_size)) {
86 DRM_DEBUG_DRIVER("user data could not be read successfully\n");
90 /* check number of parameters. isspace could not differ space and \n */
91 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
93 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
98 if (wr_buf_count == wr_buf_size)
102 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
109 if (wr_buf_count == wr_buf_size)
113 if (*param_nums > max_param_num)
114 *param_nums = max_param_num;
116 wr_buf_ptr = wr_buf; /* reset buf pointer */
117 wr_buf_count = 0; /* number of char already checked */
119 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
124 while (param_index < *param_nums) {
125 /* after strsep, wr_buf_ptr will be moved to after space */
126 sub_str = strsep(&wr_buf_ptr, delimiter);
128 r = kstrtol(sub_str, 16, &(param[param_index]));
131 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
139 /* function description
140 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
142 * valid lane count value: 1, 2, 4
143 * valid link rate value:
144 * 06h = 1.62Gbps per lane
145 * 0Ah = 2.7Gbps per lane
146 * 0Ch = 3.24Gbps per lane
147 * 14h = 5.4Gbps per lane
148 * 1Eh = 8.1Gbps per lane
150 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
152 * --- to get dp configuration
154 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
156 * It will list current, verified, reported, preferred dp configuration.
157 * current -- for current video mode
158 * verified --- maximum configuration which pass link training
159 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
160 * preferred --- user force settings
162 * --- set (or force) dp configuration
164 * echo <lane_count> <link_rate> > link_settings
166 * for example, to force to 2 lane, 2.7GHz,
167 * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
169 * spread_spectrum could not be changed dynamically.
171 * in case invalid lane count, link rate are force, no hw programming will be
172 * done. please check link settings after force operation to see if HW get
175 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
177 * check current and preferred settings.
180 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
181 size_t size, loff_t *pos)
183 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
184 struct dc_link *link = connector->dc_link;
186 char *rd_buf_ptr = NULL;
187 const uint32_t rd_buf_size = 100;
192 if (*pos & 3 || size & 3)
195 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
201 str_len = strlen("Current: %d 0x%x %d ");
202 snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
203 link->cur_link_settings.lane_count,
204 link->cur_link_settings.link_rate,
205 link->cur_link_settings.link_spread);
206 rd_buf_ptr += str_len;
208 str_len = strlen("Verified: %d 0x%x %d ");
209 snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
210 link->verified_link_cap.lane_count,
211 link->verified_link_cap.link_rate,
212 link->verified_link_cap.link_spread);
213 rd_buf_ptr += str_len;
215 str_len = strlen("Reported: %d 0x%x %d ");
216 snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
217 link->reported_link_cap.lane_count,
218 link->reported_link_cap.link_rate,
219 link->reported_link_cap.link_spread);
220 rd_buf_ptr += str_len;
222 str_len = strlen("Preferred: %d 0x%x %d ");
223 snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
224 link->preferred_link_setting.lane_count,
225 link->preferred_link_setting.link_rate,
226 link->preferred_link_setting.link_spread);
229 if (*pos >= rd_buf_size)
232 r = put_user(*(rd_buf + result), buf);
235 return r; /* r = -EFAULT */
248 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
249 size_t size, loff_t *pos)
251 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
252 struct dc_link *link = connector->dc_link;
253 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
254 struct dc *dc = (struct dc *)link->dc;
255 struct dc_link_settings prefer_link_settings;
257 const uint32_t wr_buf_size = 40;
258 /* 0: lane_count; 1: link_rate */
259 int max_param_num = 2;
260 uint8_t param_nums = 0;
262 bool valid_input = true;
267 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
271 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
279 if (param_nums <= 0) {
281 DRM_DEBUG_DRIVER("user data not be read\n");
288 case LANE_COUNT_FOUR:
299 case LINK_RATE_HIGH2:
300 case LINK_RATE_HIGH3:
301 case LINK_RATE_UHBR10:
310 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
311 mutex_lock(&adev->dm.dc_lock);
312 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
313 mutex_unlock(&adev->dm.dc_lock);
317 /* save user force lane_count, link_rate to preferred settings
318 * spread spectrum will not be changed
320 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
321 prefer_link_settings.use_link_rate_set = false;
322 prefer_link_settings.lane_count = param[0];
323 prefer_link_settings.link_rate = param[1];
325 mutex_lock(&adev->dm.dc_lock);
326 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, false);
327 mutex_unlock(&adev->dm.dc_lock);
333 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
334 * post-cursor2 (defined by VESA DP specification)
337 * voltage swing: 0,1,2,3
338 * pre-emphasis : 0,1,2,3
339 * post cursor2 : 0,1,2,3
342 * how to use this debugfs
344 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
346 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
348 * To figure out which DP-x is the display for DP to be check,
351 * There should be debugfs file, like link_settings, phy_settings.
353 * from lane_count, link_rate to figure which DP-x is for display to be worked
356 * To get current DP PHY settings,
359 * To change DP PHY settings,
360 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
361 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
363 * echo 2 3 0 > phy_settings
365 * To check if change be applied, get current phy settings by
368 * In case invalid values are set by user, like
369 * echo 1 4 0 > phy_settings
371 * HW will NOT be programmed by these settings.
372 * cat phy_settings will show the previous valid settings.
374 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
375 size_t size, loff_t *pos)
377 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
378 struct dc_link *link = connector->dc_link;
380 const uint32_t rd_buf_size = 20;
384 if (*pos & 3 || size & 3)
387 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
391 snprintf(rd_buf, rd_buf_size, " %d %d %d\n",
392 link->cur_lane_setting[0].VOLTAGE_SWING,
393 link->cur_lane_setting[0].PRE_EMPHASIS,
394 link->cur_lane_setting[0].POST_CURSOR2);
397 if (*pos >= rd_buf_size)
400 r = put_user((*(rd_buf + result)), buf);
403 return r; /* r = -EFAULT */
416 static int dp_lttpr_status_show(struct seq_file *m, void *d)
419 struct amdgpu_dm_connector *connector = file_inode(m->file)->i_private;
420 struct dc_link *link = connector->dc_link;
421 uint32_t read_size = 1;
422 uint8_t repeater_count = 0;
424 data = kzalloc(read_size, GFP_KERNEL);
428 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0002, data, read_size);
430 switch ((uint8_t)*data) {
459 repeater_count = (uint8_t)*data;
463 seq_printf(m, "phy repeater count: %d\n", repeater_count);
465 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0003, data, read_size);
467 if ((uint8_t)*data == 0x55)
468 seq_printf(m, "phy repeater mode: transparent\n");
469 else if ((uint8_t)*data == 0xAA)
470 seq_printf(m, "phy repeater mode: non-transparent\n");
471 else if ((uint8_t)*data == 0x00)
472 seq_printf(m, "phy repeater mode: non lttpr\n");
474 seq_printf(m, "phy repeater mode: read error\n");
480 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
481 size_t size, loff_t *pos)
483 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
484 struct dc_link *link = connector->dc_link;
485 struct dc *dc = (struct dc *)link->dc;
487 uint32_t wr_buf_size = 40;
489 bool use_prefer_link_setting;
490 struct link_training_settings link_lane_settings;
491 int max_param_num = 3;
492 uint8_t param_nums = 0;
499 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
503 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
511 if (param_nums <= 0) {
513 DRM_DEBUG_DRIVER("user data not be read\n");
517 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
518 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
519 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
521 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
525 /* get link settings: lane count, link rate */
526 use_prefer_link_setting =
527 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
528 (link->test_pattern_enabled));
530 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
532 if (use_prefer_link_setting) {
533 link_lane_settings.link_settings.lane_count =
534 link->preferred_link_setting.lane_count;
535 link_lane_settings.link_settings.link_rate =
536 link->preferred_link_setting.link_rate;
537 link_lane_settings.link_settings.link_spread =
538 link->preferred_link_setting.link_spread;
540 link_lane_settings.link_settings.lane_count =
541 link->cur_link_settings.lane_count;
542 link_lane_settings.link_settings.link_rate =
543 link->cur_link_settings.link_rate;
544 link_lane_settings.link_settings.link_spread =
545 link->cur_link_settings.link_spread;
548 /* apply phy settings from user */
549 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
550 link_lane_settings.hw_lane_settings[r].VOLTAGE_SWING =
551 (enum dc_voltage_swing) (param[0]);
552 link_lane_settings.hw_lane_settings[r].PRE_EMPHASIS =
553 (enum dc_pre_emphasis) (param[1]);
554 link_lane_settings.hw_lane_settings[r].POST_CURSOR2 =
555 (enum dc_post_cursor2) (param[2]);
558 /* program ASIC registers and DPCD registers */
559 dc_link_set_drive_settings(dc, &link_lane_settings, link);
565 /* function description
567 * set PHY layer or Link layer test pattern
568 * PHY test pattern is used for PHY SI check.
569 * Link layer test will not affect PHY SI.
571 * Reset Test Pattern:
572 * 0 = DP_TEST_PATTERN_VIDEO_MODE
574 * PHY test pattern supported:
575 * 1 = DP_TEST_PATTERN_D102
576 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
577 * 3 = DP_TEST_PATTERN_PRBS7
578 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
579 * 5 = DP_TEST_PATTERN_CP2520_1
580 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
581 * 7 = DP_TEST_PATTERN_CP2520_3
583 * DP PHY Link Training Patterns
584 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
585 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
586 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
587 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
589 * DP Link Layer Test pattern
590 * c = DP_TEST_PATTERN_COLOR_SQUARES
591 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
592 * e = DP_TEST_PATTERN_VERTICAL_BARS
593 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
594 * 10= DP_TEST_PATTERN_COLOR_RAMP
596 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
598 * --- set test pattern
599 * echo <test pattern #> > test_pattern
601 * If test pattern # is not supported, NO HW programming will be done.
602 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
603 * for the user pattern. input 10 bytes data are separated by space
605 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
607 * --- reset test pattern
608 * echo 0 > test_pattern
610 * --- HPD detection is disabled when set PHY test pattern
612 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
613 * is disable. User could unplug DP display from DP connected and plug scope to
614 * check test pattern PHY SI.
615 * If there is need unplug scope and plug DP display back, do steps below:
616 * echo 0 > phy_test_pattern
620 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
621 * driver could detect "unplug scope" and "plug DP display"
623 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
624 size_t size, loff_t *pos)
626 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
627 struct dc_link *link = connector->dc_link;
629 uint32_t wr_buf_size = 100;
630 long param[11] = {0x0};
631 int max_param_num = 11;
632 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
633 bool disable_hpd = false;
634 bool valid_test_pattern = false;
635 uint8_t param_nums = 0;
636 /* init with default 80bit custom pattern */
637 uint8_t custom_pattern[10] = {
638 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
639 0x1f, 0x7c, 0xf0, 0xc1, 0x07
641 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
642 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
643 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
644 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
645 struct link_training_settings link_training_settings;
651 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
655 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
663 if (param_nums <= 0) {
665 DRM_DEBUG_DRIVER("user data not be read\n");
670 test_pattern = param[0];
672 switch (test_pattern) {
673 case DP_TEST_PATTERN_VIDEO_MODE:
674 case DP_TEST_PATTERN_COLOR_SQUARES:
675 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
676 case DP_TEST_PATTERN_VERTICAL_BARS:
677 case DP_TEST_PATTERN_HORIZONTAL_BARS:
678 case DP_TEST_PATTERN_COLOR_RAMP:
679 valid_test_pattern = true;
682 case DP_TEST_PATTERN_D102:
683 case DP_TEST_PATTERN_SYMBOL_ERROR:
684 case DP_TEST_PATTERN_PRBS7:
685 case DP_TEST_PATTERN_80BIT_CUSTOM:
686 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
687 case DP_TEST_PATTERN_TRAINING_PATTERN4:
689 valid_test_pattern = true;
693 valid_test_pattern = false;
694 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
698 if (!valid_test_pattern) {
700 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
704 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
705 for (i = 0; i < 10; i++) {
706 if ((uint8_t) param[i + 1] != 0x0)
711 /* not use default value */
712 for (i = 0; i < 10; i++)
713 custom_pattern[i] = (uint8_t) param[i + 1];
717 /* Usage: set DP physical test pattern using debugfs with normal DP
718 * panel. Then plug out DP panel and connect a scope to measure
719 * For normal video mode and test pattern generated from CRCT,
720 * they are visibile to user. So do not disable HPD.
721 * Video Mode is also set to clear the test pattern, so enable HPD
722 * because it might have been disabled after a test pattern was set.
723 * AUX depends on HPD * sequence dependent, do not move!
726 dc_link_enable_hpd(link);
728 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
729 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
730 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
732 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
733 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
734 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
736 link_training_settings.link_settings = cur_link_settings;
739 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
740 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
741 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
742 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
743 prefer_link_settings.link_rate != cur_link_settings.link_rate))
744 link_training_settings.link_settings = prefer_link_settings;
747 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
748 link_training_settings.hw_lane_settings[i] = link->cur_lane_setting[i];
750 dc_link_set_test_pattern(
753 DP_TEST_PATTERN_COLOR_SPACE_RGB,
754 &link_training_settings,
758 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
759 * Then plug out DP panel and connect a scope to measure DP PHY signal.
760 * Need disable interrupt to avoid SW driver disable DP output. This is
761 * done after the test pattern is set.
763 if (valid_test_pattern && disable_hpd)
764 dc_link_disable_hpd(link);
772 * Returns the DMCUB tracebuffer contents.
773 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
775 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
777 struct amdgpu_device *adev = m->private;
778 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
779 struct dmub_debugfs_trace_entry *entries;
781 uint32_t tbuf_size, max_entries, num_entries, i;
786 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
790 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
791 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
792 sizeof(struct dmub_debugfs_trace_entry);
795 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
797 num_entries = min(num_entries, max_entries);
799 entries = (struct dmub_debugfs_trace_entry
801 sizeof(struct dmub_debugfs_trace_header));
803 for (i = 0; i < num_entries; ++i) {
804 struct dmub_debugfs_trace_entry *entry = &entries[i];
807 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
808 entry->trace_code, entry->tick_count, entry->param0,
816 * Returns the DMCUB firmware state contents.
817 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
819 static int dmub_fw_state_show(struct seq_file *m, void *data)
821 struct amdgpu_device *adev = m->private;
822 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
829 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
833 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
835 return seq_write(m, state_base, state_size);
838 /* psr_capability_show() - show eDP panel PSR capability
840 * The read function: sink_psr_capability_show
841 * Shows if sink has PSR capability or not.
842 * If yes - the PSR version is appended
844 * cat /sys/kernel/debug/dri/0/eDP-X/psr_capability
847 * "Sink support: no\n" - if panel doesn't support PSR
848 * "Sink support: yes [0x01]\n" - if panel supports PSR1
849 * "Driver support: no\n" - if driver doesn't support PSR
850 * "Driver support: yes [0x01]\n" - if driver supports PSR1
852 static int psr_capability_show(struct seq_file *m, void *data)
854 struct drm_connector *connector = m->private;
855 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
856 struct dc_link *link = aconnector->dc_link;
861 if (link->type == dc_connection_none)
864 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
867 seq_printf(m, "Sink support: %s", str_yes_no(link->dpcd_caps.psr_info.psr_version != 0));
868 if (link->dpcd_caps.psr_info.psr_version)
869 seq_printf(m, " [0x%02x]", link->dpcd_caps.psr_info.psr_version);
872 seq_printf(m, "Driver support: %s", str_yes_no(link->psr_settings.psr_feature_enabled));
873 if (link->psr_settings.psr_version)
874 seq_printf(m, " [0x%02x]", link->psr_settings.psr_version);
881 * Returns the current bpc for the crtc.
882 * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_bpc
884 static int amdgpu_current_bpc_show(struct seq_file *m, void *data)
886 struct drm_crtc *crtc = m->private;
887 struct drm_device *dev = crtc->dev;
888 struct dm_crtc_state *dm_crtc_state = NULL;
892 mutex_lock(&dev->mode_config.mutex);
893 drm_modeset_lock(&crtc->mutex, NULL);
894 if (crtc->state == NULL)
897 dm_crtc_state = to_dm_crtc_state(crtc->state);
898 if (dm_crtc_state->stream == NULL)
901 switch (dm_crtc_state->stream->timing.display_color_depth) {
902 case COLOR_DEPTH_666:
905 case COLOR_DEPTH_888:
908 case COLOR_DEPTH_101010:
911 case COLOR_DEPTH_121212:
914 case COLOR_DEPTH_161616:
921 seq_printf(m, "Current: %u\n", bpc);
925 drm_modeset_unlock(&crtc->mutex);
926 mutex_unlock(&dev->mode_config.mutex);
930 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_bpc);
934 * Disable dsc passthrough, i.e.,: have dsc decoding at converver, not external RX
935 * echo 1 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
936 * Enable dsc passthrough, i.e.,: have dsc passthrough to external RX
937 * echo 0 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
939 static ssize_t dp_dsc_passthrough_set(struct file *f, const char __user *buf,
940 size_t size, loff_t *pos)
942 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
944 uint32_t wr_buf_size = 42;
945 int max_param_num = 1;
947 uint8_t param_nums = 0;
952 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
955 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
959 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
967 aconnector->dsc_settings.dsc_force_disable_passthrough = param;
973 #ifdef CONFIG_DRM_AMD_DC_HDCP
975 * Returns the HDCP capability of the Display (1.4 for now).
977 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
978 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
980 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
981 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
983 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
985 struct drm_connector *connector = m->private;
986 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
987 bool hdcp_cap, hdcp2_cap;
989 if (connector->status != connector_status_connected)
992 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
994 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
995 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
999 seq_printf(m, "%s ", "HDCP1.4");
1001 seq_printf(m, "%s ", "HDCP2.2");
1003 if (!hdcp_cap && !hdcp2_cap)
1004 seq_printf(m, "%s ", "None");
1013 * Returns whether the connected display is internal and not hotpluggable.
1014 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/internal_display
1016 static int internal_display_show(struct seq_file *m, void *data)
1018 struct drm_connector *connector = m->private;
1019 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1020 struct dc_link *link = aconnector->dc_link;
1022 seq_printf(m, "Internal: %u\n", link->is_internal_display);
1027 /* function description
1029 * generic SDP message access for testing
1031 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
1034 * Hb0 : Secondary-Data Packet ID
1035 * Hb1 : Secondary-Data Packet type
1036 * Hb2 : Secondary-Data-packet-specific header, Byte 0
1037 * Hb3 : Secondary-Data-packet-specific header, Byte 1
1039 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
1041 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
1042 size_t size, loff_t *pos)
1046 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1047 struct dm_crtc_state *acrtc_state;
1048 uint32_t write_size = 36;
1050 if (connector->base.status != connector_status_connected)
1056 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
1058 r = copy_from_user(data, buf, write_size);
1062 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
1067 static ssize_t dp_dpcd_address_write(struct file *f, const char __user *buf,
1068 size_t size, loff_t *pos)
1071 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1073 if (size < sizeof(connector->debugfs_dpcd_address))
1076 r = copy_from_user(&connector->debugfs_dpcd_address,
1077 buf, sizeof(connector->debugfs_dpcd_address));
1082 static ssize_t dp_dpcd_size_write(struct file *f, const char __user *buf,
1083 size_t size, loff_t *pos)
1086 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1088 if (size < sizeof(connector->debugfs_dpcd_size))
1091 r = copy_from_user(&connector->debugfs_dpcd_size,
1092 buf, sizeof(connector->debugfs_dpcd_size));
1094 if (connector->debugfs_dpcd_size > 256)
1095 connector->debugfs_dpcd_size = 0;
1100 static ssize_t dp_dpcd_data_write(struct file *f, const char __user *buf,
1101 size_t size, loff_t *pos)
1105 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1106 struct dc_link *link = connector->dc_link;
1107 uint32_t write_size = connector->debugfs_dpcd_size;
1109 if (!write_size || size < write_size)
1112 data = kzalloc(write_size, GFP_KERNEL);
1116 r = copy_from_user(data, buf, write_size);
1118 dm_helpers_dp_write_dpcd(link->ctx, link,
1119 connector->debugfs_dpcd_address, data, write_size - r);
1121 return write_size - r;
1124 static ssize_t dp_dpcd_data_read(struct file *f, char __user *buf,
1125 size_t size, loff_t *pos)
1129 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1130 struct dc_link *link = connector->dc_link;
1131 uint32_t read_size = connector->debugfs_dpcd_size;
1133 if (!read_size || size < read_size)
1136 data = kzalloc(read_size, GFP_KERNEL);
1140 dm_helpers_dp_read_dpcd(link->ctx, link,
1141 connector->debugfs_dpcd_address, data, read_size);
1143 r = copy_to_user(buf, data, read_size);
1146 return read_size - r;
1149 /* function: Read link's DSC & FEC capabilities
1152 * Access it with the following command (you need to specify
1153 * connector like DP-1):
1155 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
1158 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
1160 struct drm_connector *connector = m->private;
1161 struct drm_modeset_acquire_ctx ctx;
1162 struct drm_device *dev = connector->dev;
1163 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1165 bool try_again = false;
1166 bool is_fec_supported = false;
1167 bool is_dsc_supported = false;
1168 struct dpcd_caps dpcd_caps;
1170 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1173 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1175 if (ret == -EDEADLK) {
1176 ret = drm_modeset_backoff(&ctx);
1184 if (connector->status != connector_status_connected) {
1188 dpcd_caps = aconnector->dc_link->dpcd_caps;
1189 if (aconnector->port) {
1190 /* aconnector sets dsc_aux during get_modes call
1191 * if MST connector has it means it can either
1192 * enable DSC on the sink device or on MST branch
1195 if (aconnector->dsc_aux) {
1196 is_fec_supported = true;
1197 is_dsc_supported = true;
1200 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1201 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1203 } while (try_again);
1205 drm_modeset_drop_locks(&ctx);
1206 drm_modeset_acquire_fini(&ctx);
1208 seq_printf(m, "FEC_Sink_Support: %s\n", str_yes_no(is_fec_supported));
1209 seq_printf(m, "DSC_Sink_Support: %s\n", str_yes_no(is_dsc_supported));
1214 /* function: Trigger virtual HPD redetection on connector
1216 * This function will perform link rediscovery, link disable
1217 * and enable, and dm connector state update.
1219 * Retrigger HPD on an existing connector by echoing 1 into
1220 * its respectful "trigger_hotplug" debugfs entry:
1222 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1224 * This function can perform HPD unplug:
1226 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1229 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1230 size_t size, loff_t *pos)
1232 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1233 struct drm_connector *connector = &aconnector->base;
1234 struct dc_link *link = NULL;
1235 struct drm_device *dev = connector->dev;
1236 struct amdgpu_device *adev = drm_to_adev(dev);
1237 enum dc_connection_type new_connection_type = dc_connection_none;
1238 char *wr_buf = NULL;
1239 uint32_t wr_buf_size = 42;
1240 int max_param_num = 1;
1241 long param[1] = {0};
1242 uint8_t param_nums = 0;
1245 if (!aconnector || !aconnector->dc_link)
1251 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1254 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1258 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1268 if (param_nums <= 0) {
1269 DRM_DEBUG_DRIVER("user data not be read\n");
1273 mutex_lock(&aconnector->hpd_lock);
1275 /* Don't support for mst end device*/
1276 if (aconnector->mst_port) {
1277 mutex_unlock(&aconnector->hpd_lock);
1281 if (param[0] == 1) {
1283 if (!dc_link_detect_sink(aconnector->dc_link, &new_connection_type) &&
1284 new_connection_type != dc_connection_none)
1287 mutex_lock(&adev->dm.dc_lock);
1288 ret = dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
1289 mutex_unlock(&adev->dm.dc_lock);
1294 amdgpu_dm_update_connector_after_detect(aconnector);
1296 drm_modeset_lock_all(dev);
1297 dm_restore_drm_connector_state(dev, connector);
1298 drm_modeset_unlock_all(dev);
1300 drm_kms_helper_connector_hotplug_event(connector);
1301 } else if (param[0] == 0) {
1302 if (!aconnector->dc_link)
1305 link = aconnector->dc_link;
1307 if (link->local_sink) {
1308 dc_sink_release(link->local_sink);
1309 link->local_sink = NULL;
1312 link->dpcd_sink_count = 0;
1313 link->type = dc_connection_none;
1314 link->dongle_max_pix_clk = 0;
1316 amdgpu_dm_update_connector_after_detect(aconnector);
1318 /* If the aconnector is the root node in mst topology */
1319 if (aconnector->mst_mgr.mst_state == true)
1320 reset_cur_dp_mst_topology(link);
1322 drm_modeset_lock_all(dev);
1323 dm_restore_drm_connector_state(dev, connector);
1324 drm_modeset_unlock_all(dev);
1326 drm_kms_helper_connector_hotplug_event(connector);
1330 mutex_unlock(&aconnector->hpd_lock);
1335 /* function: read DSC status on the connector
1337 * The read function: dp_dsc_clock_en_read
1338 * returns current status of DSC clock on the connector.
1339 * The return is a boolean flag: 1 or 0.
1341 * Access it with the following command (you need to specify
1342 * connector like DP-1):
1344 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1347 * 1 - means that DSC is currently enabled
1348 * 0 - means that DSC is disabled
1350 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1351 size_t size, loff_t *pos)
1353 char *rd_buf = NULL;
1354 char *rd_buf_ptr = NULL;
1355 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1356 struct display_stream_compressor *dsc;
1357 struct dcn_dsc_state dsc_state = {0};
1358 const uint32_t rd_buf_size = 10;
1359 struct pipe_ctx *pipe_ctx;
1361 int i, r, str_len = 30;
1363 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1368 rd_buf_ptr = rd_buf;
1370 for (i = 0; i < MAX_PIPES; i++) {
1371 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1372 if (pipe_ctx && pipe_ctx->stream &&
1373 pipe_ctx->stream->link == aconnector->dc_link)
1382 dsc = pipe_ctx->stream_res.dsc;
1384 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1386 snprintf(rd_buf_ptr, str_len,
1388 dsc_state.dsc_clock_en);
1389 rd_buf_ptr += str_len;
1392 if (*pos >= rd_buf_size)
1395 r = put_user(*(rd_buf + result), buf);
1398 return r; /* r = -EFAULT */
1411 /* function: write force DSC on the connector
1413 * The write function: dp_dsc_clock_en_write
1414 * enables to force DSC on the connector.
1415 * User can write to either force enable or force disable DSC
1416 * on the next modeset or set it to driver default
1419 * 0 - default DSC enablement policy
1420 * 1 - force enable DSC on the connector
1421 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1423 * Writing DSC settings is done with the following command:
1424 * - To force enable DSC (you need to specify
1425 * connector like DP-1):
1427 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1429 * - To return to default state set the flag to zero and
1430 * let driver deal with DSC automatically
1431 * (you need to specify connector like DP-1):
1433 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1436 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1437 size_t size, loff_t *pos)
1439 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1440 struct drm_connector *connector = &aconnector->base;
1441 struct drm_device *dev = connector->dev;
1442 struct drm_crtc *crtc = NULL;
1443 struct dm_crtc_state *dm_crtc_state = NULL;
1444 struct pipe_ctx *pipe_ctx;
1446 char *wr_buf = NULL;
1447 uint32_t wr_buf_size = 42;
1448 int max_param_num = 1;
1449 long param[1] = {0};
1450 uint8_t param_nums = 0;
1455 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1458 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1462 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1470 if (param_nums <= 0) {
1471 DRM_DEBUG_DRIVER("user data not be read\n");
1476 for (i = 0; i < MAX_PIPES; i++) {
1477 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1478 if (pipe_ctx && pipe_ctx->stream &&
1479 pipe_ctx->stream->link == aconnector->dc_link)
1483 if (!pipe_ctx || !pipe_ctx->stream)
1487 mutex_lock(&dev->mode_config.mutex);
1488 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1490 if (connector->state == NULL)
1493 crtc = connector->state->crtc;
1497 drm_modeset_lock(&crtc->mutex, NULL);
1498 if (crtc->state == NULL)
1501 dm_crtc_state = to_dm_crtc_state(crtc->state);
1502 if (dm_crtc_state->stream == NULL)
1506 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1507 else if (param[0] == 2)
1508 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1510 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1512 dm_crtc_state->dsc_force_changed = true;
1516 drm_modeset_unlock(&crtc->mutex);
1517 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1518 mutex_unlock(&dev->mode_config.mutex);
1525 /* function: read DSC slice width parameter on the connector
1527 * The read function: dp_dsc_slice_width_read
1528 * returns dsc slice width used in the current configuration
1529 * The return is an integer: 0 or other positive number
1531 * Access the status with the following command:
1533 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1535 * 0 - means that DSC is disabled
1537 * Any other number more than zero represents the
1538 * slice width currently used by DSC in pixels
1541 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1542 size_t size, loff_t *pos)
1544 char *rd_buf = NULL;
1545 char *rd_buf_ptr = NULL;
1546 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1547 struct display_stream_compressor *dsc;
1548 struct dcn_dsc_state dsc_state = {0};
1549 const uint32_t rd_buf_size = 100;
1550 struct pipe_ctx *pipe_ctx;
1552 int i, r, str_len = 30;
1554 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1559 rd_buf_ptr = rd_buf;
1561 for (i = 0; i < MAX_PIPES; i++) {
1562 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1563 if (pipe_ctx && pipe_ctx->stream &&
1564 pipe_ctx->stream->link == aconnector->dc_link)
1573 dsc = pipe_ctx->stream_res.dsc;
1575 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1577 snprintf(rd_buf_ptr, str_len,
1579 dsc_state.dsc_slice_width);
1580 rd_buf_ptr += str_len;
1583 if (*pos >= rd_buf_size)
1586 r = put_user(*(rd_buf + result), buf);
1589 return r; /* r = -EFAULT */
1602 /* function: write DSC slice width parameter
1604 * The write function: dp_dsc_slice_width_write
1605 * overwrites automatically generated DSC configuration
1608 * The user has to write the slice width divisible by the
1611 * Also the user has to write width in hexidecimal
1612 * rather than in decimal.
1614 * Writing DSC settings is done with the following command:
1615 * - To force overwrite slice width: (example sets to 1920 pixels)
1617 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1619 * - To stop overwriting and let driver find the optimal size,
1620 * set the width to zero:
1622 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1625 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1626 size_t size, loff_t *pos)
1628 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1629 struct pipe_ctx *pipe_ctx;
1630 struct drm_connector *connector = &aconnector->base;
1631 struct drm_device *dev = connector->dev;
1632 struct drm_crtc *crtc = NULL;
1633 struct dm_crtc_state *dm_crtc_state = NULL;
1635 char *wr_buf = NULL;
1636 uint32_t wr_buf_size = 42;
1637 int max_param_num = 1;
1638 long param[1] = {0};
1639 uint8_t param_nums = 0;
1644 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1647 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1651 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1659 if (param_nums <= 0) {
1660 DRM_DEBUG_DRIVER("user data not be read\n");
1665 for (i = 0; i < MAX_PIPES; i++) {
1666 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1667 if (pipe_ctx && pipe_ctx->stream &&
1668 pipe_ctx->stream->link == aconnector->dc_link)
1672 if (!pipe_ctx || !pipe_ctx->stream)
1675 // Safely get CRTC state
1676 mutex_lock(&dev->mode_config.mutex);
1677 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1679 if (connector->state == NULL)
1682 crtc = connector->state->crtc;
1686 drm_modeset_lock(&crtc->mutex, NULL);
1687 if (crtc->state == NULL)
1690 dm_crtc_state = to_dm_crtc_state(crtc->state);
1691 if (dm_crtc_state->stream == NULL)
1695 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1696 pipe_ctx->stream->timing.h_addressable,
1699 aconnector->dsc_settings.dsc_num_slices_h = 0;
1701 dm_crtc_state->dsc_force_changed = true;
1705 drm_modeset_unlock(&crtc->mutex);
1706 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1707 mutex_unlock(&dev->mode_config.mutex);
1714 /* function: read DSC slice height parameter on the connector
1716 * The read function: dp_dsc_slice_height_read
1717 * returns dsc slice height used in the current configuration
1718 * The return is an integer: 0 or other positive number
1720 * Access the status with the following command:
1722 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1724 * 0 - means that DSC is disabled
1726 * Any other number more than zero represents the
1727 * slice height currently used by DSC in pixels
1730 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1731 size_t size, loff_t *pos)
1733 char *rd_buf = NULL;
1734 char *rd_buf_ptr = NULL;
1735 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1736 struct display_stream_compressor *dsc;
1737 struct dcn_dsc_state dsc_state = {0};
1738 const uint32_t rd_buf_size = 100;
1739 struct pipe_ctx *pipe_ctx;
1741 int i, r, str_len = 30;
1743 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1748 rd_buf_ptr = rd_buf;
1750 for (i = 0; i < MAX_PIPES; i++) {
1751 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1752 if (pipe_ctx && pipe_ctx->stream &&
1753 pipe_ctx->stream->link == aconnector->dc_link)
1762 dsc = pipe_ctx->stream_res.dsc;
1764 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1766 snprintf(rd_buf_ptr, str_len,
1768 dsc_state.dsc_slice_height);
1769 rd_buf_ptr += str_len;
1772 if (*pos >= rd_buf_size)
1775 r = put_user(*(rd_buf + result), buf);
1778 return r; /* r = -EFAULT */
1791 /* function: write DSC slice height parameter
1793 * The write function: dp_dsc_slice_height_write
1794 * overwrites automatically generated DSC configuration
1797 * The user has to write the slice height divisible by the
1800 * Also the user has to write height in hexidecimal
1801 * rather than in decimal.
1803 * Writing DSC settings is done with the following command:
1804 * - To force overwrite slice height (example sets to 128 pixels):
1806 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1808 * - To stop overwriting and let driver find the optimal size,
1809 * set the height to zero:
1811 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1814 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1815 size_t size, loff_t *pos)
1817 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1818 struct drm_connector *connector = &aconnector->base;
1819 struct drm_device *dev = connector->dev;
1820 struct drm_crtc *crtc = NULL;
1821 struct dm_crtc_state *dm_crtc_state = NULL;
1822 struct pipe_ctx *pipe_ctx;
1824 char *wr_buf = NULL;
1825 uint32_t wr_buf_size = 42;
1826 int max_param_num = 1;
1827 uint8_t param_nums = 0;
1828 long param[1] = {0};
1833 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1836 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1840 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1848 if (param_nums <= 0) {
1849 DRM_DEBUG_DRIVER("user data not be read\n");
1854 for (i = 0; i < MAX_PIPES; i++) {
1855 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1856 if (pipe_ctx && pipe_ctx->stream &&
1857 pipe_ctx->stream->link == aconnector->dc_link)
1861 if (!pipe_ctx || !pipe_ctx->stream)
1865 mutex_lock(&dev->mode_config.mutex);
1866 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1868 if (connector->state == NULL)
1871 crtc = connector->state->crtc;
1875 drm_modeset_lock(&crtc->mutex, NULL);
1876 if (crtc->state == NULL)
1879 dm_crtc_state = to_dm_crtc_state(crtc->state);
1880 if (dm_crtc_state->stream == NULL)
1884 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1885 pipe_ctx->stream->timing.v_addressable,
1888 aconnector->dsc_settings.dsc_num_slices_v = 0;
1890 dm_crtc_state->dsc_force_changed = true;
1894 drm_modeset_unlock(&crtc->mutex);
1895 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1896 mutex_unlock(&dev->mode_config.mutex);
1903 /* function: read DSC target rate on the connector in bits per pixel
1905 * The read function: dp_dsc_bits_per_pixel_read
1906 * returns target rate of compression in bits per pixel
1907 * The return is an integer: 0 or other positive integer
1909 * Access it with the following command:
1911 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1913 * 0 - means that DSC is disabled
1915 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
1916 size_t size, loff_t *pos)
1918 char *rd_buf = NULL;
1919 char *rd_buf_ptr = NULL;
1920 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1921 struct display_stream_compressor *dsc;
1922 struct dcn_dsc_state dsc_state = {0};
1923 const uint32_t rd_buf_size = 100;
1924 struct pipe_ctx *pipe_ctx;
1926 int i, r, str_len = 30;
1928 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1933 rd_buf_ptr = rd_buf;
1935 for (i = 0; i < MAX_PIPES; i++) {
1936 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1937 if (pipe_ctx && pipe_ctx->stream &&
1938 pipe_ctx->stream->link == aconnector->dc_link)
1947 dsc = pipe_ctx->stream_res.dsc;
1949 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1951 snprintf(rd_buf_ptr, str_len,
1953 dsc_state.dsc_bits_per_pixel);
1954 rd_buf_ptr += str_len;
1957 if (*pos >= rd_buf_size)
1960 r = put_user(*(rd_buf + result), buf);
1963 return r; /* r = -EFAULT */
1976 /* function: write DSC target rate in bits per pixel
1978 * The write function: dp_dsc_bits_per_pixel_write
1979 * overwrites automatically generated DSC configuration
1980 * of DSC target bit rate.
1982 * Also the user has to write bpp in hexidecimal
1983 * rather than in decimal.
1985 * Writing DSC settings is done with the following command:
1986 * - To force overwrite rate (example sets to 256 bpp x 1/16):
1988 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1990 * - To stop overwriting and let driver find the optimal rate,
1991 * set the rate to zero:
1993 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1996 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
1997 size_t size, loff_t *pos)
1999 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2000 struct drm_connector *connector = &aconnector->base;
2001 struct drm_device *dev = connector->dev;
2002 struct drm_crtc *crtc = NULL;
2003 struct dm_crtc_state *dm_crtc_state = NULL;
2004 struct pipe_ctx *pipe_ctx;
2006 char *wr_buf = NULL;
2007 uint32_t wr_buf_size = 42;
2008 int max_param_num = 1;
2009 uint8_t param_nums = 0;
2010 long param[1] = {0};
2015 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2018 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2022 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2030 if (param_nums <= 0) {
2031 DRM_DEBUG_DRIVER("user data not be read\n");
2036 for (i = 0; i < MAX_PIPES; i++) {
2037 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2038 if (pipe_ctx && pipe_ctx->stream &&
2039 pipe_ctx->stream->link == aconnector->dc_link)
2043 if (!pipe_ctx || !pipe_ctx->stream)
2047 mutex_lock(&dev->mode_config.mutex);
2048 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2050 if (connector->state == NULL)
2053 crtc = connector->state->crtc;
2057 drm_modeset_lock(&crtc->mutex, NULL);
2058 if (crtc->state == NULL)
2061 dm_crtc_state = to_dm_crtc_state(crtc->state);
2062 if (dm_crtc_state->stream == NULL)
2065 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
2067 dm_crtc_state->dsc_force_changed = true;
2071 drm_modeset_unlock(&crtc->mutex);
2072 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2073 mutex_unlock(&dev->mode_config.mutex);
2080 /* function: read DSC picture width parameter on the connector
2082 * The read function: dp_dsc_pic_width_read
2083 * returns dsc picture width used in the current configuration
2084 * It is the same as h_addressable of the current
2086 * The return is an integer: 0 or other positive integer
2087 * If 0 then DSC is disabled.
2089 * Access it with the following command:
2091 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
2093 * 0 - means that DSC is disabled
2095 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
2096 size_t size, loff_t *pos)
2098 char *rd_buf = NULL;
2099 char *rd_buf_ptr = NULL;
2100 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2101 struct display_stream_compressor *dsc;
2102 struct dcn_dsc_state dsc_state = {0};
2103 const uint32_t rd_buf_size = 100;
2104 struct pipe_ctx *pipe_ctx;
2106 int i, r, str_len = 30;
2108 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2113 rd_buf_ptr = rd_buf;
2115 for (i = 0; i < MAX_PIPES; i++) {
2116 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2117 if (pipe_ctx && pipe_ctx->stream &&
2118 pipe_ctx->stream->link == aconnector->dc_link)
2127 dsc = pipe_ctx->stream_res.dsc;
2129 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2131 snprintf(rd_buf_ptr, str_len,
2133 dsc_state.dsc_pic_width);
2134 rd_buf_ptr += str_len;
2137 if (*pos >= rd_buf_size)
2140 r = put_user(*(rd_buf + result), buf);
2143 return r; /* r = -EFAULT */
2156 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
2157 size_t size, loff_t *pos)
2159 char *rd_buf = NULL;
2160 char *rd_buf_ptr = NULL;
2161 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2162 struct display_stream_compressor *dsc;
2163 struct dcn_dsc_state dsc_state = {0};
2164 const uint32_t rd_buf_size = 100;
2165 struct pipe_ctx *pipe_ctx;
2167 int i, r, str_len = 30;
2169 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2174 rd_buf_ptr = rd_buf;
2176 for (i = 0; i < MAX_PIPES; i++) {
2177 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2178 if (pipe_ctx && pipe_ctx->stream &&
2179 pipe_ctx->stream->link == aconnector->dc_link)
2188 dsc = pipe_ctx->stream_res.dsc;
2190 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2192 snprintf(rd_buf_ptr, str_len,
2194 dsc_state.dsc_pic_height);
2195 rd_buf_ptr += str_len;
2198 if (*pos >= rd_buf_size)
2201 r = put_user(*(rd_buf + result), buf);
2204 return r; /* r = -EFAULT */
2217 /* function: read DSC chunk size parameter on the connector
2219 * The read function: dp_dsc_chunk_size_read
2220 * returns dsc chunk size set in the current configuration
2221 * The value is calculated automatically by DSC code
2222 * and depends on slice parameters and bpp target rate
2223 * The return is an integer: 0 or other positive integer
2224 * If 0 then DSC is disabled.
2226 * Access it with the following command:
2228 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2230 * 0 - means that DSC is disabled
2232 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2233 size_t size, loff_t *pos)
2235 char *rd_buf = NULL;
2236 char *rd_buf_ptr = NULL;
2237 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2238 struct display_stream_compressor *dsc;
2239 struct dcn_dsc_state dsc_state = {0};
2240 const uint32_t rd_buf_size = 100;
2241 struct pipe_ctx *pipe_ctx;
2243 int i, r, str_len = 30;
2245 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2250 rd_buf_ptr = rd_buf;
2252 for (i = 0; i < MAX_PIPES; i++) {
2253 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2254 if (pipe_ctx && pipe_ctx->stream &&
2255 pipe_ctx->stream->link == aconnector->dc_link)
2264 dsc = pipe_ctx->stream_res.dsc;
2266 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2268 snprintf(rd_buf_ptr, str_len,
2270 dsc_state.dsc_chunk_size);
2271 rd_buf_ptr += str_len;
2274 if (*pos >= rd_buf_size)
2277 r = put_user(*(rd_buf + result), buf);
2280 return r; /* r = -EFAULT */
2293 /* function: read DSC slice bpg offset on the connector
2295 * The read function: dp_dsc_slice_bpg_offset_read
2296 * returns dsc bpg slice offset set in the current configuration
2297 * The value is calculated automatically by DSC code
2298 * and depends on slice parameters and bpp target rate
2299 * The return is an integer: 0 or other positive integer
2300 * If 0 then DSC is disabled.
2302 * Access it with the following command:
2304 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2306 * 0 - means that DSC is disabled
2308 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2309 size_t size, loff_t *pos)
2311 char *rd_buf = NULL;
2312 char *rd_buf_ptr = NULL;
2313 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2314 struct display_stream_compressor *dsc;
2315 struct dcn_dsc_state dsc_state = {0};
2316 const uint32_t rd_buf_size = 100;
2317 struct pipe_ctx *pipe_ctx;
2319 int i, r, str_len = 30;
2321 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2326 rd_buf_ptr = rd_buf;
2328 for (i = 0; i < MAX_PIPES; i++) {
2329 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2330 if (pipe_ctx && pipe_ctx->stream &&
2331 pipe_ctx->stream->link == aconnector->dc_link)
2340 dsc = pipe_ctx->stream_res.dsc;
2342 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2344 snprintf(rd_buf_ptr, str_len,
2346 dsc_state.dsc_slice_bpg_offset);
2347 rd_buf_ptr += str_len;
2350 if (*pos >= rd_buf_size)
2353 r = put_user(*(rd_buf + result), buf);
2356 return r; /* r = -EFAULT */
2371 * function description: Read max_requested_bpc property from the connector
2373 * Access it with the following command:
2375 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2378 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2379 size_t size, loff_t *pos)
2381 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2382 struct drm_connector *connector = &aconnector->base;
2383 struct drm_device *dev = connector->dev;
2384 struct dm_connector_state *state;
2386 char *rd_buf = NULL;
2387 char *rd_buf_ptr = NULL;
2388 const uint32_t rd_buf_size = 10;
2391 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2396 mutex_lock(&dev->mode_config.mutex);
2397 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2399 if (connector->state == NULL)
2402 state = to_dm_connector_state(connector->state);
2404 rd_buf_ptr = rd_buf;
2405 snprintf(rd_buf_ptr, rd_buf_size,
2407 state->base.max_requested_bpc);
2410 if (*pos >= rd_buf_size)
2413 r = put_user(*(rd_buf + result), buf);
2415 result = r; /* r = -EFAULT */
2424 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2425 mutex_unlock(&dev->mode_config.mutex);
2432 * function description: Set max_requested_bpc property on the connector
2434 * This function will not force the input BPC on connector, it will only
2435 * change the max value. This is equivalent to setting max_bpc through
2438 * The BPC value written must be >= 6 and <= 16. Values outside of this
2439 * range will result in errors.
2448 * Write the max_bpc in the following way:
2450 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2453 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2454 size_t size, loff_t *pos)
2456 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2457 struct drm_connector *connector = &aconnector->base;
2458 struct dm_connector_state *state;
2459 struct drm_device *dev = connector->dev;
2460 char *wr_buf = NULL;
2461 uint32_t wr_buf_size = 42;
2462 int max_param_num = 1;
2463 long param[1] = {0};
2464 uint8_t param_nums = 0;
2469 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2472 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2476 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2484 if (param_nums <= 0) {
2485 DRM_DEBUG_DRIVER("user data not be read\n");
2490 if (param[0] < 6 || param[0] > 16) {
2491 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2496 mutex_lock(&dev->mode_config.mutex);
2497 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2499 if (connector->state == NULL)
2502 state = to_dm_connector_state(connector->state);
2503 state->base.max_requested_bpc = param[0];
2505 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2506 mutex_unlock(&dev->mode_config.mutex);
2513 * Backlight at this moment. Read only.
2514 * As written to display, taking ABM and backlight lut into account.
2515 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2517 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/current_backlight
2519 static int current_backlight_show(struct seq_file *m, void *unused)
2521 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2522 struct dc_link *link = aconnector->dc_link;
2523 unsigned int backlight;
2525 backlight = dc_link_get_backlight_level(link);
2526 seq_printf(m, "0x%x\n", backlight);
2532 * Backlight value that is being approached. Read only.
2533 * As written to display, taking ABM and backlight lut into account.
2534 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2536 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/target_backlight
2538 static int target_backlight_show(struct seq_file *m, void *unused)
2540 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2541 struct dc_link *link = aconnector->dc_link;
2542 unsigned int backlight;
2544 backlight = dc_link_get_target_backlight_pwm(link);
2545 seq_printf(m, "0x%x\n", backlight);
2551 * function description: Determine if the connector is mst connector
2553 * This function helps to determine whether a connector is a mst connector.
2554 * - "root" stands for the root connector of the topology
2555 * - "branch" stands for branch device of the topology
2556 * - "end" stands for leaf node connector of the topology
2557 * - "no" stands for the connector is not a device of a mst topology
2558 * Access it with the following command:
2560 * cat /sys/kernel/debug/dri/0/DP-X/is_mst_connector
2563 static int dp_is_mst_connector_show(struct seq_file *m, void *unused)
2565 struct drm_connector *connector = m->private;
2566 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2567 struct drm_dp_mst_topology_mgr *mgr = NULL;
2568 struct drm_dp_mst_port *port = NULL;
2571 mutex_lock(&aconnector->hpd_lock);
2573 if (aconnector->mst_mgr.mst_state) {
2575 } else if (aconnector->mst_port &&
2576 aconnector->mst_port->mst_mgr.mst_state) {
2580 mgr = &aconnector->mst_port->mst_mgr;
2581 port = aconnector->port;
2583 drm_modeset_lock(&mgr->base.lock, NULL);
2584 if (port->pdt == DP_PEER_DEVICE_MST_BRANCHING &&
2587 drm_modeset_unlock(&mgr->base.lock);
2593 seq_printf(m, "%s\n", role);
2595 mutex_unlock(&aconnector->hpd_lock);
2601 * function description: Read out the mst progress status
2603 * This function helps to determine the mst progress status of
2606 * Access it with the following command:
2608 * cat /sys/kernel/debug/dri/0/DP-X/mst_progress_status
2611 static int dp_mst_progress_status_show(struct seq_file *m, void *unused)
2613 struct drm_connector *connector = m->private;
2614 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2615 struct amdgpu_device *adev = drm_to_adev(connector->dev);
2618 mutex_lock(&aconnector->hpd_lock);
2619 mutex_lock(&adev->dm.dc_lock);
2621 if (aconnector->mst_status == MST_STATUS_DEFAULT) {
2622 seq_puts(m, "disabled\n");
2624 for (i = 0; i < sizeof(mst_progress_status)/sizeof(char *); i++)
2625 seq_printf(m, "%s:%s\n",
2626 mst_progress_status[i],
2627 aconnector->mst_status & BIT(i) ? "done" : "not_done");
2630 mutex_unlock(&adev->dm.dc_lock);
2631 mutex_unlock(&aconnector->hpd_lock);
2636 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2637 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2638 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2639 DEFINE_SHOW_ATTRIBUTE(dp_lttpr_status);
2640 #ifdef CONFIG_DRM_AMD_DC_HDCP
2641 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2643 DEFINE_SHOW_ATTRIBUTE(internal_display);
2644 DEFINE_SHOW_ATTRIBUTE(psr_capability);
2645 DEFINE_SHOW_ATTRIBUTE(dp_is_mst_connector);
2646 DEFINE_SHOW_ATTRIBUTE(dp_mst_progress_status);
2648 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2649 .owner = THIS_MODULE,
2650 .read = dp_dsc_clock_en_read,
2651 .write = dp_dsc_clock_en_write,
2652 .llseek = default_llseek
2655 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2656 .owner = THIS_MODULE,
2657 .read = dp_dsc_slice_width_read,
2658 .write = dp_dsc_slice_width_write,
2659 .llseek = default_llseek
2662 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2663 .owner = THIS_MODULE,
2664 .read = dp_dsc_slice_height_read,
2665 .write = dp_dsc_slice_height_write,
2666 .llseek = default_llseek
2669 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2670 .owner = THIS_MODULE,
2671 .read = dp_dsc_bits_per_pixel_read,
2672 .write = dp_dsc_bits_per_pixel_write,
2673 .llseek = default_llseek
2676 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2677 .owner = THIS_MODULE,
2678 .read = dp_dsc_pic_width_read,
2679 .llseek = default_llseek
2682 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2683 .owner = THIS_MODULE,
2684 .read = dp_dsc_pic_height_read,
2685 .llseek = default_llseek
2688 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2689 .owner = THIS_MODULE,
2690 .read = dp_dsc_chunk_size_read,
2691 .llseek = default_llseek
2694 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2695 .owner = THIS_MODULE,
2696 .read = dp_dsc_slice_bpg_offset_read,
2697 .llseek = default_llseek
2700 static const struct file_operations trigger_hotplug_debugfs_fops = {
2701 .owner = THIS_MODULE,
2702 .write = trigger_hotplug,
2703 .llseek = default_llseek
2706 static const struct file_operations dp_link_settings_debugfs_fops = {
2707 .owner = THIS_MODULE,
2708 .read = dp_link_settings_read,
2709 .write = dp_link_settings_write,
2710 .llseek = default_llseek
2713 static const struct file_operations dp_phy_settings_debugfs_fop = {
2714 .owner = THIS_MODULE,
2715 .read = dp_phy_settings_read,
2716 .write = dp_phy_settings_write,
2717 .llseek = default_llseek
2720 static const struct file_operations dp_phy_test_pattern_fops = {
2721 .owner = THIS_MODULE,
2722 .write = dp_phy_test_pattern_debugfs_write,
2723 .llseek = default_llseek
2726 static const struct file_operations sdp_message_fops = {
2727 .owner = THIS_MODULE,
2728 .write = dp_sdp_message_debugfs_write,
2729 .llseek = default_llseek
2732 static const struct file_operations dp_dpcd_address_debugfs_fops = {
2733 .owner = THIS_MODULE,
2734 .write = dp_dpcd_address_write,
2735 .llseek = default_llseek
2738 static const struct file_operations dp_dpcd_size_debugfs_fops = {
2739 .owner = THIS_MODULE,
2740 .write = dp_dpcd_size_write,
2741 .llseek = default_llseek
2744 static const struct file_operations dp_dpcd_data_debugfs_fops = {
2745 .owner = THIS_MODULE,
2746 .read = dp_dpcd_data_read,
2747 .write = dp_dpcd_data_write,
2748 .llseek = default_llseek
2751 static const struct file_operations dp_max_bpc_debugfs_fops = {
2752 .owner = THIS_MODULE,
2753 .read = dp_max_bpc_read,
2754 .write = dp_max_bpc_write,
2755 .llseek = default_llseek
2758 static const struct file_operations dp_dsc_disable_passthrough_debugfs_fops = {
2759 .owner = THIS_MODULE,
2760 .write = dp_dsc_passthrough_set,
2761 .llseek = default_llseek
2764 static const struct {
2766 const struct file_operations *fops;
2767 } dp_debugfs_entries[] = {
2768 {"link_settings", &dp_link_settings_debugfs_fops},
2769 {"phy_settings", &dp_phy_settings_debugfs_fop},
2770 {"lttpr_status", &dp_lttpr_status_fops},
2771 {"test_pattern", &dp_phy_test_pattern_fops},
2772 #ifdef CONFIG_DRM_AMD_DC_HDCP
2773 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2775 {"sdp_message", &sdp_message_fops},
2776 {"aux_dpcd_address", &dp_dpcd_address_debugfs_fops},
2777 {"aux_dpcd_size", &dp_dpcd_size_debugfs_fops},
2778 {"aux_dpcd_data", &dp_dpcd_data_debugfs_fops},
2779 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2780 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2781 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2782 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2783 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2784 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2785 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2786 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2787 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
2788 {"max_bpc", &dp_max_bpc_debugfs_fops},
2789 {"dsc_disable_passthrough", &dp_dsc_disable_passthrough_debugfs_fops},
2790 {"is_mst_connector", &dp_is_mst_connector_fops},
2791 {"mst_progress_status", &dp_mst_progress_status_fops}
2794 #ifdef CONFIG_DRM_AMD_DC_HDCP
2795 static const struct {
2797 const struct file_operations *fops;
2798 } hdmi_debugfs_entries[] = {
2799 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
2803 * Force YUV420 output if available from the given mode
2805 static int force_yuv420_output_set(void *data, u64 val)
2807 struct amdgpu_dm_connector *connector = data;
2809 connector->force_yuv420_output = (bool)val;
2815 * Check if YUV420 is forced when available from the given mode
2817 static int force_yuv420_output_get(void *data, u64 *val)
2819 struct amdgpu_dm_connector *connector = data;
2821 *val = connector->force_yuv420_output;
2826 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2827 force_yuv420_output_set, "%llu\n");
2832 static int psr_get(void *data, u64 *val)
2834 struct amdgpu_dm_connector *connector = data;
2835 struct dc_link *link = connector->dc_link;
2836 enum dc_psr_state state = PSR_STATE0;
2838 dc_link_get_psr_state(link, &state);
2846 * Set dmcub trace event IRQ enable or disable.
2847 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2848 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2850 static int dmcub_trace_event_state_set(void *data, u64 val)
2852 struct amdgpu_device *adev = data;
2854 if (val == 1 || val == 0) {
2855 dc_dmub_trace_event_control(adev->dm.dc, val);
2856 adev->dm.dmcub_trace_event_en = (bool)val;
2864 * The interface doesn't need get function, so it will return the
2866 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2868 static int dmcub_trace_event_state_get(void *data, u64 *val)
2870 struct amdgpu_device *adev = data;
2872 *val = adev->dm.dmcub_trace_event_en;
2876 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
2877 dmcub_trace_event_state_set, "%llu\n");
2879 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
2881 DEFINE_SHOW_ATTRIBUTE(current_backlight);
2882 DEFINE_SHOW_ATTRIBUTE(target_backlight);
2884 static const struct {
2886 const struct file_operations *fops;
2887 } connector_debugfs_entries[] = {
2888 {"force_yuv420_output", &force_yuv420_output_fops},
2889 {"trigger_hotplug", &trigger_hotplug_debugfs_fops},
2890 {"internal_display", &internal_display_fops}
2894 * Returns supported customized link rates by this eDP panel.
2895 * Example usage: cat /sys/kernel/debug/dri/0/eDP-x/ilr_setting
2897 static int edp_ilr_show(struct seq_file *m, void *unused)
2899 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2900 struct dc_link *link = aconnector->dc_link;
2901 uint8_t supported_link_rates[16];
2902 uint32_t link_rate_in_khz;
2906 memset(supported_link_rates, 0, sizeof(supported_link_rates));
2907 dm_helpers_dp_read_dpcd(link->ctx, link, DP_SUPPORTED_LINK_RATES,
2908 supported_link_rates, sizeof(supported_link_rates));
2910 dpcd_rev = link->dpcd_caps.dpcd_rev.raw;
2912 if (dpcd_rev >= DP_DPCD_REV_13 &&
2913 (supported_link_rates[entry+1] != 0 || supported_link_rates[entry] != 0)) {
2915 for (entry = 0; entry < 16; entry += 2) {
2916 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
2917 supported_link_rates[entry]) * 200;
2918 seq_printf(m, "[%d] %d kHz\n", entry/2, link_rate_in_khz);
2921 seq_printf(m, "ILR is not supported by this eDP panel.\n");
2928 * Set supported customized link rate to eDP panel.
2930 * echo <lane_count> <link_rate option> > ilr_setting
2932 * for example, supported ILR : [0] 1620000 kHz [1] 2160000 kHz [2] 2430000 kHz ...
2933 * echo 4 1 > /sys/kernel/debug/dri/0/eDP-x/ilr_setting
2934 * to set 4 lanes and 2.16 GHz
2936 static ssize_t edp_ilr_write(struct file *f, const char __user *buf,
2937 size_t size, loff_t *pos)
2939 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
2940 struct dc_link *link = connector->dc_link;
2941 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
2942 struct dc *dc = (struct dc *)link->dc;
2943 struct dc_link_settings prefer_link_settings;
2944 char *wr_buf = NULL;
2945 const uint32_t wr_buf_size = 40;
2946 /* 0: lane_count; 1: link_rate */
2947 int max_param_num = 2;
2948 uint8_t param_nums = 0;
2950 bool valid_input = true;
2955 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2959 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2967 if (param_nums <= 0) {
2973 case LANE_COUNT_ONE:
2974 case LANE_COUNT_TWO:
2975 case LANE_COUNT_FOUR:
2978 valid_input = false;
2982 if (param[1] >= link->dpcd_caps.edp_supported_link_rates_count)
2983 valid_input = false;
2987 DRM_DEBUG_DRIVER("Invalid Input value. No HW will be programmed\n");
2988 prefer_link_settings.use_link_rate_set = false;
2989 mutex_lock(&adev->dm.dc_lock);
2990 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
2991 mutex_unlock(&adev->dm.dc_lock);
2995 /* save user force lane_count, link_rate to preferred settings
2996 * spread spectrum will not be changed
2998 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
2999 prefer_link_settings.lane_count = param[0];
3000 prefer_link_settings.use_link_rate_set = true;
3001 prefer_link_settings.link_rate_set = param[1];
3002 prefer_link_settings.link_rate = link->dpcd_caps.edp_supported_link_rates[param[1]];
3004 mutex_lock(&adev->dm.dc_lock);
3005 dc_link_set_preferred_training_settings(dc, &prefer_link_settings,
3007 mutex_unlock(&adev->dm.dc_lock);
3013 static int edp_ilr_open(struct inode *inode, struct file *file)
3015 return single_open(file, edp_ilr_show, inode->i_private);
3018 static const struct file_operations edp_ilr_debugfs_fops = {
3019 .owner = THIS_MODULE,
3020 .open = edp_ilr_open,
3022 .llseek = seq_lseek,
3023 .release = single_release,
3024 .write = edp_ilr_write
3027 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
3030 struct dentry *dir = connector->base.debugfs_entry;
3032 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
3033 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3034 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
3035 debugfs_create_file(dp_debugfs_entries[i].name,
3036 0644, dir, connector,
3037 dp_debugfs_entries[i].fops);
3040 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3041 debugfs_create_file_unsafe("psr_capability", 0444, dir, connector, &psr_capability_fops);
3042 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
3043 debugfs_create_file("amdgpu_current_backlight_pwm", 0444, dir, connector,
3044 ¤t_backlight_fops);
3045 debugfs_create_file("amdgpu_target_backlight_pwm", 0444, dir, connector,
3046 &target_backlight_fops);
3047 debugfs_create_file("ilr_setting", 0644, dir, connector,
3048 &edp_ilr_debugfs_fops);
3051 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
3052 debugfs_create_file(connector_debugfs_entries[i].name,
3053 0644, dir, connector,
3054 connector_debugfs_entries[i].fops);
3057 connector->debugfs_dpcd_address = 0;
3058 connector->debugfs_dpcd_size = 0;
3060 #ifdef CONFIG_DRM_AMD_DC_HDCP
3061 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
3062 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
3063 debugfs_create_file(hdmi_debugfs_entries[i].name,
3064 0644, dir, connector,
3065 hdmi_debugfs_entries[i].fops);
3071 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3073 * Set crc window coordinate x start
3075 static int crc_win_x_start_set(void *data, u64 val)
3077 struct drm_crtc *crtc = data;
3078 struct drm_device *drm_dev = crtc->dev;
3079 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3081 spin_lock_irq(&drm_dev->event_lock);
3082 acrtc->dm_irq_params.crc_window.x_start = (uint16_t) val;
3083 acrtc->dm_irq_params.crc_window.update_win = false;
3084 spin_unlock_irq(&drm_dev->event_lock);
3090 * Get crc window coordinate x start
3092 static int crc_win_x_start_get(void *data, u64 *val)
3094 struct drm_crtc *crtc = data;
3095 struct drm_device *drm_dev = crtc->dev;
3096 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3098 spin_lock_irq(&drm_dev->event_lock);
3099 *val = acrtc->dm_irq_params.crc_window.x_start;
3100 spin_unlock_irq(&drm_dev->event_lock);
3105 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
3106 crc_win_x_start_set, "%llu\n");
3110 * Set crc window coordinate y start
3112 static int crc_win_y_start_set(void *data, u64 val)
3114 struct drm_crtc *crtc = data;
3115 struct drm_device *drm_dev = crtc->dev;
3116 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3118 spin_lock_irq(&drm_dev->event_lock);
3119 acrtc->dm_irq_params.crc_window.y_start = (uint16_t) val;
3120 acrtc->dm_irq_params.crc_window.update_win = false;
3121 spin_unlock_irq(&drm_dev->event_lock);
3127 * Get crc window coordinate y start
3129 static int crc_win_y_start_get(void *data, u64 *val)
3131 struct drm_crtc *crtc = data;
3132 struct drm_device *drm_dev = crtc->dev;
3133 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3135 spin_lock_irq(&drm_dev->event_lock);
3136 *val = acrtc->dm_irq_params.crc_window.y_start;
3137 spin_unlock_irq(&drm_dev->event_lock);
3142 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
3143 crc_win_y_start_set, "%llu\n");
3146 * Set crc window coordinate x end
3148 static int crc_win_x_end_set(void *data, u64 val)
3150 struct drm_crtc *crtc = data;
3151 struct drm_device *drm_dev = crtc->dev;
3152 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3154 spin_lock_irq(&drm_dev->event_lock);
3155 acrtc->dm_irq_params.crc_window.x_end = (uint16_t) val;
3156 acrtc->dm_irq_params.crc_window.update_win = false;
3157 spin_unlock_irq(&drm_dev->event_lock);
3163 * Get crc window coordinate x end
3165 static int crc_win_x_end_get(void *data, u64 *val)
3167 struct drm_crtc *crtc = data;
3168 struct drm_device *drm_dev = crtc->dev;
3169 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3171 spin_lock_irq(&drm_dev->event_lock);
3172 *val = acrtc->dm_irq_params.crc_window.x_end;
3173 spin_unlock_irq(&drm_dev->event_lock);
3178 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
3179 crc_win_x_end_set, "%llu\n");
3182 * Set crc window coordinate y end
3184 static int crc_win_y_end_set(void *data, u64 val)
3186 struct drm_crtc *crtc = data;
3187 struct drm_device *drm_dev = crtc->dev;
3188 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3190 spin_lock_irq(&drm_dev->event_lock);
3191 acrtc->dm_irq_params.crc_window.y_end = (uint16_t) val;
3192 acrtc->dm_irq_params.crc_window.update_win = false;
3193 spin_unlock_irq(&drm_dev->event_lock);
3199 * Get crc window coordinate y end
3201 static int crc_win_y_end_get(void *data, u64 *val)
3203 struct drm_crtc *crtc = data;
3204 struct drm_device *drm_dev = crtc->dev;
3205 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3207 spin_lock_irq(&drm_dev->event_lock);
3208 *val = acrtc->dm_irq_params.crc_window.y_end;
3209 spin_unlock_irq(&drm_dev->event_lock);
3214 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
3215 crc_win_y_end_set, "%llu\n");
3217 * Trigger to commit crc window
3219 static int crc_win_update_set(void *data, u64 val)
3221 struct drm_crtc *new_crtc = data;
3222 struct drm_crtc *old_crtc = NULL;
3223 struct amdgpu_crtc *new_acrtc, *old_acrtc;
3224 struct amdgpu_device *adev = drm_to_adev(new_crtc->dev);
3225 struct crc_rd_work *crc_rd_wrk = adev->dm.crc_rd_wrk;
3231 spin_lock_irq(&adev_to_drm(adev)->event_lock);
3232 spin_lock_irq(&crc_rd_wrk->crc_rd_work_lock);
3233 if (crc_rd_wrk->crtc) {
3234 old_crtc = crc_rd_wrk->crtc;
3235 old_acrtc = to_amdgpu_crtc(old_crtc);
3237 new_acrtc = to_amdgpu_crtc(new_crtc);
3239 if (old_crtc && old_crtc != new_crtc) {
3240 old_acrtc->dm_irq_params.crc_window.activated = false;
3241 old_acrtc->dm_irq_params.crc_window.update_win = false;
3242 old_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3244 new_acrtc->dm_irq_params.crc_window.activated = true;
3245 new_acrtc->dm_irq_params.crc_window.update_win = true;
3246 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3247 crc_rd_wrk->crtc = new_crtc;
3249 new_acrtc->dm_irq_params.crc_window.activated = true;
3250 new_acrtc->dm_irq_params.crc_window.update_win = true;
3251 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3252 crc_rd_wrk->crtc = new_crtc;
3254 spin_unlock_irq(&crc_rd_wrk->crc_rd_work_lock);
3255 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
3262 * Get crc window update flag
3264 static int crc_win_update_get(void *data, u64 *val)
3270 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
3271 crc_win_update_set, "%llu\n");
3273 void crtc_debugfs_init(struct drm_crtc *crtc)
3275 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3276 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
3281 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
3282 &crc_win_x_start_fops);
3283 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
3284 &crc_win_y_start_fops);
3285 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
3286 &crc_win_x_end_fops);
3287 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
3288 &crc_win_y_end_fops);
3289 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
3290 &crc_win_update_fops);
3292 debugfs_create_file("amdgpu_current_bpc", 0644, crtc->debugfs_entry,
3293 crtc, &amdgpu_current_bpc_fops);
3297 * Writes DTN log state to the user supplied buffer.
3298 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3300 static ssize_t dtn_log_read(
3306 struct amdgpu_device *adev = file_inode(f)->i_private;
3307 struct dc *dc = adev->dm.dc;
3308 struct dc_log_buffer_ctx log_ctx = { 0 };
3314 if (!dc->hwss.log_hw_state)
3317 dc->hwss.log_hw_state(dc, &log_ctx);
3319 if (*pos < log_ctx.pos) {
3320 size_t to_copy = log_ctx.pos - *pos;
3322 to_copy = min(to_copy, size);
3324 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
3336 * Writes DTN log state to dmesg when triggered via a write.
3337 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3339 static ssize_t dtn_log_write(
3341 const char __user *buf,
3345 struct amdgpu_device *adev = file_inode(f)->i_private;
3346 struct dc *dc = adev->dm.dc;
3348 /* Write triggers log output via dmesg. */
3352 if (dc->hwss.log_hw_state)
3353 dc->hwss.log_hw_state(dc, NULL);
3358 static int mst_topo_show(struct seq_file *m, void *unused)
3360 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3361 struct drm_device *dev = adev_to_drm(adev);
3362 struct drm_connector *connector;
3363 struct drm_connector_list_iter conn_iter;
3364 struct amdgpu_dm_connector *aconnector;
3366 drm_connector_list_iter_begin(dev, &conn_iter);
3367 drm_for_each_connector_iter(connector, &conn_iter) {
3368 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3371 aconnector = to_amdgpu_dm_connector(connector);
3373 /* Ensure we're only dumping the topology of a root mst node */
3374 if (!aconnector->mst_mgr.mst_state)
3377 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
3378 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
3380 drm_connector_list_iter_end(&conn_iter);
3386 * Sets trigger hpd for MST topologies.
3387 * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
3388 * All topologies will be disconnected if val of 0 is set .
3389 * Usage to enable topologies: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3390 * Usage to disable topologies: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3392 static int trigger_hpd_mst_set(void *data, u64 val)
3394 struct amdgpu_device *adev = data;
3395 struct drm_device *dev = adev_to_drm(adev);
3396 struct drm_connector_list_iter iter;
3397 struct amdgpu_dm_connector *aconnector;
3398 struct drm_connector *connector;
3399 struct dc_link *link = NULL;
3402 drm_connector_list_iter_begin(dev, &iter);
3403 drm_for_each_connector_iter(connector, &iter) {
3404 aconnector = to_amdgpu_dm_connector(connector);
3405 if (aconnector->dc_link->type == dc_connection_mst_branch &&
3406 aconnector->mst_mgr.aux) {
3407 mutex_lock(&adev->dm.dc_lock);
3408 dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3409 mutex_unlock(&adev->dm.dc_lock);
3411 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
3414 } else if (val == 0) {
3415 drm_connector_list_iter_begin(dev, &iter);
3416 drm_for_each_connector_iter(connector, &iter) {
3417 aconnector = to_amdgpu_dm_connector(connector);
3418 if (!aconnector->dc_link)
3421 if (!aconnector->mst_port)
3424 link = aconnector->dc_link;
3425 dp_receiver_power_ctrl(link, false);
3426 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_port->mst_mgr, false);
3427 link->mst_stream_alloc_table.stream_count = 0;
3428 memset(link->mst_stream_alloc_table.stream_allocations, 0,
3429 sizeof(link->mst_stream_alloc_table.stream_allocations));
3434 drm_kms_helper_hotplug_event(dev);
3440 * The interface doesn't need get function, so it will return the
3442 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3444 static int trigger_hpd_mst_get(void *data, u64 *val)
3450 DEFINE_DEBUGFS_ATTRIBUTE(trigger_hpd_mst_ops, trigger_hpd_mst_get,
3451 trigger_hpd_mst_set, "%llu\n");
3455 * Sets the force_timing_sync debug option from the given string.
3456 * All connected displays will be force synchronized immediately.
3457 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3459 static int force_timing_sync_set(void *data, u64 val)
3461 struct amdgpu_device *adev = data;
3463 adev->dm.force_timing_sync = (bool)val;
3465 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
3471 * Gets the force_timing_sync debug option value into the given buffer.
3472 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3474 static int force_timing_sync_get(void *data, u64 *val)
3476 struct amdgpu_device *adev = data;
3478 *val = adev->dm.force_timing_sync;
3483 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
3484 force_timing_sync_set, "%llu\n");
3488 * Disables all HPD and HPD RX interrupt handling in the
3489 * driver when set to 1. Default is 0.
3491 static int disable_hpd_set(void *data, u64 val)
3493 struct amdgpu_device *adev = data;
3495 adev->dm.disable_hpd_irq = (bool)val;
3502 * Returns 1 if HPD and HPRX interrupt handling is disabled,
3505 static int disable_hpd_get(void *data, u64 *val)
3507 struct amdgpu_device *adev = data;
3509 *val = adev->dm.disable_hpd_irq;
3514 DEFINE_DEBUGFS_ATTRIBUTE(disable_hpd_ops, disable_hpd_get,
3515 disable_hpd_set, "%llu\n");
3518 * Temporary w/a to force sst sequence in M42D DP2 mst receiver
3519 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_set_mst_en_for_sst
3521 static int dp_force_sst_set(void *data, u64 val)
3523 struct amdgpu_device *adev = data;
3525 adev->dm.dc->debug.set_mst_en_for_sst = val;
3530 static int dp_force_sst_get(void *data, u64 *val)
3532 struct amdgpu_device *adev = data;
3534 *val = adev->dm.dc->debug.set_mst_en_for_sst;
3538 DEFINE_DEBUGFS_ATTRIBUTE(dp_set_mst_en_for_sst_ops, dp_force_sst_get,
3539 dp_force_sst_set, "%llu\n");
3542 * Force DP2 sequence without VESA certified cable.
3543 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_ignore_cable_id
3545 static int dp_ignore_cable_id_set(void *data, u64 val)
3547 struct amdgpu_device *adev = data;
3549 adev->dm.dc->debug.ignore_cable_id = val;
3554 static int dp_ignore_cable_id_get(void *data, u64 *val)
3556 struct amdgpu_device *adev = data;
3558 *val = adev->dm.dc->debug.ignore_cable_id;
3562 DEFINE_DEBUGFS_ATTRIBUTE(dp_ignore_cable_id_ops, dp_ignore_cable_id_get,
3563 dp_ignore_cable_id_set, "%llu\n");
3566 * Sets the DC visual confirm debug option from the given string.
3567 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
3569 static int visual_confirm_set(void *data, u64 val)
3571 struct amdgpu_device *adev = data;
3573 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
3579 * Reads the DC visual confirm debug option value into the given buffer.
3580 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
3582 static int visual_confirm_get(void *data, u64 *val)
3584 struct amdgpu_device *adev = data;
3586 *val = adev->dm.dc->debug.visual_confirm;
3591 DEFINE_SHOW_ATTRIBUTE(mst_topo);
3592 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
3593 visual_confirm_set, "%llu\n");
3597 * Sets the DC skip_detection_link_training debug option from the given string.
3598 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_skip_detection_link_training
3600 static int skip_detection_link_training_set(void *data, u64 val)
3602 struct amdgpu_device *adev = data;
3605 adev->dm.dc->debug.skip_detection_link_training = false;
3607 adev->dm.dc->debug.skip_detection_link_training = true;
3613 * Reads the DC skip_detection_link_training debug option value into the given buffer.
3614 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_skip_detection_link_training
3616 static int skip_detection_link_training_get(void *data, u64 *val)
3618 struct amdgpu_device *adev = data;
3620 *val = adev->dm.dc->debug.skip_detection_link_training;
3625 DEFINE_DEBUGFS_ATTRIBUTE(skip_detection_link_training_fops,
3626 skip_detection_link_training_get,
3627 skip_detection_link_training_set, "%llu\n");
3630 * Dumps the DCC_EN bit for each pipe.
3631 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dcc_en
3633 static ssize_t dcc_en_bits_read(
3639 struct amdgpu_device *adev = file_inode(f)->i_private;
3640 struct dc *dc = adev->dm.dc;
3641 char *rd_buf = NULL;
3642 const uint32_t rd_buf_size = 32;
3643 uint32_t result = 0;
3645 int num_pipes = dc->res_pool->pipe_count;
3649 dcc_en_bits = kcalloc(num_pipes, sizeof(int), GFP_KERNEL);
3653 if (!dc->hwss.get_dcc_en_bits) {
3658 dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
3660 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
3666 for (i = 0; i < num_pipes; i++)
3667 offset += snprintf(rd_buf + offset, rd_buf_size - offset,
3668 "%d ", dcc_en_bits[i]);
3669 rd_buf[strlen(rd_buf)] = '\n';
3674 if (*pos >= rd_buf_size)
3676 r = put_user(*(rd_buf + result), buf);
3679 return r; /* r = -EFAULT */
3691 void dtn_debugfs_init(struct amdgpu_device *adev)
3693 static const struct file_operations dtn_log_fops = {
3694 .owner = THIS_MODULE,
3695 .read = dtn_log_read,
3696 .write = dtn_log_write,
3697 .llseek = default_llseek
3699 static const struct file_operations dcc_en_bits_fops = {
3700 .owner = THIS_MODULE,
3701 .read = dcc_en_bits_read,
3702 .llseek = default_llseek
3705 struct drm_minor *minor = adev_to_drm(adev)->primary;
3706 struct dentry *root = minor->debugfs_root;
3708 debugfs_create_file("amdgpu_mst_topology", 0444, root,
3709 adev, &mst_topo_fops);
3710 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
3712 debugfs_create_file("amdgpu_dm_dp_set_mst_en_for_sst", 0644, root, adev,
3713 &dp_set_mst_en_for_sst_ops);
3714 debugfs_create_file("amdgpu_dm_dp_ignore_cable_id", 0644, root, adev,
3715 &dp_ignore_cable_id_ops);
3717 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
3718 &visual_confirm_fops);
3720 debugfs_create_file_unsafe("amdgpu_dm_skip_detection_link_training", 0644, root, adev,
3721 &skip_detection_link_training_fops);
3723 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
3724 adev, &dmub_tracebuffer_fops);
3726 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
3727 adev, &dmub_fw_state_fops);
3729 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
3730 adev, &force_timing_sync_ops);
3732 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
3733 adev, &dmcub_trace_event_state_fops);
3735 debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
3736 adev, &trigger_hpd_mst_ops);
3738 debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
3741 debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,