1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ 2 /* 3 * Wave5 series multi-standard codec IP - basic types 4 * 5 * Copyright (C) 2021-2023 CHIPS&MEDIA INC 6 */ 7 #ifndef __VPU_DRV_H__ 8 #define __VPU_DRV_H__ 9 10 #include <media/v4l2-ctrls.h> 11 #include <media/v4l2-ioctl.h> 12 #include <media/v4l2-event.h> 13 #include <media/v4l2-fh.h> 14 #include <media/videobuf2-v4l2.h> 15 #include <media/videobuf2-dma-contig.h> 16 #include <media/videobuf2-vmalloc.h> 17 #include "wave5-vpuconfig.h" 18 #include "wave5-vpuapi.h" 19 20 #define VPU_BUF_SYNC_TO_DEVICE 0 21 #define VPU_BUF_SYNC_FROM_DEVICE 1 22 23 struct vpu_src_buffer { 24 struct v4l2_m2m_buffer v4l2_m2m_buf; 25 struct list_head list; 26 bool consumed; 27 }; 28 29 struct vpu_dst_buffer { 30 struct v4l2_m2m_buffer v4l2_m2m_buf; 31 bool display; 32 }; 33 34 enum vpu_fmt_type { 35 VPU_FMT_TYPE_CODEC = 0, 36 VPU_FMT_TYPE_RAW = 1 37 }; 38 39 struct vpu_format { 40 unsigned int v4l2_pix_fmt; 41 const struct v4l2_frmsize_stepwise *v4l2_frmsize; 42 }; 43 44 static inline struct vpu_instance *wave5_to_vpu_inst(struct v4l2_fh *vfh) 45 { 46 return container_of(vfh, struct vpu_instance, v4l2_fh); 47 } 48 49 static inline struct vpu_instance *wave5_ctrl_to_vpu_inst(struct v4l2_ctrl *vctrl) 50 { 51 return container_of(vctrl->handler, struct vpu_instance, v4l2_ctrl_hdl); 52 } 53 54 static inline struct vpu_src_buffer *wave5_to_vpu_src_buf(struct vb2_v4l2_buffer *vbuf) 55 { 56 return container_of(vbuf, struct vpu_src_buffer, v4l2_m2m_buf.vb); 57 } 58 59 static inline struct vpu_dst_buffer *wave5_to_vpu_dst_buf(struct vb2_v4l2_buffer *vbuf) 60 { 61 return container_of(vbuf, struct vpu_dst_buffer, v4l2_m2m_buf.vb); 62 } 63 64 int wave5_vpu_wait_interrupt(struct vpu_instance *inst, unsigned int timeout); 65 66 int wave5_vpu_dec_register_device(struct vpu_device *dev); 67 void wave5_vpu_dec_unregister_device(struct vpu_device *dev); 68 int wave5_vpu_enc_register_device(struct vpu_device *dev); 69 void wave5_vpu_enc_unregister_device(struct vpu_device *dev); 70 static inline bool wave5_vpu_both_queues_are_streaming(struct vpu_instance *inst) 71 { 72 struct vb2_queue *vq_cap = 73 v4l2_m2m_get_vq(inst->v4l2_fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 74 struct vb2_queue *vq_out = 75 v4l2_m2m_get_vq(inst->v4l2_fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); 76 77 return vb2_is_streaming(vq_cap) && vb2_is_streaming(vq_out); 78 } 79 80 #endif 81