linux/drivers/media/platform/qcom/venus/core.h
<<
>>
Prefs
   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/list.h>
  11#include <media/videobuf2-v4l2.h>
  12#include <media/v4l2-ctrls.h>
  13#include <media/v4l2-device.h>
  14
  15#include "hfi.h"
  16
  17#define VIDC_CLKS_NUM_MAX       4
  18
  19struct freq_tbl {
  20        unsigned int load;
  21        unsigned long freq;
  22};
  23
  24struct reg_val {
  25        u32 reg;
  26        u32 value;
  27};
  28
  29struct codec_freq_data {
  30        u32 pixfmt;
  31        u32 session_type;
  32        unsigned long vpp_freq;
  33        unsigned long vsp_freq;
  34};
  35
  36struct bw_tbl {
  37        u32 mbs_per_sec;
  38        u32 avg;
  39        u32 peak;
  40        u32 avg_10bit;
  41        u32 peak_10bit;
  42};
  43
  44struct venus_resources {
  45        u64 dma_mask;
  46        const struct freq_tbl *freq_tbl;
  47        unsigned int freq_tbl_size;
  48        const struct bw_tbl *bw_tbl_enc;
  49        unsigned int bw_tbl_enc_size;
  50        const struct bw_tbl *bw_tbl_dec;
  51        unsigned int bw_tbl_dec_size;
  52        const struct reg_val *reg_tbl;
  53        unsigned int reg_tbl_size;
  54        const struct codec_freq_data *codec_freq_data;
  55        unsigned int codec_freq_data_size;
  56        const char * const clks[VIDC_CLKS_NUM_MAX];
  57        unsigned int clks_num;
  58        enum hfi_version hfi_version;
  59        u32 max_load;
  60        unsigned int vmem_id;
  61        u32 vmem_size;
  62        u32 vmem_addr;
  63        const char *fwname;
  64};
  65
  66struct venus_format {
  67        u32 pixfmt;
  68        unsigned int num_planes;
  69        u32 type;
  70        u32 flags;
  71};
  72
  73#define MAX_PLANES              4
  74#define MAX_FMT_ENTRIES         32
  75#define MAX_CAP_ENTRIES         32
  76#define MAX_ALLOC_MODE_ENTRIES  16
  77#define MAX_CODEC_NUM           32
  78
  79struct raw_formats {
  80        u32 buftype;
  81        u32 fmt;
  82};
  83
  84struct venus_caps {
  85        u32 codec;
  86        u32 domain;
  87        bool cap_bufs_mode_dynamic;
  88        unsigned int num_caps;
  89        struct hfi_capability caps[MAX_CAP_ENTRIES];
  90        unsigned int num_pl;
  91        struct hfi_profile_level pl[HFI_MAX_PROFILE_COUNT];
  92        unsigned int num_fmts;
  93        struct raw_formats fmts[MAX_FMT_ENTRIES];
  94        bool valid;     /* used only for Venus v1xx */
  95};
  96
  97/**
  98 * struct venus_core - holds core parameters valid for all instances
  99 *
 100 * @base:       IO memory base address
 101 * @irq:                Venus irq
 102 * @clks:       an array of struct clk pointers
 103 * @core0_clk:  a struct clk pointer for core0
 104 * @core1_clk:  a struct clk pointer for core1
 105 * @core0_bus_clk: a struct clk pointer for core0 bus clock
 106 * @core1_bus_clk: a struct clk pointer for core1 bus clock
 107 * @vdev_dec:   a reference to video device structure for decoder instances
 108 * @vdev_enc:   a reference to video device structure for encoder instances
 109 * @v4l2_dev:   a holder for v4l2 device structure
 110 * @res:                a reference to venus resources structure
 111 * @dev:                convenience struct device pointer
 112 * @dev_dec:    convenience struct device pointer for decoder device
 113 * @dev_enc:    convenience struct device pointer for encoder device
 114 * @use_tz:     a flag that suggests presence of trustzone
 115 * @lock:       a lock for this strucure
 116 * @instances:  a list_head of all instances
 117 * @insts_count:        num of instances
 118 * @state:      the state of the venus core
 119 * @done:       a completion for sync HFI operations
 120 * @error:      an error returned during last HFI sync operations
 121 * @sys_error:  an error flag that signal system error event
 122 * @core_ops:   the core operations
 123 * @enc_codecs: encoders supported by this core
 124 * @dec_codecs: decoders supported by this core
 125 * @max_sessions_supported:     holds the maximum number of sessions
 126 * @core_caps:  core capabilities
 127 * @priv:       a private filed for HFI operations
 128 * @ops:                the core HFI operations
 129 * @work:       a delayed work for handling system fatal error
 130 */
 131struct venus_core {
 132        void __iomem *base;
 133        int irq;
 134        struct clk *clks[VIDC_CLKS_NUM_MAX];
 135        struct clk *core0_clk;
 136        struct clk *core1_clk;
 137        struct clk *core0_bus_clk;
 138        struct clk *core1_bus_clk;
 139        struct icc_path *video_path;
 140        struct icc_path *cpucfg_path;
 141        struct video_device *vdev_dec;
 142        struct video_device *vdev_enc;
 143        struct v4l2_device v4l2_dev;
 144        const struct venus_resources *res;
 145        struct device *dev;
 146        struct device *dev_dec;
 147        struct device *dev_enc;
 148        unsigned int use_tz;
 149        struct video_firmware {
 150                struct device *dev;
 151                struct iommu_domain *iommu_domain;
 152                size_t mapped_mem_size;
 153        } fw;
 154        struct mutex lock;
 155        struct list_head instances;
 156        atomic_t insts_count;
 157        unsigned int state;
 158        struct completion done;
 159        unsigned int error;
 160        bool sys_error;
 161        const struct hfi_core_ops *core_ops;
 162        unsigned long enc_codecs;
 163        unsigned long dec_codecs;
 164        unsigned int max_sessions_supported;
 165#define ENC_ROTATION_CAPABILITY         0x1
 166#define ENC_SCALING_CAPABILITY          0x2
 167#define ENC_DEINTERLACE_CAPABILITY      0x4
 168#define DEC_MULTI_STREAM_CAPABILITY     0x8
 169        unsigned int core_caps;
 170        void *priv;
 171        const struct hfi_ops *ops;
 172        struct delayed_work work;
 173        struct venus_caps caps[MAX_CODEC_NUM];
 174        unsigned int codecs_count;
 175};
 176
 177struct vdec_controls {
 178        u32 post_loop_deb_mode;
 179        u32 profile;
 180        u32 level;
 181};
 182
 183struct venc_controls {
 184        u16 gop_size;
 185        u32 num_p_frames;
 186        u32 num_b_frames;
 187        u32 bitrate_mode;
 188        u32 bitrate;
 189        u32 bitrate_peak;
 190
 191        u32 h264_i_period;
 192        u32 h264_entropy_mode;
 193        u32 h264_i_qp;
 194        u32 h264_p_qp;
 195        u32 h264_b_qp;
 196        u32 h264_min_qp;
 197        u32 h264_max_qp;
 198        u32 h264_loop_filter_mode;
 199        s32 h264_loop_filter_alpha;
 200        s32 h264_loop_filter_beta;
 201
 202        u32 vp8_min_qp;
 203        u32 vp8_max_qp;
 204
 205        u32 multi_slice_mode;
 206        u32 multi_slice_max_bytes;
 207        u32 multi_slice_max_mb;
 208
 209        u32 header_mode;
 210
 211        struct {
 212                u32 mpeg4;
 213                u32 h264;
 214                u32 vpx;
 215                u32 hevc;
 216        } profile;
 217        struct {
 218                u32 mpeg4;
 219                u32 h264;
 220                u32 hevc;
 221        } level;
 222};
 223
 224struct venus_buffer {
 225        struct vb2_v4l2_buffer vb;
 226        struct list_head list;
 227        dma_addr_t dma_addr;
 228        u32 size;
 229        struct list_head reg_list;
 230        u32 flags;
 231        struct list_head ref_list;
 232};
 233
 234struct clock_data {
 235        u32 core_id;
 236        unsigned long freq;
 237        const struct codec_freq_data *codec_freq_data;
 238};
 239
 240#define to_venus_buffer(ptr)    container_of(ptr, struct venus_buffer, vb)
 241
 242enum venus_dec_state {
 243        VENUS_DEC_STATE_DEINIT          = 0,
 244        VENUS_DEC_STATE_INIT            = 1,
 245        VENUS_DEC_STATE_CAPTURE_SETUP   = 2,
 246        VENUS_DEC_STATE_STOPPED         = 3,
 247        VENUS_DEC_STATE_SEEK            = 4,
 248        VENUS_DEC_STATE_DRAIN           = 5,
 249        VENUS_DEC_STATE_DECODING        = 6,
 250        VENUS_DEC_STATE_DRC             = 7
 251};
 252
 253struct venus_ts_metadata {
 254        bool used;
 255        u64 ts_ns;
 256        u64 ts_us;
 257        u32 flags;
 258        struct v4l2_timecode tc;
 259};
 260
 261/**
 262 * struct venus_inst - holds per instance parameters
 263 *
 264 * @list:       used for attach an instance to the core
 265 * @lock:       instance lock
 266 * @core:       a reference to the core struct
 267 * @dpbbufs:    a list of decoded picture buffers
 268 * @internalbufs:       a list of internal bufferes
 269 * @registeredbufs:     a list of registered capture bufferes
 270 * @delayed_process     a list of delayed buffers
 271 * @delayed_process_work:       a work_struct for process delayed buffers
 272 * @ctrl_handler:       v4l control handler
 273 * @controls:   a union of decoder and encoder control parameters
 274 * @fh:  a holder of v4l file handle structure
 275 * @streamon_cap: stream on flag for capture queue
 276 * @streamon_out: stream on flag for output queue
 277 * @width:      current capture width
 278 * @height:     current capture height
 279 * @out_width:  current output width
 280 * @out_height: current output height
 281 * @colorspace: current color space
 282 * @quantization:       current quantization
 283 * @xfer_func:  current xfer function
 284 * @codec_state:        current codec API state (see DEC/ENC_STATE_)
 285 * @reconf_wait:        wait queue for resolution change event
 286 * @subscriptions:      used to hold current events subscriptions
 287 * @buf_count:          used to count number of buffers (reqbuf(0))
 288 * @fps:                holds current FPS
 289 * @timeperframe:       holds current time per frame structure
 290 * @fmt_out:    a reference to output format structure
 291 * @fmt_cap:    a reference to capture format structure
 292 * @num_input_bufs:     holds number of input buffers
 293 * @num_output_bufs:    holds number of output buffers
 294 * @input_buf_size      holds input buffer size
 295 * @output_buf_size:    holds output buffer size
 296 * @output2_buf_size:   holds secondary decoder output buffer size
 297 * @dpb_buftype:        decoded picture buffer type
 298 * @dpb_fmt:            decoded picture buffer raw format
 299 * @opb_buftype:        output picture buffer type
 300 * @opb_fmt:            output picture buffer raw format
 301 * @reconfig:   a flag raised by decoder when the stream resolution changed
 302 * @hfi_codec:          current codec for this instance in HFI space
 303 * @sequence_cap:       a sequence counter for capture queue
 304 * @sequence_out:       a sequence counter for output queue
 305 * @m2m_dev:    a reference to m2m device structure
 306 * @m2m_ctx:    a reference to m2m context structure
 307 * @state:      current state of the instance
 308 * @done:       a completion for sync HFI operation
 309 * @error:      an error returned during last HFI sync operation
 310 * @session_error:      a flag rised by HFI interface in case of session error
 311 * @ops:                HFI operations
 312 * @priv:       a private for HFI operations callbacks
 313 * @session_type:       the type of the session (decoder or encoder)
 314 * @hprop:      a union used as a holder by get property
 315 */
 316struct venus_inst {
 317        struct list_head list;
 318        struct mutex lock;
 319        struct venus_core *core;
 320        struct clock_data clk_data;
 321        struct list_head dpbbufs;
 322        struct list_head internalbufs;
 323        struct list_head registeredbufs;
 324        struct list_head delayed_process;
 325        struct work_struct delayed_process_work;
 326
 327        struct v4l2_ctrl_handler ctrl_handler;
 328        union {
 329                struct vdec_controls dec;
 330                struct venc_controls enc;
 331        } controls;
 332        struct v4l2_fh fh;
 333        unsigned int streamon_cap, streamon_out;
 334        u32 width;
 335        u32 height;
 336        u32 out_width;
 337        u32 out_height;
 338        u32 colorspace;
 339        u8 ycbcr_enc;
 340        u8 quantization;
 341        u8 xfer_func;
 342        enum venus_dec_state codec_state;
 343        wait_queue_head_t reconf_wait;
 344        unsigned int subscriptions;
 345        int buf_count;
 346        struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
 347        u64 fps;
 348        struct v4l2_fract timeperframe;
 349        const struct venus_format *fmt_out;
 350        const struct venus_format *fmt_cap;
 351        unsigned int num_input_bufs;
 352        unsigned int num_output_bufs;
 353        unsigned int input_buf_size;
 354        unsigned int output_buf_size;
 355        unsigned int output2_buf_size;
 356        u32 dpb_buftype;
 357        u32 dpb_fmt;
 358        u32 opb_buftype;
 359        u32 opb_fmt;
 360        bool reconfig;
 361        u32 hfi_codec;
 362        u32 sequence_cap;
 363        u32 sequence_out;
 364        struct v4l2_m2m_dev *m2m_dev;
 365        struct v4l2_m2m_ctx *m2m_ctx;
 366        unsigned int state;
 367        struct completion done;
 368        unsigned int error;
 369        bool session_error;
 370        const struct hfi_inst_ops *ops;
 371        u32 session_type;
 372        union hfi_get_property hprop;
 373};
 374
 375#define IS_V1(core)     ((core)->res->hfi_version == HFI_VERSION_1XX)
 376#define IS_V3(core)     ((core)->res->hfi_version == HFI_VERSION_3XX)
 377#define IS_V4(core)     ((core)->res->hfi_version == HFI_VERSION_4XX)
 378
 379#define ctrl_to_inst(ctrl)      \
 380        container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
 381
 382static inline struct venus_inst *to_inst(struct file *filp)
 383{
 384        return container_of(filp->private_data, struct venus_inst, fh);
 385}
 386
 387static inline void *to_hfi_priv(struct venus_core *core)
 388{
 389        return core->priv;
 390}
 391
 392static inline struct venus_caps *
 393venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
 394{
 395        unsigned int c;
 396
 397        for (c = 0; c < core->codecs_count; c++) {
 398                if (core->caps[c].codec == codec &&
 399                    core->caps[c].domain == domain)
 400                        return &core->caps[c];
 401        }
 402
 403        return NULL;
 404}
 405
 406#endif
 407