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