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/uaccess.h>
30 #include "amdgpu_dm.h"
31 #include "amdgpu_dm_debugfs.h"
32 #include "dm_helpers.h"
33 #include "dmub/dmub_srv.h"
36 #include "dc_link_dp.h"
37 #include "link_hwss.h"
38 #include "dc/dc_dmub_srv.h"
40 struct dmub_debugfs_trace_header {
45 struct dmub_debugfs_trace_entry {
52 static inline const char *yesno(bool v)
54 return v ? "yes" : "no";
57 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
59 * Function takes in attributes passed to debugfs write entry
60 * and writes into param array.
61 * The user passes max_param_num to identify maximum number of
62 * parameters that could be parsed.
65 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
66 long *param, const char __user *buf,
70 char *wr_buf_ptr = NULL;
71 uint32_t wr_buf_count = 0;
74 const char delimiter[3] = {' ', '\n', '\0'};
75 uint8_t param_index = 0;
81 /* r is bytes not be copied */
82 if (copy_from_user(wr_buf_ptr, buf, wr_buf_size)) {
83 DRM_DEBUG_DRIVER("user data could not be read successfully\n");
87 /* check number of parameters. isspace could not differ space and \n */
88 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
90 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
95 if (wr_buf_count == wr_buf_size)
99 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
106 if (wr_buf_count == wr_buf_size)
110 if (*param_nums > max_param_num)
111 *param_nums = max_param_num;
113 wr_buf_ptr = wr_buf; /* reset buf pointer */
114 wr_buf_count = 0; /* number of char already checked */
116 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
121 while (param_index < *param_nums) {
122 /* after strsep, wr_buf_ptr will be moved to after space */
123 sub_str = strsep(&wr_buf_ptr, delimiter);
125 r = kstrtol(sub_str, 16, &(param[param_index]));
128 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
136 /* function description
137 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
139 * valid lane count value: 1, 2, 4
140 * valid link rate value:
141 * 06h = 1.62Gbps per lane
142 * 0Ah = 2.7Gbps per lane
143 * 0Ch = 3.24Gbps per lane
144 * 14h = 5.4Gbps per lane
145 * 1Eh = 8.1Gbps per lane
147 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
149 * --- to get dp configuration
151 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
153 * It will list current, verified, reported, preferred dp configuration.
154 * current -- for current video mode
155 * verified --- maximum configuration which pass link training
156 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
157 * preferred --- user force settings
159 * --- set (or force) dp configuration
161 * echo <lane_count> <link_rate> > link_settings
163 * for example, to force to 2 lane, 2.7GHz,
164 * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
166 * spread_spectrum could not be changed dynamically.
168 * in case invalid lane count, link rate are force, no hw programming will be
169 * done. please check link settings after force operation to see if HW get
172 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
174 * check current and preferred settings.
177 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
178 size_t size, loff_t *pos)
180 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
181 struct dc_link *link = connector->dc_link;
183 char *rd_buf_ptr = NULL;
184 const uint32_t rd_buf_size = 100;
189 if (*pos & 3 || size & 3)
192 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
198 str_len = strlen("Current: %d 0x%x %d ");
199 snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
200 link->cur_link_settings.lane_count,
201 link->cur_link_settings.link_rate,
202 link->cur_link_settings.link_spread);
203 rd_buf_ptr += str_len;
205 str_len = strlen("Verified: %d 0x%x %d ");
206 snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
207 link->verified_link_cap.lane_count,
208 link->verified_link_cap.link_rate,
209 link->verified_link_cap.link_spread);
210 rd_buf_ptr += str_len;
212 str_len = strlen("Reported: %d 0x%x %d ");
213 snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
214 link->reported_link_cap.lane_count,
215 link->reported_link_cap.link_rate,
216 link->reported_link_cap.link_spread);
217 rd_buf_ptr += str_len;
219 str_len = strlen("Preferred: %d 0x%x %d ");
220 snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
221 link->preferred_link_setting.lane_count,
222 link->preferred_link_setting.link_rate,
223 link->preferred_link_setting.link_spread);
226 if (*pos >= rd_buf_size)
229 r = put_user(*(rd_buf + result), buf);
232 return r; /* r = -EFAULT */
245 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
246 size_t size, loff_t *pos)
248 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
249 struct dc_link *link = connector->dc_link;
250 struct dc *dc = (struct dc *)link->dc;
251 struct dc_link_settings prefer_link_settings;
253 const uint32_t wr_buf_size = 40;
254 /* 0: lane_count; 1: link_rate */
255 int max_param_num = 2;
256 uint8_t param_nums = 0;
258 bool valid_input = true;
263 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
267 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
275 if (param_nums <= 0) {
277 DRM_DEBUG_DRIVER("user data not be read\n");
284 case LANE_COUNT_FOUR:
295 case LINK_RATE_HIGH2:
296 case LINK_RATE_HIGH3:
297 #if defined(CONFIG_DRM_AMD_DC_DCN)
298 case LINK_RATE_UHBR10:
308 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
312 /* save user force lane_count, link_rate to preferred settings
313 * spread spectrum will not be changed
315 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
316 prefer_link_settings.use_link_rate_set = false;
317 prefer_link_settings.lane_count = param[0];
318 prefer_link_settings.link_rate = param[1];
320 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, true);
326 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
327 * post-cursor2 (defined by VESA DP specification)
330 * voltage swing: 0,1,2,3
331 * pre-emphasis : 0,1,2,3
332 * post cursor2 : 0,1,2,3
335 * how to use this debugfs
337 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
339 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
341 * To figure out which DP-x is the display for DP to be check,
344 * There should be debugfs file, like link_settings, phy_settings.
346 * from lane_count, link_rate to figure which DP-x is for display to be worked
349 * To get current DP PHY settings,
352 * To change DP PHY settings,
353 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
354 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
356 * echo 2 3 0 > phy_settings
358 * To check if change be applied, get current phy settings by
361 * In case invalid values are set by user, like
362 * echo 1 4 0 > phy_settings
364 * HW will NOT be programmed by these settings.
365 * cat phy_settings will show the previous valid settings.
367 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
368 size_t size, loff_t *pos)
370 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
371 struct dc_link *link = connector->dc_link;
373 const uint32_t rd_buf_size = 20;
377 if (*pos & 3 || size & 3)
380 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
384 snprintf(rd_buf, rd_buf_size, " %d %d %d\n",
385 link->cur_lane_setting[0].VOLTAGE_SWING,
386 link->cur_lane_setting[0].PRE_EMPHASIS,
387 link->cur_lane_setting[0].POST_CURSOR2);
390 if (*pos >= rd_buf_size)
393 r = put_user((*(rd_buf + result)), buf);
396 return r; /* r = -EFAULT */
409 static int dp_lttpr_status_show(struct seq_file *m, void *d)
412 struct amdgpu_dm_connector *connector = file_inode(m->file)->i_private;
413 struct dc_link *link = connector->dc_link;
414 uint32_t read_size = 1;
415 uint8_t repeater_count = 0;
417 data = kzalloc(read_size, GFP_KERNEL);
421 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0002, data, read_size);
423 switch ((uint8_t)*data) {
452 repeater_count = (uint8_t)*data;
456 seq_printf(m, "phy repeater count: %d\n", repeater_count);
458 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0003, data, read_size);
460 if ((uint8_t)*data == 0x55)
461 seq_printf(m, "phy repeater mode: transparent\n");
462 else if ((uint8_t)*data == 0xAA)
463 seq_printf(m, "phy repeater mode: non-transparent\n");
464 else if ((uint8_t)*data == 0x00)
465 seq_printf(m, "phy repeater mode: non lttpr\n");
467 seq_printf(m, "phy repeater mode: read error\n");
473 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
474 size_t size, loff_t *pos)
476 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
477 struct dc_link *link = connector->dc_link;
478 struct dc *dc = (struct dc *)link->dc;
480 uint32_t wr_buf_size = 40;
482 bool use_prefer_link_setting;
483 struct link_training_settings link_lane_settings;
484 int max_param_num = 3;
485 uint8_t param_nums = 0;
492 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
496 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
504 if (param_nums <= 0) {
506 DRM_DEBUG_DRIVER("user data not be read\n");
510 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
511 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
512 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
514 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
518 /* get link settings: lane count, link rate */
519 use_prefer_link_setting =
520 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
521 (link->test_pattern_enabled));
523 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
525 if (use_prefer_link_setting) {
526 link_lane_settings.link_settings.lane_count =
527 link->preferred_link_setting.lane_count;
528 link_lane_settings.link_settings.link_rate =
529 link->preferred_link_setting.link_rate;
530 link_lane_settings.link_settings.link_spread =
531 link->preferred_link_setting.link_spread;
533 link_lane_settings.link_settings.lane_count =
534 link->cur_link_settings.lane_count;
535 link_lane_settings.link_settings.link_rate =
536 link->cur_link_settings.link_rate;
537 link_lane_settings.link_settings.link_spread =
538 link->cur_link_settings.link_spread;
541 /* apply phy settings from user */
542 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
543 link_lane_settings.lane_settings[r].VOLTAGE_SWING =
544 (enum dc_voltage_swing) (param[0]);
545 link_lane_settings.lane_settings[r].PRE_EMPHASIS =
546 (enum dc_pre_emphasis) (param[1]);
547 link_lane_settings.lane_settings[r].POST_CURSOR2 =
548 (enum dc_post_cursor2) (param[2]);
551 /* program ASIC registers and DPCD registers */
552 dc_link_set_drive_settings(dc, &link_lane_settings, link);
558 /* function description
560 * set PHY layer or Link layer test pattern
561 * PHY test pattern is used for PHY SI check.
562 * Link layer test will not affect PHY SI.
564 * Reset Test Pattern:
565 * 0 = DP_TEST_PATTERN_VIDEO_MODE
567 * PHY test pattern supported:
568 * 1 = DP_TEST_PATTERN_D102
569 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
570 * 3 = DP_TEST_PATTERN_PRBS7
571 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
572 * 5 = DP_TEST_PATTERN_CP2520_1
573 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
574 * 7 = DP_TEST_PATTERN_CP2520_3
576 * DP PHY Link Training Patterns
577 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
578 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
579 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
580 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
582 * DP Link Layer Test pattern
583 * c = DP_TEST_PATTERN_COLOR_SQUARES
584 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
585 * e = DP_TEST_PATTERN_VERTICAL_BARS
586 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
587 * 10= DP_TEST_PATTERN_COLOR_RAMP
589 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
591 * --- set test pattern
592 * echo <test pattern #> > test_pattern
594 * If test pattern # is not supported, NO HW programming will be done.
595 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
596 * for the user pattern. input 10 bytes data are separated by space
598 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
600 * --- reset test pattern
601 * echo 0 > test_pattern
603 * --- HPD detection is disabled when set PHY test pattern
605 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
606 * is disable. User could unplug DP display from DP connected and plug scope to
607 * check test pattern PHY SI.
608 * If there is need unplug scope and plug DP display back, do steps below:
609 * echo 0 > phy_test_pattern
613 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
614 * driver could detect "unplug scope" and "plug DP display"
616 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
617 size_t size, loff_t *pos)
619 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
620 struct dc_link *link = connector->dc_link;
622 uint32_t wr_buf_size = 100;
623 long param[11] = {0x0};
624 int max_param_num = 11;
625 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
626 bool disable_hpd = false;
627 bool valid_test_pattern = false;
628 uint8_t param_nums = 0;
629 /* init with default 80bit custom pattern */
630 uint8_t custom_pattern[10] = {
631 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
632 0x1f, 0x7c, 0xf0, 0xc1, 0x07
634 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
635 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
636 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
637 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
638 struct link_training_settings link_training_settings;
644 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
648 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
656 if (param_nums <= 0) {
658 DRM_DEBUG_DRIVER("user data not be read\n");
663 test_pattern = param[0];
665 switch (test_pattern) {
666 case DP_TEST_PATTERN_VIDEO_MODE:
667 case DP_TEST_PATTERN_COLOR_SQUARES:
668 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
669 case DP_TEST_PATTERN_VERTICAL_BARS:
670 case DP_TEST_PATTERN_HORIZONTAL_BARS:
671 case DP_TEST_PATTERN_COLOR_RAMP:
672 valid_test_pattern = true;
675 case DP_TEST_PATTERN_D102:
676 case DP_TEST_PATTERN_SYMBOL_ERROR:
677 case DP_TEST_PATTERN_PRBS7:
678 case DP_TEST_PATTERN_80BIT_CUSTOM:
679 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
680 case DP_TEST_PATTERN_TRAINING_PATTERN4:
682 valid_test_pattern = true;
686 valid_test_pattern = false;
687 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
691 if (!valid_test_pattern) {
693 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
697 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
698 for (i = 0; i < 10; i++) {
699 if ((uint8_t) param[i + 1] != 0x0)
704 /* not use default value */
705 for (i = 0; i < 10; i++)
706 custom_pattern[i] = (uint8_t) param[i + 1];
710 /* Usage: set DP physical test pattern using debugfs with normal DP
711 * panel. Then plug out DP panel and connect a scope to measure
712 * For normal video mode and test pattern generated from CRCT,
713 * they are visibile to user. So do not disable HPD.
714 * Video Mode is also set to clear the test pattern, so enable HPD
715 * because it might have been disabled after a test pattern was set.
716 * AUX depends on HPD * sequence dependent, do not move!
719 dc_link_enable_hpd(link);
721 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
722 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
723 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
725 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
726 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
727 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
729 link_training_settings.link_settings = cur_link_settings;
732 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
733 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
734 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
735 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
736 prefer_link_settings.link_rate != cur_link_settings.link_rate))
737 link_training_settings.link_settings = prefer_link_settings;
740 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
741 link_training_settings.lane_settings[i] = link->cur_lane_setting[i];
743 dc_link_set_test_pattern(
746 DP_TEST_PATTERN_COLOR_SPACE_RGB,
747 &link_training_settings,
751 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
752 * Then plug out DP panel and connect a scope to measure DP PHY signal.
753 * Need disable interrupt to avoid SW driver disable DP output. This is
754 * done after the test pattern is set.
756 if (valid_test_pattern && disable_hpd)
757 dc_link_disable_hpd(link);
765 * Returns the DMCUB tracebuffer contents.
766 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
768 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
770 struct amdgpu_device *adev = m->private;
771 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
772 struct dmub_debugfs_trace_entry *entries;
774 uint32_t tbuf_size, max_entries, num_entries, i;
779 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
783 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
784 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
785 sizeof(struct dmub_debugfs_trace_entry);
788 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
790 num_entries = min(num_entries, max_entries);
792 entries = (struct dmub_debugfs_trace_entry
794 sizeof(struct dmub_debugfs_trace_header));
796 for (i = 0; i < num_entries; ++i) {
797 struct dmub_debugfs_trace_entry *entry = &entries[i];
800 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
801 entry->trace_code, entry->tick_count, entry->param0,
809 * Returns the DMCUB firmware state contents.
810 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
812 static int dmub_fw_state_show(struct seq_file *m, void *data)
814 struct amdgpu_device *adev = m->private;
815 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
822 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
826 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
828 return seq_write(m, state_base, state_size);
831 /* psr_capability_show() - show eDP panel PSR capability
833 * The read function: sink_psr_capability_show
834 * Shows if sink has PSR capability or not.
835 * If yes - the PSR version is appended
837 * cat /sys/kernel/debug/dri/0/eDP-X/psr_capability
840 * "Sink support: no\n" - if panel doesn't support PSR
841 * "Sink support: yes [0x01]\n" - if panel supports PSR1
842 * "Driver support: no\n" - if driver doesn't support PSR
843 * "Driver support: yes [0x01]\n" - if driver supports PSR1
845 static int psr_capability_show(struct seq_file *m, void *data)
847 struct drm_connector *connector = m->private;
848 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
849 struct dc_link *link = aconnector->dc_link;
854 if (link->type == dc_connection_none)
857 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
860 seq_printf(m, "Sink support: %s", yesno(link->dpcd_caps.psr_info.psr_version != 0));
861 if (link->dpcd_caps.psr_info.psr_version)
862 seq_printf(m, " [0x%02x]", link->dpcd_caps.psr_info.psr_version);
865 seq_printf(m, "Driver support: %s", yesno(link->psr_settings.psr_feature_enabled));
866 if (link->psr_settings.psr_version)
867 seq_printf(m, " [0x%02x]", link->psr_settings.psr_version);
874 * Returns the current and maximum output bpc for the connector.
875 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/output_bpc
877 static int output_bpc_show(struct seq_file *m, void *data)
879 struct drm_connector *connector = m->private;
880 struct drm_device *dev = connector->dev;
881 struct drm_crtc *crtc = NULL;
882 struct dm_crtc_state *dm_crtc_state = NULL;
886 mutex_lock(&dev->mode_config.mutex);
887 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
889 if (connector->state == NULL)
892 crtc = connector->state->crtc;
896 drm_modeset_lock(&crtc->mutex, NULL);
897 if (crtc->state == NULL)
900 dm_crtc_state = to_dm_crtc_state(crtc->state);
901 if (dm_crtc_state->stream == NULL)
904 switch (dm_crtc_state->stream->timing.display_color_depth) {
905 case COLOR_DEPTH_666:
908 case COLOR_DEPTH_888:
911 case COLOR_DEPTH_101010:
914 case COLOR_DEPTH_121212:
917 case COLOR_DEPTH_161616:
924 seq_printf(m, "Current: %u\n", bpc);
925 seq_printf(m, "Maximum: %u\n", connector->display_info.bpc);
930 drm_modeset_unlock(&crtc->mutex);
932 drm_modeset_unlock(&dev->mode_config.connection_mutex);
933 mutex_unlock(&dev->mode_config.mutex);
940 * Disable dsc passthrough, i.e.,: have dsc decoding at converver, not external RX
941 * echo 1 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
942 * Enable dsc passthrough, i.e.,: have dsc passthrough to external RX
943 * echo 0 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
945 static ssize_t dp_dsc_passthrough_set(struct file *f, const char __user *buf,
946 size_t size, loff_t *pos)
948 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
950 uint32_t wr_buf_size = 42;
951 int max_param_num = 1;
953 uint8_t param_nums = 0;
958 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
961 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
965 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
973 aconnector->dsc_settings.dsc_force_disable_passthrough = param;
979 #ifdef CONFIG_DRM_AMD_DC_HDCP
981 * Returns the HDCP capability of the Display (1.4 for now).
983 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
984 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
986 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
987 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
989 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
991 struct drm_connector *connector = m->private;
992 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
993 bool hdcp_cap, hdcp2_cap;
995 if (connector->status != connector_status_connected)
998 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
1000 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1001 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1005 seq_printf(m, "%s ", "HDCP1.4");
1007 seq_printf(m, "%s ", "HDCP2.2");
1009 if (!hdcp_cap && !hdcp2_cap)
1010 seq_printf(m, "%s ", "None");
1019 * Returns whether the connected display is internal and not hotpluggable.
1020 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/internal_display
1022 static int internal_display_show(struct seq_file *m, void *data)
1024 struct drm_connector *connector = m->private;
1025 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1026 struct dc_link *link = aconnector->dc_link;
1028 seq_printf(m, "Internal: %u\n", link->is_internal_display);
1033 /* function description
1035 * generic SDP message access for testing
1037 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
1040 * Hb0 : Secondary-Data Packet ID
1041 * Hb1 : Secondary-Data Packet type
1042 * Hb2 : Secondary-Data-packet-specific header, Byte 0
1043 * Hb3 : Secondary-Data-packet-specific header, Byte 1
1045 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
1047 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
1048 size_t size, loff_t *pos)
1052 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1053 struct dm_crtc_state *acrtc_state;
1054 uint32_t write_size = 36;
1056 if (connector->base.status != connector_status_connected)
1062 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
1064 r = copy_from_user(data, buf, write_size);
1068 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
1073 static ssize_t dp_dpcd_address_write(struct file *f, const char __user *buf,
1074 size_t size, loff_t *pos)
1077 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1079 if (size < sizeof(connector->debugfs_dpcd_address))
1082 r = copy_from_user(&connector->debugfs_dpcd_address,
1083 buf, sizeof(connector->debugfs_dpcd_address));
1088 static ssize_t dp_dpcd_size_write(struct file *f, const char __user *buf,
1089 size_t size, loff_t *pos)
1092 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1094 if (size < sizeof(connector->debugfs_dpcd_size))
1097 r = copy_from_user(&connector->debugfs_dpcd_size,
1098 buf, sizeof(connector->debugfs_dpcd_size));
1100 if (connector->debugfs_dpcd_size > 256)
1101 connector->debugfs_dpcd_size = 0;
1106 static ssize_t dp_dpcd_data_write(struct file *f, const char __user *buf,
1107 size_t size, loff_t *pos)
1111 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1112 struct dc_link *link = connector->dc_link;
1113 uint32_t write_size = connector->debugfs_dpcd_size;
1115 if (!write_size || size < write_size)
1118 data = kzalloc(write_size, GFP_KERNEL);
1122 r = copy_from_user(data, buf, write_size);
1124 dm_helpers_dp_write_dpcd(link->ctx, link,
1125 connector->debugfs_dpcd_address, data, write_size - r);
1127 return write_size - r;
1130 static ssize_t dp_dpcd_data_read(struct file *f, char __user *buf,
1131 size_t size, loff_t *pos)
1135 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1136 struct dc_link *link = connector->dc_link;
1137 uint32_t read_size = connector->debugfs_dpcd_size;
1139 if (!read_size || size < read_size)
1142 data = kzalloc(read_size, GFP_KERNEL);
1146 dm_helpers_dp_read_dpcd(link->ctx, link,
1147 connector->debugfs_dpcd_address, data, read_size);
1149 r = copy_to_user(buf, data, read_size);
1152 return read_size - r;
1155 /* function: Read link's DSC & FEC capabilities
1158 * Access it with the following command (you need to specify
1159 * connector like DP-1):
1161 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
1164 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
1166 struct drm_connector *connector = m->private;
1167 struct drm_modeset_acquire_ctx ctx;
1168 struct drm_device *dev = connector->dev;
1169 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1171 bool try_again = false;
1172 bool is_fec_supported = false;
1173 bool is_dsc_supported = false;
1174 struct dpcd_caps dpcd_caps;
1176 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1179 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1181 if (ret == -EDEADLK) {
1182 ret = drm_modeset_backoff(&ctx);
1190 if (connector->status != connector_status_connected) {
1194 dpcd_caps = aconnector->dc_link->dpcd_caps;
1195 if (aconnector->port) {
1196 /* aconnector sets dsc_aux during get_modes call
1197 * if MST connector has it means it can either
1198 * enable DSC on the sink device or on MST branch
1201 if (aconnector->dsc_aux) {
1202 is_fec_supported = true;
1203 is_dsc_supported = true;
1206 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1207 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1209 } while (try_again);
1211 drm_modeset_drop_locks(&ctx);
1212 drm_modeset_acquire_fini(&ctx);
1214 seq_printf(m, "FEC_Sink_Support: %s\n", yesno(is_fec_supported));
1215 seq_printf(m, "DSC_Sink_Support: %s\n", yesno(is_dsc_supported));
1220 /* function: Trigger virtual HPD redetection on connector
1222 * This function will perform link rediscovery, link disable
1223 * and enable, and dm connector state update.
1225 * Retrigger HPD on an existing connector by echoing 1 into
1226 * its respectful "trigger_hotplug" debugfs entry:
1228 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1230 * This function can perform HPD unplug:
1232 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1235 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1236 size_t size, loff_t *pos)
1238 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1239 struct drm_connector *connector = &aconnector->base;
1240 struct dc_link *link = NULL;
1241 struct drm_device *dev = connector->dev;
1242 enum dc_connection_type new_connection_type = dc_connection_none;
1243 char *wr_buf = NULL;
1244 uint32_t wr_buf_size = 42;
1245 int max_param_num = 1;
1246 long param[1] = {0};
1247 uint8_t param_nums = 0;
1249 if (!aconnector || !aconnector->dc_link)
1255 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1258 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1262 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1270 if (param_nums <= 0) {
1271 DRM_DEBUG_DRIVER("user data not be read\n");
1276 if (param[0] == 1) {
1277 mutex_lock(&aconnector->hpd_lock);
1279 if (!dc_link_detect_sink(aconnector->dc_link, &new_connection_type) &&
1280 new_connection_type != dc_connection_none)
1283 if (!dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD))
1286 amdgpu_dm_update_connector_after_detect(aconnector);
1288 drm_modeset_lock_all(dev);
1289 dm_restore_drm_connector_state(dev, connector);
1290 drm_modeset_unlock_all(dev);
1292 drm_kms_helper_connector_hotplug_event(connector);
1293 } else if (param[0] == 0) {
1294 if (!aconnector->dc_link)
1297 link = aconnector->dc_link;
1299 if (link->local_sink) {
1300 dc_sink_release(link->local_sink);
1301 link->local_sink = NULL;
1304 link->dpcd_sink_count = 0;
1305 link->type = dc_connection_none;
1306 link->dongle_max_pix_clk = 0;
1308 amdgpu_dm_update_connector_after_detect(aconnector);
1310 drm_modeset_lock_all(dev);
1311 dm_restore_drm_connector_state(dev, connector);
1312 drm_modeset_unlock_all(dev);
1314 drm_kms_helper_connector_hotplug_event(connector);
1318 mutex_unlock(&aconnector->hpd_lock);
1324 /* function: read DSC status on the connector
1326 * The read function: dp_dsc_clock_en_read
1327 * returns current status of DSC clock on the connector.
1328 * The return is a boolean flag: 1 or 0.
1330 * Access it with the following command (you need to specify
1331 * connector like DP-1):
1333 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1336 * 1 - means that DSC is currently enabled
1337 * 0 - means that DSC is disabled
1339 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1340 size_t size, loff_t *pos)
1342 char *rd_buf = NULL;
1343 char *rd_buf_ptr = NULL;
1344 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1345 struct display_stream_compressor *dsc;
1346 struct dcn_dsc_state dsc_state = {0};
1347 const uint32_t rd_buf_size = 10;
1348 struct pipe_ctx *pipe_ctx;
1350 int i, r, str_len = 30;
1352 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1357 rd_buf_ptr = rd_buf;
1359 for (i = 0; i < MAX_PIPES; i++) {
1360 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1361 if (pipe_ctx && pipe_ctx->stream &&
1362 pipe_ctx->stream->link == aconnector->dc_link)
1371 dsc = pipe_ctx->stream_res.dsc;
1373 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1375 snprintf(rd_buf_ptr, str_len,
1377 dsc_state.dsc_clock_en);
1378 rd_buf_ptr += str_len;
1381 if (*pos >= rd_buf_size)
1384 r = put_user(*(rd_buf + result), buf);
1387 return r; /* r = -EFAULT */
1400 /* function: write force DSC on the connector
1402 * The write function: dp_dsc_clock_en_write
1403 * enables to force DSC on the connector.
1404 * User can write to either force enable or force disable DSC
1405 * on the next modeset or set it to driver default
1408 * 0 - default DSC enablement policy
1409 * 1 - force enable DSC on the connector
1410 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1412 * Writing DSC settings is done with the following command:
1413 * - To force enable DSC (you need to specify
1414 * connector like DP-1):
1416 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1418 * - To return to default state set the flag to zero and
1419 * let driver deal with DSC automatically
1420 * (you need to specify connector like DP-1):
1422 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1425 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1426 size_t size, loff_t *pos)
1428 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1429 struct drm_connector *connector = &aconnector->base;
1430 struct drm_device *dev = connector->dev;
1431 struct drm_crtc *crtc = NULL;
1432 struct dm_crtc_state *dm_crtc_state = NULL;
1433 struct pipe_ctx *pipe_ctx;
1435 char *wr_buf = NULL;
1436 uint32_t wr_buf_size = 42;
1437 int max_param_num = 1;
1438 long param[1] = {0};
1439 uint8_t param_nums = 0;
1444 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1447 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1451 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1459 if (param_nums <= 0) {
1460 DRM_DEBUG_DRIVER("user data not be read\n");
1465 for (i = 0; i < MAX_PIPES; i++) {
1466 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1467 if (pipe_ctx && pipe_ctx->stream &&
1468 pipe_ctx->stream->link == aconnector->dc_link)
1472 if (!pipe_ctx || !pipe_ctx->stream)
1476 mutex_lock(&dev->mode_config.mutex);
1477 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1479 if (connector->state == NULL)
1482 crtc = connector->state->crtc;
1486 drm_modeset_lock(&crtc->mutex, NULL);
1487 if (crtc->state == NULL)
1490 dm_crtc_state = to_dm_crtc_state(crtc->state);
1491 if (dm_crtc_state->stream == NULL)
1495 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1496 else if (param[0] == 2)
1497 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1499 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1501 dm_crtc_state->dsc_force_changed = true;
1505 drm_modeset_unlock(&crtc->mutex);
1506 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1507 mutex_unlock(&dev->mode_config.mutex);
1514 /* function: read DSC slice width parameter on the connector
1516 * The read function: dp_dsc_slice_width_read
1517 * returns dsc slice width used in the current configuration
1518 * The return is an integer: 0 or other positive number
1520 * Access the status with the following command:
1522 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1524 * 0 - means that DSC is disabled
1526 * Any other number more than zero represents the
1527 * slice width currently used by DSC in pixels
1530 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1531 size_t size, loff_t *pos)
1533 char *rd_buf = NULL;
1534 char *rd_buf_ptr = NULL;
1535 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1536 struct display_stream_compressor *dsc;
1537 struct dcn_dsc_state dsc_state = {0};
1538 const uint32_t rd_buf_size = 100;
1539 struct pipe_ctx *pipe_ctx;
1541 int i, r, str_len = 30;
1543 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1548 rd_buf_ptr = rd_buf;
1550 for (i = 0; i < MAX_PIPES; i++) {
1551 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1552 if (pipe_ctx && pipe_ctx->stream &&
1553 pipe_ctx->stream->link == aconnector->dc_link)
1562 dsc = pipe_ctx->stream_res.dsc;
1564 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1566 snprintf(rd_buf_ptr, str_len,
1568 dsc_state.dsc_slice_width);
1569 rd_buf_ptr += str_len;
1572 if (*pos >= rd_buf_size)
1575 r = put_user(*(rd_buf + result), buf);
1578 return r; /* r = -EFAULT */
1591 /* function: write DSC slice width parameter
1593 * The write function: dp_dsc_slice_width_write
1594 * overwrites automatically generated DSC configuration
1597 * The user has to write the slice width divisible by the
1600 * Also the user has to write width in hexidecimal
1601 * rather than in decimal.
1603 * Writing DSC settings is done with the following command:
1604 * - To force overwrite slice width: (example sets to 1920 pixels)
1606 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1608 * - To stop overwriting and let driver find the optimal size,
1609 * set the width to zero:
1611 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1614 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1615 size_t size, loff_t *pos)
1617 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1618 struct pipe_ctx *pipe_ctx;
1619 struct drm_connector *connector = &aconnector->base;
1620 struct drm_device *dev = connector->dev;
1621 struct drm_crtc *crtc = NULL;
1622 struct dm_crtc_state *dm_crtc_state = NULL;
1624 char *wr_buf = NULL;
1625 uint32_t wr_buf_size = 42;
1626 int max_param_num = 1;
1627 long param[1] = {0};
1628 uint8_t param_nums = 0;
1633 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1636 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1640 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1648 if (param_nums <= 0) {
1649 DRM_DEBUG_DRIVER("user data not be read\n");
1654 for (i = 0; i < MAX_PIPES; i++) {
1655 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1656 if (pipe_ctx && pipe_ctx->stream &&
1657 pipe_ctx->stream->link == aconnector->dc_link)
1661 if (!pipe_ctx || !pipe_ctx->stream)
1664 // Safely get CRTC state
1665 mutex_lock(&dev->mode_config.mutex);
1666 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1668 if (connector->state == NULL)
1671 crtc = connector->state->crtc;
1675 drm_modeset_lock(&crtc->mutex, NULL);
1676 if (crtc->state == NULL)
1679 dm_crtc_state = to_dm_crtc_state(crtc->state);
1680 if (dm_crtc_state->stream == NULL)
1684 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1685 pipe_ctx->stream->timing.h_addressable,
1688 aconnector->dsc_settings.dsc_num_slices_h = 0;
1690 dm_crtc_state->dsc_force_changed = true;
1694 drm_modeset_unlock(&crtc->mutex);
1695 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1696 mutex_unlock(&dev->mode_config.mutex);
1703 /* function: read DSC slice height parameter on the connector
1705 * The read function: dp_dsc_slice_height_read
1706 * returns dsc slice height used in the current configuration
1707 * The return is an integer: 0 or other positive number
1709 * Access the status with the following command:
1711 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1713 * 0 - means that DSC is disabled
1715 * Any other number more than zero represents the
1716 * slice height currently used by DSC in pixels
1719 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1720 size_t size, loff_t *pos)
1722 char *rd_buf = NULL;
1723 char *rd_buf_ptr = NULL;
1724 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1725 struct display_stream_compressor *dsc;
1726 struct dcn_dsc_state dsc_state = {0};
1727 const uint32_t rd_buf_size = 100;
1728 struct pipe_ctx *pipe_ctx;
1730 int i, r, str_len = 30;
1732 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1737 rd_buf_ptr = rd_buf;
1739 for (i = 0; i < MAX_PIPES; i++) {
1740 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1741 if (pipe_ctx && pipe_ctx->stream &&
1742 pipe_ctx->stream->link == aconnector->dc_link)
1751 dsc = pipe_ctx->stream_res.dsc;
1753 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1755 snprintf(rd_buf_ptr, str_len,
1757 dsc_state.dsc_slice_height);
1758 rd_buf_ptr += str_len;
1761 if (*pos >= rd_buf_size)
1764 r = put_user(*(rd_buf + result), buf);
1767 return r; /* r = -EFAULT */
1780 /* function: write DSC slice height parameter
1782 * The write function: dp_dsc_slice_height_write
1783 * overwrites automatically generated DSC configuration
1786 * The user has to write the slice height divisible by the
1789 * Also the user has to write height in hexidecimal
1790 * rather than in decimal.
1792 * Writing DSC settings is done with the following command:
1793 * - To force overwrite slice height (example sets to 128 pixels):
1795 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1797 * - To stop overwriting and let driver find the optimal size,
1798 * set the height to zero:
1800 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1803 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1804 size_t size, loff_t *pos)
1806 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1807 struct drm_connector *connector = &aconnector->base;
1808 struct drm_device *dev = connector->dev;
1809 struct drm_crtc *crtc = NULL;
1810 struct dm_crtc_state *dm_crtc_state = NULL;
1811 struct pipe_ctx *pipe_ctx;
1813 char *wr_buf = NULL;
1814 uint32_t wr_buf_size = 42;
1815 int max_param_num = 1;
1816 uint8_t param_nums = 0;
1817 long param[1] = {0};
1822 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1825 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1829 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1837 if (param_nums <= 0) {
1838 DRM_DEBUG_DRIVER("user data not be read\n");
1843 for (i = 0; i < MAX_PIPES; i++) {
1844 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1845 if (pipe_ctx && pipe_ctx->stream &&
1846 pipe_ctx->stream->link == aconnector->dc_link)
1850 if (!pipe_ctx || !pipe_ctx->stream)
1854 mutex_lock(&dev->mode_config.mutex);
1855 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1857 if (connector->state == NULL)
1860 crtc = connector->state->crtc;
1864 drm_modeset_lock(&crtc->mutex, NULL);
1865 if (crtc->state == NULL)
1868 dm_crtc_state = to_dm_crtc_state(crtc->state);
1869 if (dm_crtc_state->stream == NULL)
1873 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1874 pipe_ctx->stream->timing.v_addressable,
1877 aconnector->dsc_settings.dsc_num_slices_v = 0;
1879 dm_crtc_state->dsc_force_changed = true;
1883 drm_modeset_unlock(&crtc->mutex);
1884 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1885 mutex_unlock(&dev->mode_config.mutex);
1892 /* function: read DSC target rate on the connector in bits per pixel
1894 * The read function: dp_dsc_bits_per_pixel_read
1895 * returns target rate of compression in bits per pixel
1896 * The return is an integer: 0 or other positive integer
1898 * Access it with the following command:
1900 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1902 * 0 - means that DSC is disabled
1904 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
1905 size_t size, loff_t *pos)
1907 char *rd_buf = NULL;
1908 char *rd_buf_ptr = NULL;
1909 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1910 struct display_stream_compressor *dsc;
1911 struct dcn_dsc_state dsc_state = {0};
1912 const uint32_t rd_buf_size = 100;
1913 struct pipe_ctx *pipe_ctx;
1915 int i, r, str_len = 30;
1917 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1922 rd_buf_ptr = rd_buf;
1924 for (i = 0; i < MAX_PIPES; i++) {
1925 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1926 if (pipe_ctx && pipe_ctx->stream &&
1927 pipe_ctx->stream->link == aconnector->dc_link)
1936 dsc = pipe_ctx->stream_res.dsc;
1938 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1940 snprintf(rd_buf_ptr, str_len,
1942 dsc_state.dsc_bits_per_pixel);
1943 rd_buf_ptr += str_len;
1946 if (*pos >= rd_buf_size)
1949 r = put_user(*(rd_buf + result), buf);
1952 return r; /* r = -EFAULT */
1965 /* function: write DSC target rate in bits per pixel
1967 * The write function: dp_dsc_bits_per_pixel_write
1968 * overwrites automatically generated DSC configuration
1969 * of DSC target bit rate.
1971 * Also the user has to write bpp in hexidecimal
1972 * rather than in decimal.
1974 * Writing DSC settings is done with the following command:
1975 * - To force overwrite rate (example sets to 256 bpp x 1/16):
1977 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1979 * - To stop overwriting and let driver find the optimal rate,
1980 * set the rate to zero:
1982 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1985 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
1986 size_t size, loff_t *pos)
1988 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1989 struct drm_connector *connector = &aconnector->base;
1990 struct drm_device *dev = connector->dev;
1991 struct drm_crtc *crtc = NULL;
1992 struct dm_crtc_state *dm_crtc_state = NULL;
1993 struct pipe_ctx *pipe_ctx;
1995 char *wr_buf = NULL;
1996 uint32_t wr_buf_size = 42;
1997 int max_param_num = 1;
1998 uint8_t param_nums = 0;
1999 long param[1] = {0};
2004 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2007 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2011 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2019 if (param_nums <= 0) {
2020 DRM_DEBUG_DRIVER("user data not be read\n");
2025 for (i = 0; i < MAX_PIPES; i++) {
2026 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2027 if (pipe_ctx && pipe_ctx->stream &&
2028 pipe_ctx->stream->link == aconnector->dc_link)
2032 if (!pipe_ctx || !pipe_ctx->stream)
2036 mutex_lock(&dev->mode_config.mutex);
2037 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2039 if (connector->state == NULL)
2042 crtc = connector->state->crtc;
2046 drm_modeset_lock(&crtc->mutex, NULL);
2047 if (crtc->state == NULL)
2050 dm_crtc_state = to_dm_crtc_state(crtc->state);
2051 if (dm_crtc_state->stream == NULL)
2054 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
2056 dm_crtc_state->dsc_force_changed = true;
2060 drm_modeset_unlock(&crtc->mutex);
2061 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2062 mutex_unlock(&dev->mode_config.mutex);
2069 /* function: read DSC picture width parameter on the connector
2071 * The read function: dp_dsc_pic_width_read
2072 * returns dsc picture width used in the current configuration
2073 * It is the same as h_addressable of the current
2075 * The return is an integer: 0 or other positive integer
2076 * If 0 then DSC is disabled.
2078 * Access it with the following command:
2080 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
2082 * 0 - means that DSC is disabled
2084 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
2085 size_t size, loff_t *pos)
2087 char *rd_buf = NULL;
2088 char *rd_buf_ptr = NULL;
2089 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2090 struct display_stream_compressor *dsc;
2091 struct dcn_dsc_state dsc_state = {0};
2092 const uint32_t rd_buf_size = 100;
2093 struct pipe_ctx *pipe_ctx;
2095 int i, r, str_len = 30;
2097 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2102 rd_buf_ptr = rd_buf;
2104 for (i = 0; i < MAX_PIPES; i++) {
2105 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2106 if (pipe_ctx && pipe_ctx->stream &&
2107 pipe_ctx->stream->link == aconnector->dc_link)
2116 dsc = pipe_ctx->stream_res.dsc;
2118 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2120 snprintf(rd_buf_ptr, str_len,
2122 dsc_state.dsc_pic_width);
2123 rd_buf_ptr += str_len;
2126 if (*pos >= rd_buf_size)
2129 r = put_user(*(rd_buf + result), buf);
2132 return r; /* r = -EFAULT */
2145 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
2146 size_t size, loff_t *pos)
2148 char *rd_buf = NULL;
2149 char *rd_buf_ptr = NULL;
2150 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2151 struct display_stream_compressor *dsc;
2152 struct dcn_dsc_state dsc_state = {0};
2153 const uint32_t rd_buf_size = 100;
2154 struct pipe_ctx *pipe_ctx;
2156 int i, r, str_len = 30;
2158 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2163 rd_buf_ptr = rd_buf;
2165 for (i = 0; i < MAX_PIPES; i++) {
2166 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2167 if (pipe_ctx && pipe_ctx->stream &&
2168 pipe_ctx->stream->link == aconnector->dc_link)
2177 dsc = pipe_ctx->stream_res.dsc;
2179 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2181 snprintf(rd_buf_ptr, str_len,
2183 dsc_state.dsc_pic_height);
2184 rd_buf_ptr += str_len;
2187 if (*pos >= rd_buf_size)
2190 r = put_user(*(rd_buf + result), buf);
2193 return r; /* r = -EFAULT */
2206 /* function: read DSC chunk size parameter on the connector
2208 * The read function: dp_dsc_chunk_size_read
2209 * returns dsc chunk size set in the current configuration
2210 * The value is calculated automatically by DSC code
2211 * and depends on slice parameters and bpp target rate
2212 * The return is an integer: 0 or other positive integer
2213 * If 0 then DSC is disabled.
2215 * Access it with the following command:
2217 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2219 * 0 - means that DSC is disabled
2221 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2222 size_t size, loff_t *pos)
2224 char *rd_buf = NULL;
2225 char *rd_buf_ptr = NULL;
2226 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2227 struct display_stream_compressor *dsc;
2228 struct dcn_dsc_state dsc_state = {0};
2229 const uint32_t rd_buf_size = 100;
2230 struct pipe_ctx *pipe_ctx;
2232 int i, r, str_len = 30;
2234 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2239 rd_buf_ptr = rd_buf;
2241 for (i = 0; i < MAX_PIPES; i++) {
2242 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2243 if (pipe_ctx && pipe_ctx->stream &&
2244 pipe_ctx->stream->link == aconnector->dc_link)
2253 dsc = pipe_ctx->stream_res.dsc;
2255 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2257 snprintf(rd_buf_ptr, str_len,
2259 dsc_state.dsc_chunk_size);
2260 rd_buf_ptr += str_len;
2263 if (*pos >= rd_buf_size)
2266 r = put_user(*(rd_buf + result), buf);
2269 return r; /* r = -EFAULT */
2282 /* function: read DSC slice bpg offset on the connector
2284 * The read function: dp_dsc_slice_bpg_offset_read
2285 * returns dsc bpg slice offset set in the current configuration
2286 * The value is calculated automatically by DSC code
2287 * and depends on slice parameters and bpp target rate
2288 * The return is an integer: 0 or other positive integer
2289 * If 0 then DSC is disabled.
2291 * Access it with the following command:
2293 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2295 * 0 - means that DSC is disabled
2297 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2298 size_t size, loff_t *pos)
2300 char *rd_buf = NULL;
2301 char *rd_buf_ptr = NULL;
2302 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2303 struct display_stream_compressor *dsc;
2304 struct dcn_dsc_state dsc_state = {0};
2305 const uint32_t rd_buf_size = 100;
2306 struct pipe_ctx *pipe_ctx;
2308 int i, r, str_len = 30;
2310 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2315 rd_buf_ptr = rd_buf;
2317 for (i = 0; i < MAX_PIPES; i++) {
2318 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2319 if (pipe_ctx && pipe_ctx->stream &&
2320 pipe_ctx->stream->link == aconnector->dc_link)
2329 dsc = pipe_ctx->stream_res.dsc;
2331 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2333 snprintf(rd_buf_ptr, str_len,
2335 dsc_state.dsc_slice_bpg_offset);
2336 rd_buf_ptr += str_len;
2339 if (*pos >= rd_buf_size)
2342 r = put_user(*(rd_buf + result), buf);
2345 return r; /* r = -EFAULT */
2360 * function description: Read max_requested_bpc property from the connector
2362 * Access it with the following command:
2364 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2367 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2368 size_t size, loff_t *pos)
2370 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2371 struct drm_connector *connector = &aconnector->base;
2372 struct drm_device *dev = connector->dev;
2373 struct dm_connector_state *state;
2375 char *rd_buf = NULL;
2376 char *rd_buf_ptr = NULL;
2377 const uint32_t rd_buf_size = 10;
2380 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2385 mutex_lock(&dev->mode_config.mutex);
2386 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2388 if (connector->state == NULL)
2391 state = to_dm_connector_state(connector->state);
2393 rd_buf_ptr = rd_buf;
2394 snprintf(rd_buf_ptr, rd_buf_size,
2396 state->base.max_requested_bpc);
2399 if (*pos >= rd_buf_size)
2402 r = put_user(*(rd_buf + result), buf);
2404 result = r; /* r = -EFAULT */
2413 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2414 mutex_unlock(&dev->mode_config.mutex);
2421 * function description: Set max_requested_bpc property on the connector
2423 * This function will not force the input BPC on connector, it will only
2424 * change the max value. This is equivalent to setting max_bpc through
2427 * The BPC value written must be >= 6 and <= 16. Values outside of this
2428 * range will result in errors.
2437 * Write the max_bpc in the following way:
2439 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2442 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2443 size_t size, loff_t *pos)
2445 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2446 struct drm_connector *connector = &aconnector->base;
2447 struct dm_connector_state *state;
2448 struct drm_device *dev = connector->dev;
2449 char *wr_buf = NULL;
2450 uint32_t wr_buf_size = 42;
2451 int max_param_num = 1;
2452 long param[1] = {0};
2453 uint8_t param_nums = 0;
2458 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2461 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2465 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2473 if (param_nums <= 0) {
2474 DRM_DEBUG_DRIVER("user data not be read\n");
2479 if (param[0] < 6 || param[0] > 16) {
2480 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2485 mutex_lock(&dev->mode_config.mutex);
2486 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2488 if (connector->state == NULL)
2491 state = to_dm_connector_state(connector->state);
2492 state->base.max_requested_bpc = param[0];
2494 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2495 mutex_unlock(&dev->mode_config.mutex);
2502 * Backlight at this moment. Read only.
2503 * As written to display, taking ABM and backlight lut into account.
2504 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2506 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/current_backlight
2508 static int current_backlight_show(struct seq_file *m, void *unused)
2510 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2511 struct dc_link *link = aconnector->dc_link;
2512 unsigned int backlight;
2514 backlight = dc_link_get_backlight_level(link);
2515 seq_printf(m, "0x%x\n", backlight);
2521 * Backlight value that is being approached. Read only.
2522 * As written to display, taking ABM and backlight lut into account.
2523 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2525 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/target_backlight
2527 static int target_backlight_show(struct seq_file *m, void *unused)
2529 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2530 struct dc_link *link = aconnector->dc_link;
2531 unsigned int backlight;
2533 backlight = dc_link_get_target_backlight_pwm(link);
2534 seq_printf(m, "0x%x\n", backlight);
2539 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2540 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2541 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2542 DEFINE_SHOW_ATTRIBUTE(output_bpc);
2543 DEFINE_SHOW_ATTRIBUTE(dp_lttpr_status);
2544 #ifdef CONFIG_DRM_AMD_DC_HDCP
2545 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2547 DEFINE_SHOW_ATTRIBUTE(internal_display);
2548 DEFINE_SHOW_ATTRIBUTE(psr_capability);
2550 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2551 .owner = THIS_MODULE,
2552 .read = dp_dsc_clock_en_read,
2553 .write = dp_dsc_clock_en_write,
2554 .llseek = default_llseek
2557 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2558 .owner = THIS_MODULE,
2559 .read = dp_dsc_slice_width_read,
2560 .write = dp_dsc_slice_width_write,
2561 .llseek = default_llseek
2564 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2565 .owner = THIS_MODULE,
2566 .read = dp_dsc_slice_height_read,
2567 .write = dp_dsc_slice_height_write,
2568 .llseek = default_llseek
2571 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2572 .owner = THIS_MODULE,
2573 .read = dp_dsc_bits_per_pixel_read,
2574 .write = dp_dsc_bits_per_pixel_write,
2575 .llseek = default_llseek
2578 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2579 .owner = THIS_MODULE,
2580 .read = dp_dsc_pic_width_read,
2581 .llseek = default_llseek
2584 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2585 .owner = THIS_MODULE,
2586 .read = dp_dsc_pic_height_read,
2587 .llseek = default_llseek
2590 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2591 .owner = THIS_MODULE,
2592 .read = dp_dsc_chunk_size_read,
2593 .llseek = default_llseek
2596 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2597 .owner = THIS_MODULE,
2598 .read = dp_dsc_slice_bpg_offset_read,
2599 .llseek = default_llseek
2602 static const struct file_operations trigger_hotplug_debugfs_fops = {
2603 .owner = THIS_MODULE,
2604 .write = trigger_hotplug,
2605 .llseek = default_llseek
2608 static const struct file_operations dp_link_settings_debugfs_fops = {
2609 .owner = THIS_MODULE,
2610 .read = dp_link_settings_read,
2611 .write = dp_link_settings_write,
2612 .llseek = default_llseek
2615 static const struct file_operations dp_phy_settings_debugfs_fop = {
2616 .owner = THIS_MODULE,
2617 .read = dp_phy_settings_read,
2618 .write = dp_phy_settings_write,
2619 .llseek = default_llseek
2622 static const struct file_operations dp_phy_test_pattern_fops = {
2623 .owner = THIS_MODULE,
2624 .write = dp_phy_test_pattern_debugfs_write,
2625 .llseek = default_llseek
2628 static const struct file_operations sdp_message_fops = {
2629 .owner = THIS_MODULE,
2630 .write = dp_sdp_message_debugfs_write,
2631 .llseek = default_llseek
2634 static const struct file_operations dp_dpcd_address_debugfs_fops = {
2635 .owner = THIS_MODULE,
2636 .write = dp_dpcd_address_write,
2637 .llseek = default_llseek
2640 static const struct file_operations dp_dpcd_size_debugfs_fops = {
2641 .owner = THIS_MODULE,
2642 .write = dp_dpcd_size_write,
2643 .llseek = default_llseek
2646 static const struct file_operations dp_dpcd_data_debugfs_fops = {
2647 .owner = THIS_MODULE,
2648 .read = dp_dpcd_data_read,
2649 .write = dp_dpcd_data_write,
2650 .llseek = default_llseek
2653 static const struct file_operations dp_max_bpc_debugfs_fops = {
2654 .owner = THIS_MODULE,
2655 .read = dp_max_bpc_read,
2656 .write = dp_max_bpc_write,
2657 .llseek = default_llseek
2660 static const struct file_operations dp_dsc_disable_passthrough_debugfs_fops = {
2661 .owner = THIS_MODULE,
2662 .write = dp_dsc_passthrough_set,
2663 .llseek = default_llseek
2666 static const struct {
2668 const struct file_operations *fops;
2669 } dp_debugfs_entries[] = {
2670 {"link_settings", &dp_link_settings_debugfs_fops},
2671 {"phy_settings", &dp_phy_settings_debugfs_fop},
2672 {"lttpr_status", &dp_lttpr_status_fops},
2673 {"test_pattern", &dp_phy_test_pattern_fops},
2674 #ifdef CONFIG_DRM_AMD_DC_HDCP
2675 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2677 {"sdp_message", &sdp_message_fops},
2678 {"aux_dpcd_address", &dp_dpcd_address_debugfs_fops},
2679 {"aux_dpcd_size", &dp_dpcd_size_debugfs_fops},
2680 {"aux_dpcd_data", &dp_dpcd_data_debugfs_fops},
2681 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2682 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2683 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2684 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2685 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2686 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2687 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2688 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2689 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
2690 {"max_bpc", &dp_max_bpc_debugfs_fops},
2691 {"dsc_disable_passthrough", &dp_dsc_disable_passthrough_debugfs_fops},
2694 #ifdef CONFIG_DRM_AMD_DC_HDCP
2695 static const struct {
2697 const struct file_operations *fops;
2698 } hdmi_debugfs_entries[] = {
2699 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
2703 * Force YUV420 output if available from the given mode
2705 static int force_yuv420_output_set(void *data, u64 val)
2707 struct amdgpu_dm_connector *connector = data;
2709 connector->force_yuv420_output = (bool)val;
2715 * Check if YUV420 is forced when available from the given mode
2717 static int force_yuv420_output_get(void *data, u64 *val)
2719 struct amdgpu_dm_connector *connector = data;
2721 *val = connector->force_yuv420_output;
2726 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2727 force_yuv420_output_set, "%llu\n");
2732 static int psr_get(void *data, u64 *val)
2734 struct amdgpu_dm_connector *connector = data;
2735 struct dc_link *link = connector->dc_link;
2736 enum dc_psr_state state = PSR_STATE0;
2738 dc_link_get_psr_state(link, &state);
2746 * Set dmcub trace event IRQ enable or disable.
2747 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2748 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2750 static int dmcub_trace_event_state_set(void *data, u64 val)
2752 struct amdgpu_device *adev = data;
2754 if (val == 1 || val == 0) {
2755 dc_dmub_trace_event_control(adev->dm.dc, val);
2756 adev->dm.dmcub_trace_event_en = (bool)val;
2764 * The interface doesn't need get function, so it will return the
2766 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2768 static int dmcub_trace_event_state_get(void *data, u64 *val)
2770 struct amdgpu_device *adev = data;
2772 *val = adev->dm.dmcub_trace_event_en;
2776 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
2777 dmcub_trace_event_state_set, "%llu\n");
2779 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
2781 DEFINE_SHOW_ATTRIBUTE(current_backlight);
2782 DEFINE_SHOW_ATTRIBUTE(target_backlight);
2784 static const struct {
2786 const struct file_operations *fops;
2787 } connector_debugfs_entries[] = {
2788 {"force_yuv420_output", &force_yuv420_output_fops},
2789 {"output_bpc", &output_bpc_fops},
2790 {"trigger_hotplug", &trigger_hotplug_debugfs_fops},
2791 {"internal_display", &internal_display_fops}
2795 * Returns supported customized link rates by this eDP panel.
2796 * Example usage: cat /sys/kernel/debug/dri/0/eDP-x/ilr_setting
2798 static int edp_ilr_show(struct seq_file *m, void *unused)
2800 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2801 struct dc_link *link = aconnector->dc_link;
2802 uint8_t supported_link_rates[16];
2803 uint32_t link_rate_in_khz;
2807 memset(supported_link_rates, 0, sizeof(supported_link_rates));
2808 dm_helpers_dp_read_dpcd(link->ctx, link, DP_SUPPORTED_LINK_RATES,
2809 supported_link_rates, sizeof(supported_link_rates));
2811 dpcd_rev = link->dpcd_caps.dpcd_rev.raw;
2813 if (dpcd_rev >= DP_DPCD_REV_13 &&
2814 (supported_link_rates[entry+1] != 0 || supported_link_rates[entry] != 0)) {
2816 for (entry = 0; entry < 16; entry += 2) {
2817 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
2818 supported_link_rates[entry]) * 200;
2819 seq_printf(m, "[%d] %d kHz\n", entry/2, link_rate_in_khz);
2822 seq_printf(m, "ILR is not supported by this eDP panel.\n");
2829 * Set supported customized link rate to eDP panel.
2831 * echo <lane_count> <link_rate option> > ilr_setting
2833 * for example, supported ILR : [0] 1620000 kHz [1] 2160000 kHz [2] 2430000 kHz ...
2834 * echo 4 1 > /sys/kernel/debug/dri/0/eDP-x/ilr_setting
2835 * to set 4 lanes and 2.16 GHz
2837 static ssize_t edp_ilr_write(struct file *f, const char __user *buf,
2838 size_t size, loff_t *pos)
2840 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
2841 struct dc_link *link = connector->dc_link;
2842 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
2843 struct dc *dc = (struct dc *)link->dc;
2844 struct dc_link_settings prefer_link_settings;
2845 char *wr_buf = NULL;
2846 const uint32_t wr_buf_size = 40;
2847 /* 0: lane_count; 1: link_rate */
2848 int max_param_num = 2;
2849 uint8_t param_nums = 0;
2851 bool valid_input = true;
2856 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2860 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2868 if (param_nums <= 0) {
2874 case LANE_COUNT_ONE:
2875 case LANE_COUNT_TWO:
2876 case LANE_COUNT_FOUR:
2879 valid_input = false;
2883 if (param[1] >= link->dpcd_caps.edp_supported_link_rates_count)
2884 valid_input = false;
2888 DRM_DEBUG_DRIVER("Invalid Input value. No HW will be programmed\n");
2889 prefer_link_settings.use_link_rate_set = false;
2890 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
2894 /* save user force lane_count, link_rate to preferred settings
2895 * spread spectrum will not be changed
2897 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
2898 prefer_link_settings.lane_count = param[0];
2899 prefer_link_settings.use_link_rate_set = true;
2900 prefer_link_settings.link_rate_set = param[1];
2901 prefer_link_settings.link_rate = link->dpcd_caps.edp_supported_link_rates[param[1]];
2903 mutex_lock(&adev->dm.dc_lock);
2904 dc_link_set_preferred_training_settings(dc, &prefer_link_settings,
2906 mutex_unlock(&adev->dm.dc_lock);
2912 static int edp_ilr_open(struct inode *inode, struct file *file)
2914 return single_open(file, edp_ilr_show, inode->i_private);
2917 static const struct file_operations edp_ilr_debugfs_fops = {
2918 .owner = THIS_MODULE,
2919 .open = edp_ilr_open,
2921 .llseek = seq_lseek,
2922 .release = single_release,
2923 .write = edp_ilr_write
2926 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
2929 struct dentry *dir = connector->base.debugfs_entry;
2931 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
2932 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2933 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
2934 debugfs_create_file(dp_debugfs_entries[i].name,
2935 0644, dir, connector,
2936 dp_debugfs_entries[i].fops);
2939 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2940 debugfs_create_file_unsafe("psr_capability", 0444, dir, connector, &psr_capability_fops);
2941 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
2942 debugfs_create_file("amdgpu_current_backlight_pwm", 0444, dir, connector,
2943 ¤t_backlight_fops);
2944 debugfs_create_file("amdgpu_target_backlight_pwm", 0444, dir, connector,
2945 &target_backlight_fops);
2946 debugfs_create_file("ilr_setting", 0644, dir, connector,
2947 &edp_ilr_debugfs_fops);
2950 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
2951 debugfs_create_file(connector_debugfs_entries[i].name,
2952 0644, dir, connector,
2953 connector_debugfs_entries[i].fops);
2956 connector->debugfs_dpcd_address = 0;
2957 connector->debugfs_dpcd_size = 0;
2959 #ifdef CONFIG_DRM_AMD_DC_HDCP
2960 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
2961 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
2962 debugfs_create_file(hdmi_debugfs_entries[i].name,
2963 0644, dir, connector,
2964 hdmi_debugfs_entries[i].fops);
2970 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
2972 * Set crc window coordinate x start
2974 static int crc_win_x_start_set(void *data, u64 val)
2976 struct drm_crtc *crtc = data;
2977 struct drm_device *drm_dev = crtc->dev;
2978 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2980 spin_lock_irq(&drm_dev->event_lock);
2981 acrtc->dm_irq_params.crc_window.x_start = (uint16_t) val;
2982 acrtc->dm_irq_params.crc_window.update_win = false;
2983 spin_unlock_irq(&drm_dev->event_lock);
2989 * Get crc window coordinate x start
2991 static int crc_win_x_start_get(void *data, u64 *val)
2993 struct drm_crtc *crtc = data;
2994 struct drm_device *drm_dev = crtc->dev;
2995 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2997 spin_lock_irq(&drm_dev->event_lock);
2998 *val = acrtc->dm_irq_params.crc_window.x_start;
2999 spin_unlock_irq(&drm_dev->event_lock);
3004 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
3005 crc_win_x_start_set, "%llu\n");
3009 * Set crc window coordinate y start
3011 static int crc_win_y_start_set(void *data, u64 val)
3013 struct drm_crtc *crtc = data;
3014 struct drm_device *drm_dev = crtc->dev;
3015 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3017 spin_lock_irq(&drm_dev->event_lock);
3018 acrtc->dm_irq_params.crc_window.y_start = (uint16_t) val;
3019 acrtc->dm_irq_params.crc_window.update_win = false;
3020 spin_unlock_irq(&drm_dev->event_lock);
3026 * Get crc window coordinate y start
3028 static int crc_win_y_start_get(void *data, u64 *val)
3030 struct drm_crtc *crtc = data;
3031 struct drm_device *drm_dev = crtc->dev;
3032 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3034 spin_lock_irq(&drm_dev->event_lock);
3035 *val = acrtc->dm_irq_params.crc_window.y_start;
3036 spin_unlock_irq(&drm_dev->event_lock);
3041 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
3042 crc_win_y_start_set, "%llu\n");
3045 * Set crc window coordinate x end
3047 static int crc_win_x_end_set(void *data, u64 val)
3049 struct drm_crtc *crtc = data;
3050 struct drm_device *drm_dev = crtc->dev;
3051 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3053 spin_lock_irq(&drm_dev->event_lock);
3054 acrtc->dm_irq_params.crc_window.x_end = (uint16_t) val;
3055 acrtc->dm_irq_params.crc_window.update_win = false;
3056 spin_unlock_irq(&drm_dev->event_lock);
3062 * Get crc window coordinate x end
3064 static int crc_win_x_end_get(void *data, u64 *val)
3066 struct drm_crtc *crtc = data;
3067 struct drm_device *drm_dev = crtc->dev;
3068 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3070 spin_lock_irq(&drm_dev->event_lock);
3071 *val = acrtc->dm_irq_params.crc_window.x_end;
3072 spin_unlock_irq(&drm_dev->event_lock);
3077 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
3078 crc_win_x_end_set, "%llu\n");
3081 * Set crc window coordinate y end
3083 static int crc_win_y_end_set(void *data, u64 val)
3085 struct drm_crtc *crtc = data;
3086 struct drm_device *drm_dev = crtc->dev;
3087 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3089 spin_lock_irq(&drm_dev->event_lock);
3090 acrtc->dm_irq_params.crc_window.y_end = (uint16_t) val;
3091 acrtc->dm_irq_params.crc_window.update_win = false;
3092 spin_unlock_irq(&drm_dev->event_lock);
3098 * Get crc window coordinate y end
3100 static int crc_win_y_end_get(void *data, u64 *val)
3102 struct drm_crtc *crtc = data;
3103 struct drm_device *drm_dev = crtc->dev;
3104 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3106 spin_lock_irq(&drm_dev->event_lock);
3107 *val = acrtc->dm_irq_params.crc_window.y_end;
3108 spin_unlock_irq(&drm_dev->event_lock);
3113 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
3114 crc_win_y_end_set, "%llu\n");
3116 * Trigger to commit crc window
3118 static int crc_win_update_set(void *data, u64 val)
3120 struct drm_crtc *new_crtc = data;
3121 struct drm_crtc *old_crtc = NULL;
3122 struct amdgpu_crtc *new_acrtc, *old_acrtc;
3123 struct amdgpu_device *adev = drm_to_adev(new_crtc->dev);
3124 struct crc_rd_work *crc_rd_wrk = adev->dm.crc_rd_wrk;
3130 spin_lock_irq(&adev_to_drm(adev)->event_lock);
3131 spin_lock_irq(&crc_rd_wrk->crc_rd_work_lock);
3132 if (crc_rd_wrk->crtc) {
3133 old_crtc = crc_rd_wrk->crtc;
3134 old_acrtc = to_amdgpu_crtc(old_crtc);
3136 new_acrtc = to_amdgpu_crtc(new_crtc);
3138 if (old_crtc && old_crtc != new_crtc) {
3139 old_acrtc->dm_irq_params.crc_window.activated = false;
3140 old_acrtc->dm_irq_params.crc_window.update_win = false;
3141 old_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3143 new_acrtc->dm_irq_params.crc_window.activated = true;
3144 new_acrtc->dm_irq_params.crc_window.update_win = true;
3145 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3146 crc_rd_wrk->crtc = new_crtc;
3148 new_acrtc->dm_irq_params.crc_window.activated = true;
3149 new_acrtc->dm_irq_params.crc_window.update_win = true;
3150 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3151 crc_rd_wrk->crtc = new_crtc;
3153 spin_unlock_irq(&crc_rd_wrk->crc_rd_work_lock);
3154 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
3161 * Get crc window update flag
3163 static int crc_win_update_get(void *data, u64 *val)
3169 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
3170 crc_win_update_set, "%llu\n");
3172 void crtc_debugfs_init(struct drm_crtc *crtc)
3174 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
3179 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
3180 &crc_win_x_start_fops);
3181 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
3182 &crc_win_y_start_fops);
3183 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
3184 &crc_win_x_end_fops);
3185 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
3186 &crc_win_y_end_fops);
3187 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
3188 &crc_win_update_fops);
3193 * Writes DTN log state to the user supplied buffer.
3194 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3196 static ssize_t dtn_log_read(
3202 struct amdgpu_device *adev = file_inode(f)->i_private;
3203 struct dc *dc = adev->dm.dc;
3204 struct dc_log_buffer_ctx log_ctx = { 0 };
3210 if (!dc->hwss.log_hw_state)
3213 dc->hwss.log_hw_state(dc, &log_ctx);
3215 if (*pos < log_ctx.pos) {
3216 size_t to_copy = log_ctx.pos - *pos;
3218 to_copy = min(to_copy, size);
3220 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
3232 * Writes DTN log state to dmesg when triggered via a write.
3233 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3235 static ssize_t dtn_log_write(
3237 const char __user *buf,
3241 struct amdgpu_device *adev = file_inode(f)->i_private;
3242 struct dc *dc = adev->dm.dc;
3244 /* Write triggers log output via dmesg. */
3248 if (dc->hwss.log_hw_state)
3249 dc->hwss.log_hw_state(dc, NULL);
3254 static int mst_topo_show(struct seq_file *m, void *unused)
3256 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3257 struct drm_device *dev = adev_to_drm(adev);
3258 struct drm_connector *connector;
3259 struct drm_connector_list_iter conn_iter;
3260 struct amdgpu_dm_connector *aconnector;
3262 drm_connector_list_iter_begin(dev, &conn_iter);
3263 drm_for_each_connector_iter(connector, &conn_iter) {
3264 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3267 aconnector = to_amdgpu_dm_connector(connector);
3269 /* Ensure we're only dumping the topology of a root mst node */
3270 if (!aconnector->mst_mgr.mst_state)
3273 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
3274 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
3276 drm_connector_list_iter_end(&conn_iter);
3282 * Sets trigger hpd for MST topologies.
3283 * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
3284 * All topologies will be disconnected if val of 0 is set .
3285 * Usage to enable topologies: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3286 * Usage to disable topologies: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3288 static int trigger_hpd_mst_set(void *data, u64 val)
3290 struct amdgpu_device *adev = data;
3291 struct drm_device *dev = adev_to_drm(adev);
3292 struct drm_connector_list_iter iter;
3293 struct amdgpu_dm_connector *aconnector;
3294 struct drm_connector *connector;
3295 struct dc_link *link = NULL;
3298 drm_connector_list_iter_begin(dev, &iter);
3299 drm_for_each_connector_iter(connector, &iter) {
3300 aconnector = to_amdgpu_dm_connector(connector);
3301 if (aconnector->dc_link->type == dc_connection_mst_branch &&
3302 aconnector->mst_mgr.aux) {
3303 dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3304 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
3307 } else if (val == 0) {
3308 drm_connector_list_iter_begin(dev, &iter);
3309 drm_for_each_connector_iter(connector, &iter) {
3310 aconnector = to_amdgpu_dm_connector(connector);
3311 if (!aconnector->dc_link)
3314 if (!aconnector->mst_port)
3317 link = aconnector->dc_link;
3318 dp_receiver_power_ctrl(link, false);
3319 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_port->mst_mgr, false);
3320 link->mst_stream_alloc_table.stream_count = 0;
3321 memset(link->mst_stream_alloc_table.stream_allocations, 0,
3322 sizeof(link->mst_stream_alloc_table.stream_allocations));
3327 drm_kms_helper_hotplug_event(dev);
3333 * The interface doesn't need get function, so it will return the
3335 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3337 static int trigger_hpd_mst_get(void *data, u64 *val)
3343 DEFINE_DEBUGFS_ATTRIBUTE(trigger_hpd_mst_ops, trigger_hpd_mst_get,
3344 trigger_hpd_mst_set, "%llu\n");
3348 * Sets the force_timing_sync debug option from the given string.
3349 * All connected displays will be force synchronized immediately.
3350 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3352 static int force_timing_sync_set(void *data, u64 val)
3354 struct amdgpu_device *adev = data;
3356 adev->dm.force_timing_sync = (bool)val;
3358 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
3364 * Gets the force_timing_sync debug option value into the given buffer.
3365 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3367 static int force_timing_sync_get(void *data, u64 *val)
3369 struct amdgpu_device *adev = data;
3371 *val = adev->dm.force_timing_sync;
3376 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
3377 force_timing_sync_set, "%llu\n");
3381 * Disables all HPD and HPD RX interrupt handling in the
3382 * driver when set to 1. Default is 0.
3384 static int disable_hpd_set(void *data, u64 val)
3386 struct amdgpu_device *adev = data;
3388 adev->dm.disable_hpd_irq = (bool)val;
3395 * Returns 1 if HPD and HPRX interrupt handling is disabled,
3398 static int disable_hpd_get(void *data, u64 *val)
3400 struct amdgpu_device *adev = data;
3402 *val = adev->dm.disable_hpd_irq;
3407 DEFINE_DEBUGFS_ATTRIBUTE(disable_hpd_ops, disable_hpd_get,
3408 disable_hpd_set, "%llu\n");
3410 #if defined(CONFIG_DRM_AMD_DC_DCN)
3412 * Temporary w/a to force sst sequence in M42D DP2 mst receiver
3413 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_set_mst_en_for_sst
3415 static int dp_force_sst_set(void *data, u64 val)
3417 struct amdgpu_device *adev = data;
3419 adev->dm.dc->debug.set_mst_en_for_sst = val;
3424 static int dp_force_sst_get(void *data, u64 *val)
3426 struct amdgpu_device *adev = data;
3428 *val = adev->dm.dc->debug.set_mst_en_for_sst;
3432 DEFINE_DEBUGFS_ATTRIBUTE(dp_set_mst_en_for_sst_ops, dp_force_sst_get,
3433 dp_force_sst_set, "%llu\n");
3436 * Force DP2 sequence without VESA certified cable.
3437 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_ignore_cable_id
3439 static int dp_ignore_cable_id_set(void *data, u64 val)
3441 struct amdgpu_device *adev = data;
3443 adev->dm.dc->debug.ignore_cable_id = val;
3448 static int dp_ignore_cable_id_get(void *data, u64 *val)
3450 struct amdgpu_device *adev = data;
3452 *val = adev->dm.dc->debug.ignore_cable_id;
3456 DEFINE_DEBUGFS_ATTRIBUTE(dp_ignore_cable_id_ops, dp_ignore_cable_id_get,
3457 dp_ignore_cable_id_set, "%llu\n");
3461 * Sets the DC visual confirm debug option from the given string.
3462 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
3464 static int visual_confirm_set(void *data, u64 val)
3466 struct amdgpu_device *adev = data;
3468 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
3474 * Reads the DC visual confirm debug option value into the given buffer.
3475 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
3477 static int visual_confirm_get(void *data, u64 *val)
3479 struct amdgpu_device *adev = data;
3481 *val = adev->dm.dc->debug.visual_confirm;
3486 DEFINE_SHOW_ATTRIBUTE(mst_topo);
3487 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
3488 visual_confirm_set, "%llu\n");
3491 * Dumps the DCC_EN bit for each pipe.
3492 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dcc_en
3494 static ssize_t dcc_en_bits_read(
3500 struct amdgpu_device *adev = file_inode(f)->i_private;
3501 struct dc *dc = adev->dm.dc;
3502 char *rd_buf = NULL;
3503 const uint32_t rd_buf_size = 32;
3504 uint32_t result = 0;
3506 int num_pipes = dc->res_pool->pipe_count;
3510 dcc_en_bits = kcalloc(num_pipes, sizeof(int), GFP_KERNEL);
3514 if (!dc->hwss.get_dcc_en_bits) {
3519 dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
3521 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
3527 for (i = 0; i < num_pipes; i++)
3528 offset += snprintf(rd_buf + offset, rd_buf_size - offset,
3529 "%d ", dcc_en_bits[i]);
3530 rd_buf[strlen(rd_buf)] = '\n';
3535 if (*pos >= rd_buf_size)
3537 r = put_user(*(rd_buf + result), buf);
3540 return r; /* r = -EFAULT */
3552 void dtn_debugfs_init(struct amdgpu_device *adev)
3554 static const struct file_operations dtn_log_fops = {
3555 .owner = THIS_MODULE,
3556 .read = dtn_log_read,
3557 .write = dtn_log_write,
3558 .llseek = default_llseek
3560 static const struct file_operations dcc_en_bits_fops = {
3561 .owner = THIS_MODULE,
3562 .read = dcc_en_bits_read,
3563 .llseek = default_llseek
3566 struct drm_minor *minor = adev_to_drm(adev)->primary;
3567 struct dentry *root = minor->debugfs_root;
3569 debugfs_create_file("amdgpu_mst_topology", 0444, root,
3570 adev, &mst_topo_fops);
3571 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
3573 #if defined(CONFIG_DRM_AMD_DC_DCN)
3574 debugfs_create_file("amdgpu_dm_dp_set_mst_en_for_sst", 0644, root, adev,
3575 &dp_set_mst_en_for_sst_ops);
3576 debugfs_create_file("amdgpu_dm_dp_ignore_cable_id", 0644, root, adev,
3577 &dp_ignore_cable_id_ops);
3580 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
3581 &visual_confirm_fops);
3583 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
3584 adev, &dmub_tracebuffer_fops);
3586 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
3587 adev, &dmub_fw_state_fops);
3589 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
3590 adev, &force_timing_sync_ops);
3592 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
3593 adev, &dmcub_trace_event_state_fops);
3595 debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
3596 adev, &trigger_hpd_mst_ops);
3598 debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
3601 debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,