1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright 2023 Advanced Micro Devices, Inc. 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 */ 24 25 #ifndef _DML2_UTILS_H_ 26 #define _DML2_UTILS_H_ 27 28 #include "os_types.h" 29 #include "dml2_dc_types.h" 30 31 struct dc; 32 struct dml_timing_cfg_st; 33 struct dml2_dcn_clocks; 34 struct dc_state; 35 36 void dml2_util_copy_dml_timing(struct dml_timing_cfg_st *dml_timing_array, unsigned int dst_index, unsigned int src_index); 37 void dml2_util_copy_dml_plane(struct dml_plane_cfg_st *dml_plane_array, unsigned int dst_index, unsigned int src_index); 38 void dml2_util_copy_dml_surface(struct dml_surface_cfg_st *dml_surface_array, unsigned int dst_index, unsigned int src_index); 39 void dml2_util_copy_dml_output(struct dml_output_cfg_st *dml_output_array, unsigned int dst_index, unsigned int src_index); 40 unsigned int dml2_util_get_maximum_odm_combine_for_output(bool force_odm_4to1, enum dml_output_encoder_class encoder, bool dsc_enabled); 41 void dml2_copy_clocks_to_dc_state(struct dml2_dcn_clocks *out_clks, struct dc_state *context); 42 void dml2_extract_watermark_set(struct dcn_watermarks *watermark, struct display_mode_lib_st *dml_core_ctx); 43 void dml2_extract_writeback_wm(struct dc_state *context, struct display_mode_lib_st *dml_core_ctx); 44 int dml2_helper_find_dml_pipe_idx_by_stream_id(struct dml2_context *ctx, unsigned int stream_id); 45 bool is_dtbclk_required(const struct dc *dc, struct dc_state *context); 46 bool dml2_is_stereo_timing(const struct dc_stream_state *stream); 47 unsigned int dml2_calc_max_scaled_time( 48 unsigned int time_per_pixel, 49 enum mmhubbub_wbif_mode mode, 50 unsigned int urgent_watermark); 51 52 /* 53 * dml2_dc_construct_pipes - This function will determine if we need additional pipes based 54 * on the DML calculated outputs for MPC, ODM and allocate them as necessary. This function 55 * could be called after in dml_validate_build_resource after dml_mode_pragramming like : 56 * { 57 * ... 58 * map_hw_resources(&s->cur_display_config, &s->mode_support_info); 59 * result = dml_mode_programming(&in_ctx->dml_core_ctx, s->mode_support_params.out_lowest_state_idx, &s->cur_display_config, true); 60 * dml2_dc_construct_pipes(in_display_state, s->mode_support_info, out_hw_context); 61 * ... 62 * } 63 * 64 * @context: To obtain res_ctx and read other information like stream ID etc. 65 * @dml_mode_support_st : To get the ODM, MPC outputs as determined by the DML. 66 * @out_hw_context : Handle to the new hardware context. 67 * 68 * 69 * Return: None. 70 */ 71 void dml2_dc_construct_pipes(struct dc_state *context, struct dml_mode_support_info_st *dml_mode_support_st, 72 struct resource_context *out_hw_context); 73 74 /* 75 * dml2_predict_pipe_split - This function is the dml2 version of predict split pipe. It predicts a 76 * if pipe split is required or not and returns the output as a bool. 77 * @context : dc_state. 78 * @pipe : old_index is the index of the pipe as derived from pipe_idx. 79 * @index : index of the pipe 80 * 81 * 82 * Return: Returns the result in boolean. 83 */ 84 bool dml2_predict_pipe_split(struct dc_state *context, display_pipe_params_st pipe, int index); 85 86 /* 87 * dml2_build_mapped_resource - This function is the dml2 version of build_mapped_resource. 88 * In case of ODM, we need to build pipe hardware params again as done in dcn20_build_mapped_resource. 89 * @dc : struct dc 90 * @context : struct dc_state. 91 * @stream : stream whoose corresponding pipe params need to be modified. 92 * 93 * 94 * Return: Returns DC_OK if successful. 95 */ 96 enum dc_status dml2_build_mapped_resource(const struct dc *dc, struct dc_state *context, struct dc_stream_state *stream); 97 98 /* 99 * dml2_extract_rq_regs - This function will extract information needed for struct _vcs_dpi_display_rq_regs_st 100 * and populate it. 101 * @context: To obtain and populate the res_ctx->pipe_ctx->rq_regs with DML outputs. 102 * @support : This structure has the DML intermediate outputs required to populate rq_regs. 103 * 104 * 105 * Return: None. 106 */ 107 108 /* 109 * dml2_calculate_rq_and_dlg_params - This function will call into DML2 functions needed 110 * for populating rq, ttu and dlg param structures and populate it. 111 * @dc : struct dc 112 * @context : dc_state provides a handle to selectively populate pipe_ctx 113 * @out_new_hw_state: To obtain and populate the rq, dlg and ttu regs in 114 * out_new_hw_state->pipe_ctx with DML outputs. 115 * @in_ctx : This structure has the pointer to display_mode_lib_st. 116 * @pipe_cnt : DML functions to obtain RQ, TTu and DLG params need a pipe_index. 117 * This helps provide pipe_index in the pipe_cnt loop. 118 * 119 * 120 * Return: None. 121 */ 122 void dml2_calculate_rq_and_dlg_params(const struct dc *dc, struct dc_state *context, struct resource_context *out_new_hw_state, struct dml2_context *in_ctx, unsigned int pipe_cnt); 123 124 /* 125 * dml2_apply_det_buffer_allocation_policy - This function will determine the DET Buffer size 126 * and return the number of streams. 127 * @dml2 : Handle for dml2 context 128 * @dml_dispcfg : dml_dispcfg is the DML2 struct representing the current display config 129 * Return : None. 130 */ 131 void dml2_apply_det_buffer_allocation_policy(struct dml2_context *in_ctx, struct dml_display_cfg_st *dml_dispcfg); 132 133 /* 134 * dml2_verify_det_buffer_configuration - This function will verify if the allocated DET buffer exceeds 135 * the total available DET size available and outputs a boolean to indicate if recalulation is needed. 136 * @dml2 : Handle for dml2 context 137 * @dml_dispcfg : dml_dispcfg is the DML2 struct representing the current display config 138 * @struct dml2_helper_det_policy_scratch : Pointer to DET helper scratch 139 * Return : returns true if recalculation is required, false otherwise. 140 */ 141 bool dml2_verify_det_buffer_configuration(struct dml2_context *in_ctx, struct dc_state *display_state, struct dml2_helper_det_policy_scratch *det_scratch); 142 143 /* 144 * dml2_initialize_det_scratch - This function will initialize the DET scratch space as per requirements. 145 * @dml2 : Handle for dml2 context 146 * Return : None 147 */ 148 void dml2_initialize_det_scratch(struct dml2_context *in_ctx); 149 #endif 150