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 "dm_helpers.h"
34 #include "dmub/dmub_srv.h"
37 #include "link_hwss.h"
38 #include "dc/dc_dmub_srv.h"
39 #include "link/protocols/link_dp_capability.h"
40 #include "inc/hw/dchubbub.h"
42 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
43 #include "amdgpu_dm_psr.h"
46 struct dmub_debugfs_trace_header {
51 struct dmub_debugfs_trace_entry {
58 static const char *const mst_progress_status[] = {
61 "allocate_new_payload",
62 "clear_allocated_payload",
65 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
67 * Function takes in attributes passed to debugfs write entry
68 * and writes into param array.
69 * The user passes max_param_num to identify maximum number of
70 * parameters that could be parsed.
73 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
74 long *param, const char __user *buf,
78 char *wr_buf_ptr = NULL;
79 uint32_t wr_buf_count = 0;
82 const char delimiter[3] = {' ', '\n', '\0'};
83 uint8_t param_index = 0;
89 /* r is bytes not be copied */
90 if (copy_from_user(wr_buf_ptr, buf, wr_buf_size)) {
91 DRM_DEBUG_DRIVER("user data could not be read successfully\n");
95 /* check number of parameters. isspace could not differ space and \n */
96 while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
98 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
103 if (wr_buf_count == wr_buf_size)
107 while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
114 if (wr_buf_count == wr_buf_size)
118 if (*param_nums > max_param_num)
119 *param_nums = max_param_num;
121 wr_buf_ptr = wr_buf; /* reset buf pointer */
122 wr_buf_count = 0; /* number of char already checked */
124 while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
129 while (param_index < *param_nums) {
130 /* after strsep, wr_buf_ptr will be moved to after space */
131 sub_str = strsep(&wr_buf_ptr, delimiter);
133 r = kstrtol(sub_str, 16, &(param[param_index]));
136 DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
144 /* function description
145 * get/ set DP configuration: lane_count, link_rate, spread_spectrum
147 * valid lane count value: 1, 2, 4
148 * valid link rate value:
149 * 06h = 1.62Gbps per lane
150 * 0Ah = 2.7Gbps per lane
151 * 0Ch = 3.24Gbps per lane
152 * 14h = 5.4Gbps per lane
153 * 1Eh = 8.1Gbps per lane
155 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
157 * --- to get dp configuration
159 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
161 * It will list current, verified, reported, preferred dp configuration.
162 * current -- for current video mode
163 * verified --- maximum configuration which pass link training
164 * reported --- DP rx report caps (DPCD register offset 0, 1 2)
165 * preferred --- user force settings
167 * --- set (or force) dp configuration
169 * echo <lane_count> <link_rate> > link_settings
171 * for example, to force to 2 lane, 2.7GHz,
172 * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
174 * spread_spectrum could not be changed dynamically.
176 * in case invalid lane count, link rate are force, no hw programming will be
177 * done. please check link settings after force operation to see if HW get
180 * cat /sys/kernel/debug/dri/0/DP-x/link_settings
182 * check current and preferred settings.
185 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
186 size_t size, loff_t *pos)
188 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
189 struct dc_link *link = connector->dc_link;
191 char *rd_buf_ptr = NULL;
192 const uint32_t rd_buf_size = 100;
197 if (*pos & 3 || size & 3)
200 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
206 str_len = strlen("Current: %d 0x%x %d ");
207 snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
208 link->cur_link_settings.lane_count,
209 link->cur_link_settings.link_rate,
210 link->cur_link_settings.link_spread);
211 rd_buf_ptr += str_len;
213 str_len = strlen("Verified: %d 0x%x %d ");
214 snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
215 link->verified_link_cap.lane_count,
216 link->verified_link_cap.link_rate,
217 link->verified_link_cap.link_spread);
218 rd_buf_ptr += str_len;
220 str_len = strlen("Reported: %d 0x%x %d ");
221 snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
222 link->reported_link_cap.lane_count,
223 link->reported_link_cap.link_rate,
224 link->reported_link_cap.link_spread);
225 rd_buf_ptr += str_len;
227 str_len = strlen("Preferred: %d 0x%x %d ");
228 snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
229 link->preferred_link_setting.lane_count,
230 link->preferred_link_setting.link_rate,
231 link->preferred_link_setting.link_spread);
234 if (*pos >= rd_buf_size)
237 r = put_user(*(rd_buf + result), buf);
240 return r; /* r = -EFAULT */
253 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
254 size_t size, loff_t *pos)
256 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
257 struct dc_link *link = connector->dc_link;
258 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
259 struct dc *dc = (struct dc *)link->dc;
260 struct dc_link_settings prefer_link_settings;
262 const uint32_t wr_buf_size = 40;
263 /* 0: lane_count; 1: link_rate */
264 int max_param_num = 2;
265 uint8_t param_nums = 0;
267 bool valid_input = true;
272 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
276 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
284 if (param_nums <= 0) {
286 DRM_DEBUG_DRIVER("user data not be read\n");
293 case LANE_COUNT_FOUR:
304 case LINK_RATE_HIGH2:
305 case LINK_RATE_HIGH3:
306 case LINK_RATE_UHBR10:
307 case LINK_RATE_UHBR13_5:
308 case LINK_RATE_UHBR20:
317 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
318 mutex_lock(&adev->dm.dc_lock);
319 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
320 mutex_unlock(&adev->dm.dc_lock);
324 /* save user force lane_count, link_rate to preferred settings
325 * spread spectrum will not be changed
327 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
328 prefer_link_settings.use_link_rate_set = false;
329 prefer_link_settings.lane_count = param[0];
330 prefer_link_settings.link_rate = param[1];
332 mutex_lock(&adev->dm.dc_lock);
333 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, false);
334 mutex_unlock(&adev->dm.dc_lock);
340 static bool dp_mst_is_end_device(struct amdgpu_dm_connector *aconnector)
342 bool is_end_device = false;
343 struct drm_dp_mst_topology_mgr *mgr = NULL;
344 struct drm_dp_mst_port *port = NULL;
346 if (aconnector->mst_root && aconnector->mst_root->mst_mgr.mst_state) {
347 mgr = &aconnector->mst_root->mst_mgr;
348 port = aconnector->mst_output_port;
350 drm_modeset_lock(&mgr->base.lock, NULL);
351 if (port->pdt == DP_PEER_DEVICE_SST_SINK ||
352 port->pdt == DP_PEER_DEVICE_DP_LEGACY_CONV)
353 is_end_device = true;
354 drm_modeset_unlock(&mgr->base.lock);
357 return is_end_device;
360 /* Change MST link setting
362 * valid lane count value: 1, 2, 4
363 * valid link rate value:
364 * 06h = 1.62Gbps per lane
365 * 0Ah = 2.7Gbps per lane
366 * 0Ch = 3.24Gbps per lane
367 * 14h = 5.4Gbps per lane
368 * 1Eh = 8.1Gbps per lane
369 * 3E8h = 10.0Gbps per lane
370 * 546h = 13.5Gbps per lane
371 * 7D0h = 20.0Gbps per lane
373 * debugfs is located at /sys/kernel/debug/dri/0/DP-x/mst_link_settings
375 * for example, to force to 2 lane, 10.0GHz,
376 * echo 2 0x3e8 > /sys/kernel/debug/dri/0/DP-x/mst_link_settings
378 * Valid input will trigger hotplug event to get new link setting applied
379 * Invalid input will trigger training setting reset
381 * The usage can be referred to link_settings entry
384 static ssize_t dp_mst_link_setting(struct file *f, const char __user *buf,
385 size_t size, loff_t *pos)
387 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
388 struct dc_link *link = aconnector->dc_link;
389 struct amdgpu_device *adev = drm_to_adev(aconnector->base.dev);
390 struct dc *dc = (struct dc *)link->dc;
391 struct dc_link_settings prefer_link_settings;
393 const uint32_t wr_buf_size = 40;
394 /* 0: lane_count; 1: link_rate */
395 int max_param_num = 2;
396 uint8_t param_nums = 0;
398 bool valid_input = true;
400 if (!dp_mst_is_end_device(aconnector))
406 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
410 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
418 if (param_nums <= 0) {
420 DRM_DEBUG_DRIVER("user data not be read\n");
427 case LANE_COUNT_FOUR:
438 case LINK_RATE_HIGH2:
439 case LINK_RATE_HIGH3:
440 case LINK_RATE_UHBR10:
441 case LINK_RATE_UHBR13_5:
442 case LINK_RATE_UHBR20:
451 DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
452 mutex_lock(&adev->dm.dc_lock);
453 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
454 mutex_unlock(&adev->dm.dc_lock);
458 /* save user force lane_count, link_rate to preferred settings
459 * spread spectrum will not be changed
461 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
462 prefer_link_settings.use_link_rate_set = false;
463 prefer_link_settings.lane_count = param[0];
464 prefer_link_settings.link_rate = param[1];
466 /* skip immediate retrain, and train to new link setting after hotplug event triggered */
467 mutex_lock(&adev->dm.dc_lock);
468 dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, true);
469 mutex_unlock(&adev->dm.dc_lock);
471 mutex_lock(&aconnector->base.dev->mode_config.mutex);
472 aconnector->base.force = DRM_FORCE_OFF;
473 mutex_unlock(&aconnector->base.dev->mode_config.mutex);
474 drm_kms_helper_hotplug_event(aconnector->base.dev);
478 mutex_lock(&aconnector->base.dev->mode_config.mutex);
479 aconnector->base.force = DRM_FORCE_UNSPECIFIED;
480 mutex_unlock(&aconnector->base.dev->mode_config.mutex);
481 drm_kms_helper_hotplug_event(aconnector->base.dev);
487 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
488 * post-cursor2 (defined by VESA DP specification)
491 * voltage swing: 0,1,2,3
492 * pre-emphasis : 0,1,2,3
493 * post cursor2 : 0,1,2,3
496 * how to use this debugfs
498 * debugfs is located at /sys/kernel/debug/dri/0/DP-x
500 * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
502 * To figure out which DP-x is the display for DP to be check,
505 * There should be debugfs file, like link_settings, phy_settings.
507 * from lane_count, link_rate to figure which DP-x is for display to be worked
510 * To get current DP PHY settings,
513 * To change DP PHY settings,
514 * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
515 * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
517 * echo 2 3 0 > phy_settings
519 * To check if change be applied, get current phy settings by
522 * In case invalid values are set by user, like
523 * echo 1 4 0 > phy_settings
525 * HW will NOT be programmed by these settings.
526 * cat phy_settings will show the previous valid settings.
528 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
529 size_t size, loff_t *pos)
531 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
532 struct dc_link *link = connector->dc_link;
534 const uint32_t rd_buf_size = 20;
538 if (*pos & 3 || size & 3)
541 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
545 snprintf(rd_buf, rd_buf_size, " %d %d %d\n",
546 link->cur_lane_setting[0].VOLTAGE_SWING,
547 link->cur_lane_setting[0].PRE_EMPHASIS,
548 link->cur_lane_setting[0].POST_CURSOR2);
551 if (*pos >= rd_buf_size)
554 r = put_user((*(rd_buf + result)), buf);
557 return r; /* r = -EFAULT */
570 static int dp_lttpr_status_show(struct seq_file *m, void *unused)
572 struct drm_connector *connector = m->private;
573 struct amdgpu_dm_connector *aconnector =
574 to_amdgpu_dm_connector(connector);
575 struct dc_lttpr_caps caps = aconnector->dc_link->dpcd_caps.lttpr_caps;
577 if (connector->status != connector_status_connected)
580 seq_printf(m, "phy repeater count: %u (raw: 0x%x)\n",
581 dp_parse_lttpr_repeater_count(caps.phy_repeater_cnt),
582 caps.phy_repeater_cnt);
584 seq_puts(m, "phy repeater mode: ");
587 case DP_PHY_REPEATER_MODE_TRANSPARENT:
588 seq_puts(m, "transparent");
590 case DP_PHY_REPEATER_MODE_NON_TRANSPARENT:
591 seq_puts(m, "non-transparent");
594 seq_puts(m, "non lttpr");
597 seq_printf(m, "read error (raw: 0x%x)", caps.mode);
605 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
606 size_t size, loff_t *pos)
608 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
609 struct dc_link *link = connector->dc_link;
610 struct dc *dc = (struct dc *)link->dc;
612 uint32_t wr_buf_size = 40;
614 bool use_prefer_link_setting;
615 struct link_training_settings link_lane_settings;
616 int max_param_num = 3;
617 uint8_t param_nums = 0;
624 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
628 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
636 if (param_nums <= 0) {
638 DRM_DEBUG_DRIVER("user data not be read\n");
642 if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
643 (param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
644 (param[2] > POST_CURSOR2_MAX_LEVEL)) {
646 DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
650 /* get link settings: lane count, link rate */
651 use_prefer_link_setting =
652 ((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
653 (link->test_pattern_enabled));
655 memset(&link_lane_settings, 0, sizeof(link_lane_settings));
657 if (use_prefer_link_setting) {
658 link_lane_settings.link_settings.lane_count =
659 link->preferred_link_setting.lane_count;
660 link_lane_settings.link_settings.link_rate =
661 link->preferred_link_setting.link_rate;
662 link_lane_settings.link_settings.link_spread =
663 link->preferred_link_setting.link_spread;
665 link_lane_settings.link_settings.lane_count =
666 link->cur_link_settings.lane_count;
667 link_lane_settings.link_settings.link_rate =
668 link->cur_link_settings.link_rate;
669 link_lane_settings.link_settings.link_spread =
670 link->cur_link_settings.link_spread;
673 /* apply phy settings from user */
674 for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
675 link_lane_settings.hw_lane_settings[r].VOLTAGE_SWING =
676 (enum dc_voltage_swing) (param[0]);
677 link_lane_settings.hw_lane_settings[r].PRE_EMPHASIS =
678 (enum dc_pre_emphasis) (param[1]);
679 link_lane_settings.hw_lane_settings[r].POST_CURSOR2 =
680 (enum dc_post_cursor2) (param[2]);
683 /* program ASIC registers and DPCD registers */
684 dc_link_set_drive_settings(dc, &link_lane_settings, link);
690 /* function description
692 * set PHY layer or Link layer test pattern
693 * PHY test pattern is used for PHY SI check.
694 * Link layer test will not affect PHY SI.
696 * Reset Test Pattern:
697 * 0 = DP_TEST_PATTERN_VIDEO_MODE
699 * PHY test pattern supported:
700 * 1 = DP_TEST_PATTERN_D102
701 * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
702 * 3 = DP_TEST_PATTERN_PRBS7
703 * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
704 * 5 = DP_TEST_PATTERN_CP2520_1
705 * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
706 * 7 = DP_TEST_PATTERN_CP2520_3
708 * DP PHY Link Training Patterns
709 * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
710 * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
711 * a = DP_TEST_PATTERN_TRAINING_PATTERN3
712 * b = DP_TEST_PATTERN_TRAINING_PATTERN4
714 * DP Link Layer Test pattern
715 * c = DP_TEST_PATTERN_COLOR_SQUARES
716 * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
717 * e = DP_TEST_PATTERN_VERTICAL_BARS
718 * f = DP_TEST_PATTERN_HORIZONTAL_BARS
719 * 10= DP_TEST_PATTERN_COLOR_RAMP
721 * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
723 * --- set test pattern
724 * echo <test pattern #> > test_pattern
726 * If test pattern # is not supported, NO HW programming will be done.
727 * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
728 * for the user pattern. input 10 bytes data are separated by space
730 * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
732 * --- reset test pattern
733 * echo 0 > test_pattern
735 * --- HPD detection is disabled when set PHY test pattern
737 * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
738 * is disable. User could unplug DP display from DP connected and plug scope to
739 * check test pattern PHY SI.
740 * If there is need unplug scope and plug DP display back, do steps below:
741 * echo 0 > phy_test_pattern
745 * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
746 * driver could detect "unplug scope" and "plug DP display"
748 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
749 size_t size, loff_t *pos)
751 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
752 struct dc_link *link = connector->dc_link;
754 uint32_t wr_buf_size = 100;
755 long param[11] = {0x0};
756 int max_param_num = 11;
757 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
758 bool disable_hpd = false;
759 bool valid_test_pattern = false;
760 uint8_t param_nums = 0;
761 /* init with default 80bit custom pattern */
762 uint8_t custom_pattern[10] = {
763 0x1f, 0x7c, 0xf0, 0xc1, 0x07,
764 0x1f, 0x7c, 0xf0, 0xc1, 0x07
766 struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
767 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
768 struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
769 LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
770 struct link_training_settings link_training_settings;
776 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
780 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
788 if (param_nums <= 0) {
790 DRM_DEBUG_DRIVER("user data not be read\n");
795 test_pattern = param[0];
797 switch (test_pattern) {
798 case DP_TEST_PATTERN_VIDEO_MODE:
799 case DP_TEST_PATTERN_COLOR_SQUARES:
800 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
801 case DP_TEST_PATTERN_VERTICAL_BARS:
802 case DP_TEST_PATTERN_HORIZONTAL_BARS:
803 case DP_TEST_PATTERN_COLOR_RAMP:
804 valid_test_pattern = true;
807 case DP_TEST_PATTERN_D102:
808 case DP_TEST_PATTERN_SYMBOL_ERROR:
809 case DP_TEST_PATTERN_PRBS7:
810 case DP_TEST_PATTERN_80BIT_CUSTOM:
811 case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
812 case DP_TEST_PATTERN_TRAINING_PATTERN4:
814 valid_test_pattern = true;
818 valid_test_pattern = false;
819 test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
823 if (!valid_test_pattern) {
825 DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
829 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
830 for (i = 0; i < 10; i++) {
831 if ((uint8_t) param[i + 1] != 0x0)
836 /* not use default value */
837 for (i = 0; i < 10; i++)
838 custom_pattern[i] = (uint8_t) param[i + 1];
842 /* Usage: set DP physical test pattern using debugfs with normal DP
843 * panel. Then plug out DP panel and connect a scope to measure
844 * For normal video mode and test pattern generated from CRCT,
845 * they are visibile to user. So do not disable HPD.
846 * Video Mode is also set to clear the test pattern, so enable HPD
847 * because it might have been disabled after a test pattern was set.
848 * AUX depends on HPD * sequence dependent, do not move!
851 dc_link_enable_hpd(link);
853 prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
854 prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
855 prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
857 cur_link_settings.lane_count = link->cur_link_settings.lane_count;
858 cur_link_settings.link_rate = link->cur_link_settings.link_rate;
859 cur_link_settings.link_spread = link->cur_link_settings.link_spread;
861 link_training_settings.link_settings = cur_link_settings;
864 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
865 if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
866 prefer_link_settings.link_rate != LINK_RATE_UNKNOWN &&
867 (prefer_link_settings.lane_count != cur_link_settings.lane_count ||
868 prefer_link_settings.link_rate != cur_link_settings.link_rate))
869 link_training_settings.link_settings = prefer_link_settings;
872 for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
873 link_training_settings.hw_lane_settings[i] = link->cur_lane_setting[i];
875 dc_link_dp_set_test_pattern(
878 DP_TEST_PATTERN_COLOR_SPACE_RGB,
879 &link_training_settings,
883 /* Usage: Set DP physical test pattern using AMDDP with normal DP panel
884 * Then plug out DP panel and connect a scope to measure DP PHY signal.
885 * Need disable interrupt to avoid SW driver disable DP output. This is
886 * done after the test pattern is set.
888 if (valid_test_pattern && disable_hpd)
889 dc_link_disable_hpd(link);
897 * Returns the DMCUB tracebuffer contents.
898 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
900 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
902 struct amdgpu_device *adev = m->private;
903 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
904 struct dmub_debugfs_trace_entry *entries;
906 uint32_t tbuf_size, max_entries, num_entries, i;
911 tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
915 tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
916 max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
917 sizeof(struct dmub_debugfs_trace_entry);
920 ((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
922 num_entries = min(num_entries, max_entries);
924 entries = (struct dmub_debugfs_trace_entry
926 sizeof(struct dmub_debugfs_trace_header));
928 for (i = 0; i < num_entries; ++i) {
929 struct dmub_debugfs_trace_entry *entry = &entries[i];
932 "trace_code=%u tick_count=%u param0=%u param1=%u\n",
933 entry->trace_code, entry->tick_count, entry->param0,
941 * Returns the DMCUB firmware state contents.
942 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
944 static int dmub_fw_state_show(struct seq_file *m, void *data)
946 struct amdgpu_device *adev = m->private;
947 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
954 state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
958 state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
960 return seq_write(m, state_base, state_size);
963 /* psr_capability_show() - show eDP panel PSR capability
965 * The read function: sink_psr_capability_show
966 * Shows if sink has PSR capability or not.
967 * If yes - the PSR version is appended
969 * cat /sys/kernel/debug/dri/0/eDP-X/psr_capability
972 * "Sink support: no\n" - if panel doesn't support PSR
973 * "Sink support: yes [0x01]\n" - if panel supports PSR1
974 * "Driver support: no\n" - if driver doesn't support PSR
975 * "Driver support: yes [0x01]\n" - if driver supports PSR1
977 static int psr_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;
986 if (link->type == dc_connection_none)
989 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
992 seq_printf(m, "Sink support: %s", str_yes_no(link->dpcd_caps.psr_info.psr_version != 0));
993 if (link->dpcd_caps.psr_info.psr_version)
994 seq_printf(m, " [0x%02x]", link->dpcd_caps.psr_info.psr_version);
997 seq_printf(m, "Driver support: %s", str_yes_no(link->psr_settings.psr_feature_enabled));
998 if (link->psr_settings.psr_version)
999 seq_printf(m, " [0x%02x]", link->psr_settings.psr_version);
1006 * Returns the current bpc for the crtc.
1007 * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_bpc
1009 static int amdgpu_current_bpc_show(struct seq_file *m, void *data)
1011 struct drm_crtc *crtc = m->private;
1012 struct drm_device *dev = crtc->dev;
1013 struct dm_crtc_state *dm_crtc_state = NULL;
1017 mutex_lock(&dev->mode_config.mutex);
1018 drm_modeset_lock(&crtc->mutex, NULL);
1019 if (crtc->state == NULL)
1022 dm_crtc_state = to_dm_crtc_state(crtc->state);
1023 if (dm_crtc_state->stream == NULL)
1026 switch (dm_crtc_state->stream->timing.display_color_depth) {
1027 case COLOR_DEPTH_666:
1030 case COLOR_DEPTH_888:
1033 case COLOR_DEPTH_101010:
1036 case COLOR_DEPTH_121212:
1039 case COLOR_DEPTH_161616:
1046 seq_printf(m, "Current: %u\n", bpc);
1050 drm_modeset_unlock(&crtc->mutex);
1051 mutex_unlock(&dev->mode_config.mutex);
1055 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_bpc);
1058 * Returns the current colorspace for the crtc.
1059 * Example usage: cat /sys/kernel/debug/dri/0/crtc-0/amdgpu_current_colorspace
1061 static int amdgpu_current_colorspace_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;
1068 mutex_lock(&dev->mode_config.mutex);
1069 drm_modeset_lock(&crtc->mutex, NULL);
1070 if (crtc->state == NULL)
1073 dm_crtc_state = to_dm_crtc_state(crtc->state);
1074 if (dm_crtc_state->stream == NULL)
1077 switch (dm_crtc_state->stream->output_color_space) {
1078 case COLOR_SPACE_SRGB:
1079 seq_puts(m, "sRGB");
1081 case COLOR_SPACE_YCBCR601:
1082 case COLOR_SPACE_YCBCR601_LIMITED:
1083 seq_puts(m, "BT601_YCC");
1085 case COLOR_SPACE_YCBCR709:
1086 case COLOR_SPACE_YCBCR709_LIMITED:
1087 seq_puts(m, "BT709_YCC");
1089 case COLOR_SPACE_ADOBERGB:
1090 seq_puts(m, "opRGB");
1092 case COLOR_SPACE_2020_RGB_FULLRANGE:
1093 seq_puts(m, "BT2020_RGB");
1095 case COLOR_SPACE_2020_YCBCR:
1096 seq_puts(m, "BT2020_YCC");
1104 drm_modeset_unlock(&crtc->mutex);
1105 mutex_unlock(&dev->mode_config.mutex);
1109 DEFINE_SHOW_ATTRIBUTE(amdgpu_current_colorspace);
1114 * Disable dsc passthrough, i.e.,: have dsc decoding at converver, not external RX
1115 * echo 1 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
1116 * Enable dsc passthrough, i.e.,: have dsc passthrough to external RX
1117 * echo 0 /sys/kernel/debug/dri/0/DP-1/dsc_disable_passthrough
1119 static ssize_t dp_dsc_passthrough_set(struct file *f, const char __user *buf,
1120 size_t size, loff_t *pos)
1122 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1123 char *wr_buf = NULL;
1124 uint32_t wr_buf_size = 42;
1125 int max_param_num = 1;
1127 uint8_t param_nums = 0;
1132 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1135 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1139 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1147 aconnector->dsc_settings.dsc_force_disable_passthrough = param;
1154 * Returns the HDCP capability of the Display (1.4 for now).
1156 * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
1157 * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
1159 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
1160 * or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
1162 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
1164 struct drm_connector *connector = m->private;
1165 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1166 bool hdcp_cap, hdcp2_cap;
1168 if (connector->status != connector_status_connected)
1171 seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
1173 hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1174 hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
1178 seq_printf(m, "%s ", "HDCP1.4");
1180 seq_printf(m, "%s ", "HDCP2.2");
1182 if (!hdcp_cap && !hdcp2_cap)
1183 seq_printf(m, "%s ", "None");
1191 * Returns whether the connected display is internal and not hotpluggable.
1192 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/internal_display
1194 static int internal_display_show(struct seq_file *m, void *data)
1196 struct drm_connector *connector = m->private;
1197 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1198 struct dc_link *link = aconnector->dc_link;
1200 seq_printf(m, "Internal: %u\n", link->is_internal_display);
1206 * Returns the number of segments used if ODM Combine mode is enabled.
1207 * Example usage: cat /sys/kernel/debug/dri/0/DP-1/odm_combine_segments
1209 static int odm_combine_segments_show(struct seq_file *m, void *unused)
1211 struct drm_connector *connector = m->private;
1212 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1213 struct dc_link *link = aconnector->dc_link;
1214 struct pipe_ctx *pipe_ctx = NULL;
1215 int i, segments = -EOPNOTSUPP;
1217 for (i = 0; i < MAX_PIPES; i++) {
1218 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
1219 if (pipe_ctx->stream &&
1220 pipe_ctx->stream->link == link)
1224 if (connector->status != connector_status_connected)
1227 if (pipe_ctx != NULL && pipe_ctx->stream_res.tg->funcs->get_odm_combine_segments)
1228 pipe_ctx->stream_res.tg->funcs->get_odm_combine_segments(pipe_ctx->stream_res.tg, &segments);
1230 seq_printf(m, "%d\n", segments);
1234 /* function description
1236 * generic SDP message access for testing
1238 * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
1241 * Hb0 : Secondary-Data Packet ID
1242 * Hb1 : Secondary-Data Packet type
1243 * Hb2 : Secondary-Data-packet-specific header, Byte 0
1244 * Hb3 : Secondary-Data-packet-specific header, Byte 1
1246 * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
1248 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
1249 size_t size, loff_t *pos)
1253 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
1254 struct dm_crtc_state *acrtc_state;
1255 uint32_t write_size = 36;
1257 if (connector->base.status != connector_status_connected)
1263 acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
1265 r = copy_from_user(data, buf, write_size);
1269 dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
1274 /* function: Read link's DSC & FEC capabilities
1277 * Access it with the following command (you need to specify
1278 * connector like DP-1):
1280 * cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
1283 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
1285 struct drm_connector *connector = m->private;
1286 struct drm_modeset_acquire_ctx ctx;
1287 struct drm_device *dev = connector->dev;
1288 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1290 bool try_again = false;
1291 bool is_fec_supported = false;
1292 bool is_dsc_supported = false;
1293 struct dpcd_caps dpcd_caps;
1295 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1298 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1300 if (ret == -EDEADLK) {
1301 ret = drm_modeset_backoff(&ctx);
1309 if (connector->status != connector_status_connected) {
1313 dpcd_caps = aconnector->dc_link->dpcd_caps;
1314 if (aconnector->mst_output_port) {
1315 /* aconnector sets dsc_aux during get_modes call
1316 * if MST connector has it means it can either
1317 * enable DSC on the sink device or on MST branch
1320 if (aconnector->dsc_aux) {
1321 is_fec_supported = true;
1322 is_dsc_supported = true;
1325 is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1326 is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1328 } while (try_again);
1330 drm_modeset_drop_locks(&ctx);
1331 drm_modeset_acquire_fini(&ctx);
1333 seq_printf(m, "FEC_Sink_Support: %s\n", str_yes_no(is_fec_supported));
1334 seq_printf(m, "DSC_Sink_Support: %s\n", str_yes_no(is_dsc_supported));
1339 /* function: Trigger virtual HPD redetection on connector
1341 * This function will perform link rediscovery, link disable
1342 * and enable, and dm connector state update.
1344 * Retrigger HPD on an existing connector by echoing 1 into
1345 * its respectful "trigger_hotplug" debugfs entry:
1347 * echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1349 * This function can perform HPD unplug:
1351 * echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1354 static ssize_t trigger_hotplug(struct file *f, const char __user *buf,
1355 size_t size, loff_t *pos)
1357 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1358 struct drm_connector *connector = &aconnector->base;
1359 struct dc_link *link = NULL;
1360 struct drm_device *dev = connector->dev;
1361 struct amdgpu_device *adev = drm_to_adev(dev);
1362 enum dc_connection_type new_connection_type = dc_connection_none;
1363 char *wr_buf = NULL;
1364 uint32_t wr_buf_size = 42;
1365 int max_param_num = 1;
1366 long param[1] = {0};
1367 uint8_t param_nums = 0;
1370 if (!aconnector || !aconnector->dc_link)
1376 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1379 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1383 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1393 if (param_nums <= 0) {
1394 DRM_DEBUG_DRIVER("user data not be read\n");
1398 mutex_lock(&aconnector->hpd_lock);
1400 /* Don't support for mst end device*/
1401 if (aconnector->mst_root) {
1402 mutex_unlock(&aconnector->hpd_lock);
1406 if (param[0] == 1) {
1408 if (!dc_link_detect_connection_type(aconnector->dc_link, &new_connection_type) &&
1409 new_connection_type != dc_connection_none)
1412 mutex_lock(&adev->dm.dc_lock);
1413 ret = dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
1414 mutex_unlock(&adev->dm.dc_lock);
1419 amdgpu_dm_update_connector_after_detect(aconnector);
1421 drm_modeset_lock_all(dev);
1422 dm_restore_drm_connector_state(dev, connector);
1423 drm_modeset_unlock_all(dev);
1425 drm_kms_helper_connector_hotplug_event(connector);
1426 } else if (param[0] == 0) {
1427 if (!aconnector->dc_link)
1430 link = aconnector->dc_link;
1432 if (link->local_sink) {
1433 dc_sink_release(link->local_sink);
1434 link->local_sink = NULL;
1437 link->dpcd_sink_count = 0;
1438 link->type = dc_connection_none;
1439 link->dongle_max_pix_clk = 0;
1441 amdgpu_dm_update_connector_after_detect(aconnector);
1443 /* If the aconnector is the root node in mst topology */
1444 if (aconnector->mst_mgr.mst_state == true)
1445 dc_link_reset_cur_dp_mst_topology(link);
1447 drm_modeset_lock_all(dev);
1448 dm_restore_drm_connector_state(dev, connector);
1449 drm_modeset_unlock_all(dev);
1451 drm_kms_helper_connector_hotplug_event(connector);
1455 mutex_unlock(&aconnector->hpd_lock);
1460 /* function: read DSC status on the connector
1462 * The read function: dp_dsc_clock_en_read
1463 * returns current status of DSC clock on the connector.
1464 * The return is a boolean flag: 1 or 0.
1466 * Access it with the following command (you need to specify
1467 * connector like DP-1):
1469 * cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1472 * 1 - means that DSC is currently enabled
1473 * 0 - means that DSC is disabled
1475 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1476 size_t size, loff_t *pos)
1478 char *rd_buf = NULL;
1479 char *rd_buf_ptr = NULL;
1480 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1481 struct display_stream_compressor *dsc;
1482 struct dcn_dsc_state dsc_state = {0};
1483 const uint32_t rd_buf_size = 10;
1484 struct pipe_ctx *pipe_ctx;
1486 int i, r, str_len = 10;
1488 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1493 rd_buf_ptr = rd_buf;
1495 for (i = 0; i < MAX_PIPES; i++) {
1496 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1497 if (pipe_ctx->stream &&
1498 pipe_ctx->stream->link == aconnector->dc_link)
1502 dsc = pipe_ctx->stream_res.dsc;
1504 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1506 snprintf(rd_buf_ptr, str_len,
1508 dsc_state.dsc_clock_en);
1509 rd_buf_ptr += str_len;
1512 if (*pos >= rd_buf_size)
1515 r = put_user(*(rd_buf + result), buf);
1518 return r; /* r = -EFAULT */
1531 /* function: write force DSC on the connector
1533 * The write function: dp_dsc_clock_en_write
1534 * enables to force DSC on the connector.
1535 * User can write to either force enable or force disable DSC
1536 * on the next modeset or set it to driver default
1539 * 0 - default DSC enablement policy
1540 * 1 - force enable DSC on the connector
1541 * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1543 * Writing DSC settings is done with the following command:
1544 * - To force enable DSC (you need to specify
1545 * connector like DP-1):
1547 * echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1549 * - To return to default state set the flag to zero and
1550 * let driver deal with DSC automatically
1551 * (you need to specify connector like DP-1):
1553 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1556 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1557 size_t size, loff_t *pos)
1559 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1560 struct drm_connector *connector = &aconnector->base;
1561 struct drm_device *dev = connector->dev;
1562 struct drm_crtc *crtc = NULL;
1563 struct dm_crtc_state *dm_crtc_state = NULL;
1564 struct pipe_ctx *pipe_ctx;
1566 char *wr_buf = NULL;
1567 uint32_t wr_buf_size = 42;
1568 int max_param_num = 1;
1569 long param[1] = {0};
1570 uint8_t param_nums = 0;
1575 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1578 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1582 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1590 if (param_nums <= 0) {
1591 DRM_DEBUG_DRIVER("user data not be read\n");
1596 for (i = 0; i < MAX_PIPES; i++) {
1597 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1598 if (pipe_ctx->stream &&
1599 pipe_ctx->stream->link == aconnector->dc_link)
1603 if (!pipe_ctx->stream)
1607 mutex_lock(&dev->mode_config.mutex);
1608 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1610 if (connector->state == NULL)
1613 crtc = connector->state->crtc;
1617 drm_modeset_lock(&crtc->mutex, NULL);
1618 if (crtc->state == NULL)
1621 dm_crtc_state = to_dm_crtc_state(crtc->state);
1622 if (dm_crtc_state->stream == NULL)
1626 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1627 else if (param[0] == 2)
1628 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1630 aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1632 dm_crtc_state->dsc_force_changed = true;
1636 drm_modeset_unlock(&crtc->mutex);
1637 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1638 mutex_unlock(&dev->mode_config.mutex);
1645 /* function: read DSC slice width parameter on the connector
1647 * The read function: dp_dsc_slice_width_read
1648 * returns dsc slice width used in the current configuration
1649 * The return is an integer: 0 or other positive number
1651 * Access the status with the following command:
1653 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1655 * 0 - means that DSC is disabled
1657 * Any other number more than zero represents the
1658 * slice width currently used by DSC in pixels
1661 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1662 size_t size, loff_t *pos)
1664 char *rd_buf = NULL;
1665 char *rd_buf_ptr = NULL;
1666 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1667 struct display_stream_compressor *dsc;
1668 struct dcn_dsc_state dsc_state = {0};
1669 const uint32_t rd_buf_size = 100;
1670 struct pipe_ctx *pipe_ctx;
1672 int i, r, str_len = 30;
1674 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1679 rd_buf_ptr = rd_buf;
1681 for (i = 0; i < MAX_PIPES; i++) {
1682 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1683 if (pipe_ctx->stream &&
1684 pipe_ctx->stream->link == aconnector->dc_link)
1688 dsc = pipe_ctx->stream_res.dsc;
1690 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1692 snprintf(rd_buf_ptr, str_len,
1694 dsc_state.dsc_slice_width);
1695 rd_buf_ptr += str_len;
1698 if (*pos >= rd_buf_size)
1701 r = put_user(*(rd_buf + result), buf);
1704 return r; /* r = -EFAULT */
1717 /* function: write DSC slice width parameter
1719 * The write function: dp_dsc_slice_width_write
1720 * overwrites automatically generated DSC configuration
1723 * The user has to write the slice width divisible by the
1726 * Also the user has to write width in hexidecimal
1727 * rather than in decimal.
1729 * Writing DSC settings is done with the following command:
1730 * - To force overwrite slice width: (example sets to 1920 pixels)
1732 * echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1734 * - To stop overwriting and let driver find the optimal size,
1735 * set the width to zero:
1737 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1740 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1741 size_t size, loff_t *pos)
1743 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1744 struct pipe_ctx *pipe_ctx;
1745 struct drm_connector *connector = &aconnector->base;
1746 struct drm_device *dev = connector->dev;
1747 struct drm_crtc *crtc = NULL;
1748 struct dm_crtc_state *dm_crtc_state = NULL;
1750 char *wr_buf = NULL;
1751 uint32_t wr_buf_size = 42;
1752 int max_param_num = 1;
1753 long param[1] = {0};
1754 uint8_t param_nums = 0;
1759 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1762 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1766 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1774 if (param_nums <= 0) {
1775 DRM_DEBUG_DRIVER("user data not be read\n");
1780 for (i = 0; i < MAX_PIPES; i++) {
1781 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1782 if (pipe_ctx->stream &&
1783 pipe_ctx->stream->link == aconnector->dc_link)
1787 if (!pipe_ctx->stream)
1790 // Safely get CRTC state
1791 mutex_lock(&dev->mode_config.mutex);
1792 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1794 if (connector->state == NULL)
1797 crtc = connector->state->crtc;
1801 drm_modeset_lock(&crtc->mutex, NULL);
1802 if (crtc->state == NULL)
1805 dm_crtc_state = to_dm_crtc_state(crtc->state);
1806 if (dm_crtc_state->stream == NULL)
1810 aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1811 pipe_ctx->stream->timing.h_addressable,
1814 aconnector->dsc_settings.dsc_num_slices_h = 0;
1816 dm_crtc_state->dsc_force_changed = true;
1820 drm_modeset_unlock(&crtc->mutex);
1821 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1822 mutex_unlock(&dev->mode_config.mutex);
1829 /* function: read DSC slice height parameter on the connector
1831 * The read function: dp_dsc_slice_height_read
1832 * returns dsc slice height used in the current configuration
1833 * The return is an integer: 0 or other positive number
1835 * Access the status with the following command:
1837 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1839 * 0 - means that DSC is disabled
1841 * Any other number more than zero represents the
1842 * slice height currently used by DSC in pixels
1845 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1846 size_t size, loff_t *pos)
1848 char *rd_buf = NULL;
1849 char *rd_buf_ptr = NULL;
1850 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1851 struct display_stream_compressor *dsc;
1852 struct dcn_dsc_state dsc_state = {0};
1853 const uint32_t rd_buf_size = 100;
1854 struct pipe_ctx *pipe_ctx;
1856 int i, r, str_len = 30;
1858 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1863 rd_buf_ptr = rd_buf;
1865 for (i = 0; i < MAX_PIPES; i++) {
1866 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1867 if (pipe_ctx->stream &&
1868 pipe_ctx->stream->link == aconnector->dc_link)
1872 dsc = pipe_ctx->stream_res.dsc;
1874 dsc->funcs->dsc_read_state(dsc, &dsc_state);
1876 snprintf(rd_buf_ptr, str_len,
1878 dsc_state.dsc_slice_height);
1879 rd_buf_ptr += str_len;
1882 if (*pos >= rd_buf_size)
1885 r = put_user(*(rd_buf + result), buf);
1888 return r; /* r = -EFAULT */
1901 /* function: write DSC slice height parameter
1903 * The write function: dp_dsc_slice_height_write
1904 * overwrites automatically generated DSC configuration
1907 * The user has to write the slice height divisible by the
1910 * Also the user has to write height in hexidecimal
1911 * rather than in decimal.
1913 * Writing DSC settings is done with the following command:
1914 * - To force overwrite slice height (example sets to 128 pixels):
1916 * echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1918 * - To stop overwriting and let driver find the optimal size,
1919 * set the height to zero:
1921 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1924 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1925 size_t size, loff_t *pos)
1927 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1928 struct drm_connector *connector = &aconnector->base;
1929 struct drm_device *dev = connector->dev;
1930 struct drm_crtc *crtc = NULL;
1931 struct dm_crtc_state *dm_crtc_state = NULL;
1932 struct pipe_ctx *pipe_ctx;
1934 char *wr_buf = NULL;
1935 uint32_t wr_buf_size = 42;
1936 int max_param_num = 1;
1937 uint8_t param_nums = 0;
1938 long param[1] = {0};
1943 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1946 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1950 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
1958 if (param_nums <= 0) {
1959 DRM_DEBUG_DRIVER("user data not be read\n");
1964 for (i = 0; i < MAX_PIPES; i++) {
1965 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1966 if (pipe_ctx->stream &&
1967 pipe_ctx->stream->link == aconnector->dc_link)
1971 if (!pipe_ctx->stream)
1975 mutex_lock(&dev->mode_config.mutex);
1976 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1978 if (connector->state == NULL)
1981 crtc = connector->state->crtc;
1985 drm_modeset_lock(&crtc->mutex, NULL);
1986 if (crtc->state == NULL)
1989 dm_crtc_state = to_dm_crtc_state(crtc->state);
1990 if (dm_crtc_state->stream == NULL)
1994 aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1995 pipe_ctx->stream->timing.v_addressable,
1998 aconnector->dsc_settings.dsc_num_slices_v = 0;
2000 dm_crtc_state->dsc_force_changed = true;
2004 drm_modeset_unlock(&crtc->mutex);
2005 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2006 mutex_unlock(&dev->mode_config.mutex);
2013 /* function: read DSC target rate on the connector in bits per pixel
2015 * The read function: dp_dsc_bits_per_pixel_read
2016 * returns target rate of compression in bits per pixel
2017 * The return is an integer: 0 or other positive integer
2019 * Access it with the following command:
2021 * cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2023 * 0 - means that DSC is disabled
2025 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
2026 size_t size, loff_t *pos)
2028 char *rd_buf = NULL;
2029 char *rd_buf_ptr = NULL;
2030 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2031 struct display_stream_compressor *dsc;
2032 struct dcn_dsc_state dsc_state = {0};
2033 const uint32_t rd_buf_size = 100;
2034 struct pipe_ctx *pipe_ctx;
2036 int i, r, str_len = 30;
2038 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2043 rd_buf_ptr = rd_buf;
2045 for (i = 0; i < MAX_PIPES; i++) {
2046 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2047 if (pipe_ctx->stream &&
2048 pipe_ctx->stream->link == aconnector->dc_link)
2052 dsc = pipe_ctx->stream_res.dsc;
2054 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2056 snprintf(rd_buf_ptr, str_len,
2058 dsc_state.dsc_bits_per_pixel);
2059 rd_buf_ptr += str_len;
2062 if (*pos >= rd_buf_size)
2065 r = put_user(*(rd_buf + result), buf);
2068 return r; /* r = -EFAULT */
2081 /* function: write DSC target rate in bits per pixel
2083 * The write function: dp_dsc_bits_per_pixel_write
2084 * overwrites automatically generated DSC configuration
2085 * of DSC target bit rate.
2087 * Also the user has to write bpp in hexidecimal
2088 * rather than in decimal.
2090 * Writing DSC settings is done with the following command:
2091 * - To force overwrite rate (example sets to 256 bpp x 1/16):
2093 * echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2095 * - To stop overwriting and let driver find the optimal rate,
2096 * set the rate to zero:
2098 * echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
2101 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
2102 size_t size, loff_t *pos)
2104 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2105 struct drm_connector *connector = &aconnector->base;
2106 struct drm_device *dev = connector->dev;
2107 struct drm_crtc *crtc = NULL;
2108 struct dm_crtc_state *dm_crtc_state = NULL;
2109 struct pipe_ctx *pipe_ctx;
2111 char *wr_buf = NULL;
2112 uint32_t wr_buf_size = 42;
2113 int max_param_num = 1;
2114 uint8_t param_nums = 0;
2115 long param[1] = {0};
2120 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2123 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2127 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2135 if (param_nums <= 0) {
2136 DRM_DEBUG_DRIVER("user data not be read\n");
2141 for (i = 0; i < MAX_PIPES; i++) {
2142 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2143 if (pipe_ctx->stream &&
2144 pipe_ctx->stream->link == aconnector->dc_link)
2148 if (!pipe_ctx->stream)
2152 mutex_lock(&dev->mode_config.mutex);
2153 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2155 if (connector->state == NULL)
2158 crtc = connector->state->crtc;
2162 drm_modeset_lock(&crtc->mutex, NULL);
2163 if (crtc->state == NULL)
2166 dm_crtc_state = to_dm_crtc_state(crtc->state);
2167 if (dm_crtc_state->stream == NULL)
2170 aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
2172 dm_crtc_state->dsc_force_changed = true;
2176 drm_modeset_unlock(&crtc->mutex);
2177 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2178 mutex_unlock(&dev->mode_config.mutex);
2185 /* function: read DSC picture width parameter on the connector
2187 * The read function: dp_dsc_pic_width_read
2188 * returns dsc picture width used in the current configuration
2189 * It is the same as h_addressable of the current
2191 * The return is an integer: 0 or other positive integer
2192 * If 0 then DSC is disabled.
2194 * Access it with the following command:
2196 * cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
2198 * 0 - means that DSC is disabled
2200 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
2201 size_t size, loff_t *pos)
2203 char *rd_buf = NULL;
2204 char *rd_buf_ptr = NULL;
2205 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2206 struct display_stream_compressor *dsc;
2207 struct dcn_dsc_state dsc_state = {0};
2208 const uint32_t rd_buf_size = 100;
2209 struct pipe_ctx *pipe_ctx;
2211 int i, r, str_len = 30;
2213 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2218 rd_buf_ptr = rd_buf;
2220 for (i = 0; i < MAX_PIPES; i++) {
2221 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2222 if (pipe_ctx->stream &&
2223 pipe_ctx->stream->link == aconnector->dc_link)
2227 dsc = pipe_ctx->stream_res.dsc;
2229 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2231 snprintf(rd_buf_ptr, str_len,
2233 dsc_state.dsc_pic_width);
2234 rd_buf_ptr += str_len;
2237 if (*pos >= rd_buf_size)
2240 r = put_user(*(rd_buf + result), buf);
2243 return r; /* r = -EFAULT */
2256 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
2257 size_t size, loff_t *pos)
2259 char *rd_buf = NULL;
2260 char *rd_buf_ptr = NULL;
2261 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2262 struct display_stream_compressor *dsc;
2263 struct dcn_dsc_state dsc_state = {0};
2264 const uint32_t rd_buf_size = 100;
2265 struct pipe_ctx *pipe_ctx;
2267 int i, r, str_len = 30;
2269 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2274 rd_buf_ptr = rd_buf;
2276 for (i = 0; i < MAX_PIPES; i++) {
2277 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2278 if (pipe_ctx->stream &&
2279 pipe_ctx->stream->link == aconnector->dc_link)
2283 dsc = pipe_ctx->stream_res.dsc;
2285 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2287 snprintf(rd_buf_ptr, str_len,
2289 dsc_state.dsc_pic_height);
2290 rd_buf_ptr += str_len;
2293 if (*pos >= rd_buf_size)
2296 r = put_user(*(rd_buf + result), buf);
2299 return r; /* r = -EFAULT */
2312 /* function: read DSC chunk size parameter on the connector
2314 * The read function: dp_dsc_chunk_size_read
2315 * returns dsc chunk size set in the current configuration
2316 * The value is calculated automatically by DSC code
2317 * and depends on slice parameters and bpp target rate
2318 * The return is an integer: 0 or other positive integer
2319 * If 0 then DSC is disabled.
2321 * Access it with the following command:
2323 * cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
2325 * 0 - means that DSC is disabled
2327 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
2328 size_t size, loff_t *pos)
2330 char *rd_buf = NULL;
2331 char *rd_buf_ptr = NULL;
2332 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2333 struct display_stream_compressor *dsc;
2334 struct dcn_dsc_state dsc_state = {0};
2335 const uint32_t rd_buf_size = 100;
2336 struct pipe_ctx *pipe_ctx;
2338 int i, r, str_len = 30;
2340 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2345 rd_buf_ptr = rd_buf;
2347 for (i = 0; i < MAX_PIPES; i++) {
2348 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2349 if (pipe_ctx->stream &&
2350 pipe_ctx->stream->link == aconnector->dc_link)
2354 dsc = pipe_ctx->stream_res.dsc;
2356 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2358 snprintf(rd_buf_ptr, str_len,
2360 dsc_state.dsc_chunk_size);
2361 rd_buf_ptr += str_len;
2364 if (*pos >= rd_buf_size)
2367 r = put_user(*(rd_buf + result), buf);
2370 return r; /* r = -EFAULT */
2383 /* function: read DSC slice bpg offset on the connector
2385 * The read function: dp_dsc_slice_bpg_offset_read
2386 * returns dsc bpg slice offset set in the current configuration
2387 * The value is calculated automatically by DSC code
2388 * and depends on slice parameters and bpp target rate
2389 * The return is an integer: 0 or other positive integer
2390 * If 0 then DSC is disabled.
2392 * Access it with the following command:
2394 * cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
2396 * 0 - means that DSC is disabled
2398 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
2399 size_t size, loff_t *pos)
2401 char *rd_buf = NULL;
2402 char *rd_buf_ptr = NULL;
2403 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2404 struct display_stream_compressor *dsc;
2405 struct dcn_dsc_state dsc_state = {0};
2406 const uint32_t rd_buf_size = 100;
2407 struct pipe_ctx *pipe_ctx;
2409 int i, r, str_len = 30;
2411 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2416 rd_buf_ptr = rd_buf;
2418 for (i = 0; i < MAX_PIPES; i++) {
2419 pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
2420 if (pipe_ctx->stream &&
2421 pipe_ctx->stream->link == aconnector->dc_link)
2425 dsc = pipe_ctx->stream_res.dsc;
2427 dsc->funcs->dsc_read_state(dsc, &dsc_state);
2429 snprintf(rd_buf_ptr, str_len,
2431 dsc_state.dsc_slice_bpg_offset);
2432 rd_buf_ptr += str_len;
2435 if (*pos >= rd_buf_size)
2438 r = put_user(*(rd_buf + result), buf);
2441 return r; /* r = -EFAULT */
2456 * function description: Read max_requested_bpc property from the connector
2458 * Access it with the following command:
2460 * cat /sys/kernel/debug/dri/0/DP-X/max_bpc
2463 static ssize_t dp_max_bpc_read(struct file *f, char __user *buf,
2464 size_t size, loff_t *pos)
2466 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2467 struct drm_connector *connector = &aconnector->base;
2468 struct drm_device *dev = connector->dev;
2469 struct dm_connector_state *state;
2471 char *rd_buf = NULL;
2472 char *rd_buf_ptr = NULL;
2473 const uint32_t rd_buf_size = 10;
2476 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
2481 mutex_lock(&dev->mode_config.mutex);
2482 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2484 if (connector->state == NULL)
2487 state = to_dm_connector_state(connector->state);
2489 rd_buf_ptr = rd_buf;
2490 snprintf(rd_buf_ptr, rd_buf_size,
2492 state->base.max_requested_bpc);
2495 if (*pos >= rd_buf_size)
2498 r = put_user(*(rd_buf + result), buf);
2500 result = r; /* r = -EFAULT */
2509 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2510 mutex_unlock(&dev->mode_config.mutex);
2517 * function description: Set max_requested_bpc property on the connector
2519 * This function will not force the input BPC on connector, it will only
2520 * change the max value. This is equivalent to setting max_bpc through
2523 * The BPC value written must be >= 6 and <= 16. Values outside of this
2524 * range will result in errors.
2533 * Write the max_bpc in the following way:
2535 * echo 0x6 > /sys/kernel/debug/dri/0/DP-X/max_bpc
2538 static ssize_t dp_max_bpc_write(struct file *f, const char __user *buf,
2539 size_t size, loff_t *pos)
2541 struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
2542 struct drm_connector *connector = &aconnector->base;
2543 struct dm_connector_state *state;
2544 struct drm_device *dev = connector->dev;
2545 char *wr_buf = NULL;
2546 uint32_t wr_buf_size = 42;
2547 int max_param_num = 1;
2548 long param[1] = {0};
2549 uint8_t param_nums = 0;
2554 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
2557 DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
2561 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
2569 if (param_nums <= 0) {
2570 DRM_DEBUG_DRIVER("user data not be read\n");
2575 if (param[0] < 6 || param[0] > 16) {
2576 DRM_DEBUG_DRIVER("bad max_bpc value\n");
2581 mutex_lock(&dev->mode_config.mutex);
2582 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2584 if (connector->state == NULL)
2587 state = to_dm_connector_state(connector->state);
2588 state->base.max_requested_bpc = param[0];
2590 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2591 mutex_unlock(&dev->mode_config.mutex);
2598 * Backlight at this moment. Read only.
2599 * As written to display, taking ABM and backlight lut into account.
2600 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2602 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/current_backlight
2604 static int current_backlight_show(struct seq_file *m, void *unused)
2606 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2607 struct dc_link *link = aconnector->dc_link;
2608 unsigned int backlight;
2610 backlight = dc_link_get_backlight_level(link);
2611 seq_printf(m, "0x%x\n", backlight);
2617 * Backlight value that is being approached. Read only.
2618 * As written to display, taking ABM and backlight lut into account.
2619 * Ranges from 0x0 to 0x10000 (= 100% PWM)
2621 * Example usage: cat /sys/kernel/debug/dri/0/eDP-1/target_backlight
2623 static int target_backlight_show(struct seq_file *m, void *unused)
2625 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
2626 struct dc_link *link = aconnector->dc_link;
2627 unsigned int backlight;
2629 backlight = dc_link_get_target_backlight_pwm(link);
2630 seq_printf(m, "0x%x\n", backlight);
2636 * function description: Determine if the connector is mst connector
2638 * This function helps to determine whether a connector is a mst connector.
2639 * - "root" stands for the root connector of the topology
2640 * - "branch" stands for branch device of the topology
2641 * - "end" stands for leaf node connector of the topology
2642 * - "no" stands for the connector is not a device of a mst topology
2643 * Access it with the following command:
2645 * cat /sys/kernel/debug/dri/0/DP-X/is_mst_connector
2648 static int dp_is_mst_connector_show(struct seq_file *m, void *unused)
2650 struct drm_connector *connector = m->private;
2651 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2652 struct drm_dp_mst_topology_mgr *mgr = NULL;
2653 struct drm_dp_mst_port *port = NULL;
2656 mutex_lock(&aconnector->hpd_lock);
2658 if (aconnector->mst_mgr.mst_state) {
2660 } else if (aconnector->mst_root &&
2661 aconnector->mst_root->mst_mgr.mst_state) {
2665 mgr = &aconnector->mst_root->mst_mgr;
2666 port = aconnector->mst_output_port;
2668 drm_modeset_lock(&mgr->base.lock, NULL);
2669 if (port->pdt == DP_PEER_DEVICE_MST_BRANCHING &&
2672 drm_modeset_unlock(&mgr->base.lock);
2678 seq_printf(m, "%s\n", role);
2680 mutex_unlock(&aconnector->hpd_lock);
2686 * function description: Read out the mst progress status
2688 * This function helps to determine the mst progress status of
2691 * Access it with the following command:
2693 * cat /sys/kernel/debug/dri/0/DP-X/mst_progress_status
2696 static int dp_mst_progress_status_show(struct seq_file *m, void *unused)
2698 struct drm_connector *connector = m->private;
2699 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2700 struct amdgpu_device *adev = drm_to_adev(connector->dev);
2703 mutex_lock(&aconnector->hpd_lock);
2704 mutex_lock(&adev->dm.dc_lock);
2706 if (aconnector->mst_status == MST_STATUS_DEFAULT) {
2707 seq_puts(m, "disabled\n");
2709 for (i = 0; i < sizeof(mst_progress_status)/sizeof(char *); i++)
2710 seq_printf(m, "%s:%s\n",
2711 mst_progress_status[i],
2712 aconnector->mst_status & BIT(i) ? "done" : "not_done");
2715 mutex_unlock(&adev->dm.dc_lock);
2716 mutex_unlock(&aconnector->hpd_lock);
2722 * Reports whether the connected display is a USB4 DPIA tunneled display
2723 * Example usage: cat /sys/kernel/debug/dri/0/DP-8/is_dpia_link
2725 static int is_dpia_link_show(struct seq_file *m, void *data)
2727 struct drm_connector *connector = m->private;
2728 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
2729 struct dc_link *link = aconnector->dc_link;
2731 if (connector->status != connector_status_connected)
2734 seq_printf(m, "%s\n", (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) ? "yes" :
2735 (link->ep_type == DISPLAY_ENDPOINT_PHY) ? "no" : "unknown");
2740 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2741 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2742 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2743 DEFINE_SHOW_ATTRIBUTE(dp_lttpr_status);
2744 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2745 DEFINE_SHOW_ATTRIBUTE(internal_display);
2746 DEFINE_SHOW_ATTRIBUTE(odm_combine_segments);
2747 DEFINE_SHOW_ATTRIBUTE(psr_capability);
2748 DEFINE_SHOW_ATTRIBUTE(dp_is_mst_connector);
2749 DEFINE_SHOW_ATTRIBUTE(dp_mst_progress_status);
2750 DEFINE_SHOW_ATTRIBUTE(is_dpia_link);
2752 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2753 .owner = THIS_MODULE,
2754 .read = dp_dsc_clock_en_read,
2755 .write = dp_dsc_clock_en_write,
2756 .llseek = default_llseek
2759 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2760 .owner = THIS_MODULE,
2761 .read = dp_dsc_slice_width_read,
2762 .write = dp_dsc_slice_width_write,
2763 .llseek = default_llseek
2766 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2767 .owner = THIS_MODULE,
2768 .read = dp_dsc_slice_height_read,
2769 .write = dp_dsc_slice_height_write,
2770 .llseek = default_llseek
2773 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2774 .owner = THIS_MODULE,
2775 .read = dp_dsc_bits_per_pixel_read,
2776 .write = dp_dsc_bits_per_pixel_write,
2777 .llseek = default_llseek
2780 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2781 .owner = THIS_MODULE,
2782 .read = dp_dsc_pic_width_read,
2783 .llseek = default_llseek
2786 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2787 .owner = THIS_MODULE,
2788 .read = dp_dsc_pic_height_read,
2789 .llseek = default_llseek
2792 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2793 .owner = THIS_MODULE,
2794 .read = dp_dsc_chunk_size_read,
2795 .llseek = default_llseek
2798 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2799 .owner = THIS_MODULE,
2800 .read = dp_dsc_slice_bpg_offset_read,
2801 .llseek = default_llseek
2804 static const struct file_operations trigger_hotplug_debugfs_fops = {
2805 .owner = THIS_MODULE,
2806 .write = trigger_hotplug,
2807 .llseek = default_llseek
2810 static const struct file_operations dp_link_settings_debugfs_fops = {
2811 .owner = THIS_MODULE,
2812 .read = dp_link_settings_read,
2813 .write = dp_link_settings_write,
2814 .llseek = default_llseek
2817 static const struct file_operations dp_phy_settings_debugfs_fop = {
2818 .owner = THIS_MODULE,
2819 .read = dp_phy_settings_read,
2820 .write = dp_phy_settings_write,
2821 .llseek = default_llseek
2824 static const struct file_operations dp_phy_test_pattern_fops = {
2825 .owner = THIS_MODULE,
2826 .write = dp_phy_test_pattern_debugfs_write,
2827 .llseek = default_llseek
2830 static const struct file_operations sdp_message_fops = {
2831 .owner = THIS_MODULE,
2832 .write = dp_sdp_message_debugfs_write,
2833 .llseek = default_llseek
2836 static const struct file_operations dp_max_bpc_debugfs_fops = {
2837 .owner = THIS_MODULE,
2838 .read = dp_max_bpc_read,
2839 .write = dp_max_bpc_write,
2840 .llseek = default_llseek
2843 static const struct file_operations dp_dsc_disable_passthrough_debugfs_fops = {
2844 .owner = THIS_MODULE,
2845 .write = dp_dsc_passthrough_set,
2846 .llseek = default_llseek
2849 static const struct file_operations dp_mst_link_settings_debugfs_fops = {
2850 .owner = THIS_MODULE,
2851 .write = dp_mst_link_setting,
2852 .llseek = default_llseek
2855 static const struct {
2857 const struct file_operations *fops;
2858 } dp_debugfs_entries[] = {
2859 {"link_settings", &dp_link_settings_debugfs_fops},
2860 {"phy_settings", &dp_phy_settings_debugfs_fop},
2861 {"lttpr_status", &dp_lttpr_status_fops},
2862 {"test_pattern", &dp_phy_test_pattern_fops},
2863 {"hdcp_sink_capability", &hdcp_sink_capability_fops},
2864 {"sdp_message", &sdp_message_fops},
2865 {"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2866 {"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2867 {"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2868 {"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2869 {"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2870 {"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2871 {"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2872 {"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2873 {"dp_dsc_fec_support", &dp_dsc_fec_support_fops},
2874 {"max_bpc", &dp_max_bpc_debugfs_fops},
2875 {"dsc_disable_passthrough", &dp_dsc_disable_passthrough_debugfs_fops},
2876 {"is_mst_connector", &dp_is_mst_connector_fops},
2877 {"mst_progress_status", &dp_mst_progress_status_fops},
2878 {"is_dpia_link", &is_dpia_link_fops},
2879 {"mst_link_settings", &dp_mst_link_settings_debugfs_fops}
2882 static const struct {
2884 const struct file_operations *fops;
2885 } hdmi_debugfs_entries[] = {
2886 {"hdcp_sink_capability", &hdcp_sink_capability_fops}
2890 * Force YUV420 output if available from the given mode
2892 static int force_yuv420_output_set(void *data, u64 val)
2894 struct amdgpu_dm_connector *connector = data;
2896 connector->force_yuv420_output = (bool)val;
2902 * Check if YUV420 is forced when available from the given mode
2904 static int force_yuv420_output_get(void *data, u64 *val)
2906 struct amdgpu_dm_connector *connector = data;
2908 *val = connector->force_yuv420_output;
2913 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2914 force_yuv420_output_set, "%llu\n");
2919 static int psr_get(void *data, u64 *val)
2921 struct amdgpu_dm_connector *connector = data;
2922 struct dc_link *link = connector->dc_link;
2923 enum dc_psr_state state = PSR_STATE0;
2925 dc_link_get_psr_state(link, &state);
2933 * Read PSR state residency
2935 static int psr_read_residency(void *data, u64 *val)
2937 struct amdgpu_dm_connector *connector = data;
2938 struct dc_link *link = connector->dc_link;
2941 link->dc->link_srv->edp_get_psr_residency(link, &residency);
2943 *val = (u64)residency;
2948 /* read allow_edp_hotplug_detection */
2949 static int allow_edp_hotplug_detection_get(void *data, u64 *val)
2951 struct amdgpu_dm_connector *aconnector = data;
2952 struct drm_connector *connector = &aconnector->base;
2953 struct drm_device *dev = connector->dev;
2954 struct amdgpu_device *adev = drm_to_adev(dev);
2956 *val = adev->dm.dc->config.allow_edp_hotplug_detection;
2961 /* set allow_edp_hotplug_detection */
2962 static int allow_edp_hotplug_detection_set(void *data, u64 val)
2964 struct amdgpu_dm_connector *aconnector = data;
2965 struct drm_connector *connector = &aconnector->base;
2966 struct drm_device *dev = connector->dev;
2967 struct amdgpu_device *adev = drm_to_adev(dev);
2969 adev->dm.dc->config.allow_edp_hotplug_detection = (uint32_t) val;
2974 /* check if kernel disallow eDP enter psr state
2975 * cat /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
2976 * 0: allow edp enter psr; 1: disallow
2978 static int disallow_edp_enter_psr_get(void *data, u64 *val)
2980 struct amdgpu_dm_connector *aconnector = data;
2982 *val = (u64) aconnector->disallow_edp_enter_psr;
2986 /* set kernel disallow eDP enter psr state
2987 * echo 0x0 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
2988 * 0: allow edp enter psr; 1: disallow
2990 * usage: test app read crc from PSR eDP rx.
2992 * during kernel boot up, kernel write dpcd 0x170 = 5.
2993 * this notify eDP rx psr enable and let rx check crc.
2994 * rx fw will start checking crc for rx internal logic.
2995 * crc read count within dpcd 0x246 is not updated and
2996 * value is 0. when eDP tx driver wants to read rx crc
2997 * from dpcd 0x246, 0x270, read count 0 lead tx driver
3000 * to avoid this, we add this debugfs to let test app to disbable
3001 * rx crc checking for rx internal logic. then test app can read
3002 * non-zero crc read count.
3004 * expected app sequence is as below:
3005 * 1. disable eDP PHY and notify eDP rx with dpcd 0x600 = 2.
3006 * 2. echo 0x1 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr
3007 * 3. enable eDP PHY and notify eDP rx with dpcd 0x600 = 1 but
3008 * without dpcd 0x170 = 5.
3009 * 4. read crc from rx dpcd 0x270, 0x246, etc.
3010 * 5. echo 0x0 /sys/kernel/debug/dri/0/eDP-X/disallow_edp_enter_psr.
3011 * this will let eDP back to normal with psr setup dpcd 0x170 = 5.
3013 static int disallow_edp_enter_psr_set(void *data, u64 val)
3015 struct amdgpu_dm_connector *aconnector = data;
3017 aconnector->disallow_edp_enter_psr = val ? true : false;
3021 static int dmub_trace_mask_set(void *data, u64 val)
3023 struct amdgpu_device *adev = data;
3024 struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
3025 enum dmub_gpint_command cmd;
3031 if (!srv->fw_version)
3034 for (i = 0; i < 4; i++) {
3035 res = (val & mask) >> shift;
3039 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD0;
3042 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD1;
3045 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD2;
3048 cmd = DMUB_GPINT__SET_TRACE_BUFFER_MASK_WORD3;
3052 if (!dc_wake_and_execute_gpint(adev->dm.dc->ctx, cmd, res, NULL, DM_DMUB_WAIT_TYPE_WAIT))
3055 usleep_range(100, 1000);
3064 static int dmub_trace_mask_show(void *data, u64 *val)
3066 enum dmub_gpint_command cmd = DMUB_GPINT__GET_TRACE_BUFFER_MASK_WORD0;
3067 struct amdgpu_device *adev = data;
3068 struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
3074 if (!srv->fw_version)
3080 if (!dc_wake_and_execute_gpint(adev->dm.dc->ctx, cmd, 0, &response, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY))
3084 usleep_range(100, 1000);
3087 res |= (raw << shift);
3097 DEFINE_DEBUGFS_ATTRIBUTE(dmub_trace_mask_fops, dmub_trace_mask_show,
3098 dmub_trace_mask_set, "0x%llx\n");
3101 * Set dmcub trace event IRQ enable or disable.
3102 * Usage to enable dmcub trace event IRQ: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3103 * Usage to disable dmcub trace event IRQ: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3105 static int dmcub_trace_event_state_set(void *data, u64 val)
3107 struct amdgpu_device *adev = data;
3109 if (val == 1 || val == 0) {
3110 dc_dmub_trace_event_control(adev->dm.dc, val);
3111 adev->dm.dmcub_trace_event_en = (bool)val;
3119 * The interface doesn't need get function, so it will return the
3121 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmcub_trace_event_en
3123 static int dmcub_trace_event_state_get(void *data, u64 *val)
3125 struct amdgpu_device *adev = data;
3127 *val = adev->dm.dmcub_trace_event_en;
3131 DEFINE_DEBUGFS_ATTRIBUTE(dmcub_trace_event_state_fops, dmcub_trace_event_state_get,
3132 dmcub_trace_event_state_set, "%llu\n");
3134 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
3135 DEFINE_DEBUGFS_ATTRIBUTE(psr_residency_fops, psr_read_residency, NULL,
3138 DEFINE_DEBUGFS_ATTRIBUTE(allow_edp_hotplug_detection_fops,
3139 allow_edp_hotplug_detection_get,
3140 allow_edp_hotplug_detection_set, "%llu\n");
3142 DEFINE_DEBUGFS_ATTRIBUTE(disallow_edp_enter_psr_fops,
3143 disallow_edp_enter_psr_get,
3144 disallow_edp_enter_psr_set, "%llu\n");
3146 DEFINE_SHOW_ATTRIBUTE(current_backlight);
3147 DEFINE_SHOW_ATTRIBUTE(target_backlight);
3149 static const struct {
3151 const struct file_operations *fops;
3152 } connector_debugfs_entries[] = {
3153 {"force_yuv420_output", &force_yuv420_output_fops},
3154 {"trigger_hotplug", &trigger_hotplug_debugfs_fops},
3155 {"internal_display", &internal_display_fops},
3156 {"odm_combine_segments", &odm_combine_segments_fops}
3160 * Returns supported customized link rates by this eDP panel.
3161 * Example usage: cat /sys/kernel/debug/dri/0/eDP-x/ilr_setting
3163 static int edp_ilr_show(struct seq_file *m, void *unused)
3165 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(m->private);
3166 struct dc_link *link = aconnector->dc_link;
3167 uint8_t supported_link_rates[16];
3168 uint32_t link_rate_in_khz;
3172 memset(supported_link_rates, 0, sizeof(supported_link_rates));
3173 dm_helpers_dp_read_dpcd(link->ctx, link, DP_SUPPORTED_LINK_RATES,
3174 supported_link_rates, sizeof(supported_link_rates));
3176 dpcd_rev = link->dpcd_caps.dpcd_rev.raw;
3178 if (dpcd_rev >= DP_DPCD_REV_13 &&
3179 (supported_link_rates[entry+1] != 0 || supported_link_rates[entry] != 0)) {
3181 for (entry = 0; entry < 16; entry += 2) {
3182 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
3183 supported_link_rates[entry]) * 200;
3184 seq_printf(m, "[%d] %d kHz\n", entry/2, link_rate_in_khz);
3187 seq_puts(m, "ILR is not supported by this eDP panel.\n");
3194 * Set supported customized link rate to eDP panel.
3196 * echo <lane_count> <link_rate option> > ilr_setting
3198 * for example, supported ILR : [0] 1620000 kHz [1] 2160000 kHz [2] 2430000 kHz ...
3199 * echo 4 1 > /sys/kernel/debug/dri/0/eDP-x/ilr_setting
3200 * to set 4 lanes and 2.16 GHz
3202 static ssize_t edp_ilr_write(struct file *f, const char __user *buf,
3203 size_t size, loff_t *pos)
3205 struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
3206 struct dc_link *link = connector->dc_link;
3207 struct amdgpu_device *adev = drm_to_adev(connector->base.dev);
3208 struct dc *dc = (struct dc *)link->dc;
3209 struct dc_link_settings prefer_link_settings;
3210 char *wr_buf = NULL;
3211 const uint32_t wr_buf_size = 40;
3212 /* 0: lane_count; 1: link_rate */
3213 int max_param_num = 2;
3214 uint8_t param_nums = 0;
3216 bool valid_input = true;
3221 wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
3225 if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
3233 if (param_nums <= 0) {
3239 case LANE_COUNT_ONE:
3240 case LANE_COUNT_TWO:
3241 case LANE_COUNT_FOUR:
3244 valid_input = false;
3248 if (param[1] >= link->dpcd_caps.edp_supported_link_rates_count)
3249 valid_input = false;
3253 DRM_DEBUG_DRIVER("Invalid Input value. No HW will be programmed\n");
3254 prefer_link_settings.use_link_rate_set = false;
3255 mutex_lock(&adev->dm.dc_lock);
3256 dc_link_set_preferred_training_settings(dc, NULL, NULL, link, false);
3257 mutex_unlock(&adev->dm.dc_lock);
3261 /* save user force lane_count, link_rate to preferred settings
3262 * spread spectrum will not be changed
3264 prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
3265 prefer_link_settings.lane_count = param[0];
3266 prefer_link_settings.use_link_rate_set = true;
3267 prefer_link_settings.link_rate_set = param[1];
3268 prefer_link_settings.link_rate = link->dpcd_caps.edp_supported_link_rates[param[1]];
3270 mutex_lock(&adev->dm.dc_lock);
3271 dc_link_set_preferred_training_settings(dc, &prefer_link_settings,
3273 mutex_unlock(&adev->dm.dc_lock);
3279 static int edp_ilr_open(struct inode *inode, struct file *file)
3281 return single_open(file, edp_ilr_show, inode->i_private);
3284 static const struct file_operations edp_ilr_debugfs_fops = {
3285 .owner = THIS_MODULE,
3286 .open = edp_ilr_open,
3288 .llseek = seq_lseek,
3289 .release = single_release,
3290 .write = edp_ilr_write
3293 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
3296 struct dentry *dir = connector->base.debugfs_entry;
3298 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
3299 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3300 for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
3301 debugfs_create_file(dp_debugfs_entries[i].name,
3302 0644, dir, connector,
3303 dp_debugfs_entries[i].fops);
3306 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
3307 debugfs_create_file_unsafe("psr_capability", 0444, dir, connector, &psr_capability_fops);
3308 debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
3309 debugfs_create_file_unsafe("psr_residency", 0444, dir,
3310 connector, &psr_residency_fops);
3311 debugfs_create_file("amdgpu_current_backlight_pwm", 0444, dir, connector,
3312 ¤t_backlight_fops);
3313 debugfs_create_file("amdgpu_target_backlight_pwm", 0444, dir, connector,
3314 &target_backlight_fops);
3315 debugfs_create_file("ilr_setting", 0644, dir, connector,
3316 &edp_ilr_debugfs_fops);
3317 debugfs_create_file("allow_edp_hotplug_detection", 0644, dir, connector,
3318 &allow_edp_hotplug_detection_fops);
3319 debugfs_create_file("disallow_edp_enter_psr", 0644, dir, connector,
3320 &disallow_edp_enter_psr_fops);
3323 for (i = 0; i < ARRAY_SIZE(connector_debugfs_entries); i++) {
3324 debugfs_create_file(connector_debugfs_entries[i].name,
3325 0644, dir, connector,
3326 connector_debugfs_entries[i].fops);
3329 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
3330 for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
3331 debugfs_create_file(hdmi_debugfs_entries[i].name,
3332 0644, dir, connector,
3333 hdmi_debugfs_entries[i].fops);
3338 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3340 * Set crc window coordinate x start
3342 static int crc_win_x_start_set(void *data, u64 val)
3344 struct drm_crtc *crtc = data;
3345 struct drm_device *drm_dev = crtc->dev;
3346 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3348 spin_lock_irq(&drm_dev->event_lock);
3349 acrtc->dm_irq_params.window_param.x_start = (uint16_t) val;
3350 acrtc->dm_irq_params.window_param.update_win = false;
3351 spin_unlock_irq(&drm_dev->event_lock);
3357 * Get crc window coordinate x start
3359 static int crc_win_x_start_get(void *data, u64 *val)
3361 struct drm_crtc *crtc = data;
3362 struct drm_device *drm_dev = crtc->dev;
3363 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3365 spin_lock_irq(&drm_dev->event_lock);
3366 *val = acrtc->dm_irq_params.window_param.x_start;
3367 spin_unlock_irq(&drm_dev->event_lock);
3372 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_start_fops, crc_win_x_start_get,
3373 crc_win_x_start_set, "%llu\n");
3377 * Set crc window coordinate y start
3379 static int crc_win_y_start_set(void *data, u64 val)
3381 struct drm_crtc *crtc = data;
3382 struct drm_device *drm_dev = crtc->dev;
3383 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3385 spin_lock_irq(&drm_dev->event_lock);
3386 acrtc->dm_irq_params.window_param.y_start = (uint16_t) val;
3387 acrtc->dm_irq_params.window_param.update_win = false;
3388 spin_unlock_irq(&drm_dev->event_lock);
3394 * Get crc window coordinate y start
3396 static int crc_win_y_start_get(void *data, u64 *val)
3398 struct drm_crtc *crtc = data;
3399 struct drm_device *drm_dev = crtc->dev;
3400 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3402 spin_lock_irq(&drm_dev->event_lock);
3403 *val = acrtc->dm_irq_params.window_param.y_start;
3404 spin_unlock_irq(&drm_dev->event_lock);
3409 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_start_fops, crc_win_y_start_get,
3410 crc_win_y_start_set, "%llu\n");
3413 * Set crc window coordinate x end
3415 static int crc_win_x_end_set(void *data, u64 val)
3417 struct drm_crtc *crtc = data;
3418 struct drm_device *drm_dev = crtc->dev;
3419 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3421 spin_lock_irq(&drm_dev->event_lock);
3422 acrtc->dm_irq_params.window_param.x_end = (uint16_t) val;
3423 acrtc->dm_irq_params.window_param.update_win = false;
3424 spin_unlock_irq(&drm_dev->event_lock);
3430 * Get crc window coordinate x end
3432 static int crc_win_x_end_get(void *data, u64 *val)
3434 struct drm_crtc *crtc = data;
3435 struct drm_device *drm_dev = crtc->dev;
3436 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3438 spin_lock_irq(&drm_dev->event_lock);
3439 *val = acrtc->dm_irq_params.window_param.x_end;
3440 spin_unlock_irq(&drm_dev->event_lock);
3445 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_x_end_fops, crc_win_x_end_get,
3446 crc_win_x_end_set, "%llu\n");
3449 * Set crc window coordinate y end
3451 static int crc_win_y_end_set(void *data, u64 val)
3453 struct drm_crtc *crtc = data;
3454 struct drm_device *drm_dev = crtc->dev;
3455 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3457 spin_lock_irq(&drm_dev->event_lock);
3458 acrtc->dm_irq_params.window_param.y_end = (uint16_t) val;
3459 acrtc->dm_irq_params.window_param.update_win = false;
3460 spin_unlock_irq(&drm_dev->event_lock);
3466 * Get crc window coordinate y end
3468 static int crc_win_y_end_get(void *data, u64 *val)
3470 struct drm_crtc *crtc = data;
3471 struct drm_device *drm_dev = crtc->dev;
3472 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
3474 spin_lock_irq(&drm_dev->event_lock);
3475 *val = acrtc->dm_irq_params.window_param.y_end;
3476 spin_unlock_irq(&drm_dev->event_lock);
3481 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_y_end_fops, crc_win_y_end_get,
3482 crc_win_y_end_set, "%llu\n");
3484 * Trigger to commit crc window
3486 static int crc_win_update_set(void *data, u64 val)
3488 struct drm_crtc *crtc = data;
3489 struct amdgpu_crtc *acrtc;
3490 struct amdgpu_device *adev = drm_to_adev(crtc->dev);
3493 acrtc = to_amdgpu_crtc(crtc);
3494 mutex_lock(&adev->dm.dc_lock);
3495 /* PSR may write to OTG CRC window control register,
3496 * so close it before starting secure_display.
3498 amdgpu_dm_psr_disable(acrtc->dm_irq_params.stream);
3500 spin_lock_irq(&adev_to_drm(adev)->event_lock);
3502 acrtc->dm_irq_params.window_param.activated = true;
3503 acrtc->dm_irq_params.window_param.update_win = true;
3504 acrtc->dm_irq_params.window_param.skip_frame_cnt = 0;
3506 spin_unlock_irq(&adev_to_drm(adev)->event_lock);
3507 mutex_unlock(&adev->dm.dc_lock);
3514 * Get crc window update flag
3516 static int crc_win_update_get(void *data, u64 *val)
3522 DEFINE_DEBUGFS_ATTRIBUTE(crc_win_update_fops, crc_win_update_get,
3523 crc_win_update_set, "%llu\n");
3525 void crtc_debugfs_init(struct drm_crtc *crtc)
3527 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
3528 struct dentry *dir = debugfs_lookup("crc", crtc->debugfs_entry);
3533 debugfs_create_file_unsafe("crc_win_x_start", 0644, dir, crtc,
3534 &crc_win_x_start_fops);
3535 debugfs_create_file_unsafe("crc_win_y_start", 0644, dir, crtc,
3536 &crc_win_y_start_fops);
3537 debugfs_create_file_unsafe("crc_win_x_end", 0644, dir, crtc,
3538 &crc_win_x_end_fops);
3539 debugfs_create_file_unsafe("crc_win_y_end", 0644, dir, crtc,
3540 &crc_win_y_end_fops);
3541 debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc,
3542 &crc_win_update_fops);
3545 debugfs_create_file("amdgpu_current_bpc", 0644, crtc->debugfs_entry,
3546 crtc, &amdgpu_current_bpc_fops);
3547 debugfs_create_file("amdgpu_current_colorspace", 0644, crtc->debugfs_entry,
3548 crtc, &amdgpu_current_colorspace_fops);
3552 * Writes DTN log state to the user supplied buffer.
3553 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3555 static ssize_t dtn_log_read(
3561 struct amdgpu_device *adev = file_inode(f)->i_private;
3562 struct dc *dc = adev->dm.dc;
3563 struct dc_log_buffer_ctx log_ctx = { 0 };
3569 if (!dc->hwss.log_hw_state)
3572 dc->hwss.log_hw_state(dc, &log_ctx);
3574 if (*pos < log_ctx.pos) {
3575 size_t to_copy = log_ctx.pos - *pos;
3577 to_copy = min(to_copy, size);
3579 if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
3591 * Writes DTN log state to dmesg when triggered via a write.
3592 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
3594 static ssize_t dtn_log_write(
3596 const char __user *buf,
3600 struct amdgpu_device *adev = file_inode(f)->i_private;
3601 struct dc *dc = adev->dm.dc;
3603 /* Write triggers log output via dmesg. */
3607 if (dc->hwss.log_hw_state)
3608 dc->hwss.log_hw_state(dc, NULL);
3613 static int mst_topo_show(struct seq_file *m, void *unused)
3615 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3616 struct drm_device *dev = adev_to_drm(adev);
3617 struct drm_connector *connector;
3618 struct drm_connector_list_iter conn_iter;
3619 struct amdgpu_dm_connector *aconnector;
3621 drm_connector_list_iter_begin(dev, &conn_iter);
3622 drm_for_each_connector_iter(connector, &conn_iter) {
3623 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3626 aconnector = to_amdgpu_dm_connector(connector);
3628 /* Ensure we're only dumping the topology of a root mst node */
3629 if (!aconnector->mst_mgr.mst_state)
3632 seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
3633 drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
3635 drm_connector_list_iter_end(&conn_iter);
3641 * Sets trigger hpd for MST topologies.
3642 * All connected connectors will be rediscovered and re started as needed if val of 1 is sent.
3643 * All topologies will be disconnected if val of 0 is set .
3644 * Usage to enable topologies: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3645 * Usage to disable topologies: echo 0 > /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3647 static int trigger_hpd_mst_set(void *data, u64 val)
3649 struct amdgpu_device *adev = data;
3650 struct drm_device *dev = adev_to_drm(adev);
3651 struct drm_connector_list_iter iter;
3652 struct amdgpu_dm_connector *aconnector;
3653 struct drm_connector *connector;
3654 struct dc_link *link = NULL;
3657 drm_connector_list_iter_begin(dev, &iter);
3658 drm_for_each_connector_iter(connector, &iter) {
3659 aconnector = to_amdgpu_dm_connector(connector);
3660 if (aconnector->dc_link->type == dc_connection_mst_branch &&
3661 aconnector->mst_mgr.aux) {
3662 mutex_lock(&adev->dm.dc_lock);
3663 dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3664 mutex_unlock(&adev->dm.dc_lock);
3666 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
3669 } else if (val == 0) {
3670 drm_connector_list_iter_begin(dev, &iter);
3671 drm_for_each_connector_iter(connector, &iter) {
3672 aconnector = to_amdgpu_dm_connector(connector);
3673 if (!aconnector->dc_link)
3676 if (!aconnector->mst_root)
3679 link = aconnector->dc_link;
3680 dc_link_dp_receiver_power_ctrl(link, false);
3681 drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_root->mst_mgr, false);
3682 link->mst_stream_alloc_table.stream_count = 0;
3683 memset(link->mst_stream_alloc_table.stream_allocations, 0,
3684 sizeof(link->mst_stream_alloc_table.stream_allocations));
3689 drm_kms_helper_hotplug_event(dev);
3695 * The interface doesn't need get function, so it will return the
3697 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_trigger_hpd_mst
3699 static int trigger_hpd_mst_get(void *data, u64 *val)
3705 DEFINE_DEBUGFS_ATTRIBUTE(trigger_hpd_mst_ops, trigger_hpd_mst_get,
3706 trigger_hpd_mst_set, "%llu\n");
3710 * Sets the force_timing_sync debug option from the given string.
3711 * All connected displays will be force synchronized immediately.
3712 * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3714 static int force_timing_sync_set(void *data, u64 val)
3716 struct amdgpu_device *adev = data;
3718 adev->dm.force_timing_sync = (bool)val;
3720 amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
3726 * Gets the force_timing_sync debug option value into the given buffer.
3727 * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
3729 static int force_timing_sync_get(void *data, u64 *val)
3731 struct amdgpu_device *adev = data;
3733 *val = adev->dm.force_timing_sync;
3738 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
3739 force_timing_sync_set, "%llu\n");
3743 * Disables all HPD and HPD RX interrupt handling in the
3744 * driver when set to 1. Default is 0.
3746 static int disable_hpd_set(void *data, u64 val)
3748 struct amdgpu_device *adev = data;
3750 adev->dm.disable_hpd_irq = (bool)val;
3757 * Returns 1 if HPD and HPRX interrupt handling is disabled,
3760 static int disable_hpd_get(void *data, u64 *val)
3762 struct amdgpu_device *adev = data;
3764 *val = adev->dm.disable_hpd_irq;
3769 DEFINE_DEBUGFS_ATTRIBUTE(disable_hpd_ops, disable_hpd_get,
3770 disable_hpd_set, "%llu\n");
3773 * Prints hardware capabilities. These are used for IGT testing.
3775 static int capabilities_show(struct seq_file *m, void *unused)
3777 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3778 struct dc *dc = adev->dm.dc;
3779 bool mall_supported = dc->caps.mall_size_total;
3780 bool subvp_supported = dc->caps.subvp_fw_processing_delay_us;
3781 unsigned int mall_in_use = false;
3782 unsigned int subvp_in_use = false;
3784 struct hubbub *hubbub = dc->res_pool->hubbub;
3786 if (hubbub->funcs->get_mall_en)
3787 hubbub->funcs->get_mall_en(hubbub, &mall_in_use);
3789 if (dc->cap_funcs.get_subvp_en)
3790 subvp_in_use = dc->cap_funcs.get_subvp_en(dc, dc->current_state);
3792 seq_printf(m, "mall supported: %s, enabled: %s\n",
3793 mall_supported ? "yes" : "no", mall_in_use ? "yes" : "no");
3794 seq_printf(m, "sub-viewport supported: %s, enabled: %s\n",
3795 subvp_supported ? "yes" : "no", subvp_in_use ? "yes" : "no");
3800 DEFINE_SHOW_ATTRIBUTE(capabilities);
3803 * Temporary w/a to force sst sequence in M42D DP2 mst receiver
3804 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_set_mst_en_for_sst
3806 static int dp_force_sst_set(void *data, u64 val)
3808 struct amdgpu_device *adev = data;
3810 adev->dm.dc->debug.set_mst_en_for_sst = val;
3815 static int dp_force_sst_get(void *data, u64 *val)
3817 struct amdgpu_device *adev = data;
3819 *val = adev->dm.dc->debug.set_mst_en_for_sst;
3823 DEFINE_DEBUGFS_ATTRIBUTE(dp_set_mst_en_for_sst_ops, dp_force_sst_get,
3824 dp_force_sst_set, "%llu\n");
3827 * Force DP2 sequence without VESA certified cable.
3828 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dp_ignore_cable_id
3830 static int dp_ignore_cable_id_set(void *data, u64 val)
3832 struct amdgpu_device *adev = data;
3834 adev->dm.dc->debug.ignore_cable_id = val;
3839 static int dp_ignore_cable_id_get(void *data, u64 *val)
3841 struct amdgpu_device *adev = data;
3843 *val = adev->dm.dc->debug.ignore_cable_id;
3847 DEFINE_DEBUGFS_ATTRIBUTE(dp_ignore_cable_id_ops, dp_ignore_cable_id_get,
3848 dp_ignore_cable_id_set, "%llu\n");
3851 * Sets the DC visual confirm debug option from the given string.
3852 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
3854 static int visual_confirm_set(void *data, u64 val)
3856 struct amdgpu_device *adev = data;
3858 adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
3864 * Reads the DC visual confirm debug option value into the given buffer.
3865 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
3867 static int visual_confirm_get(void *data, u64 *val)
3869 struct amdgpu_device *adev = data;
3871 *val = adev->dm.dc->debug.visual_confirm;
3876 DEFINE_SHOW_ATTRIBUTE(mst_topo);
3877 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
3878 visual_confirm_set, "%llu\n");
3882 * Sets the DC skip_detection_link_training debug option from the given string.
3883 * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_skip_detection_link_training
3885 static int skip_detection_link_training_set(void *data, u64 val)
3887 struct amdgpu_device *adev = data;
3890 adev->dm.dc->debug.skip_detection_link_training = false;
3892 adev->dm.dc->debug.skip_detection_link_training = true;
3898 * Reads the DC skip_detection_link_training debug option value into the given buffer.
3899 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_skip_detection_link_training
3901 static int skip_detection_link_training_get(void *data, u64 *val)
3903 struct amdgpu_device *adev = data;
3905 *val = adev->dm.dc->debug.skip_detection_link_training;
3910 DEFINE_DEBUGFS_ATTRIBUTE(skip_detection_link_training_fops,
3911 skip_detection_link_training_get,
3912 skip_detection_link_training_set, "%llu\n");
3915 * Dumps the DCC_EN bit for each pipe.
3916 * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dcc_en
3918 static ssize_t dcc_en_bits_read(
3924 struct amdgpu_device *adev = file_inode(f)->i_private;
3925 struct dc *dc = adev->dm.dc;
3926 char *rd_buf = NULL;
3927 const uint32_t rd_buf_size = 32;
3928 uint32_t result = 0;
3930 int num_pipes = dc->res_pool->pipe_count;
3934 dcc_en_bits = kcalloc(num_pipes, sizeof(int), GFP_KERNEL);
3938 if (!dc->hwss.get_dcc_en_bits) {
3943 dc->hwss.get_dcc_en_bits(dc, dcc_en_bits);
3945 rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
3951 for (i = 0; i < num_pipes; i++)
3952 offset += snprintf(rd_buf + offset, rd_buf_size - offset,
3953 "%d ", dcc_en_bits[i]);
3954 rd_buf[strlen(rd_buf)] = '\n';
3959 if (*pos >= rd_buf_size)
3961 r = put_user(*(rd_buf + result), buf);
3964 return r; /* r = -EFAULT */
3976 void dtn_debugfs_init(struct amdgpu_device *adev)
3978 static const struct file_operations dtn_log_fops = {
3979 .owner = THIS_MODULE,
3980 .read = dtn_log_read,
3981 .write = dtn_log_write,
3982 .llseek = default_llseek
3984 static const struct file_operations dcc_en_bits_fops = {
3985 .owner = THIS_MODULE,
3986 .read = dcc_en_bits_read,
3987 .llseek = default_llseek
3990 struct drm_minor *minor = adev_to_drm(adev)->primary;
3991 struct dentry *root = minor->debugfs_root;
3993 debugfs_create_file("amdgpu_mst_topology", 0444, root,
3994 adev, &mst_topo_fops);
3995 debugfs_create_file("amdgpu_dm_capabilities", 0444, root,
3996 adev, &capabilities_fops);
3997 debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
3999 debugfs_create_file("amdgpu_dm_dp_set_mst_en_for_sst", 0644, root, adev,
4000 &dp_set_mst_en_for_sst_ops);
4001 debugfs_create_file("amdgpu_dm_dp_ignore_cable_id", 0644, root, adev,
4002 &dp_ignore_cable_id_ops);
4004 debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
4005 &visual_confirm_fops);
4007 debugfs_create_file_unsafe("amdgpu_dm_skip_detection_link_training", 0644, root, adev,
4008 &skip_detection_link_training_fops);
4010 debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
4011 adev, &dmub_tracebuffer_fops);
4013 debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
4014 adev, &dmub_fw_state_fops);
4016 debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
4017 adev, &force_timing_sync_ops);
4019 debugfs_create_file_unsafe("amdgpu_dm_dmub_trace_mask", 0644, root,
4020 adev, &dmub_trace_mask_fops);
4022 debugfs_create_file_unsafe("amdgpu_dm_dmcub_trace_event_en", 0644, root,
4023 adev, &dmcub_trace_event_state_fops);
4025 debugfs_create_file_unsafe("amdgpu_dm_trigger_hpd_mst", 0644, root,
4026 adev, &trigger_hpd_mst_ops);
4028 debugfs_create_file_unsafe("amdgpu_dm_dcc_en", 0644, root, adev,
4031 debugfs_create_file_unsafe("amdgpu_dm_disable_hpd", 0644, root, adev,