2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/string_helpers.h>
27 #include <linux/uaccess.h>
31 #include "amdgpu_dm.h"
32 #include "amdgpu_dm_debugfs.h"
33 #include "amdgpu_dm_replay.h"
34 #include "dm_helpers.h"
35 #include "dmub/dmub_srv.h"
38 #include "link_hwss.h"
39 #include "dc/dc_dmub_srv.h"
40 #include "link/protocols/link_dp_capability.h"
41 #include "inc/hw/dchubbub.h"
43 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
44 #include "amdgpu_dm_psr.h"
47 struct dmub_debugfs_trace_header {
52 struct dmub_debugfs_trace_entry {
59 static const char *const mst_progress_status[] = {
62 "allocate_new_payload",
63 "clear_allocated_payload",
66 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
68 * Function takes in attributes passed to debugfs write entry
69 * and writes into param array.
70 * The user passes max_param_num to identify maximum number of
71 * parameters that could be parsed.
74 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
75 long *param, const char __user *buf,
79 char *wr_buf_ptr = NULL;
80 uint32_t wr_buf_count = 0;
83 const char delimiter[3] = {' ', '\n', '\0'};
84 uint8_t param_index = 0;
90 /* r is bytes not be copied */
91 if (copy_from_user(wr_buf_ptr, buf, wr_buf_size)) {
92 DRM_DEBUG_DRIVER("user data could not be read successfully\n");
96 /* check number of parameters. isspace could not differ space and \n */
97 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
99 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
104 if (wr_buf_count == wr_buf_size)
108 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
115 if (wr_buf_count == wr_buf_size)
119 if (*param_nums > max_param_num)
120 *param_nums = max_param_num;
122 wr_buf_ptr = wr_buf; /* reset buf pointer */
123 wr_buf_count = 0; /* number of char already checked */
125 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
130 while (param_index < *param_nums) {
131 /* after strsep, wr_buf_ptr will be moved to after space */
132 sub_str = strsep(&wr_buf_ptr, delimiter);
134 r = kstrtol(sub_str, 16, &(param[param_index]));
137 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
145 /* function description
146 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
148 * valid lane count value: 1, 2, 4
149 * valid link rate value:
150 * 06h = 1.62Gbps per lane
151 * 0Ah = 2.7Gbps per lane
152 * 0Ch = 3.24Gbps per lane
153 * 14h = 5.4Gbps per lane
154 * 1Eh = 8.1Gbps per lane
156 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
158 * --- to get dp configuration
160 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
162 * It will list current, verified, reported, preferred dp configuration.
163 * current -- for current video mode
164 * verified --- maximum configuration which pass link training
165 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
166 * preferred --- user force settings
168 * --- set (or force) dp configuration
170 * echo <lane_count> <link_rate> > link_settings
172 * for example, to force to 2 lane, 2.7GHz,
173 * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
175 * spread_spectrum could not be changed dynamically.
177 * in case invalid lane count, link rate are force, no hw programming will be
178 * done. please check link settings after force operation to see if HW get
181 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
183 * check current and preferred settings.
186 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
187 size_t size, loff_t *pos)
189 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
190 struct dc_link *link = connector->dc_link;
192 char *rd_buf_ptr = NULL;
193 const uint32_t rd_buf_size = 100;
198 if (*pos & 3 || size & 3)
201 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
207 str_len = strlen("Current: %d 0x%x %d ");
208 snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
209 link->cur_link_settings.lane_count,
210 link->cur_link_settings.link_rate,
211 link->cur_link_settings.link_spread);
212 rd_buf_ptr += str_len;
214 str_len = strlen("Verified: %d 0x%x %d ");
215 snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
216 link->verified_link_cap.lane_count,
217 link->verified_link_cap.link_rate,
218 link->verified_link_cap.link_spread);
219 rd_buf_ptr += str_len;
221 str_len = strlen("Reported: %d 0x%x %d ");
222 snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
223 link->reported_link_cap.lane_count,
224 link->reported_link_cap.link_rate,
225 link->reported_link_cap.link_spread);
226 rd_buf_ptr += str_len;
228 str_len = strlen("Preferred: %d 0x%x %d ");
229 snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
230 link->preferred_link_setting.lane_count,
231 link->preferred_link_setting.link_rate,
232 link->preferred_link_setting.link_spread);
235 if (*pos >= rd_buf_size)
238 r = put_user(*(rd_buf + result), buf);
241 return r; /* r = -EFAULT */
254 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
255 size_t size, loff_t *pos)
257 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
258 struct dc_link *link = connector->dc_link;
259 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
260 struct dc *dc = (struct dc *)link->dc;
261 struct dc_link_settings prefer_link_settings;
263 const uint32_t wr_buf_size = 40;
264 /* 0: lane_count; 1: link_rate */
265 int max_param_num = 2;
266 uint8_t param_nums = 0;
268 bool valid_input = true;
273 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
277 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
285 if (param_nums <= 0) {
287 DRM_DEBUG_DRIVER("user data not be read\n");
294 case LANE_COUNT_FOUR:
305 case LINK_RATE_HIGH2:
306 case LINK_RATE_HIGH3:
307 case LINK_RATE_UHBR10:
308 case LINK_RATE_UHBR13_5:
309 case LINK_RATE_UHBR20:
318 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
319 mutex_lock(&adev->dm.dc_lock);
320 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
321 mutex_unlock(&adev->dm.dc_lock);
325 /* save user force lane_count, link_rate to preferred settings
326 * spread spectrum will not be changed
328 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
329 prefer_link_settings.use_link_rate_set = false;
330 prefer_link_settings.lane_count = param[0];
331 prefer_link_settings.link_rate = param[1];
333 mutex_lock(&adev->dm.dc_lock);
334 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, false);
335 mutex_unlock(&adev->dm.dc_lock);
341 static bool dp_mst_is_end_device(struct amdgpu_dm_connector *aconnector)
343 bool is_end_device = false;
344 struct drm_dp_mst_topology_mgr *mgr = NULL;
345 struct drm_dp_mst_port *port = NULL;
347 if (aconnector->mst_root && aconnector->mst_root->mst_mgr.mst_state) {
348 mgr = &aconnector->mst_root->mst_mgr;
349 port = aconnector->mst_output_port;
351 drm_modeset_lock(&mgr->base.lock, NULL);
352 if (port->pdt == DP_PEER_DEVICE_SST_SINK ||
353 port->pdt == DP_PEER_DEVICE_DP_LEGACY_CONV)
354 is_end_device = true;
355 drm_modeset_unlock(&mgr->base.lock);
358 return is_end_device;
361 /* Change MST link setting
363 * valid lane count value: 1, 2, 4
364 * valid link rate value:
365 * 06h = 1.62Gbps per lane
366 * 0Ah = 2.7Gbps per lane
367 * 0Ch = 3.24Gbps per lane
368 * 14h = 5.4Gbps per lane
369 * 1Eh = 8.1Gbps per lane
370 * 3E8h = 10.0Gbps per lane
371 * 546h = 13.5Gbps per lane
372 * 7D0h = 20.0Gbps per lane
374 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/mst_link_settings
376 * for example, to force to 2 lane, 10.0GHz,
377 * echo 2 0x3e8 > /sys/kernel/debug/dri/0/DP-x/mst_link_settings
379 * Valid input will trigger hotplug event to get new link setting applied
380 * Invalid input will trigger training setting reset
382 * The usage can be referred to link_settings entry
385 static ssize_t dp_mst_link_setting(struct file *f, const char __user *buf,
386 size_t size, loff_t *pos)
388 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
389 struct dc_link *link = aconnector->dc_link;
390 struct amdgpu_device *adev = drm_to_adev(aconnector->base.dev);
391 struct dc *dc = (struct dc *)link->dc;
392 struct dc_link_settings prefer_link_settings;
394 const uint32_t wr_buf_size = 40;
395 /* 0: lane_count; 1: link_rate */
396 int max_param_num = 2;
397 uint8_t param_nums = 0;
399 bool valid_input = true;
401 if (!dp_mst_is_end_device(aconnector))
407 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
411 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
419 if (param_nums <= 0) {
421 DRM_DEBUG_DRIVER("user data not be read\n");
428 case LANE_COUNT_FOUR:
439 case LINK_RATE_HIGH2:
440 case LINK_RATE_HIGH3:
441 case LINK_RATE_UHBR10:
442 case LINK_RATE_UHBR13_5:
443 case LINK_RATE_UHBR20:
452 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
453 mutex_lock(&adev->dm.dc_lock);
454 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
455 mutex_unlock(&adev->dm.dc_lock);
459 /* save user force lane_count, link_rate to preferred settings
460 * spread spectrum will not be changed
462 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
463 prefer_link_settings.use_link_rate_set = false;
464 prefer_link_settings.lane_count = param[0];
465 prefer_link_settings.link_rate = param[1];
467 /* skip immediate retrain, and train to new link setting after hotplug event triggered */
468 mutex_lock(&adev->dm.dc_lock);
469 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, true);
470 mutex_unlock(&adev->dm.dc_lock);
472 mutex_lock(&aconnector->base.dev->mode_config.mutex);
473 aconnector->base.force = DRM_FORCE_OFF;
474 mutex_unlock(&aconnector->base.dev->mode_config.mutex);
475 drm_kms_helper_hotplug_event(aconnector->base.dev);
479 mutex_lock(&aconnector->base.dev->mode_config.mutex);
480 aconnector->base.force = DRM_FORCE_UNSPECIFIED;
481 mutex_unlock(&aconnector->base.dev->mode_config.mutex);
482 drm_kms_helper_hotplug_event(aconnector->base.dev);
488 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
489 * post-cursor2 (defined by VESA DP specification)
492 * voltage swing: 0,1,2,3
493 * pre-emphasis : 0,1,2,3
494 * post cursor2 : 0,1,2,3
497 * how to use this debugfs
499 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
501 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
503 * To figure out which DP-x is the display for DP to be check,
506 * There should be debugfs file, like link_settings, phy_settings.
508 * from lane_count, link_rate to figure which DP-x is for display to be worked
511 * To get current DP PHY settings,
514 * To change DP PHY settings,
515 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
516 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
518 * echo 2 3 0 > phy_settings
520 * To check if change be applied, get current phy settings by
523 * In case invalid values are set by user, like
524 * echo 1 4 0 > phy_settings
526 * HW will NOT be programmed by these settings.
527 * cat phy_settings will show the previous valid settings.
529 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
530 size_t size, loff_t *pos)
532 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
533 struct dc_link *link = connector->dc_link;
535 const uint32_t rd_buf_size = 20;
539 if (*pos & 3 || size & 3)
542 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
546 snprintf(rd_buf, rd_buf_size, " %d %d %d\n",
547 link->cur_lane_setting[0].VOLTAGE_SWING,
548 link->cur_lane_setting[0].PRE_EMPHASIS,
549 link->cur_lane_setting[0].POST_CURSOR2);
552 if (*pos >= rd_buf_size)
555 r = put_user((*(rd_buf + result)), buf);
558 return r; /* r = -EFAULT */
571 static int dp_lttpr_status_show(struct seq_file *m, void *unused)
573 struct drm_connector *connector = m->private;
574 struct amdgpu_dm_connector *aconnector =
575 to_amdgpu_dm_connector(connector);
576 struct dc_lttpr_caps caps = aconnector->dc_link->dpcd_caps.lttpr_caps;
578 if (connector->status != connector_status_connected)
581 seq_printf(m, "phy repeater count: %u (raw: 0x%x)\n",
582 dp_parse_lttpr_repeater_count(caps.phy_repeater_cnt),
583 caps.phy_repeater_cnt);
585 seq_puts(m, "phy repeater mode: ");
588 case DP_PHY_REPEATER_MODE_TRANSPARENT:
589 seq_puts(m, "transparent");
591 case DP_PHY_REPEATER_MODE_NON_TRANSPARENT:
592 seq_puts(m, "non-transparent");
595 seq_puts(m, "non lttpr");
598 seq_printf(m, "read error (raw: 0x%x)", caps.mode);
606 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
607 size_t size, loff_t *pos)
609 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
610 struct dc_link *link = connector->dc_link;
611 struct dc *dc = (struct dc *)link->dc;
613 uint32_t wr_buf_size = 40;
615 bool use_prefer_link_setting;
616 struct link_training_settings link_lane_settings;
617 int max_param_num = 3;
618 uint8_t param_nums = 0;
625 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
629 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
637 if (param_nums <= 0) {
639 DRM_DEBUG_DRIVER("user data not be read\n");
643 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
644 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
645 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
647 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
651 /* get link settings: lane count, link rate */
652 use_prefer_link_setting =
653 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
654 (link->test_pattern_enabled));
656 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
658 if (use_prefer_link_setting) {
659 link_lane_settings.link_settings.lane_count =
660 link->preferred_link_setting.lane_count;
661 link_lane_settings.link_settings.link_rate =
662 link->preferred_link_setting.link_rate;
663 link_lane_settings.link_settings.link_spread =
664 link->preferred_link_setting.link_spread;
666 link_lane_settings.link_settings.lane_count =
667 link->cur_link_settings.lane_count;
668 link_lane_settings.link_settings.link_rate =
669 link->cur_link_settings.link_rate;
670 link_lane_settings.link_settings.link_spread =
671 link->cur_link_settings.link_spread;
674 /* apply phy settings from user */
675 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
676 link_lane_settings.hw_lane_settings[r].VOLTAGE_SWING =
677 (enum dc_voltage_swing) (param[0]);
678 link_lane_settings.hw_lane_settings[r].PRE_EMPHASIS =
679 (enum dc_pre_emphasis) (param[1]);
680 link_lane_settings.hw_lane_settings[r].POST_CURSOR2 =
681 (enum dc_post_cursor2) (param[2]);
684 /* program ASIC registers and DPCD registers */
685 dc_link_set_drive_settings(dc, &link_lane_settings, link);
691 /* function description
693 * set PHY layer or Link layer test pattern
694 * PHY test pattern is used for PHY SI check.
695 * Link layer test will not affect PHY SI.
697 * Reset Test Pattern:
698 * 0 = DP_TEST_PATTERN_VIDEO_MODE
700 * PHY test pattern supported:
701 * 1 = DP_TEST_PATTERN_D102
702 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
703 * 3 = DP_TEST_PATTERN_PRBS7
704 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
705 * 5 = DP_TEST_PATTERN_CP2520_1
706 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
707 * 7 = DP_TEST_PATTERN_CP2520_3
709 * DP PHY Link Training Patterns
710 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
711 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
712 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
713 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
715 * DP Link Layer Test pattern
716 * c = DP_TEST_PATTERN_COLOR_SQUARES
717 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
718 * e = DP_TEST_PATTERN_VERTICAL_BARS
719 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
720 * 10= DP_TEST_PATTERN_COLOR_RAMP
722 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
724 * --- set test pattern
725 * echo <test pattern #> > test_pattern
727 * If test pattern # is not supported, NO HW programming will be done.
728 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
729 * for the user pattern. input 10 bytes data are separated by space
731 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
733 * --- reset test pattern
734 * echo 0 > test_pattern
736 * --- HPD detection is disabled when set PHY test pattern
738 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
739 * is disable. User could unplug DP display from DP connected and plug scope to
740 * check test pattern PHY SI.
741 * If there is need unplug scope and plug DP display back, do steps below:
742 * echo 0 > phy_test_pattern
746 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
747 * driver could detect "unplug scope" and "plug DP display"
749 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
750 size_t size, loff_t *pos)
752 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
753 struct dc_link *link = connector->dc_link;
755 uint32_t wr_buf_size = 100;
756 long param[11] = {0x0};
757 int max_param_num = 11;
758 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
759 bool disable_hpd = false;
760 bool valid_test_pattern = false;
761 uint8_t param_nums = 0;
762 /* init with default 80bit custom pattern */
763 uint8_t custom_pattern[10] = {
764 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
765 0x1f, 0x7c, 0xf0, 0xc1, 0x07
767 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
768 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
769 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
770 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
771 struct link_training_settings link_training_settings;
777 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
781 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
789 if (param_nums <= 0) {
791 DRM_DEBUG_DRIVER("user data not be read\n");
796 test_pattern = param[0];
798 switch (test_pattern) {
799 case DP_TEST_PATTERN_VIDEO_MODE:
800 case DP_TEST_PATTERN_COLOR_SQUARES:
801 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
802 case DP_TEST_PATTERN_VERTICAL_BARS:
803 case DP_TEST_PATTERN_HORIZONTAL_BARS:
804 case DP_TEST_PATTERN_COLOR_RAMP:
805 valid_test_pattern = true;
808 case DP_TEST_PATTERN_D102:
809 case DP_TEST_PATTERN_SYMBOL_ERROR:
810 case DP_TEST_PATTERN_PRBS7:
811 case DP_TEST_PATTERN_80BIT_CUSTOM:
812 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
813 case DP_TEST_PATTERN_TRAINING_PATTERN4:
815 valid_test_pattern = true;
819 valid_test_pattern = false;
820 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
824 if (!valid_test_pattern) {
826 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
830 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
831 for (i = 0; i < 10; i++) {
832 if ((uint8_t) param[i + 1] != 0x0)
837 /* not use default value */
838 for (i = 0; i < 10; i++)
839 custom_pattern[i] = (uint8_t) param[i + 1];
843 /* Usage: set DP physical test pattern using debugfs with normal DP
844 * panel. Then plug out DP panel and connect a scope to measure
845 * For normal video mode and test pattern generated from CRCT,
846 * they are visibile to user. So do not disable HPD.
847 * Video Mode is also set to clear the test pattern, so enable HPD
848 * because it might have been disabled after a test pattern was set.
849 * AUX depends on HPD * sequence dependent, do not move!
852 dc_link_enable_hpd(link);
854 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
855 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
856 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
858 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
859 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
860 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
862 link_training_settings.link_settings = cur_link_settings;
865 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
866 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
867 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
868 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
869 prefer_link_settings.link_rate != cur_link_settings.link_rate))
870 link_training_settings.link_settings = prefer_link_settings;
873 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
874 link_training_settings.hw_lane_settings[i] = link->cur_lane_setting[i];
876 dc_link_dp_set_test_pattern(
879 DP_TEST_PATTERN_COLOR_SPACE_RGB,
880 &link_training_settings,
884 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
885 * Then plug out DP panel and connect a scope to measure DP PHY signal.
886 * Need disable interrupt to avoid SW driver disable DP output. This is
887 * done after the test pattern is set.
889 if (valid_test_pattern && disable_hpd)
890 dc_link_disable_hpd(link);
898 * Returns the DMCUB tracebuffer contents.
899 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
901 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
903 struct amdgpu_device *adev = m->private;
904 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
905 struct dmub_debugfs_trace_entry *entries;
907 uint32_t tbuf_size, max_entries, num_entries, i;
912 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
916 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
917 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
918 sizeof(struct dmub_debugfs_trace_entry);
921 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
923 num_entries = min(num_entries, max_entries);
925 entries = (struct dmub_debugfs_trace_entry
927 sizeof(struct dmub_debugfs_trace_header));
929 for (i = 0; i < num_entries; ++i) {
930 struct dmub_debugfs_trace_entry *entry = &entries[i];
933 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
934 entry->trace_code, entry->tick_count, entry->param0,
942 * Returns the DMCUB firmware state contents.
943 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
945 static int dmub_fw_state_show(struct seq_file *m, void *data)
947 struct amdgpu_device *adev = m->private;
948 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
955 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
959 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
961 return seq_write(m, state_base, state_size);
964 /* replay_capability_show() - show eDP panel replay capability
966 * The read function: replay_capability_show
967 * Shows if sink and driver has Replay capability or not.
969 * cat /sys/kernel/debug/dri/0/eDP-X/replay_capability
972 * "Sink support: no\n" - if panel doesn't support Replay
973 * "Sink support: yes\n" - if panel supports Replay
974 * "Driver support: no\n" - if driver doesn't support Replay
975 * "Driver support: yes\n" - if driver supports Replay
977 static int replay_capability_show(struct seq_file *m, void *data)
979 struct drm_connector *connector = m->private;
980 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
981 struct dc_link *link = aconnector->dc_link;
982 bool sink_support_replay = false;
983 bool driver_support_replay = false;
988 if (link->type == dc_connection_none)
991 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
994 /* If Replay is already set to support, skip the checks */
995 if (link->replay_settings.config.replay_supported) {
996 sink_support_replay = true;
997 driver_support_replay = true;
998 } else if ((amdgpu_dc_debug_mask & DC_DISABLE_REPLAY)) {
999 sink_support_replay = amdgpu_dm_link_supports_replay(link, aconnector);
1001 struct dc *dc = link->ctx->dc;
1003 sink_support_replay = amdgpu_dm_link_supports_replay(link, aconnector);
1004 if (dc->ctx->dmub_srv && dc->ctx->dmub_srv->dmub)
1005 driver_support_replay =
1006 (bool)dc->ctx->dmub_srv->dmub->feature_caps.replay_supported;
1009 seq_printf(m, "Sink support: %s\n", str_yes_no(sink_support_replay));
1010 seq_printf(m, "Driver support: %s\n", str_yes_no(driver_support_replay));
1015 /* psr_capability_show() - show eDP panel PSR capability
1017 * The read function: sink_psr_capability_show
1018 * Shows if sink has PSR capability or not.
1019 * If yes - the PSR version is appended
1021 * cat /sys/kernel/debug/dri/0/eDP-X/psr_capability
1024 * "Sink support: no\n" - if panel doesn't support PSR
1025 * "Sink support: yes [0x01]\n" - if panel supports PSR1
1026 * "Driver support: no\n" - if driver doesn't support PSR
1027 * "Driver support: yes [0x01]\n" - if driver supports PSR1
1029 static int psr_capability_show(struct seq_file *m, void *data)
1031 struct drm_connector *connector = m->private;
1032 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1033 struct dc_link *link = aconnector->dc_link;
1038 if (link->type == dc_connection_none)
1041 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
1044 seq_printf(m, "Sink support: %s", str_yes_no(link->dpcd_caps.psr_info.psr_version != 0));
1045 if (link->dpcd_caps.psr_info.psr_version)
1046 seq_printf(m, " [0x%02x]", link->dpcd_caps.psr_info.psr_version);
1049 seq_printf(m, "Driver support: %s", str_yes_no(link->psr_settings.psr_feature_enabled));
1050 if (link->psr_settings.psr_version)
1051 seq_printf(m, " [0x%02x]", link->psr_settings.psr_version);
1058 * Returns the current bpc for the crtc.
1059 * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_bpc
1061 static int amdgpu_current_bpc_show(struct seq_file *m, void *data)
1063 struct drm_crtc *crtc = m->private;
1064 struct drm_device *dev = crtc->dev;
1065 struct dm_crtc_state *dm_crtc_state = NULL;
1069 mutex_lock(&dev->mode_config.mutex);
1070 drm_modeset_lock(&crtc->mutex, NULL);
1071 if (crtc->state == NULL)
1074 dm_crtc_state = to_dm_crtc_state(crtc->state);
1075 if (dm_crtc_state->stream == NULL)
1078 switch (dm_crtc_state->stream->timing.display_color_depth) {
1079 case COLOR_DEPTH_666:
1082 case COLOR_DEPTH_888:
1085 case COLOR_DEPTH_101010:
1088 case COLOR_DEPTH_121212:
1091 case COLOR_DEPTH_161616:
1098 seq_printf(m, "Current: %u\n", bpc);
1102 drm_modeset_unlock(&crtc->mutex);
1103 mutex_unlock(&dev->mode_config.mutex);
1107 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_bpc);
1110 * Returns the current colorspace for the crtc.
1111 * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_colorspace
1113 static int amdgpu_current_colorspace_show(struct seq_file *m, void *data)
1115 struct drm_crtc *crtc = m->private;
1116 struct drm_device *dev = crtc->dev;
1117 struct dm_crtc_state *dm_crtc_state = NULL;
1120 mutex_lock(&dev->mode_config.mutex);
1121 drm_modeset_lock(&crtc->mutex, NULL);
1122 if (crtc->state == NULL)
1125 dm_crtc_state = to_dm_crtc_state(crtc->state);
1126 if (dm_crtc_state->stream == NULL)
1129 switch (dm_crtc_state->stream->output_color_space) {
1130 case COLOR_SPACE_SRGB:
1131 seq_puts(m, "sRGB");
1133 case COLOR_SPACE_YCBCR601:
1134 case COLOR_SPACE_YCBCR601_LIMITED:
1135 seq_puts(m, "BT601_YCC");
1137 case COLOR_SPACE_YCBCR709:
1138 case COLOR_SPACE_YCBCR709_LIMITED:
1139 seq_puts(m, "BT709_YCC");
1141 case COLOR_SPACE_ADOBERGB:
1142 seq_puts(m, "opRGB");
1144 case COLOR_SPACE_2020_RGB_FULLRANGE:
1145 seq_puts(m, "BT2020_RGB");
1147 case COLOR_SPACE_2020_YCBCR:
1148 seq_puts(m, "BT2020_YCC");
1156 drm_modeset_unlock(&crtc->mutex);
1157 mutex_unlock(&dev->mode_config.mutex);
1161 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_colorspace);
1166 * Disable dsc passthrough, i.e.,: have dsc decoding at converver, not external RX
1167 * echo 1 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
1168 * Enable dsc passthrough, i.e.,: have dsc passthrough to external RX
1169 * echo 0 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
1171 static ssize_t dp_dsc_passthrough_set(struct file *f, const char __user *buf,
1172 size_t size, loff_t *pos)
1174 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1175 char *wr_buf = NULL;
1176 uint32_t wr_buf_size = 42;
1177 int max_param_num = 1;
1179 uint8_t param_nums = 0;
1184 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1187 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1191 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1199 aconnector->dsc_settings.dsc_force_disable_passthrough = param;
1206 * Returns the HDCP capability of the Display (1.4 for now).
1208 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
1209 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
1211 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
1212 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
1214 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
1216 struct drm_connector *connector = m->private;
1217 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1218 bool hdcp_cap, hdcp2_cap;
1220 if (connector->status != connector_status_connected)
1223 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
1225 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1226 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1230 seq_printf(m, "%s ", "HDCP1.4");
1232 seq_printf(m, "%s ", "HDCP2.2");
1234 if (!hdcp_cap && !hdcp2_cap)
1235 seq_printf(m, "%s ", "None");
1243 * Returns whether the connected display is internal and not hotpluggable.
1244 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/internal_display
1246 static int internal_display_show(struct seq_file *m, void *data)
1248 struct drm_connector *connector = m->private;
1249 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1250 struct dc_link *link = aconnector->dc_link;
1252 seq_printf(m, "Internal: %u\n", link->is_internal_display);
1258 * Returns the number of segments used if ODM Combine mode is enabled.
1259 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/odm_combine_segments
1261 static int odm_combine_segments_show(struct seq_file *m, void *unused)
1263 struct drm_connector *connector = m->private;
1264 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1265 struct dc_link *link = aconnector->dc_link;
1266 struct pipe_ctx *pipe_ctx = NULL;
1267 int i, segments = -EOPNOTSUPP;
1269 for (i = 0; i < MAX_PIPES; i++) {
1270 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
1271 if (pipe_ctx->stream &&
1272 pipe_ctx->stream->link == link)
1276 if (connector->status != connector_status_connected)
1279 if (pipe_ctx != NULL && pipe_ctx->stream_res.tg->funcs->get_odm_combine_segments)
1280 pipe_ctx->stream_res.tg->funcs->get_odm_combine_segments(pipe_ctx->stream_res.tg, &segments);
1282 seq_printf(m, "%d\n", segments);
1286 /* function description
1288 * generic SDP message access for testing
1290 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
1293 * Hb0 : Secondary-Data Packet ID
1294 * Hb1 : Secondary-Data Packet type
1295 * Hb2 : Secondary-Data-packet-specific header, Byte 0
1296 * Hb3 : Secondary-Data-packet-specific header, Byte 1
1298 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
1300 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
1301 size_t size, loff_t *pos)
1304 uint8_t data[36] = {0};
1305 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1306 struct dm_crtc_state *acrtc_state;
1307 uint32_t write_size = 36;
1309 if (connector->base.status != connector_status_connected)
1315 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
1317 r = copy_from_user(data, buf, write_size);
1321 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
1326 /* function: Read link's DSC & FEC capabilities
1329 * Access it with the following command (you need to specify
1330 * connector like DP-1):
1332 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
1335 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
1337 struct drm_connector *connector = m->private;
1338 struct drm_modeset_acquire_ctx ctx;
1339 struct drm_device *dev = connector->dev;
1340 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1342 bool try_again = false;
1343 bool is_fec_supported = false;
1344 bool is_dsc_supported = false;
1345 struct dpcd_caps dpcd_caps;
1347 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1350 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1352 if (ret == -EDEADLK) {
1353 ret = drm_modeset_backoff(&ctx);
1361 if (connector->status != connector_status_connected) {
1365 dpcd_caps = aconnector->dc_link->dpcd_caps;
1366 if (aconnector->mst_output_port) {
1367 /* aconnector sets dsc_aux during get_modes call
1368 * if MST connector has it means it can either
1369 * enable DSC on the sink device or on MST branch
1372 if (aconnector->dsc_aux) {
1373 is_fec_supported = true;
1374 is_dsc_supported = true;
1377 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1378 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1380 } while (try_again);
1382 drm_modeset_drop_locks(&ctx);
1383 drm_modeset_acquire_fini(&ctx);
1385 seq_printf(m, "FEC_Sink_Support: %s\n", str_yes_no(is_fec_supported));
1386 seq_printf(m, "DSC_Sink_Support: %s\n", str_yes_no(is_dsc_supported));
1391 /* function: Trigger virtual HPD redetection on connector
1393 * This function will perform link rediscovery, link disable
1394 * and enable, and dm connector state update.
1396 * Retrigger HPD on an existing connector by echoing 1 into
1397 * its respectful "trigger_hotplug" debugfs entry:
1399 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1401 * This function can perform HPD unplug:
1403 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1406 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1407 size_t size, loff_t *pos)
1409 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1410 struct drm_connector *connector = &aconnector->base;
1411 struct dc_link *link = NULL;
1412 struct drm_device *dev = connector->dev;
1413 struct amdgpu_device *adev = drm_to_adev(dev);
1414 enum dc_connection_type new_connection_type = dc_connection_none;
1415 char *wr_buf = NULL;
1416 uint32_t wr_buf_size = 42;
1417 int max_param_num = 1;
1418 long param[1] = {0};
1419 uint8_t param_nums = 0;
1422 if (!aconnector || !aconnector->dc_link)
1428 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1431 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1435 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1445 if (param_nums <= 0) {
1446 DRM_DEBUG_DRIVER("user data not be read\n");
1450 mutex_lock(&aconnector->hpd_lock);
1452 /* Don't support for mst end device*/
1453 if (aconnector->mst_root) {
1454 mutex_unlock(&aconnector->hpd_lock);
1458 if (param[0] == 1) {
1460 if (!dc_link_detect_connection_type(aconnector->dc_link, &new_connection_type) &&
1461 new_connection_type != dc_connection_none)
1464 mutex_lock(&adev->dm.dc_lock);
1465 ret = dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
1466 mutex_unlock(&adev->dm.dc_lock);
1471 amdgpu_dm_update_connector_after_detect(aconnector);
1473 drm_modeset_lock_all(dev);
1474 dm_restore_drm_connector_state(dev, connector);
1475 drm_modeset_unlock_all(dev);
1477 drm_kms_helper_connector_hotplug_event(connector);
1478 } else if (param[0] == 0) {
1479 if (!aconnector->dc_link)
1482 link = aconnector->dc_link;
1484 if (link->local_sink) {
1485 dc_sink_release(link->local_sink);
1486 link->local_sink = NULL;
1489 link->dpcd_sink_count = 0;
1490 link->type = dc_connection_none;
1491 link->dongle_max_pix_clk = 0;
1493 amdgpu_dm_update_connector_after_detect(aconnector);
1495 /* If the aconnector is the root node in mst topology */
1496 if (aconnector->mst_mgr.mst_state == true)
1497 dc_link_reset_cur_dp_mst_topology(link);
1499 drm_modeset_lock_all(dev);
1500 dm_restore_drm_connector_state(dev, connector);
1501 drm_modeset_unlock_all(dev);
1503 drm_kms_helper_connector_hotplug_event(connector);
1507 mutex_unlock(&aconnector->hpd_lock);
1512 /* function: read DSC status on the connector
1514 * The read function: dp_dsc_clock_en_read
1515 * returns current status of DSC clock on the connector.
1516 * The return is a boolean flag: 1 or 0.
1518 * Access it with the following command (you need to specify
1519 * connector like DP-1):
1521 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1524 * 1 - means that DSC is currently enabled
1525 * 0 - means that DSC is disabled
1527 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1528 size_t size, loff_t *pos)
1530 char *rd_buf = NULL;
1531 char *rd_buf_ptr = NULL;
1532 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1533 struct display_stream_compressor *dsc;
1534 struct dcn_dsc_state dsc_state = {0};
1535 const uint32_t rd_buf_size = 10;
1536 struct pipe_ctx *pipe_ctx;
1538 int i, r, str_len = 10;
1540 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1545 rd_buf_ptr = rd_buf;
1547 for (i = 0; i < MAX_PIPES; i++) {
1548 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1549 if (pipe_ctx->stream &&
1550 pipe_ctx->stream->link == aconnector->dc_link &&
1551 pipe_ctx->stream->sink &&
1552 pipe_ctx->stream->sink == aconnector->dc_sink)
1556 dsc = pipe_ctx->stream_res.dsc;
1558 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1560 snprintf(rd_buf_ptr, str_len,
1562 dsc_state.dsc_clock_en);
1563 rd_buf_ptr += str_len;
1566 if (*pos >= rd_buf_size)
1569 r = put_user(*(rd_buf + result), buf);
1572 return r; /* r = -EFAULT */
1585 /* function: write force DSC on the connector
1587 * The write function: dp_dsc_clock_en_write
1588 * enables to force DSC on the connector.
1589 * User can write to either force enable or force disable DSC
1590 * on the next modeset or set it to driver default
1593 * 0 - default DSC enablement policy
1594 * 1 - force enable DSC on the connector
1595 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1597 * Writing DSC settings is done with the following command:
1598 * - To force enable DSC (you need to specify
1599 * connector like DP-1):
1601 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1603 * - To return to default state set the flag to zero and
1604 * let driver deal with DSC automatically
1605 * (you need to specify connector like DP-1):
1607 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1610 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1611 size_t size, loff_t *pos)
1613 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1614 struct drm_connector *connector = &aconnector->base;
1615 struct drm_device *dev = connector->dev;
1616 struct drm_crtc *crtc = NULL;
1617 struct dm_crtc_state *dm_crtc_state = NULL;
1618 struct pipe_ctx *pipe_ctx;
1620 char *wr_buf = NULL;
1621 uint32_t wr_buf_size = 42;
1622 int max_param_num = 1;
1623 long param[1] = {0};
1624 uint8_t param_nums = 0;
1629 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1632 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1636 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1644 if (param_nums <= 0) {
1645 DRM_DEBUG_DRIVER("user data not be read\n");
1650 for (i = 0; i < MAX_PIPES; i++) {
1651 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1652 if (pipe_ctx->stream &&
1653 pipe_ctx->stream->link == aconnector->dc_link &&
1654 pipe_ctx->stream->sink &&
1655 pipe_ctx->stream->sink == aconnector->dc_sink)
1659 if (!pipe_ctx->stream)
1663 mutex_lock(&dev->mode_config.mutex);
1664 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1666 if (connector->state == NULL)
1669 crtc = connector->state->crtc;
1673 drm_modeset_lock(&crtc->mutex, NULL);
1674 if (crtc->state == NULL)
1677 dm_crtc_state = to_dm_crtc_state(crtc->state);
1678 if (dm_crtc_state->stream == NULL)
1682 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1683 else if (param[0] == 2)
1684 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1686 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1688 dm_crtc_state->dsc_force_changed = true;
1692 drm_modeset_unlock(&crtc->mutex);
1693 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1694 mutex_unlock(&dev->mode_config.mutex);
1701 /* function: read DSC slice width parameter on the connector
1703 * The read function: dp_dsc_slice_width_read
1704 * returns dsc slice width used in the current configuration
1705 * The return is an integer: 0 or other positive number
1707 * Access the status with the following command:
1709 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1711 * 0 - means that DSC is disabled
1713 * Any other number more than zero represents the
1714 * slice width currently used by DSC in pixels
1717 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1718 size_t size, loff_t *pos)
1720 char *rd_buf = NULL;
1721 char *rd_buf_ptr = NULL;
1722 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1723 struct display_stream_compressor *dsc;
1724 struct dcn_dsc_state dsc_state = {0};
1725 const uint32_t rd_buf_size = 100;
1726 struct pipe_ctx *pipe_ctx;
1728 int i, r, str_len = 30;
1730 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1735 rd_buf_ptr = rd_buf;
1737 for (i = 0; i < MAX_PIPES; i++) {
1738 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1739 if (pipe_ctx->stream &&
1740 pipe_ctx->stream->link == aconnector->dc_link &&
1741 pipe_ctx->stream->sink &&
1742 pipe_ctx->stream->sink == aconnector->dc_sink)
1746 dsc = pipe_ctx->stream_res.dsc;
1748 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1750 snprintf(rd_buf_ptr, str_len,
1752 dsc_state.dsc_slice_width);
1753 rd_buf_ptr += str_len;
1756 if (*pos >= rd_buf_size)
1759 r = put_user(*(rd_buf + result), buf);
1762 return r; /* r = -EFAULT */
1775 /* function: write DSC slice width parameter
1777 * The write function: dp_dsc_slice_width_write
1778 * overwrites automatically generated DSC configuration
1781 * The user has to write the slice width divisible by the
1784 * Also the user has to write width in hexidecimal
1785 * rather than in decimal.
1787 * Writing DSC settings is done with the following command:
1788 * - To force overwrite slice width: (example sets to 1920 pixels)
1790 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1792 * - To stop overwriting and let driver find the optimal size,
1793 * set the width to zero:
1795 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1798 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1799 size_t size, loff_t *pos)
1801 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1802 struct pipe_ctx *pipe_ctx;
1803 struct drm_connector *connector = &aconnector->base;
1804 struct drm_device *dev = connector->dev;
1805 struct drm_crtc *crtc = NULL;
1806 struct dm_crtc_state *dm_crtc_state = NULL;
1808 char *wr_buf = NULL;
1809 uint32_t wr_buf_size = 42;
1810 int max_param_num = 1;
1811 long param[1] = {0};
1812 uint8_t param_nums = 0;
1817 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1820 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1824 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1832 if (param_nums <= 0) {
1833 DRM_DEBUG_DRIVER("user data not be read\n");
1838 for (i = 0; i < MAX_PIPES; i++) {
1839 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1840 if (pipe_ctx->stream &&
1841 pipe_ctx->stream->link == aconnector->dc_link &&
1842 pipe_ctx->stream->sink &&
1843 pipe_ctx->stream->sink == aconnector->dc_sink)
1847 if (!pipe_ctx->stream)
1850 // Safely get CRTC state
1851 mutex_lock(&dev->mode_config.mutex);
1852 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1854 if (connector->state == NULL)
1857 crtc = connector->state->crtc;
1861 drm_modeset_lock(&crtc->mutex, NULL);
1862 if (crtc->state == NULL)
1865 dm_crtc_state = to_dm_crtc_state(crtc->state);
1866 if (dm_crtc_state->stream == NULL)
1870 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1871 pipe_ctx->stream->timing.h_addressable,
1874 aconnector->dsc_settings.dsc_num_slices_h = 0;
1876 dm_crtc_state->dsc_force_changed = true;
1880 drm_modeset_unlock(&crtc->mutex);
1881 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1882 mutex_unlock(&dev->mode_config.mutex);
1889 /* function: read DSC slice height parameter on the connector
1891 * The read function: dp_dsc_slice_height_read
1892 * returns dsc slice height used in the current configuration
1893 * The return is an integer: 0 or other positive number
1895 * Access the status with the following command:
1897 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1899 * 0 - means that DSC is disabled
1901 * Any other number more than zero represents the
1902 * slice height currently used by DSC in pixels
1905 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1906 size_t size, loff_t *pos)
1908 char *rd_buf = NULL;
1909 char *rd_buf_ptr = NULL;
1910 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1911 struct display_stream_compressor *dsc;
1912 struct dcn_dsc_state dsc_state = {0};
1913 const uint32_t rd_buf_size = 100;
1914 struct pipe_ctx *pipe_ctx;
1916 int i, r, str_len = 30;
1918 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1923 rd_buf_ptr = rd_buf;
1925 for (i = 0; i < MAX_PIPES; i++) {
1926 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1927 if (pipe_ctx->stream &&
1928 pipe_ctx->stream->link == aconnector->dc_link &&
1929 pipe_ctx->stream->sink &&
1930 pipe_ctx->stream->sink == aconnector->dc_sink)
1934 dsc = pipe_ctx->stream_res.dsc;
1936 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1938 snprintf(rd_buf_ptr, str_len,
1940 dsc_state.dsc_slice_height);
1941 rd_buf_ptr += str_len;
1944 if (*pos >= rd_buf_size)
1947 r = put_user(*(rd_buf + result), buf);
1950 return r; /* r = -EFAULT */
1963 /* function: write DSC slice height parameter
1965 * The write function: dp_dsc_slice_height_write
1966 * overwrites automatically generated DSC configuration
1969 * The user has to write the slice height divisible by the
1972 * Also the user has to write height in hexidecimal
1973 * rather than in decimal.
1975 * Writing DSC settings is done with the following command:
1976 * - To force overwrite slice height (example sets to 128 pixels):
1978 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1980 * - To stop overwriting and let driver find the optimal size,
1981 * set the height to zero:
1983 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1986 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1987 size_t size, loff_t *pos)
1989 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1990 struct drm_connector *connector = &aconnector->base;
1991 struct drm_device *dev = connector->dev;
1992 struct drm_crtc *crtc = NULL;
1993 struct dm_crtc_state *dm_crtc_state = NULL;
1994 struct pipe_ctx *pipe_ctx;
1996 char *wr_buf = NULL;
1997 uint32_t wr_buf_size = 42;
1998 int max_param_num = 1;
1999 uint8_t param_nums = 0;
2000 long param[1] = {0};
2005 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2008 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2012 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2020 if (param_nums <= 0) {
2021 DRM_DEBUG_DRIVER("user data not be read\n");
2026 for (i = 0; i < MAX_PIPES; i++) {
2027 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2028 if (pipe_ctx->stream &&
2029 pipe_ctx->stream->link == aconnector->dc_link &&
2030 pipe_ctx->stream->sink &&
2031 pipe_ctx->stream->sink == aconnector->dc_sink)
2035 if (!pipe_ctx->stream)
2039 mutex_lock(&dev->mode_config.mutex);
2040 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2042 if (connector->state == NULL)
2045 crtc = connector->state->crtc;
2049 drm_modeset_lock(&crtc->mutex, NULL);
2050 if (crtc->state == NULL)
2053 dm_crtc_state = to_dm_crtc_state(crtc->state);
2054 if (dm_crtc_state->stream == NULL)
2058 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
2059 pipe_ctx->stream->timing.v_addressable,
2062 aconnector->dsc_settings.dsc_num_slices_v = 0;
2064 dm_crtc_state->dsc_force_changed = true;
2068 drm_modeset_unlock(&crtc->mutex);
2069 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2070 mutex_unlock(&dev->mode_config.mutex);
2077 /* function: read DSC target rate on the connector in bits per pixel
2079 * The read function: dp_dsc_bits_per_pixel_read
2080 * returns target rate of compression in bits per pixel
2081 * The return is an integer: 0 or other positive integer
2083 * Access it with the following command:
2085 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2087 * 0 - means that DSC is disabled
2089 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
2090 size_t size, loff_t *pos)
2092 char *rd_buf = NULL;
2093 char *rd_buf_ptr = NULL;
2094 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2095 struct display_stream_compressor *dsc;
2096 struct dcn_dsc_state dsc_state = {0};
2097 const uint32_t rd_buf_size = 100;
2098 struct pipe_ctx *pipe_ctx;
2100 int i, r, str_len = 30;
2102 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2107 rd_buf_ptr = rd_buf;
2109 for (i = 0; i < MAX_PIPES; i++) {
2110 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2111 if (pipe_ctx->stream &&
2112 pipe_ctx->stream->link == aconnector->dc_link &&
2113 pipe_ctx->stream->sink &&
2114 pipe_ctx->stream->sink == aconnector->dc_sink)
2118 dsc = pipe_ctx->stream_res.dsc;
2120 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2122 snprintf(rd_buf_ptr, str_len,
2124 dsc_state.dsc_bits_per_pixel);
2125 rd_buf_ptr += str_len;
2128 if (*pos >= rd_buf_size)
2131 r = put_user(*(rd_buf + result), buf);
2134 return r; /* r = -EFAULT */
2147 /* function: write DSC target rate in bits per pixel
2149 * The write function: dp_dsc_bits_per_pixel_write
2150 * overwrites automatically generated DSC configuration
2151 * of DSC target bit rate.
2153 * Also the user has to write bpp in hexidecimal
2154 * rather than in decimal.
2156 * Writing DSC settings is done with the following command:
2157 * - To force overwrite rate (example sets to 256 bpp x 1/16):
2159 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2161 * - To stop overwriting and let driver find the optimal rate,
2162 * set the rate to zero:
2164 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2167 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
2168 size_t size, loff_t *pos)
2170 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2171 struct drm_connector *connector = &aconnector->base;
2172 struct drm_device *dev = connector->dev;
2173 struct drm_crtc *crtc = NULL;
2174 struct dm_crtc_state *dm_crtc_state = NULL;
2175 struct pipe_ctx *pipe_ctx;
2177 char *wr_buf = NULL;
2178 uint32_t wr_buf_size = 42;
2179 int max_param_num = 1;
2180 uint8_t param_nums = 0;
2181 long param[1] = {0};
2186 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2189 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2193 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2201 if (param_nums <= 0) {
2202 DRM_DEBUG_DRIVER("user data not be read\n");
2207 for (i = 0; i < MAX_PIPES; i++) {
2208 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2209 if (pipe_ctx->stream &&
2210 pipe_ctx->stream->link == aconnector->dc_link &&
2211 pipe_ctx->stream->sink &&
2212 pipe_ctx->stream->sink == aconnector->dc_sink)
2216 if (!pipe_ctx->stream)
2220 mutex_lock(&dev->mode_config.mutex);
2221 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2223 if (connector->state == NULL)
2226 crtc = connector->state->crtc;
2230 drm_modeset_lock(&crtc->mutex, NULL);
2231 if (crtc->state == NULL)
2234 dm_crtc_state = to_dm_crtc_state(crtc->state);
2235 if (dm_crtc_state->stream == NULL)
2238 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
2240 dm_crtc_state->dsc_force_changed = true;
2244 drm_modeset_unlock(&crtc->mutex);
2245 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2246 mutex_unlock(&dev->mode_config.mutex);
2253 /* function: read DSC picture width parameter on the connector
2255 * The read function: dp_dsc_pic_width_read
2256 * returns dsc picture width used in the current configuration
2257 * It is the same as h_addressable of the current
2259 * The return is an integer: 0 or other positive integer
2260 * If 0 then DSC is disabled.
2262 * Access it with the following command:
2264 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
2266 * 0 - means that DSC is disabled
2268 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
2269 size_t size, loff_t *pos)
2271 char *rd_buf = NULL;
2272 char *rd_buf_ptr = NULL;
2273 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2274 struct display_stream_compressor *dsc;
2275 struct dcn_dsc_state dsc_state = {0};
2276 const uint32_t rd_buf_size = 100;
2277 struct pipe_ctx *pipe_ctx;
2279 int i, r, str_len = 30;
2281 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2286 rd_buf_ptr = rd_buf;
2288 for (i = 0; i < MAX_PIPES; i++) {
2289 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2290 if (pipe_ctx->stream &&
2291 pipe_ctx->stream->link == aconnector->dc_link &&
2292 pipe_ctx->stream->sink &&
2293 pipe_ctx->stream->sink == aconnector->dc_sink)
2297 dsc = pipe_ctx->stream_res.dsc;
2299 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2301 snprintf(rd_buf_ptr, str_len,
2303 dsc_state.dsc_pic_width);
2304 rd_buf_ptr += str_len;
2307 if (*pos >= rd_buf_size)
2310 r = put_user(*(rd_buf + result), buf);
2313 return r; /* r = -EFAULT */
2326 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
2327 size_t size, loff_t *pos)
2329 char *rd_buf = NULL;
2330 char *rd_buf_ptr = NULL;
2331 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2332 struct display_stream_compressor *dsc;
2333 struct dcn_dsc_state dsc_state = {0};
2334 const uint32_t rd_buf_size = 100;
2335 struct pipe_ctx *pipe_ctx;
2337 int i, r, str_len = 30;
2339 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2344 rd_buf_ptr = rd_buf;
2346 for (i = 0; i < MAX_PIPES; i++) {
2347 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2348 if (pipe_ctx->stream &&
2349 pipe_ctx->stream->link == aconnector->dc_link &&
2350 pipe_ctx->stream->sink &&
2351 pipe_ctx->stream->sink == aconnector->dc_sink)
2355 dsc = pipe_ctx->stream_res.dsc;
2357 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2359 snprintf(rd_buf_ptr, str_len,
2361 dsc_state.dsc_pic_height);
2362 rd_buf_ptr += str_len;
2365 if (*pos >= rd_buf_size)
2368 r = put_user(*(rd_buf + result), buf);
2371 return r; /* r = -EFAULT */
2384 /* function: read DSC chunk size parameter on the connector
2386 * The read function: dp_dsc_chunk_size_read
2387 * returns dsc chunk size set in the current configuration
2388 * The value is calculated automatically by DSC code
2389 * and depends on slice parameters and bpp target rate
2390 * The return is an integer: 0 or other positive integer
2391 * If 0 then DSC is disabled.
2393 * Access it with the following command:
2395 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2397 * 0 - means that DSC is disabled
2399 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2400 size_t size, loff_t *pos)
2402 char *rd_buf = NULL;
2403 char *rd_buf_ptr = 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 rd_buf_ptr = rd_buf;
2419 for (i = 0; i < MAX_PIPES; i++) {
2420 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2421 if (pipe_ctx->stream &&
2422 pipe_ctx->stream->link == aconnector->dc_link &&
2423 pipe_ctx->stream->sink &&
2424 pipe_ctx->stream->sink == aconnector->dc_sink)
2428 dsc = pipe_ctx->stream_res.dsc;
2430 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2432 snprintf(rd_buf_ptr, str_len,
2434 dsc_state.dsc_chunk_size);
2435 rd_buf_ptr += str_len;
2438 if (*pos >= rd_buf_size)
2441 r = put_user(*(rd_buf + result), buf);
2444 return r; /* r = -EFAULT */
2457 /* function: read DSC slice bpg offset on the connector
2459 * The read function: dp_dsc_slice_bpg_offset_read
2460 * returns dsc bpg slice offset set in the current configuration
2461 * The value is calculated automatically by DSC code
2462 * and depends on slice parameters and bpp target rate
2463 * The return is an integer: 0 or other positive integer
2464 * If 0 then DSC is disabled.
2466 * Access it with the following command:
2468 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2470 * 0 - means that DSC is disabled
2472 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2473 size_t size, loff_t *pos)
2475 char *rd_buf = NULL;
2476 char *rd_buf_ptr = NULL;
2477 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2478 struct display_stream_compressor *dsc;
2479 struct dcn_dsc_state dsc_state = {0};
2480 const uint32_t rd_buf_size = 100;
2481 struct pipe_ctx *pipe_ctx;
2483 int i, r, str_len = 30;
2485 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2490 rd_buf_ptr = rd_buf;
2492 for (i = 0; i < MAX_PIPES; i++) {
2493 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2494 if (pipe_ctx->stream &&
2495 pipe_ctx->stream->link == aconnector->dc_link &&
2496 pipe_ctx->stream->sink &&
2497 pipe_ctx->stream->sink == aconnector->dc_sink)
2501 dsc = pipe_ctx->stream_res.dsc;
2503 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2505 snprintf(rd_buf_ptr, str_len,
2507 dsc_state.dsc_slice_bpg_offset);
2508 rd_buf_ptr += str_len;
2511 if (*pos >= rd_buf_size)
2514 r = put_user(*(rd_buf + result), buf);
2517 return r; /* r = -EFAULT */
2532 * function description: Read max_requested_bpc property from the connector
2534 * Access it with the following command:
2536 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2539 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2540 size_t size, loff_t *pos)
2542 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2543 struct drm_connector *connector = &aconnector->base;
2544 struct drm_device *dev = connector->dev;
2545 struct dm_connector_state *state;
2547 char *rd_buf = NULL;
2548 char *rd_buf_ptr = NULL;
2549 const uint32_t rd_buf_size = 10;
2552 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2557 mutex_lock(&dev->mode_config.mutex);
2558 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2560 if (connector->state == NULL)
2563 state = to_dm_connector_state(connector->state);
2565 rd_buf_ptr = rd_buf;
2566 snprintf(rd_buf_ptr, rd_buf_size,
2568 state->base.max_requested_bpc);
2571 if (*pos >= rd_buf_size)
2574 r = put_user(*(rd_buf + result), buf);
2576 result = r; /* r = -EFAULT */
2585 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2586 mutex_unlock(&dev->mode_config.mutex);
2593 * function description: Set max_requested_bpc property on the connector
2595 * This function will not force the input BPC on connector, it will only
2596 * change the max value. This is equivalent to setting max_bpc through
2599 * The BPC value written must be >= 6 and <= 16. Values outside of this
2600 * range will result in errors.
2609 * Write the max_bpc in the following way:
2611 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2614 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2615 size_t size, loff_t *pos)
2617 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2618 struct drm_connector *connector = &aconnector->base;
2619 struct dm_connector_state *state;
2620 struct drm_device *dev = connector->dev;
2621 char *wr_buf = NULL;
2622 uint32_t wr_buf_size = 42;
2623 int max_param_num = 1;
2624 long param[1] = {0};
2625 uint8_t param_nums = 0;
2630 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2633 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2637 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2645 if (param_nums <= 0) {
2646 DRM_DEBUG_DRIVER("user data not be read\n");
2651 if (param[0] < 6 || param[0] > 16) {
2652 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2657 mutex_lock(&dev->mode_config.mutex);
2658 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2660 if (connector->state == NULL)
2663 state = to_dm_connector_state(connector->state);
2664 state->base.max_requested_bpc = param[0];
2666 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2667 mutex_unlock(&dev->mode_config.mutex);
2674 * IPS status. Read only.
2676 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_ips_status
2678 static int ips_status_show(struct seq_file *m, void *unused)
2680 struct amdgpu_device *adev = m->private;
2681 struct dc *dc = adev->dm.dc;
2682 struct dc_dmub_srv *dc_dmub_srv;
2684 seq_printf(m, "IPS config: %d\n", dc->config.disable_ips);
2685 seq_printf(m, "Idle optimization: %d\n", dc->idle_optimizations_allowed);
2687 if (adev->dm.idle_workqueue) {
2688 seq_printf(m, "Idle workqueue - enabled: %d\n", adev->dm.idle_workqueue->enable);
2689 seq_printf(m, "Idle workqueue - running: %d\n", adev->dm.idle_workqueue->running);
2692 dc_dmub_srv = dc->ctx->dmub_srv;
2693 if (dc_dmub_srv && dc_dmub_srv->dmub) {
2694 uint32_t rcg_count, ips1_count, ips2_count;
2695 volatile const struct dmub_shared_state_ips_fw *ips_fw =
2696 &dc_dmub_srv->dmub->shared_state[DMUB_SHARED_SHARE_FEATURE__IPS_FW].data.ips_fw;
2697 rcg_count = ips_fw->rcg_entry_count;
2698 ips1_count = ips_fw->ips1_entry_count;
2699 ips2_count = ips_fw->ips2_entry_count;
2700 seq_printf(m, "entry counts: rcg=%u ips1=%u ips2=%u\n",
2704 rcg_count = ips_fw->rcg_exit_count;
2705 ips1_count = ips_fw->ips1_exit_count;
2706 ips2_count = ips_fw->ips2_exit_count;
2707 seq_printf(m, "exit counts: rcg=%u ips1=%u ips2=%u",
2717 * Backlight at this moment. Read only.
2718 * As written to display, taking ABM and backlight lut into account.
2719 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2721 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/current_backlight
2723 static int current_backlight_show(struct seq_file *m, void *unused)
2725 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2726 struct dc_link *link = aconnector->dc_link;
2727 unsigned int backlight;
2729 backlight = dc_link_get_backlight_level(link);
2730 seq_printf(m, "0x%x\n", backlight);
2736 * Backlight value that is being approached. Read only.
2737 * As written to display, taking ABM and backlight lut into account.
2738 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2740 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/target_backlight
2742 static int target_backlight_show(struct seq_file *m, void *unused)
2744 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2745 struct dc_link *link = aconnector->dc_link;
2746 unsigned int backlight;
2748 backlight = dc_link_get_target_backlight_pwm(link);
2749 seq_printf(m, "0x%x\n", backlight);
2755 * function description: Determine if the connector is mst connector
2757 * This function helps to determine whether a connector is a mst connector.
2758 * - "root" stands for the root connector of the topology
2759 * - "branch" stands for branch device of the topology
2760 * - "end" stands for leaf node connector of the topology
2761 * - "no" stands for the connector is not a device of a mst topology
2762 * Access it with the following command:
2764 * cat /sys/kernel/debug/dri/0/DP-X/is_mst_connector
2767 static int dp_is_mst_connector_show(struct seq_file *m, void *unused)
2769 struct drm_connector *connector = m->private;
2770 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2771 struct drm_dp_mst_topology_mgr *mgr = NULL;
2772 struct drm_dp_mst_port *port = NULL;
2775 mutex_lock(&aconnector->hpd_lock);
2777 if (aconnector->mst_mgr.mst_state) {
2779 } else if (aconnector->mst_root &&
2780 aconnector->mst_root->mst_mgr.mst_state) {
2784 mgr = &aconnector->mst_root->mst_mgr;
2785 port = aconnector->mst_output_port;
2787 drm_modeset_lock(&mgr->base.lock, NULL);
2788 if (port->pdt == DP_PEER_DEVICE_MST_BRANCHING &&
2791 drm_modeset_unlock(&mgr->base.lock);
2797 seq_printf(m, "%s\n", role);
2799 mutex_unlock(&aconnector->hpd_lock);
2805 * function description: Read out the mst progress status
2807 * This function helps to determine the mst progress status of
2810 * Access it with the following command:
2812 * cat /sys/kernel/debug/dri/0/DP-X/mst_progress_status
2815 static int dp_mst_progress_status_show(struct seq_file *m, void *unused)
2817 struct drm_connector *connector = m->private;
2818 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2819 struct amdgpu_device *adev = drm_to_adev(connector->dev);
2822 mutex_lock(&aconnector->hpd_lock);
2823 mutex_lock(&adev->dm.dc_lock);
2825 if (aconnector->mst_status == MST_STATUS_DEFAULT) {
2826 seq_puts(m, "disabled\n");
2828 for (i = 0; i < sizeof(mst_progress_status)/sizeof(char *); i++)
2829 seq_printf(m, "%s:%s\n",
2830 mst_progress_status[i],
2831 aconnector->mst_status & BIT(i) ? "done" : "not_done");
2834 mutex_unlock(&adev->dm.dc_lock);
2835 mutex_unlock(&aconnector->hpd_lock);
2841 * Reports whether the connected display is a USB4 DPIA tunneled display
2842 * Example usage: cat /sys/kernel/debug/dri/0/DP-8/is_dpia_link
2844 static int is_dpia_link_show(struct seq_file *m, void *data)
2846 struct drm_connector *connector = m->private;
2847 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2848 struct dc_link *link = aconnector->dc_link;
2850 if (connector->status != connector_status_connected)
2853 seq_printf(m, "%s\n", (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) ? "yes" :
2854 (link->ep_type == DISPLAY_ENDPOINT_PHY) ? "no" : "unknown");
2859 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2860 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2861 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2862 DEFINE_SHOW_ATTRIBUTE(dp_lttpr_status);
2863 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2864 DEFINE_SHOW_ATTRIBUTE(internal_display);
2865 DEFINE_SHOW_ATTRIBUTE(odm_combine_segments);
2866 DEFINE_SHOW_ATTRIBUTE(replay_capability);
2867 DEFINE_SHOW_ATTRIBUTE(psr_capability);
2868 DEFINE_SHOW_ATTRIBUTE(dp_is_mst_connector);
2869 DEFINE_SHOW_ATTRIBUTE(dp_mst_progress_status);
2870 DEFINE_SHOW_ATTRIBUTE(is_dpia_link);
2872 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2873 .owner = THIS_MODULE,
2874 .read = dp_dsc_clock_en_read,
2875 .write = dp_dsc_clock_en_write,
2876 .llseek = default_llseek
2879 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2880 .owner = THIS_MODULE,
2881 .read = dp_dsc_slice_width_read,
2882 .write = dp_dsc_slice_width_write,
2883 .llseek = default_llseek
2886 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2887 .owner = THIS_MODULE,
2888 .read = dp_dsc_slice_height_read,
2889 .write = dp_dsc_slice_height_write,
2890 .llseek = default_llseek
2893 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2894 .owner = THIS_MODULE,
2895 .read = dp_dsc_bits_per_pixel_read,
2896 .write = dp_dsc_bits_per_pixel_write,
2897 .llseek = default_llseek
2900 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2901 .owner = THIS_MODULE,
2902 .read = dp_dsc_pic_width_read,
2903 .llseek = default_llseek
2906 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2907 .owner = THIS_MODULE,
2908 .read = dp_dsc_pic_height_read,
2909 .llseek = default_llseek
2912 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2913 .owner = THIS_MODULE,
2914 .read = dp_dsc_chunk_size_read,
2915 .llseek = default_llseek
2918 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2919 .owner = THIS_MODULE,
2920 .read = dp_dsc_slice_bpg_offset_read,
2921 .llseek = default_llseek
2924 static const struct file_operations trigger_hotplug_debugfs_fops = {
2925 .owner = THIS_MODULE,
2926 .write = trigger_hotplug,
2927 .llseek = default_llseek
2930 static const struct file_operations dp_link_settings_debugfs_fops = {
2931 .owner = THIS_MODULE,
2932 .read = dp_link_settings_read,
2933 .write = dp_link_settings_write,
2934 .llseek = default_llseek
2937 static const struct file_operations dp_phy_settings_debugfs_fop = {
2938 .owner = THIS_MODULE,
2939 .read = dp_phy_settings_read,
2940 .write = dp_phy_settings_write,
2941 .llseek = default_llseek
2944 static const struct file_operations dp_phy_test_pattern_fops = {
2945 .owner = THIS_MODULE,
2946 .write = dp_phy_test_pattern_debugfs_write,
2947 .llseek = default_llseek
2950 static const struct file_operations sdp_message_fops = {
2951 .owner = THIS_MODULE,
2952 .write = dp_sdp_message_debugfs_write,
2953 .llseek = default_llseek
2956 static const struct file_operations dp_max_bpc_debugfs_fops = {
2957 .owner = THIS_MODULE,
2958 .read = dp_max_bpc_read,
2959 .write = dp_max_bpc_write,
2960 .llseek = default_llseek
2963 static const struct file_operations dp_dsc_disable_passthrough_debugfs_fops = {
2964 .owner = THIS_MODULE,
2965 .write = dp_dsc_passthrough_set,
2966 .llseek = default_llseek
2969 static const struct file_operations dp_mst_link_settings_debugfs_fops = {
2970 .owner = THIS_MODULE,
2971 .write = dp_mst_link_setting,
2972 .llseek = default_llseek
2975 static const struct {
2977 const struct file_operations *fops;
2978 } dp_debugfs_entries[] = {
2979 {"link_settings", &dp_link_settings_debugfs_fops},
2980 {"phy_settings", &dp_phy_settings_debugfs_fop},
2981 {"lttpr_status", &dp_lttpr_status_fops},
2982 {"test_pattern", &dp_phy_test_pattern_fops},
2983 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2984 {"sdp_message", &sdp_message_fops},
2985 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2986 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2987 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2988 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2989 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2990 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2991 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2992 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2993 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
2994 {"max_bpc", &dp_max_bpc_debugfs_fops},
2995 {"dsc_disable_passthrough", &dp_dsc_disable_passthrough_debugfs_fops},
2996 {"is_mst_connector", &dp_is_mst_connector_fops},
2997 {"mst_progress_status", &dp_mst_progress_status_fops},
2998 {"is_dpia_link", &is_dpia_link_fops},
2999 {"mst_link_settings", &dp_mst_link_settings_debugfs_fops}
3002 static const struct {
3004 const struct file_operations *fops;
3005 } hdmi_debugfs_entries[] = {
3006 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
3010 * Force YUV420 output if available from the given mode
3012 static int force_yuv420_output_set(void *data, u64 val)
3014 struct amdgpu_dm_connector *connector = data;
3016 connector->force_yuv420_output = (bool)val;
3022 * Check if YUV420 is forced when available from the given mode
3024 static int force_yuv420_output_get(void *data, u64 *val)
3026 struct amdgpu_dm_connector *connector = data;
3028 *val = connector->force_yuv420_output;
3033 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
3034 force_yuv420_output_set, "%llu\n");
3039 static int replay_get_state(void *data, u64 *val)
3041 struct amdgpu_dm_connector *connector = data;
3042 struct dc_link *link = connector->dc_link;
3043 uint64_t state = REPLAY_STATE_INVALID;
3045 dc_link_get_replay_state(link, &state);
3055 static int psr_get(void *data, u64 *val)
3057 struct amdgpu_dm_connector *connector = data;
3058 struct dc_link *link = connector->dc_link;
3059 enum dc_psr_state state = PSR_STATE0;
3061 dc_link_get_psr_state(link, &state);
3069 * Read PSR state residency
3071 static int psr_read_residency(void *data, u64 *val)
3073 struct amdgpu_dm_connector *connector = data;
3074 struct dc_link *link = connector->dc_link;
3077 link->dc->link_srv->edp_get_psr_residency(link, &residency);
3079 *val = (u64)residency;
3084 /* read allow_edp_hotplug_detection */
3085 static int allow_edp_hotplug_detection_get(void *data, u64 *val)
3087 struct amdgpu_dm_connector *aconnector = data;
3088 struct drm_connector *connector = &aconnector->base;
3089 struct drm_device *dev = connector->dev;
3090 struct amdgpu_device *adev = drm_to_adev(dev);
3092 *val = adev->dm.dc->config.allow_edp_hotplug_detection;
3097 /* set allow_edp_hotplug_detection */
3098 static int allow_edp_hotplug_detection_set(void *data, u64 val)
3100 struct amdgpu_dm_connector *aconnector = data;
3101 struct drm_connector *connector = &aconnector->base;
3102 struct drm_device *dev = connector->dev;
3103 struct amdgpu_device *adev = drm_to_adev(dev);
3105 adev->dm.dc->config.allow_edp_hotplug_detection = (uint32_t) val;
3110 /* check if kernel disallow eDP enter psr state
3111 * cat /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
3112 * 0: allow edp enter psr; 1: disallow
3114 static int disallow_edp_enter_psr_get(void *data, u64 *val)
3116 struct amdgpu_dm_connector *aconnector = data;
3118 *val = (u64) aconnector->disallow_edp_enter_psr;
3122 /* set kernel disallow eDP enter psr state
3123 * echo 0x0 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
3124 * 0: allow edp enter psr; 1: disallow
3126 * usage: test app read crc from PSR eDP rx.
3128 * during kernel boot up, kernel write dpcd 0x170 = 5.
3129 * this notify eDP rx psr enable and let rx check crc.
3130 * rx fw will start checking crc for rx internal logic.
3131 * crc read count within dpcd 0x246 is not updated and
3132 * value is 0. when eDP tx driver wants to read rx crc
3133 * from dpcd 0x246, 0x270, read count 0 lead tx driver
3136 * to avoid this, we add this debugfs to let test app to disbable
3137 * rx crc checking for rx internal logic. then test app can read
3138 * non-zero crc read count.
3140 * expected app sequence is as below:
3141 * 1. disable eDP PHY and notify eDP rx with dpcd 0x600 = 2.
3142 * 2. echo 0x1 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
3143 * 3. enable eDP PHY and notify eDP rx with dpcd 0x600 = 1 but
3144 * without dpcd 0x170 = 5.
3145 * 4. read crc from rx dpcd 0x270, 0x246, etc.
3146 * 5. echo 0x0 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr.
3147 * this will let eDP back to normal with psr setup dpcd 0x170 = 5.
3149 static int disallow_edp_enter_psr_set(void *data, u64 val)
3151 struct amdgpu_dm_connector *aconnector = data;
3153 aconnector->disallow_edp_enter_psr = val ? true : false;
3157 static int dmub_trace_mask_set(void *data, u64 val)
3159 struct amdgpu_device *adev = data;
3160 struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
3161 enum dmub_gpint_command cmd;
3167 if (!srv->fw_version)
3170 for (i = 0; i < 4; i++) {
3171 res = (val & mask) >> shift;
3175 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD0;
3178 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD1;
3181 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD2;
3184 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD3;
3188 if (!dc_wake_and_execute_gpint(adev->dm.dc->ctx, cmd, res, NULL, DM_DMUB_WAIT_TYPE_WAIT))
3191 usleep_range(100, 1000);
3200 static int dmub_trace_mask_show(void *data, u64 *val)
3202 enum dmub_gpint_command cmd = DMUB_GPINT__GET_TRACE_BUFFER_MASK_WORD0;
3203 struct amdgpu_device *adev = data;
3204 struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
3210 if (!srv->fw_version)
3216 if (!dc_wake_and_execute_gpint(adev->dm.dc->ctx, cmd, 0, &response, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY))
3220 usleep_range(100, 1000);
3223 res |= (raw << shift);
3233 DEFINE_DEBUGFS_ATTRIBUTE(dmub_trace_mask_fops, dmub_trace_mask_show,
3234 dmub_trace_mask_set, "0x%llx\n");
3237 * Set dmcub trace event IRQ enable or disable.
3238 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3239 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3241 static int dmcub_trace_event_state_set(void *data, u64 val)
3243 struct amdgpu_device *adev = data;
3245 if (val == 1 || val == 0) {
3246 dc_dmub_trace_event_control(adev->dm.dc, val);
3247 adev->dm.dmcub_trace_event_en = (bool)val;
3255 * The interface doesn't need get function, so it will return the
3257 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3259 static int dmcub_trace_event_state_get(void *data, u64 *val)
3261 struct amdgpu_device *adev = data;
3263 *val = adev->dm.dmcub_trace_event_en;
3267 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
3268 dmcub_trace_event_state_set, "%llu\n");
3270 DEFINE_DEBUGFS_ATTRIBUTE(replay_state_fops, replay_get_state, NULL, "%llu\n");
3272 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
3273 DEFINE_DEBUGFS_ATTRIBUTE(psr_residency_fops, psr_read_residency, NULL,
3276 DEFINE_DEBUGFS_ATTRIBUTE(allow_edp_hotplug_detection_fops,
3277 allow_edp_hotplug_detection_get,
3278 allow_edp_hotplug_detection_set, "%llu\n");
3280 DEFINE_DEBUGFS_ATTRIBUTE(disallow_edp_enter_psr_fops,
3281 disallow_edp_enter_psr_get,
3282 disallow_edp_enter_psr_set, "%llu\n");
3284 DEFINE_SHOW_ATTRIBUTE(current_backlight);
3285 DEFINE_SHOW_ATTRIBUTE(target_backlight);
3286 DEFINE_SHOW_ATTRIBUTE(ips_status);
3288 static const struct {
3290 const struct file_operations *fops;
3291 } connector_debugfs_entries[] = {
3292 {"force_yuv420_output", &force_yuv420_output_fops},
3293 {"trigger_hotplug", &trigger_hotplug_debugfs_fops},
3294 {"internal_display", &internal_display_fops},
3295 {"odm_combine_segments", &odm_combine_segments_fops}
3299 * Returns supported customized link rates by this eDP panel.
3300 * Example usage: cat /sys/kernel/debug/dri/0/eDP-x/ilr_setting
3302 static int edp_ilr_show(struct seq_file *m, void *unused)
3304 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
3305 struct dc_link *link = aconnector->dc_link;
3306 uint8_t supported_link_rates[16];
3307 uint32_t link_rate_in_khz;
3311 memset(supported_link_rates, 0, sizeof(supported_link_rates));
3312 dm_helpers_dp_read_dpcd(link->ctx, link, DP_SUPPORTED_LINK_RATES,
3313 supported_link_rates, sizeof(supported_link_rates));
3315 dpcd_rev = link->dpcd_caps.dpcd_rev.raw;
3317 if (dpcd_rev >= DP_DPCD_REV_13 &&
3318 (supported_link_rates[entry+1] != 0 || supported_link_rates[entry] != 0)) {
3320 for (entry = 0; entry < 16; entry += 2) {
3321 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
3322 supported_link_rates[entry]) * 200;
3323 seq_printf(m, "[%d] %d kHz\n", entry/2, link_rate_in_khz);
3326 seq_puts(m, "ILR is not supported by this eDP panel.\n");
3333 * Set supported customized link rate to eDP panel.
3335 * echo <lane_count> <link_rate option> > ilr_setting
3337 * for example, supported ILR : [0] 1620000 kHz [1] 2160000 kHz [2] 2430000 kHz ...
3338 * echo 4 1 > /sys/kernel/debug/dri/0/eDP-x/ilr_setting
3339 * to set 4 lanes and 2.16 GHz
3341 static ssize_t edp_ilr_write(struct file *f, const char __user *buf,
3342 size_t size, loff_t *pos)
3344 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
3345 struct dc_link *link = connector->dc_link;
3346 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
3347 struct dc *dc = (struct dc *)link->dc;
3348 struct dc_link_settings prefer_link_settings;
3349 char *wr_buf = NULL;
3350 const uint32_t wr_buf_size = 40;
3351 /* 0: lane_count; 1: link_rate */
3352 int max_param_num = 2;
3353 uint8_t param_nums = 0;
3355 bool valid_input = true;
3360 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
3364 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
3372 if (param_nums <= 0) {
3378 case LANE_COUNT_ONE:
3379 case LANE_COUNT_TWO:
3380 case LANE_COUNT_FOUR:
3383 valid_input = false;
3387 if (param[1] >= link->dpcd_caps.edp_supported_link_rates_count)
3388 valid_input = false;
3392 DRM_DEBUG_DRIVER("Invalid Input value. No HW will be programmed\n");
3393 prefer_link_settings.use_link_rate_set = false;
3394 mutex_lock(&adev->dm.dc_lock);
3395 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
3396 mutex_unlock(&adev->dm.dc_lock);
3400 /* save user force lane_count, link_rate to preferred settings
3401 * spread spectrum will not be changed
3403 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
3404 prefer_link_settings.lane_count = param[0];
3405 prefer_link_settings.use_link_rate_set = true;
3406 prefer_link_settings.link_rate_set = param[1];
3407 prefer_link_settings.link_rate = link->dpcd_caps.edp_supported_link_rates[param[1]];
3409 mutex_lock(&adev->dm.dc_lock);
3410 dc_link_set_preferred_training_settings(dc, &prefer_link_settings,
3412 mutex_unlock(&adev->dm.dc_lock);
3418 static int edp_ilr_open(struct inode *inode, struct file *file)
3420 return single_open(file, edp_ilr_show, inode->i_private);
3423 static const struct file_operations edp_ilr_debugfs_fops = {
3424 .owner = THIS_MODULE,
3425 .open = edp_ilr_open,
3427 .llseek = seq_lseek,
3428 .release = single_release,
3429 .write = edp_ilr_write
3432 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
3435 struct dentry *dir = connector->base.debugfs_entry;
3437 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
3438 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3439 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
3440 debugfs_create_file(dp_debugfs_entries[i].name,
3441 0644, dir, connector,
3442 dp_debugfs_entries[i].fops);
3445 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3446 debugfs_create_file("replay_capability", 0444, dir, connector,
3447 &replay_capability_fops);
3448 debugfs_create_file("replay_state", 0444, dir, connector, &replay_state_fops);
3449 debugfs_create_file_unsafe("psr_capability", 0444, dir, connector, &psr_capability_fops);
3450 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
3451 debugfs_create_file_unsafe("psr_residency", 0444, dir,
3452 connector, &psr_residency_fops);
3453 debugfs_create_file("amdgpu_current_backlight_pwm", 0444, dir, connector,
3454 ¤t_backlight_fops);
3455 debugfs_create_file("amdgpu_target_backlight_pwm", 0444, dir, connector,
3456 &target_backlight_fops);
3457 debugfs_create_file("ilr_setting", 0644, dir, connector,
3458 &edp_ilr_debugfs_fops);
3459 debugfs_create_file("allow_edp_hotplug_detection", 0644, dir, connector,
3460 &allow_edp_hotplug_detection_fops);
3461 debugfs_create_file("disallow_edp_enter_psr", 0644, dir, connector,
3462 &disallow_edp_enter_psr_fops);
3465 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
3466 debugfs_create_file(connector_debugfs_entries[i].name,
3467 0644, dir, connector,
3468 connector_debugfs_entries[i].fops);
3471 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
3472 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
3473 debugfs_create_file(hdmi_debugfs_entries[i].name,
3474 0644, dir, connector,
3475 hdmi_debugfs_entries[i].fops);
3480 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3482 * Set crc window coordinate x start
3484 static int crc_win_x_start_set(void *data, u64 val)
3486 struct drm_crtc *crtc = data;
3487 struct drm_device *drm_dev = crtc->dev;
3488 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3490 spin_lock_irq(&drm_dev->event_lock);
3491 acrtc->dm_irq_params.window_param.x_start = (uint16_t) val;
3492 acrtc->dm_irq_params.window_param.update_win = false;
3493 spin_unlock_irq(&drm_dev->event_lock);
3499 * Get crc window coordinate x start
3501 static int crc_win_x_start_get(void *data, u64 *val)
3503 struct drm_crtc *crtc = data;
3504 struct drm_device *drm_dev = crtc->dev;
3505 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3507 spin_lock_irq(&drm_dev->event_lock);
3508 *val = acrtc->dm_irq_params.window_param.x_start;
3509 spin_unlock_irq(&drm_dev->event_lock);
3514 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
3515 crc_win_x_start_set, "%llu\n");
3519 * Set crc window coordinate y start
3521 static int crc_win_y_start_set(void *data, u64 val)
3523 struct drm_crtc *crtc = data;
3524 struct drm_device *drm_dev = crtc->dev;
3525 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3527 spin_lock_irq(&drm_dev->event_lock);
3528 acrtc->dm_irq_params.window_param.y_start = (uint16_t) val;
3529 acrtc->dm_irq_params.window_param.update_win = false;
3530 spin_unlock_irq(&drm_dev->event_lock);
3536 * Get crc window coordinate y start
3538 static int crc_win_y_start_get(void *data, u64 *val)
3540 struct drm_crtc *crtc = data;
3541 struct drm_device *drm_dev = crtc->dev;
3542 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3544 spin_lock_irq(&drm_dev->event_lock);
3545 *val = acrtc->dm_irq_params.window_param.y_start;
3546 spin_unlock_irq(&drm_dev->event_lock);
3551 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
3552 crc_win_y_start_set, "%llu\n");
3555 * Set crc window coordinate x end
3557 static int crc_win_x_end_set(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 acrtc->dm_irq_params.window_param.x_end = (uint16_t) val;
3565 acrtc->dm_irq_params.window_param.update_win = false;
3566 spin_unlock_irq(&drm_dev->event_lock);
3572 * Get crc window coordinate x end
3574 static int crc_win_x_end_get(void *data, u64 *val)
3576 struct drm_crtc *crtc = data;
3577 struct drm_device *drm_dev = crtc->dev;
3578 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3580 spin_lock_irq(&drm_dev->event_lock);
3581 *val = acrtc->dm_irq_params.window_param.x_end;
3582 spin_unlock_irq(&drm_dev->event_lock);
3587 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
3588 crc_win_x_end_set, "%llu\n");
3591 * Set crc window coordinate y end
3593 static int crc_win_y_end_set(void *data, u64 val)
3595 struct drm_crtc *crtc = data;
3596 struct drm_device *drm_dev = crtc->dev;
3597 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3599 spin_lock_irq(&drm_dev->event_lock);
3600 acrtc->dm_irq_params.window_param.y_end = (uint16_t) val;
3601 acrtc->dm_irq_params.window_param.update_win = false;
3602 spin_unlock_irq(&drm_dev->event_lock);
3608 * Get crc window coordinate y end
3610 static int crc_win_y_end_get(void *data, u64 *val)
3612 struct drm_crtc *crtc = data;
3613 struct drm_device *drm_dev = crtc->dev;
3614 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3616 spin_lock_irq(&drm_dev->event_lock);
3617 *val = acrtc->dm_irq_params.window_param.y_end;
3618 spin_unlock_irq(&drm_dev->event_lock);
3623 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
3624 crc_win_y_end_set, "%llu\n");
3626 * Trigger to commit crc window
3628 static int crc_win_update_set(void *data, u64 val)
3630 struct drm_crtc *crtc = data;
3631 struct amdgpu_crtc *acrtc;
3632 struct amdgpu_device *adev = drm_to_adev(crtc->dev);
3635 acrtc = to_amdgpu_crtc(crtc);
3636 mutex_lock(&adev->dm.dc_lock);
3637 /* PSR may write to OTG CRC window control register,
3638 * so close it before starting secure_display.
3640 amdgpu_dm_psr_disable(acrtc->dm_irq_params.stream);
3642 spin_lock_irq(&adev_to_drm(adev)->event_lock);
3644 acrtc->dm_irq_params.window_param.activated = true;
3645 acrtc->dm_irq_params.window_param.update_win = true;
3646 acrtc->dm_irq_params.window_param.skip_frame_cnt = 0;
3648 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
3649 mutex_unlock(&adev->dm.dc_lock);
3656 * Get crc window update flag
3658 static int crc_win_update_get(void *data, u64 *val)
3664 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
3665 crc_win_update_set, "%llu\n");
3667 void crtc_debugfs_init(struct drm_crtc *crtc)
3669 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3670 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
3675 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
3676 &crc_win_x_start_fops);
3677 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
3678 &crc_win_y_start_fops);
3679 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
3680 &crc_win_x_end_fops);
3681 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
3682 &crc_win_y_end_fops);
3683 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
3684 &crc_win_update_fops);
3687 debugfs_create_file("amdgpu_current_bpc", 0644, crtc->debugfs_entry,
3688 crtc, &amdgpu_current_bpc_fops);
3689 debugfs_create_file("amdgpu_current_colorspace", 0644, crtc->debugfs_entry,
3690 crtc, &amdgpu_current_colorspace_fops);
3694 * Writes DTN log state to the user supplied buffer.
3695 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3697 static ssize_t dtn_log_read(
3703 struct amdgpu_device *adev = file_inode(f)->i_private;
3704 struct dc *dc = adev->dm.dc;
3705 struct dc_log_buffer_ctx log_ctx = { 0 };
3711 if (!dc->hwss.log_hw_state)
3714 dc->hwss.log_hw_state(dc, &log_ctx);
3716 if (*pos < log_ctx.pos) {
3717 size_t to_copy = log_ctx.pos - *pos;
3719 to_copy = min(to_copy, size);
3721 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
3733 * Writes DTN log state to dmesg when triggered via a write.
3734 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3736 static ssize_t dtn_log_write(
3738 const char __user *buf,
3742 struct amdgpu_device *adev = file_inode(f)->i_private;
3743 struct dc *dc = adev->dm.dc;
3745 /* Write triggers log output via dmesg. */
3749 if (dc->hwss.log_hw_state)
3750 dc->hwss.log_hw_state(dc, NULL);
3755 static int mst_topo_show(struct seq_file *m, void *unused)
3757 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3758 struct drm_device *dev = adev_to_drm(adev);
3759 struct drm_connector *connector;
3760 struct drm_connector_list_iter conn_iter;
3761 struct amdgpu_dm_connector *aconnector;
3763 drm_connector_list_iter_begin(dev, &conn_iter);
3764 drm_for_each_connector_iter(connector, &conn_iter) {
3765 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3768 aconnector = to_amdgpu_dm_connector(connector);
3770 /* Ensure we're only dumping the topology of a root mst node */
3771 if (!aconnector->mst_mgr.mst_state)
3774 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
3775 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
3777 drm_connector_list_iter_end(&conn_iter);
3783 * Sets trigger hpd for MST topologies.
3784 * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
3785 * All topologies will be disconnected if val of 0 is set .
3786 * Usage to enable topologies: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3787 * Usage to disable topologies: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3789 static int trigger_hpd_mst_set(void *data, u64 val)
3791 struct amdgpu_device *adev = data;
3792 struct drm_device *dev = adev_to_drm(adev);
3793 struct drm_connector_list_iter iter;
3794 struct amdgpu_dm_connector *aconnector;
3795 struct drm_connector *connector;
3796 struct dc_link *link = NULL;
3799 drm_connector_list_iter_begin(dev, &iter);
3800 drm_for_each_connector_iter(connector, &iter) {
3801 aconnector = to_amdgpu_dm_connector(connector);
3802 if (aconnector->dc_link->type == dc_connection_mst_branch &&
3803 aconnector->mst_mgr.aux) {
3804 mutex_lock(&adev->dm.dc_lock);
3805 dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3806 mutex_unlock(&adev->dm.dc_lock);
3808 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
3811 } else if (val == 0) {
3812 drm_connector_list_iter_begin(dev, &iter);
3813 drm_for_each_connector_iter(connector, &iter) {
3814 aconnector = to_amdgpu_dm_connector(connector);
3815 if (!aconnector->dc_link)
3818 if (!aconnector->mst_root)
3821 link = aconnector->dc_link;
3822 dc_link_dp_receiver_power_ctrl(link, false);
3823 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_root->mst_mgr, false);
3824 link->mst_stream_alloc_table.stream_count = 0;
3825 memset(link->mst_stream_alloc_table.stream_allocations, 0,
3826 sizeof(link->mst_stream_alloc_table.stream_allocations));
3831 drm_kms_helper_hotplug_event(dev);
3837 * The interface doesn't need get function, so it will return the
3839 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3841 static int trigger_hpd_mst_get(void *data, u64 *val)
3847 DEFINE_DEBUGFS_ATTRIBUTE(trigger_hpd_mst_ops, trigger_hpd_mst_get,
3848 trigger_hpd_mst_set, "%llu\n");
3852 * Sets the force_timing_sync debug option from the given string.
3853 * All connected displays will be force synchronized immediately.
3854 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3856 static int force_timing_sync_set(void *data, u64 val)
3858 struct amdgpu_device *adev = data;
3860 adev->dm.force_timing_sync = (bool)val;
3862 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
3868 * Gets the force_timing_sync debug option value into the given buffer.
3869 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3871 static int force_timing_sync_get(void *data, u64 *val)
3873 struct amdgpu_device *adev = data;
3875 *val = adev->dm.force_timing_sync;
3880 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
3881 force_timing_sync_set, "%llu\n");
3885 * Disables all HPD and HPD RX interrupt handling in the
3886 * driver when set to 1. Default is 0.
3888 static int disable_hpd_set(void *data, u64 val)
3890 struct amdgpu_device *adev = data;
3892 adev->dm.disable_hpd_irq = (bool)val;
3899 * Returns 1 if HPD and HPRX interrupt handling is disabled,
3902 static int disable_hpd_get(void *data, u64 *val)
3904 struct amdgpu_device *adev = data;
3906 *val = adev->dm.disable_hpd_irq;
3911 DEFINE_DEBUGFS_ATTRIBUTE(disable_hpd_ops, disable_hpd_get,
3912 disable_hpd_set, "%llu\n");
3915 * Prints hardware capabilities. These are used for IGT testing.
3917 static int capabilities_show(struct seq_file *m, void *unused)
3919 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3920 struct dc *dc = adev->dm.dc;
3921 bool mall_supported = dc->caps.mall_size_total;
3922 bool subvp_supported = dc->caps.subvp_fw_processing_delay_us;
3923 unsigned int mall_in_use = false;
3924 unsigned int subvp_in_use = false;
3926 struct hubbub *hubbub = dc->res_pool->hubbub;
3928 if (hubbub->funcs->get_mall_en)
3929 hubbub->funcs->get_mall_en(hubbub, &mall_in_use);
3931 if (dc->cap_funcs.get_subvp_en)
3932 subvp_in_use = dc->cap_funcs.get_subvp_en(dc, dc->current_state);
3934 seq_printf(m, "mall supported: %s, enabled: %s\n",
3935 mall_supported ? "yes" : "no", mall_in_use ? "yes" : "no");
3936 seq_printf(m, "sub-viewport supported: %s, enabled: %s\n",
3937 subvp_supported ? "yes" : "no", subvp_in_use ? "yes" : "no");
3942 DEFINE_SHOW_ATTRIBUTE(capabilities);
3945 * Temporary w/a to force sst sequence in M42D DP2 mst receiver
3946 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_set_mst_en_for_sst
3948 static int dp_force_sst_set(void *data, u64 val)
3950 struct amdgpu_device *adev = data;
3952 adev->dm.dc->debug.set_mst_en_for_sst = val;
3957 static int dp_force_sst_get(void *data, u64 *val)
3959 struct amdgpu_device *adev = data;
3961 *val = adev->dm.dc->debug.set_mst_en_for_sst;
3965 DEFINE_DEBUGFS_ATTRIBUTE(dp_set_mst_en_for_sst_ops, dp_force_sst_get,
3966 dp_force_sst_set, "%llu\n");
3969 * Force DP2 sequence without VESA certified cable.
3970 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_ignore_cable_id
3972 static int dp_ignore_cable_id_set(void *data, u64 val)
3974 struct amdgpu_device *adev = data;
3976 adev->dm.dc->debug.ignore_cable_id = val;
3981 static int dp_ignore_cable_id_get(void *data, u64 *val)
3983 struct amdgpu_device *adev = data;
3985 *val = adev->dm.dc->debug.ignore_cable_id;
3989 DEFINE_DEBUGFS_ATTRIBUTE(dp_ignore_cable_id_ops, dp_ignore_cable_id_get,
3990 dp_ignore_cable_id_set, "%llu\n");
3993 * Sets the DC visual confirm debug option from the given string.
3994 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
3996 static int visual_confirm_set(void *data, u64 val)
3998 struct amdgpu_device *adev = data;
4000 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
4006 * Reads the DC visual confirm debug option value into the given buffer.
4007 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
4009 static int visual_confirm_get(void *data, u64 *val)
4011 struct amdgpu_device *adev = data;
4013 *val = adev->dm.dc->debug.visual_confirm;
4018 DEFINE_SHOW_ATTRIBUTE(mst_topo);
4019 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
4020 visual_confirm_set, "%llu\n");
4024 * Sets the DC skip_detection_link_training debug option from the given string.
4025 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_skip_detection_link_training
4027 static int skip_detection_link_training_set(void *data, u64 val)
4029 struct amdgpu_device *adev = data;
4032 adev->dm.dc->debug.skip_detection_link_training = false;
4034 adev->dm.dc->debug.skip_detection_link_training = true;
4040 * Reads the DC skip_detection_link_training debug option value into the given buffer.
4041 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_skip_detection_link_training
4043 static int skip_detection_link_training_get(void *data, u64 *val)
4045 struct amdgpu_device *adev = data;
4047 *val = adev->dm.dc->debug.skip_detection_link_training;
4052 DEFINE_DEBUGFS_ATTRIBUTE(skip_detection_link_training_fops,
4053 skip_detection_link_training_get,
4054 skip_detection_link_training_set, "%llu\n");
4057 * Dumps the DCC_EN bit for each pipe.
4058 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dcc_en
4060 static ssize_t dcc_en_bits_read(
4066 struct amdgpu_device *adev = file_inode(f)->i_private;
4067 struct dc *dc = adev->dm.dc;
4068 char *rd_buf = NULL;
4069 const uint32_t rd_buf_size = 32;
4070 uint32_t result = 0;
4072 int num_pipes = dc->res_pool->pipe_count;
4076 dcc_en_bits = kcalloc(num_pipes, sizeof(int), GFP_KERNEL);
4080 if (!dc->hwss.get_dcc_en_bits) {
4085 dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
4087 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
4093 for (i = 0; i < num_pipes; i++)
4094 offset += snprintf(rd_buf + offset, rd_buf_size - offset,
4095 "%d ", dcc_en_bits[i]);
4096 rd_buf[strlen(rd_buf)] = '\n';
4101 if (*pos >= rd_buf_size)
4103 r = put_user(*(rd_buf + result), buf);
4106 return r; /* r = -EFAULT */
4118 void dtn_debugfs_init(struct amdgpu_device *adev)
4120 static const struct file_operations dtn_log_fops = {
4121 .owner = THIS_MODULE,
4122 .read = dtn_log_read,
4123 .write = dtn_log_write,
4124 .llseek = default_llseek
4126 static const struct file_operations dcc_en_bits_fops = {
4127 .owner = THIS_MODULE,
4128 .read = dcc_en_bits_read,
4129 .llseek = default_llseek
4132 struct drm_minor *minor = adev_to_drm(adev)->primary;
4133 struct dentry *root = minor->debugfs_root;
4135 debugfs_create_file("amdgpu_mst_topology", 0444, root,
4136 adev, &mst_topo_fops);
4137 debugfs_create_file("amdgpu_dm_capabilities", 0444, root,
4138 adev, &capabilities_fops);
4139 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
4141 debugfs_create_file("amdgpu_dm_dp_set_mst_en_for_sst", 0644, root, adev,
4142 &dp_set_mst_en_for_sst_ops);
4143 debugfs_create_file("amdgpu_dm_dp_ignore_cable_id", 0644, root, adev,
4144 &dp_ignore_cable_id_ops);
4146 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
4147 &visual_confirm_fops);
4149 debugfs_create_file_unsafe("amdgpu_dm_skip_detection_link_training", 0644, root, adev,
4150 &skip_detection_link_training_fops);
4152 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
4153 adev, &dmub_tracebuffer_fops);
4155 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
4156 adev, &dmub_fw_state_fops);
4158 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
4159 adev, &force_timing_sync_ops);
4161 debugfs_create_file_unsafe("amdgpu_dm_dmub_trace_mask", 0644, root,
4162 adev, &dmub_trace_mask_fops);
4164 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
4165 adev, &dmcub_trace_event_state_fops);
4167 debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
4168 adev, &trigger_hpd_mst_ops);
4170 debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
4173 debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,
4176 if (adev->dm.dc->caps.ips_support)
4177 debugfs_create_file_unsafe("amdgpu_dm_ips_status", 0644, root, adev,