2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/string_helpers.h>
27 #include <linux/uaccess.h>
28 #include <media/cec-notifier.h>
32 #include "amdgpu_dm.h"
33 #include "amdgpu_dm_debugfs.h"
34 #include "amdgpu_dm_replay.h"
35 #include "dm_helpers.h"
36 #include "dmub/dmub_srv.h"
39 #include "link_hwss.h"
40 #include "dc/dc_dmub_srv.h"
41 #include "link/protocols/link_dp_capability.h"
42 #include "inc/hw/dchubbub.h"
44 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
45 #include "amdgpu_dm_psr.h"
48 struct dmub_debugfs_trace_header {
53 struct dmub_debugfs_trace_entry {
60 static const char *const mst_progress_status[] = {
63 "allocate_new_payload",
64 "clear_allocated_payload",
67 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
69 * Function takes in attributes passed to debugfs write entry
70 * and writes into param array.
71 * The user passes max_param_num to identify maximum number of
72 * parameters that could be parsed.
75 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
76 long *param, const char __user *buf,
80 char *wr_buf_ptr = NULL;
81 uint32_t wr_buf_count = 0;
84 const char delimiter[3] = {' ', '\n', '\0'};
85 uint8_t param_index = 0;
91 /* r is bytes not be copied */
92 if (copy_from_user(wr_buf_ptr, buf, wr_buf_size)) {
93 DRM_DEBUG_DRIVER("user data could not be read successfully\n");
97 /* check number of parameters. isspace could not differ space and \n */
98 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
100 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
105 if (wr_buf_count == wr_buf_size)
109 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
116 if (wr_buf_count == wr_buf_size)
120 if (*param_nums > max_param_num)
121 *param_nums = max_param_num;
123 wr_buf_ptr = wr_buf; /* reset buf pointer */
124 wr_buf_count = 0; /* number of char already checked */
126 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
131 while (param_index < *param_nums) {
132 /* after strsep, wr_buf_ptr will be moved to after space */
133 sub_str = strsep(&wr_buf_ptr, delimiter);
135 r = kstrtol(sub_str, 16, &(param[param_index]));
138 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
146 /* function description
147 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
149 * valid lane count value: 1, 2, 4
150 * valid link rate value:
151 * 06h = 1.62Gbps per lane
152 * 0Ah = 2.7Gbps per lane
153 * 0Ch = 3.24Gbps per lane
154 * 14h = 5.4Gbps per lane
155 * 1Eh = 8.1Gbps per lane
157 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
159 * --- to get dp configuration
161 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
163 * It will list current, verified, reported, preferred dp configuration.
164 * current -- for current video mode
165 * verified --- maximum configuration which pass link training
166 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
167 * preferred --- user force settings
169 * --- set (or force) dp configuration
171 * echo <lane_count> <link_rate> > link_settings
173 * for example, to force to 2 lane, 2.7GHz,
174 * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
176 * spread_spectrum could not be changed dynamically.
178 * in case invalid lane count, link rate are force, no hw programming will be
179 * done. please check link settings after force operation to see if HW get
182 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
184 * check current and preferred settings.
187 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
188 size_t size, loff_t *pos)
190 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
191 struct dc_link *link = connector->dc_link;
193 char *rd_buf_ptr = NULL;
194 const uint32_t rd_buf_size = 100;
199 if (*pos & 3 || size & 3)
202 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
208 str_len = strlen("Current: %d 0x%x %d ");
209 snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
210 link->cur_link_settings.lane_count,
211 link->cur_link_settings.link_rate,
212 link->cur_link_settings.link_spread);
213 rd_buf_ptr += str_len;
215 str_len = strlen("Verified: %d 0x%x %d ");
216 snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
217 link->verified_link_cap.lane_count,
218 link->verified_link_cap.link_rate,
219 link->verified_link_cap.link_spread);
220 rd_buf_ptr += str_len;
222 str_len = strlen("Reported: %d 0x%x %d ");
223 snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
224 link->reported_link_cap.lane_count,
225 link->reported_link_cap.link_rate,
226 link->reported_link_cap.link_spread);
227 rd_buf_ptr += str_len;
229 str_len = strlen("Preferred: %d 0x%x %d ");
230 snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
231 link->preferred_link_setting.lane_count,
232 link->preferred_link_setting.link_rate,
233 link->preferred_link_setting.link_spread);
236 if (*pos >= rd_buf_size)
239 r = put_user(*(rd_buf + result), buf);
242 return r; /* r = -EFAULT */
255 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
256 size_t size, loff_t *pos)
258 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
259 struct dc_link *link = connector->dc_link;
260 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
261 struct dc *dc = (struct dc *)link->dc;
262 struct dc_link_settings prefer_link_settings = {0};
264 const uint32_t wr_buf_size = 40;
265 /* 0: lane_count; 1: link_rate */
266 int max_param_num = 2;
267 uint8_t param_nums = 0;
269 bool valid_input = true;
274 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
278 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
286 if (param_nums <= 0) {
288 DRM_DEBUG_DRIVER("user data not be read\n");
295 case LANE_COUNT_FOUR:
306 case LINK_RATE_HIGH2:
307 case LINK_RATE_HIGH3:
308 case LINK_RATE_UHBR10:
309 case LINK_RATE_UHBR13_5:
310 case LINK_RATE_UHBR20:
319 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
320 mutex_lock(&adev->dm.dc_lock);
321 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
322 mutex_unlock(&adev->dm.dc_lock);
326 /* save user force lane_count, link_rate to preferred settings
327 * spread spectrum will not be changed
329 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
330 prefer_link_settings.use_link_rate_set = false;
331 prefer_link_settings.lane_count = param[0];
332 prefer_link_settings.link_rate = param[1];
334 mutex_lock(&adev->dm.dc_lock);
335 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, false);
336 mutex_unlock(&adev->dm.dc_lock);
342 static bool dp_mst_is_end_device(struct amdgpu_dm_connector *aconnector)
344 bool is_end_device = false;
345 struct drm_dp_mst_topology_mgr *mgr = NULL;
346 struct drm_dp_mst_port *port = NULL;
348 if (aconnector->mst_root && aconnector->mst_root->mst_mgr.mst_state) {
349 mgr = &aconnector->mst_root->mst_mgr;
350 port = aconnector->mst_output_port;
352 drm_modeset_lock(&mgr->base.lock, NULL);
353 if (port->pdt == DP_PEER_DEVICE_SST_SINK ||
354 port->pdt == DP_PEER_DEVICE_DP_LEGACY_CONV)
355 is_end_device = true;
356 drm_modeset_unlock(&mgr->base.lock);
359 return is_end_device;
362 /* Change MST link setting
364 * valid lane count value: 1, 2, 4
365 * valid link rate value:
366 * 06h = 1.62Gbps per lane
367 * 0Ah = 2.7Gbps per lane
368 * 0Ch = 3.24Gbps per lane
369 * 14h = 5.4Gbps per lane
370 * 1Eh = 8.1Gbps per lane
371 * 3E8h = 10.0Gbps per lane
372 * 546h = 13.5Gbps per lane
373 * 7D0h = 20.0Gbps per lane
375 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/mst_link_settings
377 * for example, to force to 2 lane, 10.0GHz,
378 * echo 2 0x3e8 > /sys/kernel/debug/dri/0/DP-x/mst_link_settings
380 * Valid input will trigger hotplug event to get new link setting applied
381 * Invalid input will trigger training setting reset
383 * The usage can be referred to link_settings entry
386 static ssize_t dp_mst_link_setting(struct file *f, const char __user *buf,
387 size_t size, loff_t *pos)
389 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
390 struct dc_link *link = aconnector->dc_link;
391 struct amdgpu_device *adev = drm_to_adev(aconnector->base.dev);
392 struct dc *dc = (struct dc *)link->dc;
393 struct dc_link_settings prefer_link_settings = {0};
395 const uint32_t wr_buf_size = 40;
396 /* 0: lane_count; 1: link_rate */
397 int max_param_num = 2;
398 uint8_t param_nums = 0;
400 bool valid_input = true;
402 if (!dp_mst_is_end_device(aconnector))
408 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
412 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
420 if (param_nums <= 0) {
422 DRM_DEBUG_DRIVER("user data not be read\n");
429 case LANE_COUNT_FOUR:
440 case LINK_RATE_HIGH2:
441 case LINK_RATE_HIGH3:
442 case LINK_RATE_UHBR10:
443 case LINK_RATE_UHBR13_5:
444 case LINK_RATE_UHBR20:
453 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
454 mutex_lock(&adev->dm.dc_lock);
455 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
456 mutex_unlock(&adev->dm.dc_lock);
460 /* save user force lane_count, link_rate to preferred settings
461 * spread spectrum will not be changed
463 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
464 prefer_link_settings.use_link_rate_set = false;
465 prefer_link_settings.lane_count = param[0];
466 prefer_link_settings.link_rate = param[1];
468 /* skip immediate retrain, and train to new link setting after hotplug event triggered */
469 mutex_lock(&adev->dm.dc_lock);
470 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, true);
471 mutex_unlock(&adev->dm.dc_lock);
473 mutex_lock(&aconnector->base.dev->mode_config.mutex);
474 aconnector->base.force = DRM_FORCE_OFF;
475 mutex_unlock(&aconnector->base.dev->mode_config.mutex);
476 drm_kms_helper_hotplug_event(aconnector->base.dev);
480 mutex_lock(&aconnector->base.dev->mode_config.mutex);
481 aconnector->base.force = DRM_FORCE_UNSPECIFIED;
482 mutex_unlock(&aconnector->base.dev->mode_config.mutex);
483 drm_kms_helper_hotplug_event(aconnector->base.dev);
489 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
490 * post-cursor2 (defined by VESA DP specification)
493 * voltage swing: 0,1,2,3
494 * pre-emphasis : 0,1,2,3
495 * post cursor2 : 0,1,2,3
498 * how to use this debugfs
500 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
502 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
504 * To figure out which DP-x is the display for DP to be check,
507 * There should be debugfs file, like link_settings, phy_settings.
509 * from lane_count, link_rate to figure which DP-x is for display to be worked
512 * To get current DP PHY settings,
515 * To change DP PHY settings,
516 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
517 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
519 * echo 2 3 0 > phy_settings
521 * To check if change be applied, get current phy settings by
524 * In case invalid values are set by user, like
525 * echo 1 4 0 > phy_settings
527 * HW will NOT be programmed by these settings.
528 * cat phy_settings will show the previous valid settings.
530 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
531 size_t size, loff_t *pos)
533 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
534 struct dc_link *link = connector->dc_link;
536 const uint32_t rd_buf_size = 20;
540 if (*pos & 3 || size & 3)
543 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
547 snprintf(rd_buf, rd_buf_size, " %d %d %d\n",
548 link->cur_lane_setting[0].VOLTAGE_SWING,
549 link->cur_lane_setting[0].PRE_EMPHASIS,
550 link->cur_lane_setting[0].POST_CURSOR2);
553 if (*pos >= rd_buf_size)
556 r = put_user((*(rd_buf + result)), buf);
559 return r; /* r = -EFAULT */
572 static int dp_lttpr_status_show(struct seq_file *m, void *unused)
574 struct drm_connector *connector = m->private;
575 struct amdgpu_dm_connector *aconnector =
576 to_amdgpu_dm_connector(connector);
577 struct dc_lttpr_caps caps = aconnector->dc_link->dpcd_caps.lttpr_caps;
579 if (connector->status != connector_status_connected)
582 seq_printf(m, "phy repeater count: %u (raw: 0x%x)\n",
583 dp_parse_lttpr_repeater_count(caps.phy_repeater_cnt),
584 caps.phy_repeater_cnt);
586 seq_puts(m, "phy repeater mode: ");
589 case DP_PHY_REPEATER_MODE_TRANSPARENT:
590 seq_puts(m, "transparent");
592 case DP_PHY_REPEATER_MODE_NON_TRANSPARENT:
593 seq_puts(m, "non-transparent");
596 seq_puts(m, "non lttpr");
599 seq_printf(m, "read error (raw: 0x%x)", caps.mode);
607 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
608 size_t size, loff_t *pos)
610 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
611 struct dc_link *link = connector->dc_link;
612 struct dc *dc = (struct dc *)link->dc;
614 uint32_t wr_buf_size = 40;
616 bool use_prefer_link_setting;
617 struct link_training_settings link_lane_settings = {0};
618 int max_param_num = 3;
619 uint8_t param_nums = 0;
626 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
630 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
638 if (param_nums <= 0) {
640 DRM_DEBUG_DRIVER("user data not be read\n");
644 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
645 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
646 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
648 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
652 /* get link settings: lane count, link rate */
653 use_prefer_link_setting =
654 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
655 (link->test_pattern_enabled));
657 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
659 if (use_prefer_link_setting) {
660 link_lane_settings.link_settings.lane_count =
661 link->preferred_link_setting.lane_count;
662 link_lane_settings.link_settings.link_rate =
663 link->preferred_link_setting.link_rate;
664 link_lane_settings.link_settings.link_spread =
665 link->preferred_link_setting.link_spread;
667 link_lane_settings.link_settings.lane_count =
668 link->cur_link_settings.lane_count;
669 link_lane_settings.link_settings.link_rate =
670 link->cur_link_settings.link_rate;
671 link_lane_settings.link_settings.link_spread =
672 link->cur_link_settings.link_spread;
675 /* apply phy settings from user */
676 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
677 link_lane_settings.hw_lane_settings[r].VOLTAGE_SWING =
678 (enum dc_voltage_swing) (param[0]);
679 link_lane_settings.hw_lane_settings[r].PRE_EMPHASIS =
680 (enum dc_pre_emphasis) (param[1]);
681 link_lane_settings.hw_lane_settings[r].POST_CURSOR2 =
682 (enum dc_post_cursor2) (param[2]);
685 /* program ASIC registers and DPCD registers */
686 dc_link_set_drive_settings(dc, &link_lane_settings, link);
692 /* function description
694 * set PHY layer or Link layer test pattern
695 * PHY test pattern is used for PHY SI check.
696 * Link layer test will not affect PHY SI.
698 * Reset Test Pattern:
699 * 0 = DP_TEST_PATTERN_VIDEO_MODE
701 * PHY test pattern supported:
702 * 1 = DP_TEST_PATTERN_D102
703 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
704 * 3 = DP_TEST_PATTERN_PRBS7
705 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
706 * 5 = DP_TEST_PATTERN_CP2520_1
707 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
708 * 7 = DP_TEST_PATTERN_CP2520_3
710 * DP PHY Link Training Patterns
711 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
712 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
713 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
714 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
716 * DP Link Layer Test pattern
717 * c = DP_TEST_PATTERN_COLOR_SQUARES
718 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
719 * e = DP_TEST_PATTERN_VERTICAL_BARS
720 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
721 * 10= DP_TEST_PATTERN_COLOR_RAMP
723 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
725 * --- set test pattern
726 * echo <test pattern #> > test_pattern
728 * If test pattern # is not supported, NO HW programming will be done.
729 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
730 * for the user pattern. input 10 bytes data are separated by space
732 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
734 * --- reset test pattern
735 * echo 0 > test_pattern
737 * --- HPD detection is disabled when set PHY test pattern
739 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
740 * is disable. User could unplug DP display from DP connected and plug scope to
741 * check test pattern PHY SI.
742 * If there is need unplug scope and plug DP display back, do steps below:
743 * echo 0 > phy_test_pattern
747 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
748 * driver could detect "unplug scope" and "plug DP display"
750 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
751 size_t size, loff_t *pos)
753 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
754 struct dc_link *link = connector->dc_link;
756 uint32_t wr_buf_size = 100;
757 long param[11] = {0x0};
758 int max_param_num = 11;
759 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
760 bool disable_hpd = false;
761 bool valid_test_pattern = false;
762 uint8_t param_nums = 0;
763 /* init with default 80bit custom pattern */
764 uint8_t custom_pattern[10] = {
765 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
766 0x1f, 0x7c, 0xf0, 0xc1, 0x07
768 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
769 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
770 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
771 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
772 struct link_training_settings link_training_settings = {0};
778 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
782 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
790 if (param_nums <= 0) {
792 DRM_DEBUG_DRIVER("user data not be read\n");
797 test_pattern = param[0];
799 switch (test_pattern) {
800 case DP_TEST_PATTERN_VIDEO_MODE:
801 case DP_TEST_PATTERN_COLOR_SQUARES:
802 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
803 case DP_TEST_PATTERN_VERTICAL_BARS:
804 case DP_TEST_PATTERN_HORIZONTAL_BARS:
805 case DP_TEST_PATTERN_COLOR_RAMP:
806 valid_test_pattern = true;
809 case DP_TEST_PATTERN_D102:
810 case DP_TEST_PATTERN_SYMBOL_ERROR:
811 case DP_TEST_PATTERN_PRBS7:
812 case DP_TEST_PATTERN_80BIT_CUSTOM:
813 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
814 case DP_TEST_PATTERN_TRAINING_PATTERN4:
816 valid_test_pattern = true;
820 valid_test_pattern = false;
821 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
825 if (!valid_test_pattern) {
827 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
831 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
832 for (i = 0; i < 10; i++) {
833 if ((uint8_t) param[i + 1] != 0x0)
838 /* not use default value */
839 for (i = 0; i < 10; i++)
840 custom_pattern[i] = (uint8_t) param[i + 1];
844 /* Usage: set DP physical test pattern using debugfs with normal DP
845 * panel. Then plug out DP panel and connect a scope to measure
846 * For normal video mode and test pattern generated from CRCT,
847 * they are visibile to user. So do not disable HPD.
848 * Video Mode is also set to clear the test pattern, so enable HPD
849 * because it might have been disabled after a test pattern was set.
850 * AUX depends on HPD * sequence dependent, do not move!
853 dc_link_enable_hpd(link);
855 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
856 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
857 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
859 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
860 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
861 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
863 link_training_settings.link_settings = cur_link_settings;
866 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
867 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
868 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
869 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
870 prefer_link_settings.link_rate != cur_link_settings.link_rate))
871 link_training_settings.link_settings = prefer_link_settings;
874 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
875 link_training_settings.hw_lane_settings[i] = link->cur_lane_setting[i];
877 dc_link_dp_set_test_pattern(
880 DP_TEST_PATTERN_COLOR_SPACE_RGB,
881 &link_training_settings,
885 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
886 * Then plug out DP panel and connect a scope to measure DP PHY signal.
887 * Need disable interrupt to avoid SW driver disable DP output. This is
888 * done after the test pattern is set.
890 if (valid_test_pattern && disable_hpd)
891 dc_link_disable_hpd(link);
899 * Returns the DMCUB tracebuffer contents.
900 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
902 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
904 struct amdgpu_device *adev = m->private;
905 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
906 struct dmub_fw_meta_info *fw_meta_info = NULL;
907 struct dmub_debugfs_trace_entry *entries;
909 uint32_t tbuf_size, max_entries, num_entries, first_entry, i;
914 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
918 if (adev->dm.dmub_srv)
919 fw_meta_info = &adev->dm.dmub_srv->meta_info;
921 tbuf_size = fw_meta_info ? fw_meta_info->trace_buffer_size :
922 DMUB_TRACE_BUFFER_SIZE;
923 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
924 sizeof(struct dmub_debugfs_trace_entry);
927 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
929 /* DMCUB tracebuffer is a ring. If it rolled over, print a hint that
930 * entries are being overwritten.
932 if (num_entries > max_entries)
933 seq_printf(m, "...\n");
935 first_entry = num_entries % max_entries;
936 num_entries = min(num_entries, max_entries);
938 entries = (struct dmub_debugfs_trace_entry
940 sizeof(struct dmub_debugfs_trace_header));
942 /* To print entries chronologically, start from the first entry till the
943 * top of buffer, then from base of buffer to first entry.
945 for (i = first_entry; i < num_entries; ++i) {
946 struct dmub_debugfs_trace_entry *entry = &entries[i];
949 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
950 entry->trace_code, entry->tick_count, entry->param0,
953 for (i = 0; i < first_entry; ++i) {
954 struct dmub_debugfs_trace_entry *entry = &entries[i];
957 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
958 entry->trace_code, entry->tick_count, entry->param0,
966 * Returns the DMCUB firmware state contents.
967 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
969 static int dmub_fw_state_show(struct seq_file *m, void *data)
971 struct amdgpu_device *adev = m->private;
972 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
979 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
983 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
985 return seq_write(m, state_base, state_size);
988 /* replay_capability_show() - show eDP panel replay capability
990 * The read function: replay_capability_show
991 * Shows if sink and driver has Replay capability or not.
993 * cat /sys/kernel/debug/dri/0/eDP-X/replay_capability
996 * "Sink support: no\n" - if panel doesn't support Replay
997 * "Sink support: yes\n" - if panel supports Replay
998 * "Driver support: no\n" - if driver doesn't support Replay
999 * "Driver support: yes\n" - if driver supports Replay
1001 static int replay_capability_show(struct seq_file *m, void *data)
1003 struct drm_connector *connector = m->private;
1004 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1005 struct dc_link *link = aconnector->dc_link;
1006 bool sink_support_replay = false;
1007 bool driver_support_replay = false;
1012 if (link->type == dc_connection_none)
1015 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
1018 /* If Replay is already set to support, skip the checks */
1019 if (link->replay_settings.config.replay_supported) {
1020 sink_support_replay = true;
1021 driver_support_replay = true;
1022 } else if ((amdgpu_dc_debug_mask & DC_DISABLE_REPLAY)) {
1023 sink_support_replay = amdgpu_dm_link_supports_replay(link, aconnector);
1025 struct dc *dc = link->ctx->dc;
1027 sink_support_replay = amdgpu_dm_link_supports_replay(link, aconnector);
1028 if (dc->ctx->dmub_srv && dc->ctx->dmub_srv->dmub)
1029 driver_support_replay =
1030 (bool)dc->ctx->dmub_srv->dmub->feature_caps.replay_supported;
1033 seq_printf(m, "Sink support: %s\n", str_yes_no(sink_support_replay));
1034 seq_printf(m, "Driver support: %s\n", str_yes_no(driver_support_replay));
1035 seq_printf(m, "Config support: %s\n", str_yes_no(link->replay_settings.config.replay_supported));
1040 /* psr_capability_show() - show eDP panel PSR capability
1042 * The read function: sink_psr_capability_show
1043 * Shows if sink has PSR capability or not.
1044 * If yes - the PSR version is appended
1046 * cat /sys/kernel/debug/dri/0/eDP-X/psr_capability
1049 * "Sink support: no\n" - if panel doesn't support PSR
1050 * "Sink support: yes [0x01]\n" - if panel supports PSR1
1051 * "Driver support: no\n" - if driver doesn't support PSR
1052 * "Driver support: yes [0x01]\n" - if driver supports PSR1
1054 static int psr_capability_show(struct seq_file *m, void *data)
1056 struct drm_connector *connector = m->private;
1057 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1058 struct dc_link *link = aconnector->dc_link;
1063 if (link->type == dc_connection_none)
1066 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
1069 seq_printf(m, "Sink support: %s", str_yes_no(link->dpcd_caps.psr_info.psr_version != 0));
1070 if (link->dpcd_caps.psr_info.psr_version)
1071 seq_printf(m, " [0x%02x]", link->dpcd_caps.psr_info.psr_version);
1074 seq_printf(m, "Driver support: %s", str_yes_no(link->psr_settings.psr_feature_enabled));
1075 if (link->psr_settings.psr_version)
1076 seq_printf(m, " [0x%02x]", link->psr_settings.psr_version);
1083 * Returns the current bpc for the crtc.
1084 * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_bpc
1086 static int amdgpu_current_bpc_show(struct seq_file *m, void *data)
1088 struct drm_crtc *crtc = m->private;
1089 struct drm_device *dev = crtc->dev;
1090 struct dm_crtc_state *dm_crtc_state = NULL;
1094 mutex_lock(&dev->mode_config.mutex);
1095 drm_modeset_lock(&crtc->mutex, NULL);
1096 if (crtc->state == NULL)
1099 dm_crtc_state = to_dm_crtc_state(crtc->state);
1100 if (dm_crtc_state->stream == NULL)
1103 switch (dm_crtc_state->stream->timing.display_color_depth) {
1104 case COLOR_DEPTH_666:
1107 case COLOR_DEPTH_888:
1110 case COLOR_DEPTH_101010:
1113 case COLOR_DEPTH_121212:
1116 case COLOR_DEPTH_161616:
1123 seq_printf(m, "Current: %u\n", bpc);
1127 drm_modeset_unlock(&crtc->mutex);
1128 mutex_unlock(&dev->mode_config.mutex);
1132 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_bpc);
1135 * Returns the current colorspace for the crtc.
1136 * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_colorspace
1138 static int amdgpu_current_colorspace_show(struct seq_file *m, void *data)
1140 struct drm_crtc *crtc = m->private;
1141 struct drm_device *dev = crtc->dev;
1142 struct dm_crtc_state *dm_crtc_state = NULL;
1145 mutex_lock(&dev->mode_config.mutex);
1146 drm_modeset_lock(&crtc->mutex, NULL);
1147 if (crtc->state == NULL)
1150 dm_crtc_state = to_dm_crtc_state(crtc->state);
1151 if (dm_crtc_state->stream == NULL)
1154 switch (dm_crtc_state->stream->output_color_space) {
1155 case COLOR_SPACE_SRGB:
1156 seq_puts(m, "sRGB");
1158 case COLOR_SPACE_YCBCR601:
1159 case COLOR_SPACE_YCBCR601_LIMITED:
1160 seq_puts(m, "BT601_YCC");
1162 case COLOR_SPACE_YCBCR709:
1163 case COLOR_SPACE_YCBCR709_LIMITED:
1164 seq_puts(m, "BT709_YCC");
1166 case COLOR_SPACE_ADOBERGB:
1167 seq_puts(m, "opRGB");
1169 case COLOR_SPACE_2020_RGB_FULLRANGE:
1170 seq_puts(m, "BT2020_RGB");
1172 case COLOR_SPACE_2020_YCBCR:
1173 seq_puts(m, "BT2020_YCC");
1181 drm_modeset_unlock(&crtc->mutex);
1182 mutex_unlock(&dev->mode_config.mutex);
1186 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_colorspace);
1191 * Disable dsc passthrough, i.e.,: have dsc decoding at converver, not external RX
1192 * echo 1 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
1193 * Enable dsc passthrough, i.e.,: have dsc passthrough to external RX
1194 * echo 0 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
1196 static ssize_t dp_dsc_passthrough_set(struct file *f, const char __user *buf,
1197 size_t size, loff_t *pos)
1199 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1200 char *wr_buf = NULL;
1201 uint32_t wr_buf_size = 42;
1202 int max_param_num = 1;
1204 uint8_t param_nums = 0;
1209 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1212 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1216 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1224 aconnector->dsc_settings.dsc_force_disable_passthrough = param;
1231 * Returns the HDCP capability of the Display (1.4 for now).
1233 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
1234 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
1236 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
1237 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
1239 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
1241 struct drm_connector *connector = m->private;
1242 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1243 bool hdcp_cap, hdcp2_cap;
1245 if (connector->status != connector_status_connected)
1248 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
1250 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1251 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1255 seq_printf(m, "%s ", "HDCP1.4");
1257 seq_printf(m, "%s ", "HDCP2.2");
1259 if (!hdcp_cap && !hdcp2_cap)
1260 seq_printf(m, "%s ", "None");
1268 * Returns whether the connected display is internal and not hotpluggable.
1269 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/internal_display
1271 static int internal_display_show(struct seq_file *m, void *data)
1273 struct drm_connector *connector = m->private;
1274 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1275 struct dc_link *link = aconnector->dc_link;
1277 seq_printf(m, "Internal: %u\n", link->is_internal_display);
1283 * Returns the number of segments used if ODM Combine mode is enabled.
1284 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/odm_combine_segments
1286 static int odm_combine_segments_show(struct seq_file *m, void *unused)
1288 struct drm_connector *connector = m->private;
1289 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1290 struct dc_link *link = aconnector->dc_link;
1291 struct pipe_ctx *pipe_ctx = NULL;
1292 int i, segments = -EOPNOTSUPP;
1294 for (i = 0; i < MAX_PIPES; i++) {
1295 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
1296 if (pipe_ctx->stream &&
1297 pipe_ctx->stream->link == link)
1301 if (connector->status != connector_status_connected)
1304 if (pipe_ctx != NULL && pipe_ctx->stream_res.tg->funcs->get_odm_combine_segments)
1305 pipe_ctx->stream_res.tg->funcs->get_odm_combine_segments(pipe_ctx->stream_res.tg, &segments);
1307 seq_printf(m, "%d\n", segments);
1311 /* function description
1313 * generic SDP message access for testing
1315 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
1318 * Hb0 : Secondary-Data Packet ID
1319 * Hb1 : Secondary-Data Packet type
1320 * Hb2 : Secondary-Data-packet-specific header, Byte 0
1321 * Hb3 : Secondary-Data-packet-specific header, Byte 1
1323 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
1325 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
1326 size_t size, loff_t *pos)
1329 uint8_t data[36] = {0};
1330 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1331 struct dm_crtc_state *acrtc_state;
1332 uint32_t write_size = 36;
1334 if (connector->base.status != connector_status_connected)
1340 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
1342 r = copy_from_user(data, buf, write_size);
1346 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
1351 /* function: Read link's DSC & FEC capabilities
1354 * Access it with the following command (you need to specify
1355 * connector like DP-1):
1357 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
1360 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
1362 struct drm_connector *connector = m->private;
1363 struct drm_modeset_acquire_ctx ctx;
1364 struct drm_device *dev = connector->dev;
1365 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1367 bool try_again = false;
1368 bool is_fec_supported = false;
1369 bool is_dsc_supported = false;
1370 struct dpcd_caps dpcd_caps;
1372 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1375 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1377 if (ret == -EDEADLK) {
1378 ret = drm_modeset_backoff(&ctx);
1386 if (connector->status != connector_status_connected) {
1390 dpcd_caps = aconnector->dc_link->dpcd_caps;
1391 if (aconnector->mst_output_port) {
1392 /* aconnector sets dsc_aux during get_modes call
1393 * if MST connector has it means it can either
1394 * enable DSC on the sink device or on MST branch
1397 if (aconnector->dsc_aux) {
1398 is_fec_supported = true;
1399 is_dsc_supported = true;
1402 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1403 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1405 } while (try_again);
1407 drm_modeset_drop_locks(&ctx);
1408 drm_modeset_acquire_fini(&ctx);
1410 seq_printf(m, "FEC_Sink_Support: %s\n", str_yes_no(is_fec_supported));
1411 seq_printf(m, "DSC_Sink_Support: %s\n", str_yes_no(is_dsc_supported));
1416 /* function: Trigger virtual HPD redetection on connector
1418 * This function will perform link rediscovery, link disable
1419 * and enable, and dm connector state update.
1421 * Retrigger HPD on an existing connector by echoing 1 into
1422 * its respectful "trigger_hotplug" debugfs entry:
1424 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1426 * This function can perform HPD unplug:
1428 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1431 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1432 size_t size, loff_t *pos)
1434 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1435 struct drm_connector *connector = &aconnector->base;
1436 struct dc_link *link = NULL;
1437 struct drm_device *dev = connector->dev;
1438 struct amdgpu_device *adev = drm_to_adev(dev);
1439 enum dc_connection_type new_connection_type = dc_connection_none;
1440 char *wr_buf = NULL;
1441 uint32_t wr_buf_size = 42;
1442 int max_param_num = 1;
1443 long param[1] = {0};
1444 uint8_t param_nums = 0;
1447 if (!aconnector->dc_link)
1453 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1456 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1460 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1470 if (param_nums <= 0) {
1471 DRM_DEBUG_DRIVER("user data not be read\n");
1475 mutex_lock(&aconnector->hpd_lock);
1477 /* Don't support for mst end device*/
1478 if (aconnector->mst_root) {
1479 mutex_unlock(&aconnector->hpd_lock);
1483 if (param[0] == 1) {
1485 if (!dc_link_detect_connection_type(aconnector->dc_link, &new_connection_type) &&
1486 new_connection_type != dc_connection_none)
1489 mutex_lock(&adev->dm.dc_lock);
1490 ret = dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
1491 mutex_unlock(&adev->dm.dc_lock);
1496 amdgpu_dm_update_connector_after_detect(aconnector);
1498 drm_modeset_lock_all(dev);
1499 dm_restore_drm_connector_state(dev, connector);
1500 drm_modeset_unlock_all(dev);
1502 drm_kms_helper_connector_hotplug_event(connector);
1503 } else if (param[0] == 0) {
1504 if (!aconnector->dc_link)
1507 link = aconnector->dc_link;
1509 if (link->local_sink) {
1510 dc_sink_release(link->local_sink);
1511 link->local_sink = NULL;
1514 link->dpcd_sink_count = 0;
1515 link->type = dc_connection_none;
1516 link->dongle_max_pix_clk = 0;
1518 amdgpu_dm_update_connector_after_detect(aconnector);
1520 /* If the aconnector is the root node in mst topology */
1521 if (aconnector->mst_mgr.mst_state == true)
1522 dc_link_reset_cur_dp_mst_topology(link);
1524 drm_modeset_lock_all(dev);
1525 dm_restore_drm_connector_state(dev, connector);
1526 drm_modeset_unlock_all(dev);
1528 drm_kms_helper_connector_hotplug_event(connector);
1532 mutex_unlock(&aconnector->hpd_lock);
1537 /* function: read DSC status on the connector
1539 * The read function: dp_dsc_clock_en_read
1540 * returns current status of DSC clock on the connector.
1541 * The return is a boolean flag: 1 or 0.
1543 * Access it with the following command (you need to specify
1544 * connector like DP-1):
1546 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1549 * 1 - means that DSC is currently enabled
1550 * 0 - means that DSC is disabled
1552 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1553 size_t size, loff_t *pos)
1555 char *rd_buf = NULL;
1556 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1557 struct display_stream_compressor *dsc;
1558 struct dcn_dsc_state dsc_state = {0};
1559 const uint32_t rd_buf_size = 10;
1560 struct pipe_ctx *pipe_ctx;
1562 int i, r, str_len = 10;
1564 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1569 for (i = 0; i < MAX_PIPES; i++) {
1570 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1571 if (pipe_ctx->stream &&
1572 pipe_ctx->stream->link == aconnector->dc_link &&
1573 pipe_ctx->stream->sink &&
1574 pipe_ctx->stream->sink == aconnector->dc_sink)
1578 dsc = pipe_ctx->stream_res.dsc;
1580 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1582 snprintf(rd_buf, str_len,
1584 dsc_state.dsc_clock_en);
1587 if (*pos >= rd_buf_size)
1590 r = put_user(*(rd_buf + result), buf);
1593 return r; /* r = -EFAULT */
1606 /* function: write force DSC on the connector
1608 * The write function: dp_dsc_clock_en_write
1609 * enables to force DSC on the connector.
1610 * User can write to either force enable or force disable DSC
1611 * on the next modeset or set it to driver default
1614 * 0 - default DSC enablement policy
1615 * 1 - force enable DSC on the connector
1616 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1618 * Writing DSC settings is done with the following command:
1619 * - To force enable DSC (you need to specify
1620 * connector like DP-1):
1622 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1624 * - To return to default state set the flag to zero and
1625 * let driver deal with DSC automatically
1626 * (you need to specify connector like DP-1):
1628 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1631 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1632 size_t size, loff_t *pos)
1634 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1635 struct drm_connector *connector = &aconnector->base;
1636 struct drm_device *dev = connector->dev;
1637 struct drm_crtc *crtc = NULL;
1638 struct dm_crtc_state *dm_crtc_state = NULL;
1639 struct pipe_ctx *pipe_ctx;
1641 char *wr_buf = NULL;
1642 uint32_t wr_buf_size = 42;
1643 int max_param_num = 1;
1644 long param[1] = {0};
1645 uint8_t param_nums = 0;
1650 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1653 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1657 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1665 if (param_nums <= 0) {
1666 DRM_DEBUG_DRIVER("user data not be read\n");
1671 for (i = 0; i < MAX_PIPES; i++) {
1672 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1673 if (pipe_ctx->stream &&
1674 pipe_ctx->stream->link == aconnector->dc_link &&
1675 pipe_ctx->stream->sink &&
1676 pipe_ctx->stream->sink == aconnector->dc_sink)
1680 if (!pipe_ctx->stream)
1684 mutex_lock(&dev->mode_config.mutex);
1685 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1687 if (connector->state == NULL)
1690 crtc = connector->state->crtc;
1694 drm_modeset_lock(&crtc->mutex, NULL);
1695 if (crtc->state == NULL)
1698 dm_crtc_state = to_dm_crtc_state(crtc->state);
1699 if (dm_crtc_state->stream == NULL)
1703 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1704 else if (param[0] == 2)
1705 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1707 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1709 dm_crtc_state->dsc_force_changed = true;
1713 drm_modeset_unlock(&crtc->mutex);
1714 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1715 mutex_unlock(&dev->mode_config.mutex);
1722 /* function: read DSC slice width parameter on the connector
1724 * The read function: dp_dsc_slice_width_read
1725 * returns dsc slice width used in the current configuration
1726 * The return is an integer: 0 or other positive number
1728 * Access the status with the following command:
1730 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1732 * 0 - means that DSC is disabled
1734 * Any other number more than zero represents the
1735 * slice width currently used by DSC in pixels
1738 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1739 size_t size, loff_t *pos)
1741 char *rd_buf = NULL;
1742 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1743 struct display_stream_compressor *dsc;
1744 struct dcn_dsc_state dsc_state = {0};
1745 const uint32_t rd_buf_size = 100;
1746 struct pipe_ctx *pipe_ctx;
1748 int i, r, str_len = 30;
1750 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1755 for (i = 0; i < MAX_PIPES; i++) {
1756 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1757 if (pipe_ctx->stream &&
1758 pipe_ctx->stream->link == aconnector->dc_link &&
1759 pipe_ctx->stream->sink &&
1760 pipe_ctx->stream->sink == aconnector->dc_sink)
1764 dsc = pipe_ctx->stream_res.dsc;
1766 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1768 snprintf(rd_buf, str_len,
1770 dsc_state.dsc_slice_width);
1773 if (*pos >= rd_buf_size)
1776 r = put_user(*(rd_buf + result), buf);
1779 return r; /* r = -EFAULT */
1792 /* function: write DSC slice width parameter
1794 * The write function: dp_dsc_slice_width_write
1795 * overwrites automatically generated DSC configuration
1798 * The user has to write the slice width divisible by the
1801 * Also the user has to write width in hexidecimal
1802 * rather than in decimal.
1804 * Writing DSC settings is done with the following command:
1805 * - To force overwrite slice width: (example sets to 1920 pixels)
1807 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1809 * - To stop overwriting and let driver find the optimal size,
1810 * set the width to zero:
1812 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1815 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1816 size_t size, loff_t *pos)
1818 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1819 struct pipe_ctx *pipe_ctx;
1820 struct drm_connector *connector = &aconnector->base;
1821 struct drm_device *dev = connector->dev;
1822 struct drm_crtc *crtc = NULL;
1823 struct dm_crtc_state *dm_crtc_state = NULL;
1825 char *wr_buf = NULL;
1826 uint32_t wr_buf_size = 42;
1827 int max_param_num = 1;
1828 long param[1] = {0};
1829 uint8_t param_nums = 0;
1834 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1837 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1841 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1849 if (param_nums <= 0) {
1850 DRM_DEBUG_DRIVER("user data not be read\n");
1855 for (i = 0; i < MAX_PIPES; i++) {
1856 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1857 if (pipe_ctx->stream &&
1858 pipe_ctx->stream->link == aconnector->dc_link &&
1859 pipe_ctx->stream->sink &&
1860 pipe_ctx->stream->sink == aconnector->dc_sink)
1864 if (!pipe_ctx->stream)
1867 // Safely get CRTC state
1868 mutex_lock(&dev->mode_config.mutex);
1869 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1871 if (connector->state == NULL)
1874 crtc = connector->state->crtc;
1878 drm_modeset_lock(&crtc->mutex, NULL);
1879 if (crtc->state == NULL)
1882 dm_crtc_state = to_dm_crtc_state(crtc->state);
1883 if (dm_crtc_state->stream == NULL)
1887 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1888 pipe_ctx->stream->timing.h_addressable,
1891 aconnector->dsc_settings.dsc_num_slices_h = 0;
1893 dm_crtc_state->dsc_force_changed = true;
1897 drm_modeset_unlock(&crtc->mutex);
1898 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1899 mutex_unlock(&dev->mode_config.mutex);
1906 /* function: read DSC slice height parameter on the connector
1908 * The read function: dp_dsc_slice_height_read
1909 * returns dsc slice height used in the current configuration
1910 * The return is an integer: 0 or other positive number
1912 * Access the status with the following command:
1914 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1916 * 0 - means that DSC is disabled
1918 * Any other number more than zero represents the
1919 * slice height currently used by DSC in pixels
1922 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1923 size_t size, loff_t *pos)
1925 char *rd_buf = NULL;
1926 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1927 struct display_stream_compressor *dsc;
1928 struct dcn_dsc_state dsc_state = {0};
1929 const uint32_t rd_buf_size = 100;
1930 struct pipe_ctx *pipe_ctx;
1932 int i, r, str_len = 30;
1934 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1939 for (i = 0; i < MAX_PIPES; i++) {
1940 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1941 if (pipe_ctx->stream &&
1942 pipe_ctx->stream->link == aconnector->dc_link &&
1943 pipe_ctx->stream->sink &&
1944 pipe_ctx->stream->sink == aconnector->dc_sink)
1948 dsc = pipe_ctx->stream_res.dsc;
1950 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1952 snprintf(rd_buf, str_len,
1954 dsc_state.dsc_slice_height);
1957 if (*pos >= rd_buf_size)
1960 r = put_user(*(rd_buf + result), buf);
1963 return r; /* r = -EFAULT */
1976 /* function: write DSC slice height parameter
1978 * The write function: dp_dsc_slice_height_write
1979 * overwrites automatically generated DSC configuration
1982 * The user has to write the slice height divisible by the
1985 * Also the user has to write height in hexidecimal
1986 * rather than in decimal.
1988 * Writing DSC settings is done with the following command:
1989 * - To force overwrite slice height (example sets to 128 pixels):
1991 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1993 * - To stop overwriting and let driver find the optimal size,
1994 * set the height to zero:
1996 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1999 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
2000 size_t size, loff_t *pos)
2002 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2003 struct drm_connector *connector = &aconnector->base;
2004 struct drm_device *dev = connector->dev;
2005 struct drm_crtc *crtc = NULL;
2006 struct dm_crtc_state *dm_crtc_state = NULL;
2007 struct pipe_ctx *pipe_ctx;
2009 char *wr_buf = NULL;
2010 uint32_t wr_buf_size = 42;
2011 int max_param_num = 1;
2012 uint8_t param_nums = 0;
2013 long param[1] = {0};
2018 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2021 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2025 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2033 if (param_nums <= 0) {
2034 DRM_DEBUG_DRIVER("user data not be read\n");
2039 for (i = 0; i < MAX_PIPES; i++) {
2040 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2041 if (pipe_ctx->stream &&
2042 pipe_ctx->stream->link == aconnector->dc_link &&
2043 pipe_ctx->stream->sink &&
2044 pipe_ctx->stream->sink == aconnector->dc_sink)
2048 if (!pipe_ctx->stream)
2052 mutex_lock(&dev->mode_config.mutex);
2053 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2055 if (connector->state == NULL)
2058 crtc = connector->state->crtc;
2062 drm_modeset_lock(&crtc->mutex, NULL);
2063 if (crtc->state == NULL)
2066 dm_crtc_state = to_dm_crtc_state(crtc->state);
2067 if (dm_crtc_state->stream == NULL)
2071 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
2072 pipe_ctx->stream->timing.v_addressable,
2075 aconnector->dsc_settings.dsc_num_slices_v = 0;
2077 dm_crtc_state->dsc_force_changed = true;
2081 drm_modeset_unlock(&crtc->mutex);
2082 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2083 mutex_unlock(&dev->mode_config.mutex);
2090 /* function: read DSC target rate on the connector in bits per pixel
2092 * The read function: dp_dsc_bits_per_pixel_read
2093 * returns target rate of compression in bits per pixel
2094 * The return is an integer: 0 or other positive integer
2096 * Access it with the following command:
2098 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2100 * 0 - means that DSC is disabled
2102 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
2103 size_t size, loff_t *pos)
2105 char *rd_buf = NULL;
2106 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2107 struct display_stream_compressor *dsc;
2108 struct dcn_dsc_state dsc_state = {0};
2109 const uint32_t rd_buf_size = 100;
2110 struct pipe_ctx *pipe_ctx;
2112 int i, r, str_len = 30;
2114 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
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->stream &&
2122 pipe_ctx->stream->link == aconnector->dc_link &&
2123 pipe_ctx->stream->sink &&
2124 pipe_ctx->stream->sink == aconnector->dc_sink)
2128 dsc = pipe_ctx->stream_res.dsc;
2130 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2132 snprintf(rd_buf, str_len,
2134 dsc_state.dsc_bits_per_pixel);
2137 if (*pos >= rd_buf_size)
2140 r = put_user(*(rd_buf + result), buf);
2143 return r; /* r = -EFAULT */
2156 /* function: write DSC target rate in bits per pixel
2158 * The write function: dp_dsc_bits_per_pixel_write
2159 * overwrites automatically generated DSC configuration
2160 * of DSC target bit rate.
2162 * Also the user has to write bpp in hexidecimal
2163 * rather than in decimal.
2165 * Writing DSC settings is done with the following command:
2166 * - To force overwrite rate (example sets to 256 bpp x 1/16):
2168 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2170 * - To stop overwriting and let driver find the optimal rate,
2171 * set the rate to zero:
2173 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2176 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
2177 size_t size, loff_t *pos)
2179 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2180 struct drm_connector *connector = &aconnector->base;
2181 struct drm_device *dev = connector->dev;
2182 struct drm_crtc *crtc = NULL;
2183 struct dm_crtc_state *dm_crtc_state = NULL;
2184 struct pipe_ctx *pipe_ctx;
2186 char *wr_buf = NULL;
2187 uint32_t wr_buf_size = 42;
2188 int max_param_num = 1;
2189 uint8_t param_nums = 0;
2190 long param[1] = {0};
2195 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2198 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2202 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2210 if (param_nums <= 0) {
2211 DRM_DEBUG_DRIVER("user data not be read\n");
2216 for (i = 0; i < MAX_PIPES; i++) {
2217 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2218 if (pipe_ctx->stream &&
2219 pipe_ctx->stream->link == aconnector->dc_link &&
2220 pipe_ctx->stream->sink &&
2221 pipe_ctx->stream->sink == aconnector->dc_sink)
2225 if (!pipe_ctx->stream)
2229 mutex_lock(&dev->mode_config.mutex);
2230 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2232 if (connector->state == NULL)
2235 crtc = connector->state->crtc;
2239 drm_modeset_lock(&crtc->mutex, NULL);
2240 if (crtc->state == NULL)
2243 dm_crtc_state = to_dm_crtc_state(crtc->state);
2244 if (dm_crtc_state->stream == NULL)
2247 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
2249 dm_crtc_state->dsc_force_changed = true;
2253 drm_modeset_unlock(&crtc->mutex);
2254 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2255 mutex_unlock(&dev->mode_config.mutex);
2262 /* function: read DSC picture width parameter on the connector
2264 * The read function: dp_dsc_pic_width_read
2265 * returns dsc picture width used in the current configuration
2266 * It is the same as h_addressable of the current
2268 * The return is an integer: 0 or other positive integer
2269 * If 0 then DSC is disabled.
2271 * Access it with the following command:
2273 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
2275 * 0 - means that DSC is disabled
2277 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
2278 size_t size, loff_t *pos)
2280 char *rd_buf = NULL;
2281 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2282 struct display_stream_compressor *dsc;
2283 struct dcn_dsc_state dsc_state = {0};
2284 const uint32_t rd_buf_size = 100;
2285 struct pipe_ctx *pipe_ctx;
2287 int i, r, str_len = 30;
2289 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2294 for (i = 0; i < MAX_PIPES; i++) {
2295 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2296 if (pipe_ctx->stream &&
2297 pipe_ctx->stream->link == aconnector->dc_link &&
2298 pipe_ctx->stream->sink &&
2299 pipe_ctx->stream->sink == aconnector->dc_sink)
2303 dsc = pipe_ctx->stream_res.dsc;
2305 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2307 snprintf(rd_buf, str_len,
2309 dsc_state.dsc_pic_width);
2312 if (*pos >= rd_buf_size)
2315 r = put_user(*(rd_buf + result), buf);
2318 return r; /* r = -EFAULT */
2331 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
2332 size_t size, loff_t *pos)
2334 char *rd_buf = NULL;
2335 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2336 struct display_stream_compressor *dsc;
2337 struct dcn_dsc_state dsc_state = {0};
2338 const uint32_t rd_buf_size = 100;
2339 struct pipe_ctx *pipe_ctx;
2341 int i, r, str_len = 30;
2343 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2348 for (i = 0; i < MAX_PIPES; i++) {
2349 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2350 if (pipe_ctx->stream &&
2351 pipe_ctx->stream->link == aconnector->dc_link &&
2352 pipe_ctx->stream->sink &&
2353 pipe_ctx->stream->sink == aconnector->dc_sink)
2357 dsc = pipe_ctx->stream_res.dsc;
2359 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2361 snprintf(rd_buf, str_len,
2363 dsc_state.dsc_pic_height);
2366 if (*pos >= rd_buf_size)
2369 r = put_user(*(rd_buf + result), buf);
2372 return r; /* r = -EFAULT */
2385 /* function: read DSC chunk size parameter on the connector
2387 * The read function: dp_dsc_chunk_size_read
2388 * returns dsc chunk size set in the current configuration
2389 * The value is calculated automatically by DSC code
2390 * and depends on slice parameters and bpp target rate
2391 * The return is an integer: 0 or other positive integer
2392 * If 0 then DSC is disabled.
2394 * Access it with the following command:
2396 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2398 * 0 - means that DSC is disabled
2400 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2401 size_t size, loff_t *pos)
2403 char *rd_buf = NULL;
2404 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2405 struct display_stream_compressor *dsc;
2406 struct dcn_dsc_state dsc_state = {0};
2407 const uint32_t rd_buf_size = 100;
2408 struct pipe_ctx *pipe_ctx;
2410 int i, r, str_len = 30;
2412 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2417 for (i = 0; i < MAX_PIPES; i++) {
2418 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2419 if (pipe_ctx->stream &&
2420 pipe_ctx->stream->link == aconnector->dc_link &&
2421 pipe_ctx->stream->sink &&
2422 pipe_ctx->stream->sink == aconnector->dc_sink)
2426 dsc = pipe_ctx->stream_res.dsc;
2428 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2430 snprintf(rd_buf, str_len,
2432 dsc_state.dsc_chunk_size);
2435 if (*pos >= rd_buf_size)
2438 r = put_user(*(rd_buf + result), buf);
2441 return r; /* r = -EFAULT */
2454 /* function: read DSC slice bpg offset on the connector
2456 * The read function: dp_dsc_slice_bpg_offset_read
2457 * returns dsc bpg slice offset set in the current configuration
2458 * The value is calculated automatically by DSC code
2459 * and depends on slice parameters and bpp target rate
2460 * The return is an integer: 0 or other positive integer
2461 * If 0 then DSC is disabled.
2463 * Access it with the following command:
2465 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2467 * 0 - means that DSC is disabled
2469 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2470 size_t size, loff_t *pos)
2472 char *rd_buf = NULL;
2473 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2474 struct display_stream_compressor *dsc;
2475 struct dcn_dsc_state dsc_state = {0};
2476 const uint32_t rd_buf_size = 100;
2477 struct pipe_ctx *pipe_ctx;
2479 int i, r, str_len = 30;
2481 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2486 for (i = 0; i < MAX_PIPES; i++) {
2487 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2488 if (pipe_ctx->stream &&
2489 pipe_ctx->stream->link == aconnector->dc_link &&
2490 pipe_ctx->stream->sink &&
2491 pipe_ctx->stream->sink == aconnector->dc_sink)
2495 dsc = pipe_ctx->stream_res.dsc;
2497 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2499 snprintf(rd_buf, str_len,
2501 dsc_state.dsc_slice_bpg_offset);
2504 if (*pos >= rd_buf_size)
2507 r = put_user(*(rd_buf + result), buf);
2510 return r; /* r = -EFAULT */
2525 * function description: Read max_requested_bpc property from the connector
2527 * Access it with the following command:
2529 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2532 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2533 size_t size, loff_t *pos)
2535 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2536 struct drm_connector *connector = &aconnector->base;
2537 struct drm_device *dev = connector->dev;
2538 struct dm_connector_state *state;
2540 char *rd_buf = NULL;
2541 char *rd_buf_ptr = NULL;
2542 const uint32_t rd_buf_size = 10;
2545 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2550 mutex_lock(&dev->mode_config.mutex);
2551 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2553 if (connector->state == NULL)
2556 state = to_dm_connector_state(connector->state);
2558 rd_buf_ptr = rd_buf;
2559 snprintf(rd_buf_ptr, rd_buf_size,
2561 state->base.max_requested_bpc);
2564 if (*pos >= rd_buf_size)
2567 r = put_user(*(rd_buf + result), buf);
2569 result = r; /* r = -EFAULT */
2578 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2579 mutex_unlock(&dev->mode_config.mutex);
2586 * function description: Set max_requested_bpc property on the connector
2588 * This function will not force the input BPC on connector, it will only
2589 * change the max value. This is equivalent to setting max_bpc through
2592 * The BPC value written must be >= 6 and <= 16. Values outside of this
2593 * range will result in errors.
2602 * Write the max_bpc in the following way:
2604 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2607 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2608 size_t size, loff_t *pos)
2610 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2611 struct drm_connector *connector = &aconnector->base;
2612 struct dm_connector_state *state;
2613 struct drm_device *dev = connector->dev;
2614 char *wr_buf = NULL;
2615 uint32_t wr_buf_size = 42;
2616 int max_param_num = 1;
2617 long param[1] = {0};
2618 uint8_t param_nums = 0;
2623 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2626 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2630 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2638 if (param_nums <= 0) {
2639 DRM_DEBUG_DRIVER("user data not be read\n");
2644 if (param[0] < 6 || param[0] > 16) {
2645 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2650 mutex_lock(&dev->mode_config.mutex);
2651 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2653 if (connector->state == NULL)
2656 state = to_dm_connector_state(connector->state);
2657 state->base.max_requested_bpc = param[0];
2659 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2660 mutex_unlock(&dev->mode_config.mutex);
2667 * IPS status. Read only.
2669 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_ips_status
2671 static int ips_status_show(struct seq_file *m, void *unused)
2673 struct amdgpu_device *adev = m->private;
2674 struct dc *dc = adev->dm.dc;
2675 struct dc_dmub_srv *dc_dmub_srv;
2677 seq_printf(m, "IPS config: %d\n", dc->config.disable_ips);
2678 seq_printf(m, "Idle optimization: %d\n", dc->idle_optimizations_allowed);
2680 if (adev->dm.idle_workqueue) {
2681 seq_printf(m, "Idle workqueue - enabled: %d\n", adev->dm.idle_workqueue->enable);
2682 seq_printf(m, "Idle workqueue - running: %d\n", adev->dm.idle_workqueue->running);
2685 dc_dmub_srv = dc->ctx->dmub_srv;
2686 if (dc_dmub_srv && dc_dmub_srv->dmub) {
2687 uint32_t rcg_count, ips1_count, ips2_count;
2688 volatile const struct dmub_shared_state_ips_fw *ips_fw =
2689 &dc_dmub_srv->dmub->shared_state[DMUB_SHARED_SHARE_FEATURE__IPS_FW].data.ips_fw;
2690 rcg_count = ips_fw->rcg_entry_count;
2691 ips1_count = ips_fw->ips1_entry_count;
2692 ips2_count = ips_fw->ips2_entry_count;
2693 seq_printf(m, "entry counts: rcg=%u ips1=%u ips2=%u\n",
2697 rcg_count = ips_fw->rcg_exit_count;
2698 ips1_count = ips_fw->ips1_exit_count;
2699 ips2_count = ips_fw->ips2_exit_count;
2700 seq_printf(m, "exit counts: rcg=%u ips1=%u ips2=%u",
2710 * Backlight at this moment. Read only.
2711 * As written to display, taking ABM and backlight lut into account.
2712 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2714 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/current_backlight
2716 static int current_backlight_show(struct seq_file *m, void *unused)
2718 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2719 struct dc_link *link = aconnector->dc_link;
2720 unsigned int backlight;
2722 backlight = dc_link_get_backlight_level(link);
2723 seq_printf(m, "0x%x\n", backlight);
2729 * Backlight value that is being approached. Read only.
2730 * As written to display, taking ABM and backlight lut into account.
2731 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2733 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/target_backlight
2735 static int target_backlight_show(struct seq_file *m, void *unused)
2737 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2738 struct dc_link *link = aconnector->dc_link;
2739 unsigned int backlight;
2741 backlight = dc_link_get_target_backlight_pwm(link);
2742 seq_printf(m, "0x%x\n", backlight);
2748 * function description: Determine if the connector is mst connector
2750 * This function helps to determine whether a connector is a mst connector.
2751 * - "root" stands for the root connector of the topology
2752 * - "branch" stands for branch device of the topology
2753 * - "end" stands for leaf node connector of the topology
2754 * - "no" stands for the connector is not a device of a mst topology
2755 * Access it with the following command:
2757 * cat /sys/kernel/debug/dri/0/DP-X/is_mst_connector
2760 static int dp_is_mst_connector_show(struct seq_file *m, void *unused)
2762 struct drm_connector *connector = m->private;
2763 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2764 struct drm_dp_mst_topology_mgr *mgr = NULL;
2765 struct drm_dp_mst_port *port = NULL;
2768 mutex_lock(&aconnector->hpd_lock);
2770 if (aconnector->mst_mgr.mst_state) {
2772 } else if (aconnector->mst_root &&
2773 aconnector->mst_root->mst_mgr.mst_state) {
2777 mgr = &aconnector->mst_root->mst_mgr;
2778 port = aconnector->mst_output_port;
2780 drm_modeset_lock(&mgr->base.lock, NULL);
2781 if (port->pdt == DP_PEER_DEVICE_MST_BRANCHING &&
2784 drm_modeset_unlock(&mgr->base.lock);
2790 seq_printf(m, "%s\n", role);
2792 mutex_unlock(&aconnector->hpd_lock);
2798 * function description: Read out the mst progress status
2800 * This function helps to determine the mst progress status of
2803 * Access it with the following command:
2805 * cat /sys/kernel/debug/dri/0/DP-X/mst_progress_status
2808 static int dp_mst_progress_status_show(struct seq_file *m, void *unused)
2810 struct drm_connector *connector = m->private;
2811 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2812 struct amdgpu_device *adev = drm_to_adev(connector->dev);
2815 mutex_lock(&aconnector->hpd_lock);
2816 mutex_lock(&adev->dm.dc_lock);
2818 if (aconnector->mst_status == MST_STATUS_DEFAULT) {
2819 seq_puts(m, "disabled\n");
2821 for (i = 0; i < sizeof(mst_progress_status)/sizeof(char *); i++)
2822 seq_printf(m, "%s:%s\n",
2823 mst_progress_status[i],
2824 aconnector->mst_status & BIT(i) ? "done" : "not_done");
2827 mutex_unlock(&adev->dm.dc_lock);
2828 mutex_unlock(&aconnector->hpd_lock);
2834 * Reports whether the connected display is a USB4 DPIA tunneled display
2835 * Example usage: cat /sys/kernel/debug/dri/0/DP-8/is_dpia_link
2837 static int is_dpia_link_show(struct seq_file *m, void *data)
2839 struct drm_connector *connector = m->private;
2840 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2841 struct dc_link *link = aconnector->dc_link;
2843 if (connector->status != connector_status_connected)
2846 seq_printf(m, "%s\n", (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) ? "yes" :
2847 (link->ep_type == DISPLAY_ENDPOINT_PHY) ? "no" : "unknown");
2853 * hdmi_cec_state_show - Read out the HDMI-CEC feature status
2854 * @m: sequence file.
2857 * Return 0 on success
2859 static int hdmi_cec_state_show(struct seq_file *m, void *data)
2861 struct drm_connector *connector = m->private;
2862 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2864 seq_printf(m, "%s:%d\n", connector->name, connector->base.id);
2865 seq_printf(m, "HDMI-CEC status: %d\n", aconnector->notifier ? 1 : 0);
2871 * hdmi_cec_state_write - Enable/Disable HDMI-CEC feature from driver side
2872 * @f: file structure.
2873 * @buf: userspace buffer. set to '1' to enable; '0' to disable cec feature.
2874 * @size: size of buffer from userpsace.
2877 * Return size on success, error code on failure
2879 static ssize_t hdmi_cec_state_write(struct file *f, const char __user *buf,
2880 size_t size, loff_t *pos)
2884 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2885 struct drm_device *ddev = aconnector->base.dev;
2890 ret = kstrtobool_from_user(buf, size, &enable);
2892 drm_dbg_driver(ddev, "invalid user data !\n");
2897 if (aconnector->notifier)
2899 ret = amdgpu_dm_initialize_hdmi_connector(aconnector);
2902 hdmi_cec_set_edid(aconnector);
2904 if (!aconnector->notifier)
2906 cec_notifier_conn_unregister(aconnector->notifier);
2907 aconnector->notifier = NULL;
2913 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2914 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2915 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2916 DEFINE_SHOW_ATTRIBUTE(dp_lttpr_status);
2917 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2918 DEFINE_SHOW_ATTRIBUTE(internal_display);
2919 DEFINE_SHOW_ATTRIBUTE(odm_combine_segments);
2920 DEFINE_SHOW_ATTRIBUTE(replay_capability);
2921 DEFINE_SHOW_ATTRIBUTE(psr_capability);
2922 DEFINE_SHOW_ATTRIBUTE(dp_is_mst_connector);
2923 DEFINE_SHOW_ATTRIBUTE(dp_mst_progress_status);
2924 DEFINE_SHOW_ATTRIBUTE(is_dpia_link);
2925 DEFINE_SHOW_STORE_ATTRIBUTE(hdmi_cec_state);
2927 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2928 .owner = THIS_MODULE,
2929 .read = dp_dsc_clock_en_read,
2930 .write = dp_dsc_clock_en_write,
2931 .llseek = default_llseek
2934 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2935 .owner = THIS_MODULE,
2936 .read = dp_dsc_slice_width_read,
2937 .write = dp_dsc_slice_width_write,
2938 .llseek = default_llseek
2941 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2942 .owner = THIS_MODULE,
2943 .read = dp_dsc_slice_height_read,
2944 .write = dp_dsc_slice_height_write,
2945 .llseek = default_llseek
2948 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2949 .owner = THIS_MODULE,
2950 .read = dp_dsc_bits_per_pixel_read,
2951 .write = dp_dsc_bits_per_pixel_write,
2952 .llseek = default_llseek
2955 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2956 .owner = THIS_MODULE,
2957 .read = dp_dsc_pic_width_read,
2958 .llseek = default_llseek
2961 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2962 .owner = THIS_MODULE,
2963 .read = dp_dsc_pic_height_read,
2964 .llseek = default_llseek
2967 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2968 .owner = THIS_MODULE,
2969 .read = dp_dsc_chunk_size_read,
2970 .llseek = default_llseek
2973 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2974 .owner = THIS_MODULE,
2975 .read = dp_dsc_slice_bpg_offset_read,
2976 .llseek = default_llseek
2979 static const struct file_operations trigger_hotplug_debugfs_fops = {
2980 .owner = THIS_MODULE,
2981 .write = trigger_hotplug,
2982 .llseek = default_llseek
2985 static const struct file_operations dp_link_settings_debugfs_fops = {
2986 .owner = THIS_MODULE,
2987 .read = dp_link_settings_read,
2988 .write = dp_link_settings_write,
2989 .llseek = default_llseek
2992 static const struct file_operations dp_phy_settings_debugfs_fop = {
2993 .owner = THIS_MODULE,
2994 .read = dp_phy_settings_read,
2995 .write = dp_phy_settings_write,
2996 .llseek = default_llseek
2999 static const struct file_operations dp_phy_test_pattern_fops = {
3000 .owner = THIS_MODULE,
3001 .write = dp_phy_test_pattern_debugfs_write,
3002 .llseek = default_llseek
3005 static const struct file_operations sdp_message_fops = {
3006 .owner = THIS_MODULE,
3007 .write = dp_sdp_message_debugfs_write,
3008 .llseek = default_llseek
3011 static const struct file_operations dp_max_bpc_debugfs_fops = {
3012 .owner = THIS_MODULE,
3013 .read = dp_max_bpc_read,
3014 .write = dp_max_bpc_write,
3015 .llseek = default_llseek
3018 static const struct file_operations dp_dsc_disable_passthrough_debugfs_fops = {
3019 .owner = THIS_MODULE,
3020 .write = dp_dsc_passthrough_set,
3021 .llseek = default_llseek
3024 static const struct file_operations dp_mst_link_settings_debugfs_fops = {
3025 .owner = THIS_MODULE,
3026 .write = dp_mst_link_setting,
3027 .llseek = default_llseek
3030 static const struct {
3032 const struct file_operations *fops;
3033 } dp_debugfs_entries[] = {
3034 {"link_settings", &dp_link_settings_debugfs_fops},
3035 {"phy_settings", &dp_phy_settings_debugfs_fop},
3036 {"lttpr_status", &dp_lttpr_status_fops},
3037 {"test_pattern", &dp_phy_test_pattern_fops},
3038 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
3039 {"sdp_message", &sdp_message_fops},
3040 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
3041 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
3042 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
3043 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
3044 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
3045 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
3046 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
3047 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
3048 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
3049 {"max_bpc", &dp_max_bpc_debugfs_fops},
3050 {"dsc_disable_passthrough", &dp_dsc_disable_passthrough_debugfs_fops},
3051 {"is_mst_connector", &dp_is_mst_connector_fops},
3052 {"mst_progress_status", &dp_mst_progress_status_fops},
3053 {"is_dpia_link", &is_dpia_link_fops},
3054 {"mst_link_settings", &dp_mst_link_settings_debugfs_fops}
3057 static const struct {
3059 const struct file_operations *fops;
3060 } hdmi_debugfs_entries[] = {
3061 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
3062 {"hdmi_cec_state", &hdmi_cec_state_fops}
3066 * Force YUV420 output if available from the given mode
3068 static int force_yuv420_output_set(void *data, u64 val)
3070 struct amdgpu_dm_connector *connector = data;
3072 connector->force_yuv420_output = (bool)val;
3078 * Check if YUV420 is forced when available from the given mode
3080 static int force_yuv420_output_get(void *data, u64 *val)
3082 struct amdgpu_dm_connector *connector = data;
3084 *val = connector->force_yuv420_output;
3089 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
3090 force_yuv420_output_set, "%llu\n");
3095 static int replay_get_state(void *data, u64 *val)
3097 struct amdgpu_dm_connector *connector = data;
3098 struct dc_link *link = connector->dc_link;
3099 uint64_t state = REPLAY_STATE_INVALID;
3101 dc_link_get_replay_state(link, &state);
3111 static int psr_get(void *data, u64 *val)
3113 struct amdgpu_dm_connector *connector = data;
3114 struct dc_link *link = connector->dc_link;
3115 enum dc_psr_state state = PSR_STATE0;
3117 dc_link_get_psr_state(link, &state);
3125 * Read PSR state residency
3127 static int psr_read_residency(void *data, u64 *val)
3129 struct amdgpu_dm_connector *connector = data;
3130 struct dc_link *link = connector->dc_link;
3133 link->dc->link_srv->edp_get_psr_residency(link, &residency, PSR_RESIDENCY_MODE_PHY);
3135 *val = (u64)residency;
3140 /* read allow_edp_hotplug_detection */
3141 static int allow_edp_hotplug_detection_get(void *data, u64 *val)
3143 struct amdgpu_dm_connector *aconnector = data;
3144 struct drm_connector *connector = &aconnector->base;
3145 struct drm_device *dev = connector->dev;
3146 struct amdgpu_device *adev = drm_to_adev(dev);
3148 *val = adev->dm.dc->config.allow_edp_hotplug_detection;
3153 /* set allow_edp_hotplug_detection */
3154 static int allow_edp_hotplug_detection_set(void *data, u64 val)
3156 struct amdgpu_dm_connector *aconnector = data;
3157 struct drm_connector *connector = &aconnector->base;
3158 struct drm_device *dev = connector->dev;
3159 struct amdgpu_device *adev = drm_to_adev(dev);
3161 adev->dm.dc->config.allow_edp_hotplug_detection = (uint32_t) val;
3166 /* check if kernel disallow eDP enter psr state
3167 * cat /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
3168 * 0: allow edp enter psr; 1: disallow
3170 static int disallow_edp_enter_psr_get(void *data, u64 *val)
3172 struct amdgpu_dm_connector *aconnector = data;
3174 *val = (u64) aconnector->disallow_edp_enter_psr;
3178 /* set kernel disallow eDP enter psr state
3179 * echo 0x0 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
3180 * 0: allow edp enter psr; 1: disallow
3182 * usage: test app read crc from PSR eDP rx.
3184 * during kernel boot up, kernel write dpcd 0x170 = 5.
3185 * this notify eDP rx psr enable and let rx check crc.
3186 * rx fw will start checking crc for rx internal logic.
3187 * crc read count within dpcd 0x246 is not updated and
3188 * value is 0. when eDP tx driver wants to read rx crc
3189 * from dpcd 0x246, 0x270, read count 0 lead tx driver
3192 * to avoid this, we add this debugfs to let test app to disbable
3193 * rx crc checking for rx internal logic. then test app can read
3194 * non-zero crc read count.
3196 * expected app sequence is as below:
3197 * 1. disable eDP PHY and notify eDP rx with dpcd 0x600 = 2.
3198 * 2. echo 0x1 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
3199 * 3. enable eDP PHY and notify eDP rx with dpcd 0x600 = 1 but
3200 * without dpcd 0x170 = 5.
3201 * 4. read crc from rx dpcd 0x270, 0x246, etc.
3202 * 5. echo 0x0 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr.
3203 * this will let eDP back to normal with psr setup dpcd 0x170 = 5.
3205 static int disallow_edp_enter_psr_set(void *data, u64 val)
3207 struct amdgpu_dm_connector *aconnector = data;
3209 aconnector->disallow_edp_enter_psr = val ? true : false;
3213 static int dmub_trace_mask_set(void *data, u64 val)
3215 struct amdgpu_device *adev = data;
3216 struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
3217 enum dmub_gpint_command cmd;
3223 if (!srv->fw_version)
3226 for (i = 0; i < 4; i++) {
3227 res = (val & mask) >> shift;
3231 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD0;
3234 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD1;
3237 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD2;
3240 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD3;
3244 if (!dc_wake_and_execute_gpint(adev->dm.dc->ctx, cmd, res, NULL, DM_DMUB_WAIT_TYPE_WAIT))
3247 usleep_range(100, 1000);
3256 static int dmub_trace_mask_show(void *data, u64 *val)
3258 enum dmub_gpint_command cmd = DMUB_GPINT__GET_TRACE_BUFFER_MASK_WORD0;
3259 struct amdgpu_device *adev = data;
3260 struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
3266 if (!srv->fw_version)
3272 if (!dc_wake_and_execute_gpint(adev->dm.dc->ctx, cmd, 0, &response, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY))
3276 usleep_range(100, 1000);
3279 res |= (raw << shift);
3289 DEFINE_DEBUGFS_ATTRIBUTE(dmub_trace_mask_fops, dmub_trace_mask_show,
3290 dmub_trace_mask_set, "0x%llx\n");
3293 * Set dmcub trace event IRQ enable or disable.
3294 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3295 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3297 static int dmcub_trace_event_state_set(void *data, u64 val)
3299 struct amdgpu_device *adev = data;
3301 if (val == 1 || val == 0) {
3302 dc_dmub_trace_event_control(adev->dm.dc, val);
3303 adev->dm.dmcub_trace_event_en = (bool)val;
3311 * The interface doesn't need get function, so it will return the
3313 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3315 static int dmcub_trace_event_state_get(void *data, u64 *val)
3317 struct amdgpu_device *adev = data;
3319 *val = adev->dm.dmcub_trace_event_en;
3323 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
3324 dmcub_trace_event_state_set, "%llu\n");
3326 DEFINE_DEBUGFS_ATTRIBUTE(replay_state_fops, replay_get_state, NULL, "%llu\n");
3328 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
3329 DEFINE_DEBUGFS_ATTRIBUTE(psr_residency_fops, psr_read_residency, NULL,
3332 DEFINE_DEBUGFS_ATTRIBUTE(allow_edp_hotplug_detection_fops,
3333 allow_edp_hotplug_detection_get,
3334 allow_edp_hotplug_detection_set, "%llu\n");
3336 DEFINE_DEBUGFS_ATTRIBUTE(disallow_edp_enter_psr_fops,
3337 disallow_edp_enter_psr_get,
3338 disallow_edp_enter_psr_set, "%llu\n");
3340 DEFINE_SHOW_ATTRIBUTE(current_backlight);
3341 DEFINE_SHOW_ATTRIBUTE(target_backlight);
3342 DEFINE_SHOW_ATTRIBUTE(ips_status);
3344 static const struct {
3346 const struct file_operations *fops;
3347 } connector_debugfs_entries[] = {
3348 {"force_yuv420_output", &force_yuv420_output_fops},
3349 {"trigger_hotplug", &trigger_hotplug_debugfs_fops},
3350 {"internal_display", &internal_display_fops},
3351 {"odm_combine_segments", &odm_combine_segments_fops}
3355 * Returns supported customized link rates by this eDP panel.
3356 * Example usage: cat /sys/kernel/debug/dri/0/eDP-x/ilr_setting
3358 static int edp_ilr_show(struct seq_file *m, void *unused)
3360 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
3361 struct dc_link *link = aconnector->dc_link;
3362 uint8_t supported_link_rates[16];
3363 uint32_t link_rate_in_khz;
3367 memset(supported_link_rates, 0, sizeof(supported_link_rates));
3368 dm_helpers_dp_read_dpcd(link->ctx, link, DP_SUPPORTED_LINK_RATES,
3369 supported_link_rates, sizeof(supported_link_rates));
3371 dpcd_rev = link->dpcd_caps.dpcd_rev.raw;
3373 if (dpcd_rev >= DP_DPCD_REV_13 &&
3374 (supported_link_rates[entry+1] != 0 || supported_link_rates[entry] != 0)) {
3376 for (entry = 0; entry < 16; entry += 2) {
3377 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
3378 supported_link_rates[entry]) * 200;
3379 seq_printf(m, "[%d] %d kHz\n", entry/2, link_rate_in_khz);
3382 seq_puts(m, "ILR is not supported by this eDP panel.\n");
3389 * Set supported customized link rate to eDP panel.
3391 * echo <lane_count> <link_rate option> > ilr_setting
3393 * for example, supported ILR : [0] 1620000 kHz [1] 2160000 kHz [2] 2430000 kHz ...
3394 * echo 4 1 > /sys/kernel/debug/dri/0/eDP-x/ilr_setting
3395 * to set 4 lanes and 2.16 GHz
3397 static ssize_t edp_ilr_write(struct file *f, const char __user *buf,
3398 size_t size, loff_t *pos)
3400 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
3401 struct dc_link *link = connector->dc_link;
3402 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
3403 struct dc *dc = (struct dc *)link->dc;
3404 struct dc_link_settings prefer_link_settings;
3405 char *wr_buf = NULL;
3406 const uint32_t wr_buf_size = 40;
3407 /* 0: lane_count; 1: link_rate */
3408 int max_param_num = 2;
3409 uint8_t param_nums = 0;
3411 bool valid_input = true;
3416 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
3420 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
3428 if (param_nums <= 0) {
3434 case LANE_COUNT_ONE:
3435 case LANE_COUNT_TWO:
3436 case LANE_COUNT_FOUR:
3439 valid_input = false;
3443 if (param[1] >= link->dpcd_caps.edp_supported_link_rates_count)
3444 valid_input = false;
3448 DRM_DEBUG_DRIVER("Invalid Input value. No HW will be programmed\n");
3449 prefer_link_settings.use_link_rate_set = false;
3450 mutex_lock(&adev->dm.dc_lock);
3451 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
3452 mutex_unlock(&adev->dm.dc_lock);
3456 /* save user force lane_count, link_rate to preferred settings
3457 * spread spectrum will not be changed
3459 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
3460 prefer_link_settings.lane_count = param[0];
3461 prefer_link_settings.use_link_rate_set = true;
3462 prefer_link_settings.link_rate_set = param[1];
3463 prefer_link_settings.link_rate = link->dpcd_caps.edp_supported_link_rates[param[1]];
3465 mutex_lock(&adev->dm.dc_lock);
3466 dc_link_set_preferred_training_settings(dc, &prefer_link_settings,
3468 mutex_unlock(&adev->dm.dc_lock);
3474 static int edp_ilr_open(struct inode *inode, struct file *file)
3476 return single_open(file, edp_ilr_show, inode->i_private);
3479 static const struct file_operations edp_ilr_debugfs_fops = {
3480 .owner = THIS_MODULE,
3481 .open = edp_ilr_open,
3483 .llseek = seq_lseek,
3484 .release = single_release,
3485 .write = edp_ilr_write
3488 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
3491 struct dentry *dir = connector->base.debugfs_entry;
3493 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
3494 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3495 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
3496 debugfs_create_file(dp_debugfs_entries[i].name,
3497 0644, dir, connector,
3498 dp_debugfs_entries[i].fops);
3501 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3502 debugfs_create_file("replay_capability", 0444, dir, connector,
3503 &replay_capability_fops);
3504 debugfs_create_file("replay_state", 0444, dir, connector, &replay_state_fops);
3505 debugfs_create_file_unsafe("psr_capability", 0444, dir, connector, &psr_capability_fops);
3506 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
3507 debugfs_create_file_unsafe("psr_residency", 0444, dir,
3508 connector, &psr_residency_fops);
3509 debugfs_create_file("amdgpu_current_backlight_pwm", 0444, dir, connector,
3510 ¤t_backlight_fops);
3511 debugfs_create_file("amdgpu_target_backlight_pwm", 0444, dir, connector,
3512 &target_backlight_fops);
3513 debugfs_create_file("ilr_setting", 0644, dir, connector,
3514 &edp_ilr_debugfs_fops);
3515 debugfs_create_file("allow_edp_hotplug_detection", 0644, dir, connector,
3516 &allow_edp_hotplug_detection_fops);
3517 debugfs_create_file("disallow_edp_enter_psr", 0644, dir, connector,
3518 &disallow_edp_enter_psr_fops);
3521 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
3522 debugfs_create_file(connector_debugfs_entries[i].name,
3523 0644, dir, connector,
3524 connector_debugfs_entries[i].fops);
3527 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
3528 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
3529 debugfs_create_file(hdmi_debugfs_entries[i].name,
3530 0644, dir, connector,
3531 hdmi_debugfs_entries[i].fops);
3536 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3538 * Set crc window coordinate x start
3540 static int crc_win_x_start_set(void *data, u64 val)
3542 struct drm_crtc *crtc = data;
3543 struct drm_device *drm_dev = crtc->dev;
3544 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3546 spin_lock_irq(&drm_dev->event_lock);
3547 acrtc->dm_irq_params.window_param[0].x_start = (uint16_t) val;
3548 acrtc->dm_irq_params.window_param[0].update_win = false;
3549 spin_unlock_irq(&drm_dev->event_lock);
3555 * Get crc window coordinate x start
3557 static int crc_win_x_start_get(void *data, u64 *val)
3559 struct drm_crtc *crtc = data;
3560 struct drm_device *drm_dev = crtc->dev;
3561 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3563 spin_lock_irq(&drm_dev->event_lock);
3564 *val = acrtc->dm_irq_params.window_param[0].x_start;
3565 spin_unlock_irq(&drm_dev->event_lock);
3570 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
3571 crc_win_x_start_set, "%llu\n");
3575 * Set crc window coordinate y start
3577 static int crc_win_y_start_set(void *data, u64 val)
3579 struct drm_crtc *crtc = data;
3580 struct drm_device *drm_dev = crtc->dev;
3581 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3583 spin_lock_irq(&drm_dev->event_lock);
3584 acrtc->dm_irq_params.window_param[0].y_start = (uint16_t) val;
3585 acrtc->dm_irq_params.window_param[0].update_win = false;
3586 spin_unlock_irq(&drm_dev->event_lock);
3592 * Get crc window coordinate y start
3594 static int crc_win_y_start_get(void *data, u64 *val)
3596 struct drm_crtc *crtc = data;
3597 struct drm_device *drm_dev = crtc->dev;
3598 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3600 spin_lock_irq(&drm_dev->event_lock);
3601 *val = acrtc->dm_irq_params.window_param[0].y_start;
3602 spin_unlock_irq(&drm_dev->event_lock);
3607 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
3608 crc_win_y_start_set, "%llu\n");
3611 * Set crc window coordinate x end
3613 static int crc_win_x_end_set(void *data, u64 val)
3615 struct drm_crtc *crtc = data;
3616 struct drm_device *drm_dev = crtc->dev;
3617 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3619 spin_lock_irq(&drm_dev->event_lock);
3620 acrtc->dm_irq_params.window_param[0].x_end = (uint16_t) val;
3621 acrtc->dm_irq_params.window_param[0].update_win = false;
3622 spin_unlock_irq(&drm_dev->event_lock);
3628 * Get crc window coordinate x end
3630 static int crc_win_x_end_get(void *data, u64 *val)
3632 struct drm_crtc *crtc = data;
3633 struct drm_device *drm_dev = crtc->dev;
3634 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3636 spin_lock_irq(&drm_dev->event_lock);
3637 *val = acrtc->dm_irq_params.window_param[0].x_end;
3638 spin_unlock_irq(&drm_dev->event_lock);
3643 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
3644 crc_win_x_end_set, "%llu\n");
3647 * Set crc window coordinate y end
3649 static int crc_win_y_end_set(void *data, u64 val)
3651 struct drm_crtc *crtc = data;
3652 struct drm_device *drm_dev = crtc->dev;
3653 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3655 spin_lock_irq(&drm_dev->event_lock);
3656 acrtc->dm_irq_params.window_param[0].y_end = (uint16_t) val;
3657 acrtc->dm_irq_params.window_param[0].update_win = false;
3658 spin_unlock_irq(&drm_dev->event_lock);
3664 * Get crc window coordinate y end
3666 static int crc_win_y_end_get(void *data, u64 *val)
3668 struct drm_crtc *crtc = data;
3669 struct drm_device *drm_dev = crtc->dev;
3670 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3672 spin_lock_irq(&drm_dev->event_lock);
3673 *val = acrtc->dm_irq_params.window_param[0].y_end;
3674 spin_unlock_irq(&drm_dev->event_lock);
3679 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
3680 crc_win_y_end_set, "%llu\n");
3682 * Trigger to commit crc window
3684 static int crc_win_update_set(void *data, u64 val)
3686 struct drm_crtc *crtc = data;
3687 struct amdgpu_crtc *acrtc;
3688 struct amdgpu_device *adev = drm_to_adev(crtc->dev);
3691 acrtc = to_amdgpu_crtc(crtc);
3692 mutex_lock(&adev->dm.dc_lock);
3693 /* PSR may write to OTG CRC window control register,
3694 * so close it before starting secure_display.
3696 amdgpu_dm_psr_disable(acrtc->dm_irq_params.stream, true);
3698 spin_lock_irq(&adev_to_drm(adev)->event_lock);
3700 acrtc->dm_irq_params.window_param[0].enable = true;
3701 acrtc->dm_irq_params.window_param[0].update_win = true;
3702 acrtc->dm_irq_params.window_param[0].skip_frame_cnt = 0;
3703 acrtc->dm_irq_params.crc_window_activated = true;
3705 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
3706 mutex_unlock(&adev->dm.dc_lock);
3713 * Get crc window update flag
3715 static int crc_win_update_get(void *data, u64 *val)
3721 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
3722 crc_win_update_set, "%llu\n");
3724 void crtc_debugfs_init(struct drm_crtc *crtc)
3726 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3727 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
3732 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
3733 &crc_win_x_start_fops);
3734 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
3735 &crc_win_y_start_fops);
3736 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
3737 &crc_win_x_end_fops);
3738 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
3739 &crc_win_y_end_fops);
3740 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
3741 &crc_win_update_fops);
3744 debugfs_create_file("amdgpu_current_bpc", 0644, crtc->debugfs_entry,
3745 crtc, &amdgpu_current_bpc_fops);
3746 debugfs_create_file("amdgpu_current_colorspace", 0644, crtc->debugfs_entry,
3747 crtc, &amdgpu_current_colorspace_fops);
3751 * Writes DTN log state to the user supplied buffer.
3752 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3754 static ssize_t dtn_log_read(
3760 struct amdgpu_device *adev = file_inode(f)->i_private;
3761 struct dc *dc = adev->dm.dc;
3762 struct dc_log_buffer_ctx log_ctx = { 0 };
3768 if (!dc->hwss.log_hw_state)
3771 dc->hwss.log_hw_state(dc, &log_ctx);
3773 if (*pos < log_ctx.pos) {
3774 size_t to_copy = log_ctx.pos - *pos;
3776 to_copy = min(to_copy, size);
3778 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
3790 * Writes DTN log state to dmesg when triggered via a write.
3791 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3793 static ssize_t dtn_log_write(
3795 const char __user *buf,
3799 struct amdgpu_device *adev = file_inode(f)->i_private;
3800 struct dc *dc = adev->dm.dc;
3802 /* Write triggers log output via dmesg. */
3806 if (dc->hwss.log_hw_state)
3807 dc->hwss.log_hw_state(dc, NULL);
3812 static int mst_topo_show(struct seq_file *m, void *unused)
3814 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3815 struct drm_device *dev = adev_to_drm(adev);
3816 struct drm_connector *connector;
3817 struct drm_connector_list_iter conn_iter;
3818 struct amdgpu_dm_connector *aconnector;
3820 drm_connector_list_iter_begin(dev, &conn_iter);
3821 drm_for_each_connector_iter(connector, &conn_iter) {
3822 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3825 aconnector = to_amdgpu_dm_connector(connector);
3827 /* Ensure we're only dumping the topology of a root mst node */
3828 if (!aconnector->mst_mgr.mst_state)
3831 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
3832 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
3834 drm_connector_list_iter_end(&conn_iter);
3840 * Sets trigger hpd for MST topologies.
3841 * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
3842 * All topologies will be disconnected if val of 0 is set .
3843 * Usage to enable topologies: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3844 * Usage to disable topologies: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3846 static int trigger_hpd_mst_set(void *data, u64 val)
3848 struct amdgpu_device *adev = data;
3849 struct drm_device *dev = adev_to_drm(adev);
3850 struct drm_connector_list_iter iter;
3851 struct amdgpu_dm_connector *aconnector;
3852 struct drm_connector *connector;
3853 struct dc_link *link = NULL;
3857 drm_connector_list_iter_begin(dev, &iter);
3858 drm_for_each_connector_iter(connector, &iter) {
3859 aconnector = to_amdgpu_dm_connector(connector);
3860 if (aconnector->dc_link->type == dc_connection_mst_branch &&
3861 aconnector->mst_mgr.aux) {
3862 mutex_lock(&adev->dm.dc_lock);
3863 ret = dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3864 mutex_unlock(&adev->dm.dc_lock);
3867 DRM_ERROR("DM_MST: Failed to detect dc link!");
3869 ret = drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
3871 DRM_ERROR("DM_MST: Failed to set the device into MST mode!");
3874 } else if (val == 0) {
3875 drm_connector_list_iter_begin(dev, &iter);
3876 drm_for_each_connector_iter(connector, &iter) {
3877 aconnector = to_amdgpu_dm_connector(connector);
3878 if (!aconnector->dc_link)
3881 if (!aconnector->mst_root)
3884 link = aconnector->dc_link;
3885 dc_link_dp_receiver_power_ctrl(link, false);
3886 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_root->mst_mgr, false);
3887 link->mst_stream_alloc_table.stream_count = 0;
3888 memset(link->mst_stream_alloc_table.stream_allocations, 0,
3889 sizeof(link->mst_stream_alloc_table.stream_allocations));
3894 drm_kms_helper_hotplug_event(dev);
3900 * The interface doesn't need get function, so it will return the
3902 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3904 static int trigger_hpd_mst_get(void *data, u64 *val)
3910 DEFINE_DEBUGFS_ATTRIBUTE(trigger_hpd_mst_ops, trigger_hpd_mst_get,
3911 trigger_hpd_mst_set, "%llu\n");
3915 * Sets the force_timing_sync debug option from the given string.
3916 * All connected displays will be force synchronized immediately.
3917 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3919 static int force_timing_sync_set(void *data, u64 val)
3921 struct amdgpu_device *adev = data;
3923 adev->dm.force_timing_sync = (bool)val;
3925 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
3931 * Gets the force_timing_sync debug option value into the given buffer.
3932 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3934 static int force_timing_sync_get(void *data, u64 *val)
3936 struct amdgpu_device *adev = data;
3938 *val = adev->dm.force_timing_sync;
3943 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
3944 force_timing_sync_set, "%llu\n");
3948 * Disables all HPD and HPD RX interrupt handling in the
3949 * driver when set to 1. Default is 0.
3951 static int disable_hpd_set(void *data, u64 val)
3953 struct amdgpu_device *adev = data;
3955 adev->dm.disable_hpd_irq = (bool)val;
3962 * Returns 1 if HPD and HPRX interrupt handling is disabled,
3965 static int disable_hpd_get(void *data, u64 *val)
3967 struct amdgpu_device *adev = data;
3969 *val = adev->dm.disable_hpd_irq;
3974 DEFINE_DEBUGFS_ATTRIBUTE(disable_hpd_ops, disable_hpd_get,
3975 disable_hpd_set, "%llu\n");
3978 * Prints hardware capabilities. These are used for IGT testing.
3980 static int capabilities_show(struct seq_file *m, void *unused)
3982 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3983 struct dc *dc = adev->dm.dc;
3984 bool mall_supported = dc->caps.mall_size_total;
3985 bool subvp_supported = dc->caps.subvp_fw_processing_delay_us;
3986 unsigned int mall_in_use = false;
3987 unsigned int subvp_in_use = false;
3989 struct hubbub *hubbub = dc->res_pool->hubbub;
3991 if (hubbub->funcs->get_mall_en)
3992 hubbub->funcs->get_mall_en(hubbub, &mall_in_use);
3994 if (dc->cap_funcs.get_subvp_en)
3995 subvp_in_use = dc->cap_funcs.get_subvp_en(dc, dc->current_state);
3997 seq_printf(m, "mall supported: %s, enabled: %s\n",
3998 mall_supported ? "yes" : "no", mall_in_use ? "yes" : "no");
3999 seq_printf(m, "sub-viewport supported: %s, enabled: %s\n",
4000 subvp_supported ? "yes" : "no", subvp_in_use ? "yes" : "no");
4005 DEFINE_SHOW_ATTRIBUTE(capabilities);
4008 * Temporary w/a to force sst sequence in M42D DP2 mst receiver
4009 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_set_mst_en_for_sst
4011 static int dp_force_sst_set(void *data, u64 val)
4013 struct amdgpu_device *adev = data;
4015 adev->dm.dc->debug.set_mst_en_for_sst = val;
4020 static int dp_force_sst_get(void *data, u64 *val)
4022 struct amdgpu_device *adev = data;
4024 *val = adev->dm.dc->debug.set_mst_en_for_sst;
4028 DEFINE_DEBUGFS_ATTRIBUTE(dp_set_mst_en_for_sst_ops, dp_force_sst_get,
4029 dp_force_sst_set, "%llu\n");
4032 * Force DP2 sequence without VESA certified cable.
4033 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_ignore_cable_id
4035 static int dp_ignore_cable_id_set(void *data, u64 val)
4037 struct amdgpu_device *adev = data;
4039 adev->dm.dc->debug.ignore_cable_id = val;
4044 static int dp_ignore_cable_id_get(void *data, u64 *val)
4046 struct amdgpu_device *adev = data;
4048 *val = adev->dm.dc->debug.ignore_cable_id;
4052 DEFINE_DEBUGFS_ATTRIBUTE(dp_ignore_cable_id_ops, dp_ignore_cable_id_get,
4053 dp_ignore_cable_id_set, "%llu\n");
4056 * Sets the DC visual confirm debug option from the given string.
4057 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
4059 static int visual_confirm_set(void *data, u64 val)
4061 struct amdgpu_device *adev = data;
4063 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
4069 * Reads the DC visual confirm debug option value into the given buffer.
4070 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
4072 static int visual_confirm_get(void *data, u64 *val)
4074 struct amdgpu_device *adev = data;
4076 *val = adev->dm.dc->debug.visual_confirm;
4081 DEFINE_SHOW_ATTRIBUTE(mst_topo);
4082 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
4083 visual_confirm_set, "%llu\n");
4087 * Sets the DC skip_detection_link_training debug option from the given string.
4088 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_skip_detection_link_training
4090 static int skip_detection_link_training_set(void *data, u64 val)
4092 struct amdgpu_device *adev = data;
4095 adev->dm.dc->debug.skip_detection_link_training = false;
4097 adev->dm.dc->debug.skip_detection_link_training = true;
4103 * Reads the DC skip_detection_link_training debug option value into the given buffer.
4104 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_skip_detection_link_training
4106 static int skip_detection_link_training_get(void *data, u64 *val)
4108 struct amdgpu_device *adev = data;
4110 *val = adev->dm.dc->debug.skip_detection_link_training;
4115 DEFINE_DEBUGFS_ATTRIBUTE(skip_detection_link_training_fops,
4116 skip_detection_link_training_get,
4117 skip_detection_link_training_set, "%llu\n");
4120 * Dumps the DCC_EN bit for each pipe.
4121 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dcc_en
4123 static ssize_t dcc_en_bits_read(
4129 struct amdgpu_device *adev = file_inode(f)->i_private;
4130 struct dc *dc = adev->dm.dc;
4131 char *rd_buf = NULL;
4132 const uint32_t rd_buf_size = 32;
4133 uint32_t result = 0;
4135 int num_pipes = dc->res_pool->pipe_count;
4139 dcc_en_bits = kcalloc(num_pipes, sizeof(int), GFP_KERNEL);
4143 if (!dc->hwss.get_dcc_en_bits) {
4148 dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
4150 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
4156 for (i = 0; i < num_pipes; i++)
4157 offset += snprintf(rd_buf + offset, rd_buf_size - offset,
4158 "%d ", dcc_en_bits[i]);
4159 rd_buf[strlen(rd_buf)] = '\n';
4164 if (*pos >= rd_buf_size)
4166 r = put_user(*(rd_buf + result), buf);
4169 return r; /* r = -EFAULT */
4181 void dtn_debugfs_init(struct amdgpu_device *adev)
4183 static const struct file_operations dtn_log_fops = {
4184 .owner = THIS_MODULE,
4185 .read = dtn_log_read,
4186 .write = dtn_log_write,
4187 .llseek = default_llseek
4189 static const struct file_operations dcc_en_bits_fops = {
4190 .owner = THIS_MODULE,
4191 .read = dcc_en_bits_read,
4192 .llseek = default_llseek
4195 struct drm_minor *minor = adev_to_drm(adev)->primary;
4196 struct dentry *root = minor->debugfs_root;
4198 debugfs_create_file("amdgpu_mst_topology", 0444, root,
4199 adev, &mst_topo_fops);
4200 debugfs_create_file("amdgpu_dm_capabilities", 0444, root,
4201 adev, &capabilities_fops);
4202 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
4204 debugfs_create_file("amdgpu_dm_dp_set_mst_en_for_sst", 0644, root, adev,
4205 &dp_set_mst_en_for_sst_ops);
4206 debugfs_create_file("amdgpu_dm_dp_ignore_cable_id", 0644, root, adev,
4207 &dp_ignore_cable_id_ops);
4209 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
4210 &visual_confirm_fops);
4212 debugfs_create_file_unsafe("amdgpu_dm_skip_detection_link_training", 0644, root, adev,
4213 &skip_detection_link_training_fops);
4215 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
4216 adev, &dmub_tracebuffer_fops);
4218 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
4219 adev, &dmub_fw_state_fops);
4221 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
4222 adev, &force_timing_sync_ops);
4224 debugfs_create_file_unsafe("amdgpu_dm_dmub_trace_mask", 0644, root,
4225 adev, &dmub_trace_mask_fops);
4227 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
4228 adev, &dmcub_trace_event_state_fops);
4230 debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
4231 adev, &trigger_hpd_mst_ops);
4233 debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
4236 debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,
4239 if (adev->dm.dc->caps.ips_support)
4240 debugfs_create_file_unsafe("amdgpu_dm_ips_status", 0644, root, adev,