• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Advanced Micro Devices, Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #include <linux/uaccess.h>
27 
28 #include <drm/drm_debugfs.h>
29 
30 #include "dc.h"
31 #include "amdgpu.h"
32 #include "amdgpu_dm.h"
33 #include "amdgpu_dm_debugfs.h"
34 #include "dm_helpers.h"
35 #include "dmub/dmub_srv.h"
36 #include "resource.h"
37 #include "dsc.h"
38 #include "dc_link_dp.h"
39 
40 struct dmub_debugfs_trace_header {
41 	uint32_t entry_count;
42 	uint32_t reserved[3];
43 };
44 
45 struct dmub_debugfs_trace_entry {
46 	uint32_t trace_code;
47 	uint32_t tick_count;
48 	uint32_t param0;
49 	uint32_t param1;
50 };
51 
yesno(bool v)52 static inline const char *yesno(bool v)
53 {
54 	return v ? "yes" : "no";
55 }
56 
57 /* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array
58  *
59  * Function takes in attributes passed to debugfs write entry
60  * and writes into param array.
61  * The user passes max_param_num to identify maximum number of
62  * parameters that could be parsed.
63  *
64  */
parse_write_buffer_into_params(char * wr_buf,uint32_t wr_buf_size,long * param,const char __user * buf,int max_param_num,uint8_t * param_nums)65 static int parse_write_buffer_into_params(char *wr_buf, uint32_t wr_buf_size,
66 					  long *param, const char __user *buf,
67 					  int max_param_num,
68 					  uint8_t *param_nums)
69 {
70 	char *wr_buf_ptr = NULL;
71 	uint32_t wr_buf_count = 0;
72 	int r;
73 	char *sub_str = NULL;
74 	const char delimiter[3] = {' ', '\n', '\0'};
75 	uint8_t param_index = 0;
76 
77 	*param_nums = 0;
78 
79 	wr_buf_ptr = wr_buf;
80 
81 	r = copy_from_user(wr_buf_ptr, buf, wr_buf_size);
82 
83 		/* r is bytes not be copied */
84 	if (r >= wr_buf_size) {
85 		DRM_DEBUG_DRIVER("user data not be read\n");
86 		return -EINVAL;
87 	}
88 
89 	/* check number of parameters. isspace could not differ space and \n */
90 	while ((*wr_buf_ptr != 0xa) && (wr_buf_count < wr_buf_size)) {
91 		/* skip space*/
92 		while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
93 			wr_buf_ptr++;
94 			wr_buf_count++;
95 			}
96 
97 		if (wr_buf_count == wr_buf_size)
98 			break;
99 
100 		/* skip non-space*/
101 		while ((!isspace(*wr_buf_ptr)) && (wr_buf_count < wr_buf_size)) {
102 			wr_buf_ptr++;
103 			wr_buf_count++;
104 		}
105 
106 		(*param_nums)++;
107 
108 		if (wr_buf_count == wr_buf_size)
109 			break;
110 	}
111 
112 	if (*param_nums > max_param_num)
113 		*param_nums = max_param_num;
114 
115 	wr_buf_ptr = wr_buf; /* reset buf pointer */
116 	wr_buf_count = 0; /* number of char already checked */
117 
118 	while (isspace(*wr_buf_ptr) && (wr_buf_count < wr_buf_size)) {
119 		wr_buf_ptr++;
120 		wr_buf_count++;
121 	}
122 
123 	while (param_index < *param_nums) {
124 		/* after strsep, wr_buf_ptr will be moved to after space */
125 		sub_str = strsep(&wr_buf_ptr, delimiter);
126 
127 		r = kstrtol(sub_str, 16, &(param[param_index]));
128 
129 		if (r)
130 			DRM_DEBUG_DRIVER("string to int convert error code: %d\n", r);
131 
132 		param_index++;
133 	}
134 
135 	return 0;
136 }
137 
138 /* function description
139  * get/ set DP configuration: lane_count, link_rate, spread_spectrum
140  *
141  * valid lane count value: 1, 2, 4
142  * valid link rate value:
143  * 06h = 1.62Gbps per lane
144  * 0Ah = 2.7Gbps per lane
145  * 0Ch = 3.24Gbps per lane
146  * 14h = 5.4Gbps per lane
147  * 1Eh = 8.1Gbps per lane
148  *
149  * debugfs is located at /sys/kernel/debug/dri/0/DP-x/link_settings
150  *
151  * --- to get dp configuration
152  *
153  * cat /sys/kernel/debug/dri/0/DP-x/link_settings
154  *
155  * It will list current, verified, reported, preferred dp configuration.
156  * current -- for current video mode
157  * verified --- maximum configuration which pass link training
158  * reported --- DP rx report caps (DPCD register offset 0, 1 2)
159  * preferred --- user force settings
160  *
161  * --- set (or force) dp configuration
162  *
163  * echo <lane_count>  <link_rate> > link_settings
164  *
165  * for example, to force to  2 lane, 2.7GHz,
166  * echo 4 0xa > /sys/kernel/debug/dri/0/DP-x/link_settings
167  *
168  * spread_spectrum could not be changed dynamically.
169  *
170  * in case invalid lane count, link rate are force, no hw programming will be
171  * done. please check link settings after force operation to see if HW get
172  * programming.
173  *
174  * cat /sys/kernel/debug/dri/0/DP-x/link_settings
175  *
176  * check current and preferred settings.
177  *
178  */
dp_link_settings_read(struct file * f,char __user * buf,size_t size,loff_t * pos)179 static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
180 				 size_t size, loff_t *pos)
181 {
182 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
183 	struct dc_link *link = connector->dc_link;
184 	char *rd_buf = NULL;
185 	char *rd_buf_ptr = NULL;
186 	const uint32_t rd_buf_size = 100;
187 	uint32_t result = 0;
188 	uint8_t str_len = 0;
189 	int r;
190 
191 	if (*pos & 3 || size & 3)
192 		return -EINVAL;
193 
194 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
195 	if (!rd_buf)
196 		return 0;
197 
198 	rd_buf_ptr = rd_buf;
199 
200 	str_len = strlen("Current:  %d  0x%x  %d  ");
201 	snprintf(rd_buf_ptr, str_len, "Current:  %d  0x%x  %d  ",
202 			link->cur_link_settings.lane_count,
203 			link->cur_link_settings.link_rate,
204 			link->cur_link_settings.link_spread);
205 	rd_buf_ptr += str_len;
206 
207 	str_len = strlen("Verified:  %d  0x%x  %d  ");
208 	snprintf(rd_buf_ptr, str_len, "Verified:  %d  0x%x  %d  ",
209 			link->verified_link_cap.lane_count,
210 			link->verified_link_cap.link_rate,
211 			link->verified_link_cap.link_spread);
212 	rd_buf_ptr += str_len;
213 
214 	str_len = strlen("Reported:  %d  0x%x  %d  ");
215 	snprintf(rd_buf_ptr, str_len, "Reported:  %d  0x%x  %d  ",
216 			link->reported_link_cap.lane_count,
217 			link->reported_link_cap.link_rate,
218 			link->reported_link_cap.link_spread);
219 	rd_buf_ptr += str_len;
220 
221 	str_len = strlen("Preferred:  %d  0x%x  %d  ");
222 	snprintf(rd_buf_ptr, str_len, "Preferred:  %d  0x%x  %d\n",
223 			link->preferred_link_setting.lane_count,
224 			link->preferred_link_setting.link_rate,
225 			link->preferred_link_setting.link_spread);
226 
227 	while (size) {
228 		if (*pos >= rd_buf_size)
229 			break;
230 
231 		r = put_user(*(rd_buf + result), buf);
232 		if (r)
233 			return r; /* r = -EFAULT */
234 
235 		buf += 1;
236 		size -= 1;
237 		*pos += 1;
238 		result += 1;
239 	}
240 
241 	kfree(rd_buf);
242 	return result;
243 }
244 
dp_link_settings_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)245 static ssize_t dp_link_settings_write(struct file *f, const char __user *buf,
246 				 size_t size, loff_t *pos)
247 {
248 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
249 	struct dc_link *link = connector->dc_link;
250 	struct dc *dc = (struct dc *)link->dc;
251 	struct dc_link_settings prefer_link_settings;
252 	char *wr_buf = NULL;
253 	const uint32_t wr_buf_size = 40;
254 	/* 0: lane_count; 1: link_rate */
255 	int max_param_num = 2;
256 	uint8_t param_nums = 0;
257 	long param[2];
258 	bool valid_input = true;
259 
260 	if (size == 0)
261 		return -EINVAL;
262 
263 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
264 	if (!wr_buf)
265 		return -ENOSPC;
266 
267 	if (parse_write_buffer_into_params(wr_buf, wr_buf_size,
268 					   (long *)param, buf,
269 					   max_param_num,
270 					   &param_nums)) {
271 		kfree(wr_buf);
272 		return -EINVAL;
273 	}
274 
275 	if (param_nums <= 0) {
276 		kfree(wr_buf);
277 		DRM_DEBUG_DRIVER("user data not be read\n");
278 		return -EINVAL;
279 	}
280 
281 	switch (param[0]) {
282 	case LANE_COUNT_ONE:
283 	case LANE_COUNT_TWO:
284 	case LANE_COUNT_FOUR:
285 		break;
286 	default:
287 		valid_input = false;
288 		break;
289 	}
290 
291 	switch (param[1]) {
292 	case LINK_RATE_LOW:
293 	case LINK_RATE_HIGH:
294 	case LINK_RATE_RBR2:
295 	case LINK_RATE_HIGH2:
296 	case LINK_RATE_HIGH3:
297 		break;
298 	default:
299 		valid_input = false;
300 		break;
301 	}
302 
303 	if (!valid_input) {
304 		kfree(wr_buf);
305 		DRM_DEBUG_DRIVER("Invalid Input value No HW will be programmed\n");
306 		return size;
307 	}
308 
309 	/* save user force lane_count, link_rate to preferred settings
310 	 * spread spectrum will not be changed
311 	 */
312 	prefer_link_settings.link_spread = link->cur_link_settings.link_spread;
313 	prefer_link_settings.use_link_rate_set = false;
314 	prefer_link_settings.lane_count = param[0];
315 	prefer_link_settings.link_rate = param[1];
316 
317 	dc_link_set_preferred_training_settings(dc, &prefer_link_settings, NULL, link, true);
318 
319 	kfree(wr_buf);
320 	return size;
321 }
322 
323 /* function: get current DP PHY settings: voltage swing, pre-emphasis,
324  * post-cursor2 (defined by VESA DP specification)
325  *
326  * valid values
327  * voltage swing: 0,1,2,3
328  * pre-emphasis : 0,1,2,3
329  * post cursor2 : 0,1,2,3
330  *
331  *
332  * how to use this debugfs
333  *
334  * debugfs is located at /sys/kernel/debug/dri/0/DP-x
335  *
336  * there will be directories, like DP-1, DP-2,DP-3, etc. for DP display
337  *
338  * To figure out which DP-x is the display for DP to be check,
339  * cd DP-x
340  * ls -ll
341  * There should be debugfs file, like link_settings, phy_settings.
342  * cat link_settings
343  * from lane_count, link_rate to figure which DP-x is for display to be worked
344  * on
345  *
346  * To get current DP PHY settings,
347  * cat phy_settings
348  *
349  * To change DP PHY settings,
350  * echo <voltage_swing> <pre-emphasis> <post_cursor2> > phy_settings
351  * for examle, to change voltage swing to 2, pre-emphasis to 3, post_cursor2 to
352  * 0,
353  * echo 2 3 0 > phy_settings
354  *
355  * To check if change be applied, get current phy settings by
356  * cat phy_settings
357  *
358  * In case invalid values are set by user, like
359  * echo 1 4 0 > phy_settings
360  *
361  * HW will NOT be programmed by these settings.
362  * cat phy_settings will show the previous valid settings.
363  */
dp_phy_settings_read(struct file * f,char __user * buf,size_t size,loff_t * pos)364 static ssize_t dp_phy_settings_read(struct file *f, char __user *buf,
365 				 size_t size, loff_t *pos)
366 {
367 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
368 	struct dc_link *link = connector->dc_link;
369 	char *rd_buf = NULL;
370 	const uint32_t rd_buf_size = 20;
371 	uint32_t result = 0;
372 	int r;
373 
374 	if (*pos & 3 || size & 3)
375 		return -EINVAL;
376 
377 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
378 	if (!rd_buf)
379 		return -EINVAL;
380 
381 	snprintf(rd_buf, rd_buf_size, "  %d  %d  %d  ",
382 			link->cur_lane_setting.VOLTAGE_SWING,
383 			link->cur_lane_setting.PRE_EMPHASIS,
384 			link->cur_lane_setting.POST_CURSOR2);
385 
386 	while (size) {
387 		if (*pos >= rd_buf_size)
388 			break;
389 
390 		r = put_user((*(rd_buf + result)), buf);
391 		if (r)
392 			return r; /* r = -EFAULT */
393 
394 		buf += 1;
395 		size -= 1;
396 		*pos += 1;
397 		result += 1;
398 	}
399 
400 	kfree(rd_buf);
401 	return result;
402 }
403 
dp_phy_settings_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)404 static ssize_t dp_phy_settings_write(struct file *f, const char __user *buf,
405 				 size_t size, loff_t *pos)
406 {
407 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
408 	struct dc_link *link = connector->dc_link;
409 	struct dc *dc = (struct dc *)link->dc;
410 	char *wr_buf = NULL;
411 	uint32_t wr_buf_size = 40;
412 	long param[3];
413 	bool use_prefer_link_setting;
414 	struct link_training_settings link_lane_settings;
415 	int max_param_num = 3;
416 	uint8_t param_nums = 0;
417 	int r = 0;
418 
419 
420 	if (size == 0)
421 		return -EINVAL;
422 
423 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
424 	if (!wr_buf)
425 		return -ENOSPC;
426 
427 	if (parse_write_buffer_into_params(wr_buf, size,
428 					   (long *)param, buf,
429 					   max_param_num,
430 					   &param_nums)) {
431 		kfree(wr_buf);
432 		return -EINVAL;
433 	}
434 
435 	if (param_nums <= 0) {
436 		kfree(wr_buf);
437 		DRM_DEBUG_DRIVER("user data not be read\n");
438 		return -EINVAL;
439 	}
440 
441 	if ((param[0] > VOLTAGE_SWING_MAX_LEVEL) ||
442 			(param[1] > PRE_EMPHASIS_MAX_LEVEL) ||
443 			(param[2] > POST_CURSOR2_MAX_LEVEL)) {
444 		kfree(wr_buf);
445 		DRM_DEBUG_DRIVER("Invalid Input No HW will be programmed\n");
446 		return size;
447 	}
448 
449 	/* get link settings: lane count, link rate */
450 	use_prefer_link_setting =
451 		((link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) &&
452 		(link->test_pattern_enabled));
453 
454 	memset(&link_lane_settings, 0, sizeof(link_lane_settings));
455 
456 	if (use_prefer_link_setting) {
457 		link_lane_settings.link_settings.lane_count =
458 				link->preferred_link_setting.lane_count;
459 		link_lane_settings.link_settings.link_rate =
460 				link->preferred_link_setting.link_rate;
461 		link_lane_settings.link_settings.link_spread =
462 				link->preferred_link_setting.link_spread;
463 	} else {
464 		link_lane_settings.link_settings.lane_count =
465 				link->cur_link_settings.lane_count;
466 		link_lane_settings.link_settings.link_rate =
467 				link->cur_link_settings.link_rate;
468 		link_lane_settings.link_settings.link_spread =
469 				link->cur_link_settings.link_spread;
470 	}
471 
472 	/* apply phy settings from user */
473 	for (r = 0; r < link_lane_settings.link_settings.lane_count; r++) {
474 		link_lane_settings.lane_settings[r].VOLTAGE_SWING =
475 				(enum dc_voltage_swing) (param[0]);
476 		link_lane_settings.lane_settings[r].PRE_EMPHASIS =
477 				(enum dc_pre_emphasis) (param[1]);
478 		link_lane_settings.lane_settings[r].POST_CURSOR2 =
479 				(enum dc_post_cursor2) (param[2]);
480 	}
481 
482 	/* program ASIC registers and DPCD registers */
483 	dc_link_set_drive_settings(dc, &link_lane_settings, link);
484 
485 	kfree(wr_buf);
486 	return size;
487 }
488 
489 /* function description
490  *
491  * set PHY layer or Link layer test pattern
492  * PHY test pattern is used for PHY SI check.
493  * Link layer test will not affect PHY SI.
494  *
495  * Reset Test Pattern:
496  * 0 = DP_TEST_PATTERN_VIDEO_MODE
497  *
498  * PHY test pattern supported:
499  * 1 = DP_TEST_PATTERN_D102
500  * 2 = DP_TEST_PATTERN_SYMBOL_ERROR
501  * 3 = DP_TEST_PATTERN_PRBS7
502  * 4 = DP_TEST_PATTERN_80BIT_CUSTOM
503  * 5 = DP_TEST_PATTERN_CP2520_1
504  * 6 = DP_TEST_PATTERN_CP2520_2 = DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
505  * 7 = DP_TEST_PATTERN_CP2520_3
506  *
507  * DP PHY Link Training Patterns
508  * 8 = DP_TEST_PATTERN_TRAINING_PATTERN1
509  * 9 = DP_TEST_PATTERN_TRAINING_PATTERN2
510  * a = DP_TEST_PATTERN_TRAINING_PATTERN3
511  * b = DP_TEST_PATTERN_TRAINING_PATTERN4
512  *
513  * DP Link Layer Test pattern
514  * c = DP_TEST_PATTERN_COLOR_SQUARES
515  * d = DP_TEST_PATTERN_COLOR_SQUARES_CEA
516  * e = DP_TEST_PATTERN_VERTICAL_BARS
517  * f = DP_TEST_PATTERN_HORIZONTAL_BARS
518  * 10= DP_TEST_PATTERN_COLOR_RAMP
519  *
520  * debugfs phy_test_pattern is located at /syskernel/debug/dri/0/DP-x
521  *
522  * --- set test pattern
523  * echo <test pattern #> > test_pattern
524  *
525  * If test pattern # is not supported, NO HW programming will be done.
526  * for DP_TEST_PATTERN_80BIT_CUSTOM, it needs extra 10 bytes of data
527  * for the user pattern. input 10 bytes data are separated by space
528  *
529  * echo 0x4 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 0x99 0xaa > test_pattern
530  *
531  * --- reset test pattern
532  * echo 0 > test_pattern
533  *
534  * --- HPD detection is disabled when set PHY test pattern
535  *
536  * when PHY test pattern (pattern # within [1,7]) is set, HPD pin of HW ASIC
537  * is disable. User could unplug DP display from DP connected and plug scope to
538  * check test pattern PHY SI.
539  * If there is need unplug scope and plug DP display back, do steps below:
540  * echo 0 > phy_test_pattern
541  * unplug scope
542  * plug DP display.
543  *
544  * "echo 0 > phy_test_pattern" will re-enable HPD pin again so that video sw
545  * driver could detect "unplug scope" and "plug DP display"
546  */
dp_phy_test_pattern_debugfs_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)547 static ssize_t dp_phy_test_pattern_debugfs_write(struct file *f, const char __user *buf,
548 				 size_t size, loff_t *pos)
549 {
550 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
551 	struct dc_link *link = connector->dc_link;
552 	char *wr_buf = NULL;
553 	uint32_t wr_buf_size = 100;
554 	long param[11] = {0x0};
555 	int max_param_num = 11;
556 	enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
557 	bool disable_hpd = false;
558 	bool valid_test_pattern = false;
559 	uint8_t param_nums = 0;
560 	/* init with defalut 80bit custom pattern */
561 	uint8_t custom_pattern[10] = {
562 			0x1f, 0x7c, 0xf0, 0xc1, 0x07,
563 			0x1f, 0x7c, 0xf0, 0xc1, 0x07
564 			};
565 	struct dc_link_settings prefer_link_settings = {LANE_COUNT_UNKNOWN,
566 			LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
567 	struct dc_link_settings cur_link_settings = {LANE_COUNT_UNKNOWN,
568 			LINK_RATE_UNKNOWN, LINK_SPREAD_DISABLED};
569 	struct link_training_settings link_training_settings;
570 	int i;
571 
572 	if (size == 0)
573 		return -EINVAL;
574 
575 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
576 	if (!wr_buf)
577 		return -ENOSPC;
578 
579 	if (parse_write_buffer_into_params(wr_buf, size,
580 					   (long *)param, buf,
581 					   max_param_num,
582 					   &param_nums)) {
583 		kfree(wr_buf);
584 		return -EINVAL;
585 	}
586 
587 	if (param_nums <= 0) {
588 		kfree(wr_buf);
589 		DRM_DEBUG_DRIVER("user data not be read\n");
590 		return -EINVAL;
591 	}
592 
593 
594 	test_pattern = param[0];
595 
596 	switch (test_pattern) {
597 	case DP_TEST_PATTERN_VIDEO_MODE:
598 	case DP_TEST_PATTERN_COLOR_SQUARES:
599 	case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
600 	case DP_TEST_PATTERN_VERTICAL_BARS:
601 	case DP_TEST_PATTERN_HORIZONTAL_BARS:
602 	case DP_TEST_PATTERN_COLOR_RAMP:
603 		valid_test_pattern = true;
604 		break;
605 
606 	case DP_TEST_PATTERN_D102:
607 	case DP_TEST_PATTERN_SYMBOL_ERROR:
608 	case DP_TEST_PATTERN_PRBS7:
609 	case DP_TEST_PATTERN_80BIT_CUSTOM:
610 	case DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE:
611 	case DP_TEST_PATTERN_TRAINING_PATTERN4:
612 		disable_hpd = true;
613 		valid_test_pattern = true;
614 		break;
615 
616 	default:
617 		valid_test_pattern = false;
618 		test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
619 		break;
620 	}
621 
622 	if (!valid_test_pattern) {
623 		kfree(wr_buf);
624 		DRM_DEBUG_DRIVER("Invalid Test Pattern Parameters\n");
625 		return size;
626 	}
627 
628 	if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
629 		for (i = 0; i < 10; i++) {
630 			if ((uint8_t) param[i + 1] != 0x0)
631 				break;
632 		}
633 
634 		if (i < 10) {
635 			/* not use default value */
636 			for (i = 0; i < 10; i++)
637 				custom_pattern[i] = (uint8_t) param[i + 1];
638 		}
639 	}
640 
641 	/* Usage: set DP physical test pattern using debugfs with normal DP
642 	 * panel. Then plug out DP panel and connect a scope to measure
643 	 * For normal video mode and test pattern generated from CRCT,
644 	 * they are visibile to user. So do not disable HPD.
645 	 * Video Mode is also set to clear the test pattern, so enable HPD
646 	 * because it might have been disabled after a test pattern was set.
647 	 * AUX depends on HPD * sequence dependent, do not move!
648 	 */
649 	if (!disable_hpd)
650 		dc_link_enable_hpd(link);
651 
652 	prefer_link_settings.lane_count = link->verified_link_cap.lane_count;
653 	prefer_link_settings.link_rate = link->verified_link_cap.link_rate;
654 	prefer_link_settings.link_spread = link->verified_link_cap.link_spread;
655 
656 	cur_link_settings.lane_count = link->cur_link_settings.lane_count;
657 	cur_link_settings.link_rate = link->cur_link_settings.link_rate;
658 	cur_link_settings.link_spread = link->cur_link_settings.link_spread;
659 
660 	link_training_settings.link_settings = cur_link_settings;
661 
662 
663 	if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
664 		if (prefer_link_settings.lane_count != LANE_COUNT_UNKNOWN &&
665 			prefer_link_settings.link_rate !=  LINK_RATE_UNKNOWN &&
666 			(prefer_link_settings.lane_count != cur_link_settings.lane_count ||
667 			prefer_link_settings.link_rate != cur_link_settings.link_rate))
668 			link_training_settings.link_settings = prefer_link_settings;
669 	}
670 
671 	for (i = 0; i < (unsigned int)(link_training_settings.link_settings.lane_count); i++)
672 		link_training_settings.lane_settings[i] = link->cur_lane_setting;
673 
674 	dc_link_set_test_pattern(
675 		link,
676 		test_pattern,
677 		DP_TEST_PATTERN_COLOR_SPACE_RGB,
678 		&link_training_settings,
679 		custom_pattern,
680 		10);
681 
682 	/* Usage: Set DP physical test pattern using AMDDP with normal DP panel
683 	 * Then plug out DP panel and connect a scope to measure DP PHY signal.
684 	 * Need disable interrupt to avoid SW driver disable DP output. This is
685 	 * done after the test pattern is set.
686 	 */
687 	if (valid_test_pattern && disable_hpd)
688 		dc_link_disable_hpd(link);
689 
690 	kfree(wr_buf);
691 
692 	return size;
693 }
694 
695 /**
696  * Returns the DMCUB tracebuffer contents.
697  * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_tracebuffer
698  */
dmub_tracebuffer_show(struct seq_file * m,void * data)699 static int dmub_tracebuffer_show(struct seq_file *m, void *data)
700 {
701 	struct amdgpu_device *adev = m->private;
702 	struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
703 	struct dmub_debugfs_trace_entry *entries;
704 	uint8_t *tbuf_base;
705 	uint32_t tbuf_size, max_entries, num_entries, i;
706 
707 	if (!fb_info)
708 		return 0;
709 
710 	tbuf_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr;
711 	if (!tbuf_base)
712 		return 0;
713 
714 	tbuf_size = fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size;
715 	max_entries = (tbuf_size - sizeof(struct dmub_debugfs_trace_header)) /
716 		      sizeof(struct dmub_debugfs_trace_entry);
717 
718 	num_entries =
719 		((struct dmub_debugfs_trace_header *)tbuf_base)->entry_count;
720 
721 	num_entries = min(num_entries, max_entries);
722 
723 	entries = (struct dmub_debugfs_trace_entry
724 			   *)(tbuf_base +
725 			      sizeof(struct dmub_debugfs_trace_header));
726 
727 	for (i = 0; i < num_entries; ++i) {
728 		struct dmub_debugfs_trace_entry *entry = &entries[i];
729 
730 		seq_printf(m,
731 			   "trace_code=%u tick_count=%u param0=%u param1=%u\n",
732 			   entry->trace_code, entry->tick_count, entry->param0,
733 			   entry->param1);
734 	}
735 
736 	return 0;
737 }
738 
739 /**
740  * Returns the DMCUB firmware state contents.
741  * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_fw_state
742  */
dmub_fw_state_show(struct seq_file * m,void * data)743 static int dmub_fw_state_show(struct seq_file *m, void *data)
744 {
745 	struct amdgpu_device *adev = m->private;
746 	struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
747 	uint8_t *state_base;
748 	uint32_t state_size;
749 
750 	if (!fb_info)
751 		return 0;
752 
753 	state_base = (uint8_t *)fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr;
754 	if (!state_base)
755 		return 0;
756 
757 	state_size = fb_info->fb[DMUB_WINDOW_6_FW_STATE].size;
758 
759 	return seq_write(m, state_base, state_size);
760 }
761 
762 /*
763  * Returns the current and maximum output bpc for the connector.
764  * Example usage: cat /sys/kernel/debug/dri/0/DP-1/output_bpc
765  */
output_bpc_show(struct seq_file * m,void * data)766 static int output_bpc_show(struct seq_file *m, void *data)
767 {
768 	struct drm_connector *connector = m->private;
769 	struct drm_device *dev = connector->dev;
770 	struct drm_crtc *crtc = NULL;
771 	struct dm_crtc_state *dm_crtc_state = NULL;
772 	int res = -ENODEV;
773 	unsigned int bpc;
774 
775 	mutex_lock(&dev->mode_config.mutex);
776 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
777 
778 	if (connector->state == NULL)
779 		goto unlock;
780 
781 	crtc = connector->state->crtc;
782 	if (crtc == NULL)
783 		goto unlock;
784 
785 	drm_modeset_lock(&crtc->mutex, NULL);
786 	if (crtc->state == NULL)
787 		goto unlock;
788 
789 	dm_crtc_state = to_dm_crtc_state(crtc->state);
790 	if (dm_crtc_state->stream == NULL)
791 		goto unlock;
792 
793 	switch (dm_crtc_state->stream->timing.display_color_depth) {
794 	case COLOR_DEPTH_666:
795 		bpc = 6;
796 		break;
797 	case COLOR_DEPTH_888:
798 		bpc = 8;
799 		break;
800 	case COLOR_DEPTH_101010:
801 		bpc = 10;
802 		break;
803 	case COLOR_DEPTH_121212:
804 		bpc = 12;
805 		break;
806 	case COLOR_DEPTH_161616:
807 		bpc = 16;
808 		break;
809 	default:
810 		goto unlock;
811 	}
812 
813 	seq_printf(m, "Current: %u\n", bpc);
814 	seq_printf(m, "Maximum: %u\n", connector->display_info.bpc);
815 	res = 0;
816 
817 unlock:
818 	if (crtc)
819 		drm_modeset_unlock(&crtc->mutex);
820 
821 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
822 	mutex_unlock(&dev->mode_config.mutex);
823 
824 	return res;
825 }
826 
827 #ifdef CONFIG_DRM_AMD_DC_HDCP
828 /*
829  * Returns the HDCP capability of the Display (1.4 for now).
830  *
831  * NOTE* Not all HDMI displays report their HDCP caps even when they are capable.
832  * Since its rare for a display to not be HDCP 1.4 capable, we set HDMI as always capable.
833  *
834  * Example usage: cat /sys/kernel/debug/dri/0/DP-1/hdcp_sink_capability
835  *		or cat /sys/kernel/debug/dri/0/HDMI-A-1/hdcp_sink_capability
836  */
hdcp_sink_capability_show(struct seq_file * m,void * data)837 static int hdcp_sink_capability_show(struct seq_file *m, void *data)
838 {
839 	struct drm_connector *connector = m->private;
840 	struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
841 	bool hdcp_cap, hdcp2_cap;
842 
843 	if (connector->status != connector_status_connected)
844 		return -ENODEV;
845 
846 	seq_printf(m, "%s:%d HDCP version: ", connector->name, connector->base.id);
847 
848 	hdcp_cap = dc_link_is_hdcp14(aconnector->dc_link, aconnector->dc_sink->sink_signal);
849 	hdcp2_cap = dc_link_is_hdcp22(aconnector->dc_link, aconnector->dc_sink->sink_signal);
850 
851 
852 	if (hdcp_cap)
853 		seq_printf(m, "%s ", "HDCP1.4");
854 	if (hdcp2_cap)
855 		seq_printf(m, "%s ", "HDCP2.2");
856 
857 	if (!hdcp_cap && !hdcp2_cap)
858 		seq_printf(m, "%s ", "None");
859 
860 	seq_puts(m, "\n");
861 
862 	return 0;
863 }
864 #endif
865 /* function description
866  *
867  * generic SDP message access for testing
868  *
869  * debugfs sdp_message is located at /syskernel/debug/dri/0/DP-x
870  *
871  * SDP header
872  * Hb0 : Secondary-Data Packet ID
873  * Hb1 : Secondary-Data Packet type
874  * Hb2 : Secondary-Data-packet-specific header, Byte 0
875  * Hb3 : Secondary-Data-packet-specific header, Byte 1
876  *
877  * for using custom sdp message: input 4 bytes SDP header and 32 bytes raw data
878  */
dp_sdp_message_debugfs_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)879 static ssize_t dp_sdp_message_debugfs_write(struct file *f, const char __user *buf,
880 				 size_t size, loff_t *pos)
881 {
882 	int r;
883 	uint8_t data[36];
884 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
885 	struct dm_crtc_state *acrtc_state;
886 	uint32_t write_size = 36;
887 
888 	if (connector->base.status != connector_status_connected)
889 		return -ENODEV;
890 
891 	if (size == 0)
892 		return 0;
893 
894 	acrtc_state = to_dm_crtc_state(connector->base.state->crtc->state);
895 
896 	r = copy_from_user(data, buf, write_size);
897 
898 	write_size -= r;
899 
900 	dc_stream_send_dp_sdp(acrtc_state->stream, data, write_size);
901 
902 	return write_size;
903 }
904 
dp_dpcd_address_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)905 static ssize_t dp_dpcd_address_write(struct file *f, const char __user *buf,
906 				 size_t size, loff_t *pos)
907 {
908 	int r;
909 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
910 
911 	if (size < sizeof(connector->debugfs_dpcd_address))
912 		return -EINVAL;
913 
914 	r = copy_from_user(&connector->debugfs_dpcd_address,
915 			buf, sizeof(connector->debugfs_dpcd_address));
916 
917 	return size - r;
918 }
919 
dp_dpcd_size_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)920 static ssize_t dp_dpcd_size_write(struct file *f, const char __user *buf,
921 				 size_t size, loff_t *pos)
922 {
923 	int r;
924 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
925 
926 	if (size < sizeof(connector->debugfs_dpcd_size))
927 		return -EINVAL;
928 
929 	r = copy_from_user(&connector->debugfs_dpcd_size,
930 			buf, sizeof(connector->debugfs_dpcd_size));
931 
932 	if (connector->debugfs_dpcd_size > 256)
933 		connector->debugfs_dpcd_size = 0;
934 
935 	return size - r;
936 }
937 
dp_dpcd_data_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)938 static ssize_t dp_dpcd_data_write(struct file *f, const char __user *buf,
939 				 size_t size, loff_t *pos)
940 {
941 	int r;
942 	char *data;
943 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
944 	struct dc_link *link = connector->dc_link;
945 	uint32_t write_size = connector->debugfs_dpcd_size;
946 
947 	if (!write_size || size < write_size)
948 		return -EINVAL;
949 
950 	data = kzalloc(write_size, GFP_KERNEL);
951 	if (!data)
952 		return 0;
953 
954 	r = copy_from_user(data, buf, write_size);
955 
956 	dm_helpers_dp_write_dpcd(link->ctx, link,
957 			connector->debugfs_dpcd_address, data, write_size - r);
958 	kfree(data);
959 	return write_size - r;
960 }
961 
dp_dpcd_data_read(struct file * f,char __user * buf,size_t size,loff_t * pos)962 static ssize_t dp_dpcd_data_read(struct file *f, char __user *buf,
963 				 size_t size, loff_t *pos)
964 {
965 	int r;
966 	char *data;
967 	struct amdgpu_dm_connector *connector = file_inode(f)->i_private;
968 	struct dc_link *link = connector->dc_link;
969 	uint32_t read_size = connector->debugfs_dpcd_size;
970 
971 	if (!read_size || size < read_size)
972 		return 0;
973 
974 	data = kzalloc(read_size, GFP_KERNEL);
975 	if (!data)
976 		return 0;
977 
978 	dm_helpers_dp_read_dpcd(link->ctx, link,
979 			connector->debugfs_dpcd_address, data, read_size);
980 
981 	r = copy_to_user(buf, data, read_size);
982 
983 	kfree(data);
984 	return read_size - r;
985 }
986 
987 /* function: Read link's DSC & FEC capabilities
988  *
989  *
990  * Access it with the following command (you need to specify
991  * connector like DP-1):
992  *
993  *	cat /sys/kernel/debug/dri/0/DP-X/dp_dsc_fec_support
994  *
995  */
dp_dsc_fec_support_show(struct seq_file * m,void * data)996 static int dp_dsc_fec_support_show(struct seq_file *m, void *data)
997 {
998 	struct drm_connector *connector = m->private;
999 	struct drm_modeset_acquire_ctx ctx;
1000 	struct drm_device *dev = connector->dev;
1001 	struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
1002 	int ret = 0;
1003 	bool try_again = false;
1004 	bool is_fec_supported = false;
1005 	bool is_dsc_supported = false;
1006 	struct dpcd_caps dpcd_caps;
1007 
1008 	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
1009 	do {
1010 		try_again = false;
1011 		ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
1012 		if (ret) {
1013 			if (ret == -EDEADLK) {
1014 				ret = drm_modeset_backoff(&ctx);
1015 				if (!ret) {
1016 					try_again = true;
1017 					continue;
1018 				}
1019 			}
1020 			break;
1021 		}
1022 		if (connector->status != connector_status_connected) {
1023 			ret = -ENODEV;
1024 			break;
1025 		}
1026 		dpcd_caps = aconnector->dc_link->dpcd_caps;
1027 		if (aconnector->port) {
1028 			/* aconnector sets dsc_aux during get_modes call
1029 			 * if MST connector has it means it can either
1030 			 * enable DSC on the sink device or on MST branch
1031 			 * its connected to.
1032 			 */
1033 			if (aconnector->dsc_aux) {
1034 				is_fec_supported = true;
1035 				is_dsc_supported = true;
1036 			}
1037 		} else {
1038 			is_fec_supported = dpcd_caps.fec_cap.raw & 0x1;
1039 			is_dsc_supported = dpcd_caps.dsc_caps.dsc_basic_caps.raw[0] & 0x1;
1040 		}
1041 	} while (try_again);
1042 
1043 	drm_modeset_drop_locks(&ctx);
1044 	drm_modeset_acquire_fini(&ctx);
1045 
1046 	seq_printf(m, "FEC_Sink_Support: %s\n", yesno(is_fec_supported));
1047 	seq_printf(m, "DSC_Sink_Support: %s\n", yesno(is_dsc_supported));
1048 
1049 	return ret;
1050 }
1051 
1052 /* function: Trigger virtual HPD redetection on connector
1053  *
1054  * This function will perform link rediscovery, link disable
1055  * and enable, and dm connector state update.
1056  *
1057  * Retrigger HPD on an existing connector by echoing 1 into
1058  * its respectful "trigger_hotplug" debugfs entry:
1059  *
1060  *	echo 1 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1061  *
1062  * This function can perform HPD unplug:
1063  *
1064  *	echo 0 > /sys/kernel/debug/dri/0/DP-X/trigger_hotplug
1065  *
1066  */
dp_trigger_hotplug(struct file * f,const char __user * buf,size_t size,loff_t * pos)1067 static ssize_t dp_trigger_hotplug(struct file *f, const char __user *buf,
1068 							size_t size, loff_t *pos)
1069 {
1070 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1071 	struct drm_connector *connector = &aconnector->base;
1072 	struct dc_link *link = NULL;
1073 	struct drm_device *dev = connector->dev;
1074 	enum dc_connection_type new_connection_type = dc_connection_none;
1075 	char *wr_buf = NULL;
1076 	uint32_t wr_buf_size = 42;
1077 	int max_param_num = 1;
1078 	long param[1] = {0};
1079 	uint8_t param_nums = 0;
1080 
1081 	if (!aconnector || !aconnector->dc_link)
1082 		return -EINVAL;
1083 
1084 	if (size == 0)
1085 		return -EINVAL;
1086 
1087 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1088 
1089 	if (!wr_buf) {
1090 		DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1091 		return -ENOSPC;
1092 	}
1093 
1094 	if (parse_write_buffer_into_params(wr_buf, size,
1095 						(long *)param, buf,
1096 						max_param_num,
1097 						&param_nums)) {
1098 		kfree(wr_buf);
1099 		return -EINVAL;
1100 	}
1101 
1102 	if (param_nums <= 0) {
1103 		DRM_DEBUG_DRIVER("user data not be read\n");
1104 		kfree(wr_buf);
1105 		return -EINVAL;
1106 	}
1107 
1108 	if (param[0] == 1) {
1109 		mutex_lock(&aconnector->hpd_lock);
1110 
1111 		if (!dc_link_detect_sink(aconnector->dc_link, &new_connection_type) &&
1112 			new_connection_type != dc_connection_none)
1113 			goto unlock;
1114 
1115 		if (!dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD))
1116 			goto unlock;
1117 
1118 		amdgpu_dm_update_connector_after_detect(aconnector);
1119 
1120 		drm_modeset_lock_all(dev);
1121 		dm_restore_drm_connector_state(dev, connector);
1122 		drm_modeset_unlock_all(dev);
1123 
1124 		drm_kms_helper_hotplug_event(dev);
1125 	} else if (param[0] == 0) {
1126 		if (!aconnector->dc_link)
1127 			goto unlock;
1128 
1129 		link = aconnector->dc_link;
1130 
1131 		if (link->local_sink) {
1132 			dc_sink_release(link->local_sink);
1133 			link->local_sink = NULL;
1134 		}
1135 
1136 		link->dpcd_sink_count = 0;
1137 		link->type = dc_connection_none;
1138 		link->dongle_max_pix_clk = 0;
1139 
1140 		amdgpu_dm_update_connector_after_detect(aconnector);
1141 
1142 		drm_modeset_lock_all(dev);
1143 		dm_restore_drm_connector_state(dev, connector);
1144 		drm_modeset_unlock_all(dev);
1145 
1146 		drm_kms_helper_hotplug_event(dev);
1147 	}
1148 
1149 unlock:
1150 	mutex_unlock(&aconnector->hpd_lock);
1151 
1152 	kfree(wr_buf);
1153 	return size;
1154 }
1155 
1156 /* function: read DSC status on the connector
1157  *
1158  * The read function: dp_dsc_clock_en_read
1159  * returns current status of DSC clock on the connector.
1160  * The return is a boolean flag: 1 or 0.
1161  *
1162  * Access it with the following command (you need to specify
1163  * connector like DP-1):
1164  *
1165  *	cat /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1166  *
1167  * Expected output:
1168  * 1 - means that DSC is currently enabled
1169  * 0 - means that DSC is disabled
1170  */
dp_dsc_clock_en_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1171 static ssize_t dp_dsc_clock_en_read(struct file *f, char __user *buf,
1172 				    size_t size, loff_t *pos)
1173 {
1174 	char *rd_buf = NULL;
1175 	char *rd_buf_ptr = NULL;
1176 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1177 	struct display_stream_compressor *dsc;
1178 	struct dcn_dsc_state dsc_state = {0};
1179 	const uint32_t rd_buf_size = 10;
1180 	struct pipe_ctx *pipe_ctx;
1181 	ssize_t result = 0;
1182 	int i, r, str_len = 30;
1183 
1184 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1185 
1186 	if (!rd_buf)
1187 		return -ENOMEM;
1188 
1189 	rd_buf_ptr = rd_buf;
1190 
1191 	for (i = 0; i < MAX_PIPES; i++) {
1192 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1193 			if (pipe_ctx && pipe_ctx->stream &&
1194 			    pipe_ctx->stream->link == aconnector->dc_link)
1195 				break;
1196 	}
1197 
1198 	if (!pipe_ctx)
1199 		return -ENXIO;
1200 
1201 	dsc = pipe_ctx->stream_res.dsc;
1202 	if (dsc)
1203 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
1204 
1205 	snprintf(rd_buf_ptr, str_len,
1206 		"%d\n",
1207 		dsc_state.dsc_clock_en);
1208 	rd_buf_ptr += str_len;
1209 
1210 	while (size) {
1211 		if (*pos >= rd_buf_size)
1212 			break;
1213 
1214 		r = put_user(*(rd_buf + result), buf);
1215 		if (r)
1216 			return r; /* r = -EFAULT */
1217 
1218 		buf += 1;
1219 		size -= 1;
1220 		*pos += 1;
1221 		result += 1;
1222 	}
1223 
1224 	kfree(rd_buf);
1225 	return result;
1226 }
1227 
1228 /* function: write force DSC on the connector
1229  *
1230  * The write function: dp_dsc_clock_en_write
1231  * enables to force DSC on the connector.
1232  * User can write to either force enable or force disable DSC
1233  * on the next modeset or set it to driver default
1234  *
1235  * Accepted inputs:
1236  * 0 - default DSC enablement policy
1237  * 1 - force enable DSC on the connector
1238  * 2 - force disable DSC on the connector (might cause fail in atomic_check)
1239  *
1240  * Writing DSC settings is done with the following command:
1241  * - To force enable DSC (you need to specify
1242  * connector like DP-1):
1243  *
1244  *	echo 0x1 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1245  *
1246  * - To return to default state set the flag to zero and
1247  * let driver deal with DSC automatically
1248  * (you need to specify connector like DP-1):
1249  *
1250  *	echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_clock_en
1251  *
1252  */
dp_dsc_clock_en_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)1253 static ssize_t dp_dsc_clock_en_write(struct file *f, const char __user *buf,
1254 				     size_t size, loff_t *pos)
1255 {
1256 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1257 	struct pipe_ctx *pipe_ctx;
1258 	int i;
1259 	char *wr_buf = NULL;
1260 	uint32_t wr_buf_size = 42;
1261 	int max_param_num = 1;
1262 	long param[1] = {0};
1263 	uint8_t param_nums = 0;
1264 
1265 	if (size == 0)
1266 		return -EINVAL;
1267 
1268 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1269 
1270 	if (!wr_buf) {
1271 		DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1272 		return -ENOSPC;
1273 	}
1274 
1275 	if (parse_write_buffer_into_params(wr_buf, size,
1276 					    (long *)param, buf,
1277 					    max_param_num,
1278 					    &param_nums)) {
1279 		kfree(wr_buf);
1280 		return -EINVAL;
1281 	}
1282 
1283 	if (param_nums <= 0) {
1284 		DRM_DEBUG_DRIVER("user data not be read\n");
1285 		kfree(wr_buf);
1286 		return -EINVAL;
1287 	}
1288 
1289 	for (i = 0; i < MAX_PIPES; i++) {
1290 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1291 			if (pipe_ctx && pipe_ctx->stream &&
1292 			    pipe_ctx->stream->link == aconnector->dc_link)
1293 				break;
1294 	}
1295 
1296 	if (!pipe_ctx || !pipe_ctx->stream)
1297 		goto done;
1298 
1299 	if (param[0] == 1)
1300 		aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_ENABLE;
1301 	else if (param[0] == 2)
1302 		aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DISABLE;
1303 	else
1304 		aconnector->dsc_settings.dsc_force_enable = DSC_CLK_FORCE_DEFAULT;
1305 
1306 done:
1307 	kfree(wr_buf);
1308 	return size;
1309 }
1310 
1311 /* function: read DSC slice width parameter on the connector
1312  *
1313  * The read function: dp_dsc_slice_width_read
1314  * returns dsc slice width used in the current configuration
1315  * The return is an integer: 0 or other positive number
1316  *
1317  * Access the status with the following command:
1318  *
1319  *	cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1320  *
1321  * 0 - means that DSC is disabled
1322  *
1323  * Any other number more than zero represents the
1324  * slice width currently used by DSC in pixels
1325  *
1326  */
dp_dsc_slice_width_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1327 static ssize_t dp_dsc_slice_width_read(struct file *f, char __user *buf,
1328 				    size_t size, loff_t *pos)
1329 {
1330 	char *rd_buf = NULL;
1331 	char *rd_buf_ptr = NULL;
1332 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1333 	struct display_stream_compressor *dsc;
1334 	struct dcn_dsc_state dsc_state = {0};
1335 	const uint32_t rd_buf_size = 100;
1336 	struct pipe_ctx *pipe_ctx;
1337 	ssize_t result = 0;
1338 	int i, r, str_len = 30;
1339 
1340 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1341 
1342 	if (!rd_buf)
1343 		return -ENOMEM;
1344 
1345 	rd_buf_ptr = rd_buf;
1346 
1347 	for (i = 0; i < MAX_PIPES; i++) {
1348 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1349 			if (pipe_ctx && pipe_ctx->stream &&
1350 			    pipe_ctx->stream->link == aconnector->dc_link)
1351 				break;
1352 	}
1353 
1354 	if (!pipe_ctx)
1355 		return -ENXIO;
1356 
1357 	dsc = pipe_ctx->stream_res.dsc;
1358 	if (dsc)
1359 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
1360 
1361 	snprintf(rd_buf_ptr, str_len,
1362 		"%d\n",
1363 		dsc_state.dsc_slice_width);
1364 	rd_buf_ptr += str_len;
1365 
1366 	while (size) {
1367 		if (*pos >= rd_buf_size)
1368 			break;
1369 
1370 		r = put_user(*(rd_buf + result), buf);
1371 		if (r)
1372 			return r; /* r = -EFAULT */
1373 
1374 		buf += 1;
1375 		size -= 1;
1376 		*pos += 1;
1377 		result += 1;
1378 	}
1379 
1380 	kfree(rd_buf);
1381 	return result;
1382 }
1383 
1384 /* function: write DSC slice width parameter
1385  *
1386  * The write function: dp_dsc_slice_width_write
1387  * overwrites automatically generated DSC configuration
1388  * of slice width.
1389  *
1390  * The user has to write the slice width divisible by the
1391  * picture width.
1392  *
1393  * Also the user has to write width in hexidecimal
1394  * rather than in decimal.
1395  *
1396  * Writing DSC settings is done with the following command:
1397  * - To force overwrite slice width: (example sets to 1920 pixels)
1398  *
1399  *	echo 0x780 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1400  *
1401  *  - To stop overwriting and let driver find the optimal size,
1402  * set the width to zero:
1403  *
1404  *	echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_width
1405  *
1406  */
dp_dsc_slice_width_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)1407 static ssize_t dp_dsc_slice_width_write(struct file *f, const char __user *buf,
1408 				     size_t size, loff_t *pos)
1409 {
1410 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1411 	struct pipe_ctx *pipe_ctx;
1412 	int i;
1413 	char *wr_buf = NULL;
1414 	uint32_t wr_buf_size = 42;
1415 	int max_param_num = 1;
1416 	long param[1] = {0};
1417 	uint8_t param_nums = 0;
1418 
1419 	if (size == 0)
1420 		return -EINVAL;
1421 
1422 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1423 
1424 	if (!wr_buf) {
1425 		DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1426 		return -ENOSPC;
1427 	}
1428 
1429 	if (parse_write_buffer_into_params(wr_buf, size,
1430 					    (long *)param, buf,
1431 					    max_param_num,
1432 					    &param_nums)) {
1433 		kfree(wr_buf);
1434 		return -EINVAL;
1435 	}
1436 
1437 	if (param_nums <= 0) {
1438 		DRM_DEBUG_DRIVER("user data not be read\n");
1439 		kfree(wr_buf);
1440 		return -EINVAL;
1441 	}
1442 
1443 	for (i = 0; i < MAX_PIPES; i++) {
1444 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1445 			if (pipe_ctx && pipe_ctx->stream &&
1446 			    pipe_ctx->stream->link == aconnector->dc_link)
1447 				break;
1448 	}
1449 
1450 	if (!pipe_ctx || !pipe_ctx->stream)
1451 		goto done;
1452 
1453 	if (param[0] > 0)
1454 		aconnector->dsc_settings.dsc_num_slices_h = DIV_ROUND_UP(
1455 					pipe_ctx->stream->timing.h_addressable,
1456 					param[0]);
1457 	else
1458 		aconnector->dsc_settings.dsc_num_slices_h = 0;
1459 
1460 done:
1461 	kfree(wr_buf);
1462 	return size;
1463 }
1464 
1465 /* function: read DSC slice height parameter on the connector
1466  *
1467  * The read function: dp_dsc_slice_height_read
1468  * returns dsc slice height used in the current configuration
1469  * The return is an integer: 0 or other positive number
1470  *
1471  * Access the status with the following command:
1472  *
1473  *	cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1474  *
1475  * 0 - means that DSC is disabled
1476  *
1477  * Any other number more than zero represents the
1478  * slice height currently used by DSC in pixels
1479  *
1480  */
dp_dsc_slice_height_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1481 static ssize_t dp_dsc_slice_height_read(struct file *f, char __user *buf,
1482 				    size_t size, loff_t *pos)
1483 {
1484 	char *rd_buf = NULL;
1485 	char *rd_buf_ptr = NULL;
1486 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1487 	struct display_stream_compressor *dsc;
1488 	struct dcn_dsc_state dsc_state = {0};
1489 	const uint32_t rd_buf_size = 100;
1490 	struct pipe_ctx *pipe_ctx;
1491 	ssize_t result = 0;
1492 	int i, r, str_len = 30;
1493 
1494 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1495 
1496 	if (!rd_buf)
1497 		return -ENOMEM;
1498 
1499 	rd_buf_ptr = rd_buf;
1500 
1501 	for (i = 0; i < MAX_PIPES; i++) {
1502 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1503 			if (pipe_ctx && pipe_ctx->stream &&
1504 			    pipe_ctx->stream->link == aconnector->dc_link)
1505 				break;
1506 	}
1507 
1508 	if (!pipe_ctx)
1509 		return -ENXIO;
1510 
1511 	dsc = pipe_ctx->stream_res.dsc;
1512 	if (dsc)
1513 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
1514 
1515 	snprintf(rd_buf_ptr, str_len,
1516 		"%d\n",
1517 		dsc_state.dsc_slice_height);
1518 	rd_buf_ptr += str_len;
1519 
1520 	while (size) {
1521 		if (*pos >= rd_buf_size)
1522 			break;
1523 
1524 		r = put_user(*(rd_buf + result), buf);
1525 		if (r)
1526 			return r; /* r = -EFAULT */
1527 
1528 		buf += 1;
1529 		size -= 1;
1530 		*pos += 1;
1531 		result += 1;
1532 	}
1533 
1534 	kfree(rd_buf);
1535 	return result;
1536 }
1537 
1538 /* function: write DSC slice height parameter
1539  *
1540  * The write function: dp_dsc_slice_height_write
1541  * overwrites automatically generated DSC configuration
1542  * of slice height.
1543  *
1544  * The user has to write the slice height divisible by the
1545  * picture height.
1546  *
1547  * Also the user has to write height in hexidecimal
1548  * rather than in decimal.
1549  *
1550  * Writing DSC settings is done with the following command:
1551  * - To force overwrite slice height (example sets to 128 pixels):
1552  *
1553  *	echo 0x80 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1554  *
1555  *  - To stop overwriting and let driver find the optimal size,
1556  * set the height to zero:
1557  *
1558  *	echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_slice_height
1559  *
1560  */
dp_dsc_slice_height_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)1561 static ssize_t dp_dsc_slice_height_write(struct file *f, const char __user *buf,
1562 				     size_t size, loff_t *pos)
1563 {
1564 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1565 	struct pipe_ctx *pipe_ctx;
1566 	int i;
1567 	char *wr_buf = NULL;
1568 	uint32_t wr_buf_size = 42;
1569 	int max_param_num = 1;
1570 	uint8_t param_nums = 0;
1571 	long param[1] = {0};
1572 
1573 	if (size == 0)
1574 		return -EINVAL;
1575 
1576 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1577 
1578 	if (!wr_buf) {
1579 		DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1580 		return -ENOSPC;
1581 	}
1582 
1583 	if (parse_write_buffer_into_params(wr_buf, size,
1584 					    (long *)param, buf,
1585 					    max_param_num,
1586 					    &param_nums)) {
1587 		kfree(wr_buf);
1588 		return -EINVAL;
1589 	}
1590 
1591 	if (param_nums <= 0) {
1592 		DRM_DEBUG_DRIVER("user data not be read\n");
1593 		kfree(wr_buf);
1594 		return -EINVAL;
1595 	}
1596 
1597 	for (i = 0; i < MAX_PIPES; i++) {
1598 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1599 			if (pipe_ctx && pipe_ctx->stream &&
1600 			    pipe_ctx->stream->link == aconnector->dc_link)
1601 				break;
1602 	}
1603 
1604 	if (!pipe_ctx || !pipe_ctx->stream)
1605 		goto done;
1606 
1607 	if (param[0] > 0)
1608 		aconnector->dsc_settings.dsc_num_slices_v = DIV_ROUND_UP(
1609 					pipe_ctx->stream->timing.v_addressable,
1610 					param[0]);
1611 	else
1612 		aconnector->dsc_settings.dsc_num_slices_v = 0;
1613 
1614 done:
1615 	kfree(wr_buf);
1616 	return size;
1617 }
1618 
1619 /* function: read DSC target rate on the connector in bits per pixel
1620  *
1621  * The read function: dp_dsc_bits_per_pixel_read
1622  * returns target rate of compression in bits per pixel
1623  * The return is an integer: 0 or other positive integer
1624  *
1625  * Access it with the following command:
1626  *
1627  *	cat /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1628  *
1629  *  0 - means that DSC is disabled
1630  */
dp_dsc_bits_per_pixel_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1631 static ssize_t dp_dsc_bits_per_pixel_read(struct file *f, char __user *buf,
1632 				    size_t size, loff_t *pos)
1633 {
1634 	char *rd_buf = NULL;
1635 	char *rd_buf_ptr = NULL;
1636 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1637 	struct display_stream_compressor *dsc;
1638 	struct dcn_dsc_state dsc_state = {0};
1639 	const uint32_t rd_buf_size = 100;
1640 	struct pipe_ctx *pipe_ctx;
1641 	ssize_t result = 0;
1642 	int i, r, str_len = 30;
1643 
1644 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1645 
1646 	if (!rd_buf)
1647 		return -ENOMEM;
1648 
1649 	rd_buf_ptr = rd_buf;
1650 
1651 	for (i = 0; i < MAX_PIPES; i++) {
1652 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1653 			if (pipe_ctx && pipe_ctx->stream &&
1654 			    pipe_ctx->stream->link == aconnector->dc_link)
1655 				break;
1656 	}
1657 
1658 	if (!pipe_ctx)
1659 		return -ENXIO;
1660 
1661 	dsc = pipe_ctx->stream_res.dsc;
1662 	if (dsc)
1663 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
1664 
1665 	snprintf(rd_buf_ptr, str_len,
1666 		"%d\n",
1667 		dsc_state.dsc_bits_per_pixel);
1668 	rd_buf_ptr += str_len;
1669 
1670 	while (size) {
1671 		if (*pos >= rd_buf_size)
1672 			break;
1673 
1674 		r = put_user(*(rd_buf + result), buf);
1675 		if (r)
1676 			return r; /* r = -EFAULT */
1677 
1678 		buf += 1;
1679 		size -= 1;
1680 		*pos += 1;
1681 		result += 1;
1682 	}
1683 
1684 	kfree(rd_buf);
1685 	return result;
1686 }
1687 
1688 /* function: write DSC target rate in bits per pixel
1689  *
1690  * The write function: dp_dsc_bits_per_pixel_write
1691  * overwrites automatically generated DSC configuration
1692  * of DSC target bit rate.
1693  *
1694  * Also the user has to write bpp in hexidecimal
1695  * rather than in decimal.
1696  *
1697  * Writing DSC settings is done with the following command:
1698  * - To force overwrite rate (example sets to 256 bpp x 1/16):
1699  *
1700  *	echo 0x100 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1701  *
1702  *  - To stop overwriting and let driver find the optimal rate,
1703  * set the rate to zero:
1704  *
1705  *	echo 0x0 > /sys/kernel/debug/dri/0/DP-X/dsc_bits_per_pixel
1706  *
1707  */
dp_dsc_bits_per_pixel_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)1708 static ssize_t dp_dsc_bits_per_pixel_write(struct file *f, const char __user *buf,
1709 				     size_t size, loff_t *pos)
1710 {
1711 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1712 	struct pipe_ctx *pipe_ctx;
1713 	int i;
1714 	char *wr_buf = NULL;
1715 	uint32_t wr_buf_size = 42;
1716 	int max_param_num = 1;
1717 	uint8_t param_nums = 0;
1718 	long param[1] = {0};
1719 
1720 	if (size == 0)
1721 		return -EINVAL;
1722 
1723 	wr_buf = kcalloc(wr_buf_size, sizeof(char), GFP_KERNEL);
1724 
1725 	if (!wr_buf) {
1726 		DRM_DEBUG_DRIVER("no memory to allocate write buffer\n");
1727 		return -ENOSPC;
1728 	}
1729 
1730 	if (parse_write_buffer_into_params(wr_buf, size,
1731 					    (long *)param, buf,
1732 					    max_param_num,
1733 					    &param_nums)) {
1734 		kfree(wr_buf);
1735 		return -EINVAL;
1736 	}
1737 
1738 	if (param_nums <= 0) {
1739 		DRM_DEBUG_DRIVER("user data not be read\n");
1740 		kfree(wr_buf);
1741 		return -EINVAL;
1742 	}
1743 
1744 	for (i = 0; i < MAX_PIPES; i++) {
1745 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1746 			if (pipe_ctx && pipe_ctx->stream &&
1747 			    pipe_ctx->stream->link == aconnector->dc_link)
1748 				break;
1749 	}
1750 
1751 	if (!pipe_ctx || !pipe_ctx->stream)
1752 		goto done;
1753 
1754 	aconnector->dsc_settings.dsc_bits_per_pixel = param[0];
1755 
1756 done:
1757 	kfree(wr_buf);
1758 	return size;
1759 }
1760 
1761 /* function: read DSC picture width parameter on the connector
1762  *
1763  * The read function: dp_dsc_pic_width_read
1764  * returns dsc picture width used in the current configuration
1765  * It is the same as h_addressable of the current
1766  * display's timing
1767  * The return is an integer: 0 or other positive integer
1768  * If 0 then DSC is disabled.
1769  *
1770  * Access it with the following command:
1771  *
1772  *	cat /sys/kernel/debug/dri/0/DP-X/dsc_pic_width
1773  *
1774  * 0 - means that DSC is disabled
1775  */
dp_dsc_pic_width_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1776 static ssize_t dp_dsc_pic_width_read(struct file *f, char __user *buf,
1777 				    size_t size, loff_t *pos)
1778 {
1779 	char *rd_buf = NULL;
1780 	char *rd_buf_ptr = NULL;
1781 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1782 	struct display_stream_compressor *dsc;
1783 	struct dcn_dsc_state dsc_state = {0};
1784 	const uint32_t rd_buf_size = 100;
1785 	struct pipe_ctx *pipe_ctx;
1786 	ssize_t result = 0;
1787 	int i, r, str_len = 30;
1788 
1789 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1790 
1791 	if (!rd_buf)
1792 		return -ENOMEM;
1793 
1794 	rd_buf_ptr = rd_buf;
1795 
1796 	for (i = 0; i < MAX_PIPES; i++) {
1797 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1798 			if (pipe_ctx && pipe_ctx->stream &&
1799 			    pipe_ctx->stream->link == aconnector->dc_link)
1800 				break;
1801 	}
1802 
1803 	if (!pipe_ctx)
1804 		return -ENXIO;
1805 
1806 	dsc = pipe_ctx->stream_res.dsc;
1807 	if (dsc)
1808 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
1809 
1810 	snprintf(rd_buf_ptr, str_len,
1811 		"%d\n",
1812 		dsc_state.dsc_pic_width);
1813 	rd_buf_ptr += str_len;
1814 
1815 	while (size) {
1816 		if (*pos >= rd_buf_size)
1817 			break;
1818 
1819 		r = put_user(*(rd_buf + result), buf);
1820 		if (r)
1821 			return r; /* r = -EFAULT */
1822 
1823 		buf += 1;
1824 		size -= 1;
1825 		*pos += 1;
1826 		result += 1;
1827 	}
1828 
1829 	kfree(rd_buf);
1830 	return result;
1831 }
1832 
dp_dsc_pic_height_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1833 static ssize_t dp_dsc_pic_height_read(struct file *f, char __user *buf,
1834 				    size_t size, loff_t *pos)
1835 {
1836 	char *rd_buf = NULL;
1837 	char *rd_buf_ptr = NULL;
1838 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1839 	struct display_stream_compressor *dsc;
1840 	struct dcn_dsc_state dsc_state = {0};
1841 	const uint32_t rd_buf_size = 100;
1842 	struct pipe_ctx *pipe_ctx;
1843 	ssize_t result = 0;
1844 	int i, r, str_len = 30;
1845 
1846 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1847 
1848 	if (!rd_buf)
1849 		return -ENOMEM;
1850 
1851 	rd_buf_ptr = rd_buf;
1852 
1853 	for (i = 0; i < MAX_PIPES; i++) {
1854 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1855 			if (pipe_ctx && pipe_ctx->stream &&
1856 			    pipe_ctx->stream->link == aconnector->dc_link)
1857 				break;
1858 	}
1859 
1860 	if (!pipe_ctx)
1861 		return -ENXIO;
1862 
1863 	dsc = pipe_ctx->stream_res.dsc;
1864 	if (dsc)
1865 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
1866 
1867 	snprintf(rd_buf_ptr, str_len,
1868 		"%d\n",
1869 		dsc_state.dsc_pic_height);
1870 	rd_buf_ptr += str_len;
1871 
1872 	while (size) {
1873 		if (*pos >= rd_buf_size)
1874 			break;
1875 
1876 		r = put_user(*(rd_buf + result), buf);
1877 		if (r)
1878 			return r; /* r = -EFAULT */
1879 
1880 		buf += 1;
1881 		size -= 1;
1882 		*pos += 1;
1883 		result += 1;
1884 	}
1885 
1886 	kfree(rd_buf);
1887 	return result;
1888 }
1889 
1890 /* function: read DSC chunk size parameter on the connector
1891  *
1892  * The read function: dp_dsc_chunk_size_read
1893  * returns dsc chunk size set in the current configuration
1894  * The value is calculated automatically by DSC code
1895  * and depends on slice parameters and bpp target rate
1896  * The return is an integer: 0 or other positive integer
1897  * If 0 then DSC is disabled.
1898  *
1899  * Access it with the following command:
1900  *
1901  *	cat /sys/kernel/debug/dri/0/DP-X/dsc_chunk_size
1902  *
1903  * 0 - means that DSC is disabled
1904  */
dp_dsc_chunk_size_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1905 static ssize_t dp_dsc_chunk_size_read(struct file *f, char __user *buf,
1906 				    size_t size, loff_t *pos)
1907 {
1908 	char *rd_buf = NULL;
1909 	char *rd_buf_ptr = NULL;
1910 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1911 	struct display_stream_compressor *dsc;
1912 	struct dcn_dsc_state dsc_state = {0};
1913 	const uint32_t rd_buf_size = 100;
1914 	struct pipe_ctx *pipe_ctx;
1915 	ssize_t result = 0;
1916 	int i, r, str_len = 30;
1917 
1918 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1919 
1920 	if (!rd_buf)
1921 		return -ENOMEM;
1922 
1923 	rd_buf_ptr = rd_buf;
1924 
1925 	for (i = 0; i < MAX_PIPES; i++) {
1926 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1927 			if (pipe_ctx && pipe_ctx->stream &&
1928 			    pipe_ctx->stream->link == aconnector->dc_link)
1929 				break;
1930 	}
1931 
1932 	if (!pipe_ctx)
1933 		return -ENXIO;
1934 
1935 	dsc = pipe_ctx->stream_res.dsc;
1936 	if (dsc)
1937 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
1938 
1939 	snprintf(rd_buf_ptr, str_len,
1940 		"%d\n",
1941 		dsc_state.dsc_chunk_size);
1942 	rd_buf_ptr += str_len;
1943 
1944 	while (size) {
1945 		if (*pos >= rd_buf_size)
1946 			break;
1947 
1948 		r = put_user(*(rd_buf + result), buf);
1949 		if (r)
1950 			return r; /* r = -EFAULT */
1951 
1952 		buf += 1;
1953 		size -= 1;
1954 		*pos += 1;
1955 		result += 1;
1956 	}
1957 
1958 	kfree(rd_buf);
1959 	return result;
1960 }
1961 
1962 /* function: read DSC slice bpg offset on the connector
1963  *
1964  * The read function: dp_dsc_slice_bpg_offset_read
1965  * returns dsc bpg slice offset set in the current configuration
1966  * The value is calculated automatically by DSC code
1967  * and depends on slice parameters and bpp target rate
1968  * The return is an integer: 0 or other positive integer
1969  * If 0 then DSC is disabled.
1970  *
1971  * Access it with the following command:
1972  *
1973  *	cat /sys/kernel/debug/dri/0/DP-X/dsc_slice_bpg_offset
1974  *
1975  * 0 - means that DSC is disabled
1976  */
dp_dsc_slice_bpg_offset_read(struct file * f,char __user * buf,size_t size,loff_t * pos)1977 static ssize_t dp_dsc_slice_bpg_offset_read(struct file *f, char __user *buf,
1978 				    size_t size, loff_t *pos)
1979 {
1980 	char *rd_buf = NULL;
1981 	char *rd_buf_ptr = NULL;
1982 	struct amdgpu_dm_connector *aconnector = file_inode(f)->i_private;
1983 	struct display_stream_compressor *dsc;
1984 	struct dcn_dsc_state dsc_state = {0};
1985 	const uint32_t rd_buf_size = 100;
1986 	struct pipe_ctx *pipe_ctx;
1987 	ssize_t result = 0;
1988 	int i, r, str_len = 30;
1989 
1990 	rd_buf = kcalloc(rd_buf_size, sizeof(char), GFP_KERNEL);
1991 
1992 	if (!rd_buf)
1993 		return -ENOMEM;
1994 
1995 	rd_buf_ptr = rd_buf;
1996 
1997 	for (i = 0; i < MAX_PIPES; i++) {
1998 		pipe_ctx = &aconnector->dc_link->dc->current_state->res_ctx.pipe_ctx[i];
1999 			if (pipe_ctx && pipe_ctx->stream &&
2000 			    pipe_ctx->stream->link == aconnector->dc_link)
2001 				break;
2002 	}
2003 
2004 	if (!pipe_ctx)
2005 		return -ENXIO;
2006 
2007 	dsc = pipe_ctx->stream_res.dsc;
2008 	if (dsc)
2009 		dsc->funcs->dsc_read_state(dsc, &dsc_state);
2010 
2011 	snprintf(rd_buf_ptr, str_len,
2012 		"%d\n",
2013 		dsc_state.dsc_slice_bpg_offset);
2014 	rd_buf_ptr += str_len;
2015 
2016 	while (size) {
2017 		if (*pos >= rd_buf_size)
2018 			break;
2019 
2020 		r = put_user(*(rd_buf + result), buf);
2021 		if (r)
2022 			return r; /* r = -EFAULT */
2023 
2024 		buf += 1;
2025 		size -= 1;
2026 		*pos += 1;
2027 		result += 1;
2028 	}
2029 
2030 	kfree(rd_buf);
2031 	return result;
2032 }
2033 
2034 DEFINE_SHOW_ATTRIBUTE(dp_dsc_fec_support);
2035 DEFINE_SHOW_ATTRIBUTE(dmub_fw_state);
2036 DEFINE_SHOW_ATTRIBUTE(dmub_tracebuffer);
2037 DEFINE_SHOW_ATTRIBUTE(output_bpc);
2038 #ifdef CONFIG_DRM_AMD_DC_HDCP
2039 DEFINE_SHOW_ATTRIBUTE(hdcp_sink_capability);
2040 #endif
2041 
2042 static const struct file_operations dp_dsc_clock_en_debugfs_fops = {
2043 	.owner = THIS_MODULE,
2044 	.read = dp_dsc_clock_en_read,
2045 	.write = dp_dsc_clock_en_write,
2046 	.llseek = default_llseek
2047 };
2048 
2049 static const struct file_operations dp_dsc_slice_width_debugfs_fops = {
2050 	.owner = THIS_MODULE,
2051 	.read = dp_dsc_slice_width_read,
2052 	.write = dp_dsc_slice_width_write,
2053 	.llseek = default_llseek
2054 };
2055 
2056 static const struct file_operations dp_dsc_slice_height_debugfs_fops = {
2057 	.owner = THIS_MODULE,
2058 	.read = dp_dsc_slice_height_read,
2059 	.write = dp_dsc_slice_height_write,
2060 	.llseek = default_llseek
2061 };
2062 
2063 static const struct file_operations dp_dsc_bits_per_pixel_debugfs_fops = {
2064 	.owner = THIS_MODULE,
2065 	.read = dp_dsc_bits_per_pixel_read,
2066 	.write = dp_dsc_bits_per_pixel_write,
2067 	.llseek = default_llseek
2068 };
2069 
2070 static const struct file_operations dp_dsc_pic_width_debugfs_fops = {
2071 	.owner = THIS_MODULE,
2072 	.read = dp_dsc_pic_width_read,
2073 	.llseek = default_llseek
2074 };
2075 
2076 static const struct file_operations dp_dsc_pic_height_debugfs_fops = {
2077 	.owner = THIS_MODULE,
2078 	.read = dp_dsc_pic_height_read,
2079 	.llseek = default_llseek
2080 };
2081 
2082 static const struct file_operations dp_dsc_chunk_size_debugfs_fops = {
2083 	.owner = THIS_MODULE,
2084 	.read = dp_dsc_chunk_size_read,
2085 	.llseek = default_llseek
2086 };
2087 
2088 static const struct file_operations dp_dsc_slice_bpg_offset_debugfs_fops = {
2089 	.owner = THIS_MODULE,
2090 	.read = dp_dsc_slice_bpg_offset_read,
2091 	.llseek = default_llseek
2092 };
2093 
2094 static const struct file_operations dp_trigger_hotplug_debugfs_fops = {
2095 	.owner = THIS_MODULE,
2096 	.write = dp_trigger_hotplug,
2097 	.llseek = default_llseek
2098 };
2099 
2100 static const struct file_operations dp_link_settings_debugfs_fops = {
2101 	.owner = THIS_MODULE,
2102 	.read = dp_link_settings_read,
2103 	.write = dp_link_settings_write,
2104 	.llseek = default_llseek
2105 };
2106 
2107 static const struct file_operations dp_phy_settings_debugfs_fop = {
2108 	.owner = THIS_MODULE,
2109 	.read = dp_phy_settings_read,
2110 	.write = dp_phy_settings_write,
2111 	.llseek = default_llseek
2112 };
2113 
2114 static const struct file_operations dp_phy_test_pattern_fops = {
2115 	.owner = THIS_MODULE,
2116 	.write = dp_phy_test_pattern_debugfs_write,
2117 	.llseek = default_llseek
2118 };
2119 
2120 static const struct file_operations sdp_message_fops = {
2121 	.owner = THIS_MODULE,
2122 	.write = dp_sdp_message_debugfs_write,
2123 	.llseek = default_llseek
2124 };
2125 
2126 static const struct file_operations dp_dpcd_address_debugfs_fops = {
2127 	.owner = THIS_MODULE,
2128 	.write = dp_dpcd_address_write,
2129 	.llseek = default_llseek
2130 };
2131 
2132 static const struct file_operations dp_dpcd_size_debugfs_fops = {
2133 	.owner = THIS_MODULE,
2134 	.write = dp_dpcd_size_write,
2135 	.llseek = default_llseek
2136 };
2137 
2138 static const struct file_operations dp_dpcd_data_debugfs_fops = {
2139 	.owner = THIS_MODULE,
2140 	.read = dp_dpcd_data_read,
2141 	.write = dp_dpcd_data_write,
2142 	.llseek = default_llseek
2143 };
2144 
2145 static const struct {
2146 	char *name;
2147 	const struct file_operations *fops;
2148 } dp_debugfs_entries[] = {
2149 		{"link_settings", &dp_link_settings_debugfs_fops},
2150 		{"trigger_hotplug", &dp_trigger_hotplug_debugfs_fops},
2151 		{"phy_settings", &dp_phy_settings_debugfs_fop},
2152 		{"test_pattern", &dp_phy_test_pattern_fops},
2153 #ifdef CONFIG_DRM_AMD_DC_HDCP
2154 		{"hdcp_sink_capability", &hdcp_sink_capability_fops},
2155 #endif
2156 		{"sdp_message", &sdp_message_fops},
2157 		{"aux_dpcd_address", &dp_dpcd_address_debugfs_fops},
2158 		{"aux_dpcd_size", &dp_dpcd_size_debugfs_fops},
2159 		{"aux_dpcd_data", &dp_dpcd_data_debugfs_fops},
2160 		{"dsc_clock_en", &dp_dsc_clock_en_debugfs_fops},
2161 		{"dsc_slice_width", &dp_dsc_slice_width_debugfs_fops},
2162 		{"dsc_slice_height", &dp_dsc_slice_height_debugfs_fops},
2163 		{"dsc_bits_per_pixel", &dp_dsc_bits_per_pixel_debugfs_fops},
2164 		{"dsc_pic_width", &dp_dsc_pic_width_debugfs_fops},
2165 		{"dsc_pic_height", &dp_dsc_pic_height_debugfs_fops},
2166 		{"dsc_chunk_size", &dp_dsc_chunk_size_debugfs_fops},
2167 		{"dsc_slice_bpg", &dp_dsc_slice_bpg_offset_debugfs_fops},
2168 		{"dp_dsc_fec_support", &dp_dsc_fec_support_fops}
2169 };
2170 
2171 #ifdef CONFIG_DRM_AMD_DC_HDCP
2172 static const struct {
2173 	char *name;
2174 	const struct file_operations *fops;
2175 } hdmi_debugfs_entries[] = {
2176 		{"hdcp_sink_capability", &hdcp_sink_capability_fops}
2177 };
2178 #endif
2179 /*
2180  * Force YUV420 output if available from the given mode
2181  */
force_yuv420_output_set(void * data,u64 val)2182 static int force_yuv420_output_set(void *data, u64 val)
2183 {
2184 	struct amdgpu_dm_connector *connector = data;
2185 
2186 	connector->force_yuv420_output = (bool)val;
2187 
2188 	return 0;
2189 }
2190 
2191 /*
2192  * Check if YUV420 is forced when available from the given mode
2193  */
force_yuv420_output_get(void * data,u64 * val)2194 static int force_yuv420_output_get(void *data, u64 *val)
2195 {
2196 	struct amdgpu_dm_connector *connector = data;
2197 
2198 	*val = connector->force_yuv420_output;
2199 
2200 	return 0;
2201 }
2202 
2203 DEFINE_DEBUGFS_ATTRIBUTE(force_yuv420_output_fops, force_yuv420_output_get,
2204 			 force_yuv420_output_set, "%llu\n");
2205 
2206 /*
2207  *  Read PSR state
2208  */
psr_get(void * data,u64 * val)2209 static int psr_get(void *data, u64 *val)
2210 {
2211 	struct amdgpu_dm_connector *connector = data;
2212 	struct dc_link *link = connector->dc_link;
2213 	uint32_t psr_state = 0;
2214 
2215 	dc_link_get_psr_state(link, &psr_state);
2216 
2217 	*val = psr_state;
2218 
2219 	return 0;
2220 }
2221 
2222 
2223 DEFINE_DEBUGFS_ATTRIBUTE(psr_fops, psr_get, NULL, "%llu\n");
2224 
connector_debugfs_init(struct amdgpu_dm_connector * connector)2225 void connector_debugfs_init(struct amdgpu_dm_connector *connector)
2226 {
2227 	int i;
2228 	struct dentry *dir = connector->base.debugfs_entry;
2229 
2230 	if (connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
2231 	    connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) {
2232 		for (i = 0; i < ARRAY_SIZE(dp_debugfs_entries); i++) {
2233 			debugfs_create_file(dp_debugfs_entries[i].name,
2234 					    0644, dir, connector,
2235 					    dp_debugfs_entries[i].fops);
2236 		}
2237 	}
2238 	if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
2239 		debugfs_create_file_unsafe("psr_state", 0444, dir, connector, &psr_fops);
2240 
2241 	debugfs_create_file_unsafe("force_yuv420_output", 0644, dir, connector,
2242 				   &force_yuv420_output_fops);
2243 
2244 	debugfs_create_file("output_bpc", 0644, dir, connector,
2245 			    &output_bpc_fops);
2246 
2247 	connector->debugfs_dpcd_address = 0;
2248 	connector->debugfs_dpcd_size = 0;
2249 
2250 #ifdef CONFIG_DRM_AMD_DC_HDCP
2251 	if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) {
2252 		for (i = 0; i < ARRAY_SIZE(hdmi_debugfs_entries); i++) {
2253 			debugfs_create_file(hdmi_debugfs_entries[i].name,
2254 					    0644, dir, connector,
2255 					    hdmi_debugfs_entries[i].fops);
2256 		}
2257 	}
2258 #endif
2259 }
2260 
2261 /*
2262  * Writes DTN log state to the user supplied buffer.
2263  * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
2264  */
dtn_log_read(struct file * f,char __user * buf,size_t size,loff_t * pos)2265 static ssize_t dtn_log_read(
2266 	struct file *f,
2267 	char __user *buf,
2268 	size_t size,
2269 	loff_t *pos)
2270 {
2271 	struct amdgpu_device *adev = file_inode(f)->i_private;
2272 	struct dc *dc = adev->dm.dc;
2273 	struct dc_log_buffer_ctx log_ctx = { 0 };
2274 	ssize_t result = 0;
2275 
2276 	if (!buf || !size)
2277 		return -EINVAL;
2278 
2279 	if (!dc->hwss.log_hw_state)
2280 		return 0;
2281 
2282 	dc->hwss.log_hw_state(dc, &log_ctx);
2283 
2284 	if (*pos < log_ctx.pos) {
2285 		size_t to_copy = log_ctx.pos - *pos;
2286 
2287 		to_copy = min(to_copy, size);
2288 
2289 		if (!copy_to_user(buf, log_ctx.buf + *pos, to_copy)) {
2290 			*pos += to_copy;
2291 			result = to_copy;
2292 		}
2293 	}
2294 
2295 	kfree(log_ctx.buf);
2296 
2297 	return result;
2298 }
2299 
2300 /*
2301  * Writes DTN log state to dmesg when triggered via a write.
2302  * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_dtn_log
2303  */
dtn_log_write(struct file * f,const char __user * buf,size_t size,loff_t * pos)2304 static ssize_t dtn_log_write(
2305 	struct file *f,
2306 	const char __user *buf,
2307 	size_t size,
2308 	loff_t *pos)
2309 {
2310 	struct amdgpu_device *adev = file_inode(f)->i_private;
2311 	struct dc *dc = adev->dm.dc;
2312 
2313 	/* Write triggers log output via dmesg. */
2314 	if (size == 0)
2315 		return 0;
2316 
2317 	if (dc->hwss.log_hw_state)
2318 		dc->hwss.log_hw_state(dc, NULL);
2319 
2320 	return size;
2321 }
2322 
2323 /*
2324  * Backlight at this moment.  Read only.
2325  * As written to display, taking ABM and backlight lut into account.
2326  * Ranges from 0x0 to 0x10000 (= 100% PWM)
2327  */
current_backlight_read(struct seq_file * m,void * data)2328 static int current_backlight_read(struct seq_file *m, void *data)
2329 {
2330 	struct drm_info_node *node = (struct drm_info_node *)m->private;
2331 	struct drm_device *dev = node->minor->dev;
2332 	struct amdgpu_device *adev = drm_to_adev(dev);
2333 	struct amdgpu_display_manager *dm = &adev->dm;
2334 
2335 	unsigned int backlight = dc_link_get_backlight_level(dm->backlight_link);
2336 
2337 	seq_printf(m, "0x%x\n", backlight);
2338 	return 0;
2339 }
2340 
2341 /*
2342  * Backlight value that is being approached.  Read only.
2343  * As written to display, taking ABM and backlight lut into account.
2344  * Ranges from 0x0 to 0x10000 (= 100% PWM)
2345  */
target_backlight_read(struct seq_file * m,void * data)2346 static int target_backlight_read(struct seq_file *m, void *data)
2347 {
2348 	struct drm_info_node *node = (struct drm_info_node *)m->private;
2349 	struct drm_device *dev = node->minor->dev;
2350 	struct amdgpu_device *adev = drm_to_adev(dev);
2351 	struct amdgpu_display_manager *dm = &adev->dm;
2352 
2353 	unsigned int backlight = dc_link_get_target_backlight_pwm(dm->backlight_link);
2354 
2355 	seq_printf(m, "0x%x\n", backlight);
2356 	return 0;
2357 }
2358 
mst_topo(struct seq_file * m,void * unused)2359 static int mst_topo(struct seq_file *m, void *unused)
2360 {
2361 	struct drm_info_node *node = (struct drm_info_node *)m->private;
2362 	struct drm_device *dev = node->minor->dev;
2363 	struct drm_connector *connector;
2364 	struct drm_connector_list_iter conn_iter;
2365 	struct amdgpu_dm_connector *aconnector;
2366 
2367 	drm_connector_list_iter_begin(dev, &conn_iter);
2368 	drm_for_each_connector_iter(connector, &conn_iter) {
2369 		if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2370 			continue;
2371 
2372 		aconnector = to_amdgpu_dm_connector(connector);
2373 
2374 		seq_printf(m, "\nMST topology for connector %d\n", aconnector->connector_id);
2375 		drm_dp_mst_dump_topology(m, &aconnector->mst_mgr);
2376 	}
2377 	drm_connector_list_iter_end(&conn_iter);
2378 
2379 	return 0;
2380 }
2381 
2382 static const struct drm_info_list amdgpu_dm_debugfs_list[] = {
2383 	{"amdgpu_current_backlight_pwm", &current_backlight_read},
2384 	{"amdgpu_target_backlight_pwm", &target_backlight_read},
2385 	{"amdgpu_mst_topology", &mst_topo},
2386 };
2387 
2388 /*
2389  * Sets the force_timing_sync debug optino from the given string.
2390  * All connected displays will be force synchronized immediately.
2391  * Usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
2392  */
force_timing_sync_set(void * data,u64 val)2393 static int force_timing_sync_set(void *data, u64 val)
2394 {
2395 	struct amdgpu_device *adev = data;
2396 
2397 	adev->dm.force_timing_sync = (bool)val;
2398 
2399 	amdgpu_dm_trigger_timing_sync(adev_to_drm(adev));
2400 
2401 	return 0;
2402 }
2403 
2404 /*
2405  * Gets the force_timing_sync debug option value into the given buffer.
2406  * Usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_force_timing_sync
2407  */
force_timing_sync_get(void * data,u64 * val)2408 static int force_timing_sync_get(void *data, u64 *val)
2409 {
2410 	struct amdgpu_device *adev = data;
2411 
2412 	*val = adev->dm.force_timing_sync;
2413 
2414 	return 0;
2415 }
2416 
2417 DEFINE_DEBUGFS_ATTRIBUTE(force_timing_sync_ops, force_timing_sync_get,
2418 			 force_timing_sync_set, "%llu\n");
2419 
2420 /*
2421  * Sets the DC visual confirm debug option from the given string.
2422  * Example usage: echo 1 > /sys/kernel/debug/dri/0/amdgpu_visual_confirm
2423  */
visual_confirm_set(void * data,u64 val)2424 static int visual_confirm_set(void *data, u64 val)
2425 {
2426 	struct amdgpu_device *adev = data;
2427 
2428 	adev->dm.dc->debug.visual_confirm = (enum visual_confirm)val;
2429 
2430 	return 0;
2431 }
2432 
2433 /*
2434  * Reads the DC visual confirm debug option value into the given buffer.
2435  * Example usage: cat /sys/kernel/debug/dri/0/amdgpu_dm_visual_confirm
2436  */
visual_confirm_get(void * data,u64 * val)2437 static int visual_confirm_get(void *data, u64 *val)
2438 {
2439 	struct amdgpu_device *adev = data;
2440 
2441 	*val = adev->dm.dc->debug.visual_confirm;
2442 
2443 	return 0;
2444 }
2445 
2446 DEFINE_DEBUGFS_ATTRIBUTE(visual_confirm_fops, visual_confirm_get,
2447 			 visual_confirm_set, "%llu\n");
2448 
dtn_debugfs_init(struct amdgpu_device * adev)2449 int dtn_debugfs_init(struct amdgpu_device *adev)
2450 {
2451 	static const struct file_operations dtn_log_fops = {
2452 		.owner = THIS_MODULE,
2453 		.read = dtn_log_read,
2454 		.write = dtn_log_write,
2455 		.llseek = default_llseek
2456 	};
2457 
2458 	struct drm_minor *minor = adev_to_drm(adev)->primary;
2459 	struct dentry *root = minor->debugfs_root;
2460 	int ret;
2461 
2462 	ret = amdgpu_debugfs_add_files(adev, amdgpu_dm_debugfs_list,
2463 				ARRAY_SIZE(amdgpu_dm_debugfs_list));
2464 	if (ret)
2465 		return ret;
2466 
2467 	debugfs_create_file("amdgpu_dm_dtn_log", 0644, root, adev,
2468 			    &dtn_log_fops);
2469 
2470 	debugfs_create_file_unsafe("amdgpu_dm_visual_confirm", 0644, root, adev,
2471 				   &visual_confirm_fops);
2472 
2473 	debugfs_create_file_unsafe("amdgpu_dm_dmub_tracebuffer", 0644, root,
2474 				   adev, &dmub_tracebuffer_fops);
2475 
2476 	debugfs_create_file_unsafe("amdgpu_dm_dmub_fw_state", 0644, root,
2477 				   adev, &dmub_fw_state_fops);
2478 
2479 	debugfs_create_file_unsafe("amdgpu_dm_force_timing_sync", 0644, root,
2480 				   adev, &force_timing_sync_ops);
2481 
2482 	return 0;
2483 }
2484