hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/platform/coda/coda.h
....@@ -1,3 +1,4 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Coda multi-standard codec IP
34 *
....@@ -5,11 +6,6 @@
56 * Javier Martin, <javier.martin@vista-silicon.com>
67 * Xavier Duret
78 * Copyright (C) 2012-2014 Philipp Zabel, Pengutronix
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
139 */
1410
1511 #ifndef __CODA_H__
....@@ -73,8 +69,8 @@
7369
7470 struct coda_dev {
7571 struct v4l2_device v4l2_dev;
76
- struct video_device vfd[5];
77
- struct platform_device *plat_dev;
72
+ struct video_device vfd[6];
73
+ struct device *dev;
7874 const struct coda_devtype *devtype;
7975 int firmware;
8076 struct vdoa_data *vdoa;
....@@ -90,12 +86,10 @@
9086 struct gen_pool *iram_pool;
9187 struct coda_aux_buf iram;
9288
93
- spinlock_t irqlock;
9489 struct mutex dev_mutex;
9590 struct mutex coda_mutex;
9691 struct workqueue_struct *workqueue;
9792 struct v4l2_m2m_dev *m2m_dev;
98
- struct list_head instances;
9993 struct ida ida;
10094 struct dentry *debugfs_root;
10195 };
....@@ -119,15 +113,25 @@
119113 u8 h264_disable_deblocking_filter_idc;
120114 s8 h264_slice_alpha_c0_offset_div2;
121115 s8 h264_slice_beta_offset_div2;
116
+ bool h264_constrained_intra_pred_flag;
117
+ s8 h264_chroma_qp_index_offset;
122118 u8 h264_profile_idc;
123119 u8 h264_level_idc;
120
+ u8 mpeg2_profile_idc;
121
+ u8 mpeg2_level_idc;
124122 u8 mpeg4_intra_qp;
125123 u8 mpeg4_inter_qp;
126124 u8 gop_size;
127125 int intra_refresh;
126
+ enum v4l2_jpeg_chroma_subsampling jpeg_chroma_subsampling;
128127 u8 jpeg_quality;
129128 u8 jpeg_restart_interval;
130129 u8 *jpeg_qmat_tab[3];
130
+ int jpeg_qmat_index[3];
131
+ int jpeg_huff_dc_index[3];
132
+ int jpeg_huff_ac_index[3];
133
+ u32 *jpeg_huff_data;
134
+ struct coda_huff_tab *jpeg_huff_tab;
131135 int codec_mode;
132136 int codec_mode_aux;
133137 enum v4l2_mpeg_video_multi_slice_mode slice_mode;
....@@ -138,6 +142,14 @@
138142 u32 slice_max_bits;
139143 u32 slice_max_mb;
140144 bool force_ipicture;
145
+ bool gop_size_changed;
146
+ bool bitrate_changed;
147
+ bool framerate_changed;
148
+ bool h264_intra_qp_changed;
149
+ bool intra_refresh_changed;
150
+ bool slice_mode_changed;
151
+ bool frame_rc_enable;
152
+ bool mb_rc_enable;
141153 };
142154
143155 struct coda_buffer_meta {
....@@ -145,8 +157,9 @@
145157 u32 sequence;
146158 struct v4l2_timecode timecode;
147159 u64 timestamp;
148
- u32 start;
149
- u32 end;
160
+ unsigned int start;
161
+ unsigned int end;
162
+ bool last;
150163 };
151164
152165 /* Per-queue, driver-specific private data */
....@@ -186,15 +199,23 @@
186199 int (*prepare_run)(struct coda_ctx *ctx);
187200 void (*finish_run)(struct coda_ctx *ctx);
188201 void (*run_timeout)(struct coda_ctx *ctx);
202
+ void (*seq_init_work)(struct work_struct *work);
189203 void (*seq_end_work)(struct work_struct *work);
190204 void (*release)(struct coda_ctx *ctx);
205
+};
206
+
207
+struct coda_internal_frame {
208
+ struct coda_aux_buf buf;
209
+ struct coda_buffer_meta meta;
210
+ u32 type;
211
+ u32 error;
191212 };
192213
193214 struct coda_ctx {
194215 struct coda_dev *dev;
195216 struct mutex buffer_mutex;
196
- struct list_head list;
197217 struct work_struct pic_run_work;
218
+ struct work_struct seq_init_work;
198219 struct work_struct seq_end_work;
199220 struct completion completion;
200221 const struct coda_video_device *cvd;
....@@ -217,9 +238,14 @@
217238 struct v4l2_ctrl_handler ctrls;
218239 struct v4l2_ctrl *h264_profile_ctrl;
219240 struct v4l2_ctrl *h264_level_ctrl;
241
+ struct v4l2_ctrl *mpeg2_profile_ctrl;
242
+ struct v4l2_ctrl *mpeg2_level_ctrl;
243
+ struct v4l2_ctrl *mpeg4_profile_ctrl;
244
+ struct v4l2_ctrl *mpeg4_level_ctrl;
220245 struct v4l2_fh fh;
221246 int gopcounter;
222247 int runcounter;
248
+ int jpeg_ecs_offset;
223249 char vpu_header[3][64];
224250 int vpu_header_size[3];
225251 struct kfifo bitstream_fifo;
....@@ -229,10 +255,7 @@
229255 struct coda_aux_buf parabuf;
230256 struct coda_aux_buf psbuf;
231257 struct coda_aux_buf slicebuf;
232
- struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
233
- u32 frame_types[CODA_MAX_FRAMEBUFFERS];
234
- struct coda_buffer_meta frame_metas[CODA_MAX_FRAMEBUFFERS];
235
- u32 frame_errors[CODA_MAX_FRAMEBUFFERS];
258
+ struct coda_internal_frame internal_frames[CODA_MAX_FRAMEBUFFERS];
236259 struct list_head buffer_meta_list;
237260 spinlock_t buffer_meta_lock;
238261 int num_metas;
....@@ -245,14 +268,28 @@
245268 u32 bit_stream_param;
246269 u32 frm_dis_flg;
247270 u32 frame_mem_ctrl;
271
+ u32 para_change;
248272 int display_idx;
249273 struct dentry *debugfs_entry;
250274 bool use_bit;
251275 bool use_vdoa;
252276 struct vdoa_ctx *vdoa;
277
+ /*
278
+ * wakeup mutex used to serialize encoder stop command and finish_run,
279
+ * ensures that finish_run always either flags the last returned buffer
280
+ * or wakes up the capture queue to signal EOS afterwards.
281
+ */
282
+ struct mutex wakeup_mutex;
253283 };
254284
255285 extern int coda_debug;
286
+
287
+#define coda_dbg(level, ctx, fmt, arg...) \
288
+ do { \
289
+ if (coda_debug >= (level)) \
290
+ v4l2_dbg((level), coda_debug, &(ctx)->dev->v4l2_dev, \
291
+ "%u: " fmt, (ctx)->idx, ##arg); \
292
+ } while (0)
256293
257294 void coda_write(struct coda_dev *dev, u32 data, u32 reg);
258295 unsigned int coda_read(struct coda_dev *dev, u32 reg);
....@@ -296,6 +333,19 @@
296333 return kfifo_len(&ctx->bitstream_fifo);
297334 }
298335
336
+/*
337
+ * The bitstream prefetcher needs to read at least 2 256 byte periods past
338
+ * the desired bitstream position for all data to reach the decoder.
339
+ */
340
+static inline bool coda_bitstream_can_fetch_past(struct coda_ctx *ctx,
341
+ unsigned int pos)
342
+{
343
+ return (int)(ctx->bitstream_fifo.kfifo.in - ALIGN(pos, 256)) > 512;
344
+}
345
+
346
+bool coda_bitstream_can_fetch_past(struct coda_ctx *ctx, unsigned int pos);
347
+int coda_bitstream_flush(struct coda_ctx *ctx);
348
+
299349 void coda_bit_stream_end_flag(struct coda_ctx *ctx);
300350
301351 void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
....@@ -309,13 +359,27 @@
309359 int coda_h264_sps_fixup(struct coda_ctx *ctx, int width, int height, char *buf,
310360 int *size, int max_size);
311361
362
+int coda_mpeg2_profile(int profile_idc);
363
+int coda_mpeg2_level(int level_idc);
364
+u32 coda_mpeg2_parse_headers(struct coda_ctx *ctx, u8 *buf, u32 size);
365
+int coda_mpeg4_profile(int profile_idc);
366
+int coda_mpeg4_level(int level_idc);
367
+u32 coda_mpeg4_parse_headers(struct coda_ctx *ctx, u8 *buf, u32 size);
368
+
369
+void coda_update_profile_level_ctrls(struct coda_ctx *ctx, u8 profile_idc,
370
+ u8 level_idc);
371
+
312372 bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb);
373
+int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb);
313374 int coda_jpeg_write_tables(struct coda_ctx *ctx);
314375 void coda_set_jpeg_compression_quality(struct coda_ctx *ctx, int quality);
315376
316377 extern const struct coda_context_ops coda_bit_encode_ops;
317378 extern const struct coda_context_ops coda_bit_decode_ops;
379
+extern const struct coda_context_ops coda9_jpeg_encode_ops;
380
+extern const struct coda_context_ops coda9_jpeg_decode_ops;
318381
319382 irqreturn_t coda_irq_handler(int irq, void *data);
383
+irqreturn_t coda9_jpeg_irq_handler(int irq, void *data);
320384
321385 #endif /* __CODA_H__ */