forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/media/platform/qcom/venus/core.h
....@@ -1,16 +1,7 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
34 * Copyright (C) 2017 Linaro Ltd.
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 and
7
- * only version 2 as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
145 */
156
167 #ifndef __VENUS_CORE_H_
....@@ -21,9 +12,19 @@
2112 #include <media/v4l2-ctrls.h>
2213 #include <media/v4l2-device.h>
2314
15
+#include "dbgfs.h"
2416 #include "hfi.h"
2517
26
-#define VIDC_CLKS_NUM_MAX 4
18
+#define VDBGL "VenusLow : "
19
+#define VDBGM "VenusMed : "
20
+#define VDBGH "VenusHigh: "
21
+#define VDBGFW "VenusFW : "
22
+
23
+#define VIDC_CLKS_NUM_MAX 4
24
+#define VIDC_VCODEC_CLKS_NUM_MAX 2
25
+#define VIDC_PMDOMAINS_NUM_MAX 3
26
+
27
+extern int venus_fw_debug;
2728
2829 struct freq_tbl {
2930 unsigned int load;
....@@ -35,19 +36,51 @@
3536 u32 value;
3637 };
3738
39
+struct codec_freq_data {
40
+ u32 pixfmt;
41
+ u32 session_type;
42
+ unsigned long vpp_freq;
43
+ unsigned long vsp_freq;
44
+};
45
+
46
+struct bw_tbl {
47
+ u32 mbs_per_sec;
48
+ u32 avg;
49
+ u32 peak;
50
+ u32 avg_10bit;
51
+ u32 peak_10bit;
52
+};
53
+
3854 struct venus_resources {
3955 u64 dma_mask;
4056 const struct freq_tbl *freq_tbl;
4157 unsigned int freq_tbl_size;
58
+ const struct bw_tbl *bw_tbl_enc;
59
+ unsigned int bw_tbl_enc_size;
60
+ const struct bw_tbl *bw_tbl_dec;
61
+ unsigned int bw_tbl_dec_size;
4262 const struct reg_val *reg_tbl;
4363 unsigned int reg_tbl_size;
64
+ const struct codec_freq_data *codec_freq_data;
65
+ unsigned int codec_freq_data_size;
4466 const char * const clks[VIDC_CLKS_NUM_MAX];
4567 unsigned int clks_num;
68
+ const char * const vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
69
+ const char * const vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
70
+ unsigned int vcodec_clks_num;
71
+ const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX];
72
+ unsigned int vcodec_pmdomains_num;
73
+ const char **opp_pmdomain;
74
+ unsigned int vcodec_num;
4675 enum hfi_version hfi_version;
4776 u32 max_load;
4877 unsigned int vmem_id;
4978 u32 vmem_size;
5079 u32 vmem_addr;
80
+ u32 cp_start;
81
+ u32 cp_size;
82
+ u32 cp_nonpixel_start;
83
+ u32 cp_nonpixel_size;
5184 const char *fwname;
5285 };
5386
....@@ -55,6 +88,7 @@
5588 u32 pixfmt;
5689 unsigned int num_planes;
5790 u32 type;
91
+ u32 flags;
5892 };
5993
6094 #define MAX_PLANES 4
....@@ -87,10 +121,9 @@
87121 * @base: IO memory base address
88122 * @irq: Venus irq
89123 * @clks: an array of struct clk pointers
90
- * @core0_clk: a struct clk pointer for core0
91
- * @core1_clk: a struct clk pointer for core1
92
- * @core0_bus_clk: a struct clk pointer for core0 bus clock
93
- * @core1_bus_clk: a struct clk pointer for core1 bus clock
124
+ * @vcodec0_clks: an array of vcodec0 struct clk pointers
125
+ * @vcodec1_clks: an array of vcodec1 struct clk pointers
126
+ * @pmdomains: an array of pmdomains struct device pointers
94127 * @vdev_dec: a reference to video device structure for decoder instances
95128 * @vdev_enc: a reference to video device structure for encoder instances
96129 * @v4l2_dev: a holder for v4l2 device structure
....@@ -98,6 +131,7 @@
98131 * @dev: convenience struct device pointer
99132 * @dev_dec: convenience struct device pointer for decoder device
100133 * @dev_enc: convenience struct device pointer for encoder device
134
+ * @use_tz: a flag that suggests presence of trustzone
101135 * @lock: a lock for this strucure
102136 * @instances: a list_head of all instances
103137 * @insts_count: num of instances
....@@ -106,6 +140,7 @@
106140 * @error: an error returned during last HFI sync operations
107141 * @sys_error: an error flag that signal system error event
108142 * @core_ops: the core operations
143
+ * @pm_lock: a lock for PM operations
109144 * @enc_codecs: encoders supported by this core
110145 * @dec_codecs: decoders supported by this core
111146 * @max_sessions_supported: holds the maximum number of sessions
....@@ -113,15 +148,21 @@
113148 * @priv: a private filed for HFI operations
114149 * @ops: the core HFI operations
115150 * @work: a delayed work for handling system fatal error
151
+ * @root: debugfs root directory
116152 */
117153 struct venus_core {
118154 void __iomem *base;
119155 int irq;
120156 struct clk *clks[VIDC_CLKS_NUM_MAX];
121
- struct clk *core0_clk;
122
- struct clk *core1_clk;
123
- struct clk *core0_bus_clk;
124
- struct clk *core1_bus_clk;
157
+ struct clk *vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
158
+ struct clk *vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
159
+ struct icc_path *video_path;
160
+ struct icc_path *cpucfg_path;
161
+ struct opp_table *opp_table;
162
+ bool has_opp_table;
163
+ struct device *pmdomains[VIDC_PMDOMAINS_NUM_MAX];
164
+ struct device_link *opp_dl_venus;
165
+ struct device *opp_pmdomain;
125166 struct video_device *vdev_dec;
126167 struct video_device *vdev_enc;
127168 struct v4l2_device v4l2_dev;
....@@ -129,6 +170,12 @@
129170 struct device *dev;
130171 struct device *dev_dec;
131172 struct device *dev_enc;
173
+ unsigned int use_tz;
174
+ struct video_firmware {
175
+ struct device *dev;
176
+ struct iommu_domain *iommu_domain;
177
+ size_t mapped_mem_size;
178
+ } fw;
132179 struct mutex lock;
133180 struct list_head instances;
134181 atomic_t insts_count;
....@@ -137,6 +184,8 @@
137184 unsigned int error;
138185 bool sys_error;
139186 const struct hfi_core_ops *core_ops;
187
+ const struct venus_pm_ops *pm_ops;
188
+ struct mutex pm_lock;
140189 unsigned long enc_codecs;
141190 unsigned long dec_codecs;
142191 unsigned int max_sessions_supported;
....@@ -150,6 +199,9 @@
150199 struct delayed_work work;
151200 struct venus_caps caps[MAX_CODEC_NUM];
152201 unsigned int codecs_count;
202
+ unsigned int core0_usage_count;
203
+ unsigned int core1_usage_count;
204
+ struct dentry *root;
153205 };
154206
155207 struct vdec_controls {
....@@ -165,6 +217,9 @@
165217 u32 bitrate_mode;
166218 u32 bitrate;
167219 u32 bitrate_peak;
220
+ u32 rc_enable;
221
+ u32 const_quality;
222
+ u32 frame_skip_mode;
168223
169224 u32 h264_i_period;
170225 u32 h264_entropy_mode;
....@@ -187,15 +242,17 @@
187242 u32 header_mode;
188243
189244 struct {
190
- u32 mpeg4;
191245 u32 h264;
192
- u32 vpx;
246
+ u32 mpeg4;
193247 u32 hevc;
248
+ u32 vp8;
249
+ u32 vp9;
194250 } profile;
195251 struct {
196
- u32 mpeg4;
197252 u32 h264;
253
+ u32 mpeg4;
198254 u32 hevc;
255
+ u32 vp9;
199256 } level;
200257 };
201258
....@@ -209,10 +266,36 @@
209266 struct list_head ref_list;
210267 };
211268
269
+struct clock_data {
270
+ u32 core_id;
271
+ unsigned long freq;
272
+ const struct codec_freq_data *codec_freq_data;
273
+};
274
+
212275 #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
213276
277
+enum venus_dec_state {
278
+ VENUS_DEC_STATE_DEINIT = 0,
279
+ VENUS_DEC_STATE_INIT = 1,
280
+ VENUS_DEC_STATE_CAPTURE_SETUP = 2,
281
+ VENUS_DEC_STATE_STOPPED = 3,
282
+ VENUS_DEC_STATE_SEEK = 4,
283
+ VENUS_DEC_STATE_DRAIN = 5,
284
+ VENUS_DEC_STATE_DECODING = 6,
285
+ VENUS_DEC_STATE_DRC = 7,
286
+ VENUS_DEC_STATE_DRC_FLUSH_DONE = 8,
287
+};
288
+
289
+struct venus_ts_metadata {
290
+ bool used;
291
+ u64 ts_ns;
292
+ u64 ts_us;
293
+ u32 flags;
294
+ struct v4l2_timecode tc;
295
+};
296
+
214297 /**
215
- * struct venus_inst - holds per instance paramerters
298
+ * struct venus_inst - holds per instance parameters
216299 *
217300 * @list: used for attach an instance to the core
218301 * @lock: instance lock
....@@ -234,6 +317,10 @@
234317 * @colorspace: current color space
235318 * @quantization: current quantization
236319 * @xfer_func: current xfer function
320
+ * @codec_state: current codec API state (see DEC/ENC_STATE_)
321
+ * @reconf_wait: wait queue for resolution change event
322
+ * @subscriptions: used to hold current events subscriptions
323
+ * @buf_count: used to count number of buffers (reqbuf(0))
237324 * @fps: holds current FPS
238325 * @timeperframe: holds current time per frame structure
239326 * @fmt_out: a reference to output format structure
....@@ -248,8 +335,6 @@
248335 * @opb_buftype: output picture buffer type
249336 * @opb_fmt: output picture buffer raw format
250337 * @reconfig: a flag raised by decoder when the stream resolution changed
251
- * @reconfig_width: holds the new width
252
- * @reconfig_height: holds the new height
253338 * @hfi_codec: current codec for this instance in HFI space
254339 * @sequence_cap: a sequence counter for capture queue
255340 * @sequence_out: a sequence counter for output queue
....@@ -263,11 +348,13 @@
263348 * @priv: a private for HFI operations callbacks
264349 * @session_type: the type of the session (decoder or encoder)
265350 * @hprop: a union used as a holder by get property
351
+ * @last_buf: last capture buffer for dynamic-resoluton-change
266352 */
267353 struct venus_inst {
268354 struct list_head list;
269355 struct mutex lock;
270356 struct venus_core *core;
357
+ struct clock_data clk_data;
271358 struct list_head dpbbufs;
272359 struct list_head internalbufs;
273360 struct list_head registeredbufs;
....@@ -289,6 +376,12 @@
289376 u8 ycbcr_enc;
290377 u8 quantization;
291378 u8 xfer_func;
379
+ enum venus_dec_state codec_state;
380
+ wait_queue_head_t reconf_wait;
381
+ unsigned int subscriptions;
382
+ int buf_count;
383
+ struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
384
+ unsigned long payloads[VIDEO_MAX_FRAME];
292385 u64 fps;
293386 struct v4l2_fract timeperframe;
294387 const struct venus_format *fmt_out;
....@@ -303,8 +396,6 @@
303396 u32 opb_buftype;
304397 u32 opb_fmt;
305398 bool reconfig;
306
- u32 reconfig_width;
307
- u32 reconfig_height;
308399 u32 hfi_codec;
309400 u32 sequence_cap;
310401 u32 sequence_out;
....@@ -317,6 +408,9 @@
317408 const struct hfi_inst_ops *ops;
318409 u32 session_type;
319410 union hfi_get_property hprop;
411
+ unsigned int core_acquired: 1;
412
+ unsigned int bit_depth;
413
+ struct vb2_buffer *last_buf;
320414 };
321415
322416 #define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX)