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>
28 #include <drm/drm_debugfs.h>
32 #include "amdgpu_dm.h"
33 #include "amdgpu_dm_debugfs.h"
34 #include "dm_helpers.h"
35 #include "dmub/dmub_srv.h"
38 #include "dc_link_dp.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
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 > 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
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 %d %d ");
201 snprintf(rd_buf_ptr, str_len, "Current: %d %d %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 %d %d ");
208 snprintf(rd_buf_ptr, str_len, "Verified: %d %d %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 %d %d ");
215 snprintf(rd_buf_ptr, str_len, "Reported: %d %d %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 %d %d ");
222 snprintf(rd_buf_ptr, str_len, "Preferred: %d %d %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 = false;
263 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
267 if (parse_write_buffer_into_params(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:
305 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
309 /* save user force lane_count, link_rate to preferred settings
310 * spread spectrum will not be changed
312 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
313 prefer_link_settings.lane_count = param[0];
314 prefer_link_settings.link_rate = param[1];
316 dc_link_set_preferred_link_settings(dc, &prefer_link_settings, link);
322 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
323 * post-cursor2 (defined by VESA DP specification)
326 * voltage swing: 0,1,2,3
327 * pre-emphasis : 0,1,2,3
328 * post cursor2 : 0,1,2,3
331 * how to use this debugfs
333 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
335 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
337 * To figure out which DP-x is the display for DP to be check,
340 * There should be debugfs file, like link_settings, phy_settings.
342 * from lane_count, link_rate to figure which DP-x is for display to be worked
345 * To get current DP PHY settings,
348 * To change DP PHY settings,
349 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
350 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
352 * echo 2 3 0 > phy_settings
354 * To check if change be applied, get current phy settings by
357 * In case invalid values are set by user, like
358 * echo 1 4 0 > phy_settings
360 * HW will NOT be programmed by these settings.
361 * cat phy_settings will show the previous valid settings.
363 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
364 size_t size, loff_t *pos)
366 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
367 struct dc_link *link = connector->dc_link;
369 const uint32_t rd_buf_size = 20;
373 if (*pos & 3 || size & 3)
376 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
380 snprintf(rd_buf, rd_buf_size, " %d %d %d ",
381 link->cur_lane_setting.VOLTAGE_SWING,
382 link->cur_lane_setting.PRE_EMPHASIS,
383 link->cur_lane_setting.POST_CURSOR2);
386 if (*pos >= rd_buf_size)
389 r = put_user((*(rd_buf + result)), buf);
391 return r; /* r = -EFAULT */
403 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
404 size_t size, loff_t *pos)
406 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
407 struct dc_link *link = connector->dc_link;
408 struct dc *dc = (struct dc *)link->dc;
410 uint32_t wr_buf_size = 40;
412 bool use_prefer_link_setting;
413 struct link_training_settings link_lane_settings;
414 int max_param_num = 3;
415 uint8_t param_nums = 0;
422 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
426 if (parse_write_buffer_into_params(wr_buf, size,
434 if (param_nums <= 0) {
436 DRM_DEBUG_DRIVER("user data not be read\n");
440 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
441 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
442 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
444 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
448 /* get link settings: lane count, link rate */
449 use_prefer_link_setting =
450 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
451 (link->test_pattern_enabled));
453 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
455 if (use_prefer_link_setting) {
456 link_lane_settings.link_settings.lane_count =
457 link->preferred_link_setting.lane_count;
458 link_lane_settings.link_settings.link_rate =
459 link->preferred_link_setting.link_rate;
460 link_lane_settings.link_settings.link_spread =
461 link->preferred_link_setting.link_spread;
463 link_lane_settings.link_settings.lane_count =
464 link->cur_link_settings.lane_count;
465 link_lane_settings.link_settings.link_rate =
466 link->cur_link_settings.link_rate;
467 link_lane_settings.link_settings.link_spread =
468 link->cur_link_settings.link_spread;
471 /* apply phy settings from user */
472 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
473 link_lane_settings.lane_settings[r].VOLTAGE_SWING =
474 (enum dc_voltage_swing) (param[0]);
475 link_lane_settings.lane_settings[r].PRE_EMPHASIS =
476 (enum dc_pre_emphasis) (param[1]);
477 link_lane_settings.lane_settings[r].POST_CURSOR2 =
478 (enum dc_post_cursor2) (param[2]);
481 /* program ASIC registers and DPCD registers */
482 dc_link_set_drive_settings(dc, &link_lane_settings, link);
488 /* function description
490 * set PHY layer or Link layer test pattern
491 * PHY test pattern is used for PHY SI check.
492 * Link layer test will not affect PHY SI.
494 * Reset Test Pattern:
495 * 0 = DP_TEST_PATTERN_VIDEO_MODE
497 * PHY test pattern supported:
498 * 1 = DP_TEST_PATTERN_D102
499 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
500 * 3 = DP_TEST_PATTERN_PRBS7
501 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
502 * 5 = DP_TEST_PATTERN_CP2520_1
503 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
504 * 7 = DP_TEST_PATTERN_CP2520_3
506 * DP PHY Link Training Patterns
507 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
508 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
509 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
510 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
512 * DP Link Layer Test pattern
513 * c = DP_TEST_PATTERN_COLOR_SQUARES
514 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
515 * e = DP_TEST_PATTERN_VERTICAL_BARS
516 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
517 * 10= DP_TEST_PATTERN_COLOR_RAMP
519 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
521 * --- set test pattern
522 * echo <test pattern #> > test_pattern
524 * If test pattern # is not supported, NO HW programming will be done.
525 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
526 * for the user pattern. input 10 bytes data are separated by space
528 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
530 * --- reset test pattern
531 * echo 0 > test_pattern
533 * --- HPD detection is disabled when set PHY test pattern
535 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
536 * is disable. User could unplug DP display from DP connected and plug scope to
537 * check test pattern PHY SI.
538 * If there is need unplug scope and plug DP display back, do steps below:
539 * echo 0 > phy_test_pattern
543 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
544 * driver could detect "unplug scope" and "plug DP display"
546 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
547 size_t size, loff_t *pos)
549 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
550 struct dc_link *link = connector->dc_link;
552 uint32_t wr_buf_size = 100;
553 long param[11] = {0x0};
554 int max_param_num = 11;
555 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
556 bool disable_hpd = false;
557 bool valid_test_pattern = false;
558 uint8_t param_nums = 0;
559 /* init with defalut 80bit custom pattern */
560 uint8_t custom_pattern[10] = {
561 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
562 0x1f, 0x7c, 0xf0, 0xc1, 0x07
564 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
565 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
566 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
567 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
568 struct link_training_settings link_training_settings;
574 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
578 if (parse_write_buffer_into_params(wr_buf, size,
586 if (param_nums <= 0) {
588 DRM_DEBUG_DRIVER("user data not be read\n");
593 test_pattern = param[0];
595 switch (test_pattern) {
596 case DP_TEST_PATTERN_VIDEO_MODE:
597 case DP_TEST_PATTERN_COLOR_SQUARES:
598 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
599 case DP_TEST_PATTERN_VERTICAL_BARS:
600 case DP_TEST_PATTERN_HORIZONTAL_BARS:
601 case DP_TEST_PATTERN_COLOR_RAMP:
602 valid_test_pattern = true;
605 case DP_TEST_PATTERN_D102:
606 case DP_TEST_PATTERN_SYMBOL_ERROR:
607 case DP_TEST_PATTERN_PRBS7:
608 case DP_TEST_PATTERN_80BIT_CUSTOM:
609 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
610 case DP_TEST_PATTERN_TRAINING_PATTERN4:
612 valid_test_pattern = true;
616 valid_test_pattern = false;
617 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
621 if (!valid_test_pattern) {
623 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
627 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
628 for (i = 0; i < 10; i++) {
629 if ((uint8_t) param[i + 1] != 0x0)
634 /* not use default value */
635 for (i = 0; i < 10; i++)
636 custom_pattern[i] = (uint8_t) param[i + 1];
640 /* Usage: set DP physical test pattern using debugfs with normal DP
641 * panel. Then plug out DP panel and connect a scope to measure
642 * For normal video mode and test pattern generated from CRCT,
643 * they are visibile to user. So do not disable HPD.
644 * Video Mode is also set to clear the test pattern, so enable HPD
645 * because it might have been disabled after a test pattern was set.
646 * AUX depends on HPD * sequence dependent, do not move!
649 dc_link_enable_hpd(link);
651 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
652 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
653 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
655 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
656 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
657 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
659 link_training_settings.link_settings = cur_link_settings;
662 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
663 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
664 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
665 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
666 prefer_link_settings.link_rate != cur_link_settings.link_rate))
667 link_training_settings.link_settings = prefer_link_settings;
670 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
671 link_training_settings.lane_settings[i] = link->cur_lane_setting;
673 dc_link_set_test_pattern(
676 DP_TEST_PATTERN_COLOR_SPACE_RGB,
677 &link_training_settings,
681 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
682 * Then plug out DP panel and connect a scope to measure DP PHY signal.
683 * Need disable interrupt to avoid SW driver disable DP output. This is
684 * done after the test pattern is set.
686 if (valid_test_pattern && disable_hpd)
687 dc_link_disable_hpd(link);
695 * Returns the DMCUB tracebuffer contents.
696 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
698 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
700 struct amdgpu_device *adev = m->private;
701 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
702 struct dmub_debugfs_trace_entry *entries;
704 uint32_t tbuf_size, max_entries, num_entries, i;
709 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
713 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
714 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
715 sizeof(struct dmub_debugfs_trace_entry);
718 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
720 num_entries = min(num_entries, max_entries);
722 entries = (struct dmub_debugfs_trace_entry
724 sizeof(struct dmub_debugfs_trace_header));
726 for (i = 0; i < num_entries; ++i) {
727 struct dmub_debugfs_trace_entry *entry = &entries[i];
730 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
731 entry->trace_code, entry->tick_count, entry->param0,
739 * Returns the DMCUB firmware state contents.
740 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
742 static int dmub_fw_state_show(struct seq_file *m, void *data)
744 struct amdgpu_device *adev = m->private;
745 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
752 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
756 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
758 return seq_write(m, state_base, state_size);
762 * Returns the current and maximum output bpc for the connector.
763 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/output_bpc
765 static int output_bpc_show(struct seq_file *m, void *data)
767 struct drm_connector *connector = m->private;
768 struct drm_device *dev = connector->dev;
769 struct drm_crtc *crtc = NULL;
770 struct dm_crtc_state *dm_crtc_state = NULL;
774 mutex_lock(&dev->mode_config.mutex);
775 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
777 if (connector->state == NULL)
780 crtc = connector->state->crtc;
784 drm_modeset_lock(&crtc->mutex, NULL);
785 if (crtc->state == NULL)
788 dm_crtc_state = to_dm_crtc_state(crtc->state);
789 if (dm_crtc_state->stream == NULL)
792 switch (dm_crtc_state->stream->timing.display_color_depth) {
793 case COLOR_DEPTH_666:
796 case COLOR_DEPTH_888:
799 case COLOR_DEPTH_101010:
802 case COLOR_DEPTH_121212:
805 case COLOR_DEPTH_161616:
812 seq_printf(m, "Current: %u\n", bpc);
813 seq_printf(m, "Maximum: %u\n", connector->display_info.bpc);
818 drm_modeset_unlock(&crtc->mutex);
820 drm_modeset_unlock(&dev->mode_config.connection_mutex);
821 mutex_unlock(&dev->mode_config.mutex);
826 #ifdef CONFIG_DRM_AMD_DC_HDCP
828 * Returns the HDCP capability of the Display (1.4 for now).
830 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
831 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
833 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
834 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
836 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
838 struct drm_connector *connector = m->private;
839 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
840 bool hdcp_cap, hdcp2_cap;
842 if (connector->status != connector_status_connected)
845 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
847 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
848 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
852 seq_printf(m, "%s ", "HDCP1.4");
854 seq_printf(m, "%s ", "HDCP2.2");
856 if (!hdcp_cap && !hdcp2_cap)
857 seq_printf(m, "%s ", "None");
864 /* function description
866 * generic SDP message access for testing
868 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
871 * Hb0 : Secondary-Data Packet ID
872 * Hb1 : Secondary-Data Packet type
873 * Hb2 : Secondary-Data-packet-specific header, Byte 0
874 * Hb3 : Secondary-Data-packet-specific header, Byte 1
876 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
878 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
879 size_t size, loff_t *pos)
883 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
884 struct dm_crtc_state *acrtc_state;
885 uint32_t write_size = 36;
887 if (connector->base.status != connector_status_connected)
893 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
895 r = copy_from_user(data, buf, write_size);
899 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
904 static ssize_t dp_dpcd_address_write(struct file *f, const char __user *buf,
905 size_t size, loff_t *pos)
908 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
910 if (size < sizeof(connector->debugfs_dpcd_address))
913 r = copy_from_user(&connector->debugfs_dpcd_address,
914 buf, sizeof(connector->debugfs_dpcd_address));
919 static ssize_t dp_dpcd_size_write(struct file *f, const char __user *buf,
920 size_t size, loff_t *pos)
923 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
925 if (size < sizeof(connector->debugfs_dpcd_size))
928 r = copy_from_user(&connector->debugfs_dpcd_size,
929 buf, sizeof(connector->debugfs_dpcd_size));
931 if (connector->debugfs_dpcd_size > 256)
932 connector->debugfs_dpcd_size = 0;
937 static ssize_t dp_dpcd_data_write(struct file *f, const char __user *buf,
938 size_t size, loff_t *pos)
942 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
943 struct dc_link *link = connector->dc_link;
944 uint32_t write_size = connector->debugfs_dpcd_size;
946 if (!write_size || size < write_size)
949 data = kzalloc(write_size, GFP_KERNEL);
953 r = copy_from_user(data, buf, write_size);
955 dm_helpers_dp_write_dpcd(link->ctx, link,
956 connector->debugfs_dpcd_address, data, write_size - r);
958 return write_size - r;
961 static ssize_t dp_dpcd_data_read(struct file *f, char __user *buf,
962 size_t size, loff_t *pos)
966 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
967 struct dc_link *link = connector->dc_link;
968 uint32_t read_size = connector->debugfs_dpcd_size;
970 if (!read_size || size < read_size)
973 data = kzalloc(read_size, GFP_KERNEL);
977 dm_helpers_dp_read_dpcd(link->ctx, link,
978 connector->debugfs_dpcd_address, data, read_size);
980 r = copy_to_user(buf, data, read_size);
983 return read_size - r;
986 /* function: Read link's DSC & FEC capabilities
989 * Access it with the following command (you need to specify
990 * connector like DP-1):
992 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
995 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
997 struct drm_connector *connector = m->private;
998 struct drm_modeset_acquire_ctx ctx;
999 struct drm_device *dev = connector->dev;
1000 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1002 bool try_again = false;
1003 bool is_fec_supported = false;
1004 bool is_dsc_supported = false;
1005 struct dpcd_caps dpcd_caps;
1007 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1010 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1012 if (ret == -EDEADLK) {
1013 ret = drm_modeset_backoff(&ctx);
1021 if (connector->status != connector_status_connected) {
1025 dpcd_caps = aconnector->dc_link->dpcd_caps;
1026 if (aconnector->port) {
1027 /* aconnector sets dsc_aux during get_modes call
1028 * if MST connector has it means it can either
1029 * enable DSC on the sink device or on MST branch
1032 if (aconnector->dsc_aux) {
1033 is_fec_supported = true;
1034 is_dsc_supported = true;
1037 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1038 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1040 } while (try_again);
1042 drm_modeset_drop_locks(&ctx);
1043 drm_modeset_acquire_fini(&ctx);
1045 seq_printf(m, "FEC_Sink_Support: %s\n", yesno(is_fec_supported));
1046 seq_printf(m, "DSC_Sink_Support: %s\n", yesno(is_dsc_supported));
1051 /* function: Trigger virtual HPD redetection on connector
1053 * This function will perform link rediscovery, link disable
1054 * and enable, and dm connector state update.
1056 * Retrigger HPD on an existing connector by echoing 1 into
1057 * its respectful "trigger_hotplug" debugfs entry:
1059 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1061 * This function can perform HPD unplug:
1063 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1066 static ssize_t dp_trigger_hotplug(struct file *f, const char __user *buf,
1067 size_t size, loff_t *pos)
1069 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1070 struct drm_connector *connector = &aconnector->base;
1071 struct dc_link *link = NULL;
1072 struct drm_device *dev = connector->dev;
1073 enum dc_connection_type new_connection_type = dc_connection_none;
1074 char *wr_buf = NULL;
1075 uint32_t wr_buf_size = 42;
1076 int max_param_num = 1;
1077 long param[1] = {0};
1078 uint8_t param_nums = 0;
1080 if (!aconnector || !aconnector->dc_link)
1086 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1089 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1093 if (parse_write_buffer_into_params(wr_buf, size,
1101 if (param_nums <= 0) {
1102 DRM_DEBUG_DRIVER("user data not be read\n");
1107 if (param[0] == 1) {
1108 mutex_lock(&aconnector->hpd_lock);
1110 if (!dc_link_detect_sink(aconnector->dc_link, &new_connection_type) &&
1111 new_connection_type != dc_connection_none)
1114 if (!dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD))
1117 amdgpu_dm_update_connector_after_detect(aconnector);
1119 drm_modeset_lock_all(dev);
1120 dm_restore_drm_connector_state(dev, connector);
1121 drm_modeset_unlock_all(dev);
1123 drm_kms_helper_hotplug_event(dev);
1124 } else if (param[0] == 0) {
1125 if (!aconnector->dc_link)
1128 link = aconnector->dc_link;
1130 if (link->local_sink) {
1131 dc_sink_release(link->local_sink);
1132 link->local_sink = NULL;
1135 link->dpcd_sink_count = 0;
1136 link->type = dc_connection_none;
1137 link->dongle_max_pix_clk = 0;
1139 amdgpu_dm_update_connector_after_detect(aconnector);
1141 drm_modeset_lock_all(dev);
1142 dm_restore_drm_connector_state(dev, connector);
1143 drm_modeset_unlock_all(dev);
1145 drm_kms_helper_hotplug_event(dev);
1149 mutex_unlock(&aconnector->hpd_lock);
1155 /* function: read DSC status on the connector
1157 * The read function: dp_dsc_clock_en_read
1158 * returns current status of DSC clock on the connector.
1159 * The return is a boolean flag: 1 or 0.
1161 * Access it with the following command (you need to specify
1162 * connector like DP-1):
1164 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1167 * 1 - means that DSC is currently enabled
1168 * 0 - means that DSC is disabled
1170 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1171 size_t size, loff_t *pos)
1173 char *rd_buf = NULL;
1174 char *rd_buf_ptr = NULL;
1175 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1176 struct display_stream_compressor *dsc;
1177 struct dcn_dsc_state dsc_state = {0};
1178 const uint32_t rd_buf_size = 10;
1179 struct pipe_ctx *pipe_ctx;
1181 int i, r, str_len = 30;
1183 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1188 rd_buf_ptr = rd_buf;
1190 for (i = 0; i < MAX_PIPES; i++) {
1191 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1192 if (pipe_ctx && pipe_ctx->stream &&
1193 pipe_ctx->stream->link == aconnector->dc_link)
1200 dsc = pipe_ctx->stream_res.dsc;
1202 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1204 snprintf(rd_buf_ptr, str_len,
1206 dsc_state.dsc_clock_en);
1207 rd_buf_ptr += str_len;
1210 if (*pos >= rd_buf_size)
1213 r = put_user(*(rd_buf + result), buf);
1215 return r; /* r = -EFAULT */
1227 /* function: write force DSC on the connector
1229 * The write function: dp_dsc_clock_en_write
1230 * enables to force DSC on the connector.
1231 * User can write to either force enable or force disable DSC
1232 * on the next modeset or set it to driver default
1235 * 0 - default DSC enablement policy
1236 * 1 - force enable DSC on the connector
1237 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1239 * Writing DSC settings is done with the following command:
1240 * - To force enable DSC (you need to specify
1241 * connector like DP-1):
1243 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1245 * - To return to default state set the flag to zero and
1246 * let driver deal with DSC automatically
1247 * (you need to specify connector like DP-1):
1249 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1252 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1253 size_t size, loff_t *pos)
1255 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1256 struct pipe_ctx *pipe_ctx;
1258 char *wr_buf = NULL;
1259 uint32_t wr_buf_size = 42;
1260 int max_param_num = 1;
1261 long param[1] = {0};
1262 uint8_t param_nums = 0;
1267 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1270 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1274 if (parse_write_buffer_into_params(wr_buf, size,
1282 if (param_nums <= 0) {
1283 DRM_DEBUG_DRIVER("user data not be read\n");
1288 for (i = 0; i < MAX_PIPES; i++) {
1289 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1290 if (pipe_ctx && pipe_ctx->stream &&
1291 pipe_ctx->stream->link == aconnector->dc_link)
1295 if (!pipe_ctx || !pipe_ctx->stream)
1299 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1300 else if (param[0] == 2)
1301 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1303 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1310 /* function: read DSC slice width parameter on the connector
1312 * The read function: dp_dsc_slice_width_read
1313 * returns dsc slice width used in the current configuration
1314 * The return is an integer: 0 or other positive number
1316 * Access the status with the following command:
1318 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1320 * 0 - means that DSC is disabled
1322 * Any other number more than zero represents the
1323 * slice width currently used by DSC in pixels
1326 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1327 size_t size, loff_t *pos)
1329 char *rd_buf = NULL;
1330 char *rd_buf_ptr = NULL;
1331 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1332 struct display_stream_compressor *dsc;
1333 struct dcn_dsc_state dsc_state = {0};
1334 const uint32_t rd_buf_size = 100;
1335 struct pipe_ctx *pipe_ctx;
1337 int i, r, str_len = 30;
1339 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1344 rd_buf_ptr = rd_buf;
1346 for (i = 0; i < MAX_PIPES; i++) {
1347 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1348 if (pipe_ctx && pipe_ctx->stream &&
1349 pipe_ctx->stream->link == aconnector->dc_link)
1356 dsc = pipe_ctx->stream_res.dsc;
1358 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1360 snprintf(rd_buf_ptr, str_len,
1362 dsc_state.dsc_slice_width);
1363 rd_buf_ptr += str_len;
1366 if (*pos >= rd_buf_size)
1369 r = put_user(*(rd_buf + result), buf);
1371 return r; /* r = -EFAULT */
1383 /* function: write DSC slice width parameter
1385 * The write function: dp_dsc_slice_width_write
1386 * overwrites automatically generated DSC configuration
1389 * The user has to write the slice width divisible by the
1392 * Also the user has to write width in hexidecimal
1393 * rather than in decimal.
1395 * Writing DSC settings is done with the following command:
1396 * - To force overwrite slice width: (example sets to 1920 pixels)
1398 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1400 * - To stop overwriting and let driver find the optimal size,
1401 * set the width to zero:
1403 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1406 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1407 size_t size, loff_t *pos)
1409 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1410 struct pipe_ctx *pipe_ctx;
1412 char *wr_buf = NULL;
1413 uint32_t wr_buf_size = 42;
1414 int max_param_num = 1;
1415 long param[1] = {0};
1416 uint8_t param_nums = 0;
1421 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1424 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1428 if (parse_write_buffer_into_params(wr_buf, size,
1436 if (param_nums <= 0) {
1437 DRM_DEBUG_DRIVER("user data not be read\n");
1442 for (i = 0; i < MAX_PIPES; i++) {
1443 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1444 if (pipe_ctx && pipe_ctx->stream &&
1445 pipe_ctx->stream->link == aconnector->dc_link)
1449 if (!pipe_ctx || !pipe_ctx->stream)
1453 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1454 pipe_ctx->stream->timing.h_addressable,
1457 aconnector->dsc_settings.dsc_num_slices_h = 0;
1464 /* function: read DSC slice height parameter on the connector
1466 * The read function: dp_dsc_slice_height_read
1467 * returns dsc slice height used in the current configuration
1468 * The return is an integer: 0 or other positive number
1470 * Access the status with the following command:
1472 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1474 * 0 - means that DSC is disabled
1476 * Any other number more than zero represents the
1477 * slice height currently used by DSC in pixels
1480 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1481 size_t size, loff_t *pos)
1483 char *rd_buf = NULL;
1484 char *rd_buf_ptr = NULL;
1485 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1486 struct display_stream_compressor *dsc;
1487 struct dcn_dsc_state dsc_state = {0};
1488 const uint32_t rd_buf_size = 100;
1489 struct pipe_ctx *pipe_ctx;
1491 int i, r, str_len = 30;
1493 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1498 rd_buf_ptr = rd_buf;
1500 for (i = 0; i < MAX_PIPES; i++) {
1501 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1502 if (pipe_ctx && pipe_ctx->stream &&
1503 pipe_ctx->stream->link == aconnector->dc_link)
1510 dsc = pipe_ctx->stream_res.dsc;
1512 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1514 snprintf(rd_buf_ptr, str_len,
1516 dsc_state.dsc_slice_height);
1517 rd_buf_ptr += str_len;
1520 if (*pos >= rd_buf_size)
1523 r = put_user(*(rd_buf + result), buf);
1525 return r; /* r = -EFAULT */
1537 /* function: write DSC slice height parameter
1539 * The write function: dp_dsc_slice_height_write
1540 * overwrites automatically generated DSC configuration
1543 * The user has to write the slice height divisible by the
1546 * Also the user has to write height in hexidecimal
1547 * rather than in decimal.
1549 * Writing DSC settings is done with the following command:
1550 * - To force overwrite slice height (example sets to 128 pixels):
1552 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1554 * - To stop overwriting and let driver find the optimal size,
1555 * set the height to zero:
1557 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1560 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1561 size_t size, loff_t *pos)
1563 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1564 struct pipe_ctx *pipe_ctx;
1566 char *wr_buf = NULL;
1567 uint32_t wr_buf_size = 42;
1568 int max_param_num = 1;
1569 uint8_t param_nums = 0;
1570 long param[1] = {0};
1575 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1578 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1582 if (parse_write_buffer_into_params(wr_buf, size,
1590 if (param_nums <= 0) {
1591 DRM_DEBUG_DRIVER("user data not be read\n");
1596 for (i = 0; i < MAX_PIPES; i++) {
1597 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1598 if (pipe_ctx && pipe_ctx->stream &&
1599 pipe_ctx->stream->link == aconnector->dc_link)
1603 if (!pipe_ctx || !pipe_ctx->stream)
1607 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1608 pipe_ctx->stream->timing.v_addressable,
1611 aconnector->dsc_settings.dsc_num_slices_v = 0;
1618 /* function: read DSC target rate on the connector in bits per pixel
1620 * The read function: dp_dsc_bits_per_pixel_read
1621 * returns target rate of compression in bits per pixel
1622 * The return is an integer: 0 or other positive integer
1624 * Access it with the following command:
1626 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1628 * 0 - means that DSC is disabled
1630 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
1631 size_t size, loff_t *pos)
1633 char *rd_buf = NULL;
1634 char *rd_buf_ptr = NULL;
1635 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1636 struct display_stream_compressor *dsc;
1637 struct dcn_dsc_state dsc_state = {0};
1638 const uint32_t rd_buf_size = 100;
1639 struct pipe_ctx *pipe_ctx;
1641 int i, r, str_len = 30;
1643 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1648 rd_buf_ptr = rd_buf;
1650 for (i = 0; i < MAX_PIPES; i++) {
1651 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1652 if (pipe_ctx && pipe_ctx->stream &&
1653 pipe_ctx->stream->link == aconnector->dc_link)
1660 dsc = pipe_ctx->stream_res.dsc;
1662 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1664 snprintf(rd_buf_ptr, str_len,
1666 dsc_state.dsc_bits_per_pixel);
1667 rd_buf_ptr += str_len;
1670 if (*pos >= rd_buf_size)
1673 r = put_user(*(rd_buf + result), buf);
1675 return r; /* r = -EFAULT */
1687 /* function: write DSC target rate in bits per pixel
1689 * The write function: dp_dsc_bits_per_pixel_write
1690 * overwrites automatically generated DSC configuration
1691 * of DSC target bit rate.
1693 * Also the user has to write bpp in hexidecimal
1694 * rather than in decimal.
1696 * Writing DSC settings is done with the following command:
1697 * - To force overwrite rate (example sets to 256 bpp x 1/16):
1699 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1701 * - To stop overwriting and let driver find the optimal rate,
1702 * set the rate to zero:
1704 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1707 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
1708 size_t size, loff_t *pos)
1710 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1711 struct pipe_ctx *pipe_ctx;
1713 char *wr_buf = NULL;
1714 uint32_t wr_buf_size = 42;
1715 int max_param_num = 1;
1716 uint8_t param_nums = 0;
1717 long param[1] = {0};
1722 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1725 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1729 if (parse_write_buffer_into_params(wr_buf, size,
1737 if (param_nums <= 0) {
1738 DRM_DEBUG_DRIVER("user data not be read\n");
1743 for (i = 0; i < MAX_PIPES; i++) {
1744 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1745 if (pipe_ctx && pipe_ctx->stream &&
1746 pipe_ctx->stream->link == aconnector->dc_link)
1750 if (!pipe_ctx || !pipe_ctx->stream)
1753 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
1760 /* function: read DSC picture width parameter on the connector
1762 * The read function: dp_dsc_pic_width_read
1763 * returns dsc picture width used in the current configuration
1764 * It is the same as h_addressable of the current
1766 * The return is an integer: 0 or other positive integer
1767 * If 0 then DSC is disabled.
1769 * Access it with the following command:
1771 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
1773 * 0 - means that DSC is disabled
1775 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
1776 size_t size, loff_t *pos)
1778 char *rd_buf = NULL;
1779 char *rd_buf_ptr = NULL;
1780 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1781 struct display_stream_compressor *dsc;
1782 struct dcn_dsc_state dsc_state = {0};
1783 const uint32_t rd_buf_size = 100;
1784 struct pipe_ctx *pipe_ctx;
1786 int i, r, str_len = 30;
1788 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1793 rd_buf_ptr = rd_buf;
1795 for (i = 0; i < MAX_PIPES; i++) {
1796 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1797 if (pipe_ctx && pipe_ctx->stream &&
1798 pipe_ctx->stream->link == aconnector->dc_link)
1805 dsc = pipe_ctx->stream_res.dsc;
1807 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1809 snprintf(rd_buf_ptr, str_len,
1811 dsc_state.dsc_pic_width);
1812 rd_buf_ptr += str_len;
1815 if (*pos >= rd_buf_size)
1818 r = put_user(*(rd_buf + result), buf);
1820 return r; /* r = -EFAULT */
1832 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
1833 size_t size, loff_t *pos)
1835 char *rd_buf = NULL;
1836 char *rd_buf_ptr = NULL;
1837 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1838 struct display_stream_compressor *dsc;
1839 struct dcn_dsc_state dsc_state = {0};
1840 const uint32_t rd_buf_size = 100;
1841 struct pipe_ctx *pipe_ctx;
1843 int i, r, str_len = 30;
1845 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1850 rd_buf_ptr = rd_buf;
1852 for (i = 0; i < MAX_PIPES; i++) {
1853 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1854 if (pipe_ctx && pipe_ctx->stream &&
1855 pipe_ctx->stream->link == aconnector->dc_link)
1862 dsc = pipe_ctx->stream_res.dsc;
1864 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1866 snprintf(rd_buf_ptr, str_len,
1868 dsc_state.dsc_pic_height);
1869 rd_buf_ptr += str_len;
1872 if (*pos >= rd_buf_size)
1875 r = put_user(*(rd_buf + result), buf);
1877 return r; /* r = -EFAULT */
1889 /* function: read DSC chunk size parameter on the connector
1891 * The read function: dp_dsc_chunk_size_read
1892 * returns dsc chunk size set in the current configuration
1893 * The value is calculated automatically by DSC code
1894 * and depends on slice parameters and bpp target rate
1895 * The return is an integer: 0 or other positive integer
1896 * If 0 then DSC is disabled.
1898 * Access it with the following command:
1900 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
1902 * 0 - means that DSC is disabled
1904 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
1905 size_t size, loff_t *pos)
1907 char *rd_buf = NULL;
1908 char *rd_buf_ptr = NULL;
1909 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1910 struct display_stream_compressor *dsc;
1911 struct dcn_dsc_state dsc_state = {0};
1912 const uint32_t rd_buf_size = 100;
1913 struct pipe_ctx *pipe_ctx;
1915 int i, r, str_len = 30;
1917 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1922 rd_buf_ptr = rd_buf;
1924 for (i = 0; i < MAX_PIPES; i++) {
1925 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1926 if (pipe_ctx && pipe_ctx->stream &&
1927 pipe_ctx->stream->link == aconnector->dc_link)
1934 dsc = pipe_ctx->stream_res.dsc;
1936 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1938 snprintf(rd_buf_ptr, str_len,
1940 dsc_state.dsc_chunk_size);
1941 rd_buf_ptr += str_len;
1944 if (*pos >= rd_buf_size)
1947 r = put_user(*(rd_buf + result), buf);
1949 return r; /* r = -EFAULT */
1961 /* function: read DSC slice bpg offset on the connector
1963 * The read function: dp_dsc_slice_bpg_offset_read
1964 * returns dsc bpg slice offset set in the current configuration
1965 * The value is calculated automatically by DSC code
1966 * and depends on slice parameters and bpp target rate
1967 * The return is an integer: 0 or other positive integer
1968 * If 0 then DSC is disabled.
1970 * Access it with the following command:
1972 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
1974 * 0 - means that DSC is disabled
1976 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
1977 size_t size, loff_t *pos)
1979 char *rd_buf = NULL;
1980 char *rd_buf_ptr = NULL;
1981 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1982 struct display_stream_compressor *dsc;
1983 struct dcn_dsc_state dsc_state = {0};
1984 const uint32_t rd_buf_size = 100;
1985 struct pipe_ctx *pipe_ctx;
1987 int i, r, str_len = 30;
1989 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1994 rd_buf_ptr = rd_buf;
1996 for (i = 0; i < MAX_PIPES; i++) {
1997 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1998 if (pipe_ctx && pipe_ctx->stream &&
1999 pipe_ctx->stream->link == aconnector->dc_link)
2006 dsc = pipe_ctx->stream_res.dsc;
2008 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2010 snprintf(rd_buf_ptr, str_len,
2012 dsc_state.dsc_slice_bpg_offset);
2013 rd_buf_ptr += str_len;
2016 if (*pos >= rd_buf_size)
2019 r = put_user(*(rd_buf + result), buf);
2021 return r; /* r = -EFAULT */
2033 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2034 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2035 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2036 DEFINE_SHOW_ATTRIBUTE(output_bpc);
2037 #ifdef CONFIG_DRM_AMD_DC_HDCP
2038 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2041 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2042 .owner = THIS_MODULE,
2043 .read = dp_dsc_clock_en_read,
2044 .write = dp_dsc_clock_en_write,
2045 .llseek = default_llseek
2048 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2049 .owner = THIS_MODULE,
2050 .read = dp_dsc_slice_width_read,
2051 .write = dp_dsc_slice_width_write,
2052 .llseek = default_llseek
2055 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2056 .owner = THIS_MODULE,
2057 .read = dp_dsc_slice_height_read,
2058 .write = dp_dsc_slice_height_write,
2059 .llseek = default_llseek
2062 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2063 .owner = THIS_MODULE,
2064 .read = dp_dsc_bits_per_pixel_read,
2065 .write = dp_dsc_bits_per_pixel_write,
2066 .llseek = default_llseek
2069 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2070 .owner = THIS_MODULE,
2071 .read = dp_dsc_pic_width_read,
2072 .llseek = default_llseek
2075 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2076 .owner = THIS_MODULE,
2077 .read = dp_dsc_pic_height_read,
2078 .llseek = default_llseek
2081 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2082 .owner = THIS_MODULE,
2083 .read = dp_dsc_chunk_size_read,
2084 .llseek = default_llseek
2087 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2088 .owner = THIS_MODULE,
2089 .read = dp_dsc_slice_bpg_offset_read,
2090 .llseek = default_llseek
2093 static const struct file_operations dp_trigger_hotplug_debugfs_fops = {
2094 .owner = THIS_MODULE,
2095 .write = dp_trigger_hotplug,
2096 .llseek = default_llseek
2099 static const struct file_operations dp_link_settings_debugfs_fops = {
2100 .owner = THIS_MODULE,
2101 .read = dp_link_settings_read,
2102 .write = dp_link_settings_write,
2103 .llseek = default_llseek
2106 static const struct file_operations dp_phy_settings_debugfs_fop = {
2107 .owner = THIS_MODULE,
2108 .read = dp_phy_settings_read,
2109 .write = dp_phy_settings_write,
2110 .llseek = default_llseek
2113 static const struct file_operations dp_phy_test_pattern_fops = {
2114 .owner = THIS_MODULE,
2115 .write = dp_phy_test_pattern_debugfs_write,
2116 .llseek = default_llseek
2119 static const struct file_operations sdp_message_fops = {
2120 .owner = THIS_MODULE,
2121 .write = dp_sdp_message_debugfs_write,
2122 .llseek = default_llseek
2125 static const struct file_operations dp_dpcd_address_debugfs_fops = {
2126 .owner = THIS_MODULE,
2127 .write = dp_dpcd_address_write,
2128 .llseek = default_llseek
2131 static const struct file_operations dp_dpcd_size_debugfs_fops = {
2132 .owner = THIS_MODULE,
2133 .write = dp_dpcd_size_write,
2134 .llseek = default_llseek
2137 static const struct file_operations dp_dpcd_data_debugfs_fops = {
2138 .owner = THIS_MODULE,
2139 .read = dp_dpcd_data_read,
2140 .write = dp_dpcd_data_write,
2141 .llseek = default_llseek
2144 static const struct {
2146 const struct file_operations *fops;
2147 } dp_debugfs_entries[] = {
2148 {"link_settings", &dp_link_settings_debugfs_fops},
2149 {"trigger_hotplug", &dp_trigger_hotplug_debugfs_fops},
2150 {"phy_settings", &dp_phy_settings_debugfs_fop},
2151 {"test_pattern", &dp_phy_test_pattern_fops},
2152 #ifdef CONFIG_DRM_AMD_DC_HDCP
2153 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2155 {"sdp_message", &sdp_message_fops},
2156 {"aux_dpcd_address", &dp_dpcd_address_debugfs_fops},
2157 {"aux_dpcd_size", &dp_dpcd_size_debugfs_fops},
2158 {"aux_dpcd_data", &dp_dpcd_data_debugfs_fops},
2159 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2160 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2161 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2162 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2163 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2164 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2165 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2166 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2167 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops}
2170 #ifdef CONFIG_DRM_AMD_DC_HDCP
2171 static const struct {
2173 const struct file_operations *fops;
2174 } hdmi_debugfs_entries[] = {
2175 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
2179 * Force YUV420 output if available from the given mode
2181 static int force_yuv420_output_set(void *data, u64 val)
2183 struct amdgpu_dm_connector *connector = data;
2185 connector->force_yuv420_output = (bool)val;
2191 * Check if YUV420 is forced when available from the given mode
2193 static int force_yuv420_output_get(void *data, u64 *val)
2195 struct amdgpu_dm_connector *connector = data;
2197 *val = connector->force_yuv420_output;
2202 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2203 force_yuv420_output_set, "%llu\n");
2208 static int psr_get(void *data, u64 *val)
2210 struct amdgpu_dm_connector *connector = data;
2211 struct dc_link *link = connector->dc_link;
2212 uint32_t psr_state = 0;
2214 dc_link_get_psr_state(link, &psr_state);
2222 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
2224 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
2227 struct dentry *dir = connector->base.debugfs_entry;
2229 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
2230 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2231 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
2232 debugfs_create_file(dp_debugfs_entries[i].name,
2233 0644, dir, connector,
2234 dp_debugfs_entries[i].fops);
2237 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
2238 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
2240 debugfs_create_file_unsafe("force_yuv420_output", 0644, dir, connector,
2241 &force_yuv420_output_fops);
2243 debugfs_create_file("output_bpc", 0644, dir, connector,
2246 connector->debugfs_dpcd_address = 0;
2247 connector->debugfs_dpcd_size = 0;
2249 #ifdef CONFIG_DRM_AMD_DC_HDCP
2250 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
2251 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
2252 debugfs_create_file(hdmi_debugfs_entries[i].name,
2253 0644, dir, connector,
2254 hdmi_debugfs_entries[i].fops);
2261 * Writes DTN log state to the user supplied buffer.
2262 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
2264 static ssize_t dtn_log_read(
2270 struct amdgpu_device *adev = file_inode(f)->i_private;
2271 struct dc *dc = adev->dm.dc;
2272 struct dc_log_buffer_ctx log_ctx = { 0 };
2278 if (!dc->hwss.log_hw_state)
2281 dc->hwss.log_hw_state(dc, &log_ctx);
2283 if (*pos < log_ctx.pos) {
2284 size_t to_copy = log_ctx.pos - *pos;
2286 to_copy = min(to_copy, size);
2288 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
2300 * Writes DTN log state to dmesg when triggered via a write.
2301 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
2303 static ssize_t dtn_log_write(
2305 const char __user *buf,
2309 struct amdgpu_device *adev = file_inode(f)->i_private;
2310 struct dc *dc = adev->dm.dc;
2312 /* Write triggers log output via dmesg. */
2316 if (dc->hwss.log_hw_state)
2317 dc->hwss.log_hw_state(dc, NULL);
2323 * Backlight at this moment. Read only.
2324 * As written to display, taking ABM and backlight lut into account.
2325 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2327 static int current_backlight_read(struct seq_file *m, void *data)
2329 struct drm_info_node *node = (struct drm_info_node *)m->private;
2330 struct drm_device *dev = node->minor->dev;
2331 struct amdgpu_device *adev = drm_to_adev(dev);
2332 struct amdgpu_display_manager *dm = &adev->dm;
2334 unsigned int backlight = dc_link_get_backlight_level(dm->backlight_link);
2336 seq_printf(m, "0x%x\n", backlight);
2341 * Backlight value that is being approached. Read only.
2342 * As written to display, taking ABM and backlight lut into account.
2343 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2345 static int target_backlight_read(struct seq_file *m, void *data)
2347 struct drm_info_node *node = (struct drm_info_node *)m->private;
2348 struct drm_device *dev = node->minor->dev;
2349 struct amdgpu_device *adev = drm_to_adev(dev);
2350 struct amdgpu_display_manager *dm = &adev->dm;
2352 unsigned int backlight = dc_link_get_target_backlight_pwm(dm->backlight_link);
2354 seq_printf(m, "0x%x\n", backlight);
2358 static int mst_topo(struct seq_file *m, void *unused)
2360 struct drm_info_node *node = (struct drm_info_node *)m->private;
2361 struct drm_device *dev = node->minor->dev;
2362 struct drm_connector *connector;
2363 struct drm_connector_list_iter conn_iter;
2364 struct amdgpu_dm_connector *aconnector;
2366 drm_connector_list_iter_begin(dev, &conn_iter);
2367 drm_for_each_connector_iter(connector, &conn_iter) {
2368 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2371 aconnector = to_amdgpu_dm_connector(connector);
2373 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
2374 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
2376 drm_connector_list_iter_end(&conn_iter);
2381 static const struct drm_info_list amdgpu_dm_debugfs_list[] = {
2382 {"amdgpu_current_backlight_pwm", ¤t_backlight_read},
2383 {"amdgpu_target_backlight_pwm", &target_backlight_read},
2384 {"amdgpu_mst_topology", &mst_topo},
2388 * Sets the force_timing_sync debug optino from the given string.
2389 * All connected displays will be force synchronized immediately.
2390 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
2392 static int force_timing_sync_set(void *data, u64 val)
2394 struct amdgpu_device *adev = data;
2396 adev->dm.force_timing_sync = (bool)val;
2398 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
2404 * Gets the force_timing_sync debug option value into the given buffer.
2405 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
2407 static int force_timing_sync_get(void *data, u64 *val)
2409 struct amdgpu_device *adev = data;
2411 *val = adev->dm.force_timing_sync;
2416 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
2417 force_timing_sync_set, "%llu\n");
2420 * Sets the DC visual confirm debug option from the given string.
2421 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
2423 static int visual_confirm_set(void *data, u64 val)
2425 struct amdgpu_device *adev = data;
2427 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
2433 * Reads the DC visual confirm debug option value into the given buffer.
2434 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
2436 static int visual_confirm_get(void *data, u64 *val)
2438 struct amdgpu_device *adev = data;
2440 *val = adev->dm.dc->debug.visual_confirm;
2445 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
2446 visual_confirm_set, "%llu\n");
2448 int dtn_debugfs_init(struct amdgpu_device *adev)
2450 static const struct file_operations dtn_log_fops = {
2451 .owner = THIS_MODULE,
2452 .read = dtn_log_read,
2453 .write = dtn_log_write,
2454 .llseek = default_llseek
2457 struct drm_minor *minor = adev_to_drm(adev)->primary;
2458 struct dentry *root = minor->debugfs_root;
2461 ret = amdgpu_debugfs_add_files(adev, amdgpu_dm_debugfs_list,
2462 ARRAY_SIZE(amdgpu_dm_debugfs_list));
2466 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
2469 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
2470 &visual_confirm_fops);
2472 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
2473 adev, &dmub_tracebuffer_fops);
2475 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
2476 adev, &dmub_fw_state_fops);
2478 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
2479 adev, &force_timing_sync_ops);