CHROMIUM: [media] rk3288_vpu: implement vp8d hw config part
[firefly-linux-kernel-4.4.55.git] / drivers / media / platform / rk3288-vpu / rk3288_vpu_hw.h
1 /*
2  * Rockchip RK3288 VPU codec driver
3  *
4  * Copyright (C) 2014 Google, Inc.
5  *      Tomasz Figa <tfiga@chromium.org>
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16
17 #ifndef RK3288_VPU_HW_H_
18 #define RK3288_VPU_HW_H_
19
20 #include <media/videobuf2-core.h>
21
22 #define RK3288_HEADER_SIZE              256
23 #define RK3288_HW_PARAMS_SIZE           5487
24 #define RK3288_RET_PARAMS_SIZE          488
25
26 struct rk3288_vpu_dev;
27 struct rk3288_vpu_ctx;
28 struct rk3288_vpu_buf;
29
30 struct rk3288_vpu_h264d_priv_tbl;
31
32 /**
33  * enum rk3288_vpu_enc_fmt - source format ID for hardware registers.
34  */
35 enum rk3288_vpu_enc_fmt {
36         RK3288_VPU_ENC_FMT_YUV420P = 0,
37         RK3288_VPU_ENC_FMT_YUV420SP = 1,
38         RK3288_VPU_ENC_FMT_YUYV422 = 2,
39         RK3288_VPU_ENC_FMT_UYVY422 = 3,
40 };
41
42 /**
43  * struct rk3288_vp8e_reg_params - low level encoding parameters
44  * TODO: Create abstract structures for more generic controls or just
45  *       remove unused fields.
46  */
47 struct rk3288_vp8e_reg_params {
48         u32 unused_00[5];
49         u32 hdr_len;
50         u32 unused_18[8];
51         u32 enc_ctrl;
52         u32 unused_3c;
53         u32 enc_ctrl0;
54         u32 enc_ctrl1;
55         u32 enc_ctrl2;
56         u32 enc_ctrl3;
57         u32 enc_ctrl5;
58         u32 enc_ctrl4;
59         u32 str_hdr_rem_msb;
60         u32 str_hdr_rem_lsb;
61         u32 unused_60;
62         u32 mad_ctrl;
63         u32 unused_68;
64         u32 qp_val[8];
65         u32 bool_enc;
66         u32 vp8_ctrl0;
67         u32 rlc_ctrl;
68         u32 mb_ctrl;
69         u32 unused_9c[14];
70         u32 rgb_yuv_coeff[2];
71         u32 rgb_mask_msb;
72         u32 intra_area_ctrl;
73         u32 cir_intra_ctrl;
74         u32 unused_e8[2];
75         u32 first_roi_area;
76         u32 second_roi_area;
77         u32 mvc_ctrl;
78         u32 unused_fc;
79         u32 intra_penalty[7];
80         u32 unused_11c;
81         u32 seg_qp[24];
82         u32 dmv_4p_1p_penalty[32];
83         u32 dmv_qpel_penalty[32];
84         u32 vp8_ctrl1;
85         u32 bit_cost_golden;
86         u32 loop_flt_delta[2];
87 };
88
89 /**
90  * struct rk3288_vpu_aux_buf - auxiliary DMA buffer for hardware data
91  * @cpu:        CPU pointer to the buffer.
92  * @dma:        DMA address of the buffer.
93  * @size:       Size of the buffer.
94  */
95 struct rk3288_vpu_aux_buf {
96         void *cpu;
97         dma_addr_t dma;
98         size_t size;
99 };
100
101 /**
102  * struct rk3288_vpu_vp8e_hw_ctx - Context private data specific to codec mode.
103  * @ctrl_buf:           VP8 control buffer.
104  * @ext_buf:            VP8 ext data buffer.
105  * @mv_buf:             VP8 motion vector buffer.
106  * @ref_rec_ptr:        Bit flag for swapping ref and rec buffers every frame.
107  */
108 struct rk3288_vpu_vp8e_hw_ctx {
109         struct rk3288_vpu_aux_buf ctrl_buf;
110         struct rk3288_vpu_aux_buf ext_buf;
111         struct rk3288_vpu_aux_buf mv_buf;
112         u8 ref_rec_ptr:1;
113 };
114
115 /**
116  * struct rk3288_vpu_vp8d_hw_ctx - Context private data of VP8 decoder.
117  * @segment_map:        Segment map buffer.
118  * @prob_tbl:           Probability table buffer.
119  */
120 struct rk3288_vpu_vp8d_hw_ctx {
121         struct rk3288_vpu_aux_buf segment_map;
122         struct rk3288_vpu_aux_buf prob_tbl;
123 };
124
125 /**
126  * struct rk3288_vpu_h264d_hw_ctx - Per context data specific to H264 decoding.
127  * @priv_tbl:           Private auxiliary buffer for hardware.
128  */
129 struct rk3288_vpu_h264d_hw_ctx {
130         struct rk3288_vpu_aux_buf priv_tbl;
131 };
132
133 /**
134  * struct rk3288_vpu_hw_ctx - Context private data of hardware code.
135  * @codec_ops:          Set of operations associated with current codec mode.
136  */
137 struct rk3288_vpu_hw_ctx {
138         const struct rk3288_vpu_codec_ops *codec_ops;
139
140         /* Specific for particular codec modes. */
141         union {
142                 struct rk3288_vpu_vp8e_hw_ctx vp8e;
143                 struct rk3288_vpu_vp8d_hw_ctx vp8d;
144                 struct rk3288_vpu_h264d_hw_ctx h264d;
145                 /* Other modes will need different data. */
146         };
147 };
148
149 int rk3288_vpu_hw_probe(struct rk3288_vpu_dev *vpu);
150 void rk3288_vpu_hw_remove(struct rk3288_vpu_dev *vpu);
151
152 int rk3288_vpu_init(struct rk3288_vpu_ctx *ctx);
153 void rk3288_vpu_deinit(struct rk3288_vpu_ctx *ctx);
154
155 void rk3288_vpu_run(struct rk3288_vpu_ctx *ctx);
156
157 /* Run ops for H264 decoder */
158 int rk3288_vpu_h264d_init(struct rk3288_vpu_ctx *ctx);
159 void rk3288_vpu_h264d_exit(struct rk3288_vpu_ctx *ctx);
160 void rk3288_vpu_h264d_run(struct rk3288_vpu_ctx *ctx);
161 void rk3288_vpu_power_on(struct rk3288_vpu_dev *vpu);
162
163 /* Run ops for VP8 decoder */
164 int rk3288_vpu_vp8d_init(struct rk3288_vpu_ctx *ctx);
165 void rk3288_vpu_vp8d_exit(struct rk3288_vpu_ctx *ctx);
166 void rk3288_vpu_vp8d_run(struct rk3288_vpu_ctx *ctx);
167
168 /* Run ops for VP8 encoder */
169 int rk3288_vpu_vp8e_init(struct rk3288_vpu_ctx *ctx);
170 void rk3288_vpu_vp8e_exit(struct rk3288_vpu_ctx *ctx);
171 void rk3288_vpu_vp8e_run(struct rk3288_vpu_ctx *ctx);
172 void rk3288_vpu_vp8e_done(struct rk3288_vpu_ctx *ctx,
173                           enum vb2_buffer_state result);
174
175 void rk3288_vpu_vp8e_assemble_bitstream(struct rk3288_vpu_ctx *ctx,
176                                         struct rk3288_vpu_buf *dst_buf);
177
178 #endif /* RK3288_VPU_HW_H_ */