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 amdgpu_dm_prev_state { 58 struct drm_framebuffer *fb; 59 int32_t x; 60 int32_t y; 61 struct drm_display_mode mode; 62 }; 63 64 struct common_irq_params { 65 struct amdgpu_device *adev; 66 enum dc_irq_source irq_src; 67 }; 68 69 struct irq_list_head { 70 struct list_head head; 71 /* In case this interrupt needs post-processing, 'work' will be queued*/ 72 struct work_struct work; 73 }; 74 75 struct dm_comressor_info { 76 void *cpu_addr; 77 struct amdgpu_bo *bo_ptr; 78 uint64_t gpu_addr; 79 }; 80 81 82 struct amdgpu_display_manager { 83 struct dal *dal; 84 struct dc *dc; 85 struct cgs_device *cgs_device; 86 87 struct amdgpu_device *adev; /*AMD base driver*/ 88 struct drm_device *ddev; /*DRM base driver*/ 89 u16 display_indexes_num; 90 91 struct amdgpu_dm_prev_state prev_state; 92 93 /* 94 * 'irq_source_handler_table' holds a list of handlers 95 * per (DAL) IRQ source. 96 * 97 * Each IRQ source may need to be handled at different contexts. 98 * By 'context' we mean, for example: 99 * - The ISR context, which is the direct interrupt handler. 100 * - The 'deferred' context - this is the post-processing of the 101 * interrupt, but at a lower priority. 102 * 103 * Note that handlers are called in the same order as they were 104 * registered (FIFO). 105 */ 106 struct irq_list_head irq_handler_list_low_tab[DAL_IRQ_SOURCES_NUMBER]; 107 struct list_head irq_handler_list_high_tab[DAL_IRQ_SOURCES_NUMBER]; 108 109 struct common_irq_params 110 pflip_params[DC_IRQ_SOURCE_PFLIP_LAST - DC_IRQ_SOURCE_PFLIP_FIRST + 1]; 111 112 struct common_irq_params 113 vblank_params[DC_IRQ_SOURCE_VBLANK6 - DC_IRQ_SOURCE_VBLANK1 + 1]; 114 115 /* this spin lock synchronizes access to 'irq_handler_list_table' */ 116 spinlock_t irq_handler_list_table_lock; 117 118 struct backlight_device *backlight_dev; 119 120 const struct dc_link *backlight_link; 121 122 struct work_struct mst_hotplug_work; 123 124 struct mod_freesync *freesync_module; 125 126 /** 127 * Caches device atomic state for suspend/resume 128 */ 129 struct drm_atomic_state *cached_state; 130 131 struct dm_comressor_info compressor; 132 }; 133 134 struct amdgpu_dm_connector { 135 136 struct drm_connector base; 137 uint32_t connector_id; 138 139 /* we need to mind the EDID between detect 140 and get modes due to analog/digital/tvencoder */ 141 struct edid *edid; 142 143 /* shared with amdgpu */ 144 struct amdgpu_hpd hpd; 145 146 /* number of modes generated from EDID at 'dc_sink' */ 147 int num_modes; 148 149 /* The 'old' sink - before an HPD. 150 * The 'current' sink is in dc_link->sink. */ 151 struct dc_sink *dc_sink; 152 struct dc_link *dc_link; 153 struct dc_sink *dc_em_sink; 154 155 /* DM only */ 156 struct drm_dp_mst_topology_mgr mst_mgr; 157 struct amdgpu_dm_dp_aux dm_dp_aux; 158 struct drm_dp_mst_port *port; 159 struct amdgpu_dm_connector *mst_port; 160 struct amdgpu_encoder *mst_encoder; 161 162 /* TODO see if we can merge with ddc_bus or make a dm_connector */ 163 struct amdgpu_i2c_adapter *i2c; 164 165 /* Monitor range limits */ 166 int min_vfreq ; 167 int max_vfreq ; 168 int pixel_clock_mhz; 169 170 /*freesync caps*/ 171 struct mod_freesync_caps caps; 172 173 struct mutex hpd_lock; 174 175 bool fake_enable; 176 177 bool mst_connected; 178 }; 179 180 #define to_amdgpu_dm_connector(x) container_of(x, struct amdgpu_dm_connector, base) 181 182 extern const struct amdgpu_ip_block_version dm_ip_block; 183 184 struct amdgpu_framebuffer; 185 struct amdgpu_display_manager; 186 struct dc_validation_set; 187 struct dc_plane_state; 188 189 struct dm_plane_state { 190 struct drm_plane_state base; 191 struct dc_plane_state *dc_state; 192 }; 193 194 struct dm_crtc_state { 195 struct drm_crtc_state base; 196 struct dc_stream_state *stream; 197 198 int crc_skip_count; 199 bool crc_enabled; 200 }; 201 202 #define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base) 203 204 struct dm_atomic_state { 205 struct drm_atomic_state base; 206 207 struct dc_state *context; 208 }; 209 210 #define to_dm_atomic_state(x) container_of(x, struct dm_atomic_state, base) 211 212 struct dm_connector_state { 213 struct drm_connector_state base; 214 215 enum amdgpu_rmx_type scaling; 216 uint8_t underscan_vborder; 217 uint8_t underscan_hborder; 218 bool underscan_enable; 219 struct mod_freesync_user_enable user_enable; 220 bool freesync_capable; 221 }; 222 223 #define to_dm_connector_state(x)\ 224 container_of((x), struct dm_connector_state, base) 225 226 void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector); 227 struct drm_connector_state * 228 amdgpu_dm_connector_atomic_duplicate_state(struct drm_connector *connector); 229 int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector, 230 struct drm_connector_state *state, 231 struct drm_property *property, 232 uint64_t val); 233 234 int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector, 235 const struct drm_connector_state *state, 236 struct drm_property *property, 237 uint64_t *val); 238 239 int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev); 240 241 void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm, 242 struct amdgpu_dm_connector *aconnector, 243 int connector_type, 244 struct dc_link *link, 245 int link_index); 246 247 enum drm_mode_status amdgpu_dm_connector_mode_valid(struct drm_connector *connector, 248 struct drm_display_mode *mode); 249 250 void dm_restore_drm_connector_state(struct drm_device *dev, 251 struct drm_connector *connector); 252 253 void amdgpu_dm_add_sink_to_freesync_module(struct drm_connector *connector, 254 struct edid *edid); 255 256 void 257 amdgpu_dm_remove_sink_from_freesync_module(struct drm_connector *connector); 258 259 /* amdgpu_dm_crc.c */ 260 #ifdef CONFIG_DEBUG_FS 261 int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name, 262 size_t *values_cnt); 263 void amdgpu_dm_crtc_handle_crc_irq(struct drm_crtc *crtc); 264 #else 265 #define amdgpu_dm_crtc_set_crc_source NULL 266 #define amdgpu_dm_crtc_handle_crc_irq(x) 267 #endif 268 269 #define MAX_COLOR_LUT_ENTRIES 4096 270 /* Legacy gamm LUT users such as X doesn't like large LUT sizes */ 271 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256 272 273 void amdgpu_dm_init_color_mod(void); 274 int amdgpu_dm_set_degamma_lut(struct drm_crtc_state *crtc_state, 275 struct dc_plane_state *dc_plane_state); 276 void amdgpu_dm_set_ctm(struct dm_crtc_state *crtc); 277 int amdgpu_dm_set_regamma_lut(struct dm_crtc_state *crtc); 278 279 extern const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs; 280 281 #endif /* __AMDGPU_DM_H__ */ 282