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 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 struct config_writer; 34 35 #define TF_HELPER_REG_FIELD_LIST(type) \ 36 type exp_region0_lut_offset; \ 37 type exp_region0_num_segments; \ 38 type exp_region1_lut_offset; \ 39 type exp_region1_num_segments; \ 40 type field_region_end; \ 41 type field_region_end_slope; \ 42 type field_region_end_base; \ 43 type exp_region_start; \ 44 type exp_region_start_segment; \ 45 type field_region_linear_slope; \ 46 type field_region_start_base; \ 47 type field_offset 48 49 #define TF_HELPER_REG_LIST \ 50 uint32_t start_cntl_b; \ 51 uint32_t start_cntl_g; \ 52 uint32_t start_cntl_r; \ 53 uint32_t start_slope_cntl_b; \ 54 uint32_t start_slope_cntl_g; \ 55 uint32_t start_slope_cntl_r; \ 56 uint32_t start_end_cntl1_b; \ 57 uint32_t start_end_cntl2_b; \ 58 uint32_t start_end_cntl1_g; \ 59 uint32_t start_end_cntl2_g; \ 60 uint32_t start_end_cntl1_r; \ 61 uint32_t start_end_cntl2_r; \ 62 uint32_t region_start; \ 63 uint32_t region_end 64 65 struct vpe10_xfer_func_shift { 66 TF_HELPER_REG_FIELD_LIST(uint8_t); 67 }; 68 69 struct vpe10_xfer_func_mask { 70 TF_HELPER_REG_FIELD_LIST(uint32_t); 71 }; 72 73 struct vpe10_xfer_func_reg { 74 struct vpe10_xfer_func_shift shifts; 75 struct vpe10_xfer_func_mask masks; 76 77 TF_HELPER_REG_LIST; 78 uint32_t offset_b; 79 uint32_t offset_g; 80 uint32_t offset_r; 81 uint32_t start_base_cntl_b; 82 uint32_t start_base_cntl_g; 83 uint32_t start_base_cntl_r; 84 }; 85 86 #define TF_CM_REG_FIELD_LIST(type) \ 87 type csc_c11; \ 88 type csc_c12 89 90 struct cm_color_matrix_shift { 91 TF_CM_REG_FIELD_LIST(uint8_t); 92 }; 93 94 struct cm_color_matrix_mask { 95 TF_CM_REG_FIELD_LIST(uint32_t); 96 }; 97 98 struct color_matrices_reg { 99 struct cm_color_matrix_shift shifts; 100 struct cm_color_matrix_mask masks; 101 102 uint32_t csc_c11_c12; 103 uint32_t csc_c33_c34; 104 }; 105 106 enum cm_rgb_channel { 107 CM_PWL_R, 108 CM_PWL_G, 109 CM_PWL_B 110 }; 111 112 void vpe10_cm_helper_program_pwl(struct config_writer *config_writer, 113 const struct pwl_result_data *rgb, uint32_t last_base_value, uint32_t num, 114 uint32_t lut_data_reg_offset, uint8_t lut_data_reg_shift, uint32_t lut_data_reg_mask, 115 enum cm_rgb_channel channel); 116 117 void vpe10_cm_helper_program_color_matrices(struct config_writer *config_writer, 118 const uint16_t *regval, const struct color_matrices_reg *reg); 119 120 void vpe10_cm_helper_program_gamcor_xfer_func(struct config_writer *config_writer, 121 const struct pwl_params *params, const struct vpe10_xfer_func_reg *reg); 122 123 bool vpe10_cm_helper_translate_curve_to_hw_format( 124 const struct transfer_func *output_tf, struct pwl_params *lut_params, bool fixpoint); 125 126 bool vpe10_cm_helper_translate_curve_to_degamma_hw_format( 127 const struct transfer_func *output_tf, struct pwl_params *lut_params); 128 129 #ifdef __cplusplus 130 } 131 #endif 132