1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Hantro VPU codec driver
5 * Copyright 2018 Google LLC.
6 * Tomasz Figa <tfiga@chromium.org>
12 #include <linux/interrupt.h>
13 #include <linux/v4l2-controls.h>
14 #include <media/h264-ctrls.h>
15 #include <media/mpeg2-ctrls.h>
16 #include <media/vp8-ctrls.h>
17 #include <media/videobuf2-core.h>
19 #define DEC_8190_ALIGN_MASK 0x07U
24 struct hantro_variant;
27 * struct hantro_aux_buf - auxiliary DMA buffer for hardware data
28 * @cpu: CPU pointer to the buffer.
29 * @dma: DMA address of the buffer.
30 * @size: Size of the buffer.
32 struct hantro_aux_buf {
39 * struct hantro_jpeg_enc_hw_ctx
40 * @bounce_buffer: Bounce buffer
42 struct hantro_jpeg_enc_hw_ctx {
43 struct hantro_aux_buf bounce_buffer;
46 /* Max. number of entries in the DPB (HW limitation). */
47 #define HANTRO_H264_DPB_SIZE 16
50 * struct hantro_h264_dec_ctrls
51 * @decode: Decode params
52 * @scaling: Scaling info
53 * @slice: Slice params
57 struct hantro_h264_dec_ctrls {
58 const struct v4l2_ctrl_h264_decode_params *decode;
59 const struct v4l2_ctrl_h264_scaling_matrix *scaling;
60 const struct v4l2_ctrl_h264_slice_params *slices;
61 const struct v4l2_ctrl_h264_sps *sps;
62 const struct v4l2_ctrl_h264_pps *pps;
66 * struct hantro_h264_dec_reflists
71 struct hantro_h264_dec_reflists {
72 u8 p[HANTRO_H264_DPB_SIZE];
73 u8 b0[HANTRO_H264_DPB_SIZE];
74 u8 b1[HANTRO_H264_DPB_SIZE];
78 * struct hantro_h264_dec_hw_ctx
79 * @priv: Private auxiliary buffer for hardware.
81 * @reflists: P/B0/B1 reflists
82 * @ctrls: V4L2 controls attached to a run
83 * @pic_size: Size in bytes of decoded picture, this is needed
84 * to pass the location of motion vectors.
86 struct hantro_h264_dec_hw_ctx {
87 struct hantro_aux_buf priv;
88 struct v4l2_h264_dpb_entry dpb[HANTRO_H264_DPB_SIZE];
89 struct hantro_h264_dec_reflists reflists;
90 struct hantro_h264_dec_ctrls ctrls;
95 * struct hantro_mpeg2_dec_hw_ctx
96 * @qtable: Quantization table
98 struct hantro_mpeg2_dec_hw_ctx {
99 struct hantro_aux_buf qtable;
103 * struct hantro_vp8d_hw_ctx
104 * @segment_map: Segment map buffer.
105 * @prob_tbl: Probability table buffer.
107 struct hantro_vp8_dec_hw_ctx {
108 struct hantro_aux_buf segment_map;
109 struct hantro_aux_buf prob_tbl;
113 * struct hantro_codec_ops - codec mode specific operations
115 * @init: If needed, can be used for initialization.
116 * Optional and called from process context.
117 * @exit: If needed, can be used to undo the .init phase.
118 * Optional and called from process context.
119 * @run: Start single {en,de)coding job. Called from atomic context
120 * to indicate that a pair of buffers is ready and the hardware
121 * should be programmed and started.
122 * @done: Read back processing results and additional data from hardware.
123 * @reset: Reset the hardware in case of a timeout.
125 struct hantro_codec_ops {
126 int (*init)(struct hantro_ctx *ctx);
127 void (*exit)(struct hantro_ctx *ctx);
128 void (*run)(struct hantro_ctx *ctx);
129 void (*done)(struct hantro_ctx *ctx, enum vb2_buffer_state);
130 void (*reset)(struct hantro_ctx *ctx);
134 * enum hantro_enc_fmt - source format ID for hardware registers.
136 enum hantro_enc_fmt {
137 RK3288_VPU_ENC_FMT_YUV420P = 0,
138 RK3288_VPU_ENC_FMT_YUV420SP = 1,
139 RK3288_VPU_ENC_FMT_YUYV422 = 2,
140 RK3288_VPU_ENC_FMT_UYVY422 = 3,
143 extern const struct hantro_variant rk3399_vpu_variant;
144 extern const struct hantro_variant rk3328_vpu_variant;
145 extern const struct hantro_variant rk3288_vpu_variant;
147 extern const u32 hantro_vp8_dec_mc_filter[8][6];
149 void hantro_watchdog(struct work_struct *work);
150 void hantro_run(struct hantro_ctx *ctx);
151 void hantro_irq_done(struct hantro_dev *vpu, unsigned int bytesused,
152 enum vb2_buffer_state result);
153 void hantro_prepare_run(struct hantro_ctx *ctx);
154 void hantro_finish_run(struct hantro_ctx *ctx);
156 void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
157 void rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx);
158 int hantro_jpeg_enc_init(struct hantro_ctx *ctx);
159 void hantro_jpeg_enc_exit(struct hantro_ctx *ctx);
161 struct vb2_buffer *hantro_h264_get_ref_buf(struct hantro_ctx *ctx,
162 unsigned int dpb_idx);
163 int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx);
164 void hantro_g1_h264_dec_run(struct hantro_ctx *ctx);
165 int hantro_h264_dec_init(struct hantro_ctx *ctx);
166 void hantro_h264_dec_exit(struct hantro_ctx *ctx);
168 void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
169 void rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx);
170 void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
171 const struct v4l2_ctrl_mpeg2_quantization *ctrl);
172 int hantro_mpeg2_dec_init(struct hantro_ctx *ctx);
173 void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx);
175 void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx);
176 void rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx);
177 int hantro_vp8_dec_init(struct hantro_ctx *ctx);
178 void hantro_vp8_dec_exit(struct hantro_ctx *ctx);
179 void hantro_vp8_prob_update(struct hantro_ctx *ctx,
180 const struct v4l2_ctrl_vp8_frame_header *hdr);
182 #endif /* HANTRO_HW_H_ */