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 "dc/dc_dmub_srv.h"
39 struct dmub_debugfs_trace_header {
44 struct dmub_debugfs_trace_entry {
51 static inline const char *yesno(bool v)
53 return v ? "yes" : "no";
56 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
58 * Function takes in attributes passed to debugfs write entry
59 * and writes into param array.
60 * The user passes max_param_num to identify maximum number of
61 * parameters that could be parsed.
64 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
65 long *param, const char __user *buf,
69 char *wr_buf_ptr = NULL;
70 uint32_t wr_buf_count = 0;
73 const char delimiter[3] = {' ', '\n', '\0'};
74 uint8_t param_index = 0;
80 r = copy_from_user(wr_buf_ptr, buf, wr_buf_size);
82 /* r is bytes not be copied */
83 if (r >= wr_buf_size) {
84 DRM_DEBUG_DRIVER("user data not be read\n");
88 /* check number of parameters. isspace could not differ space and \n */
89 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
91 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
96 if (wr_buf_count == wr_buf_size)
100 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
107 if (wr_buf_count == wr_buf_size)
111 if (*param_nums > max_param_num)
112 *param_nums = max_param_num;
114 wr_buf_ptr = wr_buf; /* reset buf pointer */
115 wr_buf_count = 0; /* number of char already checked */
117 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
122 while (param_index < *param_nums) {
123 /* after strsep, wr_buf_ptr will be moved to after space */
124 sub_str = strsep(&wr_buf_ptr, delimiter);
126 r = kstrtol(sub_str, 16, &(param[param_index]));
129 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
137 /* function description
138 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
140 * valid lane count value: 1, 2, 4
141 * valid link rate value:
142 * 06h = 1.62Gbps per lane
143 * 0Ah = 2.7Gbps per lane
144 * 0Ch = 3.24Gbps per lane
145 * 14h = 5.4Gbps per lane
146 * 1Eh = 8.1Gbps per lane
148 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
150 * --- to get dp configuration
154 * It will list current, verified, reported, preferred dp configuration.
155 * current -- for current video mode
156 * verified --- maximum configuration which pass link training
157 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
158 * preferred --- user force settings
160 * --- set (or force) dp configuration
162 * echo <lane_count> <link_rate> > link_settings
164 * for example, to force to 2 lane, 2.7GHz,
165 * echo 4 0xa > link_settings
167 * spread_spectrum could not be changed dynamically.
169 * in case invalid lane count, link rate are force, no hw programming will be
170 * done. please check link settings after force operation to see if HW get
175 * check current and preferred settings.
178 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
179 size_t size, loff_t *pos)
181 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
182 struct dc_link *link = connector->dc_link;
184 char *rd_buf_ptr = NULL;
185 const uint32_t rd_buf_size = 100;
190 if (*pos & 3 || size & 3)
193 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
199 str_len = strlen("Current: %d %d %d ");
200 snprintf(rd_buf_ptr, str_len, "Current: %d %d %d ",
201 link->cur_link_settings.lane_count,
202 link->cur_link_settings.link_rate,
203 link->cur_link_settings.link_spread);
204 rd_buf_ptr += str_len;
206 str_len = strlen("Verified: %d %d %d ");
207 snprintf(rd_buf_ptr, str_len, "Verified: %d %d %d ",
208 link->verified_link_cap.lane_count,
209 link->verified_link_cap.link_rate,
210 link->verified_link_cap.link_spread);
211 rd_buf_ptr += str_len;
213 str_len = strlen("Reported: %d %d %d ");
214 snprintf(rd_buf_ptr, str_len, "Reported: %d %d %d ",
215 link->reported_link_cap.lane_count,
216 link->reported_link_cap.link_rate,
217 link->reported_link_cap.link_spread);
218 rd_buf_ptr += str_len;
220 str_len = strlen("Preferred: %d %d %d ");
221 snprintf(rd_buf_ptr, str_len, "Preferred: %d %d %d\n",
222 link->preferred_link_setting.lane_count,
223 link->preferred_link_setting.link_rate,
224 link->preferred_link_setting.link_spread);
227 if (*pos >= rd_buf_size)
230 r = put_user(*(rd_buf + result), buf);
232 return r; /* r = -EFAULT */
244 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
245 size_t size, loff_t *pos)
247 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
248 struct dc_link *link = connector->dc_link;
249 struct dc *dc = (struct dc *)link->dc;
250 struct dc_link_settings prefer_link_settings;
252 const uint32_t wr_buf_size = 40;
253 /* 0: lane_count; 1: link_rate */
254 int max_param_num = 2;
255 uint8_t param_nums = 0;
257 bool valid_input = false;
262 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
266 if (parse_write_buffer_into_params(wr_buf, size,
274 if (param_nums <= 0) {
276 DRM_DEBUG_DRIVER("user data not be read\n");
283 case LANE_COUNT_FOUR:
294 case LINK_RATE_HIGH2:
295 case LINK_RATE_HIGH3:
304 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
308 /* save user force lane_count, link_rate to preferred settings
309 * spread spectrum will not be changed
311 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
312 prefer_link_settings.lane_count = param[0];
313 prefer_link_settings.link_rate = param[1];
315 dc_link_set_preferred_link_settings(dc, &prefer_link_settings, link);
321 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
322 * post-cursor2 (defined by VESA DP specification)
325 * voltage swing: 0,1,2,3
326 * pre-emphasis : 0,1,2,3
327 * post cursor2 : 0,1,2,3
330 * how to use this debugfs
332 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
334 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
336 * To figure out which DP-x is the display for DP to be check,
339 * There should be debugfs file, like link_settings, phy_settings.
341 * from lane_count, link_rate to figure which DP-x is for display to be worked
344 * To get current DP PHY settings,
347 * To change DP PHY settings,
348 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
349 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
351 * echo 2 3 0 > phy_settings
353 * To check if change be applied, get current phy settings by
356 * In case invalid values are set by user, like
357 * echo 1 4 0 > phy_settings
359 * HW will NOT be programmed by these settings.
360 * cat phy_settings will show the previous valid settings.
362 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
363 size_t size, loff_t *pos)
365 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
366 struct dc_link *link = connector->dc_link;
368 const uint32_t rd_buf_size = 20;
372 if (*pos & 3 || size & 3)
375 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
379 snprintf(rd_buf, rd_buf_size, " %d %d %d ",
380 link->cur_lane_setting.VOLTAGE_SWING,
381 link->cur_lane_setting.PRE_EMPHASIS,
382 link->cur_lane_setting.POST_CURSOR2);
385 if (*pos >= rd_buf_size)
388 r = put_user((*(rd_buf + result)), buf);
390 return r; /* r = -EFAULT */
402 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
403 size_t size, loff_t *pos)
405 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
406 struct dc_link *link = connector->dc_link;
407 struct dc *dc = (struct dc *)link->dc;
409 uint32_t wr_buf_size = 40;
411 bool use_prefer_link_setting;
412 struct link_training_settings link_lane_settings;
413 int max_param_num = 3;
414 uint8_t param_nums = 0;
421 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
425 if (parse_write_buffer_into_params(wr_buf, size,
433 if (param_nums <= 0) {
435 DRM_DEBUG_DRIVER("user data not be read\n");
439 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
440 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
441 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
443 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
447 /* get link settings: lane count, link rate */
448 use_prefer_link_setting =
449 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
450 (link->test_pattern_enabled));
452 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
454 if (use_prefer_link_setting) {
455 link_lane_settings.link_settings.lane_count =
456 link->preferred_link_setting.lane_count;
457 link_lane_settings.link_settings.link_rate =
458 link->preferred_link_setting.link_rate;
459 link_lane_settings.link_settings.link_spread =
460 link->preferred_link_setting.link_spread;
462 link_lane_settings.link_settings.lane_count =
463 link->cur_link_settings.lane_count;
464 link_lane_settings.link_settings.link_rate =
465 link->cur_link_settings.link_rate;
466 link_lane_settings.link_settings.link_spread =
467 link->cur_link_settings.link_spread;
470 /* apply phy settings from user */
471 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
472 link_lane_settings.lane_settings[r].VOLTAGE_SWING =
473 (enum dc_voltage_swing) (param[0]);
474 link_lane_settings.lane_settings[r].PRE_EMPHASIS =
475 (enum dc_pre_emphasis) (param[1]);
476 link_lane_settings.lane_settings[r].POST_CURSOR2 =
477 (enum dc_post_cursor2) (param[2]);
480 /* program ASIC registers and DPCD registers */
481 dc_link_set_drive_settings(dc, &link_lane_settings, link);
487 /* function description
489 * set PHY layer or Link layer test pattern
490 * PHY test pattern is used for PHY SI check.
491 * Link layer test will not affect PHY SI.
493 * Reset Test Pattern:
494 * 0 = DP_TEST_PATTERN_VIDEO_MODE
496 * PHY test pattern supported:
497 * 1 = DP_TEST_PATTERN_D102
498 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
499 * 3 = DP_TEST_PATTERN_PRBS7
500 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
501 * 5 = DP_TEST_PATTERN_CP2520_1
502 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
503 * 7 = DP_TEST_PATTERN_CP2520_3
505 * DP PHY Link Training Patterns
506 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
507 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
508 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
509 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
511 * DP Link Layer Test pattern
512 * c = DP_TEST_PATTERN_COLOR_SQUARES
513 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
514 * e = DP_TEST_PATTERN_VERTICAL_BARS
515 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
516 * 10= DP_TEST_PATTERN_COLOR_RAMP
518 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
520 * --- set test pattern
521 * echo <test pattern #> > test_pattern
523 * If test pattern # is not supported, NO HW programming will be done.
524 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
525 * for the user pattern. input 10 bytes data are separated by space
527 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
529 * --- reset test pattern
530 * echo 0 > test_pattern
532 * --- HPD detection is disabled when set PHY test pattern
534 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
535 * is disable. User could unplug DP display from DP connected and plug scope to
536 * check test pattern PHY SI.
537 * If there is need unplug scope and plug DP display back, do steps below:
538 * echo 0 > phy_test_pattern
542 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
543 * driver could detect "unplug scope" and "plug DP display"
545 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
546 size_t size, loff_t *pos)
548 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
549 struct dc_link *link = connector->dc_link;
551 uint32_t wr_buf_size = 100;
552 long param[11] = {0x0};
553 int max_param_num = 11;
554 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
555 bool disable_hpd = false;
556 bool valid_test_pattern = false;
557 uint8_t param_nums = 0;
558 /* init with default 80bit custom pattern */
559 uint8_t custom_pattern[10] = {
560 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
561 0x1f, 0x7c, 0xf0, 0xc1, 0x07
563 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
564 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
565 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
566 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
567 struct link_training_settings link_training_settings;
573 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
577 if (parse_write_buffer_into_params(wr_buf, size,
585 if (param_nums <= 0) {
587 DRM_DEBUG_DRIVER("user data not be read\n");
592 test_pattern = param[0];
594 switch (test_pattern) {
595 case DP_TEST_PATTERN_VIDEO_MODE:
596 case DP_TEST_PATTERN_COLOR_SQUARES:
597 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
598 case DP_TEST_PATTERN_VERTICAL_BARS:
599 case DP_TEST_PATTERN_HORIZONTAL_BARS:
600 case DP_TEST_PATTERN_COLOR_RAMP:
601 valid_test_pattern = true;
604 case DP_TEST_PATTERN_D102:
605 case DP_TEST_PATTERN_SYMBOL_ERROR:
606 case DP_TEST_PATTERN_PRBS7:
607 case DP_TEST_PATTERN_80BIT_CUSTOM:
608 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
609 case DP_TEST_PATTERN_TRAINING_PATTERN4:
611 valid_test_pattern = true;
615 valid_test_pattern = false;
616 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
620 if (!valid_test_pattern) {
622 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
626 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
627 for (i = 0; i < 10; i++) {
628 if ((uint8_t) param[i + 1] != 0x0)
633 /* not use default value */
634 for (i = 0; i < 10; i++)
635 custom_pattern[i] = (uint8_t) param[i + 1];
639 /* Usage: set DP physical test pattern using debugfs with normal DP
640 * panel. Then plug out DP panel and connect a scope to measure
641 * For normal video mode and test pattern generated from CRCT,
642 * they are visibile to user. So do not disable HPD.
643 * Video Mode is also set to clear the test pattern, so enable HPD
644 * because it might have been disabled after a test pattern was set.
645 * AUX depends on HPD * sequence dependent, do not move!
648 dc_link_enable_hpd(link);
650 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
651 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
652 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
654 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
655 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
656 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
658 link_training_settings.link_settings = cur_link_settings;
661 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
662 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
663 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
664 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
665 prefer_link_settings.link_rate != cur_link_settings.link_rate))
666 link_training_settings.link_settings = prefer_link_settings;
669 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
670 link_training_settings.lane_settings[i] = link->cur_lane_setting;
672 dc_link_set_test_pattern(
675 DP_TEST_PATTERN_COLOR_SPACE_RGB,
676 &link_training_settings,
680 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
681 * Then plug out DP panel and connect a scope to measure DP PHY signal.
682 * Need disable interrupt to avoid SW driver disable DP output. This is
683 * done after the test pattern is set.
685 if (valid_test_pattern && disable_hpd)
686 dc_link_disable_hpd(link);
694 * Returns the DMCUB tracebuffer contents.
695 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
697 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
699 struct amdgpu_device *adev = m->private;
700 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
701 struct dmub_debugfs_trace_entry *entries;
703 uint32_t tbuf_size, max_entries, num_entries, i;
708 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
712 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
713 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
714 sizeof(struct dmub_debugfs_trace_entry);
717 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
719 num_entries = min(num_entries, max_entries);
721 entries = (struct dmub_debugfs_trace_entry
723 sizeof(struct dmub_debugfs_trace_header));
725 for (i = 0; i < num_entries; ++i) {
726 struct dmub_debugfs_trace_entry *entry = &entries[i];
729 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
730 entry->trace_code, entry->tick_count, entry->param0,
738 * Returns the DMCUB firmware state contents.
739 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
741 static int dmub_fw_state_show(struct seq_file *m, void *data)
743 struct amdgpu_device *adev = m->private;
744 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
751 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
755 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
757 return seq_write(m, state_base, state_size);
761 * Returns the current and maximum output bpc for the connector.
762 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/output_bpc
764 static int output_bpc_show(struct seq_file *m, void *data)
766 struct drm_connector *connector = m->private;
767 struct drm_device *dev = connector->dev;
768 struct drm_crtc *crtc = NULL;
769 struct dm_crtc_state *dm_crtc_state = NULL;
773 mutex_lock(&dev->mode_config.mutex);
774 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
776 if (connector->state == NULL)
779 crtc = connector->state->crtc;
783 drm_modeset_lock(&crtc->mutex, NULL);
784 if (crtc->state == NULL)
787 dm_crtc_state = to_dm_crtc_state(crtc->state);
788 if (dm_crtc_state->stream == NULL)
791 switch (dm_crtc_state->stream->timing.display_color_depth) {
792 case COLOR_DEPTH_666:
795 case COLOR_DEPTH_888:
798 case COLOR_DEPTH_101010:
801 case COLOR_DEPTH_121212:
804 case COLOR_DEPTH_161616:
811 seq_printf(m, "Current: %u\n", bpc);
812 seq_printf(m, "Maximum: %u\n", connector->display_info.bpc);
817 drm_modeset_unlock(&crtc->mutex);
819 drm_modeset_unlock(&dev->mode_config.connection_mutex);
820 mutex_unlock(&dev->mode_config.mutex);
825 #ifdef CONFIG_DRM_AMD_DC_HDCP
827 * Returns the HDCP capability of the Display (1.4 for now).
829 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
830 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
832 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
833 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
835 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
837 struct drm_connector *connector = m->private;
838 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
839 bool hdcp_cap, hdcp2_cap;
841 if (connector->status != connector_status_connected)
844 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
846 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
847 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
851 seq_printf(m, "%s ", "HDCP1.4");
853 seq_printf(m, "%s ", "HDCP2.2");
855 if (!hdcp_cap && !hdcp2_cap)
856 seq_printf(m, "%s ", "None");
863 /* function description
865 * generic SDP message access for testing
867 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
870 * Hb0 : Secondary-Data Packet ID
871 * Hb1 : Secondary-Data Packet type
872 * Hb2 : Secondary-Data-packet-specific header, Byte 0
873 * Hb3 : Secondary-Data-packet-specific header, Byte 1
875 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
877 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
878 size_t size, loff_t *pos)
882 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
883 struct dm_crtc_state *acrtc_state;
884 uint32_t write_size = 36;
886 if (connector->base.status != connector_status_connected)
892 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
894 r = copy_from_user(data, buf, write_size);
898 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
903 static ssize_t dp_dpcd_address_write(struct file *f, const char __user *buf,
904 size_t size, loff_t *pos)
907 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
909 if (size < sizeof(connector->debugfs_dpcd_address))
912 r = copy_from_user(&connector->debugfs_dpcd_address,
913 buf, sizeof(connector->debugfs_dpcd_address));
918 static ssize_t dp_dpcd_size_write(struct file *f, const char __user *buf,
919 size_t size, loff_t *pos)
922 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
924 if (size < sizeof(connector->debugfs_dpcd_size))
927 r = copy_from_user(&connector->debugfs_dpcd_size,
928 buf, sizeof(connector->debugfs_dpcd_size));
930 if (connector->debugfs_dpcd_size > 256)
931 connector->debugfs_dpcd_size = 0;
936 static ssize_t dp_dpcd_data_write(struct file *f, const char __user *buf,
937 size_t size, loff_t *pos)
941 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
942 struct dc_link *link = connector->dc_link;
943 uint32_t write_size = connector->debugfs_dpcd_size;
945 if (!write_size || size < write_size)
948 data = kzalloc(write_size, GFP_KERNEL);
952 r = copy_from_user(data, buf, write_size);
954 dm_helpers_dp_write_dpcd(link->ctx, link,
955 connector->debugfs_dpcd_address, data, write_size - r);
957 return write_size - r;
960 static ssize_t dp_dpcd_data_read(struct file *f, char __user *buf,
961 size_t size, loff_t *pos)
965 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
966 struct dc_link *link = connector->dc_link;
967 uint32_t read_size = connector->debugfs_dpcd_size;
969 if (!read_size || size < read_size)
972 data = kzalloc(read_size, GFP_KERNEL);
976 dm_helpers_dp_read_dpcd(link->ctx, link,
977 connector->debugfs_dpcd_address, data, read_size);
979 r = copy_to_user(buf, data, read_size);
982 return read_size - r;
985 /* function: Read link's DSC & FEC capabilities
988 * Access it with the following command (you need to specify
989 * connector like DP-1):
991 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
994 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
996 struct drm_connector *connector = m->private;
997 struct drm_modeset_acquire_ctx ctx;
998 struct drm_device *dev = connector->dev;
999 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1001 bool try_again = false;
1002 bool is_fec_supported = false;
1003 bool is_dsc_supported = false;
1004 struct dpcd_caps dpcd_caps;
1006 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1009 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1011 if (ret == -EDEADLK) {
1012 ret = drm_modeset_backoff(&ctx);
1020 if (connector->status != connector_status_connected) {
1024 dpcd_caps = aconnector->dc_link->dpcd_caps;
1025 if (aconnector->port) {
1026 /* aconnector sets dsc_aux during get_modes call
1027 * if MST connector has it means it can either
1028 * enable DSC on the sink device or on MST branch
1031 if (aconnector->dsc_aux) {
1032 is_fec_supported = true;
1033 is_dsc_supported = true;
1036 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1037 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1039 } while (try_again);
1041 drm_modeset_drop_locks(&ctx);
1042 drm_modeset_acquire_fini(&ctx);
1044 seq_printf(m, "FEC_Sink_Support: %s\n", yesno(is_fec_supported));
1045 seq_printf(m, "DSC_Sink_Support: %s\n", yesno(is_dsc_supported));
1050 /* function: Trigger virtual HPD redetection on connector
1052 * This function will perform link rediscovery, link disable
1053 * and enable, and dm connector state update.
1055 * Retrigger HPD on an existing connector by echoing 1 into
1056 * its respectful "trigger_hotplug" debugfs entry:
1058 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1060 * This function can perform HPD unplug:
1062 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1065 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1066 size_t size, loff_t *pos)
1068 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1069 struct drm_connector *connector = &aconnector->base;
1070 struct dc_link *link = NULL;
1071 struct drm_device *dev = connector->dev;
1072 enum dc_connection_type new_connection_type = dc_connection_none;
1073 char *wr_buf = NULL;
1074 uint32_t wr_buf_size = 42;
1075 int max_param_num = 1;
1076 long param[1] = {0};
1077 uint8_t param_nums = 0;
1079 if (!aconnector || !aconnector->dc_link)
1085 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1088 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1092 if (parse_write_buffer_into_params(wr_buf, size,
1100 if (param_nums <= 0) {
1101 DRM_DEBUG_DRIVER("user data not be read\n");
1106 if (param[0] == 1) {
1107 mutex_lock(&aconnector->hpd_lock);
1109 if (!dc_link_detect_sink(aconnector->dc_link, &new_connection_type) &&
1110 new_connection_type != dc_connection_none)
1113 if (!dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD))
1116 amdgpu_dm_update_connector_after_detect(aconnector);
1118 drm_modeset_lock_all(dev);
1119 dm_restore_drm_connector_state(dev, connector);
1120 drm_modeset_unlock_all(dev);
1122 drm_kms_helper_hotplug_event(dev);
1123 } else if (param[0] == 0) {
1124 if (!aconnector->dc_link)
1127 link = aconnector->dc_link;
1129 if (link->local_sink) {
1130 dc_sink_release(link->local_sink);
1131 link->local_sink = NULL;
1134 link->dpcd_sink_count = 0;
1135 link->type = dc_connection_none;
1136 link->dongle_max_pix_clk = 0;
1138 amdgpu_dm_update_connector_after_detect(aconnector);
1140 drm_modeset_lock_all(dev);
1141 dm_restore_drm_connector_state(dev, connector);
1142 drm_modeset_unlock_all(dev);
1144 drm_kms_helper_hotplug_event(dev);
1148 mutex_unlock(&aconnector->hpd_lock);
1154 /* function: read DSC status on the connector
1156 * The read function: dp_dsc_clock_en_read
1157 * returns current status of DSC clock on the connector.
1158 * The return is a boolean flag: 1 or 0.
1160 * Access it with the following command (you need to specify
1161 * connector like DP-1):
1163 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1166 * 1 - means that DSC is currently enabled
1167 * 0 - means that DSC is disabled
1169 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1170 size_t size, loff_t *pos)
1172 char *rd_buf = NULL;
1173 char *rd_buf_ptr = NULL;
1174 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1175 struct display_stream_compressor *dsc;
1176 struct dcn_dsc_state dsc_state = {0};
1177 const uint32_t rd_buf_size = 10;
1178 struct pipe_ctx *pipe_ctx;
1180 int i, r, str_len = 30;
1182 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1187 rd_buf_ptr = rd_buf;
1189 for (i = 0; i < MAX_PIPES; i++) {
1190 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1191 if (pipe_ctx && pipe_ctx->stream &&
1192 pipe_ctx->stream->link == aconnector->dc_link)
1199 dsc = pipe_ctx->stream_res.dsc;
1201 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1203 snprintf(rd_buf_ptr, str_len,
1205 dsc_state.dsc_clock_en);
1206 rd_buf_ptr += str_len;
1209 if (*pos >= rd_buf_size)
1212 r = put_user(*(rd_buf + result), buf);
1214 return r; /* r = -EFAULT */
1226 /* function: write force DSC on the connector
1228 * The write function: dp_dsc_clock_en_write
1229 * enables to force DSC on the connector.
1230 * User can write to either force enable or force disable DSC
1231 * on the next modeset or set it to driver default
1234 * 0 - default DSC enablement policy
1235 * 1 - force enable DSC on the connector
1236 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1238 * Writing DSC settings is done with the following command:
1239 * - To force enable DSC (you need to specify
1240 * connector like DP-1):
1242 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1244 * - To return to default state set the flag to zero and
1245 * let driver deal with DSC automatically
1246 * (you need to specify connector like DP-1):
1248 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1251 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1252 size_t size, loff_t *pos)
1254 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1255 struct drm_connector *connector = &aconnector->base;
1256 struct drm_device *dev = connector->dev;
1257 struct drm_crtc *crtc = NULL;
1258 struct dm_crtc_state *dm_crtc_state = NULL;
1259 struct pipe_ctx *pipe_ctx;
1261 char *wr_buf = NULL;
1262 uint32_t wr_buf_size = 42;
1263 int max_param_num = 1;
1264 long param[1] = {0};
1265 uint8_t param_nums = 0;
1270 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1273 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1277 if (parse_write_buffer_into_params(wr_buf, size,
1285 if (param_nums <= 0) {
1286 DRM_DEBUG_DRIVER("user data not be read\n");
1291 for (i = 0; i < MAX_PIPES; i++) {
1292 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1293 if (pipe_ctx && pipe_ctx->stream &&
1294 pipe_ctx->stream->link == aconnector->dc_link)
1298 if (!pipe_ctx || !pipe_ctx->stream)
1302 mutex_lock(&dev->mode_config.mutex);
1303 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1305 if (connector->state == NULL)
1308 crtc = connector->state->crtc;
1312 drm_modeset_lock(&crtc->mutex, NULL);
1313 if (crtc->state == NULL)
1316 dm_crtc_state = to_dm_crtc_state(crtc->state);
1317 if (dm_crtc_state->stream == NULL)
1321 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1322 else if (param[0] == 2)
1323 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1325 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1327 dm_crtc_state->dsc_force_changed = true;
1331 drm_modeset_unlock(&crtc->mutex);
1332 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1333 mutex_unlock(&dev->mode_config.mutex);
1340 /* function: read DSC slice width parameter on the connector
1342 * The read function: dp_dsc_slice_width_read
1343 * returns dsc slice width used in the current configuration
1344 * The return is an integer: 0 or other positive number
1346 * Access the status with the following command:
1348 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1350 * 0 - means that DSC is disabled
1352 * Any other number more than zero represents the
1353 * slice width currently used by DSC in pixels
1356 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1357 size_t size, loff_t *pos)
1359 char *rd_buf = NULL;
1360 char *rd_buf_ptr = NULL;
1361 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1362 struct display_stream_compressor *dsc;
1363 struct dcn_dsc_state dsc_state = {0};
1364 const uint32_t rd_buf_size = 100;
1365 struct pipe_ctx *pipe_ctx;
1367 int i, r, str_len = 30;
1369 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1374 rd_buf_ptr = rd_buf;
1376 for (i = 0; i < MAX_PIPES; i++) {
1377 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1378 if (pipe_ctx && pipe_ctx->stream &&
1379 pipe_ctx->stream->link == aconnector->dc_link)
1386 dsc = pipe_ctx->stream_res.dsc;
1388 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1390 snprintf(rd_buf_ptr, str_len,
1392 dsc_state.dsc_slice_width);
1393 rd_buf_ptr += str_len;
1396 if (*pos >= rd_buf_size)
1399 r = put_user(*(rd_buf + result), buf);
1401 return r; /* r = -EFAULT */
1413 /* function: write DSC slice width parameter
1415 * The write function: dp_dsc_slice_width_write
1416 * overwrites automatically generated DSC configuration
1419 * The user has to write the slice width divisible by the
1422 * Also the user has to write width in hexidecimal
1423 * rather than in decimal.
1425 * Writing DSC settings is done with the following command:
1426 * - To force overwrite slice width: (example sets to 1920 pixels)
1428 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1430 * - To stop overwriting and let driver find the optimal size,
1431 * set the width to zero:
1433 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1436 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1437 size_t size, loff_t *pos)
1439 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1440 struct pipe_ctx *pipe_ctx;
1441 struct drm_connector *connector = &aconnector->base;
1442 struct drm_device *dev = connector->dev;
1443 struct drm_crtc *crtc = NULL;
1444 struct dm_crtc_state *dm_crtc_state = NULL;
1446 char *wr_buf = NULL;
1447 uint32_t wr_buf_size = 42;
1448 int max_param_num = 1;
1449 long param[1] = {0};
1450 uint8_t param_nums = 0;
1455 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1458 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1462 if (parse_write_buffer_into_params(wr_buf, size,
1470 if (param_nums <= 0) {
1471 DRM_DEBUG_DRIVER("user data not be read\n");
1476 for (i = 0; i < MAX_PIPES; i++) {
1477 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1478 if (pipe_ctx && pipe_ctx->stream &&
1479 pipe_ctx->stream->link == aconnector->dc_link)
1483 if (!pipe_ctx || !pipe_ctx->stream)
1486 // Safely get CRTC state
1487 mutex_lock(&dev->mode_config.mutex);
1488 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1490 if (connector->state == NULL)
1493 crtc = connector->state->crtc;
1497 drm_modeset_lock(&crtc->mutex, NULL);
1498 if (crtc->state == NULL)
1501 dm_crtc_state = to_dm_crtc_state(crtc->state);
1502 if (dm_crtc_state->stream == NULL)
1506 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1507 pipe_ctx->stream->timing.h_addressable,
1510 aconnector->dsc_settings.dsc_num_slices_h = 0;
1512 dm_crtc_state->dsc_force_changed = true;
1516 drm_modeset_unlock(&crtc->mutex);
1517 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1518 mutex_unlock(&dev->mode_config.mutex);
1525 /* function: read DSC slice height parameter on the connector
1527 * The read function: dp_dsc_slice_height_read
1528 * returns dsc slice height used in the current configuration
1529 * The return is an integer: 0 or other positive number
1531 * Access the status with the following command:
1533 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1535 * 0 - means that DSC is disabled
1537 * Any other number more than zero represents the
1538 * slice height currently used by DSC in pixels
1541 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1542 size_t size, loff_t *pos)
1544 char *rd_buf = NULL;
1545 char *rd_buf_ptr = NULL;
1546 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1547 struct display_stream_compressor *dsc;
1548 struct dcn_dsc_state dsc_state = {0};
1549 const uint32_t rd_buf_size = 100;
1550 struct pipe_ctx *pipe_ctx;
1552 int i, r, str_len = 30;
1554 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1559 rd_buf_ptr = rd_buf;
1561 for (i = 0; i < MAX_PIPES; i++) {
1562 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1563 if (pipe_ctx && pipe_ctx->stream &&
1564 pipe_ctx->stream->link == aconnector->dc_link)
1571 dsc = pipe_ctx->stream_res.dsc;
1573 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1575 snprintf(rd_buf_ptr, str_len,
1577 dsc_state.dsc_slice_height);
1578 rd_buf_ptr += str_len;
1581 if (*pos >= rd_buf_size)
1584 r = put_user(*(rd_buf + result), buf);
1586 return r; /* r = -EFAULT */
1598 /* function: write DSC slice height parameter
1600 * The write function: dp_dsc_slice_height_write
1601 * overwrites automatically generated DSC configuration
1604 * The user has to write the slice height divisible by the
1607 * Also the user has to write height in hexidecimal
1608 * rather than in decimal.
1610 * Writing DSC settings is done with the following command:
1611 * - To force overwrite slice height (example sets to 128 pixels):
1613 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1615 * - To stop overwriting and let driver find the optimal size,
1616 * set the height to zero:
1618 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1621 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1622 size_t size, loff_t *pos)
1624 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1625 struct drm_connector *connector = &aconnector->base;
1626 struct drm_device *dev = connector->dev;
1627 struct drm_crtc *crtc = NULL;
1628 struct dm_crtc_state *dm_crtc_state = NULL;
1629 struct pipe_ctx *pipe_ctx;
1631 char *wr_buf = NULL;
1632 uint32_t wr_buf_size = 42;
1633 int max_param_num = 1;
1634 uint8_t param_nums = 0;
1635 long param[1] = {0};
1640 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1643 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1647 if (parse_write_buffer_into_params(wr_buf, size,
1655 if (param_nums <= 0) {
1656 DRM_DEBUG_DRIVER("user data not be read\n");
1661 for (i = 0; i < MAX_PIPES; i++) {
1662 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1663 if (pipe_ctx && pipe_ctx->stream &&
1664 pipe_ctx->stream->link == aconnector->dc_link)
1668 if (!pipe_ctx || !pipe_ctx->stream)
1672 mutex_lock(&dev->mode_config.mutex);
1673 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1675 if (connector->state == NULL)
1678 crtc = connector->state->crtc;
1682 drm_modeset_lock(&crtc->mutex, NULL);
1683 if (crtc->state == NULL)
1686 dm_crtc_state = to_dm_crtc_state(crtc->state);
1687 if (dm_crtc_state->stream == NULL)
1691 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1692 pipe_ctx->stream->timing.v_addressable,
1695 aconnector->dsc_settings.dsc_num_slices_v = 0;
1697 dm_crtc_state->dsc_force_changed = true;
1701 drm_modeset_unlock(&crtc->mutex);
1702 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1703 mutex_unlock(&dev->mode_config.mutex);
1710 /* function: read DSC target rate on the connector in bits per pixel
1712 * The read function: dp_dsc_bits_per_pixel_read
1713 * returns target rate of compression in bits per pixel
1714 * The return is an integer: 0 or other positive integer
1716 * Access it with the following command:
1718 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1720 * 0 - means that DSC is disabled
1722 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
1723 size_t size, loff_t *pos)
1725 char *rd_buf = NULL;
1726 char *rd_buf_ptr = NULL;
1727 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1728 struct display_stream_compressor *dsc;
1729 struct dcn_dsc_state dsc_state = {0};
1730 const uint32_t rd_buf_size = 100;
1731 struct pipe_ctx *pipe_ctx;
1733 int i, r, str_len = 30;
1735 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1740 rd_buf_ptr = rd_buf;
1742 for (i = 0; i < MAX_PIPES; i++) {
1743 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1744 if (pipe_ctx && pipe_ctx->stream &&
1745 pipe_ctx->stream->link == aconnector->dc_link)
1752 dsc = pipe_ctx->stream_res.dsc;
1754 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1756 snprintf(rd_buf_ptr, str_len,
1758 dsc_state.dsc_bits_per_pixel);
1759 rd_buf_ptr += str_len;
1762 if (*pos >= rd_buf_size)
1765 r = put_user(*(rd_buf + result), buf);
1767 return r; /* r = -EFAULT */
1779 /* function: write DSC target rate in bits per pixel
1781 * The write function: dp_dsc_bits_per_pixel_write
1782 * overwrites automatically generated DSC configuration
1783 * of DSC target bit rate.
1785 * Also the user has to write bpp in hexidecimal
1786 * rather than in decimal.
1788 * Writing DSC settings is done with the following command:
1789 * - To force overwrite rate (example sets to 256 bpp x 1/16):
1791 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1793 * - To stop overwriting and let driver find the optimal rate,
1794 * set the rate to zero:
1796 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1799 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
1800 size_t size, loff_t *pos)
1802 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1803 struct drm_connector *connector = &aconnector->base;
1804 struct drm_device *dev = connector->dev;
1805 struct drm_crtc *crtc = NULL;
1806 struct dm_crtc_state *dm_crtc_state = NULL;
1807 struct pipe_ctx *pipe_ctx;
1809 char *wr_buf = NULL;
1810 uint32_t wr_buf_size = 42;
1811 int max_param_num = 1;
1812 uint8_t param_nums = 0;
1813 long param[1] = {0};
1818 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1821 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1825 if (parse_write_buffer_into_params(wr_buf, size,
1833 if (param_nums <= 0) {
1834 DRM_DEBUG_DRIVER("user data not be read\n");
1839 for (i = 0; i < MAX_PIPES; i++) {
1840 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1841 if (pipe_ctx && pipe_ctx->stream &&
1842 pipe_ctx->stream->link == aconnector->dc_link)
1846 if (!pipe_ctx || !pipe_ctx->stream)
1850 mutex_lock(&dev->mode_config.mutex);
1851 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1853 if (connector->state == NULL)
1856 crtc = connector->state->crtc;
1860 drm_modeset_lock(&crtc->mutex, NULL);
1861 if (crtc->state == NULL)
1864 dm_crtc_state = to_dm_crtc_state(crtc->state);
1865 if (dm_crtc_state->stream == NULL)
1868 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
1870 dm_crtc_state->dsc_force_changed = true;
1874 drm_modeset_unlock(&crtc->mutex);
1875 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1876 mutex_unlock(&dev->mode_config.mutex);
1883 /* function: read DSC picture width parameter on the connector
1885 * The read function: dp_dsc_pic_width_read
1886 * returns dsc picture width used in the current configuration
1887 * It is the same as h_addressable of the current
1889 * The return is an integer: 0 or other positive integer
1890 * If 0 then DSC is disabled.
1892 * Access it with the following command:
1894 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
1896 * 0 - means that DSC is disabled
1898 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
1899 size_t size, loff_t *pos)
1901 char *rd_buf = NULL;
1902 char *rd_buf_ptr = NULL;
1903 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1904 struct display_stream_compressor *dsc;
1905 struct dcn_dsc_state dsc_state = {0};
1906 const uint32_t rd_buf_size = 100;
1907 struct pipe_ctx *pipe_ctx;
1909 int i, r, str_len = 30;
1911 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1916 rd_buf_ptr = rd_buf;
1918 for (i = 0; i < MAX_PIPES; i++) {
1919 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1920 if (pipe_ctx && pipe_ctx->stream &&
1921 pipe_ctx->stream->link == aconnector->dc_link)
1928 dsc = pipe_ctx->stream_res.dsc;
1930 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1932 snprintf(rd_buf_ptr, str_len,
1934 dsc_state.dsc_pic_width);
1935 rd_buf_ptr += str_len;
1938 if (*pos >= rd_buf_size)
1941 r = put_user(*(rd_buf + result), buf);
1943 return r; /* r = -EFAULT */
1955 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
1956 size_t size, loff_t *pos)
1958 char *rd_buf = NULL;
1959 char *rd_buf_ptr = NULL;
1960 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1961 struct display_stream_compressor *dsc;
1962 struct dcn_dsc_state dsc_state = {0};
1963 const uint32_t rd_buf_size = 100;
1964 struct pipe_ctx *pipe_ctx;
1966 int i, r, str_len = 30;
1968 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1973 rd_buf_ptr = rd_buf;
1975 for (i = 0; i < MAX_PIPES; i++) {
1976 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1977 if (pipe_ctx && pipe_ctx->stream &&
1978 pipe_ctx->stream->link == aconnector->dc_link)
1985 dsc = pipe_ctx->stream_res.dsc;
1987 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1989 snprintf(rd_buf_ptr, str_len,
1991 dsc_state.dsc_pic_height);
1992 rd_buf_ptr += str_len;
1995 if (*pos >= rd_buf_size)
1998 r = put_user(*(rd_buf + result), buf);
2000 return r; /* r = -EFAULT */
2012 /* function: read DSC chunk size parameter on the connector
2014 * The read function: dp_dsc_chunk_size_read
2015 * returns dsc chunk size set in the current configuration
2016 * The value is calculated automatically by DSC code
2017 * and depends on slice parameters and bpp target rate
2018 * The return is an integer: 0 or other positive integer
2019 * If 0 then DSC is disabled.
2021 * Access it with the following command:
2023 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2025 * 0 - means that DSC is disabled
2027 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2028 size_t size, loff_t *pos)
2030 char *rd_buf = NULL;
2031 char *rd_buf_ptr = NULL;
2032 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2033 struct display_stream_compressor *dsc;
2034 struct dcn_dsc_state dsc_state = {0};
2035 const uint32_t rd_buf_size = 100;
2036 struct pipe_ctx *pipe_ctx;
2038 int i, r, str_len = 30;
2040 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2045 rd_buf_ptr = rd_buf;
2047 for (i = 0; i < MAX_PIPES; i++) {
2048 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2049 if (pipe_ctx && pipe_ctx->stream &&
2050 pipe_ctx->stream->link == aconnector->dc_link)
2057 dsc = pipe_ctx->stream_res.dsc;
2059 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2061 snprintf(rd_buf_ptr, str_len,
2063 dsc_state.dsc_chunk_size);
2064 rd_buf_ptr += str_len;
2067 if (*pos >= rd_buf_size)
2070 r = put_user(*(rd_buf + result), buf);
2072 return r; /* r = -EFAULT */
2084 /* function: read DSC slice bpg offset on the connector
2086 * The read function: dp_dsc_slice_bpg_offset_read
2087 * returns dsc bpg slice offset set in the current configuration
2088 * The value is calculated automatically by DSC code
2089 * and depends on slice parameters and bpp target rate
2090 * The return is an integer: 0 or other positive integer
2091 * If 0 then DSC is disabled.
2093 * Access it with the following command:
2095 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2097 * 0 - means that DSC is disabled
2099 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2100 size_t size, loff_t *pos)
2102 char *rd_buf = NULL;
2103 char *rd_buf_ptr = NULL;
2104 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2105 struct display_stream_compressor *dsc;
2106 struct dcn_dsc_state dsc_state = {0};
2107 const uint32_t rd_buf_size = 100;
2108 struct pipe_ctx *pipe_ctx;
2110 int i, r, str_len = 30;
2112 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2117 rd_buf_ptr = rd_buf;
2119 for (i = 0; i < MAX_PIPES; i++) {
2120 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2121 if (pipe_ctx && pipe_ctx->stream &&
2122 pipe_ctx->stream->link == aconnector->dc_link)
2129 dsc = pipe_ctx->stream_res.dsc;
2131 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2133 snprintf(rd_buf_ptr, str_len,
2135 dsc_state.dsc_slice_bpg_offset);
2136 rd_buf_ptr += str_len;
2139 if (*pos >= rd_buf_size)
2142 r = put_user(*(rd_buf + result), buf);
2144 return r; /* r = -EFAULT */
2158 * function description: Read max_requested_bpc property from the connector
2160 * Access it with the following command:
2162 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2165 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2166 size_t size, loff_t *pos)
2168 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2169 struct drm_connector *connector = &aconnector->base;
2170 struct drm_device *dev = connector->dev;
2171 struct dm_connector_state *state;
2173 char *rd_buf = NULL;
2174 char *rd_buf_ptr = NULL;
2175 const uint32_t rd_buf_size = 10;
2178 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2183 mutex_lock(&dev->mode_config.mutex);
2184 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2186 if (connector->state == NULL)
2189 state = to_dm_connector_state(connector->state);
2191 rd_buf_ptr = rd_buf;
2192 snprintf(rd_buf_ptr, rd_buf_size,
2194 state->base.max_requested_bpc);
2197 if (*pos >= rd_buf_size)
2200 r = put_user(*(rd_buf + result), buf);
2202 result = r; /* r = -EFAULT */
2211 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2212 mutex_unlock(&dev->mode_config.mutex);
2219 * function description: Set max_requested_bpc property on the connector
2221 * This function will not force the input BPC on connector, it will only
2222 * change the max value. This is equivalent to setting max_bpc through
2225 * The BPC value written must be >= 6 and <= 16. Values outside of this
2226 * range will result in errors.
2235 * Write the max_bpc in the following way:
2237 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2240 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2241 size_t size, loff_t *pos)
2243 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2244 struct drm_connector *connector = &aconnector->base;
2245 struct dm_connector_state *state;
2246 struct drm_device *dev = connector->dev;
2247 char *wr_buf = NULL;
2248 uint32_t wr_buf_size = 42;
2249 int max_param_num = 1;
2250 long param[1] = {0};
2251 uint8_t param_nums = 0;
2256 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2259 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2263 if (parse_write_buffer_into_params(wr_buf, size,
2271 if (param_nums <= 0) {
2272 DRM_DEBUG_DRIVER("user data not be read\n");
2277 if (param[0] < 6 || param[0] > 16) {
2278 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2283 mutex_lock(&dev->mode_config.mutex);
2284 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2286 if (connector->state == NULL)
2289 state = to_dm_connector_state(connector->state);
2290 state->base.max_requested_bpc = param[0];
2292 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2293 mutex_unlock(&dev->mode_config.mutex);
2299 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2300 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2301 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2302 DEFINE_SHOW_ATTRIBUTE(output_bpc);
2303 #ifdef CONFIG_DRM_AMD_DC_HDCP
2304 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2307 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2308 .owner = THIS_MODULE,
2309 .read = dp_dsc_clock_en_read,
2310 .write = dp_dsc_clock_en_write,
2311 .llseek = default_llseek
2314 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2315 .owner = THIS_MODULE,
2316 .read = dp_dsc_slice_width_read,
2317 .write = dp_dsc_slice_width_write,
2318 .llseek = default_llseek
2321 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2322 .owner = THIS_MODULE,
2323 .read = dp_dsc_slice_height_read,
2324 .write = dp_dsc_slice_height_write,
2325 .llseek = default_llseek
2328 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2329 .owner = THIS_MODULE,
2330 .read = dp_dsc_bits_per_pixel_read,
2331 .write = dp_dsc_bits_per_pixel_write,
2332 .llseek = default_llseek
2335 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2336 .owner = THIS_MODULE,
2337 .read = dp_dsc_pic_width_read,
2338 .llseek = default_llseek
2341 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2342 .owner = THIS_MODULE,
2343 .read = dp_dsc_pic_height_read,
2344 .llseek = default_llseek
2347 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2348 .owner = THIS_MODULE,
2349 .read = dp_dsc_chunk_size_read,
2350 .llseek = default_llseek
2353 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2354 .owner = THIS_MODULE,
2355 .read = dp_dsc_slice_bpg_offset_read,
2356 .llseek = default_llseek
2359 static const struct file_operations trigger_hotplug_debugfs_fops = {
2360 .owner = THIS_MODULE,
2361 .write = trigger_hotplug,
2362 .llseek = default_llseek
2365 static const struct file_operations dp_link_settings_debugfs_fops = {
2366 .owner = THIS_MODULE,
2367 .read = dp_link_settings_read,
2368 .write = dp_link_settings_write,
2369 .llseek = default_llseek
2372 static const struct file_operations dp_phy_settings_debugfs_fop = {
2373 .owner = THIS_MODULE,
2374 .read = dp_phy_settings_read,
2375 .write = dp_phy_settings_write,
2376 .llseek = default_llseek
2379 static const struct file_operations dp_phy_test_pattern_fops = {
2380 .owner = THIS_MODULE,
2381 .write = dp_phy_test_pattern_debugfs_write,
2382 .llseek = default_llseek
2385 static const struct file_operations sdp_message_fops = {
2386 .owner = THIS_MODULE,
2387 .write = dp_sdp_message_debugfs_write,
2388 .llseek = default_llseek
2391 static const struct file_operations dp_dpcd_address_debugfs_fops = {
2392 .owner = THIS_MODULE,
2393 .write = dp_dpcd_address_write,
2394 .llseek = default_llseek
2397 static const struct file_operations dp_dpcd_size_debugfs_fops = {
2398 .owner = THIS_MODULE,
2399 .write = dp_dpcd_size_write,
2400 .llseek = default_llseek
2403 static const struct file_operations dp_dpcd_data_debugfs_fops = {
2404 .owner = THIS_MODULE,
2405 .read = dp_dpcd_data_read,
2406 .write = dp_dpcd_data_write,
2407 .llseek = default_llseek
2410 static const struct file_operations dp_max_bpc_debugfs_fops = {
2411 .owner = THIS_MODULE,
2412 .read = dp_max_bpc_read,
2413 .write = dp_max_bpc_write,
2414 .llseek = default_llseek
2417 static const struct {
2419 const struct file_operations *fops;
2420 } dp_debugfs_entries[] = {
2421 {"link_settings", &dp_link_settings_debugfs_fops},
2422 {"phy_settings", &dp_phy_settings_debugfs_fop},
2423 {"test_pattern", &dp_phy_test_pattern_fops},
2424 #ifdef CONFIG_DRM_AMD_DC_HDCP
2425 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2427 {"sdp_message", &sdp_message_fops},
2428 {"aux_dpcd_address", &dp_dpcd_address_debugfs_fops},
2429 {"aux_dpcd_size", &dp_dpcd_size_debugfs_fops},
2430 {"aux_dpcd_data", &dp_dpcd_data_debugfs_fops},
2431 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2432 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2433 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2434 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2435 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2436 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2437 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2438 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2439 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
2440 {"max_bpc", &dp_max_bpc_debugfs_fops}
2443 #ifdef CONFIG_DRM_AMD_DC_HDCP
2444 static const struct {
2446 const struct file_operations *fops;
2447 } hdmi_debugfs_entries[] = {
2448 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
2452 * Force YUV420 output if available from the given mode
2454 static int force_yuv420_output_set(void *data, u64 val)
2456 struct amdgpu_dm_connector *connector = data;
2458 connector->force_yuv420_output = (bool)val;
2464 * Check if YUV420 is forced when available from the given mode
2466 static int force_yuv420_output_get(void *data, u64 *val)
2468 struct amdgpu_dm_connector *connector = data;
2470 *val = connector->force_yuv420_output;
2475 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2476 force_yuv420_output_set, "%llu\n");
2481 static int psr_get(void *data, u64 *val)
2483 struct amdgpu_dm_connector *connector = data;
2484 struct dc_link *link = connector->dc_link;
2485 enum dc_psr_state state = PSR_STATE0;
2487 dc_link_get_psr_state(link, &state);
2495 * Set dmcub trace event IRQ enable or disable.
2496 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2497 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2499 static int dmcub_trace_event_state_set(void *data, u64 val)
2501 struct amdgpu_device *adev = data;
2503 if (val == 1 || val == 0) {
2504 dc_dmub_trace_event_control(adev->dm.dc, val);
2505 adev->dm.dmcub_trace_event_en = (bool)val;
2513 * The interface doesn't need get function, so it will return the
2515 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
2517 static int dmcub_trace_event_state_get(void *data, u64 *val)
2519 struct amdgpu_device *adev = data;
2521 *val = adev->dm.dmcub_trace_event_en;
2525 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
2526 dmcub_trace_event_state_set, "%llu\n");
2528 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
2530 static const struct {
2532 const struct file_operations *fops;
2533 } connector_debugfs_entries[] = {
2534 {"force_yuv420_output", &force_yuv420_output_fops},
2535 {"output_bpc", &output_bpc_fops},
2536 {"trigger_hotplug", &trigger_hotplug_debugfs_fops}
2539 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
2542 struct dentry *dir = connector->base.debugfs_entry;
2544 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
2545 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2546 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
2547 debugfs_create_file(dp_debugfs_entries[i].name,
2548 0644, dir, connector,
2549 dp_debugfs_entries[i].fops);
2552 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
2553 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
2555 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
2556 debugfs_create_file(connector_debugfs_entries[i].name,
2557 0644, dir, connector,
2558 connector_debugfs_entries[i].fops);
2561 connector->debugfs_dpcd_address = 0;
2562 connector->debugfs_dpcd_size = 0;
2564 #ifdef CONFIG_DRM_AMD_DC_HDCP
2565 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
2566 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
2567 debugfs_create_file(hdmi_debugfs_entries[i].name,
2568 0644, dir, connector,
2569 hdmi_debugfs_entries[i].fops);
2575 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
2577 * Set crc window coordinate x start
2579 static int crc_win_x_start_set(void *data, u64 val)
2581 struct drm_crtc *crtc = data;
2582 struct drm_device *drm_dev = crtc->dev;
2583 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2585 spin_lock_irq(&drm_dev->event_lock);
2586 acrtc->dm_irq_params.crc_window.x_start = (uint16_t) val;
2587 acrtc->dm_irq_params.crc_window.update_win = false;
2588 spin_unlock_irq(&drm_dev->event_lock);
2594 * Get crc window coordinate x start
2596 static int crc_win_x_start_get(void *data, u64 *val)
2598 struct drm_crtc *crtc = data;
2599 struct drm_device *drm_dev = crtc->dev;
2600 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2602 spin_lock_irq(&drm_dev->event_lock);
2603 *val = acrtc->dm_irq_params.crc_window.x_start;
2604 spin_unlock_irq(&drm_dev->event_lock);
2609 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
2610 crc_win_x_start_set, "%llu\n");
2614 * Set crc window coordinate y start
2616 static int crc_win_y_start_set(void *data, u64 val)
2618 struct drm_crtc *crtc = data;
2619 struct drm_device *drm_dev = crtc->dev;
2620 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2622 spin_lock_irq(&drm_dev->event_lock);
2623 acrtc->dm_irq_params.crc_window.y_start = (uint16_t) val;
2624 acrtc->dm_irq_params.crc_window.update_win = false;
2625 spin_unlock_irq(&drm_dev->event_lock);
2631 * Get crc window coordinate y start
2633 static int crc_win_y_start_get(void *data, u64 *val)
2635 struct drm_crtc *crtc = data;
2636 struct drm_device *drm_dev = crtc->dev;
2637 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2639 spin_lock_irq(&drm_dev->event_lock);
2640 *val = acrtc->dm_irq_params.crc_window.y_start;
2641 spin_unlock_irq(&drm_dev->event_lock);
2646 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
2647 crc_win_y_start_set, "%llu\n");
2650 * Set crc window coordinate x end
2652 static int crc_win_x_end_set(void *data, u64 val)
2654 struct drm_crtc *crtc = data;
2655 struct drm_device *drm_dev = crtc->dev;
2656 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2658 spin_lock_irq(&drm_dev->event_lock);
2659 acrtc->dm_irq_params.crc_window.x_end = (uint16_t) val;
2660 acrtc->dm_irq_params.crc_window.update_win = false;
2661 spin_unlock_irq(&drm_dev->event_lock);
2667 * Get crc window coordinate x end
2669 static int crc_win_x_end_get(void *data, u64 *val)
2671 struct drm_crtc *crtc = data;
2672 struct drm_device *drm_dev = crtc->dev;
2673 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2675 spin_lock_irq(&drm_dev->event_lock);
2676 *val = acrtc->dm_irq_params.crc_window.x_end;
2677 spin_unlock_irq(&drm_dev->event_lock);
2682 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
2683 crc_win_x_end_set, "%llu\n");
2686 * Set crc window coordinate y end
2688 static int crc_win_y_end_set(void *data, u64 val)
2690 struct drm_crtc *crtc = data;
2691 struct drm_device *drm_dev = crtc->dev;
2692 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2694 spin_lock_irq(&drm_dev->event_lock);
2695 acrtc->dm_irq_params.crc_window.y_end = (uint16_t) val;
2696 acrtc->dm_irq_params.crc_window.update_win = false;
2697 spin_unlock_irq(&drm_dev->event_lock);
2703 * Get crc window coordinate y end
2705 static int crc_win_y_end_get(void *data, u64 *val)
2707 struct drm_crtc *crtc = data;
2708 struct drm_device *drm_dev = crtc->dev;
2709 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
2711 spin_lock_irq(&drm_dev->event_lock);
2712 *val = acrtc->dm_irq_params.crc_window.y_end;
2713 spin_unlock_irq(&drm_dev->event_lock);
2718 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
2719 crc_win_y_end_set, "%llu\n");
2721 * Trigger to commit crc window
2723 static int crc_win_update_set(void *data, u64 val)
2725 struct drm_crtc *new_crtc = data;
2726 struct drm_crtc *old_crtc = NULL;
2727 struct amdgpu_crtc *new_acrtc, *old_acrtc;
2728 struct amdgpu_device *adev = drm_to_adev(new_crtc->dev);
2729 struct crc_rd_work *crc_rd_wrk = adev->dm.crc_rd_wrk;
2732 spin_lock_irq(&adev_to_drm(adev)->event_lock);
2733 spin_lock_irq(&crc_rd_wrk->crc_rd_work_lock);
2734 if (crc_rd_wrk && crc_rd_wrk->crtc) {
2735 old_crtc = crc_rd_wrk->crtc;
2736 old_acrtc = to_amdgpu_crtc(old_crtc);
2738 new_acrtc = to_amdgpu_crtc(new_crtc);
2740 if (old_crtc && old_crtc != new_crtc) {
2741 old_acrtc->dm_irq_params.crc_window.activated = false;
2742 old_acrtc->dm_irq_params.crc_window.update_win = false;
2743 old_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
2745 new_acrtc->dm_irq_params.crc_window.activated = true;
2746 new_acrtc->dm_irq_params.crc_window.update_win = true;
2747 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
2748 crc_rd_wrk->crtc = new_crtc;
2750 new_acrtc->dm_irq_params.crc_window.activated = true;
2751 new_acrtc->dm_irq_params.crc_window.update_win = true;
2752 new_acrtc->dm_irq_params.crc_window.skip_frame_cnt = 0;
2753 crc_rd_wrk->crtc = new_crtc;
2755 spin_unlock_irq(&crc_rd_wrk->crc_rd_work_lock);
2756 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
2763 * Get crc window update flag
2765 static int crc_win_update_get(void *data, u64 *val)
2771 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
2772 crc_win_update_set, "%llu\n");
2774 void crtc_debugfs_init(struct drm_crtc *crtc)
2776 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
2781 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
2782 &crc_win_x_start_fops);
2783 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
2784 &crc_win_y_start_fops);
2785 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
2786 &crc_win_x_end_fops);
2787 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
2788 &crc_win_y_end_fops);
2789 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
2790 &crc_win_update_fops);
2795 * Writes DTN log state to the user supplied buffer.
2796 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
2798 static ssize_t dtn_log_read(
2804 struct amdgpu_device *adev = file_inode(f)->i_private;
2805 struct dc *dc = adev->dm.dc;
2806 struct dc_log_buffer_ctx log_ctx = { 0 };
2812 if (!dc->hwss.log_hw_state)
2815 dc->hwss.log_hw_state(dc, &log_ctx);
2817 if (*pos < log_ctx.pos) {
2818 size_t to_copy = log_ctx.pos - *pos;
2820 to_copy = min(to_copy, size);
2822 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
2834 * Writes DTN log state to dmesg when triggered via a write.
2835 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
2837 static ssize_t dtn_log_write(
2839 const char __user *buf,
2843 struct amdgpu_device *adev = file_inode(f)->i_private;
2844 struct dc *dc = adev->dm.dc;
2846 /* Write triggers log output via dmesg. */
2850 if (dc->hwss.log_hw_state)
2851 dc->hwss.log_hw_state(dc, NULL);
2857 * Backlight at this moment. Read only.
2858 * As written to display, taking ABM and backlight lut into account.
2859 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2861 static int current_backlight_show(struct seq_file *m, void *unused)
2863 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
2864 struct amdgpu_display_manager *dm = &adev->dm;
2866 unsigned int backlight = dc_link_get_backlight_level(dm->backlight_link);
2868 seq_printf(m, "0x%x\n", backlight);
2873 * Backlight value that is being approached. Read only.
2874 * As written to display, taking ABM and backlight lut into account.
2875 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2877 static int target_backlight_show(struct seq_file *m, void *unused)
2879 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
2880 struct amdgpu_display_manager *dm = &adev->dm;
2882 unsigned int backlight = dc_link_get_target_backlight_pwm(dm->backlight_link);
2884 seq_printf(m, "0x%x\n", backlight);
2888 static int mst_topo_show(struct seq_file *m, void *unused)
2890 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
2891 struct drm_device *dev = adev_to_drm(adev);
2892 struct drm_connector *connector;
2893 struct drm_connector_list_iter conn_iter;
2894 struct amdgpu_dm_connector *aconnector;
2896 drm_connector_list_iter_begin(dev, &conn_iter);
2897 drm_for_each_connector_iter(connector, &conn_iter) {
2898 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2901 aconnector = to_amdgpu_dm_connector(connector);
2903 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
2904 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
2906 drm_connector_list_iter_end(&conn_iter);
2912 * Sets the force_timing_sync debug optino from the given string.
2913 * All connected displays will be force synchronized immediately.
2914 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
2916 static int force_timing_sync_set(void *data, u64 val)
2918 struct amdgpu_device *adev = data;
2920 adev->dm.force_timing_sync = (bool)val;
2922 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
2928 * Gets the force_timing_sync debug option value into the given buffer.
2929 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
2931 static int force_timing_sync_get(void *data, u64 *val)
2933 struct amdgpu_device *adev = data;
2935 *val = adev->dm.force_timing_sync;
2940 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
2941 force_timing_sync_set, "%llu\n");
2944 * Sets the DC visual confirm debug option from the given string.
2945 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
2947 static int visual_confirm_set(void *data, u64 val)
2949 struct amdgpu_device *adev = data;
2951 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
2957 * Reads the DC visual confirm debug option value into the given buffer.
2958 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
2960 static int visual_confirm_get(void *data, u64 *val)
2962 struct amdgpu_device *adev = data;
2964 *val = adev->dm.dc->debug.visual_confirm;
2969 DEFINE_SHOW_ATTRIBUTE(current_backlight);
2970 DEFINE_SHOW_ATTRIBUTE(target_backlight);
2971 DEFINE_SHOW_ATTRIBUTE(mst_topo);
2972 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
2973 visual_confirm_set, "%llu\n");
2975 void dtn_debugfs_init(struct amdgpu_device *adev)
2977 static const struct file_operations dtn_log_fops = {
2978 .owner = THIS_MODULE,
2979 .read = dtn_log_read,
2980 .write = dtn_log_write,
2981 .llseek = default_llseek
2984 struct drm_minor *minor = adev_to_drm(adev)->primary;
2985 struct dentry *root = minor->debugfs_root;
2987 debugfs_create_file("amdgpu_current_backlight_pwm", 0444,
2988 root, adev, ¤t_backlight_fops);
2989 debugfs_create_file("amdgpu_target_backlight_pwm", 0444,
2990 root, adev, &target_backlight_fops);
2991 debugfs_create_file("amdgpu_mst_topology", 0444, root,
2992 adev, &mst_topo_fops);
2993 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
2996 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
2997 &visual_confirm_fops);
2999 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
3000 adev, &dmub_tracebuffer_fops);
3002 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
3003 adev, &dmub_fw_state_fops);
3005 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
3006 adev, &force_timing_sync_ops);
3008 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
3009 adev, &dmcub_trace_event_state_fops);