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