]> Git Repo - J-linux.git/blob - drivers/media/platform/qcom/venus/core.h
Merge tag 'amd-drm-next-6.5-2023-06-09' of https://gitlab.freedesktop.org/agd5f/linux...
[J-linux.git] / drivers / media / platform / qcom / venus / core.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2017 Linaro Ltd.
5  */
6
7 #ifndef __VENUS_CORE_H_
8 #define __VENUS_CORE_H_
9
10 #include <linux/bitops.h>
11 #include <linux/list.h>
12 #include <media/videobuf2-v4l2.h>
13 #include <media/v4l2-ctrls.h>
14 #include <media/v4l2-device.h>
15
16 #include "dbgfs.h"
17 #include "hfi.h"
18 #include "hfi_platform.h"
19 #include "hfi_helper.h"
20
21 #define VDBGL   "VenusLow : "
22 #define VDBGM   "VenusMed : "
23 #define VDBGH   "VenusHigh: "
24 #define VDBGFW  "VenusFW  : "
25
26 #define VIDC_CLKS_NUM_MAX               4
27 #define VIDC_VCODEC_CLKS_NUM_MAX        2
28 #define VIDC_PMDOMAINS_NUM_MAX          3
29 #define VIDC_RESETS_NUM_MAX             2
30
31 extern int venus_fw_debug;
32
33 struct freq_tbl {
34         unsigned int load;
35         unsigned long freq;
36 };
37
38 struct reg_val {
39         u32 reg;
40         u32 value;
41 };
42
43 struct bw_tbl {
44         u32 mbs_per_sec;
45         u32 avg;
46         u32 peak;
47         u32 avg_10bit;
48         u32 peak_10bit;
49 };
50
51 struct venus_resources {
52         u64 dma_mask;
53         const struct freq_tbl *freq_tbl;
54         unsigned int freq_tbl_size;
55         const struct bw_tbl *bw_tbl_enc;
56         unsigned int bw_tbl_enc_size;
57         const struct bw_tbl *bw_tbl_dec;
58         unsigned int bw_tbl_dec_size;
59         const struct reg_val *reg_tbl;
60         unsigned int reg_tbl_size;
61         const struct hfi_ubwc_config *ubwc_conf;
62         const char * const clks[VIDC_CLKS_NUM_MAX];
63         unsigned int clks_num;
64         const char * const vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
65         const char * const vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
66         unsigned int vcodec_clks_num;
67         const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX];
68         unsigned int vcodec_pmdomains_num;
69         const char **opp_pmdomain;
70         unsigned int vcodec_num;
71         const char * const resets[VIDC_RESETS_NUM_MAX];
72         unsigned int resets_num;
73         enum hfi_version hfi_version;
74         u8 num_vpp_pipes;
75         u32 max_load;
76         unsigned int vmem_id;
77         u32 vmem_size;
78         u32 vmem_addr;
79         u32 cp_start;
80         u32 cp_size;
81         u32 cp_nonpixel_start;
82         u32 cp_nonpixel_size;
83         const char *fwname;
84 };
85
86 struct venus_format {
87         u32 pixfmt;
88         unsigned int num_planes;
89         u32 type;
90         u32 flags;
91 };
92
93 /**
94  * struct venus_core - holds core parameters valid for all instances
95  *
96  * @base:       IO memory base address
97  * @vbif_base:  IO memory vbif base address
98  * @cpu_base:   IO memory cpu base address
99  * @cpu_cs_base:        IO memory cpu_cs base address
100  * @cpu_ic_base:        IO memory cpu_ic base address
101  * @wrapper_base:       IO memory wrapper base address
102  * @wrapper_tz_base:    IO memory wrapper TZ base address
103  * @aon_base:   AON base address
104  * @irq:                Venus irq
105  * @clks:       an array of struct clk pointers
106  * @vcodec0_clks: an array of vcodec0 struct clk pointers
107  * @vcodec1_clks: an array of vcodec1 struct clk pointers
108  * @video_path: an interconnect handle to video to/from memory path
109  * @cpucfg_path: an interconnect handle to cpu configuration path
110  * @has_opp_table: does OPP table exist
111  * @pmdomains:  an array of pmdomains struct device pointers
112  * @opp_dl_venus: an device-link for device OPP
113  * @opp_pmdomain: an OPP power-domain
114  * @resets: an array of reset signals
115  * @vdev_dec:   a reference to video device structure for decoder instances
116  * @vdev_enc:   a reference to video device structure for encoder instances
117  * @v4l2_dev:   a holder for v4l2 device structure
118  * @res:                a reference to venus resources structure
119  * @dev:                convenience struct device pointer
120  * @dev_dec:    convenience struct device pointer for decoder device
121  * @dev_enc:    convenience struct device pointer for encoder device
122  * @use_tz:     a flag that suggests presence of trustzone
123  * @fw:         structure of firmware parameters
124  * @lock:       a lock for this strucure
125  * @instances:  a list_head of all instances
126  * @insts_count:        num of instances
127  * @state:      the state of the venus core
128  * @done:       a completion for sync HFI operations
129  * @error:      an error returned during last HFI sync operations
130  * @sys_error:  an error flag that signal system error event
131  * @sys_err_done: a waitqueue to wait for system error recovery end
132  * @core_ops:   the core operations
133  * @pm_ops:     a pointer to pm operations
134  * @pm_lock:    a lock for PM operations
135  * @enc_codecs: encoders supported by this core
136  * @dec_codecs: decoders supported by this core
137  * @max_sessions_supported:     holds the maximum number of sessions
138  * @priv:       a private filed for HFI operations
139  * @ops:                the core HFI operations
140  * @work:       a delayed work for handling system fatal error
141  * @caps:       an array of supported HFI capabilities
142  * @codecs_count: platform codecs count
143  * @core0_usage_count: usage counter for core0
144  * @core1_usage_count: usage counter for core1
145  * @root:       debugfs root directory
146  */
147 struct venus_core {
148         void __iomem *base;
149         void __iomem *vbif_base;
150         void __iomem *cpu_base;
151         void __iomem *cpu_cs_base;
152         void __iomem *cpu_ic_base;
153         void __iomem *wrapper_base;
154         void __iomem *wrapper_tz_base;
155         void __iomem *aon_base;
156         int irq;
157         struct clk *clks[VIDC_CLKS_NUM_MAX];
158         struct clk *vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
159         struct clk *vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
160         struct icc_path *video_path;
161         struct icc_path *cpucfg_path;
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;
166         struct reset_control *resets[VIDC_RESETS_NUM_MAX];
167         struct video_device *vdev_dec;
168         struct video_device *vdev_enc;
169         struct v4l2_device v4l2_dev;
170         const struct venus_resources *res;
171         struct device *dev;
172         struct device *dev_dec;
173         struct device *dev_enc;
174         unsigned int use_tz;
175         struct video_firmware {
176                 struct device *dev;
177                 struct iommu_domain *iommu_domain;
178                 size_t mapped_mem_size;
179                 phys_addr_t mem_phys;
180                 size_t mem_size;
181         } fw;
182         struct mutex lock;
183         struct list_head instances;
184         atomic_t insts_count;
185         unsigned int state;
186         struct completion done;
187         unsigned int error;
188         unsigned long sys_error;
189         wait_queue_head_t sys_err_done;
190         const struct hfi_core_ops *core_ops;
191         const struct venus_pm_ops *pm_ops;
192         struct mutex pm_lock;
193         unsigned long enc_codecs;
194         unsigned long dec_codecs;
195         unsigned int max_sessions_supported;
196         void *priv;
197         const struct hfi_ops *ops;
198         struct delayed_work work;
199         struct hfi_plat_caps caps[MAX_CODEC_NUM];
200         unsigned int codecs_count;
201         unsigned int core0_usage_count;
202         unsigned int core1_usage_count;
203         struct dentry *root;
204 };
205
206 struct vdec_controls {
207         u32 post_loop_deb_mode;
208         u32 profile;
209         u32 level;
210         u32 display_delay;
211         u32 display_delay_enable;
212         u64 conceal_color;
213 };
214
215 struct venc_controls {
216         u16 gop_size;
217         u32 num_p_frames;
218         u32 num_b_frames;
219         u32 bitrate_mode;
220         u32 bitrate;
221         u32 bitrate_peak;
222         u32 rc_enable;
223         u32 const_quality;
224         u32 frame_skip_mode;
225
226         u32 h264_i_period;
227         u32 h264_entropy_mode;
228         u32 h264_i_qp;
229         u32 h264_p_qp;
230         u32 h264_b_qp;
231         u32 h264_min_qp;
232         u32 h264_max_qp;
233         u32 h264_i_min_qp;
234         u32 h264_i_max_qp;
235         u32 h264_p_min_qp;
236         u32 h264_p_max_qp;
237         u32 h264_b_min_qp;
238         u32 h264_b_max_qp;
239         u32 h264_loop_filter_mode;
240         s32 h264_loop_filter_alpha;
241         s32 h264_loop_filter_beta;
242         u32 h264_8x8_transform;
243
244         u32 hevc_i_qp;
245         u32 hevc_p_qp;
246         u32 hevc_b_qp;
247         u32 hevc_min_qp;
248         u32 hevc_max_qp;
249         u32 hevc_i_min_qp;
250         u32 hevc_i_max_qp;
251         u32 hevc_p_min_qp;
252         u32 hevc_p_max_qp;
253         u32 hevc_b_min_qp;
254         u32 hevc_b_max_qp;
255
256         u32 vp8_min_qp;
257         u32 vp8_max_qp;
258
259         u32 multi_slice_mode;
260         u32 multi_slice_max_bytes;
261         u32 multi_slice_max_mb;
262
263         u32 header_mode;
264         bool aud_enable;
265         u32 intra_refresh_type;
266         u32 intra_refresh_period;
267
268         struct {
269                 u32 h264;
270                 u32 mpeg4;
271                 u32 hevc;
272                 u32 vp8;
273                 u32 vp9;
274         } profile;
275         struct {
276                 u32 h264;
277                 u32 mpeg4;
278                 u32 hevc;
279                 u32 vp9;
280         } level;
281
282         u32 base_priority_id;
283         u32 ltr_count;
284         struct v4l2_ctrl_hdr10_cll_info cll;
285         struct v4l2_ctrl_hdr10_mastering_display mastering;
286 };
287
288 struct venus_buffer {
289         struct vb2_v4l2_buffer vb;
290         struct list_head list;
291         dma_addr_t dma_addr;
292         u32 size;
293         struct list_head reg_list;
294         u32 flags;
295         struct list_head ref_list;
296 };
297
298 struct clock_data {
299         u32 core_id;
300         unsigned long freq;
301         unsigned long vpp_freq;
302         unsigned long vsp_freq;
303         unsigned long low_power_freq;
304 };
305
306 #define to_venus_buffer(ptr)    container_of(ptr, struct venus_buffer, vb)
307
308 enum venus_dec_state {
309         VENUS_DEC_STATE_DEINIT          = 0,
310         VENUS_DEC_STATE_INIT            = 1,
311         VENUS_DEC_STATE_CAPTURE_SETUP   = 2,
312         VENUS_DEC_STATE_STOPPED         = 3,
313         VENUS_DEC_STATE_SEEK            = 4,
314         VENUS_DEC_STATE_DRAIN           = 5,
315         VENUS_DEC_STATE_DECODING        = 6,
316         VENUS_DEC_STATE_DRC             = 7,
317 };
318
319 enum venus_enc_state {
320         VENUS_ENC_STATE_DEINIT          = 0,
321         VENUS_ENC_STATE_INIT            = 1,
322         VENUS_ENC_STATE_ENCODING        = 2,
323         VENUS_ENC_STATE_STOPPED         = 3,
324         VENUS_ENC_STATE_DRAIN           = 4,
325 };
326
327 struct venus_ts_metadata {
328         bool used;
329         u64 ts_ns;
330         u64 ts_us;
331         u32 flags;
332         struct v4l2_timecode tc;
333 };
334
335 enum venus_inst_modes {
336         VENUS_LOW_POWER = BIT(0),
337 };
338
339 /**
340  * struct venus_inst - holds per instance parameters
341  *
342  * @list:       used for attach an instance to the core
343  * @lock:       instance lock
344  * @core:       a reference to the core struct
345  * @clk_data:   clock data per core ID
346  * @dpbbufs:    a list of decoded picture buffers
347  * @internalbufs:       a list of internal bufferes
348  * @registeredbufs:     a list of registered capture bufferes
349  * @delayed_process:    a list of delayed buffers
350  * @delayed_process_work:       a work_struct for process delayed buffers
351  * @nonblock:           nonblocking flag
352  * @ctrl_handler:       v4l control handler
353  * @controls:   a union of decoder and encoder control parameters
354  * @fh:  a holder of v4l file handle structure
355  * @streamon_cap: stream on flag for capture queue
356  * @streamon_out: stream on flag for output queue
357  * @width:      current capture width
358  * @height:     current capture height
359  * @crop:       current crop rectangle
360  * @fw_min_cnt:  firmware minimum buffer count
361  * @out_width:  current output width
362  * @out_height: current output height
363  * @colorspace: current color space
364  * @ycbcr_enc:  current YCbCr encoding
365  * @quantization:       current quantization
366  * @xfer_func:  current xfer function
367  * @codec_state:        current codec API state (see DEC/ENC_STATE_)
368  * @reconf_wait:        wait queue for resolution change event
369  * @subscriptions:      used to hold current events subscriptions
370  * @buf_count:          used to count number of buffers (reqbuf(0))
371  * @tss:                timestamp metadata
372  * @payloads:           cache plane payload to use it for clock/BW scaling
373  * @fps:                holds current FPS
374  * @timeperframe:       holds current time per frame structure
375  * @fmt_out:    a reference to output format structure
376  * @fmt_cap:    a reference to capture format structure
377  * @num_input_bufs:     holds number of input buffers
378  * @num_output_bufs:    holds number of output buffers
379  * @input_buf_size:     holds input buffer size
380  * @output_buf_size:    holds output buffer size
381  * @output2_buf_size:   holds secondary decoder output buffer size
382  * @dpb_buftype:        decoded picture buffer type
383  * @dpb_fmt:            decoded picture buffer raw format
384  * @opb_buftype:        output picture buffer type
385  * @opb_fmt:            output picture buffer raw format
386  * @reconfig:   a flag raised by decoder when the stream resolution changed
387  * @hfi_codec:          current codec for this instance in HFI space
388  * @sequence_cap:       a sequence counter for capture queue
389  * @sequence_out:       a sequence counter for output queue
390  * @m2m_dev:    a reference to m2m device structure
391  * @m2m_ctx:    a reference to m2m context structure
392  * @state:      current state of the instance
393  * @done:       a completion for sync HFI operation
394  * @error:      an error returned during last HFI sync operation
395  * @session_error:      a flag rised by HFI interface in case of session error
396  * @ops:                HFI operations
397  * @priv:       a private for HFI operations callbacks
398  * @session_type:       the type of the session (decoder or encoder)
399  * @hprop:      a union used as a holder by get property
400  * @core_acquired:      the Core has been acquired
401  * @bit_depth:          current bitstream bit-depth
402  * @pic_struct:         bitstream progressive vs interlaced
403  * @next_buf_last: a flag to mark next queued capture buffer as last
404  * @drain_active:       Drain sequence is in progress
405  * @flags:      bitmask flags describing current instance mode
406  * @dpb_ids:    DPB buffer ID's
407  */
408 struct venus_inst {
409         struct list_head list;
410         struct mutex lock;
411         struct venus_core *core;
412         struct clock_data clk_data;
413         struct list_head dpbbufs;
414         struct list_head internalbufs;
415         struct list_head registeredbufs;
416         struct list_head delayed_process;
417         struct work_struct delayed_process_work;
418         bool nonblock;
419
420         struct v4l2_ctrl_handler ctrl_handler;
421         union {
422                 struct vdec_controls dec;
423                 struct venc_controls enc;
424         } controls;
425         struct v4l2_fh fh;
426         unsigned int streamon_cap, streamon_out;
427         u32 width;
428         u32 height;
429         struct v4l2_rect crop;
430         u32 fw_min_cnt;
431         u32 out_width;
432         u32 out_height;
433         u32 colorspace;
434         u8 ycbcr_enc;
435         u8 quantization;
436         u8 xfer_func;
437         enum venus_dec_state codec_state;
438         enum venus_enc_state enc_state;
439         wait_queue_head_t reconf_wait;
440         unsigned int subscriptions;
441         int buf_count;
442         struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
443         unsigned long payloads[VIDEO_MAX_FRAME];
444         u64 fps;
445         struct v4l2_fract timeperframe;
446         const struct venus_format *fmt_out;
447         const struct venus_format *fmt_cap;
448         unsigned int num_input_bufs;
449         unsigned int num_output_bufs;
450         unsigned int input_buf_size;
451         unsigned int output_buf_size;
452         unsigned int output2_buf_size;
453         u32 dpb_buftype;
454         u32 dpb_fmt;
455         u32 opb_buftype;
456         u32 opb_fmt;
457         bool reconfig;
458         u32 hfi_codec;
459         u32 sequence_cap;
460         u32 sequence_out;
461         struct v4l2_m2m_dev *m2m_dev;
462         struct v4l2_m2m_ctx *m2m_ctx;
463         unsigned int state;
464         struct completion done;
465         unsigned int error;
466         bool session_error;
467         const struct hfi_inst_ops *ops;
468         u32 session_type;
469         union hfi_get_property hprop;
470         unsigned int core_acquired: 1;
471         unsigned int bit_depth;
472         unsigned int pic_struct;
473         bool next_buf_last;
474         bool drain_active;
475         enum venus_inst_modes flags;
476         struct ida dpb_ids;
477 };
478
479 #define IS_V1(core)     ((core)->res->hfi_version == HFI_VERSION_1XX)
480 #define IS_V3(core)     ((core)->res->hfi_version == HFI_VERSION_3XX)
481 #define IS_V4(core)     ((core)->res->hfi_version == HFI_VERSION_4XX)
482 #define IS_V6(core)     ((core)->res->hfi_version == HFI_VERSION_6XX)
483
484 #define ctrl_to_inst(ctrl)      \
485         container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
486
487 static inline struct venus_inst *to_inst(struct file *filp)
488 {
489         return container_of(filp->private_data, struct venus_inst, fh);
490 }
491
492 static inline void *to_hfi_priv(struct venus_core *core)
493 {
494         return core->priv;
495 }
496
497 static inline struct hfi_plat_caps *
498 venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
499 {
500         unsigned int c;
501
502         for (c = 0; c < core->codecs_count; c++) {
503                 if (core->caps[c].codec == codec &&
504                     core->caps[c].domain == domain)
505                         return &core->caps[c];
506         }
507
508         return NULL;
509 }
510
511 #endif
This page took 0.06122 seconds and 4 git commands to generate.