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