1 /* Copyright 2022 Advanced Micro Devices, Inc. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a 4 * copy of this software and associated documentation files (the "Software"), 5 * to deal in the Software without restriction, including without limitation 6 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 * and/or sell copies of the Software, and to permit persons to whom the 8 * Software is furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 19 * OTHER DEALINGS IN THE SOFTWARE. 20 * 21 * Authors: AMD 22 * 23 */ 24 #pragma once 25 26 #include "color.h" 27 #include "hw_shared.h" 28 #include "color_pwl.h" 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 struct config_writer; 35 36 #define TF_HELPER_REG_FIELD_LIST(type) \ 37 type exp_region0_lut_offset; \ 38 type exp_region0_num_segments; \ 39 type exp_region1_lut_offset; \ 40 type exp_region1_num_segments; \ 41 type field_region_end; \ 42 type field_region_end_slope; \ 43 type field_region_end_base; \ 44 type exp_region_start; \ 45 type exp_region_start_segment; \ 46 type field_region_linear_slope; \ 47 type field_region_start_base; \ 48 type field_offset 49 50 #define TF_HELPER_REG_LIST \ 51 uint32_t start_cntl_b; \ 52 uint32_t start_cntl_g; \ 53 uint32_t start_cntl_r; \ 54 uint32_t start_slope_cntl_b; \ 55 uint32_t start_slope_cntl_g; \ 56 uint32_t start_slope_cntl_r; \ 57 uint32_t start_end_cntl1_b; \ 58 uint32_t start_end_cntl2_b; \ 59 uint32_t start_end_cntl1_g; \ 60 uint32_t start_end_cntl2_g; \ 61 uint32_t start_end_cntl1_r; \ 62 uint32_t start_end_cntl2_r; \ 63 uint32_t region_start; \ 64 uint32_t region_end 65 66 struct vpe10_xfer_func_shift { 67 TF_HELPER_REG_FIELD_LIST(uint8_t); 68 }; 69 70 struct vpe10_xfer_func_mask { 71 TF_HELPER_REG_FIELD_LIST(uint32_t); 72 }; 73 74 struct vpe10_xfer_func_reg { 75 struct vpe10_xfer_func_shift shifts; 76 struct vpe10_xfer_func_mask masks; 77 78 TF_HELPER_REG_LIST; 79 uint32_t offset_b; 80 uint32_t offset_g; 81 uint32_t offset_r; 82 uint32_t start_base_cntl_b; 83 uint32_t start_base_cntl_g; 84 uint32_t start_base_cntl_r; 85 }; 86 87 #define TF_CM_REG_FIELD_LIST(type) \ 88 type csc_c11; \ 89 type csc_c12 90 91 struct cm_color_matrix_shift { 92 TF_CM_REG_FIELD_LIST(uint8_t); 93 }; 94 95 struct cm_color_matrix_mask { 96 TF_CM_REG_FIELD_LIST(uint32_t); 97 }; 98 99 struct color_matrices_reg { 100 struct cm_color_matrix_shift shifts; 101 struct cm_color_matrix_mask masks; 102 103 uint32_t csc_c11_c12; 104 uint32_t csc_c33_c34; 105 }; 106 107 enum cm_rgb_channel { 108 CM_PWL_R, 109 CM_PWL_G, 110 CM_PWL_B 111 }; 112 113 void vpe10_cm_helper_program_pwl(struct config_writer *config_writer, 114 const struct pwl_result_data *rgb, uint32_t last_base_value, uint32_t num, 115 uint32_t lut_data_reg_offset, uint8_t lut_data_reg_shift, uint32_t lut_data_reg_mask, 116 enum cm_rgb_channel channel); 117 118 void vpe10_cm_helper_program_color_matrices(struct config_writer *config_writer, 119 const uint16_t *regval, const struct color_matrices_reg *reg); 120 121 void vpe10_cm_helper_program_gamcor_xfer_func(struct config_writer *config_writer, 122 const struct pwl_params *params, const struct vpe10_xfer_func_reg *reg); 123 124 bool vpe10_cm_helper_translate_curve_to_hw_format( 125 const struct transfer_func *output_tf, struct pwl_params *lut_params, bool fixpoint); 126 127 bool vpe10_cm_helper_translate_curve_to_degamma_hw_format( 128 const struct transfer_func *output_tf, struct pwl_params *lut_params); 129 130 void vpe10_cm_get_tf_pwl_params(const struct transfer_func *output_tf, 131 struct pwl_params **lut_params, enum cm_type vpe_cm_type); 132 133 #ifdef __cplusplus 134 } 135 #endif 136