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 enum amd_vsdb_panel_type { 57 AMD_VSDB_PANEL_TYPE_DEFAULT = 0, 58 AMD_VSDB_PANEL_TYPE_MINILED, 59 AMD_VSDB_PANEL_TYPE_OLED, 60 AMD_VSDB_PANEL_TYPE_RESERVED, 61 }; 62 63 #define AMDGPU_HDR_MULT_DEFAULT (0x100000000LL) 64 65 /* 66 * Maximum HDMI HPD debounce delay in milliseconds 67 */ 68 #define AMDGPU_DM_MAX_HDMI_HPD_DEBOUNCE_MS 5000 69 /* 70 #include "include/amdgpu_dal_power_if.h" 71 #include "amdgpu_dm_irq.h" 72 */ 73 74 #include "irq_types.h" 75 #include "signal_types.h" 76 #include "amdgpu_dm_crc.h" 77 #include "mod_info_packet.h" 78 struct aux_payload; 79 struct set_config_cmd_payload; 80 enum aux_return_code_type; 81 enum set_config_status; 82 83 /* Forward declarations */ 84 struct amdgpu_device; 85 struct amdgpu_crtc; 86 struct drm_device; 87 struct dc; 88 struct amdgpu_bo; 89 struct dmub_srv; 90 struct dc_plane_state; 91 struct dmub_notification; 92 struct dmub_cmd_fused_request; 93 94 struct common_irq_params { 95 struct amdgpu_device *adev; 96 enum dc_irq_source irq_src; 97 atomic64_t previous_timestamp; 98 }; 99 100 /** 101 * struct dm_compressor_info - Buffer info used by frame buffer compression 102 * @cpu_addr: MMIO cpu addr 103 * @bo_ptr: Pointer to the buffer object 104 * @gpu_addr: MMIO gpu addr 105 */ 106 struct dm_compressor_info { 107 void *cpu_addr; 108 struct amdgpu_bo *bo_ptr; 109 uint64_t gpu_addr; 110 }; 111 112 /** 113 * struct dm_boot_time_crc_info - Buffer info used by boot time CRC 114 * @cpu_addr: MMIO cpu addr 115 * @bo_ptr: Pointer to the buffer object 116 * @gpu_addr: MMIO gpu addr 117 * @size: Size of the buffer 118 */ 119 struct dm_boot_time_crc_info { 120 void *cpu_addr; 121 struct amdgpu_bo *bo_ptr; 122 uint64_t gpu_addr; 123 uint32_t size; 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 * @dm_boot_time_crc_info: 704 * 705 * Buffer info for the boot time crc. 706 */ 707 struct dm_boot_time_crc_info boot_time_crc_info; 708 }; 709 710 enum dsc_clock_force_state { 711 DSC_CLK_FORCE_DEFAULT = 0, 712 DSC_CLK_FORCE_ENABLE, 713 DSC_CLK_FORCE_DISABLE, 714 }; 715 716 struct dsc_preferred_settings { 717 enum dsc_clock_force_state dsc_force_enable; 718 uint32_t dsc_num_slices_v; 719 uint32_t dsc_num_slices_h; 720 uint32_t dsc_bits_per_pixel; 721 bool dsc_force_disable_passthrough; 722 }; 723 724 enum mst_progress_status { 725 MST_STATUS_DEFAULT = 0, 726 MST_PROBE = BIT(0), 727 MST_REMOTE_EDID = BIT(1), 728 MST_ALLOCATE_NEW_PAYLOAD = BIT(2), 729 MST_CLEAR_ALLOCATED_PAYLOAD = BIT(3), 730 }; 731 732 /** 733 * struct amdgpu_hdmi_vsdb_info - Keep track of the VSDB info 734 * 735 * AMDGPU supports FreeSync over HDMI by using the VSDB section, and this 736 * struct is useful to keep track of the display-specific information about 737 * FreeSync. 738 */ 739 struct amdgpu_hdmi_vsdb_info { 740 /** 741 * @amd_vsdb_version: Vendor Specific Data Block Version, should be 742 * used to determine which Vendor Specific InfoFrame (VSIF) to send. 743 */ 744 unsigned int amd_vsdb_version; 745 746 /** 747 * @freesync_supported: FreeSync Supported. 748 */ 749 bool freesync_supported; 750 751 /** 752 * @min_refresh_rate_hz: FreeSync Minimum Refresh Rate in Hz. 753 */ 754 unsigned int min_refresh_rate_hz; 755 756 /** 757 * @max_refresh_rate_hz: FreeSync Maximum Refresh Rate in Hz 758 */ 759 unsigned int max_refresh_rate_hz; 760 761 /** 762 * @replay_mode: Replay supported 763 */ 764 bool replay_mode; 765 }; 766 767 struct amdgpu_dm_connector { 768 769 struct drm_connector base; 770 uint32_t connector_id; 771 int bl_idx; 772 773 struct cec_notifier *notifier; 774 775 /* we need to mind the EDID between detect 776 and get modes due to analog/digital/tvencoder */ 777 const struct drm_edid *drm_edid; 778 779 /* shared with amdgpu */ 780 struct amdgpu_hpd hpd; 781 782 /* number of modes generated from EDID at 'dc_sink' */ 783 int num_modes; 784 785 /* The 'old' sink - before an HPD. 786 * The 'current' sink is in dc_link->sink. */ 787 struct dc_sink *dc_sink; 788 struct dc_link *dc_link; 789 790 /** 791 * @dc_em_sink: Reference to the emulated (virtual) sink. 792 */ 793 struct dc_sink *dc_em_sink; 794 795 /* DM only */ 796 struct drm_dp_mst_topology_mgr mst_mgr; 797 struct amdgpu_dm_dp_aux dm_dp_aux; 798 struct drm_dp_mst_port *mst_output_port; 799 struct amdgpu_dm_connector *mst_root; 800 struct drm_dp_aux *dsc_aux; 801 uint32_t mst_local_bw; 802 uint16_t vc_full_pbn; 803 struct mutex handle_mst_msg_ready; 804 805 /* branch device specific data */ 806 uint32_t branch_ieee_oui; 807 808 /* TODO see if we can merge with ddc_bus or make a dm_connector */ 809 struct amdgpu_i2c_adapter *i2c; 810 811 /* Monitor range limits */ 812 /** 813 * @min_vfreq: Minimal frequency supported by the display in Hz. This 814 * value is set to zero when there is no FreeSync support. 815 */ 816 int min_vfreq; 817 818 /** 819 * @max_vfreq: Maximum frequency supported by the display in Hz. This 820 * value is set to zero when there is no FreeSync support. 821 */ 822 int max_vfreq ; 823 824 /* Audio instance - protected by audio_lock. */ 825 int audio_inst; 826 827 struct mutex hpd_lock; 828 829 bool fake_enable; 830 bool force_yuv420_output; 831 bool force_yuv422_output; 832 struct dsc_preferred_settings dsc_settings; 833 union dp_downstream_port_present mst_downstream_port_present; 834 /* Cached display modes */ 835 struct drm_display_mode freesync_vid_base; 836 837 int sr_skip_count; 838 bool disallow_edp_enter_psr; 839 bool disallow_edp_enter_replay; 840 841 /* Record progress status of mst*/ 842 uint8_t mst_status; 843 844 /* Automated testing */ 845 bool timing_changed; 846 struct dc_crtc_timing *timing_requested; 847 848 /* Adaptive Sync */ 849 bool pack_sdp_v1_3; 850 enum adaptive_sync_type as_type; 851 struct amdgpu_hdmi_vsdb_info vsdb_info; 852 853 /* HDMI HPD debounce support */ 854 unsigned int hdmi_hpd_debounce_delay_ms; 855 struct delayed_work hdmi_hpd_debounce_work; 856 struct dc_sink *hdmi_prev_sink; 857 }; 858 859 static inline void amdgpu_dm_set_mst_status(uint8_t *status, 860 uint8_t flags, bool set) 861 { 862 if (set) 863 *status |= flags; 864 else 865 *status &= ~flags; 866 } 867 868 #define to_amdgpu_dm_connector(x) container_of(x, struct amdgpu_dm_connector, base) 869 870 struct amdgpu_dm_wb_connector { 871 struct drm_writeback_connector base; 872 struct dc_link *link; 873 }; 874 875 #define to_amdgpu_dm_wb_connector(x) container_of(x, struct amdgpu_dm_wb_connector, base) 876 877 extern const struct amdgpu_ip_block_version dm_ip_block; 878 879 /* enum amdgpu_transfer_function: pre-defined transfer function supported by AMD. 880 * 881 * It includes standardized transfer functions and pure power functions. The 882 * transfer function coefficients are available at modules/color/color_gamma.c 883 */ 884 enum amdgpu_transfer_function { 885 AMDGPU_TRANSFER_FUNCTION_DEFAULT, 886 AMDGPU_TRANSFER_FUNCTION_SRGB_EOTF, 887 AMDGPU_TRANSFER_FUNCTION_BT709_INV_OETF, 888 AMDGPU_TRANSFER_FUNCTION_PQ_EOTF, 889 AMDGPU_TRANSFER_FUNCTION_IDENTITY, 890 AMDGPU_TRANSFER_FUNCTION_GAMMA22_EOTF, 891 AMDGPU_TRANSFER_FUNCTION_GAMMA24_EOTF, 892 AMDGPU_TRANSFER_FUNCTION_GAMMA26_EOTF, 893 AMDGPU_TRANSFER_FUNCTION_SRGB_INV_EOTF, 894 AMDGPU_TRANSFER_FUNCTION_BT709_OETF, 895 AMDGPU_TRANSFER_FUNCTION_PQ_INV_EOTF, 896 AMDGPU_TRANSFER_FUNCTION_GAMMA22_INV_EOTF, 897 AMDGPU_TRANSFER_FUNCTION_GAMMA24_INV_EOTF, 898 AMDGPU_TRANSFER_FUNCTION_GAMMA26_INV_EOTF, 899 AMDGPU_TRANSFER_FUNCTION_COUNT 900 }; 901 902 struct dm_plane_state { 903 struct drm_plane_state base; 904 struct dc_plane_state *dc_state; 905 906 /* Plane color mgmt */ 907 /** 908 * @degamma_lut: 909 * 910 * 1D LUT for mapping framebuffer/plane pixel data before sampling or 911 * blending operations. It's usually applied to linearize input space. 912 * The blob (if not NULL) is an array of &struct drm_color_lut. 913 */ 914 struct drm_property_blob *degamma_lut; 915 /** 916 * @degamma_tf: 917 * 918 * Predefined transfer function to tell DC driver the input space to 919 * linearize. 920 */ 921 enum amdgpu_transfer_function degamma_tf; 922 /** 923 * @hdr_mult: 924 * 925 * Multiplier to 'gain' the plane. When PQ is decoded using the fixed 926 * func transfer function to the internal FP16 fb, 1.0 -> 80 nits (on 927 * AMD at least). When sRGB is decoded, 1.0 -> 1.0, obviously. 928 * Therefore, 1.0 multiplier = 80 nits for SDR content. So if you 929 * want, 203 nits for SDR content, pass in (203.0 / 80.0). Format is 930 * S31.32 sign-magnitude. 931 * 932 * HDR multiplier can wide range beyond [0.0, 1.0]. This means that PQ 933 * TF is needed for any subsequent linear-to-non-linear transforms. 934 */ 935 __u64 hdr_mult; 936 /** 937 * @ctm: 938 * 939 * Color transformation matrix. The blob (if not NULL) is a &struct 940 * drm_color_ctm_3x4. 941 */ 942 struct drm_property_blob *ctm; 943 /** 944 * @shaper_lut: shaper lookup table blob. The blob (if not NULL) is an 945 * array of &struct drm_color_lut. 946 */ 947 struct drm_property_blob *shaper_lut; 948 /** 949 * @shaper_tf: 950 * 951 * Predefined transfer function to delinearize color space. 952 */ 953 enum amdgpu_transfer_function shaper_tf; 954 /** 955 * @lut3d: 3D lookup table blob. The blob (if not NULL) is an array of 956 * &struct drm_color_lut. 957 */ 958 struct drm_property_blob *lut3d; 959 /** 960 * @blend_lut: blend lut lookup table blob. The blob (if not NULL) is an 961 * array of &struct drm_color_lut. 962 */ 963 struct drm_property_blob *blend_lut; 964 /** 965 * @blend_tf: 966 * 967 * Pre-defined transfer function for converting plane pixel data before 968 * applying blend LUT. 969 */ 970 enum amdgpu_transfer_function blend_tf; 971 }; 972 973 enum amdgpu_dm_cursor_mode { 974 DM_CURSOR_NATIVE_MODE = 0, 975 DM_CURSOR_OVERLAY_MODE, 976 }; 977 978 struct dm_crtc_state { 979 struct drm_crtc_state base; 980 struct dc_stream_state *stream; 981 982 bool cm_has_degamma; 983 bool cm_is_degamma_srgb; 984 985 bool mpo_requested; 986 987 int update_type; 988 int active_planes; 989 990 int crc_skip_count; 991 992 bool freesync_vrr_info_changed; 993 994 bool mode_changed_independent_from_dsc; 995 bool dsc_force_changed; 996 bool vrr_supported; 997 struct mod_freesync_config freesync_config; 998 struct dc_info_packet vrr_infopacket; 999 1000 int abm_level; 1001 1002 /** 1003 * @regamma_tf: 1004 * 1005 * Pre-defined transfer function for converting internal FB -> wire 1006 * encoding. 1007 */ 1008 enum amdgpu_transfer_function regamma_tf; 1009 1010 enum amdgpu_dm_cursor_mode cursor_mode; 1011 }; 1012 1013 #define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base) 1014 1015 struct dm_atomic_state { 1016 struct drm_private_state base; 1017 1018 struct dc_state *context; 1019 }; 1020 1021 #define to_dm_atomic_state(x) container_of(x, struct dm_atomic_state, base) 1022 1023 struct dm_connector_state { 1024 struct drm_connector_state base; 1025 1026 enum amdgpu_rmx_type scaling; 1027 uint8_t underscan_vborder; 1028 uint8_t underscan_hborder; 1029 bool underscan_enable; 1030 bool freesync_capable; 1031 bool update_hdcp; 1032 bool abm_sysfs_forbidden; 1033 uint8_t abm_level; 1034 int vcpi_slots; 1035 uint64_t pbn; 1036 }; 1037 1038 #define to_dm_connector_state(x)\ 1039 container_of((x), struct dm_connector_state, base) 1040 1041 void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector); 1042 struct drm_connector_state * 1043 amdgpu_dm_connector_atomic_duplicate_state(struct drm_connector *connector); 1044 int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector, 1045 struct drm_connector_state *state, 1046 struct drm_property *property, 1047 uint64_t val); 1048 1049 int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector, 1050 const struct drm_connector_state *state, 1051 struct drm_property *property, 1052 uint64_t *val); 1053 1054 int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev); 1055 1056 void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm, 1057 struct amdgpu_dm_connector *aconnector, 1058 int connector_type, 1059 struct dc_link *link, 1060 int link_index); 1061 1062 enum drm_mode_status amdgpu_dm_connector_mode_valid(struct drm_connector *connector, 1063 const struct drm_display_mode *mode); 1064 1065 void dm_restore_drm_connector_state(struct drm_device *dev, 1066 struct drm_connector *connector); 1067 1068 void amdgpu_dm_update_freesync_caps(struct drm_connector *connector, 1069 const struct drm_edid *drm_edid); 1070 1071 void amdgpu_dm_trigger_timing_sync(struct drm_device *dev); 1072 1073 /* 3D LUT max size is 17x17x17 (4913 entries) */ 1074 #define MAX_COLOR_3DLUT_SIZE 17 1075 #define MAX_COLOR_3DLUT_BITDEPTH 12 1076 int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev, 1077 struct drm_plane_state *plane_state); 1078 /* 1D LUT size */ 1079 #define MAX_COLOR_LUT_ENTRIES 4096 1080 /* Legacy gamm LUT users such as X doesn't like large LUT sizes */ 1081 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256 1082 1083 void amdgpu_dm_init_color_mod(void); 1084 int amdgpu_dm_create_color_properties(struct amdgpu_device *adev); 1085 int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state); 1086 int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc); 1087 int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state *crtc, 1088 bool check_only); 1089 int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc, 1090 struct drm_plane_state *plane_state, 1091 struct dc_plane_state *dc_plane_state); 1092 1093 void amdgpu_dm_update_connector_after_detect( 1094 struct amdgpu_dm_connector *aconnector); 1095 1096 void populate_hdmi_info_from_connector(struct drm_hdmi_info *info, 1097 struct dc_edid_caps *edid_caps); 1098 1099 extern const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs; 1100 1101 int amdgpu_dm_process_dmub_aux_transfer_sync(struct dc_context *ctx, unsigned int link_index, 1102 struct aux_payload *payload, enum aux_return_code_type *operation_result); 1103 1104 bool amdgpu_dm_execute_fused_io( 1105 struct amdgpu_device *dev, 1106 struct dc_link *link, 1107 union dmub_rb_cmd *commands, 1108 uint8_t count, 1109 uint32_t timeout_us 1110 ); 1111 1112 int amdgpu_dm_process_dmub_set_config_sync(struct dc_context *ctx, unsigned int link_index, 1113 struct set_config_cmd_payload *payload, enum set_config_status *operation_result); 1114 1115 struct dc_stream_state * 1116 create_validate_stream_for_sink(struct drm_connector *connector, 1117 const struct drm_display_mode *drm_mode, 1118 const struct dm_connector_state *dm_state, 1119 const struct dc_stream_state *old_stream); 1120 1121 int dm_atomic_get_state(struct drm_atomic_state *state, 1122 struct dm_atomic_state **dm_state); 1123 1124 struct drm_connector * 1125 amdgpu_dm_find_first_crtc_matching_connector(struct drm_atomic_state *state, 1126 struct drm_crtc *crtc); 1127 1128 int convert_dc_color_depth_into_bpc(enum dc_color_depth display_color_depth); 1129 struct idle_workqueue *idle_create_workqueue(struct amdgpu_device *adev); 1130 1131 void *dm_allocate_gpu_mem(struct amdgpu_device *adev, 1132 enum dc_gpu_mem_alloc_type type, 1133 size_t size, 1134 long long *addr); 1135 void dm_free_gpu_mem(struct amdgpu_device *adev, 1136 enum dc_gpu_mem_alloc_type type, 1137 void *addr); 1138 1139 bool amdgpu_dm_is_headless(struct amdgpu_device *adev); 1140 1141 void hdmi_cec_set_edid(struct amdgpu_dm_connector *aconnector); 1142 void hdmi_cec_unset_edid(struct amdgpu_dm_connector *aconnector); 1143 int amdgpu_dm_initialize_hdmi_connector(struct amdgpu_dm_connector *aconnector); 1144 1145 void retrieve_dmi_info(struct amdgpu_display_manager *dm); 1146 1147 #endif /* __AMDGPU_DM_H__ */ 1148