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 25 #pragma once 26 27 #include "vpe_types.h" 28 #include "cmd_builder.h" 29 #include "vpec.h" 30 #include "cdc.h" 31 #include "dpp.h" 32 #include "mpc.h" 33 #include "opp.h" 34 #include "vector.h" 35 #include "hw_shared.h" 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 struct vpe_priv; 42 struct vpe_cmd_info; 43 struct segment_ctx; 44 45 #define MIN_VPE_CMD (1024) 46 #define MIN_NUM_CONFIG (16) 47 48 enum vpe_cmd_ops; 49 50 /** struct resource stores all the hw subblocks function pointers 51 * which assist in constructing the command packets. 52 * 53 * As differnt asic may have its own deviation in the subblocks, 54 * each hw ip has its own set of function pointers to expose 55 * the programming interface of the blocks. 56 * 57 * The upper level should have a sequencer that constructs the 58 * final programming sequence using subblock functions 59 */ 60 struct resource { 61 struct vpe_priv *vpe_priv; 62 struct vpec vpec; 63 64 bool (*check_input_color_space)(struct vpe_priv *vpe_priv, enum vpe_surface_pixel_format format, 65 const struct vpe_color_space *vcs); 66 67 bool (*check_output_color_space)(struct vpe_priv *vpe_priv, 68 enum vpe_surface_pixel_format format, const struct vpe_color_space *vcs); 69 70 bool (*check_h_mirror_support)(bool *input_mirror, bool *output_miror); 71 72 enum vpe_status (*calculate_segments)( 73 struct vpe_priv *vpe_priv, const struct vpe_build_param *params); 74 75 enum vpe_status(*check_bg_color_support)(struct vpe_priv* vpe_priv, struct vpe_color* bg_color); 76 77 enum vpe_status (*set_num_segments)(struct vpe_priv *vpe_priv, struct stream_ctx *stream_ctx, 78 struct scaler_data *scl_data, struct vpe_rect *src_rect, struct vpe_rect *dst_rect, 79 uint32_t *max_seg_width); 80 81 bool (*split_bg_gap)(struct vpe_rect *gaps, const struct vpe_rect *target_rect, 82 uint32_t max_width, uint16_t max_gaps, uint16_t *num_gaps, uint16_t num_instances); 83 84 void (*calculate_dst_viewport_and_active)( 85 struct segment_ctx *segment_ctx, uint32_t max_seg_width); 86 87 uint16_t (*find_bg_gaps)(struct vpe_priv *vpe_priv, const struct vpe_rect *target_rect, 88 struct vpe_rect *gaps, uint16_t max_gaps); 89 90 void (*create_bg_segments)( 91 struct vpe_priv *vpe_priv, struct vpe_rect *gaps, uint16_t gaps_cnt, enum vpe_cmd_ops ops); 92 93 enum vpe_status (*populate_cmd_info)(struct vpe_priv *vpe_priv); 94 95 int32_t (*program_frontend)(struct vpe_priv *vpe_priv, uint32_t pipe_idx, uint32_t cmd_idx, 96 uint32_t cmd_input_idx, bool seg_only); 97 98 int32_t (*program_backend)( 99 struct vpe_priv *vpe_priv, uint32_t pipe_idx, uint32_t cmd_idx, bool seg_only); 100 101 void (*get_bufs_req)(struct vpe_priv *vpe_priv, struct vpe_bufs_req *req); 102 103 enum vpe_status (*check_mirror_rotation_support)(const struct vpe_stream *stream); 104 105 enum vpe_status (*update_blnd_gamma)(struct vpe_priv *vpe_priv, 106 const struct vpe_build_param *param, const struct vpe_stream *stream, 107 struct transfer_func *blnd_tf); 108 109 // Indicates the nominal range hdr input content should be in during processing. 110 int internal_hdr_normalization; 111 112 // vpep components 113 struct cdc_fe *cdc_fe[MAX_INPUT_PIPE]; 114 struct cdc_be *cdc_be[MAX_OUTPUT_PIPE]; 115 struct dpp *dpp[MAX_INPUT_PIPE]; 116 struct opp *opp[MAX_INPUT_PIPE]; 117 struct mpc *mpc[MAX_INPUT_PIPE]; 118 struct cmd_builder cmd_builder; 119 }; 120 121 /** translate the vpe ip version into vpe hw level */ 122 enum vpe_ip_level vpe_resource_parse_ip_version( 123 uint8_t major, uint8_t minor, uint8_t rev_id); 124 125 /** initialize the resource ased on vpe hw level */ 126 enum vpe_status vpe_construct_resource( 127 struct vpe_priv *vpe_priv, enum vpe_ip_level level, struct resource *resource); 128 129 /** destroy the resource */ 130 void vpe_destroy_resource(struct vpe_priv *vpe_priv, struct resource *res); 131 132 /** alloc segment ctx*/ 133 struct segment_ctx *vpe_alloc_segment_ctx(struct vpe_priv *vpe_priv, uint16_t num_segments); 134 135 /** stream ctx */ 136 struct stream_ctx *vpe_alloc_stream_ctx(struct vpe_priv *vpe_priv, uint32_t num_streams); 137 138 void vpe_free_stream_ctx(struct vpe_priv *vpe_priv); 139 140 /** pipe resource management */ 141 void vpe_pipe_reset(struct vpe_priv *vpe_priv); 142 143 void vpe_pipe_reclaim(struct vpe_priv *vpe_priv, struct vpe_cmd_info *cmd_info); 144 145 struct pipe_ctx *vpe_pipe_find_owner(struct vpe_priv *vpe_priv, uint32_t stream_idx, bool *reuse); 146 147 /** resource helper */ 148 void vpe_clip_stream( 149 struct vpe_rect *src_rect, struct vpe_rect *dst_rect, const struct vpe_rect *target_rect); 150 151 void calculate_scaling_ratios(struct scaler_data *scl_data, struct vpe_rect *src_rect, 152 struct vpe_rect *dst_rect, enum vpe_surface_pixel_format format); 153 154 uint16_t vpe_get_num_segments(struct vpe_priv *vpe_priv, const struct vpe_rect *src, 155 const struct vpe_rect *dst, const uint32_t max_seg_width); 156 157 enum vpe_status vpe_resource_build_scaling_params(struct segment_ctx *segment); 158 159 void vpe_handle_output_h_mirror(struct vpe_priv *vpe_priv); 160 161 void vpe_resource_build_bit_depth_reduction_params( 162 struct opp *opp, struct bit_depth_reduction_params *fmt_bit_depth); 163 164 /** resource function call backs*/ 165 void vpe_frontend_config_callback( 166 void *ctx, uint64_t cfg_base_gpu, uint64_t cfg_base_cpu, uint64_t size, uint32_t pipe_idx); 167 168 void vpe_backend_config_callback( 169 void *ctx, uint64_t cfg_base_gpu, uint64_t cfg_base_cpu, uint64_t size, uint32_t pipe_idx); 170 171 bool vpe_rec_is_equal(struct vpe_rect rec1, struct vpe_rect rec2); 172 173 #ifdef __cplusplus 174 } 175 #endif 176