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 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
55 * Function takes in attributes passed to debugfs write entry
56 * and writes into param array.
57 * The user passes max_param_num to identify maximum number of
58 * parameters that could be parsed.
61 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
62 long *param, const char __user *buf,
66 char *wr_buf_ptr = NULL;
67 uint32_t wr_buf_count = 0;
70 const char delimiter[3] = {' ', '\n', '\0'};
71 uint8_t param_index = 0;
77 /* r is bytes not be copied */
78 if (copy_from_user(wr_buf_ptr, buf, wr_buf_size)) {
79 DRM_DEBUG_DRIVER("user data could not be read successfully\n");
83 /* check number of parameters. isspace could not differ space and \n */
84 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
86 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
91 if (wr_buf_count == wr_buf_size)
95 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
102 if (wr_buf_count == wr_buf_size)
106 if (*param_nums > max_param_num)
107 *param_nums = max_param_num;
109 wr_buf_ptr = wr_buf; /* reset buf pointer */
110 wr_buf_count = 0; /* number of char already checked */
112 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
117 while (param_index < *param_nums) {
118 /* after strsep, wr_buf_ptr will be moved to after space */
119 sub_str = strsep(&wr_buf_ptr, delimiter);
121 r = kstrtol(sub_str, 16, &(param[param_index]));
124 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
132 /* function description
133 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
135 * valid lane count value: 1, 2, 4
136 * valid link rate value:
137 * 06h = 1.62Gbps per lane
138 * 0Ah = 2.7Gbps per lane
139 * 0Ch = 3.24Gbps per lane
140 * 14h = 5.4Gbps per lane
141 * 1Eh = 8.1Gbps per lane
143 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
145 * --- to get dp configuration
147 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
149 * It will list current, verified, reported, preferred dp configuration.
150 * current -- for current video mode
151 * verified --- maximum configuration which pass link training
152 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
153 * preferred --- user force settings
155 * --- set (or force) dp configuration
157 * echo <lane_count> <link_rate> > link_settings
159 * for example, to force to 2 lane, 2.7GHz,
160 * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
162 * spread_spectrum could not be changed dynamically.
164 * in case invalid lane count, link rate are force, no hw programming will be
165 * done. please check link settings after force operation to see if HW get
168 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
170 * check current and preferred settings.
173 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
174 size_t size, loff_t *pos)
176 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
177 struct dc_link *link = connector->dc_link;
179 char *rd_buf_ptr = NULL;
180 const uint32_t rd_buf_size = 100;
185 if (*pos & 3 || size & 3)
188 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
194 str_len = strlen("Current: %d 0x%x %d ");
195 snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
196 link->cur_link_settings.lane_count,
197 link->cur_link_settings.link_rate,
198 link->cur_link_settings.link_spread);
199 rd_buf_ptr += str_len;
201 str_len = strlen("Verified: %d 0x%x %d ");
202 snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
203 link->verified_link_cap.lane_count,
204 link->verified_link_cap.link_rate,
205 link->verified_link_cap.link_spread);
206 rd_buf_ptr += str_len;
208 str_len = strlen("Reported: %d 0x%x %d ");
209 snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
210 link->reported_link_cap.lane_count,
211 link->reported_link_cap.link_rate,
212 link->reported_link_cap.link_spread);
213 rd_buf_ptr += str_len;
215 str_len = strlen("Preferred: %d 0x%x %d ");
216 snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
217 link->preferred_link_setting.lane_count,
218 link->preferred_link_setting.link_rate,
219 link->preferred_link_setting.link_spread);
222 if (*pos >= rd_buf_size)
225 r = put_user(*(rd_buf + result), buf);
228 return r; /* r = -EFAULT */
241 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
242 size_t size, loff_t *pos)
244 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
245 struct dc_link *link = connector->dc_link;
246 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
247 struct dc *dc = (struct dc *)link->dc;
248 struct dc_link_settings prefer_link_settings;
250 const uint32_t wr_buf_size = 40;
251 /* 0: lane_count; 1: link_rate */
252 int max_param_num = 2;
253 uint8_t param_nums = 0;
255 bool valid_input = true;
260 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
264 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
272 if (param_nums <= 0) {
274 DRM_DEBUG_DRIVER("user data not be read\n");
281 case LANE_COUNT_FOUR:
292 case LINK_RATE_HIGH2:
293 case LINK_RATE_HIGH3:
294 #if defined(CONFIG_DRM_AMD_DC_DCN)
295 case LINK_RATE_UHBR10:
305 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
306 mutex_lock(&adev->dm.dc_lock);
307 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
308 mutex_unlock(&adev->dm.dc_lock);
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 mutex_lock(&adev->dm.dc_lock);
321 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, false);
322 mutex_unlock(&adev->dm.dc_lock);
328 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
329 * post-cursor2 (defined by VESA DP specification)
332 * voltage swing: 0,1,2,3
333 * pre-emphasis : 0,1,2,3
334 * post cursor2 : 0,1,2,3
337 * how to use this debugfs
339 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
341 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
343 * To figure out which DP-x is the display for DP to be check,
346 * There should be debugfs file, like link_settings, phy_settings.
348 * from lane_count, link_rate to figure which DP-x is for display to be worked
351 * To get current DP PHY settings,
354 * To change DP PHY settings,
355 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
356 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
358 * echo 2 3 0 > phy_settings
360 * To check if change be applied, get current phy settings by
363 * In case invalid values are set by user, like
364 * echo 1 4 0 > phy_settings
366 * HW will NOT be programmed by these settings.
367 * cat phy_settings will show the previous valid settings.
369 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
370 size_t size, loff_t *pos)
372 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
373 struct dc_link *link = connector->dc_link;
375 const uint32_t rd_buf_size = 20;
379 if (*pos & 3 || size & 3)
382 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
386 snprintf(rd_buf, rd_buf_size, " %d %d %d\n",
387 link->cur_lane_setting[0].VOLTAGE_SWING,
388 link->cur_lane_setting[0].PRE_EMPHASIS,
389 link->cur_lane_setting[0].POST_CURSOR2);
392 if (*pos >= rd_buf_size)
395 r = put_user((*(rd_buf + result)), buf);
398 return r; /* r = -EFAULT */
411 static int dp_lttpr_status_show(struct seq_file *m, void *d)
414 struct amdgpu_dm_connector *connector = file_inode(m->file)->i_private;
415 struct dc_link *link = connector->dc_link;
416 uint32_t read_size = 1;
417 uint8_t repeater_count = 0;
419 data = kzalloc(read_size, GFP_KERNEL);
423 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0002, data, read_size);
425 switch ((uint8_t)*data) {
454 repeater_count = (uint8_t)*data;
458 seq_printf(m, "phy repeater count: %d\n", repeater_count);
460 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0003, data, read_size);
462 if ((uint8_t)*data == 0x55)
463 seq_printf(m, "phy repeater mode: transparent\n");
464 else if ((uint8_t)*data == 0xAA)
465 seq_printf(m, "phy repeater mode: non-transparent\n");
466 else if ((uint8_t)*data == 0x00)
467 seq_printf(m, "phy repeater mode: non lttpr\n");
469 seq_printf(m, "phy repeater mode: read error\n");
475 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
476 size_t size, loff_t *pos)
478 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
479 struct dc_link *link = connector->dc_link;
480 struct dc *dc = (struct dc *)link->dc;
482 uint32_t wr_buf_size = 40;
484 bool use_prefer_link_setting;
485 struct link_training_settings link_lane_settings;
486 int max_param_num = 3;
487 uint8_t param_nums = 0;
494 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
498 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
506 if (param_nums <= 0) {
508 DRM_DEBUG_DRIVER("user data not be read\n");
512 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
513 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
514 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
516 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
520 /* get link settings: lane count, link rate */
521 use_prefer_link_setting =
522 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
523 (link->test_pattern_enabled));
525 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
527 if (use_prefer_link_setting) {
528 link_lane_settings.link_settings.lane_count =
529 link->preferred_link_setting.lane_count;
530 link_lane_settings.link_settings.link_rate =
531 link->preferred_link_setting.link_rate;
532 link_lane_settings.link_settings.link_spread =
533 link->preferred_link_setting.link_spread;
535 link_lane_settings.link_settings.lane_count =
536 link->cur_link_settings.lane_count;
537 link_lane_settings.link_settings.link_rate =
538 link->cur_link_settings.link_rate;
539 link_lane_settings.link_settings.link_spread =
540 link->cur_link_settings.link_spread;
543 /* apply phy settings from user */
544 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
545 link_lane_settings.lane_settings[r].VOLTAGE_SWING =
546 (enum dc_voltage_swing) (param[0]);
547 link_lane_settings.lane_settings[r].PRE_EMPHASIS =
548 (enum dc_pre_emphasis) (param[1]);
549 link_lane_settings.lane_settings[r].POST_CURSOR2 =
550 (enum dc_post_cursor2) (param[2]);
553 /* program ASIC registers and DPCD registers */
554 dc_link_set_drive_settings(dc, &link_lane_settings, link);
560 /* function description
562 * set PHY layer or Link layer test pattern
563 * PHY test pattern is used for PHY SI check.
564 * Link layer test will not affect PHY SI.
566 * Reset Test Pattern:
567 * 0 = DP_TEST_PATTERN_VIDEO_MODE
569 * PHY test pattern supported:
570 * 1 = DP_TEST_PATTERN_D102
571 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
572 * 3 = DP_TEST_PATTERN_PRBS7
573 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
574 * 5 = DP_TEST_PATTERN_CP2520_1
575 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
576 * 7 = DP_TEST_PATTERN_CP2520_3
578 * DP PHY Link Training Patterns
579 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
580 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
581 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
582 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
584 * DP Link Layer Test pattern
585 * c = DP_TEST_PATTERN_COLOR_SQUARES
586 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
587 * e = DP_TEST_PATTERN_VERTICAL_BARS
588 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
589 * 10= DP_TEST_PATTERN_COLOR_RAMP
591 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
593 * --- set test pattern
594 * echo <test pattern #> > test_pattern
596 * If test pattern # is not supported, NO HW programming will be done.
597 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
598 * for the user pattern. input 10 bytes data are separated by space
600 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
602 * --- reset test pattern
603 * echo 0 > test_pattern
605 * --- HPD detection is disabled when set PHY test pattern
607 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
608 * is disable. User could unplug DP display from DP connected and plug scope to
609 * check test pattern PHY SI.
610 * If there is need unplug scope and plug DP display back, do steps below:
611 * echo 0 > phy_test_pattern
615 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
616 * driver could detect "unplug scope" and "plug DP display"
618 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
619 size_t size, loff_t *pos)
621 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
622 struct dc_link *link = connector->dc_link;
624 uint32_t wr_buf_size = 100;
625 long param[11] = {0x0};
626 int max_param_num = 11;
627 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
628 bool disable_hpd = false;
629 bool valid_test_pattern = false;
630 uint8_t param_nums = 0;
631 /* init with default 80bit custom pattern */
632 uint8_t custom_pattern[10] = {
633 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
634 0x1f, 0x7c, 0xf0, 0xc1, 0x07
636 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
637 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
638 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
639 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
640 struct link_training_settings link_training_settings;
646 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
650 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
658 if (param_nums <= 0) {
660 DRM_DEBUG_DRIVER("user data not be read\n");
665 test_pattern = param[0];
667 switch (test_pattern) {
668 case DP_TEST_PATTERN_VIDEO_MODE:
669 case DP_TEST_PATTERN_COLOR_SQUARES:
670 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
671 case DP_TEST_PATTERN_VERTICAL_BARS:
672 case DP_TEST_PATTERN_HORIZONTAL_BARS:
673 case DP_TEST_PATTERN_COLOR_RAMP:
674 valid_test_pattern = true;
677 case DP_TEST_PATTERN_D102:
678 case DP_TEST_PATTERN_SYMBOL_ERROR:
679 case DP_TEST_PATTERN_PRBS7:
680 case DP_TEST_PATTERN_80BIT_CUSTOM:
681 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
682 case DP_TEST_PATTERN_TRAINING_PATTERN4:
684 valid_test_pattern = true;
688 valid_test_pattern = false;
689 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
693 if (!valid_test_pattern) {
695 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
699 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
700 for (i = 0; i < 10; i++) {
701 if ((uint8_t) param[i + 1] != 0x0)
706 /* not use default value */
707 for (i = 0; i < 10; i++)
708 custom_pattern[i] = (uint8_t) param[i + 1];
712 /* Usage: set DP physical test pattern using debugfs with normal DP
713 * panel. Then plug out DP panel and connect a scope to measure
714 * For normal video mode and test pattern generated from CRCT,
715 * they are visibile to user. So do not disable HPD.
716 * Video Mode is also set to clear the test pattern, so enable HPD
717 * because it might have been disabled after a test pattern was set.
718 * AUX depends on HPD * sequence dependent, do not move!
721 dc_link_enable_hpd(link);
723 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
724 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
725 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
727 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
728 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
729 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
731 link_training_settings.link_settings = cur_link_settings;
734 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
735 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
736 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
737 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
738 prefer_link_settings.link_rate != cur_link_settings.link_rate))
739 link_training_settings.link_settings = prefer_link_settings;
742 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
743 link_training_settings.lane_settings[i] = link->cur_lane_setting[i];
745 dc_link_set_test_pattern(
748 DP_TEST_PATTERN_COLOR_SPACE_RGB,
749 &link_training_settings,
753 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
754 * Then plug out DP panel and connect a scope to measure DP PHY signal.
755 * Need disable interrupt to avoid SW driver disable DP output. This is
756 * done after the test pattern is set.
758 if (valid_test_pattern && disable_hpd)
759 dc_link_disable_hpd(link);
767 * Returns the DMCUB tracebuffer contents.
768 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
770 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
772 struct amdgpu_device *adev = m->private;
773 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
774 struct dmub_debugfs_trace_entry *entries;
776 uint32_t tbuf_size, max_entries, num_entries, i;
781 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
785 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
786 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
787 sizeof(struct dmub_debugfs_trace_entry);
790 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
792 num_entries = min(num_entries, max_entries);
794 entries = (struct dmub_debugfs_trace_entry
796 sizeof(struct dmub_debugfs_trace_header));
798 for (i = 0; i < num_entries; ++i) {
799 struct dmub_debugfs_trace_entry *entry = &entries[i];
802 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
803 entry->trace_code, entry->tick_count, entry->param0,
811 * Returns the DMCUB firmware state contents.
812 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
814 static int dmub_fw_state_show(struct seq_file *m, void *data)
816 struct amdgpu_device *adev = m->private;
817 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
824 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
828 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
830 return seq_write(m, state_base, state_size);
833 /* psr_capability_show() - show eDP panel PSR capability
835 * The read function: sink_psr_capability_show
836 * Shows if sink has PSR capability or not.
837 * If yes - the PSR version is appended
839 * cat /sys/kernel/debug/dri/0/eDP-X/psr_capability
842 * "Sink support: no\n" - if panel doesn't support PSR
843 * "Sink support: yes [0x01]\n" - if panel supports PSR1
844 * "Driver support: no\n" - if driver doesn't support PSR
845 * "Driver support: yes [0x01]\n" - if driver supports PSR1
847 static int psr_capability_show(struct seq_file *m, void *data)
849 struct drm_connector *connector = m->private;
850 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
851 struct dc_link *link = aconnector->dc_link;
856 if (link->type == dc_connection_none)
859 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
862 seq_printf(m, "Sink support: %s", str_yes_no(link->dpcd_caps.psr_info.psr_version != 0));
863 if (link->dpcd_caps.psr_info.psr_version)
864 seq_printf(m, " [0x%02x]", link->dpcd_caps.psr_info.psr_version);
867 seq_printf(m, "Driver support: %s", str_yes_no(link->psr_settings.psr_feature_enabled));
868 if (link->psr_settings.psr_version)
869 seq_printf(m, " [0x%02x]", link->psr_settings.psr_version);
876 * Returns the current and maximum output bpc for the connector.
877 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/output_bpc
879 static int output_bpc_show(struct seq_file *m, void *data)
881 struct drm_connector *connector = m->private;
882 struct drm_device *dev = connector->dev;
883 struct drm_crtc *crtc = NULL;
884 struct dm_crtc_state *dm_crtc_state = NULL;
888 mutex_lock(&dev->mode_config.mutex);
889 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
891 if (connector->state == NULL)
894 crtc = connector->state->crtc;
898 drm_modeset_lock(&crtc->mutex, NULL);
899 if (crtc->state == NULL)
902 dm_crtc_state = to_dm_crtc_state(crtc->state);
903 if (dm_crtc_state->stream == NULL)
906 switch (dm_crtc_state->stream->timing.display_color_depth) {
907 case COLOR_DEPTH_666:
910 case COLOR_DEPTH_888:
913 case COLOR_DEPTH_101010:
916 case COLOR_DEPTH_121212:
919 case COLOR_DEPTH_161616:
926 seq_printf(m, "Current: %u\n", bpc);
927 seq_printf(m, "Maximum: %u\n", connector->display_info.bpc);
932 drm_modeset_unlock(&crtc->mutex);
934 drm_modeset_unlock(&dev->mode_config.connection_mutex);
935 mutex_unlock(&dev->mode_config.mutex);
942 * Disable dsc passthrough, i.e.,: have dsc decoding at converver, not external RX
943 * echo 1 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
944 * Enable dsc passthrough, i.e.,: have dsc passthrough to external RX
945 * echo 0 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
947 static ssize_t dp_dsc_passthrough_set(struct file *f, const char __user *buf,
948 size_t size, loff_t *pos)
950 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
952 uint32_t wr_buf_size = 42;
953 int max_param_num = 1;
955 uint8_t param_nums = 0;
960 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
963 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
967 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
975 aconnector->dsc_settings.dsc_force_disable_passthrough = param;
981 #ifdef CONFIG_DRM_AMD_DC_HDCP
983 * Returns the HDCP capability of the Display (1.4 for now).
985 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
986 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
988 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
989 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
991 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
993 struct drm_connector *connector = m->private;
994 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
995 bool hdcp_cap, hdcp2_cap;
997 if (connector->status != connector_status_connected)
1000 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
1002 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1003 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1007 seq_printf(m, "%s ", "HDCP1.4");
1009 seq_printf(m, "%s ", "HDCP2.2");
1011 if (!hdcp_cap && !hdcp2_cap)
1012 seq_printf(m, "%s ", "None");
1021 * Returns whether the connected display is internal and not hotpluggable.
1022 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/internal_display
1024 static int internal_display_show(struct seq_file *m, void *data)
1026 struct drm_connector *connector = m->private;
1027 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1028 struct dc_link *link = aconnector->dc_link;
1030 seq_printf(m, "Internal: %u\n", link->is_internal_display);
1035 /* function description
1037 * generic SDP message access for testing
1039 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
1042 * Hb0 : Secondary-Data Packet ID
1043 * Hb1 : Secondary-Data Packet type
1044 * Hb2 : Secondary-Data-packet-specific header, Byte 0
1045 * Hb3 : Secondary-Data-packet-specific header, Byte 1
1047 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
1049 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
1050 size_t size, loff_t *pos)
1054 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1055 struct dm_crtc_state *acrtc_state;
1056 uint32_t write_size = 36;
1058 if (connector->base.status != connector_status_connected)
1064 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
1066 r = copy_from_user(data, buf, write_size);
1070 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
1075 static ssize_t dp_dpcd_address_write(struct file *f, const char __user *buf,
1076 size_t size, loff_t *pos)
1079 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1081 if (size < sizeof(connector->debugfs_dpcd_address))
1084 r = copy_from_user(&connector->debugfs_dpcd_address,
1085 buf, sizeof(connector->debugfs_dpcd_address));
1090 static ssize_t dp_dpcd_size_write(struct file *f, const char __user *buf,
1091 size_t size, loff_t *pos)
1094 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1096 if (size < sizeof(connector->debugfs_dpcd_size))
1099 r = copy_from_user(&connector->debugfs_dpcd_size,
1100 buf, sizeof(connector->debugfs_dpcd_size));
1102 if (connector->debugfs_dpcd_size > 256)
1103 connector->debugfs_dpcd_size = 0;
1108 static ssize_t dp_dpcd_data_write(struct file *f, const char __user *buf,
1109 size_t size, loff_t *pos)
1113 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1114 struct dc_link *link = connector->dc_link;
1115 uint32_t write_size = connector->debugfs_dpcd_size;
1117 if (!write_size || size < write_size)
1120 data = kzalloc(write_size, GFP_KERNEL);
1124 r = copy_from_user(data, buf, write_size);
1126 dm_helpers_dp_write_dpcd(link->ctx, link,
1127 connector->debugfs_dpcd_address, data, write_size - r);
1129 return write_size - r;
1132 static ssize_t dp_dpcd_data_read(struct file *f, char __user *buf,
1133 size_t size, loff_t *pos)
1137 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1138 struct dc_link *link = connector->dc_link;
1139 uint32_t read_size = connector->debugfs_dpcd_size;
1141 if (!read_size || size < read_size)
1144 data = kzalloc(read_size, GFP_KERNEL);
1148 dm_helpers_dp_read_dpcd(link->ctx, link,
1149 connector->debugfs_dpcd_address, data, read_size);
1151 r = copy_to_user(buf, data, read_size);
1154 return read_size - r;
1157 /* function: Read link's DSC & FEC capabilities
1160 * Access it with the following command (you need to specify
1161 * connector like DP-1):
1163 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
1166 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
1168 struct drm_connector *connector = m->private;
1169 struct drm_modeset_acquire_ctx ctx;
1170 struct drm_device *dev = connector->dev;
1171 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1173 bool try_again = false;
1174 bool is_fec_supported = false;
1175 bool is_dsc_supported = false;
1176 struct dpcd_caps dpcd_caps;
1178 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1181 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1183 if (ret == -EDEADLK) {
1184 ret = drm_modeset_backoff(&ctx);
1192 if (connector->status != connector_status_connected) {
1196 dpcd_caps = aconnector->dc_link->dpcd_caps;
1197 if (aconnector->port) {
1198 /* aconnector sets dsc_aux during get_modes call
1199 * if MST connector has it means it can either
1200 * enable DSC on the sink device or on MST branch
1203 if (aconnector->dsc_aux) {
1204 is_fec_supported = true;
1205 is_dsc_supported = true;
1208 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1209 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1211 } while (try_again);
1213 drm_modeset_drop_locks(&ctx);
1214 drm_modeset_acquire_fini(&ctx);
1216 seq_printf(m, "FEC_Sink_Support: %s\n", str_yes_no(is_fec_supported));
1217 seq_printf(m, "DSC_Sink_Support: %s\n", str_yes_no(is_dsc_supported));
1222 /* function: Trigger virtual HPD redetection on connector
1224 * This function will perform link rediscovery, link disable
1225 * and enable, and dm connector state update.
1227 * Retrigger HPD on an existing connector by echoing 1 into
1228 * its respectful "trigger_hotplug" debugfs entry:
1230 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1232 * This function can perform HPD unplug:
1234 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1237 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1238 size_t size, loff_t *pos)
1240 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1241 struct drm_connector *connector = &aconnector->base;
1242 struct dc_link *link = NULL;
1243 struct drm_device *dev = connector->dev;
1244 enum dc_connection_type new_connection_type = dc_connection_none;
1245 char *wr_buf = NULL;
1246 uint32_t wr_buf_size = 42;
1247 int max_param_num = 1;
1248 long param[1] = {0};
1249 uint8_t param_nums = 0;
1251 if (!aconnector || !aconnector->dc_link)
1257 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1260 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1264 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1272 if (param_nums <= 0) {
1273 DRM_DEBUG_DRIVER("user data not be read\n");
1278 if (param[0] == 1) {
1279 mutex_lock(&aconnector->hpd_lock);
1281 if (!dc_link_detect_sink(aconnector->dc_link, &new_connection_type) &&
1282 new_connection_type != dc_connection_none)
1285 if (!dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD))
1288 amdgpu_dm_update_connector_after_detect(aconnector);
1290 drm_modeset_lock_all(dev);
1291 dm_restore_drm_connector_state(dev, connector);
1292 drm_modeset_unlock_all(dev);
1294 drm_kms_helper_connector_hotplug_event(connector);
1295 } else if (param[0] == 0) {
1296 if (!aconnector->dc_link)
1299 link = aconnector->dc_link;
1301 if (link->local_sink) {
1302 dc_sink_release(link->local_sink);
1303 link->local_sink = NULL;
1306 link->dpcd_sink_count = 0;
1307 link->type = dc_connection_none;
1308 link->dongle_max_pix_clk = 0;
1310 amdgpu_dm_update_connector_after_detect(aconnector);
1312 drm_modeset_lock_all(dev);
1313 dm_restore_drm_connector_state(dev, connector);
1314 drm_modeset_unlock_all(dev);
1316 drm_kms_helper_connector_hotplug_event(connector);
1320 mutex_unlock(&aconnector->hpd_lock);
1326 /* function: read DSC status on the connector
1328 * The read function: dp_dsc_clock_en_read
1329 * returns current status of DSC clock on the connector.
1330 * The return is a boolean flag: 1 or 0.
1332 * Access it with the following command (you need to specify
1333 * connector like DP-1):
1335 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1338 * 1 - means that DSC is currently enabled
1339 * 0 - means that DSC is disabled
1341 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1342 size_t size, loff_t *pos)
1344 char *rd_buf = NULL;
1345 char *rd_buf_ptr = NULL;
1346 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1347 struct display_stream_compressor *dsc;
1348 struct dcn_dsc_state dsc_state = {0};
1349 const uint32_t rd_buf_size = 10;
1350 struct pipe_ctx *pipe_ctx;
1352 int i, r, str_len = 30;
1354 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1359 rd_buf_ptr = rd_buf;
1361 for (i = 0; i < MAX_PIPES; i++) {
1362 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1363 if (pipe_ctx && pipe_ctx->stream &&
1364 pipe_ctx->stream->link == aconnector->dc_link)
1373 dsc = pipe_ctx->stream_res.dsc;
1375 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1377 snprintf(rd_buf_ptr, str_len,
1379 dsc_state.dsc_clock_en);
1380 rd_buf_ptr += str_len;
1383 if (*pos >= rd_buf_size)
1386 r = put_user(*(rd_buf + result), buf);
1389 return r; /* r = -EFAULT */
1402 /* function: write force DSC on the connector
1404 * The write function: dp_dsc_clock_en_write
1405 * enables to force DSC on the connector.
1406 * User can write to either force enable or force disable DSC
1407 * on the next modeset or set it to driver default
1410 * 0 - default DSC enablement policy
1411 * 1 - force enable DSC on the connector
1412 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1414 * Writing DSC settings is done with the following command:
1415 * - To force enable DSC (you need to specify
1416 * connector like DP-1):
1418 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1420 * - To return to default state set the flag to zero and
1421 * let driver deal with DSC automatically
1422 * (you need to specify connector like DP-1):
1424 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1427 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1428 size_t size, loff_t *pos)
1430 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1431 struct drm_connector *connector = &aconnector->base;
1432 struct drm_device *dev = connector->dev;
1433 struct drm_crtc *crtc = NULL;
1434 struct dm_crtc_state *dm_crtc_state = NULL;
1435 struct pipe_ctx *pipe_ctx;
1437 char *wr_buf = NULL;
1438 uint32_t wr_buf_size = 42;
1439 int max_param_num = 1;
1440 long param[1] = {0};
1441 uint8_t param_nums = 0;
1446 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1449 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1453 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1461 if (param_nums <= 0) {
1462 DRM_DEBUG_DRIVER("user data not be read\n");
1467 for (i = 0; i < MAX_PIPES; i++) {
1468 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1469 if (pipe_ctx && pipe_ctx->stream &&
1470 pipe_ctx->stream->link == aconnector->dc_link)
1474 if (!pipe_ctx || !pipe_ctx->stream)
1478 mutex_lock(&dev->mode_config.mutex);
1479 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1481 if (connector->state == NULL)
1484 crtc = connector->state->crtc;
1488 drm_modeset_lock(&crtc->mutex, NULL);
1489 if (crtc->state == NULL)
1492 dm_crtc_state = to_dm_crtc_state(crtc->state);
1493 if (dm_crtc_state->stream == NULL)
1497 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1498 else if (param[0] == 2)
1499 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1501 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1503 dm_crtc_state->dsc_force_changed = true;
1507 drm_modeset_unlock(&crtc->mutex);
1508 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1509 mutex_unlock(&dev->mode_config.mutex);
1516 /* function: read DSC slice width parameter on the connector
1518 * The read function: dp_dsc_slice_width_read
1519 * returns dsc slice width used in the current configuration
1520 * The return is an integer: 0 or other positive number
1522 * Access the status with the following command:
1524 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1526 * 0 - means that DSC is disabled
1528 * Any other number more than zero represents the
1529 * slice width currently used by DSC in pixels
1532 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1533 size_t size, loff_t *pos)
1535 char *rd_buf = NULL;
1536 char *rd_buf_ptr = NULL;
1537 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1538 struct display_stream_compressor *dsc;
1539 struct dcn_dsc_state dsc_state = {0};
1540 const uint32_t rd_buf_size = 100;
1541 struct pipe_ctx *pipe_ctx;
1543 int i, r, str_len = 30;
1545 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1550 rd_buf_ptr = rd_buf;
1552 for (i = 0; i < MAX_PIPES; i++) {
1553 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1554 if (pipe_ctx && pipe_ctx->stream &&
1555 pipe_ctx->stream->link == aconnector->dc_link)
1564 dsc = pipe_ctx->stream_res.dsc;
1566 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1568 snprintf(rd_buf_ptr, str_len,
1570 dsc_state.dsc_slice_width);
1571 rd_buf_ptr += str_len;
1574 if (*pos >= rd_buf_size)
1577 r = put_user(*(rd_buf + result), buf);
1580 return r; /* r = -EFAULT */
1593 /* function: write DSC slice width parameter
1595 * The write function: dp_dsc_slice_width_write
1596 * overwrites automatically generated DSC configuration
1599 * The user has to write the slice width divisible by the
1602 * Also the user has to write width in hexidecimal
1603 * rather than in decimal.
1605 * Writing DSC settings is done with the following command:
1606 * - To force overwrite slice width: (example sets to 1920 pixels)
1608 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1610 * - To stop overwriting and let driver find the optimal size,
1611 * set the width to zero:
1613 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1616 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1617 size_t size, loff_t *pos)
1619 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1620 struct pipe_ctx *pipe_ctx;
1621 struct drm_connector *connector = &aconnector->base;
1622 struct drm_device *dev = connector->dev;
1623 struct drm_crtc *crtc = NULL;
1624 struct dm_crtc_state *dm_crtc_state = NULL;
1626 char *wr_buf = NULL;
1627 uint32_t wr_buf_size = 42;
1628 int max_param_num = 1;
1629 long param[1] = {0};
1630 uint8_t param_nums = 0;
1635 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1638 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1642 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1650 if (param_nums <= 0) {
1651 DRM_DEBUG_DRIVER("user data not be read\n");
1656 for (i = 0; i < MAX_PIPES; i++) {
1657 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1658 if (pipe_ctx && pipe_ctx->stream &&
1659 pipe_ctx->stream->link == aconnector->dc_link)
1663 if (!pipe_ctx || !pipe_ctx->stream)
1666 // Safely get CRTC state
1667 mutex_lock(&dev->mode_config.mutex);
1668 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1670 if (connector->state == NULL)
1673 crtc = connector->state->crtc;
1677 drm_modeset_lock(&crtc->mutex, NULL);
1678 if (crtc->state == NULL)
1681 dm_crtc_state = to_dm_crtc_state(crtc->state);
1682 if (dm_crtc_state->stream == NULL)
1686 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1687 pipe_ctx->stream->timing.h_addressable,
1690 aconnector->dsc_settings.dsc_num_slices_h = 0;
1692 dm_crtc_state->dsc_force_changed = true;
1696 drm_modeset_unlock(&crtc->mutex);
1697 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1698 mutex_unlock(&dev->mode_config.mutex);
1705 /* function: read DSC slice height parameter on the connector
1707 * The read function: dp_dsc_slice_height_read
1708 * returns dsc slice height used in the current configuration
1709 * The return is an integer: 0 or other positive number
1711 * Access the status with the following command:
1713 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1715 * 0 - means that DSC is disabled
1717 * Any other number more than zero represents the
1718 * slice height currently used by DSC in pixels
1721 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1722 size_t size, loff_t *pos)
1724 char *rd_buf = NULL;
1725 char *rd_buf_ptr = NULL;
1726 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1727 struct display_stream_compressor *dsc;
1728 struct dcn_dsc_state dsc_state = {0};
1729 const uint32_t rd_buf_size = 100;
1730 struct pipe_ctx *pipe_ctx;
1732 int i, r, str_len = 30;
1734 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1739 rd_buf_ptr = rd_buf;
1741 for (i = 0; i < MAX_PIPES; i++) {
1742 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1743 if (pipe_ctx && pipe_ctx->stream &&
1744 pipe_ctx->stream->link == aconnector->dc_link)
1753 dsc = pipe_ctx->stream_res.dsc;
1755 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1757 snprintf(rd_buf_ptr, str_len,
1759 dsc_state.dsc_slice_height);
1760 rd_buf_ptr += str_len;
1763 if (*pos >= rd_buf_size)
1766 r = put_user(*(rd_buf + result), buf);
1769 return r; /* r = -EFAULT */
1782 /* function: write DSC slice height parameter
1784 * The write function: dp_dsc_slice_height_write
1785 * overwrites automatically generated DSC configuration
1788 * The user has to write the slice height divisible by the
1791 * Also the user has to write height in hexidecimal
1792 * rather than in decimal.
1794 * Writing DSC settings is done with the following command:
1795 * - To force overwrite slice height (example sets to 128 pixels):
1797 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1799 * - To stop overwriting and let driver find the optimal size,
1800 * set the height to zero:
1802 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1805 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1806 size_t size, loff_t *pos)
1808 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1809 struct drm_connector *connector = &aconnector->base;
1810 struct drm_device *dev = connector->dev;
1811 struct drm_crtc *crtc = NULL;
1812 struct dm_crtc_state *dm_crtc_state = NULL;
1813 struct pipe_ctx *pipe_ctx;
1815 char *wr_buf = NULL;
1816 uint32_t wr_buf_size = 42;
1817 int max_param_num = 1;
1818 uint8_t param_nums = 0;
1819 long param[1] = {0};
1824 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1827 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1831 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1839 if (param_nums <= 0) {
1840 DRM_DEBUG_DRIVER("user data not be read\n");
1845 for (i = 0; i < MAX_PIPES; i++) {
1846 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1847 if (pipe_ctx && pipe_ctx->stream &&
1848 pipe_ctx->stream->link == aconnector->dc_link)
1852 if (!pipe_ctx || !pipe_ctx->stream)
1856 mutex_lock(&dev->mode_config.mutex);
1857 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1859 if (connector->state == NULL)
1862 crtc = connector->state->crtc;
1866 drm_modeset_lock(&crtc->mutex, NULL);
1867 if (crtc->state == NULL)
1870 dm_crtc_state = to_dm_crtc_state(crtc->state);
1871 if (dm_crtc_state->stream == NULL)
1875 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1876 pipe_ctx->stream->timing.v_addressable,
1879 aconnector->dsc_settings.dsc_num_slices_v = 0;
1881 dm_crtc_state->dsc_force_changed = true;
1885 drm_modeset_unlock(&crtc->mutex);
1886 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1887 mutex_unlock(&dev->mode_config.mutex);
1894 /* function: read DSC target rate on the connector in bits per pixel
1896 * The read function: dp_dsc_bits_per_pixel_read
1897 * returns target rate of compression in bits per pixel
1898 * The return is an integer: 0 or other positive integer
1900 * Access it with the following command:
1902 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1904 * 0 - means that DSC is disabled
1906 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
1907 size_t size, loff_t *pos)
1909 char *rd_buf = NULL;
1910 char *rd_buf_ptr = NULL;
1911 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1912 struct display_stream_compressor *dsc;
1913 struct dcn_dsc_state dsc_state = {0};
1914 const uint32_t rd_buf_size = 100;
1915 struct pipe_ctx *pipe_ctx;
1917 int i, r, str_len = 30;
1919 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1924 rd_buf_ptr = rd_buf;
1926 for (i = 0; i < MAX_PIPES; i++) {
1927 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1928 if (pipe_ctx && pipe_ctx->stream &&
1929 pipe_ctx->stream->link == aconnector->dc_link)
1938 dsc = pipe_ctx->stream_res.dsc;
1940 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1942 snprintf(rd_buf_ptr, str_len,
1944 dsc_state.dsc_bits_per_pixel);
1945 rd_buf_ptr += str_len;
1948 if (*pos >= rd_buf_size)
1951 r = put_user(*(rd_buf + result), buf);
1954 return r; /* r = -EFAULT */
1967 /* function: write DSC target rate in bits per pixel
1969 * The write function: dp_dsc_bits_per_pixel_write
1970 * overwrites automatically generated DSC configuration
1971 * of DSC target bit rate.
1973 * Also the user has to write bpp in hexidecimal
1974 * rather than in decimal.
1976 * Writing DSC settings is done with the following command:
1977 * - To force overwrite rate (example sets to 256 bpp x 1/16):
1979 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1981 * - To stop overwriting and let driver find the optimal rate,
1982 * set the rate to zero:
1984 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1987 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
1988 size_t size, loff_t *pos)
1990 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1991 struct drm_connector *connector = &aconnector->base;
1992 struct drm_device *dev = connector->dev;
1993 struct drm_crtc *crtc = NULL;
1994 struct dm_crtc_state *dm_crtc_state = NULL;
1995 struct pipe_ctx *pipe_ctx;
1997 char *wr_buf = NULL;
1998 uint32_t wr_buf_size = 42;
1999 int max_param_num = 1;
2000 uint8_t param_nums = 0;
2001 long param[1] = {0};
2006 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2009 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2013 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2021 if (param_nums <= 0) {
2022 DRM_DEBUG_DRIVER("user data not be read\n");
2027 for (i = 0; i < MAX_PIPES; i++) {
2028 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2029 if (pipe_ctx && pipe_ctx->stream &&
2030 pipe_ctx->stream->link == aconnector->dc_link)
2034 if (!pipe_ctx || !pipe_ctx->stream)
2038 mutex_lock(&dev->mode_config.mutex);
2039 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2041 if (connector->state == NULL)
2044 crtc = connector->state->crtc;
2048 drm_modeset_lock(&crtc->mutex, NULL);
2049 if (crtc->state == NULL)
2052 dm_crtc_state = to_dm_crtc_state(crtc->state);
2053 if (dm_crtc_state->stream == NULL)
2056 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
2058 dm_crtc_state->dsc_force_changed = true;
2062 drm_modeset_unlock(&crtc->mutex);
2063 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2064 mutex_unlock(&dev->mode_config.mutex);
2071 /* function: read DSC picture width parameter on the connector
2073 * The read function: dp_dsc_pic_width_read
2074 * returns dsc picture width used in the current configuration
2075 * It is the same as h_addressable of the current
2077 * The return is an integer: 0 or other positive integer
2078 * If 0 then DSC is disabled.
2080 * Access it with the following command:
2082 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
2084 * 0 - means that DSC is disabled
2086 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
2087 size_t size, loff_t *pos)
2089 char *rd_buf = NULL;
2090 char *rd_buf_ptr = NULL;
2091 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2092 struct display_stream_compressor *dsc;
2093 struct dcn_dsc_state dsc_state = {0};
2094 const uint32_t rd_buf_size = 100;
2095 struct pipe_ctx *pipe_ctx;
2097 int i, r, str_len = 30;
2099 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2104 rd_buf_ptr = rd_buf;
2106 for (i = 0; i < MAX_PIPES; i++) {
2107 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2108 if (pipe_ctx && pipe_ctx->stream &&
2109 pipe_ctx->stream->link == aconnector->dc_link)
2118 dsc = pipe_ctx->stream_res.dsc;
2120 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2122 snprintf(rd_buf_ptr, str_len,
2124 dsc_state.dsc_pic_width);
2125 rd_buf_ptr += str_len;
2128 if (*pos >= rd_buf_size)
2131 r = put_user(*(rd_buf + result), buf);
2134 return r; /* r = -EFAULT */
2147 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
2148 size_t size, loff_t *pos)
2150 char *rd_buf = NULL;
2151 char *rd_buf_ptr = NULL;
2152 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2153 struct display_stream_compressor *dsc;
2154 struct dcn_dsc_state dsc_state = {0};
2155 const uint32_t rd_buf_size = 100;
2156 struct pipe_ctx *pipe_ctx;
2158 int i, r, str_len = 30;
2160 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2165 rd_buf_ptr = rd_buf;
2167 for (i = 0; i < MAX_PIPES; i++) {
2168 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2169 if (pipe_ctx && pipe_ctx->stream &&
2170 pipe_ctx->stream->link == aconnector->dc_link)
2179 dsc = pipe_ctx->stream_res.dsc;
2181 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2183 snprintf(rd_buf_ptr, str_len,
2185 dsc_state.dsc_pic_height);
2186 rd_buf_ptr += str_len;
2189 if (*pos >= rd_buf_size)
2192 r = put_user(*(rd_buf + result), buf);
2195 return r; /* r = -EFAULT */
2208 /* function: read DSC chunk size parameter on the connector
2210 * The read function: dp_dsc_chunk_size_read
2211 * returns dsc chunk size set in the current configuration
2212 * The value is calculated automatically by DSC code
2213 * and depends on slice parameters and bpp target rate
2214 * The return is an integer: 0 or other positive integer
2215 * If 0 then DSC is disabled.
2217 * Access it with the following command:
2219 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2221 * 0 - means that DSC is disabled
2223 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2224 size_t size, loff_t *pos)
2226 char *rd_buf = NULL;
2227 char *rd_buf_ptr = NULL;
2228 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2229 struct display_stream_compressor *dsc;
2230 struct dcn_dsc_state dsc_state = {0};
2231 const uint32_t rd_buf_size = 100;
2232 struct pipe_ctx *pipe_ctx;
2234 int i, r, str_len = 30;
2236 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2241 rd_buf_ptr = rd_buf;
2243 for (i = 0; i < MAX_PIPES; i++) {
2244 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2245 if (pipe_ctx && pipe_ctx->stream &&
2246 pipe_ctx->stream->link == aconnector->dc_link)
2255 dsc = pipe_ctx->stream_res.dsc;
2257 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2259 snprintf(rd_buf_ptr, str_len,
2261 dsc_state.dsc_chunk_size);
2262 rd_buf_ptr += str_len;
2265 if (*pos >= rd_buf_size)
2268 r = put_user(*(rd_buf + result), buf);
2271 return r; /* r = -EFAULT */
2284 /* function: read DSC slice bpg offset on the connector
2286 * The read function: dp_dsc_slice_bpg_offset_read
2287 * returns dsc bpg slice offset set in the current configuration
2288 * The value is calculated automatically by DSC code
2289 * and depends on slice parameters and bpp target rate
2290 * The return is an integer: 0 or other positive integer
2291 * If 0 then DSC is disabled.
2293 * Access it with the following command:
2295 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2297 * 0 - means that DSC is disabled
2299 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2300 size_t size, loff_t *pos)
2302 char *rd_buf = NULL;
2303 char *rd_buf_ptr = NULL;
2304 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2305 struct display_stream_compressor *dsc;
2306 struct dcn_dsc_state dsc_state = {0};
2307 const uint32_t rd_buf_size = 100;
2308 struct pipe_ctx *pipe_ctx;
2310 int i, r, str_len = 30;
2312 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2317 rd_buf_ptr = rd_buf;
2319 for (i = 0; i < MAX_PIPES; i++) {
2320 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2321 if (pipe_ctx && pipe_ctx->stream &&
2322 pipe_ctx->stream->link == aconnector->dc_link)
2331 dsc = pipe_ctx->stream_res.dsc;
2333 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2335 snprintf(rd_buf_ptr, str_len,
2337 dsc_state.dsc_slice_bpg_offset);
2338 rd_buf_ptr += str_len;
2341 if (*pos >= rd_buf_size)
2344 r = put_user(*(rd_buf + result), buf);
2347 return r; /* r = -EFAULT */
2362 * function description: Read max_requested_bpc property from the connector
2364 * Access it with the following command:
2366 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2369 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2370 size_t size, loff_t *pos)
2372 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2373 struct drm_connector *connector = &aconnector->base;
2374 struct drm_device *dev = connector->dev;
2375 struct dm_connector_state *state;
2377 char *rd_buf = NULL;
2378 char *rd_buf_ptr = NULL;
2379 const uint32_t rd_buf_size = 10;
2382 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2387 mutex_lock(&dev->mode_config.mutex);
2388 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2390 if (connector->state == NULL)
2393 state = to_dm_connector_state(connector->state);
2395 rd_buf_ptr = rd_buf;
2396 snprintf(rd_buf_ptr, rd_buf_size,
2398 state->base.max_requested_bpc);
2401 if (*pos >= rd_buf_size)
2404 r = put_user(*(rd_buf + result), buf);
2406 result = r; /* r = -EFAULT */
2415 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2416 mutex_unlock(&dev->mode_config.mutex);
2423 * function description: Set max_requested_bpc property on the connector
2425 * This function will not force the input BPC on connector, it will only
2426 * change the max value. This is equivalent to setting max_bpc through
2429 * The BPC value written must be >= 6 and <= 16. Values outside of this
2430 * range will result in errors.
2439 * Write the max_bpc in the following way:
2441 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2444 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2445 size_t size, loff_t *pos)
2447 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2448 struct drm_connector *connector = &aconnector->base;
2449 struct dm_connector_state *state;
2450 struct drm_device *dev = connector->dev;
2451 char *wr_buf = NULL;
2452 uint32_t wr_buf_size = 42;
2453 int max_param_num = 1;
2454 long param[1] = {0};
2455 uint8_t param_nums = 0;
2460 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2463 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2467 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2475 if (param_nums <= 0) {
2476 DRM_DEBUG_DRIVER("user data not be read\n");
2481 if (param[0] < 6 || param[0] > 16) {
2482 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2487 mutex_lock(&dev->mode_config.mutex);
2488 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2490 if (connector->state == NULL)
2493 state = to_dm_connector_state(connector->state);
2494 state->base.max_requested_bpc = param[0];
2496 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2497 mutex_unlock(&dev->mode_config.mutex);
2504 * Backlight at this moment. Read only.
2505 * As written to display, taking ABM and backlight lut into account.
2506 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2508 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/current_backlight
2510 static int current_backlight_show(struct seq_file *m, void *unused)
2512 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2513 struct dc_link *link = aconnector->dc_link;
2514 unsigned int backlight;
2516 backlight = dc_link_get_backlight_level(link);
2517 seq_printf(m, "0x%x\n", backlight);
2523 * Backlight value that is being approached. Read only.
2524 * As written to display, taking ABM and backlight lut into account.
2525 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2527 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/target_backlight
2529 static int target_backlight_show(struct seq_file *m, void *unused)
2531 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2532 struct dc_link *link = aconnector->dc_link;
2533 unsigned int backlight;
2535 backlight = dc_link_get_target_backlight_pwm(link);
2536 seq_printf(m, "0x%x\n", backlight);
2541 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2542 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2543 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2544 DEFINE_SHOW_ATTRIBUTE(output_bpc);
2545 DEFINE_SHOW_ATTRIBUTE(dp_lttpr_status);
2546 #ifdef CONFIG_DRM_AMD_DC_HDCP
2547 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2549 DEFINE_SHOW_ATTRIBUTE(internal_display);
2550 DEFINE_SHOW_ATTRIBUTE(psr_capability);
2552 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2553 .owner = THIS_MODULE,
2554 .read = dp_dsc_clock_en_read,
2555 .write = dp_dsc_clock_en_write,
2556 .llseek = default_llseek
2559 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2560 .owner = THIS_MODULE,
2561 .read = dp_dsc_slice_width_read,
2562 .write = dp_dsc_slice_width_write,
2563 .llseek = default_llseek
2566 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2567 .owner = THIS_MODULE,
2568 .read = dp_dsc_slice_height_read,
2569 .write = dp_dsc_slice_height_write,
2570 .llseek = default_llseek
2573 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2574 .owner = THIS_MODULE,
2575 .read = dp_dsc_bits_per_pixel_read,
2576 .write = dp_dsc_bits_per_pixel_write,
2577 .llseek = default_llseek
2580 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2581 .owner = THIS_MODULE,
2582 .read = dp_dsc_pic_width_read,
2583 .llseek = default_llseek
2586 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2587 .owner = THIS_MODULE,
2588 .read = dp_dsc_pic_height_read,
2589 .llseek = default_llseek
2592 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2593 .owner = THIS_MODULE,
2594 .read = dp_dsc_chunk_size_read,
2595 .llseek = default_llseek
2598 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2599 .owner = THIS_MODULE,
2600 .read = dp_dsc_slice_bpg_offset_read,
2601 .llseek = default_llseek
2604 static const struct file_operations trigger_hotplug_debugfs_fops = {
2605 .owner = THIS_MODULE,
2606 .write = trigger_hotplug,
2607 .llseek = default_llseek
2610 static const struct file_operations dp_link_settings_debugfs_fops = {
2611 .owner = THIS_MODULE,
2612 .read = dp_link_settings_read,
2613 .write = dp_link_settings_write,
2614 .llseek = default_llseek
2617 static const struct file_operations dp_phy_settings_debugfs_fop = {
2618 .owner = THIS_MODULE,
2619 .read = dp_phy_settings_read,
2620 .write = dp_phy_settings_write,
2621 .llseek = default_llseek
2624 static const struct file_operations dp_phy_test_pattern_fops = {
2625 .owner = THIS_MODULE,
2626 .write = dp_phy_test_pattern_debugfs_write,
2627 .llseek = default_llseek
2630 static const struct file_operations sdp_message_fops = {
2631 .owner = THIS_MODULE,
2632 .write = dp_sdp_message_debugfs_write,
2633 .llseek = default_llseek
2636 static const struct file_operations dp_dpcd_address_debugfs_fops = {
2637 .owner = THIS_MODULE,
2638 .write = dp_dpcd_address_write,
2639 .llseek = default_llseek
2642 static const struct file_operations dp_dpcd_size_debugfs_fops = {
2643 .owner = THIS_MODULE,
2644 .write = dp_dpcd_size_write,
2645 .llseek = default_llseek
2648 static const struct file_operations dp_dpcd_data_debugfs_fops = {
2649 .owner = THIS_MODULE,
2650 .read = dp_dpcd_data_read,
2651 .write = dp_dpcd_data_write,
2652 .llseek = default_llseek
2655 static const struct file_operations dp_max_bpc_debugfs_fops = {
2656 .owner = THIS_MODULE,
2657 .read = dp_max_bpc_read,
2658 .write = dp_max_bpc_write,
2659 .llseek = default_llseek
2662 static const struct file_operations dp_dsc_disable_passthrough_debugfs_fops = {
2663 .owner = THIS_MODULE,
2664 .write = dp_dsc_passthrough_set,
2665 .llseek = default_llseek
2668 static const struct {
2670 const struct file_operations *fops;
2671 } dp_debugfs_entries[] = {
2672 {"link_settings", &dp_link_settings_debugfs_fops},
2673 {"phy_settings", &dp_phy_settings_debugfs_fop},
2674 {"lttpr_status", &dp_lttpr_status_fops},
2675 {"test_pattern", &dp_phy_test_pattern_fops},
2676 #ifdef CONFIG_DRM_AMD_DC_HDCP
2677 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2679 {"sdp_message", &sdp_message_fops},
2680 {"aux_dpcd_address", &dp_dpcd_address_debugfs_fops},
2681 {"aux_dpcd_size", &dp_dpcd_size_debugfs_fops},
2682 {"aux_dpcd_data", &dp_dpcd_data_debugfs_fops},
2683 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2684 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2685 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2686 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2687 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2688 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2689 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2690 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2691 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
2692 {"max_bpc", &dp_max_bpc_debugfs_fops},
2693 {"dsc_disable_passthrough", &dp_dsc_disable_passthrough_debugfs_fops},
2696 #ifdef CONFIG_DRM_AMD_DC_HDCP
2697 static const struct {
2699 const struct file_operations *fops;
2700 } hdmi_debugfs_entries[] = {
2701 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
2705 * Force YUV420 output if available from the given mode
2707 static int force_yuv420_output_set(void *data, u64 val)
2709 struct amdgpu_dm_connector *connector = data;
2711 connector->force_yuv420_output = (bool)val;
2717 * Check if YUV420 is forced when available from the given mode
2719 static int force_yuv420_output_get(void *data, u64 *val)
2721 struct amdgpu_dm_connector *connector = data;
2723 *val = connector->force_yuv420_output;
2728 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2729 force_yuv420_output_set, "%llu\n");
2734 static int psr_get(void *data, u64 *val)
2736 struct amdgpu_dm_connector *connector = data;
2737 struct dc_link *link = connector->dc_link;
2738 enum dc_psr_state state = PSR_STATE0;
2740 dc_link_get_psr_state(link, &state);
2748 * Set dmcub trace event IRQ enable or disable.
2749 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2750 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2752 static int dmcub_trace_event_state_set(void *data, u64 val)
2754 struct amdgpu_device *adev = data;
2756 if (val == 1 || val == 0) {
2757 dc_dmub_trace_event_control(adev->dm.dc, val);
2758 adev->dm.dmcub_trace_event_en = (bool)val;
2766 * The interface doesn't need get function, so it will return the
2768 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2770 static int dmcub_trace_event_state_get(void *data, u64 *val)
2772 struct amdgpu_device *adev = data;
2774 *val = adev->dm.dmcub_trace_event_en;
2778 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
2779 dmcub_trace_event_state_set, "%llu\n");
2781 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
2783 DEFINE_SHOW_ATTRIBUTE(current_backlight);
2784 DEFINE_SHOW_ATTRIBUTE(target_backlight);
2786 static const struct {
2788 const struct file_operations *fops;
2789 } connector_debugfs_entries[] = {
2790 {"force_yuv420_output", &force_yuv420_output_fops},
2791 {"output_bpc", &output_bpc_fops},
2792 {"trigger_hotplug", &trigger_hotplug_debugfs_fops},
2793 {"internal_display", &internal_display_fops}
2797 * Returns supported customized link rates by this eDP panel.
2798 * Example usage: cat /sys/kernel/debug/dri/0/eDP-x/ilr_setting
2800 static int edp_ilr_show(struct seq_file *m, void *unused)
2802 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2803 struct dc_link *link = aconnector->dc_link;
2804 uint8_t supported_link_rates[16];
2805 uint32_t link_rate_in_khz;
2809 memset(supported_link_rates, 0, sizeof(supported_link_rates));
2810 dm_helpers_dp_read_dpcd(link->ctx, link, DP_SUPPORTED_LINK_RATES,
2811 supported_link_rates, sizeof(supported_link_rates));
2813 dpcd_rev = link->dpcd_caps.dpcd_rev.raw;
2815 if (dpcd_rev >= DP_DPCD_REV_13 &&
2816 (supported_link_rates[entry+1] != 0 || supported_link_rates[entry] != 0)) {
2818 for (entry = 0; entry < 16; entry += 2) {
2819 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
2820 supported_link_rates[entry]) * 200;
2821 seq_printf(m, "[%d] %d kHz\n", entry/2, link_rate_in_khz);
2824 seq_printf(m, "ILR is not supported by this eDP panel.\n");
2831 * Set supported customized link rate to eDP panel.
2833 * echo <lane_count> <link_rate option> > ilr_setting
2835 * for example, supported ILR : [0] 1620000 kHz [1] 2160000 kHz [2] 2430000 kHz ...
2836 * echo 4 1 > /sys/kernel/debug/dri/0/eDP-x/ilr_setting
2837 * to set 4 lanes and 2.16 GHz
2839 static ssize_t edp_ilr_write(struct file *f, const char __user *buf,
2840 size_t size, loff_t *pos)
2842 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
2843 struct dc_link *link = connector->dc_link;
2844 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
2845 struct dc *dc = (struct dc *)link->dc;
2846 struct dc_link_settings prefer_link_settings;
2847 char *wr_buf = NULL;
2848 const uint32_t wr_buf_size = 40;
2849 /* 0: lane_count; 1: link_rate */
2850 int max_param_num = 2;
2851 uint8_t param_nums = 0;
2853 bool valid_input = true;
2858 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2862 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2870 if (param_nums <= 0) {
2876 case LANE_COUNT_ONE:
2877 case LANE_COUNT_TWO:
2878 case LANE_COUNT_FOUR:
2881 valid_input = false;
2885 if (param[1] >= link->dpcd_caps.edp_supported_link_rates_count)
2886 valid_input = false;
2890 DRM_DEBUG_DRIVER("Invalid Input value. No HW will be programmed\n");
2891 prefer_link_settings.use_link_rate_set = false;
2892 mutex_lock(&adev->dm.dc_lock);
2893 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
2894 mutex_unlock(&adev->dm.dc_lock);
2898 /* save user force lane_count, link_rate to preferred settings
2899 * spread spectrum will not be changed
2901 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
2902 prefer_link_settings.lane_count = param[0];
2903 prefer_link_settings.use_link_rate_set = true;
2904 prefer_link_settings.link_rate_set = param[1];
2905 prefer_link_settings.link_rate = link->dpcd_caps.edp_supported_link_rates[param[1]];
2907 mutex_lock(&adev->dm.dc_lock);
2908 dc_link_set_preferred_training_settings(dc, &prefer_link_settings,
2910 mutex_unlock(&adev->dm.dc_lock);
2916 static int edp_ilr_open(struct inode *inode, struct file *file)
2918 return single_open(file, edp_ilr_show, inode->i_private);
2921 static const struct file_operations edp_ilr_debugfs_fops = {
2922 .owner = THIS_MODULE,
2923 .open = edp_ilr_open,
2925 .llseek = seq_lseek,
2926 .release = single_release,
2927 .write = edp_ilr_write
2930 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
2933 struct dentry *dir = connector->base.debugfs_entry;
2935 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
2936 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2937 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
2938 debugfs_create_file(dp_debugfs_entries[i].name,
2939 0644, dir, connector,
2940 dp_debugfs_entries[i].fops);
2943 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2944 debugfs_create_file_unsafe("psr_capability", 0444, dir, connector, &psr_capability_fops);
2945 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
2946 debugfs_create_file("amdgpu_current_backlight_pwm", 0444, dir, connector,
2947 ¤t_backlight_fops);
2948 debugfs_create_file("amdgpu_target_backlight_pwm", 0444, dir, connector,
2949 &target_backlight_fops);
2950 debugfs_create_file("ilr_setting", 0644, dir, connector,
2951 &edp_ilr_debugfs_fops);
2954 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
2955 debugfs_create_file(connector_debugfs_entries[i].name,
2956 0644, dir, connector,
2957 connector_debugfs_entries[i].fops);
2960 connector->debugfs_dpcd_address = 0;
2961 connector->debugfs_dpcd_size = 0;
2963 #ifdef CONFIG_DRM_AMD_DC_HDCP
2964 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
2965 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
2966 debugfs_create_file(hdmi_debugfs_entries[i].name,
2967 0644, dir, connector,
2968 hdmi_debugfs_entries[i].fops);
2974 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
2976 * Set crc window coordinate x start
2978 static int crc_win_x_start_set(void *data, u64 val)
2980 struct drm_crtc *crtc = data;
2981 struct drm_device *drm_dev = crtc->dev;
2982 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2984 spin_lock_irq(&drm_dev->event_lock);
2985 acrtc->dm_irq_params.crc_window.x_start = (uint16_t) val;
2986 acrtc->dm_irq_params.crc_window.update_win = false;
2987 spin_unlock_irq(&drm_dev->event_lock);
2993 * Get crc window coordinate x start
2995 static int crc_win_x_start_get(void *data, u64 *val)
2997 struct drm_crtc *crtc = data;
2998 struct drm_device *drm_dev = crtc->dev;
2999 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3001 spin_lock_irq(&drm_dev->event_lock);
3002 *val = acrtc->dm_irq_params.crc_window.x_start;
3003 spin_unlock_irq(&drm_dev->event_lock);
3008 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
3009 crc_win_x_start_set, "%llu\n");
3013 * Set crc window coordinate y start
3015 static int crc_win_y_start_set(void *data, u64 val)
3017 struct drm_crtc *crtc = data;
3018 struct drm_device *drm_dev = crtc->dev;
3019 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3021 spin_lock_irq(&drm_dev->event_lock);
3022 acrtc->dm_irq_params.crc_window.y_start = (uint16_t) val;
3023 acrtc->dm_irq_params.crc_window.update_win = false;
3024 spin_unlock_irq(&drm_dev->event_lock);
3030 * Get crc window coordinate y start
3032 static int crc_win_y_start_get(void *data, u64 *val)
3034 struct drm_crtc *crtc = data;
3035 struct drm_device *drm_dev = crtc->dev;
3036 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3038 spin_lock_irq(&drm_dev->event_lock);
3039 *val = acrtc->dm_irq_params.crc_window.y_start;
3040 spin_unlock_irq(&drm_dev->event_lock);
3045 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
3046 crc_win_y_start_set, "%llu\n");
3049 * Set crc window coordinate x end
3051 static int crc_win_x_end_set(void *data, u64 val)
3053 struct drm_crtc *crtc = data;
3054 struct drm_device *drm_dev = crtc->dev;
3055 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3057 spin_lock_irq(&drm_dev->event_lock);
3058 acrtc->dm_irq_params.crc_window.x_end = (uint16_t) val;
3059 acrtc->dm_irq_params.crc_window.update_win = false;
3060 spin_unlock_irq(&drm_dev->event_lock);
3066 * Get crc window coordinate x end
3068 static int crc_win_x_end_get(void *data, u64 *val)
3070 struct drm_crtc *crtc = data;
3071 struct drm_device *drm_dev = crtc->dev;
3072 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3074 spin_lock_irq(&drm_dev->event_lock);
3075 *val = acrtc->dm_irq_params.crc_window.x_end;
3076 spin_unlock_irq(&drm_dev->event_lock);
3081 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
3082 crc_win_x_end_set, "%llu\n");
3085 * Set crc window coordinate y end
3087 static int crc_win_y_end_set(void *data, u64 val)
3089 struct drm_crtc *crtc = data;
3090 struct drm_device *drm_dev = crtc->dev;
3091 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3093 spin_lock_irq(&drm_dev->event_lock);
3094 acrtc->dm_irq_params.crc_window.y_end = (uint16_t) val;
3095 acrtc->dm_irq_params.crc_window.update_win = false;
3096 spin_unlock_irq(&drm_dev->event_lock);
3102 * Get crc window coordinate y end
3104 static int crc_win_y_end_get(void *data, u64 *val)
3106 struct drm_crtc *crtc = data;
3107 struct drm_device *drm_dev = crtc->dev;
3108 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3110 spin_lock_irq(&drm_dev->event_lock);
3111 *val = acrtc->dm_irq_params.crc_window.y_end;
3112 spin_unlock_irq(&drm_dev->event_lock);
3117 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
3118 crc_win_y_end_set, "%llu\n");
3120 * Trigger to commit crc window
3122 static int crc_win_update_set(void *data, u64 val)
3124 struct drm_crtc *new_crtc = data;
3125 struct drm_crtc *old_crtc = NULL;
3126 struct amdgpu_crtc *new_acrtc, *old_acrtc;
3127 struct amdgpu_device *adev = drm_to_adev(new_crtc->dev);
3128 struct crc_rd_work *crc_rd_wrk = adev->dm.crc_rd_wrk;
3134 spin_lock_irq(&adev_to_drm(adev)->event_lock);
3135 spin_lock_irq(&crc_rd_wrk->crc_rd_work_lock);
3136 if (crc_rd_wrk->crtc) {
3137 old_crtc = crc_rd_wrk->crtc;
3138 old_acrtc = to_amdgpu_crtc(old_crtc);
3140 new_acrtc = to_amdgpu_crtc(new_crtc);
3142 if (old_crtc && old_crtc != new_crtc) {
3143 old_acrtc->dm_irq_params.crc_window.activated = false;
3144 old_acrtc->dm_irq_params.crc_window.update_win = false;
3145 old_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3147 new_acrtc->dm_irq_params.crc_window.activated = true;
3148 new_acrtc->dm_irq_params.crc_window.update_win = true;
3149 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3150 crc_rd_wrk->crtc = new_crtc;
3152 new_acrtc->dm_irq_params.crc_window.activated = true;
3153 new_acrtc->dm_irq_params.crc_window.update_win = true;
3154 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
3155 crc_rd_wrk->crtc = new_crtc;
3157 spin_unlock_irq(&crc_rd_wrk->crc_rd_work_lock);
3158 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
3165 * Get crc window update flag
3167 static int crc_win_update_get(void *data, u64 *val)
3173 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
3174 crc_win_update_set, "%llu\n");
3176 void crtc_debugfs_init(struct drm_crtc *crtc)
3178 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
3183 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
3184 &crc_win_x_start_fops);
3185 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
3186 &crc_win_y_start_fops);
3187 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
3188 &crc_win_x_end_fops);
3189 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
3190 &crc_win_y_end_fops);
3191 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
3192 &crc_win_update_fops);
3197 * Writes DTN log state to the user supplied buffer.
3198 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3200 static ssize_t dtn_log_read(
3206 struct amdgpu_device *adev = file_inode(f)->i_private;
3207 struct dc *dc = adev->dm.dc;
3208 struct dc_log_buffer_ctx log_ctx = { 0 };
3214 if (!dc->hwss.log_hw_state)
3217 dc->hwss.log_hw_state(dc, &log_ctx);
3219 if (*pos < log_ctx.pos) {
3220 size_t to_copy = log_ctx.pos - *pos;
3222 to_copy = min(to_copy, size);
3224 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
3236 * Writes DTN log state to dmesg when triggered via a write.
3237 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3239 static ssize_t dtn_log_write(
3241 const char __user *buf,
3245 struct amdgpu_device *adev = file_inode(f)->i_private;
3246 struct dc *dc = adev->dm.dc;
3248 /* Write triggers log output via dmesg. */
3252 if (dc->hwss.log_hw_state)
3253 dc->hwss.log_hw_state(dc, NULL);
3258 static int mst_topo_show(struct seq_file *m, void *unused)
3260 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3261 struct drm_device *dev = adev_to_drm(adev);
3262 struct drm_connector *connector;
3263 struct drm_connector_list_iter conn_iter;
3264 struct amdgpu_dm_connector *aconnector;
3266 drm_connector_list_iter_begin(dev, &conn_iter);
3267 drm_for_each_connector_iter(connector, &conn_iter) {
3268 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3271 aconnector = to_amdgpu_dm_connector(connector);
3273 /* Ensure we're only dumping the topology of a root mst node */
3274 if (!aconnector->mst_mgr.mst_state)
3277 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
3278 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
3280 drm_connector_list_iter_end(&conn_iter);
3286 * Sets trigger hpd for MST topologies.
3287 * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
3288 * All topologies will be disconnected if val of 0 is set .
3289 * Usage to enable topologies: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3290 * Usage to disable topologies: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3292 static int trigger_hpd_mst_set(void *data, u64 val)
3294 struct amdgpu_device *adev = data;
3295 struct drm_device *dev = adev_to_drm(adev);
3296 struct drm_connector_list_iter iter;
3297 struct amdgpu_dm_connector *aconnector;
3298 struct drm_connector *connector;
3299 struct dc_link *link = NULL;
3302 drm_connector_list_iter_begin(dev, &iter);
3303 drm_for_each_connector_iter(connector, &iter) {
3304 aconnector = to_amdgpu_dm_connector(connector);
3305 if (aconnector->dc_link->type == dc_connection_mst_branch &&
3306 aconnector->mst_mgr.aux) {
3307 dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3308 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
3311 } else if (val == 0) {
3312 drm_connector_list_iter_begin(dev, &iter);
3313 drm_for_each_connector_iter(connector, &iter) {
3314 aconnector = to_amdgpu_dm_connector(connector);
3315 if (!aconnector->dc_link)
3318 if (!aconnector->mst_port)
3321 link = aconnector->dc_link;
3322 dp_receiver_power_ctrl(link, false);
3323 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_port->mst_mgr, false);
3324 link->mst_stream_alloc_table.stream_count = 0;
3325 memset(link->mst_stream_alloc_table.stream_allocations, 0,
3326 sizeof(link->mst_stream_alloc_table.stream_allocations));
3331 drm_kms_helper_hotplug_event(dev);
3337 * The interface doesn't need get function, so it will return the
3339 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3341 static int trigger_hpd_mst_get(void *data, u64 *val)
3347 DEFINE_DEBUGFS_ATTRIBUTE(trigger_hpd_mst_ops, trigger_hpd_mst_get,
3348 trigger_hpd_mst_set, "%llu\n");
3352 * Sets the force_timing_sync debug option from the given string.
3353 * All connected displays will be force synchronized immediately.
3354 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3356 static int force_timing_sync_set(void *data, u64 val)
3358 struct amdgpu_device *adev = data;
3360 adev->dm.force_timing_sync = (bool)val;
3362 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
3368 * Gets the force_timing_sync debug option value into the given buffer.
3369 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3371 static int force_timing_sync_get(void *data, u64 *val)
3373 struct amdgpu_device *adev = data;
3375 *val = adev->dm.force_timing_sync;
3380 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
3381 force_timing_sync_set, "%llu\n");
3385 * Disables all HPD and HPD RX interrupt handling in the
3386 * driver when set to 1. Default is 0.
3388 static int disable_hpd_set(void *data, u64 val)
3390 struct amdgpu_device *adev = data;
3392 adev->dm.disable_hpd_irq = (bool)val;
3399 * Returns 1 if HPD and HPRX interrupt handling is disabled,
3402 static int disable_hpd_get(void *data, u64 *val)
3404 struct amdgpu_device *adev = data;
3406 *val = adev->dm.disable_hpd_irq;
3411 DEFINE_DEBUGFS_ATTRIBUTE(disable_hpd_ops, disable_hpd_get,
3412 disable_hpd_set, "%llu\n");
3414 #if defined(CONFIG_DRM_AMD_DC_DCN)
3416 * Temporary w/a to force sst sequence in M42D DP2 mst receiver
3417 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_set_mst_en_for_sst
3419 static int dp_force_sst_set(void *data, u64 val)
3421 struct amdgpu_device *adev = data;
3423 adev->dm.dc->debug.set_mst_en_for_sst = val;
3428 static int dp_force_sst_get(void *data, u64 *val)
3430 struct amdgpu_device *adev = data;
3432 *val = adev->dm.dc->debug.set_mst_en_for_sst;
3436 DEFINE_DEBUGFS_ATTRIBUTE(dp_set_mst_en_for_sst_ops, dp_force_sst_get,
3437 dp_force_sst_set, "%llu\n");
3440 * Force DP2 sequence without VESA certified cable.
3441 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_ignore_cable_id
3443 static int dp_ignore_cable_id_set(void *data, u64 val)
3445 struct amdgpu_device *adev = data;
3447 adev->dm.dc->debug.ignore_cable_id = val;
3452 static int dp_ignore_cable_id_get(void *data, u64 *val)
3454 struct amdgpu_device *adev = data;
3456 *val = adev->dm.dc->debug.ignore_cable_id;
3460 DEFINE_DEBUGFS_ATTRIBUTE(dp_ignore_cable_id_ops, dp_ignore_cable_id_get,
3461 dp_ignore_cable_id_set, "%llu\n");
3465 * Sets the DC visual confirm debug option from the given string.
3466 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
3468 static int visual_confirm_set(void *data, u64 val)
3470 struct amdgpu_device *adev = data;
3472 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
3478 * Reads the DC visual confirm debug option value into the given buffer.
3479 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
3481 static int visual_confirm_get(void *data, u64 *val)
3483 struct amdgpu_device *adev = data;
3485 *val = adev->dm.dc->debug.visual_confirm;
3490 DEFINE_SHOW_ATTRIBUTE(mst_topo);
3491 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
3492 visual_confirm_set, "%llu\n");
3495 * Dumps the DCC_EN bit for each pipe.
3496 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dcc_en
3498 static ssize_t dcc_en_bits_read(
3504 struct amdgpu_device *adev = file_inode(f)->i_private;
3505 struct dc *dc = adev->dm.dc;
3506 char *rd_buf = NULL;
3507 const uint32_t rd_buf_size = 32;
3508 uint32_t result = 0;
3510 int num_pipes = dc->res_pool->pipe_count;
3514 dcc_en_bits = kcalloc(num_pipes, sizeof(int), GFP_KERNEL);
3518 if (!dc->hwss.get_dcc_en_bits) {
3523 dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
3525 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
3531 for (i = 0; i < num_pipes; i++)
3532 offset += snprintf(rd_buf + offset, rd_buf_size - offset,
3533 "%d ", dcc_en_bits[i]);
3534 rd_buf[strlen(rd_buf)] = '\n';
3539 if (*pos >= rd_buf_size)
3541 r = put_user(*(rd_buf + result), buf);
3544 return r; /* r = -EFAULT */
3556 void dtn_debugfs_init(struct amdgpu_device *adev)
3558 static const struct file_operations dtn_log_fops = {
3559 .owner = THIS_MODULE,
3560 .read = dtn_log_read,
3561 .write = dtn_log_write,
3562 .llseek = default_llseek
3564 static const struct file_operations dcc_en_bits_fops = {
3565 .owner = THIS_MODULE,
3566 .read = dcc_en_bits_read,
3567 .llseek = default_llseek
3570 struct drm_minor *minor = adev_to_drm(adev)->primary;
3571 struct dentry *root = minor->debugfs_root;
3573 debugfs_create_file("amdgpu_mst_topology", 0444, root,
3574 adev, &mst_topo_fops);
3575 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
3577 #if defined(CONFIG_DRM_AMD_DC_DCN)
3578 debugfs_create_file("amdgpu_dm_dp_set_mst_en_for_sst", 0644, root, adev,
3579 &dp_set_mst_en_for_sst_ops);
3580 debugfs_create_file("amdgpu_dm_dp_ignore_cable_id", 0644, root, adev,
3581 &dp_ignore_cable_id_ops);
3584 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
3585 &visual_confirm_fops);
3587 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
3588 adev, &dmub_tracebuffer_fops);
3590 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
3591 adev, &dmub_fw_state_fops);
3593 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
3594 adev, &force_timing_sync_ops);
3596 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
3597 adev, &dmcub_trace_event_state_fops);
3599 debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
3600 adev, &trigger_hpd_mst_ops);
3602 debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
3605 debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,