1 /* 2 * Copyright 2022 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 __DC_LINK_H__ 27 #define __DC_LINK_H__ 28 29 /* FILE POLICY AND INTENDED USAGE: 30 * 31 * This header declares link functions exposed to dc. All functions must use 32 * function pointers. This header is strictly private in dc and should never be 33 * included by DM. If DM needs to call a new link function, it needs to be 34 * translated by dc_link_exports.c. 35 */ 36 #include "core_types.h" 37 38 struct link_init_data { 39 const struct dc *dc; 40 struct dc_context *ctx; /* TODO: remove 'dal' when DC is complete. */ 41 uint32_t connector_index; /* this will be mapped to the HPD pins */ 42 uint32_t link_index; /* this is mapped to DAL display_index 43 TODO: remove it when DC is complete. */ 44 bool is_dpia_link; 45 }; 46 47 struct link_service { 48 /* Detection */ 49 struct dc_sink *(*add_remote_sink)( 50 struct dc_link *link, 51 const uint8_t *edid, 52 int len, 53 struct dc_sink_init_data *init_data); 54 void (*remove_remote_sink)(struct dc_link *link, struct dc_sink *sink); 55 bool (*get_hpd_state)(struct dc_link *link); 56 void (*enable_hpd)(const struct dc_link *link); 57 void (*disable_hpd)(const struct dc_link *link); 58 void (*enable_hpd_filter)(struct dc_link *link, bool enable); 59 60 /* DDC */ 61 int (*aux_transfer_raw)(struct ddc_service *ddc, 62 struct aux_payload *payload, 63 enum aux_return_code_type *operation_result); 64 65 /* DP Capability */ 66 bool (*dp_is_sink_present)(struct dc_link *link); 67 bool (*dp_is_fec_supported)(const struct dc_link *link); 68 bool (*dp_get_max_link_enc_cap)(const struct dc_link *link, 69 struct dc_link_settings *max_link_enc_cap); 70 const struct dc_link_settings *(*dp_get_verified_link_cap)( 71 const struct dc_link *link); 72 bool (*dp_should_enable_fec)(const struct dc_link *link); 73 enum dp_link_encoding (*mst_decide_link_encoding_format)(const struct dc_link *link); 74 bool (*edp_decide_link_settings)(struct dc_link *link, 75 struct dc_link_settings *link_setting, uint32_t req_bw); 76 uint32_t (*bw_kbps_from_raw_frl_link_rate_data)(uint8_t bw); 77 bool (*dp_overwrite_extended_receiver_cap)(struct dc_link *link); 78 enum lttpr_mode (*dp_decide_lttpr_mode)(struct dc_link *link, 79 struct dc_link_settings *link_setting); 80 81 /* DP DPIA/PHY */ 82 int (*dpia_handle_usb4_bandwidth_allocation_for_link)(struct dc_link *link, int peak_bw); 83 void (*dpia_handle_bw_alloc_response)(struct dc_link *link, uint8_t bw, uint8_t result); 84 void (*dpcd_write_rx_power_ctrl)(struct dc_link *link, bool on); 85 86 /* DP IRQ Handler */ 87 bool (*dp_parse_link_loss_status)( 88 struct dc_link *link, 89 union hpd_irq_data *hpd_irq_dpcd_data); 90 bool (*dp_should_allow_hpd_rx_irq)(const struct dc_link *link); 91 void (*dp_handle_link_loss)(struct dc_link *link); 92 enum dc_status (*dp_read_hpd_rx_irq_data)( 93 struct dc_link *link, 94 union hpd_irq_data *irq_data); 95 bool (*dp_handle_hpd_rx_irq)(struct dc_link *link, 96 union hpd_irq_data *out_hpd_irq_dpcd_data, bool *out_link_loss, 97 bool defer_handling, bool *has_left_work); 98 99 /* eDP Panel Control */ 100 void (*edp_panel_backlight_power_on)(struct dc_link *link, bool wait_for_hpd); 101 int (*edp_get_backlight_level)(const struct dc_link *link); 102 bool (*edp_get_backlight_level_nits)(struct dc_link *link, 103 uint32_t *backlight_millinits_avg, 104 uint32_t *backlight_millinits_peak); 105 bool (*edp_set_backlight_level)(const struct dc_link *link, 106 uint32_t backlight_pwm_u16_16, 107 uint32_t frame_ramp); 108 bool (*edp_set_backlight_level_nits)(struct dc_link *link, 109 bool isHDR, 110 uint32_t backlight_millinits, 111 uint32_t transition_time_in_ms); 112 int (*edp_get_target_backlight_pwm)(const struct dc_link *link); 113 bool (*edp_get_psr_state)(const struct dc_link *link, enum dc_psr_state *state); 114 bool (*edp_set_psr_allow_active)(struct dc_link *link, const bool *allow_active, 115 bool wait, bool force_static, const unsigned int *power_opts); 116 bool (*edp_setup_psr)(struct dc_link *link, 117 const struct dc_stream_state *stream, 118 struct psr_config *psr_config, 119 struct psr_context *psr_context); 120 bool (*edp_wait_for_t12)(struct dc_link *link); 121 122 /* DP CTS */ 123 void (*dp_handle_automated_test)(struct dc_link *link); 124 bool (*dp_set_test_pattern)( 125 struct dc_link *link, 126 enum dp_test_pattern test_pattern, 127 enum dp_test_pattern_color_space test_pattern_color_space, 128 const struct link_training_settings *p_link_settings, 129 const unsigned char *p_custom_pattern, 130 unsigned int cust_pattern_size); 131 void (*dp_set_preferred_link_settings)(struct dc *dc, 132 struct dc_link_settings *link_setting, 133 struct dc_link *link); 134 void (*dp_set_preferred_training_settings)(struct dc *dc, 135 struct dc_link_settings *link_setting, 136 struct dc_link_training_overrides *lt_overrides, 137 struct dc_link *link, 138 bool skip_immediate_retrain); 139 140 /* DP Trace */ 141 bool (*dp_trace_is_initialized)(struct dc_link *link); 142 void (*dp_trace_set_is_logged_flag)(struct dc_link *link, 143 bool in_detection, 144 bool is_logged); 145 bool (*dp_trace_is_logged)(struct dc_link *link, bool in_detection); 146 unsigned long long (*dp_trace_get_lt_end_timestamp)( 147 struct dc_link *link, bool in_detection); 148 const struct dp_trace_lt_counts *(*dp_trace_get_lt_counts)( 149 struct dc_link *link, bool in_detection); 150 unsigned int (*dp_trace_get_link_loss_count)(struct dc_link *link); 151 }; 152 153 struct dc_link *link_create(const struct link_init_data *init_params); 154 void link_destroy(struct dc_link **link); 155 const struct link_service *link_get_link_service(void); 156 157 // TODO - convert any function declarations below to function pointers 158 struct gpio *link_get_hpd_gpio(struct dc_bios *dcb, 159 struct graphics_object_id link_id, 160 struct gpio_service *gpio_service); 161 162 struct ddc_service_init_data { 163 struct graphics_object_id id; 164 struct dc_context *ctx; 165 struct dc_link *link; 166 bool is_dpia_link; 167 }; 168 169 struct ddc_service *link_create_ddc_service( 170 struct ddc_service_init_data *ddc_init_data); 171 172 void link_destroy_ddc_service(struct ddc_service **ddc); 173 174 bool link_is_in_aux_transaction_mode(struct ddc_service *ddc); 175 176 bool link_query_ddc_data( 177 struct ddc_service *ddc, 178 uint32_t address, 179 uint8_t *write_buf, 180 uint32_t write_size, 181 uint8_t *read_buf, 182 uint32_t read_size); 183 184 185 /* Attempt to submit an aux payload, retrying on timeouts, defers, and busy 186 * states as outlined in the DP spec. Returns true if the request was 187 * successful. 188 * 189 * NOTE: The function requires explicit mutex on DM side in order to prevent 190 * potential race condition. DC components should call the dpcd read/write 191 * function in dm_helpers in order to access dpcd safely 192 */ 193 bool link_aux_transfer_with_retries_no_mutex(struct ddc_service *ddc, 194 struct aux_payload *payload); 195 196 uint32_t link_get_aux_defer_delay(struct ddc_service *ddc); 197 198 bool link_is_dp_128b_132b_signal(struct pipe_ctx *pipe_ctx); 199 200 enum dp_link_encoding link_dp_get_encoding_format( 201 const struct dc_link_settings *link_settings); 202 203 bool link_decide_link_settings( 204 struct dc_stream_state *stream, 205 struct dc_link_settings *link_setting); 206 207 void link_dp_trace_set_edp_power_timestamp(struct dc_link *link, 208 bool power_up); 209 uint64_t link_dp_trace_get_edp_poweron_timestamp(struct dc_link *link); 210 uint64_t link_dp_trace_get_edp_poweroff_timestamp(struct dc_link *link); 211 212 bool link_is_edp_ilr_optimization_required(struct dc_link *link, 213 struct dc_crtc_timing *crtc_timing); 214 215 bool link_backlight_enable_aux(struct dc_link *link, bool enable); 216 void link_edp_add_delay_for_T9(struct dc_link *link); 217 bool link_edp_receiver_ready_T9(struct dc_link *link); 218 bool link_edp_receiver_ready_T7(struct dc_link *link); 219 bool link_power_alpm_dpcd_enable(struct dc_link *link, bool enable); 220 bool link_set_sink_vtotal_in_psr_active(const struct dc_link *link, 221 uint16_t psr_vtotal_idle, uint16_t psr_vtotal_su); 222 void link_get_psr_residency(const struct dc_link *link, uint32_t *residency); 223 enum dc_status link_increase_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn); 224 enum dc_status link_reduce_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn); 225 void link_blank_all_dp_displays(struct dc *dc); 226 void link_blank_all_edp_displays(struct dc *dc); 227 void link_blank_dp_stream(struct dc_link *link, bool hw_init); 228 void link_resume(struct dc_link *link); 229 void link_set_dpms_on( 230 struct dc_state *state, 231 struct pipe_ctx *pipe_ctx); 232 void link_set_dpms_off(struct pipe_ctx *pipe_ctx); 233 void link_dp_source_sequence_trace(struct dc_link *link, uint8_t dp_test_mode); 234 void link_set_dsc_on_stream(struct pipe_ctx *pipe_ctx, bool enable); 235 bool link_set_dsc_enable(struct pipe_ctx *pipe_ctx, bool enable); 236 bool link_update_dsc_config(struct pipe_ctx *pipe_ctx); 237 enum dc_status link_validate_mode_timing( 238 const struct dc_stream_state *stream, 239 struct dc_link *link, 240 const struct dc_crtc_timing *timing); 241 bool link_detect(struct dc_link *link, enum dc_detect_reason reason); 242 bool link_detect_connection_type(struct dc_link *link, 243 enum dc_connection_type *type); 244 const struct dc_link_status *link_get_status(const struct dc_link *link); 245 /* return true if the connected receiver supports the hdcp version */ 246 bool link_is_hdcp14(struct dc_link *link, enum signal_type signal); 247 bool link_is_hdcp22(struct dc_link *link, enum signal_type signal); 248 void link_clear_dprx_states(struct dc_link *link); 249 bool link_reset_cur_dp_mst_topology(struct dc_link *link); 250 uint32_t dp_link_bandwidth_kbps( 251 const struct dc_link *link, 252 const struct dc_link_settings *link_settings); 253 uint32_t link_timing_bandwidth_kbps(const struct dc_crtc_timing *timing); 254 void link_get_cur_res_map(const struct dc *dc, uint32_t *map); 255 void link_restore_res_map(const struct dc *dc, uint32_t *map); 256 void link_get_cur_link_res(const struct dc_link *link, 257 struct link_resource *link_res); 258 void dp_set_drive_settings( 259 struct dc_link *link, 260 const struct link_resource *link_res, 261 struct link_training_settings *lt_settings); 262 #endif /* __DC_LINK_HPD_H__ */ 263