xref: /linux/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h (revision b0a3a811634aa7422f8a92196db47a06a70bda16)
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_CRTC 6
49 
50 #define AMDGPU_DM_MAX_NUM_EDP 2
51 
52 #define AMDGPU_DMUB_NOTIFICATION_MAX 8
53 
54 enum amd_vsdb_panel_type {
55 	AMD_VSDB_PANEL_TYPE_DEFAULT = 0,
56 	AMD_VSDB_PANEL_TYPE_MINILED,
57 	AMD_VSDB_PANEL_TYPE_OLED,
58 	AMD_VSDB_PANEL_TYPE_RESERVED,
59 };
60 
61 #define AMDGPU_HDR_MULT_DEFAULT (0x100000000LL)
62 
63 /*
64  * Maximum HDMI HPD debounce delay in milliseconds
65  */
66 #define AMDGPU_DM_MAX_HDMI_HPD_DEBOUNCE_MS 5000
67 /*
68 #include "include/amdgpu_dal_power_if.h"
69 #include "amdgpu_dm_irq.h"
70 */
71 
72 #include "irq_types.h"
73 #include "signal_types.h"
74 #include "amdgpu_dm_crc.h"
75 #include "mod_info_packet.h"
76 struct aux_payload;
77 struct set_config_cmd_payload;
78 enum aux_return_code_type;
79 enum set_config_status;
80 
81 /* Forward declarations */
82 struct amdgpu_device;
83 struct amdgpu_crtc;
84 struct drm_device;
85 struct dc;
86 struct amdgpu_bo;
87 struct dmub_srv;
88 struct dc_plane_state;
89 struct dc_stream_state;
90 struct dc_stream_update;
91 struct dc_surface_update;
92 struct dmub_notification;
93 struct dmub_cmd_fused_request;
94 
95 struct common_irq_params {
96 	struct amdgpu_device *adev;
97 	enum dc_irq_source irq_src;
98 	atomic64_t previous_timestamp;
99 };
100 
101 /**
102  * struct dm_compressor_info - Buffer info used by frame buffer compression
103  * @cpu_addr: MMIO cpu addr
104  * @bo_ptr: Pointer to the buffer object
105  * @gpu_addr: MMIO gpu addr
106  */
107 struct dm_compressor_info {
108 	void *cpu_addr;
109 	struct amdgpu_bo *bo_ptr;
110 	uint64_t gpu_addr;
111 };
112 
113 /**
114  * struct dm_boot_time_crc_info - Buffer info used by boot time CRC
115  * @cpu_addr: MMIO cpu addr
116  * @bo_ptr: Pointer to the buffer object
117  * @gpu_addr: MMIO gpu addr
118  * @size: Size of the buffer
119  */
120 struct dm_boot_time_crc_info {
121 	void *cpu_addr;
122 	struct amdgpu_bo *bo_ptr;
123 	uint64_t gpu_addr;
124 	uint32_t size;
125 };
126 
127 typedef void (*dmub_notify_interrupt_callback_t)(struct amdgpu_device *adev, struct dmub_notification *notify);
128 
129 /**
130  * struct dmub_hpd_work - Handle time consuming work in low priority outbox IRQ
131  *
132  * @handle_hpd_work: Work to be executed in a separate thread to handle hpd_low_irq
133  * @dmub_notify:  notification for callback function
134  * @adev: amdgpu_device pointer
135  */
136 struct dmub_hpd_work {
137 	struct work_struct handle_hpd_work;
138 	struct dmub_notification *dmub_notify;
139 	struct amdgpu_device *adev;
140 };
141 
142 /**
143  * struct vblank_control_work - Work data for vblank control
144  * @work: Kernel work data for the work event
145  * @dm: amdgpu display manager device
146  * @acrtc: amdgpu CRTC instance for which the event has occurred
147  * @stream: DC stream for which the event has occurred
148  * @enable: true if enabling vblank
149  */
150 struct vblank_control_work {
151 	struct work_struct work;
152 	struct amdgpu_display_manager *dm;
153 	struct amdgpu_crtc *acrtc;
154 	struct dc_stream_state *stream;
155 	bool enable;
156 };
157 
158 /**
159  * struct idle_workqueue - Work data for periodic action in idle
160  * @work: Kernel work data for the work event
161  * @dm: amdgpu display manager device
162  * @enable: true if idle worker is enabled
163  * @running: true if idle worker is running
164  */
165 struct idle_workqueue {
166 	struct work_struct work;
167 	struct amdgpu_display_manager *dm;
168 	bool enable;
169 	bool running;
170 };
171 
172 /**
173  * struct vupdate_offload_work - Work data for offloading task from vupdate handler
174  * @work: Kernel work data for the work event
175  * @adev: amdgpu_device back pointer
176  * @stream: DC stream associated with the crtc
177  * @adjust: DC CRTC timing adjust to be applied to the crtc
178  */
179 struct vupdate_offload_work {
180 	struct work_struct work;
181 	struct amdgpu_device *adev;
182 	struct dc_stream_state *stream;
183 	struct dc_crtc_timing_adjust *adjust;
184 };
185 
186 #define MAX_LUMINANCE_DATA_POINTS 99
187 
188 /**
189  * struct amdgpu_dm_luminance_data - Custom luminance data
190  * @luminance: Luminance in percent
191  * @input_signal: Input signal in range 0-255
192  */
193 struct amdgpu_dm_luminance_data {
194 	u8 luminance;
195 	u8 input_signal;
196 } __packed;
197 
198 /**
199  * struct amdgpu_dm_backlight_caps - Information about backlight
200  *
201  * Describe the backlight support for ACPI or eDP AUX.
202  */
203 struct amdgpu_dm_backlight_caps {
204 	/**
205 	 * @ext_caps: Keep the data struct with all the information about the
206 	 * display support for HDR.
207 	 */
208 	union dpcd_sink_ext_caps *ext_caps;
209 	/**
210 	 * @aux_min_input_signal: Min brightness value supported by the display
211 	 */
212 	u32 aux_min_input_signal;
213 	/**
214 	 * @aux_max_input_signal: Max brightness value supported by the display
215 	 * in nits.
216 	 */
217 	u32 aux_max_input_signal;
218 	/**
219 	 * @min_input_signal: minimum possible input in range 0-255.
220 	 */
221 	int min_input_signal;
222 	/**
223 	 * @max_input_signal: maximum possible input in range 0-255.
224 	 */
225 	int max_input_signal;
226 	/**
227 	 * @caps_valid: true if these values are from the ACPI interface.
228 	 */
229 	bool caps_valid;
230 	/**
231 	 * @aux_support: Describes if the display supports AUX backlight.
232 	 */
233 	bool aux_support;
234 	/**
235 	 * @brightness_mask: After deriving brightness, OR it with this mask.
236 	 * Workaround for panels with issues with certain brightness values.
237 	 */
238 	u32 brightness_mask;
239 	/**
240 	 * @ac_level: the default brightness if booted on AC
241 	 */
242 	u8 ac_level;
243 	/**
244 	 * @dc_level: the default brightness if booted on DC
245 	 */
246 	u8 dc_level;
247 	/**
248 	 * @data_points: the number of custom luminance data points
249 	 */
250 	u8 data_points;
251 	/**
252 	 * @luminance_data: custom luminance data
253 	 */
254 	struct amdgpu_dm_luminance_data luminance_data[MAX_LUMINANCE_DATA_POINTS];
255 };
256 
257 /**
258  * struct dal_allocation - Tracks mapped FB memory for SMU communication
259  * @list: list of dal allocations
260  * @bo: GPU buffer object
261  * @cpu_ptr: CPU virtual address of the GPU buffer object
262  * @gpu_addr: GPU virtual address of the GPU buffer object
263  */
264 struct dal_allocation {
265 	struct list_head list;
266 	struct amdgpu_bo *bo;
267 	void *cpu_ptr;
268 	u64 gpu_addr;
269 };
270 
271 /**
272  * struct hpd_rx_irq_offload_work_queue - Work queue to handle hpd_rx_irq
273  * offload work
274  */
275 struct hpd_rx_irq_offload_work_queue {
276 	/**
277 	 * @wq: workqueue structure to queue offload work.
278 	 */
279 	struct workqueue_struct *wq;
280 	/**
281 	 * @offload_lock: To protect fields of offload work queue.
282 	 */
283 	spinlock_t offload_lock;
284 	/**
285 	 * @is_handling_link_loss: Used to prevent inserting link loss event when
286 	 * we're handling link loss
287 	 */
288 	bool is_handling_link_loss;
289 	/**
290 	 * @is_handling_mst_msg_rdy_event: Used to prevent inserting mst message
291 	 * ready event when we're already handling mst message ready event
292 	 */
293 	bool is_handling_mst_msg_rdy_event;
294 	/**
295 	 * @aconnector: The aconnector that this work queue is attached to
296 	 */
297 	struct amdgpu_dm_connector *aconnector;
298 };
299 
300 /**
301  * struct hpd_rx_irq_offload_work - hpd_rx_irq offload work structure
302  */
303 struct hpd_rx_irq_offload_work {
304 	/**
305 	 * @work: offload work
306 	 */
307 	struct work_struct work;
308 	/**
309 	 * @data: reference irq data which is used while handling offload work
310 	 */
311 	union hpd_irq_data data;
312 	/**
313 	 * @offload_wq: offload work queue that this work is queued to
314 	 */
315 	struct hpd_rx_irq_offload_work_queue *offload_wq;
316 	/**
317 	 * @adev: amdgpu_device pointer
318 	 */
319 	struct amdgpu_device *adev;
320 };
321 
322 /**
323  * struct amdgpu_display_manager - Central amdgpu display manager device
324  *
325  * @dc: Display Core control structure
326  * @adev: AMDGPU base driver structure
327  * @ddev: DRM base driver structure
328  * @display_indexes_num: Max number of display streams supported
329  * @irq_handler_list_table_lock: Synchronizes access to IRQ tables
330  * @irq_wq: Dedicated high-priority unbound workqueue for deferred IRQ work
331  * @vmin_vmax_wq: Dedicated unbound workqueue for deferred vmin/vmax updates
332  * @backlight_dev: Backlight control device
333  * @backlight_link: Link on which to control backlight
334  * @backlight_caps: Capabilities of the backlight device
335  * @freesync_module: Module handling freesync calculations
336  * @power_module: Module handling power calculations
337  * @hdcp_workqueue: AMDGPU content protection queue
338  * @fw_dmcu: Reference to DMCU firmware
339  * @dmcu_fw_version: Version of the DMCU firmware
340  * @soc_bounding_box: SOC bounding box values provided by gpu_info FW
341  * @cached_state: Caches device atomic state for suspend/resume
342  * @cached_dc_state: Cached state of content streams
343  * @compressor: Frame buffer compression buffer. See &struct dm_compressor_info
344  * @force_timing_sync: set via debugfs. When set, indicates that all connected
345  *		       displays will be forced to synchronize.
346  * @dmcub_trace_event_en: enable dmcub trace events
347  * @dmub_outbox_params: DMUB Outbox parameters
348  * @num_of_edps: number of backlight eDPs
349  * @disable_hpd_irq: disables all HPD and HPD RX interrupt handling in the
350  *		     driver when true
351  * @dmub_aux_transfer_done: struct completion used to indicate when DMUB
352  * 			    transfers are done
353  * @delayed_hpd_wq: work queue used to delay DMUB HPD work
354  */
355 struct amdgpu_display_manager {
356 
357 	struct dc *dc;
358 
359 	/**
360 	 * @dmub_srv:
361 	 *
362 	 * DMUB service, used for controlling the DMUB on hardware
363 	 * that supports it. The pointer to the dmub_srv will be
364 	 * NULL on hardware that does not support it.
365 	 */
366 	struct dmub_srv *dmub_srv;
367 
368 	/**
369 	 * @dmub_notify:
370 	 *
371 	 * Notification from DMUB.
372 	 */
373 
374 	struct dmub_notification *dmub_notify;
375 
376 	/**
377 	 * @dmub_callback:
378 	 *
379 	 * Callback functions to handle notification from DMUB.
380 	 */
381 
382 	dmub_notify_interrupt_callback_t dmub_callback[AMDGPU_DMUB_NOTIFICATION_MAX];
383 
384 	/**
385 	 * @dmub_thread_offload:
386 	 *
387 	 * Flag to indicate if callback is offload.
388 	 */
389 
390 	bool dmub_thread_offload[AMDGPU_DMUB_NOTIFICATION_MAX];
391 
392 	/**
393 	 * @dmub_fb_info:
394 	 *
395 	 * Framebuffer regions for the DMUB.
396 	 */
397 	struct dmub_srv_fb_info *dmub_fb_info;
398 
399 	/**
400 	 * @dmub_fw:
401 	 *
402 	 * DMUB firmware, required on hardware that has DMUB support.
403 	 */
404 	const struct firmware *dmub_fw;
405 
406 	/**
407 	 * @dmub_bo:
408 	 *
409 	 * Buffer object for the DMUB.
410 	 */
411 	struct amdgpu_bo *dmub_bo;
412 
413 	/**
414 	 * @dmub_bo_gpu_addr:
415 	 *
416 	 * GPU virtual address for the DMUB buffer object.
417 	 */
418 	u64 dmub_bo_gpu_addr;
419 
420 	/**
421 	 * @dmub_bo_cpu_addr:
422 	 *
423 	 * CPU address for the DMUB buffer object.
424 	 */
425 	void *dmub_bo_cpu_addr;
426 
427 	/**
428 	 * @dmcub_fw_version:
429 	 *
430 	 * DMCUB firmware version.
431 	 */
432 	uint32_t dmcub_fw_version;
433 
434 	/**
435 	 * @fw_inst_size:
436 	 *
437 	 * Size of the firmware instruction buffer.
438 	 */
439 	uint32_t fw_inst_size;
440 
441 	/**
442 	 * @cgs_device:
443 	 *
444 	 * The Common Graphics Services device. It provides an interface for
445 	 * accessing registers.
446 	 */
447 	struct cgs_device *cgs_device;
448 
449 	struct amdgpu_device *adev;
450 	struct drm_device *ddev;
451 	u16 display_indexes_num;
452 
453 	/**
454 	 * @atomic_obj:
455 	 *
456 	 * In combination with &dm_atomic_state it helps manage
457 	 * global atomic state that doesn't map cleanly into existing
458 	 * drm resources, like &dc_context.
459 	 */
460 	struct drm_private_obj atomic_obj;
461 
462 	/**
463 	 * @dc_lock:
464 	 *
465 	 * Guards access to DC functions that can issue register write
466 	 * sequences.
467 	 */
468 	struct mutex dc_lock;
469 
470 	/**
471 	 * @dmub_lock:
472 	 *
473 	 * Guards access to DMUB command submission.
474 	 */
475 	spinlock_t dmub_lock;
476 
477 	/**
478 	 * @audio_lock:
479 	 *
480 	 * Guards access to audio instance changes.
481 	 */
482 	struct mutex audio_lock;
483 
484 	/**
485 	 * @audio_component:
486 	 *
487 	 * Used to notify ELD changes to sound driver.
488 	 */
489 	struct drm_audio_component *audio_component;
490 
491 	/**
492 	 * @audio_registered:
493 	 *
494 	 * True if the audio component has been registered
495 	 * successfully, false otherwise.
496 	 */
497 	bool audio_registered;
498 
499 	/**
500 	 * @irq_handler_list_low_tab:
501 	 *
502 	 * Low priority IRQ handler table.
503 	 *
504 	 * It is a n*m table consisting of n IRQ sources, and m handlers per IRQ
505 	 * source. Low priority IRQ handlers are deferred to a workqueue to be
506 	 * processed. Hence, they can sleep.
507 	 *
508 	 * Note that handlers are called in the same order as they were
509 	 * registered (FIFO).
510 	 */
511 	struct list_head irq_handler_list_low_tab[DAL_IRQ_SOURCES_NUMBER];
512 
513 	/**
514 	 * @irq_handler_list_high_tab:
515 	 *
516 	 * High priority IRQ handler table.
517 	 *
518 	 * It is a n*m table, same as &irq_handler_list_low_tab. However,
519 	 * handlers in this table are not deferred and are called immediately.
520 	 */
521 	struct list_head irq_handler_list_high_tab[DAL_IRQ_SOURCES_NUMBER];
522 
523 	/**
524 	 * @pflip_params:
525 	 *
526 	 * Page flip IRQ parameters, passed to registered handlers when
527 	 * triggered.
528 	 */
529 	struct common_irq_params
530 	pflip_params[DC_IRQ_SOURCE_PFLIP_LAST - DC_IRQ_SOURCE_PFLIP_FIRST + 1];
531 
532 	/**
533 	 * @vblank_params:
534 	 *
535 	 * Vertical blanking IRQ parameters, passed to registered handlers when
536 	 * triggered.
537 	 */
538 	struct common_irq_params
539 	vblank_params[DC_IRQ_SOURCE_VBLANK6 - DC_IRQ_SOURCE_VBLANK1 + 1];
540 
541 	/**
542 	 * @vline0_params:
543 	 *
544 	 * OTG vertical interrupt0 IRQ parameters, passed to registered
545 	 * handlers when triggered.
546 	 */
547 	struct common_irq_params
548 	vline0_params[DC_IRQ_SOURCE_DC6_VLINE0 - DC_IRQ_SOURCE_DC1_VLINE0 + 1];
549 
550 	/**
551 	 * @vupdate_params:
552 	 *
553 	 * Vertical update IRQ parameters, passed to registered handlers when
554 	 * triggered.
555 	 */
556 	struct common_irq_params
557 	vupdate_params[DC_IRQ_SOURCE_VUPDATE6 - DC_IRQ_SOURCE_VUPDATE1 + 1];
558 
559 	/**
560 	 * @irq_reg_lock:
561 	 *
562 	 * Serializes the read-modify-writes of the HW interrupt control
563 	 * registers. Several interrupt sources share one register - e.g. the
564 	 * enable and clear bits of both VSTARTUP (vblank) and VUPDATE_NO_LOCK
565 	 * live in OTG_GLOBAL_SYNC_STATUS. Therefore, enabling one source must
566 	 * not race with acking another. Held only across amdgpu_dm_irq_set()
567 	 * and amdgpu_dm_irq_ack().
568 	 */
569 	spinlock_t irq_reg_lock;
570 
571 	/**
572 	 * @dmub_trace_params:
573 	 *
574 	 * DMUB trace event IRQ parameters, passed to registered handlers when
575 	 * triggered.
576 	 */
577 	struct common_irq_params
578 	dmub_trace_params[1];
579 
580 	struct common_irq_params
581 	dmub_outbox_params[1];
582 
583 	spinlock_t irq_handler_list_table_lock;
584 	struct workqueue_struct *irq_wq;
585 	struct workqueue_struct *vmin_vmax_wq;
586 
587 	struct backlight_device *backlight_dev[AMDGPU_DM_MAX_NUM_EDP];
588 
589 	const struct dc_link *backlight_link[AMDGPU_DM_MAX_NUM_EDP];
590 
591 	uint8_t num_of_edps;
592 
593 	struct amdgpu_dm_backlight_caps backlight_caps[AMDGPU_DM_MAX_NUM_EDP];
594 
595 	struct mod_freesync *freesync_module;
596 	struct mod_power *power_module;
597 	struct hdcp_workqueue *hdcp_workqueue;
598 
599 	/**
600 	 * @vblank_control_workqueue:
601 	 *
602 	 * Deferred work for vblank control events.
603 	 */
604 	struct workqueue_struct *vblank_control_workqueue;
605 
606 	/**
607 	 * @idle_workqueue:
608 	 *
609 	 * Periodic work for idle events.
610 	 */
611 	struct idle_workqueue *idle_workqueue;
612 
613 	struct drm_atomic_commit *cached_state;
614 	struct dc_state *cached_dc_state;
615 
616 	struct dm_compressor_info compressor;
617 
618 	const struct firmware *fw_dmcu;
619 	uint32_t dmcu_fw_version;
620 	/**
621 	 * @soc_bounding_box:
622 	 *
623 	 * gpu_info FW provided soc bounding box struct or 0 if not
624 	 * available in FW
625 	 */
626 	const struct gpu_info_soc_bounding_box_v1_0 *soc_bounding_box;
627 
628 	/**
629 	 * @active_vblank_irq_count:
630 	 *
631 	 * number of currently active vblank irqs
632 	 */
633 	uint32_t active_vblank_irq_count;
634 
635 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
636 	/**
637 	 * @secure_display_ctx:
638 	 *
639 	 * Store secure display relevant info. e.g. the ROI information
640 	 * , the work_struct to command dmub, etc.
641 	 */
642 	struct secure_display_context secure_display_ctx;
643 #endif
644 	/**
645 	 * @hpd_rx_offload_wq:
646 	 *
647 	 * Work queue to offload works of hpd_rx_irq
648 	 */
649 	struct hpd_rx_irq_offload_work_queue *hpd_rx_offload_wq;
650 	/**
651 	 * @mst_encoders:
652 	 *
653 	 * fake encoders used for DP MST.
654 	 */
655 	struct amdgpu_encoder mst_encoders[AMDGPU_DM_MAX_CRTC];
656 	bool force_timing_sync;
657 	bool disable_hpd_irq;
658 	bool dmcub_trace_event_en;
659 	/**
660 	 * @da_list:
661 	 *
662 	 * DAL fb memory allocation list, for communication with SMU.
663 	 */
664 	struct list_head da_list;
665 	struct completion dmub_aux_transfer_done;
666 	struct workqueue_struct *delayed_hpd_wq;
667 
668 	/**
669 	 * @brightness:
670 	 *
671 	 * cached backlight values.
672 	 */
673 	u32 brightness[AMDGPU_DM_MAX_NUM_EDP];
674 	/**
675 	 * @actual_brightness:
676 	 *
677 	 * last successfully applied backlight values.
678 	 */
679 	u32 actual_brightness[AMDGPU_DM_MAX_NUM_EDP];
680 
681 	/**
682 	 * @aux_hpd_discon_quirk:
683 	 *
684 	 * quirk for hpd discon while aux is on-going.
685 	 * occurred on certain intel platform
686 	 */
687 	bool aux_hpd_discon_quirk;
688 
689 	/**
690 	 * @edp0_on_dp1_quirk:
691 	 *
692 	 * quirk for platforms that put edp0 on DP1.
693 	 */
694 	bool edp0_on_dp1_quirk;
695 
696 	/**
697 	 * @dpia_aux_lock:
698 	 *
699 	 * Guards access to DPIA AUX
700 	 */
701 	struct mutex dpia_aux_lock;
702 
703 	/**
704 	 * @bb_from_dmub:
705 	 *
706 	 * Bounding box data read from dmub during early initialization for DCN4+
707 	 * Data is stored as a byte array that should be casted to the appropriate bb struct
708 	 */
709 	void *bb_from_dmub;
710 
711 	/**
712 	 * @i2c_devres_group:
713 	 *
714 	 * Devres group for DM i2c adapter lifetime management.
715 	 */
716 	void *i2c_devres_group;
717 
718 	/**
719 	 * @oem_i2c:
720 	 *
721 	 * OEM i2c bus
722 	 */
723 	struct amdgpu_i2c_adapter *oem_i2c;
724 
725 	/**
726 	 * @fused_io:
727 	 *
728 	 * dmub fused io interface
729 	 */
730 	struct fused_io_sync {
731 		struct completion replied;
732 		char reply_data[0x40];  // Cannot include dmub_cmd here
733 	} fused_io[8];
734 	/**
735 	 * @hdmi_frl_status_polling_wq:
736 	 *
737 	 * workqueue for 200ms frl status polling
738 	 */
739 	struct workqueue_struct *hdmi_frl_status_polling_wq;
740 	/**
741 	 * @hdmi_frl_status_polling_work:
742 	 *
743 	 * Delayed work for 200ms HDMI FRL status polling.
744 	 */
745 	struct delayed_work hdmi_frl_status_polling_work;
746 	/**
747 	 * @hdmi_frl_status_polling_delay_ms:
748 	 *
749 	 * Delay, in milliseconds, between HDMI FRL status polls.
750 	 */
751 	unsigned int hdmi_frl_status_polling_delay_ms;
752 
753 	/**
754 	 * @boot_time_crc_info:
755 	 *
756 	 * Buffer info for the boot time crc.
757 	 */
758 	struct dm_boot_time_crc_info boot_time_crc_info;
759 };
760 
761 enum dsc_clock_force_state {
762 	DSC_CLK_FORCE_DEFAULT = 0,
763 	DSC_CLK_FORCE_ENABLE,
764 	DSC_CLK_FORCE_DISABLE,
765 };
766 
767 struct dsc_preferred_settings {
768 	enum dsc_clock_force_state dsc_force_enable;
769 	uint32_t dsc_num_slices_v;
770 	uint32_t dsc_num_slices_h;
771 	uint32_t dsc_bits_per_pixel;
772 	bool dsc_force_disable_passthrough;
773 };
774 
775 enum mst_progress_status {
776 	MST_STATUS_DEFAULT = 0,
777 	MST_PROBE = BIT(0),
778 	MST_REMOTE_EDID = BIT(1),
779 	MST_ALLOCATE_NEW_PAYLOAD = BIT(2),
780 	MST_CLEAR_ALLOCATED_PAYLOAD = BIT(3),
781 };
782 
783 /**
784  * struct amdgpu_hdmi_vsdb_info - Keep track of the VSDB info
785  *
786  * AMDGPU supports FreeSync over HDMI by using the VSDB section, and this
787  * struct is useful to keep track of the display-specific information about
788  * FreeSync.
789  */
790 struct amdgpu_hdmi_vsdb_info {
791 	/**
792 	 * @amd_vsdb_version: Vendor Specific Data Block Version, should be
793 	 * used to determine which Vendor Specific InfoFrame (VSIF) to send.
794 	 */
795 	unsigned int amd_vsdb_version;
796 
797 	/**
798 	 * @freesync_supported: FreeSync Supported.
799 	 */
800 	bool freesync_supported;
801 
802 	/**
803 	 * @min_refresh_rate_hz: FreeSync Minimum Refresh Rate in Hz.
804 	 */
805 	unsigned int min_refresh_rate_hz;
806 
807 	/**
808 	 * @max_refresh_rate_hz: FreeSync Maximum Refresh Rate in Hz
809 	 */
810 	unsigned int max_refresh_rate_hz;
811 
812 	/**
813 	 * @freesync_mccs_vcp_code: MCCS VCP code for freesync state
814 	 */
815 	unsigned int freesync_mccs_vcp_code;
816 
817 	/**
818 	 * @replay_mode: Replay supported
819 	 */
820 	bool replay_mode;
821 };
822 
823 struct amdgpu_dm_connector {
824 
825 	struct drm_connector base;
826 	uint32_t connector_id;
827 	int bl_idx;
828 
829 	struct cec_notifier *notifier;
830 
831 	/* we need to mind the EDID between detect
832 	   and get modes due to analog/digital/tvencoder */
833 	const struct drm_edid *drm_edid;
834 
835 	/* shared with amdgpu */
836 	struct amdgpu_hpd hpd;
837 
838 	/* number of modes generated from EDID at 'dc_sink' */
839 	int num_modes;
840 
841 	/* The 'old' sink - before an HPD.
842 	 * The 'current' sink is in dc_link->sink. */
843 	struct dc_sink *dc_sink;
844 	struct dc_link *dc_link;
845 
846 	/**
847 	 * @dc_em_sink: Reference to the emulated (virtual) sink.
848 	 */
849 	struct dc_sink *dc_em_sink;
850 
851 	/* DM only */
852 	struct drm_dp_mst_topology_mgr mst_mgr;
853 	struct amdgpu_dm_dp_aux dm_dp_aux;
854 	struct drm_dp_mst_port *mst_output_port;
855 	struct amdgpu_dm_connector *mst_root;
856 	struct drm_dp_aux *dsc_aux;
857 	uint32_t mst_local_bw;
858 	uint16_t vc_full_pbn;
859 	struct mutex handle_mst_msg_ready;
860 
861 	/* branch device specific data */
862 	uint32_t branch_ieee_oui;
863 
864 	/* TODO see if we can merge with ddc_bus or make a dm_connector */
865 	struct amdgpu_i2c_adapter *i2c;
866 
867 	/* Monitor range limits */
868 	/**
869 	 * @min_vfreq: Minimal frequency supported by the display in Hz. This
870 	 * value is set to zero when there is no FreeSync support.
871 	 */
872 	int min_vfreq;
873 
874 	/**
875 	 * @max_vfreq: Maximum frequency supported by the display in Hz. This
876 	 * value is set to zero when there is no FreeSync support.
877 	 */
878 	int max_vfreq ;
879 
880 	/* Audio instance - protected by audio_lock. */
881 	int audio_inst;
882 
883 	struct mutex hpd_lock;
884 
885 	bool fake_enable;
886 	uint8_t force_yuv_pixel_format;
887 	struct dsc_preferred_settings dsc_settings;
888 	struct psr_caps psr_caps;
889 	union dp_downstream_port_present mst_downstream_port_present;
890 	/* Cached display modes */
891 	struct drm_display_mode freesync_vid_base;
892 
893 	int sr_skip_count;
894 	bool disallow_edp_enter_psr;
895 	bool disallow_edp_enter_replay;
896 
897 	union dwnstream_portxcaps mst_downstream_port_caps;
898 
899 	/* Record progress status of mst*/
900 	uint8_t mst_status;
901 
902 	/* Automated testing */
903 	bool timing_changed;
904 	struct dc_crtc_timing *timing_requested;
905 
906 	/* Adaptive Sync */
907 	bool pack_sdp_v1_3;
908 	enum adaptive_sync_type as_type;
909 	struct amdgpu_hdmi_vsdb_info vsdb_info;
910 
911 	/* HDMI HPD debounce support */
912 	unsigned int hdmi_hpd_debounce_delay_ms;
913 	struct delayed_work hdmi_hpd_debounce_work;
914 	struct dc_sink *hdmi_prev_sink;
915 
916 	/* HDMI compliance automation */
917 	bool hdmi_comp_auto;
918 };
919 
920 static inline void amdgpu_dm_set_mst_status(uint8_t *status,
921 		uint8_t flags, bool set)
922 {
923 	if (set)
924 		*status |= flags;
925 	else
926 		*status &= ~flags;
927 }
928 
929 #define to_amdgpu_dm_connector(x) container_of(x, struct amdgpu_dm_connector, base)
930 
931 struct amdgpu_dm_wb_connector {
932 	struct drm_writeback_connector base;
933 	struct dc_link *link;
934 };
935 
936 #define to_amdgpu_dm_wb_connector(x) container_of(x, struct amdgpu_dm_wb_connector, base)
937 
938 extern const struct amdgpu_ip_block_version dm_ip_block;
939 
940 /* enum amdgpu_transfer_function: pre-defined transfer function supported by AMD.
941  *
942  * It includes standardized transfer functions and pure power functions. The
943  * transfer function coefficients are available at modules/color/color_gamma.c
944  */
945 enum amdgpu_transfer_function {
946 	AMDGPU_TRANSFER_FUNCTION_DEFAULT,
947 	AMDGPU_TRANSFER_FUNCTION_SRGB_EOTF,
948 	AMDGPU_TRANSFER_FUNCTION_BT709_INV_OETF,
949 	AMDGPU_TRANSFER_FUNCTION_PQ_EOTF,
950 	AMDGPU_TRANSFER_FUNCTION_IDENTITY,
951 	AMDGPU_TRANSFER_FUNCTION_GAMMA22_EOTF,
952 	AMDGPU_TRANSFER_FUNCTION_GAMMA24_EOTF,
953 	AMDGPU_TRANSFER_FUNCTION_GAMMA26_EOTF,
954 	AMDGPU_TRANSFER_FUNCTION_SRGB_INV_EOTF,
955 	AMDGPU_TRANSFER_FUNCTION_BT709_OETF,
956 	AMDGPU_TRANSFER_FUNCTION_PQ_INV_EOTF,
957 	AMDGPU_TRANSFER_FUNCTION_GAMMA22_INV_EOTF,
958 	AMDGPU_TRANSFER_FUNCTION_GAMMA24_INV_EOTF,
959 	AMDGPU_TRANSFER_FUNCTION_GAMMA26_INV_EOTF,
960 	AMDGPU_TRANSFER_FUNCTION_COUNT
961 };
962 
963 struct dc_flip_addrs;
964 struct dc_scaling_info;
965 struct dc_plane_info;
966 
967 struct dm_plane_state {
968 	struct drm_plane_state base;
969 	struct dc_plane_state *dc_state;
970 
971 	/* Plane color mgmt */
972 	/**
973 	 * @degamma_lut:
974 	 *
975 	 * 1D LUT for mapping framebuffer/plane pixel data before sampling or
976 	 * blending operations. It's usually applied to linearize input space.
977 	 * The blob (if not NULL) is an array of &struct drm_color_lut.
978 	 */
979 	struct drm_property_blob *degamma_lut;
980 	/**
981 	 * @degamma_tf:
982 	 *
983 	 * Predefined transfer function to tell DC driver the input space to
984 	 * linearize.
985 	 */
986 	enum amdgpu_transfer_function degamma_tf;
987 	/**
988 	 * @hdr_mult:
989 	 *
990 	 * Multiplier to 'gain' the plane.  When PQ is decoded using the fixed
991 	 * func transfer function to the internal FP16 fb, 1.0 -> 80 nits (on
992 	 * AMD at least). When sRGB is decoded, 1.0 -> 1.0, obviously.
993 	 * Therefore, 1.0 multiplier = 80 nits for SDR content.  So if you
994 	 * want, 203 nits for SDR content, pass in (203.0 / 80.0).  Format is
995 	 * S31.32 sign-magnitude.
996 	 *
997 	 * HDR multiplier can wide range beyond [0.0, 1.0]. This means that PQ
998 	 * TF is needed for any subsequent linear-to-non-linear transforms.
999 	 */
1000 	__u64 hdr_mult;
1001 	/**
1002 	 * @ctm:
1003 	 *
1004 	 * Color transformation matrix. The blob (if not NULL) is a &struct
1005 	 * drm_color_ctm_3x4.
1006 	 */
1007 	struct drm_property_blob *ctm;
1008 	/**
1009 	 * @shaper_lut: shaper lookup table blob. The blob (if not NULL) is an
1010 	 * array of &struct drm_color_lut.
1011 	 */
1012 	struct drm_property_blob *shaper_lut;
1013 	/**
1014 	 * @shaper_tf:
1015 	 *
1016 	 * Predefined transfer function to delinearize color space.
1017 	 */
1018 	enum amdgpu_transfer_function shaper_tf;
1019 	/**
1020 	 * @lut3d: 3D lookup table blob. The blob (if not NULL) is an array of
1021 	 * &struct drm_color_lut.
1022 	 */
1023 	struct drm_property_blob *lut3d;
1024 	/**
1025 	 * @blend_lut: blend lut lookup table blob. The blob (if not NULL) is an
1026 	 * array of &struct drm_color_lut.
1027 	 */
1028 	struct drm_property_blob *blend_lut;
1029 	/**
1030 	 * @blend_tf:
1031 	 *
1032 	 * Pre-defined transfer function for converting plane pixel data before
1033 	 * applying blend LUT.
1034 	 */
1035 	enum amdgpu_transfer_function blend_tf;
1036 
1037 	/* Cached per-plane surface descriptors kept in the DRM plane state.
1038 	 * The DRM atomic old/new state swap lets us compare the previous
1039 	 * commit's values (old) against the newly computed ones to detect a
1040 	 * real plane change (vs an address-only flip) so DC only gets a
1041 	 * scaling_info/plane_info surface update when it actually changed.
1042 	 */
1043 	struct dc_flip_addrs *flip_addr;
1044 	struct dc_scaling_info *scaling_info;
1045 	struct dc_plane_info *plane_info;
1046 };
1047 
1048 enum amdgpu_dm_cursor_mode {
1049 	DM_CURSOR_NATIVE_MODE = 0,
1050 	DM_CURSOR_OVERLAY_MODE,
1051 };
1052 
1053 struct dm_crtc_state {
1054 	struct drm_crtc_state base;
1055 	struct dc_stream_state *stream;
1056 
1057 	bool cm_has_degamma;
1058 	bool cm_is_degamma_srgb;
1059 
1060 	bool mpo_requested;
1061 
1062 	int update_type;
1063 	int active_planes;
1064 
1065 	int crc_skip_count;
1066 
1067 	bool freesync_vrr_info_changed;
1068 
1069 	bool mode_changed_independent_from_dsc;
1070 	bool dsc_force_changed;
1071 	bool vrr_supported;
1072 	struct mod_freesync_config freesync_config;
1073 	struct dc_info_packet vrr_infopacket;
1074 
1075 	int abm_level;
1076 
1077 	/**
1078 	 * @regamma_tf:
1079 	 *
1080 	 * Pre-defined transfer function for converting internal FB -> wire
1081 	 * encoding.
1082 	 */
1083 	enum amdgpu_transfer_function regamma_tf;
1084 
1085 	enum amdgpu_dm_cursor_mode cursor_mode;
1086 };
1087 
1088 #define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base)
1089 
1090 struct dm_atomic_state {
1091 	struct drm_private_state base;
1092 
1093 	struct dc_state *context;
1094 };
1095 
1096 #define to_dm_atomic_state(x) container_of(x, struct dm_atomic_state, base)
1097 
1098 struct dm_connector_state {
1099 	struct drm_connector_state base;
1100 
1101 	enum amdgpu_rmx_type scaling;
1102 	uint8_t underscan_vborder;
1103 	uint8_t underscan_hborder;
1104 	bool underscan_enable;
1105 	bool freesync_capable;
1106 	bool update_hdcp;
1107 	bool abm_sysfs_forbidden;
1108 	uint8_t abm_level;
1109 	int vcpi_slots;
1110 	uint64_t pbn;
1111 };
1112 
1113 #define to_dm_connector_state(x)\
1114 	container_of((x), struct dm_connector_state, base)
1115 
1116 #include "amdgpu_dm_connector.h"
1117 
1118 void amdgpu_dm_trigger_timing_sync(struct drm_device *dev);
1119 
1120 /* 3D LUT max size is 17x17x17 (4913 entries) */
1121 #define MAX_COLOR_3DLUT_SIZE 17
1122 #define MAX_COLOR_3DLUT_BITDEPTH 12
1123 int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev,
1124 				struct drm_plane_state *plane_state);
1125 /* 1D LUT size */
1126 #define MAX_COLOR_LUT_ENTRIES 4096
1127 /* Legacy gamm LUT users such as X doesn't like large LUT sizes */
1128 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256
1129 
1130 void amdgpu_dm_init_color_mod(void);
1131 int amdgpu_dm_create_color_properties(struct amdgpu_device *adev);
1132 int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state);
1133 int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc);
1134 int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state *crtc,
1135 				    bool check_only);
1136 int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
1137 				      struct drm_plane_state *plane_state,
1138 				      struct dc_plane_state *dc_plane_state);
1139 
1140 void populate_hdmi_info_from_connector(bool enable_frl, struct drm_hdmi_info *info,
1141 				      struct dc_edid_caps *edid_caps);
1142 
1143 int amdgpu_dm_process_dmub_aux_transfer_sync(struct dc_context *ctx, unsigned int link_index,
1144 					struct aux_payload *payload, enum aux_return_code_type *operation_result);
1145 
1146 bool amdgpu_dm_execute_fused_io(
1147 		struct amdgpu_device *dev,
1148 		struct dc_link *link,
1149 		union dmub_rb_cmd *commands,
1150 		uint8_t count,
1151 		uint32_t timeout_us
1152 );
1153 
1154 int amdgpu_dm_process_dmub_set_config_sync(struct dc_context *ctx, unsigned int link_index,
1155 					struct set_config_cmd_payload *payload, enum set_config_status *operation_result);
1156 
1157 int dm_atomic_get_state(struct drm_atomic_commit *state,
1158 			struct dm_atomic_state **dm_state);
1159 
1160 struct idle_workqueue *idle_create_workqueue(struct amdgpu_device *adev);
1161 
1162 void *dm_allocate_gpu_mem(struct amdgpu_device *adev,
1163 						  enum dc_gpu_mem_alloc_type type,
1164 						  size_t size,
1165 						  long long *addr);
1166 void dm_free_gpu_mem(struct amdgpu_device *adev,
1167 						  enum dc_gpu_mem_alloc_type type,
1168 						  void *addr);
1169 
1170 bool amdgpu_dm_is_headless(struct amdgpu_device *adev);
1171 
1172 bool amdgpu_dm_crtc_complete_writeback(struct amdgpu_crtc *acrtc);
1173 
1174 void retrieve_dmi_info(struct amdgpu_display_manager *dm);
1175 struct pci_dev;
1176 bool dm_should_disable_stutter(struct pci_dev *pdev);
1177 
1178 void amdgpu_dm_emulated_link_detect(struct dc_link *link);
1179 void amdgpu_dm_apply_delay_after_dpcd_poweroff(struct amdgpu_device *adev,
1180 											   struct dc_sink *sink);
1181 
1182 struct __drm_planes_state *amdgpu_dm_get_next_zpos(struct drm_atomic_commit *state,
1183 						   struct __drm_planes_state *prev);
1184 
1185 /*
1186  * Use the uniqueness of the plane's (zpos, drm obj ID) combination to iterate
1187  * by descending zpos, as read from the new plane state. This is the same
1188  * ordering as defined by drm_atomic_normalize_zpos().
1189  */
1190 #define for_each_oldnew_plane_in_descending_zpos(__state, plane, old_plane_state, new_plane_state) \
1191 	for (struct __drm_planes_state *__i = amdgpu_dm_get_next_zpos((__state), NULL); \
1192 	     __i != NULL; __i = amdgpu_dm_get_next_zpos((__state), __i))		\
1193 		for_each_if(((plane) = __i->ptr,				\
1194 			     (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
1195 			     (old_plane_state) = __i->old_state,		\
1196 			     (new_plane_state) = __i->new_state, 1))
1197 
1198 #if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
1199 struct amdgpu_ip_block;
1200 int dm_wait_for_idle(struct amdgpu_ip_block *ip_block);
1201 int dm_soft_reset(struct amdgpu_ip_block *ip_block);
1202 int dm_set_clockgating_state(struct amdgpu_ip_block *ip_block,
1203 			     enum amd_clockgating_state state);
1204 int dm_set_powergating_state(struct amdgpu_ip_block *ip_block,
1205 			     enum amd_powergating_state state);
1206 void dm_bandwidth_update(struct amdgpu_device *adev);
1207 u32 dm_vblank_get_counter(struct amdgpu_device *adev, int crtc);
1208 int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
1209 			   u32 *vbl, u32 *position);
1210 struct dm_atomic_state *dm_atomic_get_new_state(struct drm_atomic_commit *state);
1211 struct drm_private_state *dm_atomic_duplicate_state(struct drm_private_obj *obj);
1212 void dm_atomic_destroy_state(struct drm_private_obj *obj,
1213 			     struct drm_private_state *state);
1214 struct dc_flip_addrs;
1215 void fill_dc_dirty_rects(struct drm_plane *plane,
1216 			 struct drm_plane_state *old_plane_state,
1217 			 struct drm_plane_state *new_plane_state,
1218 			 struct drm_crtc_state *crtc_state,
1219 			 struct dc_flip_addrs *flip_addrs,
1220 			 bool is_psr_su,
1221 			 bool *dirty_regions_changed);
1222 void dm_update_pflip_irq_state(struct amdgpu_device *adev,
1223 			       struct amdgpu_crtc *acrtc);
1224 void amdgpu_dm_commit_cursors(struct drm_atomic_commit *state);
1225 void amdgpu_dm_update_cursor(struct drm_plane *plane,
1226 			     struct drm_plane_state *old_plane_state,
1227 			     struct dc_stream_update *update);
1228 void dm_arm_vblank_event(struct amdgpu_crtc *acrtc,
1229 			 struct dm_crtc_state *acrtc_state,
1230 			 bool pflip_update, bool cursor_update);
1231 void dm_arm_vblank_event_pre_programming(struct amdgpu_crtc *acrtc,
1232 					 struct dm_crtc_state *acrtc_state,
1233 					 bool pflip_update, bool cursor_update);
1234 bool should_reset_plane(struct drm_atomic_commit *state,
1235 			struct drm_plane *plane,
1236 			struct drm_plane_state *old_plane_state,
1237 			struct drm_plane_state *new_plane_state);
1238 int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state,
1239 			       struct drm_crtc *crtc);
1240 bool amdgpu_dm_crtc_mem_type_changed(struct drm_device *dev,
1241 				     struct drm_atomic_commit *state,
1242 				     struct drm_crtc_state *crtc_state);
1243 void amdgpu_dm_dump_links_and_sinks(struct amdgpu_device *adev);
1244 void amdgpu_dm_update_hdcp(struct drm_atomic_commit *state);
1245 int amdgpu_dm_atomic_setup_commit(struct drm_atomic_commit *state);
1246 int do_aquire_global_lock(struct drm_device *dev,
1247 			  struct drm_atomic_commit *state);
1248 int dm_update_crtc_state(struct amdgpu_display_manager *dm,
1249 			 struct drm_atomic_commit *state,
1250 			 struct drm_crtc *crtc,
1251 			 struct drm_crtc_state *old_crtc_state,
1252 			 struct drm_crtc_state *new_crtc_state,
1253 			 bool enable,
1254 			 bool *lock_and_validation_needed);
1255 int dm_update_plane_state(struct dc *dc,
1256 			  struct drm_atomic_commit *state,
1257 			  struct drm_plane *plane,
1258 			  struct drm_plane_state *old_plane_state,
1259 			  struct drm_plane_state *new_plane_state,
1260 			  bool enable,
1261 			  bool *lock_and_validation_needed,
1262 			  bool *is_top_most_overlay);
1263 int amdgpu_dm_atomic_check(struct drm_device *dev,
1264 			   struct drm_atomic_commit *state);
1265 void amdgpu_dm_mod_power_update_streams(struct drm_atomic_commit *state,
1266 					struct amdgpu_display_manager *dm);
1267 void amdgpu_dm_mod_power_setup_streams(struct drm_atomic_commit *state,
1268 				       struct amdgpu_display_manager *dm);
1269 int amdgpu_dm_early_fini(struct amdgpu_ip_block *ip_block);
1270 int dm_sw_fini(struct amdgpu_ip_block *ip_block);
1271 int dm_oem_i2c_hw_init(struct amdgpu_device *adev);
1272 void resume_mst_branch_status(struct drm_dp_mst_topology_mgr *mgr);
1273 void s3_handle_mst(struct drm_device *dev, bool suspend);
1274 void dm_gpureset_commit_state(struct dc_state *dc_state, struct amdgpu_display_manager *dm);
1275 int dm_plane_layer_index_cmp(const void *a, const void *b);
1276 bool update_planes_and_stream_adapter(struct dc *dc,
1277 				      int planes_count,
1278 				      struct dc_stream_state *stream,
1279 				      struct dc_stream_update *stream_update,
1280 				      struct dc_surface_update *array_of_surface_update);
1281 int fill_plane_color_attributes(struct drm_atomic_commit *state,
1282 			    const struct drm_plane_state *plane_state,
1283 			    const enum surface_pixel_format format,
1284 			    enum dc_color_space *color_space);
1285 bool modereset_required(struct drm_crtc_state *crtc_state);
1286 bool is_scaling_state_different(const struct dm_connector_state *dm_state,
1287 				const struct dm_connector_state *old_dm_state);
1288 void set_multisync_trigger_params(struct dc_stream_state *stream);
1289 void set_master_stream(struct dc_stream_state *stream_set[], int stream_count);
1290 void dm_enable_per_frame_crtc_master_sync(struct dc_state *context);
1291 struct hdcp_workqueue;
1292 bool is_content_protection_different(struct drm_crtc_state *new_crtc_state,
1293 				     struct drm_crtc_state *old_crtc_state,
1294 				     struct drm_connector_state *new_conn_state,
1295 				     struct drm_connector_state *old_conn_state,
1296 				     const struct drm_connector *connector,
1297 				     struct hdcp_workqueue *hdcp_w);
1298 
1299 struct amdgpu_dm_services_kunit_ops {
1300 	int (*bo_create_kernel)(struct amdgpu_device *adev, unsigned long size,
1301 				int align, u32 domain, struct amdgpu_bo **bo_ptr,
1302 				u64 *gpu_addr, void **cpu_addr);
1303 	void (*bo_free_kernel)(struct amdgpu_bo **bo, u64 *gpu_addr,
1304 			       void **cpu_addr);
1305 };
1306 
1307 void amdgpu_dm_services_kunit_set_ops(const struct amdgpu_dm_services_kunit_ops *ops);
1308 
1309 struct amdgpu_dm_kunit_ops {
1310 	uint64_t (*gmc_pd_addr)(struct amdgpu_bo *bo);
1311 	void (*post_update_surfaces_to_stream)(struct dc *dc);
1312 	bool (*update_planes_and_stream)(struct dc *dc,
1313 					 struct dc_surface_update *surface_updates,
1314 					 int surface_count,
1315 					 struct dc_stream_state *dc_stream,
1316 					 struct dc_stream_update *stream_update);
1317 	struct drm_atomic_commit *(*atomic_helper_suspend)(struct drm_device *dev);
1318 };
1319 
1320 void amdgpu_dm_kunit_set_ops(const struct amdgpu_dm_kunit_ops *ops);
1321 
1322 struct dc_phy_addr_space_config;
1323 struct dc_plane_address;
1324 struct dc_plane_cap;
1325 struct dc_plane_info;
1326 struct dsc_mst_fairness_vars;
1327 
1328 void mmhub_read_system_context(struct amdgpu_device *adev,
1329 			       struct dc_phy_addr_space_config *pa_config);
1330 int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm);
1331 void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev, struct dc_state *state, bool enable);
1332 enum dc_status amdgpu_dm_commit_zero_streams(struct dc *dc);
1333 int dm_cache_state(struct amdgpu_device *adev);
1334 void dm_destroy_cached_state(struct amdgpu_device *adev);
1335 void dm_clear_writeback(struct amdgpu_display_manager *dm,
1336 			struct amdgpu_crtc *acrtc,
1337 			struct dm_crtc_state *crtc_state);
1338 void dm_set_writeback(struct amdgpu_display_manager *dm,
1339 		      struct dm_crtc_state *crtc_state,
1340 		      struct drm_connector *connector,
1341 		      struct drm_connector_state *new_con_state);
1342 int dm_early_init(struct amdgpu_ip_block *ip_block);
1343 int fill_dc_plane_info_and_addr(struct amdgpu_device *adev,
1344 				struct drm_atomic_commit *state,
1345 				const struct drm_plane_state *plane_state,
1346 				struct dc_plane_info *plane_info,
1347 				struct dc_plane_address *address,
1348 				bool tmz_surface);
1349 int dm_update_mst_vcpi_slots_for_dsc(struct drm_atomic_commit *state, struct dc_state *dc_state,
1350 				     struct dsc_mst_fairness_vars *vars);
1351 void manage_dm_interrupts(struct amdgpu_device *adev, struct amdgpu_crtc *acrtc,
1352 			  struct dm_crtc_state *acrtc_state);
1353 void amdgpu_dm_enable_self_refresh(struct amdgpu_display_manager *dm,
1354 				   struct amdgpu_crtc *acrtc_attach,
1355 				   const struct dm_crtc_state *acrtc_state, const u64 current_ts);
1356 int load_dmcu_fw(struct amdgpu_device *adev);
1357 int dm_sw_init(struct amdgpu_ip_block *ip_block);
1358 int dm_late_init(struct amdgpu_ip_block *ip_block);
1359 int amdgpu_dm_mode_config_init(struct amdgpu_device *adev);
1360 int initialize_plane(struct amdgpu_display_manager *dm, struct amdgpu_mode_info *mode_info,
1361 		     int plane_id, enum drm_plane_type plane_type,
1362 		     const struct dc_plane_cap *plane_cap);
1363 int fill_dc_plane_attributes(struct amdgpu_device *adev, struct dc_plane_state *dc_plane_state,
1364 			     struct drm_plane_state *plane_state,
1365 			     struct drm_crtc_state *crtc_state);
1366 #endif
1367 
1368 #endif /* __AMDGPU_DM_H__ */
1369