1 /* 2 * Copyright 2015 Advanced Micro Devices, Inc. 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/drmP.h> 30 #include <drm/drm_atomic.h> 31 32 /* 33 * This file contains the definition for amdgpu_display_manager 34 * and its API for amdgpu driver's use. 35 * This component provides all the display related functionality 36 * and this is the only component that calls DAL API. 37 * The API contained here intended for amdgpu driver use. 38 * The API that is called directly from KMS framework is located 39 * in amdgpu_dm_kms.h file 40 */ 41 42 #define AMDGPU_DM_MAX_DISPLAY_INDEX 31 43 /* 44 #include "include/amdgpu_dal_power_if.h" 45 #include "amdgpu_dm_irq.h" 46 */ 47 48 #include "irq_types.h" 49 #include "signal_types.h" 50 51 /* Forward declarations */ 52 struct amdgpu_device; 53 struct drm_device; 54 struct amdgpu_dm_irq_handler_data; 55 struct dc; 56 57 struct common_irq_params { 58 struct amdgpu_device *adev; 59 enum dc_irq_source irq_src; 60 }; 61 62 /** 63 * struct irq_list_head - Linked-list for low context IRQ handlers. 64 * 65 * @head: The list_head within &struct handler_data 66 * @work: A work_struct containing the deferred handler work 67 */ 68 struct irq_list_head { 69 struct list_head head; 70 /* In case this interrupt needs post-processing, 'work' will be queued*/ 71 struct work_struct work; 72 }; 73 74 /** 75 * struct dm_compressor_info - Buffer info used by frame buffer compression 76 * @cpu_addr: MMIO cpu addr 77 * @bo_ptr: Pointer to the buffer object 78 * @gpu_addr: MMIO gpu addr 79 */ 80 struct dm_comressor_info { 81 void *cpu_addr; 82 struct amdgpu_bo *bo_ptr; 83 uint64_t gpu_addr; 84 }; 85 86 /** 87 * struct amdgpu_dm_backlight_caps - Usable range of backlight values from ACPI 88 * @min_input_signal: minimum possible input in range 0-255 89 * @max_input_signal: maximum possible input in range 0-255 90 * @caps_valid: true if these values are from the ACPI interface 91 */ 92 struct amdgpu_dm_backlight_caps { 93 int min_input_signal; 94 int max_input_signal; 95 bool caps_valid; 96 }; 97 98 /** 99 * struct amdgpu_display_manager - Central amdgpu display manager device 100 * 101 * @dc: Display Core control structure 102 * @adev: AMDGPU base driver structure 103 * @ddev: DRM base driver structure 104 * @display_indexes_num: Max number of display streams supported 105 * @irq_handler_list_table_lock: Synchronizes access to IRQ tables 106 * @backlight_dev: Backlight control device 107 * @cached_state: Caches device atomic state for suspend/resume 108 * @compressor: Frame buffer compression buffer. See &struct dm_comressor_info 109 */ 110 struct amdgpu_display_manager { 111 112 struct dc *dc; 113 114 /** 115 * @cgs_device: 116 * 117 * The Common Graphics Services device. It provides an interface for 118 * accessing registers. 119 */ 120 struct cgs_device *cgs_device; 121 122 struct amdgpu_device *adev; 123 struct drm_device *ddev; 124 u16 display_indexes_num; 125 126 /** 127 * @atomic_obj 128 * 129 * In combination with &dm_atomic_state it helps manage 130 * global atomic state that doesn't map cleanly into existing 131 * drm resources, like &dc_context. 132 */ 133 struct drm_private_obj atomic_obj; 134 135 struct drm_modeset_lock atomic_obj_lock; 136 137 /** 138 * @irq_handler_list_low_tab: 139 * 140 * Low priority IRQ handler table. 141 * 142 * It is a n*m table consisting of n IRQ sources, and m handlers per IRQ 143 * source. Low priority IRQ handlers are deferred to a workqueue to be 144 * processed. Hence, they can sleep. 145 * 146 * Note that handlers are called in the same order as they were 147 * registered (FIFO). 148 */ 149 struct irq_list_head irq_handler_list_low_tab[DAL_IRQ_SOURCES_NUMBER]; 150 151 /** 152 * @irq_handler_list_high_tab: 153 * 154 * High priority IRQ handler table. 155 * 156 * It is a n*m table, same as &irq_handler_list_low_tab. However, 157 * handlers in this table are not deferred and are called immediately. 158 */ 159 struct list_head irq_handler_list_high_tab[DAL_IRQ_SOURCES_NUMBER]; 160 161 /** 162 * @pflip_params: 163 * 164 * Page flip IRQ parameters, passed to registered handlers when 165 * triggered. 166 */ 167 struct common_irq_params 168 pflip_params[DC_IRQ_SOURCE_PFLIP_LAST - DC_IRQ_SOURCE_PFLIP_FIRST + 1]; 169 170 /** 171 * @vblank_params: 172 * 173 * Vertical blanking IRQ parameters, passed to registered handlers when 174 * triggered. 175 */ 176 struct common_irq_params 177 vblank_params[DC_IRQ_SOURCE_VBLANK6 - DC_IRQ_SOURCE_VBLANK1 + 1]; 178 179 spinlock_t irq_handler_list_table_lock; 180 181 struct backlight_device *backlight_dev; 182 183 const struct dc_link *backlight_link; 184 struct amdgpu_dm_backlight_caps backlight_caps; 185 186 struct mod_freesync *freesync_module; 187 188 struct drm_atomic_state *cached_state; 189 190 struct dm_comressor_info compressor; 191 192 const struct firmware *fw_dmcu; 193 uint32_t dmcu_fw_version; 194 }; 195 196 struct amdgpu_dm_connector { 197 198 struct drm_connector base; 199 uint32_t connector_id; 200 201 /* we need to mind the EDID between detect 202 and get modes due to analog/digital/tvencoder */ 203 struct edid *edid; 204 205 /* shared with amdgpu */ 206 struct amdgpu_hpd hpd; 207 208 /* number of modes generated from EDID at 'dc_sink' */ 209 int num_modes; 210 211 /* The 'old' sink - before an HPD. 212 * The 'current' sink is in dc_link->sink. */ 213 struct dc_sink *dc_sink; 214 struct dc_link *dc_link; 215 struct dc_sink *dc_em_sink; 216 217 /* DM only */ 218 struct drm_dp_mst_topology_mgr mst_mgr; 219 struct amdgpu_dm_dp_aux dm_dp_aux; 220 struct drm_dp_mst_port *port; 221 struct amdgpu_dm_connector *mst_port; 222 struct amdgpu_encoder *mst_encoder; 223 224 /* TODO see if we can merge with ddc_bus or make a dm_connector */ 225 struct amdgpu_i2c_adapter *i2c; 226 227 /* Monitor range limits */ 228 int min_vfreq ; 229 int max_vfreq ; 230 int pixel_clock_mhz; 231 232 struct mutex hpd_lock; 233 234 bool fake_enable; 235 }; 236 237 #define to_amdgpu_dm_connector(x) container_of(x, struct amdgpu_dm_connector, base) 238 239 extern const struct amdgpu_ip_block_version dm_ip_block; 240 241 struct amdgpu_framebuffer; 242 struct amdgpu_display_manager; 243 struct dc_validation_set; 244 struct dc_plane_state; 245 246 struct dm_plane_state { 247 struct drm_plane_state base; 248 struct dc_plane_state *dc_state; 249 }; 250 251 struct dm_crtc_state { 252 struct drm_crtc_state base; 253 struct dc_stream_state *stream; 254 255 int crc_skip_count; 256 bool crc_enabled; 257 258 bool freesync_timing_changed; 259 bool freesync_vrr_info_changed; 260 261 bool vrr_supported; 262 struct mod_freesync_config freesync_config; 263 struct dc_crtc_timing_adjust adjust; 264 struct dc_info_packet vrr_infopacket; 265 266 int abm_level; 267 }; 268 269 #define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base) 270 271 struct dm_atomic_state { 272 struct drm_private_state base; 273 274 struct dc_state *context; 275 }; 276 277 #define to_dm_atomic_state(x) container_of(x, struct dm_atomic_state, base) 278 279 struct dm_connector_state { 280 struct drm_connector_state base; 281 282 enum amdgpu_rmx_type scaling; 283 uint8_t underscan_vborder; 284 uint8_t underscan_hborder; 285 uint8_t max_bpc; 286 bool underscan_enable; 287 bool freesync_capable; 288 uint8_t abm_level; 289 }; 290 291 #define to_dm_connector_state(x)\ 292 container_of((x), struct dm_connector_state, base) 293 294 void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector); 295 struct drm_connector_state * 296 amdgpu_dm_connector_atomic_duplicate_state(struct drm_connector *connector); 297 int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector, 298 struct drm_connector_state *state, 299 struct drm_property *property, 300 uint64_t val); 301 302 int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector, 303 const struct drm_connector_state *state, 304 struct drm_property *property, 305 uint64_t *val); 306 307 int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev); 308 309 void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm, 310 struct amdgpu_dm_connector *aconnector, 311 int connector_type, 312 struct dc_link *link, 313 int link_index); 314 315 enum drm_mode_status amdgpu_dm_connector_mode_valid(struct drm_connector *connector, 316 struct drm_display_mode *mode); 317 318 void dm_restore_drm_connector_state(struct drm_device *dev, 319 struct drm_connector *connector); 320 321 void amdgpu_dm_update_freesync_caps(struct drm_connector *connector, 322 struct edid *edid); 323 324 /* amdgpu_dm_crc.c */ 325 #ifdef CONFIG_DEBUG_FS 326 int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name); 327 int amdgpu_dm_crtc_verify_crc_source(struct drm_crtc *crtc, 328 const char *src_name, 329 size_t *values_cnt); 330 void amdgpu_dm_crtc_handle_crc_irq(struct drm_crtc *crtc); 331 #else 332 #define amdgpu_dm_crtc_set_crc_source NULL 333 #define amdgpu_dm_crtc_verify_crc_source NULL 334 #define amdgpu_dm_crtc_handle_crc_irq(x) 335 #endif 336 337 #define MAX_COLOR_LUT_ENTRIES 4096 338 /* Legacy gamm LUT users such as X doesn't like large LUT sizes */ 339 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256 340 341 void amdgpu_dm_init_color_mod(void); 342 int amdgpu_dm_set_degamma_lut(struct drm_crtc_state *crtc_state, 343 struct dc_plane_state *dc_plane_state); 344 void amdgpu_dm_set_ctm(struct dm_crtc_state *crtc); 345 int amdgpu_dm_set_regamma_lut(struct dm_crtc_state *crtc); 346 347 extern const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs; 348 349 #endif /* __AMDGPU_DM_H__ */ 350