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 dmub_notification; 90 struct dmub_cmd_fused_request; 91 92 struct common_irq_params { 93 struct amdgpu_device *adev; 94 enum dc_irq_source irq_src; 95 atomic64_t previous_timestamp; 96 }; 97 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 */ 104 struct dm_compressor_info { 105 void *cpu_addr; 106 struct amdgpu_bo *bo_ptr; 107 uint64_t gpu_addr; 108 }; 109 110 /** 111 * struct dm_boot_time_crc_info - Buffer info used by boot time CRC 112 * @cpu_addr: MMIO cpu addr 113 * @bo_ptr: Pointer to the buffer object 114 * @gpu_addr: MMIO gpu addr 115 * @size: Size of the buffer 116 */ 117 struct dm_boot_time_crc_info { 118 void *cpu_addr; 119 struct amdgpu_bo *bo_ptr; 120 uint64_t gpu_addr; 121 uint32_t size; 122 }; 123 124 typedef void (*dmub_notify_interrupt_callback_t)(struct amdgpu_device *adev, struct dmub_notification *notify); 125 126 /** 127 * struct dmub_hpd_work - Handle time consuming work in low priority outbox IRQ 128 * 129 * @handle_hpd_work: Work to be executed in a separate thread to handle hpd_low_irq 130 * @dmub_notify: notification for callback function 131 * @adev: amdgpu_device pointer 132 */ 133 struct dmub_hpd_work { 134 struct work_struct handle_hpd_work; 135 struct dmub_notification *dmub_notify; 136 struct amdgpu_device *adev; 137 }; 138 139 /** 140 * struct vblank_control_work - Work data for vblank control 141 * @work: Kernel work data for the work event 142 * @dm: amdgpu display manager device 143 * @acrtc: amdgpu CRTC instance for which the event has occurred 144 * @stream: DC stream for which the event has occurred 145 * @enable: true if enabling vblank 146 */ 147 struct vblank_control_work { 148 struct work_struct work; 149 struct amdgpu_display_manager *dm; 150 struct amdgpu_crtc *acrtc; 151 struct dc_stream_state *stream; 152 bool enable; 153 }; 154 155 /** 156 * struct idle_workqueue - Work data for periodic action in idle 157 * @work: Kernel work data for the work event 158 * @dm: amdgpu display manager device 159 * @enable: true if idle worker is enabled 160 * @running: true if idle worker is running 161 */ 162 struct idle_workqueue { 163 struct work_struct work; 164 struct amdgpu_display_manager *dm; 165 bool enable; 166 bool running; 167 }; 168 169 /** 170 * struct vupdate_offload_work - Work data for offloading task from vupdate handler 171 * @work: Kernel work data for the work event 172 * @adev: amdgpu_device back pointer 173 * @stream: DC stream associated with the crtc 174 * @adjust: DC CRTC timing adjust to be applied to the crtc 175 */ 176 struct vupdate_offload_work { 177 struct work_struct work; 178 struct amdgpu_device *adev; 179 struct dc_stream_state *stream; 180 struct dc_crtc_timing_adjust *adjust; 181 }; 182 183 #define MAX_LUMINANCE_DATA_POINTS 99 184 185 /** 186 * struct amdgpu_dm_luminance_data - Custom luminance data 187 * @luminance: Luminance in percent 188 * @input_signal: Input signal in range 0-255 189 */ 190 struct amdgpu_dm_luminance_data { 191 u8 luminance; 192 u8 input_signal; 193 } __packed; 194 195 /** 196 * struct amdgpu_dm_backlight_caps - Information about backlight 197 * 198 * Describe the backlight support for ACPI or eDP AUX. 199 */ 200 struct amdgpu_dm_backlight_caps { 201 /** 202 * @ext_caps: Keep the data struct with all the information about the 203 * display support for HDR. 204 */ 205 union dpcd_sink_ext_caps *ext_caps; 206 /** 207 * @aux_min_input_signal: Min brightness value supported by the display 208 */ 209 u32 aux_min_input_signal; 210 /** 211 * @aux_max_input_signal: Max brightness value supported by the display 212 * in nits. 213 */ 214 u32 aux_max_input_signal; 215 /** 216 * @min_input_signal: minimum possible input in range 0-255. 217 */ 218 int min_input_signal; 219 /** 220 * @max_input_signal: maximum possible input in range 0-255. 221 */ 222 int max_input_signal; 223 /** 224 * @caps_valid: true if these values are from the ACPI interface. 225 */ 226 bool caps_valid; 227 /** 228 * @aux_support: Describes if the display supports AUX backlight. 229 */ 230 bool aux_support; 231 /** 232 * @brightness_mask: After deriving brightness, OR it with this mask. 233 * Workaround for panels with issues with certain brightness values. 234 */ 235 u32 brightness_mask; 236 /** 237 * @ac_level: the default brightness if booted on AC 238 */ 239 u8 ac_level; 240 /** 241 * @dc_level: the default brightness if booted on DC 242 */ 243 u8 dc_level; 244 /** 245 * @data_points: the number of custom luminance data points 246 */ 247 u8 data_points; 248 /** 249 * @luminance_data: custom luminance data 250 */ 251 struct amdgpu_dm_luminance_data luminance_data[MAX_LUMINANCE_DATA_POINTS]; 252 }; 253 254 /** 255 * struct dal_allocation - Tracks mapped FB memory for SMU communication 256 * @list: list of dal allocations 257 * @bo: GPU buffer object 258 * @cpu_ptr: CPU virtual address of the GPU buffer object 259 * @gpu_addr: GPU virtual address of the GPU buffer object 260 */ 261 struct dal_allocation { 262 struct list_head list; 263 struct amdgpu_bo *bo; 264 void *cpu_ptr; 265 u64 gpu_addr; 266 }; 267 268 /** 269 * struct hpd_rx_irq_offload_work_queue - Work queue to handle hpd_rx_irq 270 * offload work 271 */ 272 struct hpd_rx_irq_offload_work_queue { 273 /** 274 * @wq: workqueue structure to queue offload work. 275 */ 276 struct workqueue_struct *wq; 277 /** 278 * @offload_lock: To protect fields of offload work queue. 279 */ 280 spinlock_t offload_lock; 281 /** 282 * @is_handling_link_loss: Used to prevent inserting link loss event when 283 * we're handling link loss 284 */ 285 bool is_handling_link_loss; 286 /** 287 * @is_handling_mst_msg_rdy_event: Used to prevent inserting mst message 288 * ready event when we're already handling mst message ready event 289 */ 290 bool is_handling_mst_msg_rdy_event; 291 /** 292 * @aconnector: The aconnector that this work queue is attached to 293 */ 294 struct amdgpu_dm_connector *aconnector; 295 }; 296 297 /** 298 * struct hpd_rx_irq_offload_work - hpd_rx_irq offload work structure 299 */ 300 struct hpd_rx_irq_offload_work { 301 /** 302 * @work: offload work 303 */ 304 struct work_struct work; 305 /** 306 * @data: reference irq data which is used while handling offload work 307 */ 308 union hpd_irq_data data; 309 /** 310 * @offload_wq: offload work queue that this work is queued to 311 */ 312 struct hpd_rx_irq_offload_work_queue *offload_wq; 313 /** 314 * @adev: amdgpu_device pointer 315 */ 316 struct amdgpu_device *adev; 317 }; 318 319 /** 320 * struct amdgpu_display_manager - Central amdgpu display manager device 321 * 322 * @dc: Display Core control structure 323 * @adev: AMDGPU base driver structure 324 * @ddev: DRM base driver structure 325 * @display_indexes_num: Max number of display streams supported 326 * @irq_handler_list_table_lock: Synchronizes access to IRQ tables 327 * @irq_wq: Dedicated high-priority unbound workqueue for deferred IRQ work 328 * @vmin_vmax_wq: Dedicated unbound workqueue for deferred vmin/vmax updates 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 * @dmub_lock: 468 * 469 * Guards access to DMUB command submission. 470 */ 471 spinlock_t dmub_lock; 472 473 /** 474 * @audio_lock: 475 * 476 * Guards access to audio instance changes. 477 */ 478 struct mutex audio_lock; 479 480 /** 481 * @audio_component: 482 * 483 * Used to notify ELD changes to sound driver. 484 */ 485 struct drm_audio_component *audio_component; 486 487 /** 488 * @audio_registered: 489 * 490 * True if the audio component has been registered 491 * successfully, false otherwise. 492 */ 493 bool audio_registered; 494 495 /** 496 * @irq_handler_list_low_tab: 497 * 498 * Low priority IRQ handler table. 499 * 500 * It is a n*m table consisting of n IRQ sources, and m handlers per IRQ 501 * source. Low priority IRQ handlers are deferred to a workqueue to be 502 * processed. Hence, they can sleep. 503 * 504 * Note that handlers are called in the same order as they were 505 * registered (FIFO). 506 */ 507 struct list_head irq_handler_list_low_tab[DAL_IRQ_SOURCES_NUMBER]; 508 509 /** 510 * @irq_handler_list_high_tab: 511 * 512 * High priority IRQ handler table. 513 * 514 * It is a n*m table, same as &irq_handler_list_low_tab. However, 515 * handlers in this table are not deferred and are called immediately. 516 */ 517 struct list_head irq_handler_list_high_tab[DAL_IRQ_SOURCES_NUMBER]; 518 519 /** 520 * @pflip_params: 521 * 522 * Page flip IRQ parameters, passed to registered handlers when 523 * triggered. 524 */ 525 struct common_irq_params 526 pflip_params[DC_IRQ_SOURCE_PFLIP_LAST - DC_IRQ_SOURCE_PFLIP_FIRST + 1]; 527 528 /** 529 * @vblank_params: 530 * 531 * Vertical blanking IRQ parameters, passed to registered handlers when 532 * triggered. 533 */ 534 struct common_irq_params 535 vblank_params[DC_IRQ_SOURCE_VBLANK6 - DC_IRQ_SOURCE_VBLANK1 + 1]; 536 537 /** 538 * @vline0_params: 539 * 540 * OTG vertical interrupt0 IRQ parameters, passed to registered 541 * handlers when triggered. 542 */ 543 struct common_irq_params 544 vline0_params[DC_IRQ_SOURCE_DC6_VLINE0 - DC_IRQ_SOURCE_DC1_VLINE0 + 1]; 545 546 /** 547 * @vupdate_params: 548 * 549 * Vertical update IRQ parameters, passed to registered handlers when 550 * triggered. 551 */ 552 struct common_irq_params 553 vupdate_params[DC_IRQ_SOURCE_VUPDATE6 - DC_IRQ_SOURCE_VUPDATE1 + 1]; 554 555 /** 556 * @dmub_trace_params: 557 * 558 * DMUB trace event IRQ parameters, passed to registered handlers when 559 * triggered. 560 */ 561 struct common_irq_params 562 dmub_trace_params[1]; 563 564 struct common_irq_params 565 dmub_outbox_params[1]; 566 567 spinlock_t irq_handler_list_table_lock; 568 struct workqueue_struct *irq_wq; 569 struct workqueue_struct *vmin_vmax_wq; 570 571 struct backlight_device *backlight_dev[AMDGPU_DM_MAX_NUM_EDP]; 572 573 const struct dc_link *backlight_link[AMDGPU_DM_MAX_NUM_EDP]; 574 575 uint8_t num_of_edps; 576 577 struct amdgpu_dm_backlight_caps backlight_caps[AMDGPU_DM_MAX_NUM_EDP]; 578 579 struct mod_freesync *freesync_module; 580 struct mod_power *power_module; 581 struct hdcp_workqueue *hdcp_workqueue; 582 583 /** 584 * @vblank_control_workqueue: 585 * 586 * Deferred work for vblank control events. 587 */ 588 struct workqueue_struct *vblank_control_workqueue; 589 590 /** 591 * @idle_workqueue: 592 * 593 * Periodic work for idle events. 594 */ 595 struct idle_workqueue *idle_workqueue; 596 597 struct drm_atomic_commit *cached_state; 598 struct dc_state *cached_dc_state; 599 600 struct dm_compressor_info compressor; 601 602 const struct firmware *fw_dmcu; 603 uint32_t dmcu_fw_version; 604 /** 605 * @soc_bounding_box: 606 * 607 * gpu_info FW provided soc bounding box struct or 0 if not 608 * available in FW 609 */ 610 const struct gpu_info_soc_bounding_box_v1_0 *soc_bounding_box; 611 612 /** 613 * @active_vblank_irq_count: 614 * 615 * number of currently active vblank irqs 616 */ 617 uint32_t active_vblank_irq_count; 618 619 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY) 620 /** 621 * @secure_display_ctx: 622 * 623 * Store secure display relevant info. e.g. the ROI information 624 * , the work_struct to command dmub, etc. 625 */ 626 struct secure_display_context secure_display_ctx; 627 #endif 628 /** 629 * @hpd_rx_offload_wq: 630 * 631 * Work queue to offload works of hpd_rx_irq 632 */ 633 struct hpd_rx_irq_offload_work_queue *hpd_rx_offload_wq; 634 /** 635 * @mst_encoders: 636 * 637 * fake encoders used for DP MST. 638 */ 639 struct amdgpu_encoder mst_encoders[AMDGPU_DM_MAX_CRTC]; 640 bool force_timing_sync; 641 bool disable_hpd_irq; 642 bool dmcub_trace_event_en; 643 /** 644 * @da_list: 645 * 646 * DAL fb memory allocation list, for communication with SMU. 647 */ 648 struct list_head da_list; 649 struct completion dmub_aux_transfer_done; 650 struct workqueue_struct *delayed_hpd_wq; 651 652 /** 653 * @brightness: 654 * 655 * cached backlight values. 656 */ 657 u32 brightness[AMDGPU_DM_MAX_NUM_EDP]; 658 /** 659 * @actual_brightness: 660 * 661 * last successfully applied backlight values. 662 */ 663 u32 actual_brightness[AMDGPU_DM_MAX_NUM_EDP]; 664 665 /** 666 * @aux_hpd_discon_quirk: 667 * 668 * quirk for hpd discon while aux is on-going. 669 * occurred on certain intel platform 670 */ 671 bool aux_hpd_discon_quirk; 672 673 /** 674 * @edp0_on_dp1_quirk: 675 * 676 * quirk for platforms that put edp0 on DP1. 677 */ 678 bool edp0_on_dp1_quirk; 679 680 /** 681 * @dpia_aux_lock: 682 * 683 * Guards access to DPIA AUX 684 */ 685 struct mutex dpia_aux_lock; 686 687 /** 688 * @bb_from_dmub: 689 * 690 * Bounding box data read from dmub during early initialization for DCN4+ 691 * Data is stored as a byte array that should be casted to the appropriate bb struct 692 */ 693 void *bb_from_dmub; 694 695 /** 696 * @i2c_devres_group: 697 * 698 * Devres group for DM i2c adapter lifetime management. 699 */ 700 void *i2c_devres_group; 701 702 /** 703 * @oem_i2c: 704 * 705 * OEM i2c bus 706 */ 707 struct amdgpu_i2c_adapter *oem_i2c; 708 709 /** 710 * @fused_io: 711 * 712 * dmub fused io interface 713 */ 714 struct fused_io_sync { 715 struct completion replied; 716 char reply_data[0x40]; // Cannot include dmub_cmd here 717 } fused_io[8]; 718 /** 719 * @hdmi_frl_status_polling_work: 720 * 721 * workqueue for 200ms frl status polling 722 */ 723 struct workqueue_struct *hdmi_frl_status_polling_wq; 724 struct delayed_work hdmi_frl_status_polling_work; 725 unsigned int hdmi_frl_status_polling_delay_ms; 726 727 /** 728 * @dm_boot_time_crc_info: 729 * 730 * Buffer info for the boot time crc. 731 */ 732 struct dm_boot_time_crc_info boot_time_crc_info; 733 }; 734 735 enum dsc_clock_force_state { 736 DSC_CLK_FORCE_DEFAULT = 0, 737 DSC_CLK_FORCE_ENABLE, 738 DSC_CLK_FORCE_DISABLE, 739 }; 740 741 struct dsc_preferred_settings { 742 enum dsc_clock_force_state dsc_force_enable; 743 uint32_t dsc_num_slices_v; 744 uint32_t dsc_num_slices_h; 745 uint32_t dsc_bits_per_pixel; 746 bool dsc_force_disable_passthrough; 747 }; 748 749 enum mst_progress_status { 750 MST_STATUS_DEFAULT = 0, 751 MST_PROBE = BIT(0), 752 MST_REMOTE_EDID = BIT(1), 753 MST_ALLOCATE_NEW_PAYLOAD = BIT(2), 754 MST_CLEAR_ALLOCATED_PAYLOAD = BIT(3), 755 }; 756 757 /** 758 * struct amdgpu_hdmi_vsdb_info - Keep track of the VSDB info 759 * 760 * AMDGPU supports FreeSync over HDMI by using the VSDB section, and this 761 * struct is useful to keep track of the display-specific information about 762 * FreeSync. 763 */ 764 struct amdgpu_hdmi_vsdb_info { 765 /** 766 * @amd_vsdb_version: Vendor Specific Data Block Version, should be 767 * used to determine which Vendor Specific InfoFrame (VSIF) to send. 768 */ 769 unsigned int amd_vsdb_version; 770 771 /** 772 * @freesync_supported: FreeSync Supported. 773 */ 774 bool freesync_supported; 775 776 /** 777 * @min_refresh_rate_hz: FreeSync Minimum Refresh Rate in Hz. 778 */ 779 unsigned int min_refresh_rate_hz; 780 781 /** 782 * @max_refresh_rate_hz: FreeSync Maximum Refresh Rate in Hz 783 */ 784 unsigned int max_refresh_rate_hz; 785 786 /** 787 * @freesync_mccs_vcp_code: MCCS VCP code for freesync state 788 */ 789 unsigned int freesync_mccs_vcp_code; 790 791 /** 792 * @replay_mode: Replay supported 793 */ 794 bool replay_mode; 795 }; 796 797 struct amdgpu_dm_connector { 798 799 struct drm_connector base; 800 uint32_t connector_id; 801 int bl_idx; 802 803 struct cec_notifier *notifier; 804 805 /* we need to mind the EDID between detect 806 and get modes due to analog/digital/tvencoder */ 807 const struct drm_edid *drm_edid; 808 809 /* shared with amdgpu */ 810 struct amdgpu_hpd hpd; 811 812 /* number of modes generated from EDID at 'dc_sink' */ 813 int num_modes; 814 815 /* The 'old' sink - before an HPD. 816 * The 'current' sink is in dc_link->sink. */ 817 struct dc_sink *dc_sink; 818 struct dc_link *dc_link; 819 820 /** 821 * @dc_em_sink: Reference to the emulated (virtual) sink. 822 */ 823 struct dc_sink *dc_em_sink; 824 825 /* DM only */ 826 struct drm_dp_mst_topology_mgr mst_mgr; 827 struct amdgpu_dm_dp_aux dm_dp_aux; 828 struct drm_dp_mst_port *mst_output_port; 829 struct amdgpu_dm_connector *mst_root; 830 struct drm_dp_aux *dsc_aux; 831 uint32_t mst_local_bw; 832 uint16_t vc_full_pbn; 833 struct mutex handle_mst_msg_ready; 834 835 /* branch device specific data */ 836 uint32_t branch_ieee_oui; 837 838 /* TODO see if we can merge with ddc_bus or make a dm_connector */ 839 struct amdgpu_i2c_adapter *i2c; 840 841 /* Monitor range limits */ 842 /** 843 * @min_vfreq: Minimal frequency supported by the display in Hz. This 844 * value is set to zero when there is no FreeSync support. 845 */ 846 int min_vfreq; 847 848 /** 849 * @max_vfreq: Maximum frequency supported by the display in Hz. This 850 * value is set to zero when there is no FreeSync support. 851 */ 852 int max_vfreq ; 853 854 /* Audio instance - protected by audio_lock. */ 855 int audio_inst; 856 857 struct mutex hpd_lock; 858 859 bool fake_enable; 860 bool force_yuv420_output; 861 bool force_yuv422_output; 862 uint8_t force_yuv_pixel_format; 863 struct dsc_preferred_settings dsc_settings; 864 struct psr_caps psr_caps; 865 union dp_downstream_port_present mst_downstream_port_present; 866 /* Cached display modes */ 867 struct drm_display_mode freesync_vid_base; 868 869 int sr_skip_count; 870 bool disallow_edp_enter_psr; 871 bool disallow_edp_enter_replay; 872 873 union dwnstream_portxcaps mst_downstream_port_caps; 874 875 /* Record progress status of mst*/ 876 uint8_t mst_status; 877 878 /* Automated testing */ 879 bool timing_changed; 880 struct dc_crtc_timing *timing_requested; 881 882 /* Adaptive Sync */ 883 bool pack_sdp_v1_3; 884 enum adaptive_sync_type as_type; 885 struct amdgpu_hdmi_vsdb_info vsdb_info; 886 887 /* HDMI HPD debounce support */ 888 unsigned int hdmi_hpd_debounce_delay_ms; 889 struct delayed_work hdmi_hpd_debounce_work; 890 struct dc_sink *hdmi_prev_sink; 891 892 /* HDMI compliance automation */ 893 bool hdmi_comp_auto; 894 }; 895 896 static inline void amdgpu_dm_set_mst_status(uint8_t *status, 897 uint8_t flags, bool set) 898 { 899 if (set) 900 *status |= flags; 901 else 902 *status &= ~flags; 903 } 904 905 #define to_amdgpu_dm_connector(x) container_of(x, struct amdgpu_dm_connector, base) 906 907 struct amdgpu_dm_wb_connector { 908 struct drm_writeback_connector base; 909 struct dc_link *link; 910 }; 911 912 #define to_amdgpu_dm_wb_connector(x) container_of(x, struct amdgpu_dm_wb_connector, base) 913 914 extern const struct amdgpu_ip_block_version dm_ip_block; 915 916 /* enum amdgpu_transfer_function: pre-defined transfer function supported by AMD. 917 * 918 * It includes standardized transfer functions and pure power functions. The 919 * transfer function coefficients are available at modules/color/color_gamma.c 920 */ 921 enum amdgpu_transfer_function { 922 AMDGPU_TRANSFER_FUNCTION_DEFAULT, 923 AMDGPU_TRANSFER_FUNCTION_SRGB_EOTF, 924 AMDGPU_TRANSFER_FUNCTION_BT709_INV_OETF, 925 AMDGPU_TRANSFER_FUNCTION_PQ_EOTF, 926 AMDGPU_TRANSFER_FUNCTION_IDENTITY, 927 AMDGPU_TRANSFER_FUNCTION_GAMMA22_EOTF, 928 AMDGPU_TRANSFER_FUNCTION_GAMMA24_EOTF, 929 AMDGPU_TRANSFER_FUNCTION_GAMMA26_EOTF, 930 AMDGPU_TRANSFER_FUNCTION_SRGB_INV_EOTF, 931 AMDGPU_TRANSFER_FUNCTION_BT709_OETF, 932 AMDGPU_TRANSFER_FUNCTION_PQ_INV_EOTF, 933 AMDGPU_TRANSFER_FUNCTION_GAMMA22_INV_EOTF, 934 AMDGPU_TRANSFER_FUNCTION_GAMMA24_INV_EOTF, 935 AMDGPU_TRANSFER_FUNCTION_GAMMA26_INV_EOTF, 936 AMDGPU_TRANSFER_FUNCTION_COUNT 937 }; 938 939 struct dm_plane_state { 940 struct drm_plane_state base; 941 struct dc_plane_state *dc_state; 942 943 /* Plane color mgmt */ 944 /** 945 * @degamma_lut: 946 * 947 * 1D LUT for mapping framebuffer/plane pixel data before sampling or 948 * blending operations. It's usually applied to linearize input space. 949 * The blob (if not NULL) is an array of &struct drm_color_lut. 950 */ 951 struct drm_property_blob *degamma_lut; 952 /** 953 * @degamma_tf: 954 * 955 * Predefined transfer function to tell DC driver the input space to 956 * linearize. 957 */ 958 enum amdgpu_transfer_function degamma_tf; 959 /** 960 * @hdr_mult: 961 * 962 * Multiplier to 'gain' the plane. When PQ is decoded using the fixed 963 * func transfer function to the internal FP16 fb, 1.0 -> 80 nits (on 964 * AMD at least). When sRGB is decoded, 1.0 -> 1.0, obviously. 965 * Therefore, 1.0 multiplier = 80 nits for SDR content. So if you 966 * want, 203 nits for SDR content, pass in (203.0 / 80.0). Format is 967 * S31.32 sign-magnitude. 968 * 969 * HDR multiplier can wide range beyond [0.0, 1.0]. This means that PQ 970 * TF is needed for any subsequent linear-to-non-linear transforms. 971 */ 972 __u64 hdr_mult; 973 /** 974 * @ctm: 975 * 976 * Color transformation matrix. The blob (if not NULL) is a &struct 977 * drm_color_ctm_3x4. 978 */ 979 struct drm_property_blob *ctm; 980 /** 981 * @shaper_lut: shaper lookup table blob. The blob (if not NULL) is an 982 * array of &struct drm_color_lut. 983 */ 984 struct drm_property_blob *shaper_lut; 985 /** 986 * @shaper_tf: 987 * 988 * Predefined transfer function to delinearize color space. 989 */ 990 enum amdgpu_transfer_function shaper_tf; 991 /** 992 * @lut3d: 3D lookup table blob. The blob (if not NULL) is an array of 993 * &struct drm_color_lut. 994 */ 995 struct drm_property_blob *lut3d; 996 /** 997 * @blend_lut: blend lut lookup table blob. The blob (if not NULL) is an 998 * array of &struct drm_color_lut. 999 */ 1000 struct drm_property_blob *blend_lut; 1001 /** 1002 * @blend_tf: 1003 * 1004 * Pre-defined transfer function for converting plane pixel data before 1005 * applying blend LUT. 1006 */ 1007 enum amdgpu_transfer_function blend_tf; 1008 }; 1009 1010 enum amdgpu_dm_cursor_mode { 1011 DM_CURSOR_NATIVE_MODE = 0, 1012 DM_CURSOR_OVERLAY_MODE, 1013 }; 1014 1015 struct dm_crtc_state { 1016 struct drm_crtc_state base; 1017 struct dc_stream_state *stream; 1018 1019 bool cm_has_degamma; 1020 bool cm_is_degamma_srgb; 1021 1022 bool mpo_requested; 1023 1024 int update_type; 1025 int active_planes; 1026 1027 int crc_skip_count; 1028 1029 bool freesync_vrr_info_changed; 1030 1031 bool mode_changed_independent_from_dsc; 1032 bool dsc_force_changed; 1033 bool vrr_supported; 1034 struct mod_freesync_config freesync_config; 1035 struct dc_info_packet vrr_infopacket; 1036 1037 int abm_level; 1038 1039 /** 1040 * @regamma_tf: 1041 * 1042 * Pre-defined transfer function for converting internal FB -> wire 1043 * encoding. 1044 */ 1045 enum amdgpu_transfer_function regamma_tf; 1046 1047 enum amdgpu_dm_cursor_mode cursor_mode; 1048 }; 1049 1050 #define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base) 1051 1052 struct dm_atomic_state { 1053 struct drm_private_state base; 1054 1055 struct dc_state *context; 1056 }; 1057 1058 #define to_dm_atomic_state(x) container_of(x, struct dm_atomic_state, base) 1059 1060 struct dm_connector_state { 1061 struct drm_connector_state base; 1062 1063 enum amdgpu_rmx_type scaling; 1064 uint8_t underscan_vborder; 1065 uint8_t underscan_hborder; 1066 bool underscan_enable; 1067 bool freesync_capable; 1068 bool update_hdcp; 1069 bool abm_sysfs_forbidden; 1070 uint8_t abm_level; 1071 int vcpi_slots; 1072 uint64_t pbn; 1073 }; 1074 1075 #define to_dm_connector_state(x)\ 1076 container_of((x), struct dm_connector_state, base) 1077 1078 #include "amdgpu_dm_connector.h" 1079 1080 void amdgpu_dm_trigger_timing_sync(struct drm_device *dev); 1081 1082 /* 3D LUT max size is 17x17x17 (4913 entries) */ 1083 #define MAX_COLOR_3DLUT_SIZE 17 1084 #define MAX_COLOR_3DLUT_BITDEPTH 12 1085 int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev, 1086 struct drm_plane_state *plane_state); 1087 /* 1D LUT size */ 1088 #define MAX_COLOR_LUT_ENTRIES 4096 1089 /* Legacy gamm LUT users such as X doesn't like large LUT sizes */ 1090 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256 1091 1092 void amdgpu_dm_init_color_mod(void); 1093 int amdgpu_dm_create_color_properties(struct amdgpu_device *adev); 1094 int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state); 1095 int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc); 1096 int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state *crtc, 1097 bool check_only); 1098 int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc, 1099 struct drm_plane_state *plane_state, 1100 struct dc_plane_state *dc_plane_state); 1101 1102 void populate_hdmi_info_from_connector(bool enable_frl, struct drm_hdmi_info *info, 1103 struct dc_edid_caps *edid_caps); 1104 1105 int amdgpu_dm_process_dmub_aux_transfer_sync(struct dc_context *ctx, unsigned int link_index, 1106 struct aux_payload *payload, enum aux_return_code_type *operation_result); 1107 1108 bool amdgpu_dm_execute_fused_io( 1109 struct amdgpu_device *dev, 1110 struct dc_link *link, 1111 union dmub_rb_cmd *commands, 1112 uint8_t count, 1113 uint32_t timeout_us 1114 ); 1115 1116 int amdgpu_dm_process_dmub_set_config_sync(struct dc_context *ctx, unsigned int link_index, 1117 struct set_config_cmd_payload *payload, enum set_config_status *operation_result); 1118 1119 int dm_atomic_get_state(struct drm_atomic_commit *state, 1120 struct dm_atomic_state **dm_state); 1121 1122 struct idle_workqueue *idle_create_workqueue(struct amdgpu_device *adev); 1123 1124 void *dm_allocate_gpu_mem(struct amdgpu_device *adev, 1125 enum dc_gpu_mem_alloc_type type, 1126 size_t size, 1127 long long *addr); 1128 void dm_free_gpu_mem(struct amdgpu_device *adev, 1129 enum dc_gpu_mem_alloc_type type, 1130 void *addr); 1131 1132 bool amdgpu_dm_is_headless(struct amdgpu_device *adev); 1133 1134 bool amdgpu_dm_crtc_complete_writeback(struct amdgpu_crtc *acrtc); 1135 1136 void retrieve_dmi_info(struct amdgpu_display_manager *dm); 1137 struct pci_dev; 1138 bool dm_should_disable_stutter(struct pci_dev *pdev); 1139 1140 void amdgpu_dm_emulated_link_detect(struct dc_link *link); 1141 void amdgpu_dm_apply_delay_after_dpcd_poweroff(struct amdgpu_device *adev, 1142 struct dc_sink *sink); 1143 1144 struct __drm_planes_state *amdgpu_dm_get_next_zpos(struct drm_atomic_commit *state, 1145 struct __drm_planes_state *prev); 1146 1147 /* 1148 * Use the uniqueness of the plane's (zpos, drm obj ID) combination to iterate 1149 * by descending zpos, as read from the new plane state. This is the same 1150 * ordering as defined by drm_atomic_normalize_zpos(). 1151 */ 1152 #define for_each_oldnew_plane_in_descending_zpos(__state, plane, old_plane_state, new_plane_state) \ 1153 for (struct __drm_planes_state *__i = amdgpu_dm_get_next_zpos((__state), NULL); \ 1154 __i != NULL; __i = amdgpu_dm_get_next_zpos((__state), __i)) \ 1155 for_each_if(((plane) = __i->ptr, \ 1156 (void)(plane) /* Only to avoid unused-but-set-variable warning */, \ 1157 (old_plane_state) = __i->old_state, \ 1158 (new_plane_state) = __i->new_state, 1)) 1159 1160 #if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST) 1161 struct amdgpu_ip_block; 1162 bool dm_is_idle(struct amdgpu_ip_block *ip_block); 1163 int dm_wait_for_idle(struct amdgpu_ip_block *ip_block); 1164 int dm_soft_reset(struct amdgpu_ip_block *ip_block); 1165 int dm_set_clockgating_state(struct amdgpu_ip_block *ip_block, 1166 enum amd_clockgating_state state); 1167 int dm_set_powergating_state(struct amdgpu_ip_block *ip_block, 1168 enum amd_powergating_state state); 1169 void dm_bandwidth_update(struct amdgpu_device *adev); 1170 u32 dm_vblank_get_counter(struct amdgpu_device *adev, int crtc); 1171 int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc, 1172 u32 *vbl, u32 *position); 1173 struct dm_atomic_state *dm_atomic_get_new_state(struct drm_atomic_commit *state); 1174 void dm_atomic_destroy_state(struct drm_private_obj *obj, 1175 struct drm_private_state *state); 1176 int dm_plane_layer_index_cmp(const void *a, const void *b); 1177 int fill_plane_color_attributes(const struct drm_plane_state *plane_state, 1178 const enum surface_pixel_format format, 1179 enum dc_color_space *color_space); 1180 bool modereset_required(struct drm_crtc_state *crtc_state); 1181 bool is_scaling_state_different(const struct dm_connector_state *dm_state, 1182 const struct dm_connector_state *old_dm_state); 1183 void set_multisync_trigger_params(struct dc_stream_state *stream); 1184 void set_master_stream(struct dc_stream_state *stream_set[], int stream_count); 1185 void dm_enable_per_frame_crtc_master_sync(struct dc_state *context); 1186 struct hdcp_workqueue; 1187 bool is_content_protection_different(struct drm_crtc_state *new_crtc_state, 1188 struct drm_crtc_state *old_crtc_state, 1189 struct drm_connector_state *new_conn_state, 1190 struct drm_connector_state *old_conn_state, 1191 const struct drm_connector *connector, 1192 struct hdcp_workqueue *hdcp_w); 1193 #endif 1194 1195 #endif /* __AMDGPU_DM_H__ */ 1196