xref: /linux/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h (revision 0a62732e53d7e295e1733a2d9bf661e593d86675)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright (C) 2015-2020 Advanced Micro Devices, Inc. All rights reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: AMD
24  *
25  */
26 
27 #ifndef __AMDGPU_DM_H__
28 #define __AMDGPU_DM_H__
29 
30 #include <drm/display/drm_dp_mst_helper.h>
31 #include <drm/drm_atomic.h>
32 #include <drm/drm_connector.h>
33 #include <drm/drm_crtc.h>
34 #include <drm/drm_plane.h>
35 #include "link_service_types.h"
36 #include <drm/drm_writeback.h>
37 
38 /*
39  * This file contains the definition for amdgpu_display_manager
40  * and its API for amdgpu driver's use.
41  * This component provides all the display related functionality
42  * and this is the only component that calls DAL API.
43  * The API contained here intended for amdgpu driver use.
44  * The API that is called directly from KMS framework is located
45  * in amdgpu_dm_kms.h file
46  */
47 
48 #define AMDGPU_DM_MAX_DISPLAY_INDEX 31
49 
50 #define AMDGPU_DM_MAX_CRTC 6
51 
52 #define AMDGPU_DM_MAX_NUM_EDP 2
53 
54 #define AMDGPU_DMUB_NOTIFICATION_MAX 8
55 
56 #define HDMI_AMD_VENDOR_SPECIFIC_DATA_BLOCK_IEEE_REGISTRATION_ID 0x00001A
57 #define AMD_VSDB_VERSION_3_FEATURECAP_REPLAYMODE 0x40
58 #define AMD_VDSB_VERSION_3_PANEL_TYPE_MASK 0xC0
59 #define AMD_VDSB_VERSION_3_PANEL_TYPE_SHIFT 6
60 #define HDMI_AMD_VENDOR_SPECIFIC_DATA_BLOCK_VERSION_3 0x3
61 
62 enum amd_vsdb_panel_type {
63 	AMD_VSDB_PANEL_TYPE_DEFAULT = 0,
64 	AMD_VSDB_PANEL_TYPE_MINILED,
65 	AMD_VSDB_PANEL_TYPE_OLED,
66 	AMD_VSDB_PANEL_TYPE_RESERVED,
67 };
68 
69 #define AMDGPU_HDR_MULT_DEFAULT (0x100000000LL)
70 
71 /*
72  * Maximum HDMI HPD debounce delay in milliseconds
73  */
74 #define AMDGPU_DM_MAX_HDMI_HPD_DEBOUNCE_MS 5000
75 /*
76 #include "include/amdgpu_dal_power_if.h"
77 #include "amdgpu_dm_irq.h"
78 */
79 
80 #include "irq_types.h"
81 #include "signal_types.h"
82 #include "amdgpu_dm_crc.h"
83 #include "mod_info_packet.h"
84 struct aux_payload;
85 struct set_config_cmd_payload;
86 enum aux_return_code_type;
87 enum set_config_status;
88 
89 /* Forward declarations */
90 struct amdgpu_device;
91 struct amdgpu_crtc;
92 struct drm_device;
93 struct dc;
94 struct amdgpu_bo;
95 struct dmub_srv;
96 struct dc_plane_state;
97 struct dmub_notification;
98 struct dmub_cmd_fused_request;
99 
100 struct amd_vsdb_block {
101 	unsigned char ieee_id[3];
102 	unsigned char version;
103 	unsigned char feature_caps;
104 	unsigned char reserved[3];
105 	unsigned char color_space_eotf_support;
106 };
107 
108 struct common_irq_params {
109 	struct amdgpu_device *adev;
110 	enum dc_irq_source irq_src;
111 	atomic64_t previous_timestamp;
112 };
113 
114 /**
115  * struct dm_compressor_info - Buffer info used by frame buffer compression
116  * @cpu_addr: MMIO cpu addr
117  * @bo_ptr: Pointer to the buffer object
118  * @gpu_addr: MMIO gpu addr
119  */
120 struct dm_compressor_info {
121 	void *cpu_addr;
122 	struct amdgpu_bo *bo_ptr;
123 	uint64_t gpu_addr;
124 };
125 
126 typedef void (*dmub_notify_interrupt_callback_t)(struct amdgpu_device *adev, struct dmub_notification *notify);
127 
128 /**
129  * struct dmub_hpd_work - Handle time consuming work in low priority outbox IRQ
130  *
131  * @handle_hpd_work: Work to be executed in a separate thread to handle hpd_low_irq
132  * @dmub_notify:  notification for callback function
133  * @adev: amdgpu_device pointer
134  */
135 struct dmub_hpd_work {
136 	struct work_struct handle_hpd_work;
137 	struct dmub_notification *dmub_notify;
138 	struct amdgpu_device *adev;
139 };
140 
141 /**
142  * struct vblank_control_work - Work data for vblank control
143  * @work: Kernel work data for the work event
144  * @dm: amdgpu display manager device
145  * @acrtc: amdgpu CRTC instance for which the event has occurred
146  * @stream: DC stream for which the event has occurred
147  * @enable: true if enabling vblank
148  */
149 struct vblank_control_work {
150 	struct work_struct work;
151 	struct amdgpu_display_manager *dm;
152 	struct amdgpu_crtc *acrtc;
153 	struct dc_stream_state *stream;
154 	bool enable;
155 };
156 
157 /**
158  * struct idle_workqueue - Work data for periodic action in idle
159  * @work: Kernel work data for the work event
160  * @dm: amdgpu display manager device
161  * @enable: true if idle worker is enabled
162  * @running: true if idle worker is running
163  */
164 struct idle_workqueue {
165 	struct work_struct work;
166 	struct amdgpu_display_manager *dm;
167 	bool enable;
168 	bool running;
169 };
170 
171 /**
172  * struct vupdate_offload_work - Work data for offloading task from vupdate handler
173  * @work: Kernel work data for the work event
174  * @adev: amdgpu_device back pointer
175  * @stream: DC stream associated with the crtc
176  * @adjust: DC CRTC timing adjust to be applied to the crtc
177  */
178 struct vupdate_offload_work {
179 	struct work_struct work;
180 	struct amdgpu_device *adev;
181 	struct dc_stream_state *stream;
182 	struct dc_crtc_timing_adjust *adjust;
183 };
184 
185 #define MAX_LUMINANCE_DATA_POINTS 99
186 
187 /**
188  * struct amdgpu_dm_luminance_data - Custom luminance data
189  * @luminance: Luminance in percent
190  * @input_signal: Input signal in range 0-255
191  */
192 struct amdgpu_dm_luminance_data {
193 	u8 luminance;
194 	u8 input_signal;
195 } __packed;
196 
197 /**
198  * struct amdgpu_dm_backlight_caps - Information about backlight
199  *
200  * Describe the backlight support for ACPI or eDP AUX.
201  */
202 struct amdgpu_dm_backlight_caps {
203 	/**
204 	 * @ext_caps: Keep the data struct with all the information about the
205 	 * display support for HDR.
206 	 */
207 	union dpcd_sink_ext_caps *ext_caps;
208 	/**
209 	 * @aux_min_input_signal: Min brightness value supported by the display
210 	 */
211 	u32 aux_min_input_signal;
212 	/**
213 	 * @aux_max_input_signal: Max brightness value supported by the display
214 	 * in nits.
215 	 */
216 	u32 aux_max_input_signal;
217 	/**
218 	 * @min_input_signal: minimum possible input in range 0-255.
219 	 */
220 	int min_input_signal;
221 	/**
222 	 * @max_input_signal: maximum possible input in range 0-255.
223 	 */
224 	int max_input_signal;
225 	/**
226 	 * @caps_valid: true if these values are from the ACPI interface.
227 	 */
228 	bool caps_valid;
229 	/**
230 	 * @aux_support: Describes if the display supports AUX backlight.
231 	 */
232 	bool aux_support;
233 	/**
234 	 * @brightness_mask: After deriving brightness, OR it with this mask.
235 	 * Workaround for panels with issues with certain brightness values.
236 	 */
237 	u32 brightness_mask;
238 	/**
239 	 * @ac_level: the default brightness if booted on AC
240 	 */
241 	u8 ac_level;
242 	/**
243 	 * @dc_level: the default brightness if booted on DC
244 	 */
245 	u8 dc_level;
246 	/**
247 	 * @data_points: the number of custom luminance data points
248 	 */
249 	u8 data_points;
250 	/**
251 	 * @luminance_data: custom luminance data
252 	 */
253 	struct amdgpu_dm_luminance_data luminance_data[MAX_LUMINANCE_DATA_POINTS];
254 };
255 
256 /**
257  * struct dal_allocation - Tracks mapped FB memory for SMU communication
258  * @list: list of dal allocations
259  * @bo: GPU buffer object
260  * @cpu_ptr: CPU virtual address of the GPU buffer object
261  * @gpu_addr: GPU virtual address of the GPU buffer object
262  */
263 struct dal_allocation {
264 	struct list_head list;
265 	struct amdgpu_bo *bo;
266 	void *cpu_ptr;
267 	u64 gpu_addr;
268 };
269 
270 /**
271  * struct hpd_rx_irq_offload_work_queue - Work queue to handle hpd_rx_irq
272  * offload work
273  */
274 struct hpd_rx_irq_offload_work_queue {
275 	/**
276 	 * @wq: workqueue structure to queue offload work.
277 	 */
278 	struct workqueue_struct *wq;
279 	/**
280 	 * @offload_lock: To protect fields of offload work queue.
281 	 */
282 	spinlock_t offload_lock;
283 	/**
284 	 * @is_handling_link_loss: Used to prevent inserting link loss event when
285 	 * we're handling link loss
286 	 */
287 	bool is_handling_link_loss;
288 	/**
289 	 * @is_handling_mst_msg_rdy_event: Used to prevent inserting mst message
290 	 * ready event when we're already handling mst message ready event
291 	 */
292 	bool is_handling_mst_msg_rdy_event;
293 	/**
294 	 * @aconnector: The aconnector that this work queue is attached to
295 	 */
296 	struct amdgpu_dm_connector *aconnector;
297 };
298 
299 /**
300  * struct hpd_rx_irq_offload_work - hpd_rx_irq offload work structure
301  */
302 struct hpd_rx_irq_offload_work {
303 	/**
304 	 * @work: offload work
305 	 */
306 	struct work_struct work;
307 	/**
308 	 * @data: reference irq data which is used while handling offload work
309 	 */
310 	union hpd_irq_data data;
311 	/**
312 	 * @offload_wq: offload work queue that this work is queued to
313 	 */
314 	struct hpd_rx_irq_offload_work_queue *offload_wq;
315 	/**
316 	 * @adev: amdgpu_device pointer
317 	 */
318 	struct amdgpu_device *adev;
319 };
320 
321 /**
322  * struct amdgpu_display_manager - Central amdgpu display manager device
323  *
324  * @dc: Display Core control structure
325  * @adev: AMDGPU base driver structure
326  * @ddev: DRM base driver structure
327  * @display_indexes_num: Max number of display streams supported
328  * @irq_handler_list_table_lock: Synchronizes access to IRQ tables
329  * @backlight_dev: Backlight control device
330  * @backlight_link: Link on which to control backlight
331  * @backlight_caps: Capabilities of the backlight device
332  * @freesync_module: Module handling freesync calculations
333  * @hdcp_workqueue: AMDGPU content protection queue
334  * @fw_dmcu: Reference to DMCU firmware
335  * @dmcu_fw_version: Version of the DMCU firmware
336  * @soc_bounding_box: SOC bounding box values provided by gpu_info FW
337  * @cached_state: Caches device atomic state for suspend/resume
338  * @cached_dc_state: Cached state of content streams
339  * @compressor: Frame buffer compression buffer. See &struct dm_compressor_info
340  * @force_timing_sync: set via debugfs. When set, indicates that all connected
341  *		       displays will be forced to synchronize.
342  * @dmcub_trace_event_en: enable dmcub trace events
343  * @dmub_outbox_params: DMUB Outbox parameters
344  * @num_of_edps: number of backlight eDPs
345  * @disable_hpd_irq: disables all HPD and HPD RX interrupt handling in the
346  *		     driver when true
347  * @dmub_aux_transfer_done: struct completion used to indicate when DMUB
348  * 			    transfers are done
349  * @delayed_hpd_wq: work queue used to delay DMUB HPD work
350  */
351 struct amdgpu_display_manager {
352 
353 	struct dc *dc;
354 
355 	/**
356 	 * @dmub_srv:
357 	 *
358 	 * DMUB service, used for controlling the DMUB on hardware
359 	 * that supports it. The pointer to the dmub_srv will be
360 	 * NULL on hardware that does not support it.
361 	 */
362 	struct dmub_srv *dmub_srv;
363 
364 	/**
365 	 * @dmub_notify:
366 	 *
367 	 * Notification from DMUB.
368 	 */
369 
370 	struct dmub_notification *dmub_notify;
371 
372 	/**
373 	 * @dmub_callback:
374 	 *
375 	 * Callback functions to handle notification from DMUB.
376 	 */
377 
378 	dmub_notify_interrupt_callback_t dmub_callback[AMDGPU_DMUB_NOTIFICATION_MAX];
379 
380 	/**
381 	 * @dmub_thread_offload:
382 	 *
383 	 * Flag to indicate if callback is offload.
384 	 */
385 
386 	bool dmub_thread_offload[AMDGPU_DMUB_NOTIFICATION_MAX];
387 
388 	/**
389 	 * @dmub_fb_info:
390 	 *
391 	 * Framebuffer regions for the DMUB.
392 	 */
393 	struct dmub_srv_fb_info *dmub_fb_info;
394 
395 	/**
396 	 * @dmub_fw:
397 	 *
398 	 * DMUB firmware, required on hardware that has DMUB support.
399 	 */
400 	const struct firmware *dmub_fw;
401 
402 	/**
403 	 * @dmub_bo:
404 	 *
405 	 * Buffer object for the DMUB.
406 	 */
407 	struct amdgpu_bo *dmub_bo;
408 
409 	/**
410 	 * @dmub_bo_gpu_addr:
411 	 *
412 	 * GPU virtual address for the DMUB buffer object.
413 	 */
414 	u64 dmub_bo_gpu_addr;
415 
416 	/**
417 	 * @dmub_bo_cpu_addr:
418 	 *
419 	 * CPU address for the DMUB buffer object.
420 	 */
421 	void *dmub_bo_cpu_addr;
422 
423 	/**
424 	 * @dmcub_fw_version:
425 	 *
426 	 * DMCUB firmware version.
427 	 */
428 	uint32_t dmcub_fw_version;
429 
430 	/**
431 	 * @fw_inst_size:
432 	 *
433 	 * Size of the firmware instruction buffer.
434 	 */
435 	uint32_t fw_inst_size;
436 
437 	/**
438 	 * @cgs_device:
439 	 *
440 	 * The Common Graphics Services device. It provides an interface for
441 	 * accessing registers.
442 	 */
443 	struct cgs_device *cgs_device;
444 
445 	struct amdgpu_device *adev;
446 	struct drm_device *ddev;
447 	u16 display_indexes_num;
448 
449 	/**
450 	 * @atomic_obj:
451 	 *
452 	 * In combination with &dm_atomic_state it helps manage
453 	 * global atomic state that doesn't map cleanly into existing
454 	 * drm resources, like &dc_context.
455 	 */
456 	struct drm_private_obj atomic_obj;
457 
458 	/**
459 	 * @dc_lock:
460 	 *
461 	 * Guards access to DC functions that can issue register write
462 	 * sequences.
463 	 */
464 	struct mutex dc_lock;
465 
466 	/**
467 	 * @audio_lock:
468 	 *
469 	 * Guards access to audio instance changes.
470 	 */
471 	struct mutex audio_lock;
472 
473 	/**
474 	 * @audio_component:
475 	 *
476 	 * Used to notify ELD changes to sound driver.
477 	 */
478 	struct drm_audio_component *audio_component;
479 
480 	/**
481 	 * @audio_registered:
482 	 *
483 	 * True if the audio component has been registered
484 	 * successfully, false otherwise.
485 	 */
486 	bool audio_registered;
487 
488 	/**
489 	 * @irq_handler_list_low_tab:
490 	 *
491 	 * Low priority IRQ handler table.
492 	 *
493 	 * It is a n*m table consisting of n IRQ sources, and m handlers per IRQ
494 	 * source. Low priority IRQ handlers are deferred to a workqueue to be
495 	 * processed. Hence, they can sleep.
496 	 *
497 	 * Note that handlers are called in the same order as they were
498 	 * registered (FIFO).
499 	 */
500 	struct list_head irq_handler_list_low_tab[DAL_IRQ_SOURCES_NUMBER];
501 
502 	/**
503 	 * @irq_handler_list_high_tab:
504 	 *
505 	 * High priority IRQ handler table.
506 	 *
507 	 * It is a n*m table, same as &irq_handler_list_low_tab. However,
508 	 * handlers in this table are not deferred and are called immediately.
509 	 */
510 	struct list_head irq_handler_list_high_tab[DAL_IRQ_SOURCES_NUMBER];
511 
512 	/**
513 	 * @pflip_params:
514 	 *
515 	 * Page flip IRQ parameters, passed to registered handlers when
516 	 * triggered.
517 	 */
518 	struct common_irq_params
519 	pflip_params[DC_IRQ_SOURCE_PFLIP_LAST - DC_IRQ_SOURCE_PFLIP_FIRST + 1];
520 
521 	/**
522 	 * @vblank_params:
523 	 *
524 	 * Vertical blanking IRQ parameters, passed to registered handlers when
525 	 * triggered.
526 	 */
527 	struct common_irq_params
528 	vblank_params[DC_IRQ_SOURCE_VBLANK6 - DC_IRQ_SOURCE_VBLANK1 + 1];
529 
530 	/**
531 	 * @vline0_params:
532 	 *
533 	 * OTG vertical interrupt0 IRQ parameters, passed to registered
534 	 * handlers when triggered.
535 	 */
536 	struct common_irq_params
537 	vline0_params[DC_IRQ_SOURCE_DC6_VLINE0 - DC_IRQ_SOURCE_DC1_VLINE0 + 1];
538 
539 	/**
540 	 * @vupdate_params:
541 	 *
542 	 * Vertical update IRQ parameters, passed to registered handlers when
543 	 * triggered.
544 	 */
545 	struct common_irq_params
546 	vupdate_params[DC_IRQ_SOURCE_VUPDATE6 - DC_IRQ_SOURCE_VUPDATE1 + 1];
547 
548 	/**
549 	 * @dmub_trace_params:
550 	 *
551 	 * DMUB trace event IRQ parameters, passed to registered handlers when
552 	 * triggered.
553 	 */
554 	struct common_irq_params
555 	dmub_trace_params[1];
556 
557 	struct common_irq_params
558 	dmub_outbox_params[1];
559 
560 	spinlock_t irq_handler_list_table_lock;
561 
562 	struct backlight_device *backlight_dev[AMDGPU_DM_MAX_NUM_EDP];
563 
564 	const struct dc_link *backlight_link[AMDGPU_DM_MAX_NUM_EDP];
565 
566 	uint8_t num_of_edps;
567 
568 	struct amdgpu_dm_backlight_caps backlight_caps[AMDGPU_DM_MAX_NUM_EDP];
569 
570 	struct mod_freesync *freesync_module;
571 	struct hdcp_workqueue *hdcp_workqueue;
572 
573 	/**
574 	 * @vblank_control_workqueue:
575 	 *
576 	 * Deferred work for vblank control events.
577 	 */
578 	struct workqueue_struct *vblank_control_workqueue;
579 
580 	/**
581 	 * @idle_workqueue:
582 	 *
583 	 * Periodic work for idle events.
584 	 */
585 	struct idle_workqueue *idle_workqueue;
586 
587 	struct drm_atomic_state *cached_state;
588 	struct dc_state *cached_dc_state;
589 
590 	struct dm_compressor_info compressor;
591 
592 	const struct firmware *fw_dmcu;
593 	uint32_t dmcu_fw_version;
594 	/**
595 	 * @soc_bounding_box:
596 	 *
597 	 * gpu_info FW provided soc bounding box struct or 0 if not
598 	 * available in FW
599 	 */
600 	const struct gpu_info_soc_bounding_box_v1_0 *soc_bounding_box;
601 
602 	/**
603 	 * @active_vblank_irq_count:
604 	 *
605 	 * number of currently active vblank irqs
606 	 */
607 	uint32_t active_vblank_irq_count;
608 
609 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
610 	/**
611 	 * @secure_display_ctx:
612 	 *
613 	 * Store secure display relevant info. e.g. the ROI information
614 	 * , the work_struct to command dmub, etc.
615 	 */
616 	struct secure_display_context secure_display_ctx;
617 #endif
618 	/**
619 	 * @hpd_rx_offload_wq:
620 	 *
621 	 * Work queue to offload works of hpd_rx_irq
622 	 */
623 	struct hpd_rx_irq_offload_work_queue *hpd_rx_offload_wq;
624 	/**
625 	 * @mst_encoders:
626 	 *
627 	 * fake encoders used for DP MST.
628 	 */
629 	struct amdgpu_encoder mst_encoders[AMDGPU_DM_MAX_CRTC];
630 	bool force_timing_sync;
631 	bool disable_hpd_irq;
632 	bool dmcub_trace_event_en;
633 	/**
634 	 * @da_list:
635 	 *
636 	 * DAL fb memory allocation list, for communication with SMU.
637 	 */
638 	struct list_head da_list;
639 	struct completion dmub_aux_transfer_done;
640 	struct workqueue_struct *delayed_hpd_wq;
641 
642 	/**
643 	 * @brightness:
644 	 *
645 	 * cached backlight values.
646 	 */
647 	u32 brightness[AMDGPU_DM_MAX_NUM_EDP];
648 	/**
649 	 * @actual_brightness:
650 	 *
651 	 * last successfully applied backlight values.
652 	 */
653 	u32 actual_brightness[AMDGPU_DM_MAX_NUM_EDP];
654 
655 	/**
656 	 * @aux_hpd_discon_quirk:
657 	 *
658 	 * quirk for hpd discon while aux is on-going.
659 	 * occurred on certain intel platform
660 	 */
661 	bool aux_hpd_discon_quirk;
662 
663 	/**
664 	 * @edp0_on_dp1_quirk:
665 	 *
666 	 * quirk for platforms that put edp0 on DP1.
667 	 */
668 	bool edp0_on_dp1_quirk;
669 
670 	/**
671 	 * @dpia_aux_lock:
672 	 *
673 	 * Guards access to DPIA AUX
674 	 */
675 	struct mutex dpia_aux_lock;
676 
677 	/**
678 	 * @bb_from_dmub:
679 	 *
680 	 * Bounding box data read from dmub during early initialization for DCN4+
681 	 * Data is stored as a byte array that should be casted to the appropriate bb struct
682 	 */
683 	void *bb_from_dmub;
684 
685 	/**
686 	 * @oem_i2c:
687 	 *
688 	 * OEM i2c bus
689 	 */
690 	struct amdgpu_i2c_adapter *oem_i2c;
691 
692 	/**
693 	 * @fused_io:
694 	 *
695 	 * dmub fused io interface
696 	 */
697 	struct fused_io_sync {
698 		struct completion replied;
699 		char reply_data[0x40];  // Cannot include dmub_cmd here
700 	} fused_io[8];
701 };
702 
703 enum dsc_clock_force_state {
704 	DSC_CLK_FORCE_DEFAULT = 0,
705 	DSC_CLK_FORCE_ENABLE,
706 	DSC_CLK_FORCE_DISABLE,
707 };
708 
709 struct dsc_preferred_settings {
710 	enum dsc_clock_force_state dsc_force_enable;
711 	uint32_t dsc_num_slices_v;
712 	uint32_t dsc_num_slices_h;
713 	uint32_t dsc_bits_per_pixel;
714 	bool dsc_force_disable_passthrough;
715 };
716 
717 enum mst_progress_status {
718 	MST_STATUS_DEFAULT = 0,
719 	MST_PROBE = BIT(0),
720 	MST_REMOTE_EDID = BIT(1),
721 	MST_ALLOCATE_NEW_PAYLOAD = BIT(2),
722 	MST_CLEAR_ALLOCATED_PAYLOAD = BIT(3),
723 };
724 
725 /**
726  * struct amdgpu_hdmi_vsdb_info - Keep track of the VSDB info
727  *
728  * AMDGPU supports FreeSync over HDMI by using the VSDB section, and this
729  * struct is useful to keep track of the display-specific information about
730  * FreeSync.
731  */
732 struct amdgpu_hdmi_vsdb_info {
733 	/**
734 	 * @amd_vsdb_version: Vendor Specific Data Block Version, should be
735 	 * used to determine which Vendor Specific InfoFrame (VSIF) to send.
736 	 */
737 	unsigned int amd_vsdb_version;
738 
739 	/**
740 	 * @freesync_supported: FreeSync Supported.
741 	 */
742 	bool freesync_supported;
743 
744 	/**
745 	 * @min_refresh_rate_hz: FreeSync Minimum Refresh Rate in Hz.
746 	 */
747 	unsigned int min_refresh_rate_hz;
748 
749 	/**
750 	 * @max_refresh_rate_hz: FreeSync Maximum Refresh Rate in Hz
751 	 */
752 	unsigned int max_refresh_rate_hz;
753 
754 	/**
755 	 * @replay_mode: Replay supported
756 	 */
757 	bool replay_mode;
758 };
759 
760 struct amdgpu_dm_connector {
761 
762 	struct drm_connector base;
763 	uint32_t connector_id;
764 	int bl_idx;
765 
766 	struct cec_notifier *notifier;
767 
768 	/* we need to mind the EDID between detect
769 	   and get modes due to analog/digital/tvencoder */
770 	const struct drm_edid *drm_edid;
771 
772 	/* shared with amdgpu */
773 	struct amdgpu_hpd hpd;
774 
775 	/* number of modes generated from EDID at 'dc_sink' */
776 	int num_modes;
777 
778 	/* The 'old' sink - before an HPD.
779 	 * The 'current' sink is in dc_link->sink. */
780 	struct dc_sink *dc_sink;
781 	struct dc_link *dc_link;
782 
783 	/**
784 	 * @dc_em_sink: Reference to the emulated (virtual) sink.
785 	 */
786 	struct dc_sink *dc_em_sink;
787 
788 	/* DM only */
789 	struct drm_dp_mst_topology_mgr mst_mgr;
790 	struct amdgpu_dm_dp_aux dm_dp_aux;
791 	struct drm_dp_mst_port *mst_output_port;
792 	struct amdgpu_dm_connector *mst_root;
793 	struct drm_dp_aux *dsc_aux;
794 	uint32_t mst_local_bw;
795 	uint16_t vc_full_pbn;
796 	struct mutex handle_mst_msg_ready;
797 
798 	/* branch device specific data */
799 	uint32_t branch_ieee_oui;
800 
801 	/* TODO see if we can merge with ddc_bus or make a dm_connector */
802 	struct amdgpu_i2c_adapter *i2c;
803 
804 	/* Monitor range limits */
805 	/**
806 	 * @min_vfreq: Minimal frequency supported by the display in Hz. This
807 	 * value is set to zero when there is no FreeSync support.
808 	 */
809 	int min_vfreq;
810 
811 	/**
812 	 * @max_vfreq: Maximum frequency supported by the display in Hz. This
813 	 * value is set to zero when there is no FreeSync support.
814 	 */
815 	int max_vfreq ;
816 
817 	/* Audio instance - protected by audio_lock. */
818 	int audio_inst;
819 
820 	struct mutex hpd_lock;
821 
822 	bool fake_enable;
823 	bool force_yuv420_output;
824 	bool force_yuv422_output;
825 	struct dsc_preferred_settings dsc_settings;
826 	union dp_downstream_port_present mst_downstream_port_present;
827 	/* Cached display modes */
828 	struct drm_display_mode freesync_vid_base;
829 
830 	int sr_skip_count;
831 	bool disallow_edp_enter_psr;
832 	bool disallow_edp_enter_replay;
833 
834 	/* Record progress status of mst*/
835 	uint8_t mst_status;
836 
837 	/* Automated testing */
838 	bool timing_changed;
839 	struct dc_crtc_timing *timing_requested;
840 
841 	/* Adaptive Sync */
842 	bool pack_sdp_v1_3;
843 	enum adaptive_sync_type as_type;
844 	struct amdgpu_hdmi_vsdb_info vsdb_info;
845 
846 	/* HDMI HPD debounce support */
847 	unsigned int hdmi_hpd_debounce_delay_ms;
848 	struct delayed_work hdmi_hpd_debounce_work;
849 	struct dc_sink *hdmi_prev_sink;
850 };
851 
852 static inline void amdgpu_dm_set_mst_status(uint8_t *status,
853 		uint8_t flags, bool set)
854 {
855 	if (set)
856 		*status |= flags;
857 	else
858 		*status &= ~flags;
859 }
860 
861 #define to_amdgpu_dm_connector(x) container_of(x, struct amdgpu_dm_connector, base)
862 
863 struct amdgpu_dm_wb_connector {
864 	struct drm_writeback_connector base;
865 	struct dc_link *link;
866 };
867 
868 #define to_amdgpu_dm_wb_connector(x) container_of(x, struct amdgpu_dm_wb_connector, base)
869 
870 extern const struct amdgpu_ip_block_version dm_ip_block;
871 
872 /* enum amdgpu_transfer_function: pre-defined transfer function supported by AMD.
873  *
874  * It includes standardized transfer functions and pure power functions. The
875  * transfer function coefficients are available at modules/color/color_gamma.c
876  */
877 enum amdgpu_transfer_function {
878 	AMDGPU_TRANSFER_FUNCTION_DEFAULT,
879 	AMDGPU_TRANSFER_FUNCTION_SRGB_EOTF,
880 	AMDGPU_TRANSFER_FUNCTION_BT709_INV_OETF,
881 	AMDGPU_TRANSFER_FUNCTION_PQ_EOTF,
882 	AMDGPU_TRANSFER_FUNCTION_IDENTITY,
883 	AMDGPU_TRANSFER_FUNCTION_GAMMA22_EOTF,
884 	AMDGPU_TRANSFER_FUNCTION_GAMMA24_EOTF,
885 	AMDGPU_TRANSFER_FUNCTION_GAMMA26_EOTF,
886 	AMDGPU_TRANSFER_FUNCTION_SRGB_INV_EOTF,
887 	AMDGPU_TRANSFER_FUNCTION_BT709_OETF,
888 	AMDGPU_TRANSFER_FUNCTION_PQ_INV_EOTF,
889 	AMDGPU_TRANSFER_FUNCTION_GAMMA22_INV_EOTF,
890 	AMDGPU_TRANSFER_FUNCTION_GAMMA24_INV_EOTF,
891 	AMDGPU_TRANSFER_FUNCTION_GAMMA26_INV_EOTF,
892 	AMDGPU_TRANSFER_FUNCTION_COUNT
893 };
894 
895 struct dm_plane_state {
896 	struct drm_plane_state base;
897 	struct dc_plane_state *dc_state;
898 
899 	/* Plane color mgmt */
900 	/**
901 	 * @degamma_lut:
902 	 *
903 	 * 1D LUT for mapping framebuffer/plane pixel data before sampling or
904 	 * blending operations. It's usually applied to linearize input space.
905 	 * The blob (if not NULL) is an array of &struct drm_color_lut.
906 	 */
907 	struct drm_property_blob *degamma_lut;
908 	/**
909 	 * @degamma_tf:
910 	 *
911 	 * Predefined transfer function to tell DC driver the input space to
912 	 * linearize.
913 	 */
914 	enum amdgpu_transfer_function degamma_tf;
915 	/**
916 	 * @hdr_mult:
917 	 *
918 	 * Multiplier to 'gain' the plane.  When PQ is decoded using the fixed
919 	 * func transfer function to the internal FP16 fb, 1.0 -> 80 nits (on
920 	 * AMD at least). When sRGB is decoded, 1.0 -> 1.0, obviously.
921 	 * Therefore, 1.0 multiplier = 80 nits for SDR content.  So if you
922 	 * want, 203 nits for SDR content, pass in (203.0 / 80.0).  Format is
923 	 * S31.32 sign-magnitude.
924 	 *
925 	 * HDR multiplier can wide range beyond [0.0, 1.0]. This means that PQ
926 	 * TF is needed for any subsequent linear-to-non-linear transforms.
927 	 */
928 	__u64 hdr_mult;
929 	/**
930 	 * @ctm:
931 	 *
932 	 * Color transformation matrix. The blob (if not NULL) is a &struct
933 	 * drm_color_ctm_3x4.
934 	 */
935 	struct drm_property_blob *ctm;
936 	/**
937 	 * @shaper_lut: shaper lookup table blob. The blob (if not NULL) is an
938 	 * array of &struct drm_color_lut.
939 	 */
940 	struct drm_property_blob *shaper_lut;
941 	/**
942 	 * @shaper_tf:
943 	 *
944 	 * Predefined transfer function to delinearize color space.
945 	 */
946 	enum amdgpu_transfer_function shaper_tf;
947 	/**
948 	 * @lut3d: 3D lookup table blob. The blob (if not NULL) is an array of
949 	 * &struct drm_color_lut.
950 	 */
951 	struct drm_property_blob *lut3d;
952 	/**
953 	 * @blend_lut: blend lut lookup table blob. The blob (if not NULL) is an
954 	 * array of &struct drm_color_lut.
955 	 */
956 	struct drm_property_blob *blend_lut;
957 	/**
958 	 * @blend_tf:
959 	 *
960 	 * Pre-defined transfer function for converting plane pixel data before
961 	 * applying blend LUT.
962 	 */
963 	enum amdgpu_transfer_function blend_tf;
964 };
965 
966 enum amdgpu_dm_cursor_mode {
967 	DM_CURSOR_NATIVE_MODE = 0,
968 	DM_CURSOR_OVERLAY_MODE,
969 };
970 
971 struct dm_crtc_state {
972 	struct drm_crtc_state base;
973 	struct dc_stream_state *stream;
974 
975 	bool cm_has_degamma;
976 	bool cm_is_degamma_srgb;
977 
978 	bool mpo_requested;
979 
980 	int update_type;
981 	int active_planes;
982 
983 	int crc_skip_count;
984 
985 	bool freesync_vrr_info_changed;
986 
987 	bool dsc_force_changed;
988 	bool vrr_supported;
989 	struct mod_freesync_config freesync_config;
990 	struct dc_info_packet vrr_infopacket;
991 
992 	int abm_level;
993 
994 	/**
995 	 * @regamma_tf:
996 	 *
997 	 * Pre-defined transfer function for converting internal FB -> wire
998 	 * encoding.
999 	 */
1000 	enum amdgpu_transfer_function regamma_tf;
1001 
1002 	enum amdgpu_dm_cursor_mode cursor_mode;
1003 };
1004 
1005 #define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base)
1006 
1007 struct dm_atomic_state {
1008 	struct drm_private_state base;
1009 
1010 	struct dc_state *context;
1011 };
1012 
1013 #define to_dm_atomic_state(x) container_of(x, struct dm_atomic_state, base)
1014 
1015 struct dm_connector_state {
1016 	struct drm_connector_state base;
1017 
1018 	enum amdgpu_rmx_type scaling;
1019 	uint8_t underscan_vborder;
1020 	uint8_t underscan_hborder;
1021 	bool underscan_enable;
1022 	bool freesync_capable;
1023 	bool update_hdcp;
1024 	bool abm_sysfs_forbidden;
1025 	uint8_t abm_level;
1026 	int vcpi_slots;
1027 	uint64_t pbn;
1028 };
1029 
1030 #define to_dm_connector_state(x)\
1031 	container_of((x), struct dm_connector_state, base)
1032 
1033 void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector);
1034 struct drm_connector_state *
1035 amdgpu_dm_connector_atomic_duplicate_state(struct drm_connector *connector);
1036 int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector,
1037 					    struct drm_connector_state *state,
1038 					    struct drm_property *property,
1039 					    uint64_t val);
1040 
1041 int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector,
1042 					    const struct drm_connector_state *state,
1043 					    struct drm_property *property,
1044 					    uint64_t *val);
1045 
1046 int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev);
1047 
1048 void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
1049 				     struct amdgpu_dm_connector *aconnector,
1050 				     int connector_type,
1051 				     struct dc_link *link,
1052 				     int link_index);
1053 
1054 enum drm_mode_status amdgpu_dm_connector_mode_valid(struct drm_connector *connector,
1055 				   const struct drm_display_mode *mode);
1056 
1057 void dm_restore_drm_connector_state(struct drm_device *dev,
1058 				    struct drm_connector *connector);
1059 
1060 void amdgpu_dm_update_freesync_caps(struct drm_connector *connector,
1061 				    const struct drm_edid *drm_edid);
1062 
1063 void amdgpu_dm_trigger_timing_sync(struct drm_device *dev);
1064 
1065 /* 3D LUT max size is 17x17x17 (4913 entries) */
1066 #define MAX_COLOR_3DLUT_SIZE 17
1067 #define MAX_COLOR_3DLUT_BITDEPTH 12
1068 int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev,
1069 				struct drm_plane_state *plane_state);
1070 /* 1D LUT size */
1071 #define MAX_COLOR_LUT_ENTRIES 4096
1072 /* Legacy gamm LUT users such as X doesn't like large LUT sizes */
1073 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256
1074 
1075 void amdgpu_dm_init_color_mod(void);
1076 int amdgpu_dm_create_color_properties(struct amdgpu_device *adev);
1077 int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state);
1078 int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc);
1079 int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state *crtc,
1080 				    bool check_only);
1081 int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
1082 				      struct drm_plane_state *plane_state,
1083 				      struct dc_plane_state *dc_plane_state);
1084 
1085 void amdgpu_dm_update_connector_after_detect(
1086 		struct amdgpu_dm_connector *aconnector);
1087 
1088 void populate_hdmi_info_from_connector(struct drm_hdmi_info *info,
1089 				      struct dc_edid_caps *edid_caps);
1090 
1091 extern const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs;
1092 
1093 int amdgpu_dm_process_dmub_aux_transfer_sync(struct dc_context *ctx, unsigned int link_index,
1094 					struct aux_payload *payload, enum aux_return_code_type *operation_result);
1095 
1096 bool amdgpu_dm_execute_fused_io(
1097 		struct amdgpu_device *dev,
1098 		struct dc_link *link,
1099 		union dmub_rb_cmd *commands,
1100 		uint8_t count,
1101 		uint32_t timeout_us
1102 );
1103 
1104 int amdgpu_dm_process_dmub_set_config_sync(struct dc_context *ctx, unsigned int link_index,
1105 					struct set_config_cmd_payload *payload, enum set_config_status *operation_result);
1106 
1107 struct dc_stream_state *
1108 	create_validate_stream_for_sink(struct drm_connector *connector,
1109 					const struct drm_display_mode *drm_mode,
1110 					const struct dm_connector_state *dm_state,
1111 					const struct dc_stream_state *old_stream);
1112 
1113 int dm_atomic_get_state(struct drm_atomic_state *state,
1114 			struct dm_atomic_state **dm_state);
1115 
1116 struct drm_connector *
1117 amdgpu_dm_find_first_crtc_matching_connector(struct drm_atomic_state *state,
1118 					     struct drm_crtc *crtc);
1119 
1120 int convert_dc_color_depth_into_bpc(enum dc_color_depth display_color_depth);
1121 struct idle_workqueue *idle_create_workqueue(struct amdgpu_device *adev);
1122 
1123 void *dm_allocate_gpu_mem(struct amdgpu_device *adev,
1124 						  enum dc_gpu_mem_alloc_type type,
1125 						  size_t size,
1126 						  long long *addr);
1127 void dm_free_gpu_mem(struct amdgpu_device *adev,
1128 						  enum dc_gpu_mem_alloc_type type,
1129 						  void *addr);
1130 
1131 bool amdgpu_dm_is_headless(struct amdgpu_device *adev);
1132 
1133 void hdmi_cec_set_edid(struct amdgpu_dm_connector *aconnector);
1134 void hdmi_cec_unset_edid(struct amdgpu_dm_connector *aconnector);
1135 int amdgpu_dm_initialize_hdmi_connector(struct amdgpu_dm_connector *aconnector);
1136 
1137 void retrieve_dmi_info(struct amdgpu_display_manager *dm);
1138 
1139 #endif /* __AMDGPU_DM_H__ */
1140