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 = copy_from_user(wr_buf_ptr, buf, wr_buf_size);
83 /* r is bytes not be copied */
84 if (r >= wr_buf_size) {
85 DRM_DEBUG_DRIVER("user data not be read\n");
89 /* check number of parameters. isspace could not differ space and \n */
90 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
92 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
97 if (wr_buf_count == wr_buf_size)
101 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
108 if (wr_buf_count == wr_buf_size)
112 if (*param_nums > max_param_num)
113 *param_nums = max_param_num;
115 wr_buf_ptr = wr_buf; /* reset buf pointer */
116 wr_buf_count = 0; /* number of char already checked */
118 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
123 while (param_index < *param_nums) {
124 /* after strsep, wr_buf_ptr will be moved to after space */
125 sub_str = strsep(&wr_buf_ptr, delimiter);
127 r = kstrtol(sub_str, 16, &(param[param_index]));
130 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
138 /* function description
139 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
141 * valid lane count value: 1, 2, 4
142 * valid link rate value:
143 * 06h = 1.62Gbps per lane
144 * 0Ah = 2.7Gbps per lane
145 * 0Ch = 3.24Gbps per lane
146 * 14h = 5.4Gbps per lane
147 * 1Eh = 8.1Gbps per lane
149 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
151 * --- to get dp configuration
153 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
155 * It will list current, verified, reported, preferred dp configuration.
156 * current -- for current video mode
157 * verified --- maximum configuration which pass link training
158 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
159 * preferred --- user force settings
161 * --- set (or force) dp configuration
163 * echo <lane_count> <link_rate> > link_settings
165 * for example, to force to 2 lane, 2.7GHz,
166 * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
168 * spread_spectrum could not be changed dynamically.
170 * in case invalid lane count, link rate are force, no hw programming will be
171 * done. please check link settings after force operation to see if HW get
174 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
176 * check current and preferred settings.
179 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
180 size_t size, loff_t *pos)
182 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
183 struct dc_link *link = connector->dc_link;
185 char *rd_buf_ptr = NULL;
186 const uint32_t rd_buf_size = 100;
191 if (*pos & 3 || size & 3)
194 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
200 str_len = strlen("Current: %d 0x%x %d ");
201 snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
202 link->cur_link_settings.lane_count,
203 link->cur_link_settings.link_rate,
204 link->cur_link_settings.link_spread);
205 rd_buf_ptr += str_len;
207 str_len = strlen("Verified: %d 0x%x %d ");
208 snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
209 link->verified_link_cap.lane_count,
210 link->verified_link_cap.link_rate,
211 link->verified_link_cap.link_spread);
212 rd_buf_ptr += str_len;
214 str_len = strlen("Reported: %d 0x%x %d ");
215 snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
216 link->reported_link_cap.lane_count,
217 link->reported_link_cap.link_rate,
218 link->reported_link_cap.link_spread);
219 rd_buf_ptr += str_len;
221 str_len = strlen("Preferred: %d 0x%x %d ");
222 snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
223 link->preferred_link_setting.lane_count,
224 link->preferred_link_setting.link_rate,
225 link->preferred_link_setting.link_spread);
228 if (*pos >= rd_buf_size)
231 r = put_user(*(rd_buf + result), buf);
233 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);
395 return r; /* r = -EFAULT */
407 static int dp_lttpr_status_show(struct seq_file *m, void *d)
410 struct amdgpu_dm_connector *connector = file_inode(m->file)->i_private;
411 struct dc_link *link = connector->dc_link;
412 uint32_t read_size = 1;
413 uint8_t repeater_count = 0;
415 data = kzalloc(read_size, GFP_KERNEL);
419 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0002, data, read_size);
421 switch ((uint8_t)*data) {
450 repeater_count = (uint8_t)*data;
454 seq_printf(m, "phy repeater count: %d\n", repeater_count);
456 dm_helpers_dp_read_dpcd(link->ctx, link, 0xF0003, data, read_size);
458 if ((uint8_t)*data == 0x55)
459 seq_printf(m, "phy repeater mode: transparent\n");
460 else if ((uint8_t)*data == 0xAA)
461 seq_printf(m, "phy repeater mode: non-transparent\n");
462 else if ((uint8_t)*data == 0x00)
463 seq_printf(m, "phy repeater mode: non lttpr\n");
465 seq_printf(m, "phy repeater mode: read error\n");
471 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
472 size_t size, loff_t *pos)
474 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
475 struct dc_link *link = connector->dc_link;
476 struct dc *dc = (struct dc *)link->dc;
478 uint32_t wr_buf_size = 40;
480 bool use_prefer_link_setting;
481 struct link_training_settings link_lane_settings;
482 int max_param_num = 3;
483 uint8_t param_nums = 0;
490 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
494 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
502 if (param_nums <= 0) {
504 DRM_DEBUG_DRIVER("user data not be read\n");
508 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
509 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
510 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
512 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
516 /* get link settings: lane count, link rate */
517 use_prefer_link_setting =
518 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
519 (link->test_pattern_enabled));
521 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
523 if (use_prefer_link_setting) {
524 link_lane_settings.link_settings.lane_count =
525 link->preferred_link_setting.lane_count;
526 link_lane_settings.link_settings.link_rate =
527 link->preferred_link_setting.link_rate;
528 link_lane_settings.link_settings.link_spread =
529 link->preferred_link_setting.link_spread;
531 link_lane_settings.link_settings.lane_count =
532 link->cur_link_settings.lane_count;
533 link_lane_settings.link_settings.link_rate =
534 link->cur_link_settings.link_rate;
535 link_lane_settings.link_settings.link_spread =
536 link->cur_link_settings.link_spread;
539 /* apply phy settings from user */
540 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
541 link_lane_settings.lane_settings[r].VOLTAGE_SWING =
542 (enum dc_voltage_swing) (param[0]);
543 link_lane_settings.lane_settings[r].PRE_EMPHASIS =
544 (enum dc_pre_emphasis) (param[1]);
545 link_lane_settings.lane_settings[r].POST_CURSOR2 =
546 (enum dc_post_cursor2) (param[2]);
549 /* program ASIC registers and DPCD registers */
550 dc_link_set_drive_settings(dc, &link_lane_settings, link);
556 /* function description
558 * set PHY layer or Link layer test pattern
559 * PHY test pattern is used for PHY SI check.
560 * Link layer test will not affect PHY SI.
562 * Reset Test Pattern:
563 * 0 = DP_TEST_PATTERN_VIDEO_MODE
565 * PHY test pattern supported:
566 * 1 = DP_TEST_PATTERN_D102
567 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
568 * 3 = DP_TEST_PATTERN_PRBS7
569 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
570 * 5 = DP_TEST_PATTERN_CP2520_1
571 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
572 * 7 = DP_TEST_PATTERN_CP2520_3
574 * DP PHY Link Training Patterns
575 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
576 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
577 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
578 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
580 * DP Link Layer Test pattern
581 * c = DP_TEST_PATTERN_COLOR_SQUARES
582 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
583 * e = DP_TEST_PATTERN_VERTICAL_BARS
584 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
585 * 10= DP_TEST_PATTERN_COLOR_RAMP
587 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
589 * --- set test pattern
590 * echo <test pattern #> > test_pattern
592 * If test pattern # is not supported, NO HW programming will be done.
593 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
594 * for the user pattern. input 10 bytes data are separated by space
596 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
598 * --- reset test pattern
599 * echo 0 > test_pattern
601 * --- HPD detection is disabled when set PHY test pattern
603 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
604 * is disable. User could unplug DP display from DP connected and plug scope to
605 * check test pattern PHY SI.
606 * If there is need unplug scope and plug DP display back, do steps below:
607 * echo 0 > phy_test_pattern
611 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
612 * driver could detect "unplug scope" and "plug DP display"
614 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
615 size_t size, loff_t *pos)
617 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
618 struct dc_link *link = connector->dc_link;
620 uint32_t wr_buf_size = 100;
621 long param[11] = {0x0};
622 int max_param_num = 11;
623 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
624 bool disable_hpd = false;
625 bool valid_test_pattern = false;
626 uint8_t param_nums = 0;
627 /* init with default 80bit custom pattern */
628 uint8_t custom_pattern[10] = {
629 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
630 0x1f, 0x7c, 0xf0, 0xc1, 0x07
632 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
633 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
634 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
635 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
636 struct link_training_settings link_training_settings;
642 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
646 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
654 if (param_nums <= 0) {
656 DRM_DEBUG_DRIVER("user data not be read\n");
661 test_pattern = param[0];
663 switch (test_pattern) {
664 case DP_TEST_PATTERN_VIDEO_MODE:
665 case DP_TEST_PATTERN_COLOR_SQUARES:
666 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
667 case DP_TEST_PATTERN_VERTICAL_BARS:
668 case DP_TEST_PATTERN_HORIZONTAL_BARS:
669 case DP_TEST_PATTERN_COLOR_RAMP:
670 valid_test_pattern = true;
673 case DP_TEST_PATTERN_D102:
674 case DP_TEST_PATTERN_SYMBOL_ERROR:
675 case DP_TEST_PATTERN_PRBS7:
676 case DP_TEST_PATTERN_80BIT_CUSTOM:
677 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
678 case DP_TEST_PATTERN_TRAINING_PATTERN4:
680 valid_test_pattern = true;
684 valid_test_pattern = false;
685 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
689 if (!valid_test_pattern) {
691 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
695 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
696 for (i = 0; i < 10; i++) {
697 if ((uint8_t) param[i + 1] != 0x0)
702 /* not use default value */
703 for (i = 0; i < 10; i++)
704 custom_pattern[i] = (uint8_t) param[i + 1];
708 /* Usage: set DP physical test pattern using debugfs with normal DP
709 * panel. Then plug out DP panel and connect a scope to measure
710 * For normal video mode and test pattern generated from CRCT,
711 * they are visibile to user. So do not disable HPD.
712 * Video Mode is also set to clear the test pattern, so enable HPD
713 * because it might have been disabled after a test pattern was set.
714 * AUX depends on HPD * sequence dependent, do not move!
717 dc_link_enable_hpd(link);
719 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
720 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
721 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
723 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
724 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
725 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
727 link_training_settings.link_settings = cur_link_settings;
730 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
731 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
732 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
733 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
734 prefer_link_settings.link_rate != cur_link_settings.link_rate))
735 link_training_settings.link_settings = prefer_link_settings;
738 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
739 link_training_settings.lane_settings[i] = link->cur_lane_setting[i];
741 dc_link_set_test_pattern(
744 DP_TEST_PATTERN_COLOR_SPACE_RGB,
745 &link_training_settings,
749 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
750 * Then plug out DP panel and connect a scope to measure DP PHY signal.
751 * Need disable interrupt to avoid SW driver disable DP output. This is
752 * done after the test pattern is set.
754 if (valid_test_pattern && disable_hpd)
755 dc_link_disable_hpd(link);
763 * Returns the DMCUB tracebuffer contents.
764 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
766 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
768 struct amdgpu_device *adev = m->private;
769 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
770 struct dmub_debugfs_trace_entry *entries;
772 uint32_t tbuf_size, max_entries, num_entries, i;
777 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
781 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
782 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
783 sizeof(struct dmub_debugfs_trace_entry);
786 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
788 num_entries = min(num_entries, max_entries);
790 entries = (struct dmub_debugfs_trace_entry
792 sizeof(struct dmub_debugfs_trace_header));
794 for (i = 0; i < num_entries; ++i) {
795 struct dmub_debugfs_trace_entry *entry = &entries[i];
798 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
799 entry->trace_code, entry->tick_count, entry->param0,
807 * Returns the DMCUB firmware state contents.
808 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
810 static int dmub_fw_state_show(struct seq_file *m, void *data)
812 struct amdgpu_device *adev = m->private;
813 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
820 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
824 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
826 return seq_write(m, state_base, state_size);
830 * Returns the current and maximum output bpc for the connector.
831 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/output_bpc
833 static int output_bpc_show(struct seq_file *m, void *data)
835 struct drm_connector *connector = m->private;
836 struct drm_device *dev = connector->dev;
837 struct drm_crtc *crtc = NULL;
838 struct dm_crtc_state *dm_crtc_state = NULL;
842 mutex_lock(&dev->mode_config.mutex);
843 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
845 if (connector->state == NULL)
848 crtc = connector->state->crtc;
852 drm_modeset_lock(&crtc->mutex, NULL);
853 if (crtc->state == NULL)
856 dm_crtc_state = to_dm_crtc_state(crtc->state);
857 if (dm_crtc_state->stream == NULL)
860 switch (dm_crtc_state->stream->timing.display_color_depth) {
861 case COLOR_DEPTH_666:
864 case COLOR_DEPTH_888:
867 case COLOR_DEPTH_101010:
870 case COLOR_DEPTH_121212:
873 case COLOR_DEPTH_161616:
880 seq_printf(m, "Current: %u\n", bpc);
881 seq_printf(m, "Maximum: %u\n", connector->display_info.bpc);
886 drm_modeset_unlock(&crtc->mutex);
888 drm_modeset_unlock(&dev->mode_config.connection_mutex);
889 mutex_unlock(&dev->mode_config.mutex);
896 * Disable dsc passthrough, i.e.,: have dsc decoding at converver, not external RX
897 * echo 1 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
898 * Enable dsc passthrough, i.e.,: have dsc passthrough to external RX
899 * echo 0 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
901 static ssize_t dp_dsc_passthrough_set(struct file *f, const char __user *buf,
902 size_t size, loff_t *pos)
904 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
906 uint32_t wr_buf_size = 42;
907 int max_param_num = 1;
909 uint8_t param_nums = 0;
914 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
917 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
921 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
929 aconnector->dsc_settings.dsc_force_disable_passthrough = param;
935 #ifdef CONFIG_DRM_AMD_DC_HDCP
937 * Returns the HDCP capability of the Display (1.4 for now).
939 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
940 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
942 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
943 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
945 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
947 struct drm_connector *connector = m->private;
948 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
949 bool hdcp_cap, hdcp2_cap;
951 if (connector->status != connector_status_connected)
954 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
956 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
957 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
961 seq_printf(m, "%s ", "HDCP1.4");
963 seq_printf(m, "%s ", "HDCP2.2");
965 if (!hdcp_cap && !hdcp2_cap)
966 seq_printf(m, "%s ", "None");
975 * Returns whether the connected display is internal and not hotpluggable.
976 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/internal_display
978 static int internal_display_show(struct seq_file *m, void *data)
980 struct drm_connector *connector = m->private;
981 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
982 struct dc_link *link = aconnector->dc_link;
984 seq_printf(m, "Internal: %u\n", link->is_internal_display);
989 /* function description
991 * generic SDP message access for testing
993 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
996 * Hb0 : Secondary-Data Packet ID
997 * Hb1 : Secondary-Data Packet type
998 * Hb2 : Secondary-Data-packet-specific header, Byte 0
999 * Hb3 : Secondary-Data-packet-specific header, Byte 1
1001 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
1003 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
1004 size_t size, loff_t *pos)
1008 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1009 struct dm_crtc_state *acrtc_state;
1010 uint32_t write_size = 36;
1012 if (connector->base.status != connector_status_connected)
1018 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
1020 r = copy_from_user(data, buf, write_size);
1024 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
1029 static ssize_t dp_dpcd_address_write(struct file *f, const char __user *buf,
1030 size_t size, loff_t *pos)
1033 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1035 if (size < sizeof(connector->debugfs_dpcd_address))
1038 r = copy_from_user(&connector->debugfs_dpcd_address,
1039 buf, sizeof(connector->debugfs_dpcd_address));
1044 static ssize_t dp_dpcd_size_write(struct file *f, const char __user *buf,
1045 size_t size, loff_t *pos)
1048 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1050 if (size < sizeof(connector->debugfs_dpcd_size))
1053 r = copy_from_user(&connector->debugfs_dpcd_size,
1054 buf, sizeof(connector->debugfs_dpcd_size));
1056 if (connector->debugfs_dpcd_size > 256)
1057 connector->debugfs_dpcd_size = 0;
1062 static ssize_t dp_dpcd_data_write(struct file *f, const char __user *buf,
1063 size_t size, loff_t *pos)
1067 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1068 struct dc_link *link = connector->dc_link;
1069 uint32_t write_size = connector->debugfs_dpcd_size;
1071 if (!write_size || size < write_size)
1074 data = kzalloc(write_size, GFP_KERNEL);
1078 r = copy_from_user(data, buf, write_size);
1080 dm_helpers_dp_write_dpcd(link->ctx, link,
1081 connector->debugfs_dpcd_address, data, write_size - r);
1083 return write_size - r;
1086 static ssize_t dp_dpcd_data_read(struct file *f, char __user *buf,
1087 size_t size, loff_t *pos)
1091 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1092 struct dc_link *link = connector->dc_link;
1093 uint32_t read_size = connector->debugfs_dpcd_size;
1095 if (!read_size || size < read_size)
1098 data = kzalloc(read_size, GFP_KERNEL);
1102 dm_helpers_dp_read_dpcd(link->ctx, link,
1103 connector->debugfs_dpcd_address, data, read_size);
1105 r = copy_to_user(buf, data, read_size);
1108 return read_size - r;
1111 /* function: Read link's DSC & FEC capabilities
1114 * Access it with the following command (you need to specify
1115 * connector like DP-1):
1117 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
1120 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
1122 struct drm_connector *connector = m->private;
1123 struct drm_modeset_acquire_ctx ctx;
1124 struct drm_device *dev = connector->dev;
1125 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1127 bool try_again = false;
1128 bool is_fec_supported = false;
1129 bool is_dsc_supported = false;
1130 struct dpcd_caps dpcd_caps;
1132 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1135 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1137 if (ret == -EDEADLK) {
1138 ret = drm_modeset_backoff(&ctx);
1146 if (connector->status != connector_status_connected) {
1150 dpcd_caps = aconnector->dc_link->dpcd_caps;
1151 if (aconnector->port) {
1152 /* aconnector sets dsc_aux during get_modes call
1153 * if MST connector has it means it can either
1154 * enable DSC on the sink device or on MST branch
1157 if (aconnector->dsc_aux) {
1158 is_fec_supported = true;
1159 is_dsc_supported = true;
1162 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1163 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1165 } while (try_again);
1167 drm_modeset_drop_locks(&ctx);
1168 drm_modeset_acquire_fini(&ctx);
1170 seq_printf(m, "FEC_Sink_Support: %s\n", yesno(is_fec_supported));
1171 seq_printf(m, "DSC_Sink_Support: %s\n", yesno(is_dsc_supported));
1176 /* function: Trigger virtual HPD redetection on connector
1178 * This function will perform link rediscovery, link disable
1179 * and enable, and dm connector state update.
1181 * Retrigger HPD on an existing connector by echoing 1 into
1182 * its respectful "trigger_hotplug" debugfs entry:
1184 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1186 * This function can perform HPD unplug:
1188 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1191 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1192 size_t size, loff_t *pos)
1194 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1195 struct drm_connector *connector = &aconnector->base;
1196 struct dc_link *link = NULL;
1197 struct drm_device *dev = connector->dev;
1198 enum dc_connection_type new_connection_type = dc_connection_none;
1199 char *wr_buf = NULL;
1200 uint32_t wr_buf_size = 42;
1201 int max_param_num = 1;
1202 long param[1] = {0};
1203 uint8_t param_nums = 0;
1205 if (!aconnector || !aconnector->dc_link)
1211 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1214 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1218 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1226 if (param_nums <= 0) {
1227 DRM_DEBUG_DRIVER("user data not be read\n");
1232 if (param[0] == 1) {
1233 mutex_lock(&aconnector->hpd_lock);
1235 if (!dc_link_detect_sink(aconnector->dc_link, &new_connection_type) &&
1236 new_connection_type != dc_connection_none)
1239 if (!dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD))
1242 amdgpu_dm_update_connector_after_detect(aconnector);
1244 drm_modeset_lock_all(dev);
1245 dm_restore_drm_connector_state(dev, connector);
1246 drm_modeset_unlock_all(dev);
1248 drm_kms_helper_hotplug_event(dev);
1249 } else if (param[0] == 0) {
1250 if (!aconnector->dc_link)
1253 link = aconnector->dc_link;
1255 if (link->local_sink) {
1256 dc_sink_release(link->local_sink);
1257 link->local_sink = NULL;
1260 link->dpcd_sink_count = 0;
1261 link->type = dc_connection_none;
1262 link->dongle_max_pix_clk = 0;
1264 amdgpu_dm_update_connector_after_detect(aconnector);
1266 drm_modeset_lock_all(dev);
1267 dm_restore_drm_connector_state(dev, connector);
1268 drm_modeset_unlock_all(dev);
1270 drm_kms_helper_hotplug_event(dev);
1274 mutex_unlock(&aconnector->hpd_lock);
1280 /* function: read DSC status on the connector
1282 * The read function: dp_dsc_clock_en_read
1283 * returns current status of DSC clock on the connector.
1284 * The return is a boolean flag: 1 or 0.
1286 * Access it with the following command (you need to specify
1287 * connector like DP-1):
1289 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1292 * 1 - means that DSC is currently enabled
1293 * 0 - means that DSC is disabled
1295 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1296 size_t size, loff_t *pos)
1298 char *rd_buf = NULL;
1299 char *rd_buf_ptr = NULL;
1300 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1301 struct display_stream_compressor *dsc;
1302 struct dcn_dsc_state dsc_state = {0};
1303 const uint32_t rd_buf_size = 10;
1304 struct pipe_ctx *pipe_ctx;
1306 int i, r, str_len = 30;
1308 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1313 rd_buf_ptr = rd_buf;
1315 for (i = 0; i < MAX_PIPES; i++) {
1316 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1317 if (pipe_ctx && pipe_ctx->stream &&
1318 pipe_ctx->stream->link == aconnector->dc_link)
1325 dsc = pipe_ctx->stream_res.dsc;
1327 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1329 snprintf(rd_buf_ptr, str_len,
1331 dsc_state.dsc_clock_en);
1332 rd_buf_ptr += str_len;
1335 if (*pos >= rd_buf_size)
1338 r = put_user(*(rd_buf + result), buf);
1340 return r; /* r = -EFAULT */
1352 /* function: write force DSC on the connector
1354 * The write function: dp_dsc_clock_en_write
1355 * enables to force DSC on the connector.
1356 * User can write to either force enable or force disable DSC
1357 * on the next modeset or set it to driver default
1360 * 0 - default DSC enablement policy
1361 * 1 - force enable DSC on the connector
1362 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1364 * Writing DSC settings is done with the following command:
1365 * - To force enable DSC (you need to specify
1366 * connector like DP-1):
1368 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1370 * - To return to default state set the flag to zero and
1371 * let driver deal with DSC automatically
1372 * (you need to specify connector like DP-1):
1374 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1377 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1378 size_t size, loff_t *pos)
1380 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1381 struct drm_connector *connector = &aconnector->base;
1382 struct drm_device *dev = connector->dev;
1383 struct drm_crtc *crtc = NULL;
1384 struct dm_crtc_state *dm_crtc_state = NULL;
1385 struct pipe_ctx *pipe_ctx;
1387 char *wr_buf = NULL;
1388 uint32_t wr_buf_size = 42;
1389 int max_param_num = 1;
1390 long param[1] = {0};
1391 uint8_t param_nums = 0;
1396 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1399 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1403 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1411 if (param_nums <= 0) {
1412 DRM_DEBUG_DRIVER("user data not be read\n");
1417 for (i = 0; i < MAX_PIPES; i++) {
1418 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1419 if (pipe_ctx && pipe_ctx->stream &&
1420 pipe_ctx->stream->link == aconnector->dc_link)
1424 if (!pipe_ctx || !pipe_ctx->stream)
1428 mutex_lock(&dev->mode_config.mutex);
1429 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1431 if (connector->state == NULL)
1434 crtc = connector->state->crtc;
1438 drm_modeset_lock(&crtc->mutex, NULL);
1439 if (crtc->state == NULL)
1442 dm_crtc_state = to_dm_crtc_state(crtc->state);
1443 if (dm_crtc_state->stream == NULL)
1447 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1448 else if (param[0] == 2)
1449 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1451 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1453 dm_crtc_state->dsc_force_changed = true;
1457 drm_modeset_unlock(&crtc->mutex);
1458 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1459 mutex_unlock(&dev->mode_config.mutex);
1466 /* function: read DSC slice width parameter on the connector
1468 * The read function: dp_dsc_slice_width_read
1469 * returns dsc slice width used in the current configuration
1470 * The return is an integer: 0 or other positive number
1472 * Access the status with the following command:
1474 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1476 * 0 - means that DSC is disabled
1478 * Any other number more than zero represents the
1479 * slice width currently used by DSC in pixels
1482 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1483 size_t size, loff_t *pos)
1485 char *rd_buf = NULL;
1486 char *rd_buf_ptr = NULL;
1487 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1488 struct display_stream_compressor *dsc;
1489 struct dcn_dsc_state dsc_state = {0};
1490 const uint32_t rd_buf_size = 100;
1491 struct pipe_ctx *pipe_ctx;
1493 int i, r, str_len = 30;
1495 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1500 rd_buf_ptr = rd_buf;
1502 for (i = 0; i < MAX_PIPES; i++) {
1503 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1504 if (pipe_ctx && pipe_ctx->stream &&
1505 pipe_ctx->stream->link == aconnector->dc_link)
1512 dsc = pipe_ctx->stream_res.dsc;
1514 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1516 snprintf(rd_buf_ptr, str_len,
1518 dsc_state.dsc_slice_width);
1519 rd_buf_ptr += str_len;
1522 if (*pos >= rd_buf_size)
1525 r = put_user(*(rd_buf + result), buf);
1527 return r; /* r = -EFAULT */
1539 /* function: write DSC slice width parameter
1541 * The write function: dp_dsc_slice_width_write
1542 * overwrites automatically generated DSC configuration
1545 * The user has to write the slice width divisible by the
1548 * Also the user has to write width in hexidecimal
1549 * rather than in decimal.
1551 * Writing DSC settings is done with the following command:
1552 * - To force overwrite slice width: (example sets to 1920 pixels)
1554 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1556 * - To stop overwriting and let driver find the optimal size,
1557 * set the width to zero:
1559 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1562 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1563 size_t size, loff_t *pos)
1565 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1566 struct pipe_ctx *pipe_ctx;
1567 struct drm_connector *connector = &aconnector->base;
1568 struct drm_device *dev = connector->dev;
1569 struct drm_crtc *crtc = NULL;
1570 struct dm_crtc_state *dm_crtc_state = NULL;
1572 char *wr_buf = NULL;
1573 uint32_t wr_buf_size = 42;
1574 int max_param_num = 1;
1575 long param[1] = {0};
1576 uint8_t param_nums = 0;
1581 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1584 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1588 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1596 if (param_nums <= 0) {
1597 DRM_DEBUG_DRIVER("user data not be read\n");
1602 for (i = 0; i < MAX_PIPES; i++) {
1603 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1604 if (pipe_ctx && pipe_ctx->stream &&
1605 pipe_ctx->stream->link == aconnector->dc_link)
1609 if (!pipe_ctx || !pipe_ctx->stream)
1612 // Safely get CRTC state
1613 mutex_lock(&dev->mode_config.mutex);
1614 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1616 if (connector->state == NULL)
1619 crtc = connector->state->crtc;
1623 drm_modeset_lock(&crtc->mutex, NULL);
1624 if (crtc->state == NULL)
1627 dm_crtc_state = to_dm_crtc_state(crtc->state);
1628 if (dm_crtc_state->stream == NULL)
1632 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1633 pipe_ctx->stream->timing.h_addressable,
1636 aconnector->dsc_settings.dsc_num_slices_h = 0;
1638 dm_crtc_state->dsc_force_changed = true;
1642 drm_modeset_unlock(&crtc->mutex);
1643 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1644 mutex_unlock(&dev->mode_config.mutex);
1651 /* function: read DSC slice height parameter on the connector
1653 * The read function: dp_dsc_slice_height_read
1654 * returns dsc slice height used in the current configuration
1655 * The return is an integer: 0 or other positive number
1657 * Access the status with the following command:
1659 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1661 * 0 - means that DSC is disabled
1663 * Any other number more than zero represents the
1664 * slice height currently used by DSC in pixels
1667 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1668 size_t size, loff_t *pos)
1670 char *rd_buf = NULL;
1671 char *rd_buf_ptr = NULL;
1672 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1673 struct display_stream_compressor *dsc;
1674 struct dcn_dsc_state dsc_state = {0};
1675 const uint32_t rd_buf_size = 100;
1676 struct pipe_ctx *pipe_ctx;
1678 int i, r, str_len = 30;
1680 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1685 rd_buf_ptr = rd_buf;
1687 for (i = 0; i < MAX_PIPES; i++) {
1688 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1689 if (pipe_ctx && pipe_ctx->stream &&
1690 pipe_ctx->stream->link == aconnector->dc_link)
1697 dsc = pipe_ctx->stream_res.dsc;
1699 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1701 snprintf(rd_buf_ptr, str_len,
1703 dsc_state.dsc_slice_height);
1704 rd_buf_ptr += str_len;
1707 if (*pos >= rd_buf_size)
1710 r = put_user(*(rd_buf + result), buf);
1712 return r; /* r = -EFAULT */
1724 /* function: write DSC slice height parameter
1726 * The write function: dp_dsc_slice_height_write
1727 * overwrites automatically generated DSC configuration
1730 * The user has to write the slice height divisible by the
1733 * Also the user has to write height in hexidecimal
1734 * rather than in decimal.
1736 * Writing DSC settings is done with the following command:
1737 * - To force overwrite slice height (example sets to 128 pixels):
1739 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1741 * - To stop overwriting and let driver find the optimal size,
1742 * set the height to zero:
1744 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1747 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1748 size_t size, loff_t *pos)
1750 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1751 struct drm_connector *connector = &aconnector->base;
1752 struct drm_device *dev = connector->dev;
1753 struct drm_crtc *crtc = NULL;
1754 struct dm_crtc_state *dm_crtc_state = NULL;
1755 struct pipe_ctx *pipe_ctx;
1757 char *wr_buf = NULL;
1758 uint32_t wr_buf_size = 42;
1759 int max_param_num = 1;
1760 uint8_t param_nums = 0;
1761 long param[1] = {0};
1766 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1769 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1773 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1781 if (param_nums <= 0) {
1782 DRM_DEBUG_DRIVER("user data not be read\n");
1787 for (i = 0; i < MAX_PIPES; i++) {
1788 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1789 if (pipe_ctx && pipe_ctx->stream &&
1790 pipe_ctx->stream->link == aconnector->dc_link)
1794 if (!pipe_ctx || !pipe_ctx->stream)
1798 mutex_lock(&dev->mode_config.mutex);
1799 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1801 if (connector->state == NULL)
1804 crtc = connector->state->crtc;
1808 drm_modeset_lock(&crtc->mutex, NULL);
1809 if (crtc->state == NULL)
1812 dm_crtc_state = to_dm_crtc_state(crtc->state);
1813 if (dm_crtc_state->stream == NULL)
1817 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1818 pipe_ctx->stream->timing.v_addressable,
1821 aconnector->dsc_settings.dsc_num_slices_v = 0;
1823 dm_crtc_state->dsc_force_changed = true;
1827 drm_modeset_unlock(&crtc->mutex);
1828 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1829 mutex_unlock(&dev->mode_config.mutex);
1836 /* function: read DSC target rate on the connector in bits per pixel
1838 * The read function: dp_dsc_bits_per_pixel_read
1839 * returns target rate of compression in bits per pixel
1840 * The return is an integer: 0 or other positive integer
1842 * Access it with the following command:
1844 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1846 * 0 - means that DSC is disabled
1848 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
1849 size_t size, loff_t *pos)
1851 char *rd_buf = NULL;
1852 char *rd_buf_ptr = NULL;
1853 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1854 struct display_stream_compressor *dsc;
1855 struct dcn_dsc_state dsc_state = {0};
1856 const uint32_t rd_buf_size = 100;
1857 struct pipe_ctx *pipe_ctx;
1859 int i, r, str_len = 30;
1861 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1866 rd_buf_ptr = rd_buf;
1868 for (i = 0; i < MAX_PIPES; i++) {
1869 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1870 if (pipe_ctx && pipe_ctx->stream &&
1871 pipe_ctx->stream->link == aconnector->dc_link)
1878 dsc = pipe_ctx->stream_res.dsc;
1880 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1882 snprintf(rd_buf_ptr, str_len,
1884 dsc_state.dsc_bits_per_pixel);
1885 rd_buf_ptr += str_len;
1888 if (*pos >= rd_buf_size)
1891 r = put_user(*(rd_buf + result), buf);
1893 return r; /* r = -EFAULT */
1905 /* function: write DSC target rate in bits per pixel
1907 * The write function: dp_dsc_bits_per_pixel_write
1908 * overwrites automatically generated DSC configuration
1909 * of DSC target bit rate.
1911 * Also the user has to write bpp in hexidecimal
1912 * rather than in decimal.
1914 * Writing DSC settings is done with the following command:
1915 * - To force overwrite rate (example sets to 256 bpp x 1/16):
1917 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1919 * - To stop overwriting and let driver find the optimal rate,
1920 * set the rate to zero:
1922 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1925 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
1926 size_t size, loff_t *pos)
1928 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1929 struct drm_connector *connector = &aconnector->base;
1930 struct drm_device *dev = connector->dev;
1931 struct drm_crtc *crtc = NULL;
1932 struct dm_crtc_state *dm_crtc_state = NULL;
1933 struct pipe_ctx *pipe_ctx;
1935 char *wr_buf = NULL;
1936 uint32_t wr_buf_size = 42;
1937 int max_param_num = 1;
1938 uint8_t param_nums = 0;
1939 long param[1] = {0};
1944 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1947 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1951 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1959 if (param_nums <= 0) {
1960 DRM_DEBUG_DRIVER("user data not be read\n");
1965 for (i = 0; i < MAX_PIPES; i++) {
1966 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1967 if (pipe_ctx && pipe_ctx->stream &&
1968 pipe_ctx->stream->link == aconnector->dc_link)
1972 if (!pipe_ctx || !pipe_ctx->stream)
1976 mutex_lock(&dev->mode_config.mutex);
1977 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1979 if (connector->state == NULL)
1982 crtc = connector->state->crtc;
1986 drm_modeset_lock(&crtc->mutex, NULL);
1987 if (crtc->state == NULL)
1990 dm_crtc_state = to_dm_crtc_state(crtc->state);
1991 if (dm_crtc_state->stream == NULL)
1994 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
1996 dm_crtc_state->dsc_force_changed = true;
2000 drm_modeset_unlock(&crtc->mutex);
2001 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2002 mutex_unlock(&dev->mode_config.mutex);
2009 /* function: read DSC picture width parameter on the connector
2011 * The read function: dp_dsc_pic_width_read
2012 * returns dsc picture width used in the current configuration
2013 * It is the same as h_addressable of the current
2015 * The return is an integer: 0 or other positive integer
2016 * If 0 then DSC is disabled.
2018 * Access it with the following command:
2020 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
2022 * 0 - means that DSC is disabled
2024 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
2025 size_t size, loff_t *pos)
2027 char *rd_buf = NULL;
2028 char *rd_buf_ptr = NULL;
2029 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2030 struct display_stream_compressor *dsc;
2031 struct dcn_dsc_state dsc_state = {0};
2032 const uint32_t rd_buf_size = 100;
2033 struct pipe_ctx *pipe_ctx;
2035 int i, r, str_len = 30;
2037 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2042 rd_buf_ptr = rd_buf;
2044 for (i = 0; i < MAX_PIPES; i++) {
2045 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2046 if (pipe_ctx && pipe_ctx->stream &&
2047 pipe_ctx->stream->link == aconnector->dc_link)
2054 dsc = pipe_ctx->stream_res.dsc;
2056 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2058 snprintf(rd_buf_ptr, str_len,
2060 dsc_state.dsc_pic_width);
2061 rd_buf_ptr += str_len;
2064 if (*pos >= rd_buf_size)
2067 r = put_user(*(rd_buf + result), buf);
2069 return r; /* r = -EFAULT */
2081 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
2082 size_t size, loff_t *pos)
2084 char *rd_buf = NULL;
2085 char *rd_buf_ptr = NULL;
2086 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2087 struct display_stream_compressor *dsc;
2088 struct dcn_dsc_state dsc_state = {0};
2089 const uint32_t rd_buf_size = 100;
2090 struct pipe_ctx *pipe_ctx;
2092 int i, r, str_len = 30;
2094 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2099 rd_buf_ptr = rd_buf;
2101 for (i = 0; i < MAX_PIPES; i++) {
2102 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2103 if (pipe_ctx && pipe_ctx->stream &&
2104 pipe_ctx->stream->link == aconnector->dc_link)
2111 dsc = pipe_ctx->stream_res.dsc;
2113 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2115 snprintf(rd_buf_ptr, str_len,
2117 dsc_state.dsc_pic_height);
2118 rd_buf_ptr += str_len;
2121 if (*pos >= rd_buf_size)
2124 r = put_user(*(rd_buf + result), buf);
2126 return r; /* r = -EFAULT */
2138 /* function: read DSC chunk size parameter on the connector
2140 * The read function: dp_dsc_chunk_size_read
2141 * returns dsc chunk size set in the current configuration
2142 * The value is calculated automatically by DSC code
2143 * and depends on slice parameters and bpp target rate
2144 * The return is an integer: 0 or other positive integer
2145 * If 0 then DSC is disabled.
2147 * Access it with the following command:
2149 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2151 * 0 - means that DSC is disabled
2153 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2154 size_t size, loff_t *pos)
2156 char *rd_buf = NULL;
2157 char *rd_buf_ptr = NULL;
2158 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2159 struct display_stream_compressor *dsc;
2160 struct dcn_dsc_state dsc_state = {0};
2161 const uint32_t rd_buf_size = 100;
2162 struct pipe_ctx *pipe_ctx;
2164 int i, r, str_len = 30;
2166 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2171 rd_buf_ptr = rd_buf;
2173 for (i = 0; i < MAX_PIPES; i++) {
2174 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2175 if (pipe_ctx && pipe_ctx->stream &&
2176 pipe_ctx->stream->link == aconnector->dc_link)
2183 dsc = pipe_ctx->stream_res.dsc;
2185 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2187 snprintf(rd_buf_ptr, str_len,
2189 dsc_state.dsc_chunk_size);
2190 rd_buf_ptr += str_len;
2193 if (*pos >= rd_buf_size)
2196 r = put_user(*(rd_buf + result), buf);
2198 return r; /* r = -EFAULT */
2210 /* function: read DSC slice bpg offset on the connector
2212 * The read function: dp_dsc_slice_bpg_offset_read
2213 * returns dsc bpg slice offset set in the current configuration
2214 * The value is calculated automatically by DSC code
2215 * and depends on slice parameters and bpp target rate
2216 * The return is an integer: 0 or other positive integer
2217 * If 0 then DSC is disabled.
2219 * Access it with the following command:
2221 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2223 * 0 - means that DSC is disabled
2225 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2226 size_t size, loff_t *pos)
2228 char *rd_buf = NULL;
2229 char *rd_buf_ptr = NULL;
2230 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2231 struct display_stream_compressor *dsc;
2232 struct dcn_dsc_state dsc_state = {0};
2233 const uint32_t rd_buf_size = 100;
2234 struct pipe_ctx *pipe_ctx;
2236 int i, r, str_len = 30;
2238 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2243 rd_buf_ptr = rd_buf;
2245 for (i = 0; i < MAX_PIPES; i++) {
2246 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2247 if (pipe_ctx && pipe_ctx->stream &&
2248 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_slice_bpg_offset);
2262 rd_buf_ptr += str_len;
2265 if (*pos >= rd_buf_size)
2268 r = put_user(*(rd_buf + result), buf);
2270 return r; /* r = -EFAULT */
2284 * function description: Read max_requested_bpc property from the connector
2286 * Access it with the following command:
2288 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2291 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2292 size_t size, loff_t *pos)
2294 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2295 struct drm_connector *connector = &aconnector->base;
2296 struct drm_device *dev = connector->dev;
2297 struct dm_connector_state *state;
2299 char *rd_buf = NULL;
2300 char *rd_buf_ptr = NULL;
2301 const uint32_t rd_buf_size = 10;
2304 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2309 mutex_lock(&dev->mode_config.mutex);
2310 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2312 if (connector->state == NULL)
2315 state = to_dm_connector_state(connector->state);
2317 rd_buf_ptr = rd_buf;
2318 snprintf(rd_buf_ptr, rd_buf_size,
2320 state->base.max_requested_bpc);
2323 if (*pos >= rd_buf_size)
2326 r = put_user(*(rd_buf + result), buf);
2328 result = r; /* r = -EFAULT */
2337 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2338 mutex_unlock(&dev->mode_config.mutex);
2345 * function description: Set max_requested_bpc property on the connector
2347 * This function will not force the input BPC on connector, it will only
2348 * change the max value. This is equivalent to setting max_bpc through
2351 * The BPC value written must be >= 6 and <= 16. Values outside of this
2352 * range will result in errors.
2361 * Write the max_bpc in the following way:
2363 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2366 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2367 size_t size, loff_t *pos)
2369 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2370 struct drm_connector *connector = &aconnector->base;
2371 struct dm_connector_state *state;
2372 struct drm_device *dev = connector->dev;
2373 char *wr_buf = NULL;
2374 uint32_t wr_buf_size = 42;
2375 int max_param_num = 1;
2376 long param[1] = {0};
2377 uint8_t param_nums = 0;
2382 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2385 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2389 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2397 if (param_nums <= 0) {
2398 DRM_DEBUG_DRIVER("user data not be read\n");
2403 if (param[0] < 6 || param[0] > 16) {
2404 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2409 mutex_lock(&dev->mode_config.mutex);
2410 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2412 if (connector->state == NULL)
2415 state = to_dm_connector_state(connector->state);
2416 state->base.max_requested_bpc = param[0];
2418 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2419 mutex_unlock(&dev->mode_config.mutex);
2426 * Backlight at this moment. Read only.
2427 * As written to display, taking ABM and backlight lut into account.
2428 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2430 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/current_backlight
2432 static int current_backlight_show(struct seq_file *m, void *unused)
2434 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2435 struct dc_link *link = aconnector->dc_link;
2436 unsigned int backlight;
2438 backlight = dc_link_get_backlight_level(link);
2439 seq_printf(m, "0x%x\n", backlight);
2445 * Backlight value that is being approached. Read only.
2446 * As written to display, taking ABM and backlight lut into account.
2447 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2449 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/target_backlight
2451 static int target_backlight_show(struct seq_file *m, void *unused)
2453 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2454 struct dc_link *link = aconnector->dc_link;
2455 unsigned int backlight;
2457 backlight = dc_link_get_target_backlight_pwm(link);
2458 seq_printf(m, "0x%x\n", backlight);
2463 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2464 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2465 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2466 DEFINE_SHOW_ATTRIBUTE(output_bpc);
2467 DEFINE_SHOW_ATTRIBUTE(dp_lttpr_status);
2468 #ifdef CONFIG_DRM_AMD_DC_HDCP
2469 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2471 DEFINE_SHOW_ATTRIBUTE(internal_display);
2473 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2474 .owner = THIS_MODULE,
2475 .read = dp_dsc_clock_en_read,
2476 .write = dp_dsc_clock_en_write,
2477 .llseek = default_llseek
2480 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2481 .owner = THIS_MODULE,
2482 .read = dp_dsc_slice_width_read,
2483 .write = dp_dsc_slice_width_write,
2484 .llseek = default_llseek
2487 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2488 .owner = THIS_MODULE,
2489 .read = dp_dsc_slice_height_read,
2490 .write = dp_dsc_slice_height_write,
2491 .llseek = default_llseek
2494 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2495 .owner = THIS_MODULE,
2496 .read = dp_dsc_bits_per_pixel_read,
2497 .write = dp_dsc_bits_per_pixel_write,
2498 .llseek = default_llseek
2501 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2502 .owner = THIS_MODULE,
2503 .read = dp_dsc_pic_width_read,
2504 .llseek = default_llseek
2507 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2508 .owner = THIS_MODULE,
2509 .read = dp_dsc_pic_height_read,
2510 .llseek = default_llseek
2513 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2514 .owner = THIS_MODULE,
2515 .read = dp_dsc_chunk_size_read,
2516 .llseek = default_llseek
2519 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2520 .owner = THIS_MODULE,
2521 .read = dp_dsc_slice_bpg_offset_read,
2522 .llseek = default_llseek
2525 static const struct file_operations trigger_hotplug_debugfs_fops = {
2526 .owner = THIS_MODULE,
2527 .write = trigger_hotplug,
2528 .llseek = default_llseek
2531 static const struct file_operations dp_link_settings_debugfs_fops = {
2532 .owner = THIS_MODULE,
2533 .read = dp_link_settings_read,
2534 .write = dp_link_settings_write,
2535 .llseek = default_llseek
2538 static const struct file_operations dp_phy_settings_debugfs_fop = {
2539 .owner = THIS_MODULE,
2540 .read = dp_phy_settings_read,
2541 .write = dp_phy_settings_write,
2542 .llseek = default_llseek
2545 static const struct file_operations dp_phy_test_pattern_fops = {
2546 .owner = THIS_MODULE,
2547 .write = dp_phy_test_pattern_debugfs_write,
2548 .llseek = default_llseek
2551 static const struct file_operations sdp_message_fops = {
2552 .owner = THIS_MODULE,
2553 .write = dp_sdp_message_debugfs_write,
2554 .llseek = default_llseek
2557 static const struct file_operations dp_dpcd_address_debugfs_fops = {
2558 .owner = THIS_MODULE,
2559 .write = dp_dpcd_address_write,
2560 .llseek = default_llseek
2563 static const struct file_operations dp_dpcd_size_debugfs_fops = {
2564 .owner = THIS_MODULE,
2565 .write = dp_dpcd_size_write,
2566 .llseek = default_llseek
2569 static const struct file_operations dp_dpcd_data_debugfs_fops = {
2570 .owner = THIS_MODULE,
2571 .read = dp_dpcd_data_read,
2572 .write = dp_dpcd_data_write,
2573 .llseek = default_llseek
2576 static const struct file_operations dp_max_bpc_debugfs_fops = {
2577 .owner = THIS_MODULE,
2578 .read = dp_max_bpc_read,
2579 .write = dp_max_bpc_write,
2580 .llseek = default_llseek
2583 static const struct file_operations dp_dsc_disable_passthrough_debugfs_fops = {
2584 .owner = THIS_MODULE,
2585 .write = dp_dsc_passthrough_set,
2586 .llseek = default_llseek
2589 static const struct {
2591 const struct file_operations *fops;
2592 } dp_debugfs_entries[] = {
2593 {"link_settings", &dp_link_settings_debugfs_fops},
2594 {"phy_settings", &dp_phy_settings_debugfs_fop},
2595 {"lttpr_status", &dp_lttpr_status_fops},
2596 {"test_pattern", &dp_phy_test_pattern_fops},
2597 #ifdef CONFIG_DRM_AMD_DC_HDCP
2598 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2600 {"sdp_message", &sdp_message_fops},
2601 {"aux_dpcd_address", &dp_dpcd_address_debugfs_fops},
2602 {"aux_dpcd_size", &dp_dpcd_size_debugfs_fops},
2603 {"aux_dpcd_data", &dp_dpcd_data_debugfs_fops},
2604 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2605 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2606 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2607 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2608 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2609 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2610 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2611 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2612 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
2613 {"max_bpc", &dp_max_bpc_debugfs_fops},
2614 {"dsc_disable_passthrough", &dp_dsc_disable_passthrough_debugfs_fops},
2617 #ifdef CONFIG_DRM_AMD_DC_HDCP
2618 static const struct {
2620 const struct file_operations *fops;
2621 } hdmi_debugfs_entries[] = {
2622 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
2626 * Force YUV420 output if available from the given mode
2628 static int force_yuv420_output_set(void *data, u64 val)
2630 struct amdgpu_dm_connector *connector = data;
2632 connector->force_yuv420_output = (bool)val;
2638 * Check if YUV420 is forced when available from the given mode
2640 static int force_yuv420_output_get(void *data, u64 *val)
2642 struct amdgpu_dm_connector *connector = data;
2644 *val = connector->force_yuv420_output;
2649 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2650 force_yuv420_output_set, "%llu\n");
2655 static int psr_get(void *data, u64 *val)
2657 struct amdgpu_dm_connector *connector = data;
2658 struct dc_link *link = connector->dc_link;
2659 enum dc_psr_state state = PSR_STATE0;
2661 dc_link_get_psr_state(link, &state);
2669 * Set dmcub trace event IRQ enable or disable.
2670 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2671 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2673 static int dmcub_trace_event_state_set(void *data, u64 val)
2675 struct amdgpu_device *adev = data;
2677 if (val == 1 || val == 0) {
2678 dc_dmub_trace_event_control(adev->dm.dc, val);
2679 adev->dm.dmcub_trace_event_en = (bool)val;
2687 * The interface doesn't need get function, so it will return the
2689 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2691 static int dmcub_trace_event_state_get(void *data, u64 *val)
2693 struct amdgpu_device *adev = data;
2695 *val = adev->dm.dmcub_trace_event_en;
2699 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
2700 dmcub_trace_event_state_set, "%llu\n");
2702 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
2704 DEFINE_SHOW_ATTRIBUTE(current_backlight);
2705 DEFINE_SHOW_ATTRIBUTE(target_backlight);
2707 static const struct {
2709 const struct file_operations *fops;
2710 } connector_debugfs_entries[] = {
2711 {"force_yuv420_output", &force_yuv420_output_fops},
2712 {"output_bpc", &output_bpc_fops},
2713 {"trigger_hotplug", &trigger_hotplug_debugfs_fops},
2714 {"internal_display", &internal_display_fops}
2717 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
2720 struct dentry *dir = connector->base.debugfs_entry;
2722 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
2723 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2724 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
2725 debugfs_create_file(dp_debugfs_entries[i].name,
2726 0644, dir, connector,
2727 dp_debugfs_entries[i].fops);
2730 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2731 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
2732 debugfs_create_file("amdgpu_current_backlight_pwm", 0444, dir, connector,
2733 ¤t_backlight_fops);
2734 debugfs_create_file("amdgpu_target_backlight_pwm", 0444, dir, connector,
2735 &target_backlight_fops);
2738 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
2739 debugfs_create_file(connector_debugfs_entries[i].name,
2740 0644, dir, connector,
2741 connector_debugfs_entries[i].fops);
2744 connector->debugfs_dpcd_address = 0;
2745 connector->debugfs_dpcd_size = 0;
2747 #ifdef CONFIG_DRM_AMD_DC_HDCP
2748 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
2749 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
2750 debugfs_create_file(hdmi_debugfs_entries[i].name,
2751 0644, dir, connector,
2752 hdmi_debugfs_entries[i].fops);
2758 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
2760 * Set crc window coordinate x start
2762 static int crc_win_x_start_set(void *data, u64 val)
2764 struct drm_crtc *crtc = data;
2765 struct drm_device *drm_dev = crtc->dev;
2766 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2768 spin_lock_irq(&drm_dev->event_lock);
2769 acrtc->dm_irq_params.crc_window.x_start = (uint16_t) val;
2770 acrtc->dm_irq_params.crc_window.update_win = false;
2771 spin_unlock_irq(&drm_dev->event_lock);
2777 * Get crc window coordinate x start
2779 static int crc_win_x_start_get(void *data, u64 *val)
2781 struct drm_crtc *crtc = data;
2782 struct drm_device *drm_dev = crtc->dev;
2783 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2785 spin_lock_irq(&drm_dev->event_lock);
2786 *val = acrtc->dm_irq_params.crc_window.x_start;
2787 spin_unlock_irq(&drm_dev->event_lock);
2792 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
2793 crc_win_x_start_set, "%llu\n");
2797 * Set crc window coordinate y start
2799 static int crc_win_y_start_set(void *data, u64 val)
2801 struct drm_crtc *crtc = data;
2802 struct drm_device *drm_dev = crtc->dev;
2803 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2805 spin_lock_irq(&drm_dev->event_lock);
2806 acrtc->dm_irq_params.crc_window.y_start = (uint16_t) val;
2807 acrtc->dm_irq_params.crc_window.update_win = false;
2808 spin_unlock_irq(&drm_dev->event_lock);
2814 * Get crc window coordinate y start
2816 static int crc_win_y_start_get(void *data, u64 *val)
2818 struct drm_crtc *crtc = data;
2819 struct drm_device *drm_dev = crtc->dev;
2820 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2822 spin_lock_irq(&drm_dev->event_lock);
2823 *val = acrtc->dm_irq_params.crc_window.y_start;
2824 spin_unlock_irq(&drm_dev->event_lock);
2829 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
2830 crc_win_y_start_set, "%llu\n");
2833 * Set crc window coordinate x end
2835 static int crc_win_x_end_set(void *data, u64 val)
2837 struct drm_crtc *crtc = data;
2838 struct drm_device *drm_dev = crtc->dev;
2839 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2841 spin_lock_irq(&drm_dev->event_lock);
2842 acrtc->dm_irq_params.crc_window.x_end = (uint16_t) val;
2843 acrtc->dm_irq_params.crc_window.update_win = false;
2844 spin_unlock_irq(&drm_dev->event_lock);
2850 * Get crc window coordinate x end
2852 static int crc_win_x_end_get(void *data, u64 *val)
2854 struct drm_crtc *crtc = data;
2855 struct drm_device *drm_dev = crtc->dev;
2856 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2858 spin_lock_irq(&drm_dev->event_lock);
2859 *val = acrtc->dm_irq_params.crc_window.x_end;
2860 spin_unlock_irq(&drm_dev->event_lock);
2865 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
2866 crc_win_x_end_set, "%llu\n");
2869 * Set crc window coordinate y end
2871 static int crc_win_y_end_set(void *data, u64 val)
2873 struct drm_crtc *crtc = data;
2874 struct drm_device *drm_dev = crtc->dev;
2875 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2877 spin_lock_irq(&drm_dev->event_lock);
2878 acrtc->dm_irq_params.crc_window.y_end = (uint16_t) val;
2879 acrtc->dm_irq_params.crc_window.update_win = false;
2880 spin_unlock_irq(&drm_dev->event_lock);
2886 * Get crc window coordinate y end
2888 static int crc_win_y_end_get(void *data, u64 *val)
2890 struct drm_crtc *crtc = data;
2891 struct drm_device *drm_dev = crtc->dev;
2892 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2894 spin_lock_irq(&drm_dev->event_lock);
2895 *val = acrtc->dm_irq_params.crc_window.y_end;
2896 spin_unlock_irq(&drm_dev->event_lock);
2901 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
2902 crc_win_y_end_set, "%llu\n");
2904 * Trigger to commit crc window
2906 static int crc_win_update_set(void *data, u64 val)
2908 struct drm_crtc *new_crtc = data;
2909 struct drm_crtc *old_crtc = NULL;
2910 struct amdgpu_crtc *new_acrtc, *old_acrtc;
2911 struct amdgpu_device *adev = drm_to_adev(new_crtc->dev);
2912 struct crc_rd_work *crc_rd_wrk = adev->dm.crc_rd_wrk;
2915 spin_lock_irq(&adev_to_drm(adev)->event_lock);
2916 spin_lock_irq(&crc_rd_wrk->crc_rd_work_lock);
2917 if (crc_rd_wrk && crc_rd_wrk->crtc) {
2918 old_crtc = crc_rd_wrk->crtc;
2919 old_acrtc = to_amdgpu_crtc(old_crtc);
2921 new_acrtc = to_amdgpu_crtc(new_crtc);
2923 if (old_crtc && old_crtc != new_crtc) {
2924 old_acrtc->dm_irq_params.crc_window.activated = false;
2925 old_acrtc->dm_irq_params.crc_window.update_win = false;
2926 old_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
2928 new_acrtc->dm_irq_params.crc_window.activated = true;
2929 new_acrtc->dm_irq_params.crc_window.update_win = true;
2930 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
2931 crc_rd_wrk->crtc = new_crtc;
2933 new_acrtc->dm_irq_params.crc_window.activated = true;
2934 new_acrtc->dm_irq_params.crc_window.update_win = true;
2935 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
2936 crc_rd_wrk->crtc = new_crtc;
2938 spin_unlock_irq(&crc_rd_wrk->crc_rd_work_lock);
2939 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
2946 * Get crc window update flag
2948 static int crc_win_update_get(void *data, u64 *val)
2954 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
2955 crc_win_update_set, "%llu\n");
2957 void crtc_debugfs_init(struct drm_crtc *crtc)
2959 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
2964 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
2965 &crc_win_x_start_fops);
2966 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
2967 &crc_win_y_start_fops);
2968 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
2969 &crc_win_x_end_fops);
2970 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
2971 &crc_win_y_end_fops);
2972 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
2973 &crc_win_update_fops);
2978 * Writes DTN log state to the user supplied buffer.
2979 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
2981 static ssize_t dtn_log_read(
2987 struct amdgpu_device *adev = file_inode(f)->i_private;
2988 struct dc *dc = adev->dm.dc;
2989 struct dc_log_buffer_ctx log_ctx = { 0 };
2995 if (!dc->hwss.log_hw_state)
2998 dc->hwss.log_hw_state(dc, &log_ctx);
3000 if (*pos < log_ctx.pos) {
3001 size_t to_copy = log_ctx.pos - *pos;
3003 to_copy = min(to_copy, size);
3005 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
3017 * Writes DTN log state to dmesg when triggered via a write.
3018 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3020 static ssize_t dtn_log_write(
3022 const char __user *buf,
3026 struct amdgpu_device *adev = file_inode(f)->i_private;
3027 struct dc *dc = adev->dm.dc;
3029 /* Write triggers log output via dmesg. */
3033 if (dc->hwss.log_hw_state)
3034 dc->hwss.log_hw_state(dc, NULL);
3039 static int mst_topo_show(struct seq_file *m, void *unused)
3041 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3042 struct drm_device *dev = adev_to_drm(adev);
3043 struct drm_connector *connector;
3044 struct drm_connector_list_iter conn_iter;
3045 struct amdgpu_dm_connector *aconnector;
3047 drm_connector_list_iter_begin(dev, &conn_iter);
3048 drm_for_each_connector_iter(connector, &conn_iter) {
3049 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3052 aconnector = to_amdgpu_dm_connector(connector);
3054 /* Ensure we're only dumping the topology of a root mst node */
3055 if (!aconnector->mst_mgr.mst_state)
3058 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
3059 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
3061 drm_connector_list_iter_end(&conn_iter);
3067 * Sets trigger hpd for MST topologies.
3068 * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
3069 * All topologies will be disconnected if val of 0 is set .
3070 * Usage to enable topologies: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3071 * Usage to disable topologies: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3073 static int trigger_hpd_mst_set(void *data, u64 val)
3075 struct amdgpu_device *adev = data;
3076 struct drm_device *dev = adev_to_drm(adev);
3077 struct drm_connector_list_iter iter;
3078 struct amdgpu_dm_connector *aconnector;
3079 struct drm_connector *connector;
3080 struct dc_link *link = NULL;
3083 drm_connector_list_iter_begin(dev, &iter);
3084 drm_for_each_connector_iter(connector, &iter) {
3085 aconnector = to_amdgpu_dm_connector(connector);
3086 if (aconnector->dc_link->type == dc_connection_mst_branch &&
3087 aconnector->mst_mgr.aux) {
3088 dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3089 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
3092 } else if (val == 0) {
3093 drm_connector_list_iter_begin(dev, &iter);
3094 drm_for_each_connector_iter(connector, &iter) {
3095 aconnector = to_amdgpu_dm_connector(connector);
3096 if (!aconnector->dc_link)
3099 if (!aconnector->mst_port)
3102 link = aconnector->dc_link;
3103 dp_receiver_power_ctrl(link, false);
3104 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_port->mst_mgr, false);
3105 link->mst_stream_alloc_table.stream_count = 0;
3106 memset(link->mst_stream_alloc_table.stream_allocations, 0,
3107 sizeof(link->mst_stream_alloc_table.stream_allocations));
3112 drm_kms_helper_hotplug_event(dev);
3118 * The interface doesn't need get function, so it will return the
3120 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3122 static int trigger_hpd_mst_get(void *data, u64 *val)
3128 DEFINE_DEBUGFS_ATTRIBUTE(trigger_hpd_mst_ops, trigger_hpd_mst_get,
3129 trigger_hpd_mst_set, "%llu\n");
3133 * Sets the force_timing_sync debug option from the given string.
3134 * All connected displays will be force synchronized immediately.
3135 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3137 static int force_timing_sync_set(void *data, u64 val)
3139 struct amdgpu_device *adev = data;
3141 adev->dm.force_timing_sync = (bool)val;
3143 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
3149 * Gets the force_timing_sync debug option value into the given buffer.
3150 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3152 static int force_timing_sync_get(void *data, u64 *val)
3154 struct amdgpu_device *adev = data;
3156 *val = adev->dm.force_timing_sync;
3161 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
3162 force_timing_sync_set, "%llu\n");
3166 * Disables all HPD and HPD RX interrupt handling in the
3167 * driver when set to 1. Default is 0.
3169 static int disable_hpd_set(void *data, u64 val)
3171 struct amdgpu_device *adev = data;
3173 adev->dm.disable_hpd_irq = (bool)val;
3180 * Returns 1 if HPD and HPRX interrupt handling is disabled,
3183 static int disable_hpd_get(void *data, u64 *val)
3185 struct amdgpu_device *adev = data;
3187 *val = adev->dm.disable_hpd_irq;
3192 DEFINE_DEBUGFS_ATTRIBUTE(disable_hpd_ops, disable_hpd_get,
3193 disable_hpd_set, "%llu\n");
3196 * Sets the DC visual confirm debug option from the given string.
3197 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
3199 static int visual_confirm_set(void *data, u64 val)
3201 struct amdgpu_device *adev = data;
3203 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
3209 * Reads the DC visual confirm debug option value into the given buffer.
3210 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
3212 static int visual_confirm_get(void *data, u64 *val)
3214 struct amdgpu_device *adev = data;
3216 *val = adev->dm.dc->debug.visual_confirm;
3221 DEFINE_SHOW_ATTRIBUTE(mst_topo);
3222 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
3223 visual_confirm_set, "%llu\n");
3226 * Dumps the DCC_EN bit for each pipe.
3227 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dcc_en
3229 static ssize_t dcc_en_bits_read(
3235 struct amdgpu_device *adev = file_inode(f)->i_private;
3236 struct dc *dc = adev->dm.dc;
3237 char *rd_buf = NULL;
3238 const uint32_t rd_buf_size = 32;
3239 uint32_t result = 0;
3241 int num_pipes = dc->res_pool->pipe_count;
3245 dcc_en_bits = kcalloc(num_pipes, sizeof(int), GFP_KERNEL);
3249 if (!dc->hwss.get_dcc_en_bits) {
3254 dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
3256 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
3260 for (i = 0; i < num_pipes; i++)
3261 offset += snprintf(rd_buf + offset, rd_buf_size - offset,
3262 "%d ", dcc_en_bits[i]);
3263 rd_buf[strlen(rd_buf)] = '\n';
3268 if (*pos >= rd_buf_size)
3270 r = put_user(*(rd_buf + result), buf);
3272 return r; /* r = -EFAULT */
3283 void dtn_debugfs_init(struct amdgpu_device *adev)
3285 static const struct file_operations dtn_log_fops = {
3286 .owner = THIS_MODULE,
3287 .read = dtn_log_read,
3288 .write = dtn_log_write,
3289 .llseek = default_llseek
3291 static const struct file_operations dcc_en_bits_fops = {
3292 .owner = THIS_MODULE,
3293 .read = dcc_en_bits_read,
3294 .llseek = default_llseek
3297 struct drm_minor *minor = adev_to_drm(adev)->primary;
3298 struct dentry *root = minor->debugfs_root;
3300 debugfs_create_file("amdgpu_mst_topology", 0444, root,
3301 adev, &mst_topo_fops);
3302 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
3305 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
3306 &visual_confirm_fops);
3308 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
3309 adev, &dmub_tracebuffer_fops);
3311 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
3312 adev, &dmub_fw_state_fops);
3314 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
3315 adev, &force_timing_sync_ops);
3317 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
3318 adev, &dmcub_trace_event_state_fops);
3320 debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
3321 adev, &trigger_hpd_mst_ops);
3323 debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
3326 debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,