s5p_mfc_common.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * Samsung S5P Multi Format Codec v 5.0
  3. *
  4. * This file contains definitions of enums and structs used by the codec
  5. * driver.
  6. *
  7. * Copyright (C) 2011 Samsung Electronics Co., Ltd.
  8. * Kamil Debski, <[email protected]>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version
  14. */
  15. #ifndef S5P_MFC_COMMON_H_
  16. #define S5P_MFC_COMMON_H_
  17. #include <linux/platform_device.h>
  18. #include <linux/videodev2.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <media/v4l2-device.h>
  21. #include <media/v4l2-ioctl.h>
  22. #include <media/videobuf2-v4l2.h>
  23. #include "regs-mfc.h"
  24. #include "regs-mfc-v8.h"
  25. #define S5P_MFC_NAME "s5p-mfc"
  26. /* Definitions related to MFC memory */
  27. /* Offset base used to differentiate between CAPTURE and OUTPUT
  28. * while mmaping */
  29. #define DST_QUEUE_OFF_BASE (1 << 30)
  30. #define MFC_BANK1_ALLOC_CTX 0
  31. #define MFC_BANK2_ALLOC_CTX 1
  32. #define MFC_BANK1_ALIGN_ORDER 13
  33. #define MFC_BANK2_ALIGN_ORDER 13
  34. #define MFC_BASE_ALIGN_ORDER 17
  35. #define MFC_FW_MAX_VERSIONS 2
  36. #include <media/videobuf2-dma-contig.h>
  37. static inline dma_addr_t s5p_mfc_mem_cookie(void *a, void *b)
  38. {
  39. /* Same functionality as the vb2_dma_contig_plane_paddr */
  40. dma_addr_t *paddr = vb2_dma_contig_memops.cookie(b);
  41. return *paddr;
  42. }
  43. /* MFC definitions */
  44. #define MFC_MAX_EXTRA_DPB 5
  45. #define MFC_MAX_BUFFERS 32
  46. #define MFC_NUM_CONTEXTS 4
  47. /* Interrupt timeout */
  48. #define MFC_INT_TIMEOUT 2000
  49. /* Busy wait timeout */
  50. #define MFC_BW_TIMEOUT 500
  51. /* Watchdog interval */
  52. #define MFC_WATCHDOG_INTERVAL 1000
  53. /* After how many executions watchdog should assume lock up */
  54. #define MFC_WATCHDOG_CNT 10
  55. #define MFC_NO_INSTANCE_SET -1
  56. #define MFC_ENC_CAP_PLANE_COUNT 1
  57. #define MFC_ENC_OUT_PLANE_COUNT 2
  58. #define STUFF_BYTE 4
  59. #define MFC_MAX_CTRLS 77
  60. #define S5P_MFC_CODEC_NONE -1
  61. #define S5P_MFC_CODEC_H264_DEC 0
  62. #define S5P_MFC_CODEC_H264_MVC_DEC 1
  63. #define S5P_MFC_CODEC_VC1_DEC 2
  64. #define S5P_MFC_CODEC_MPEG4_DEC 3
  65. #define S5P_MFC_CODEC_MPEG2_DEC 4
  66. #define S5P_MFC_CODEC_H263_DEC 5
  67. #define S5P_MFC_CODEC_VC1RCV_DEC 6
  68. #define S5P_MFC_CODEC_VP8_DEC 7
  69. #define S5P_MFC_CODEC_H264_ENC 20
  70. #define S5P_MFC_CODEC_H264_MVC_ENC 21
  71. #define S5P_MFC_CODEC_MPEG4_ENC 22
  72. #define S5P_MFC_CODEC_H263_ENC 23
  73. #define S5P_MFC_CODEC_VP8_ENC 24
  74. #define S5P_MFC_R2H_CMD_EMPTY 0
  75. #define S5P_MFC_R2H_CMD_SYS_INIT_RET 1
  76. #define S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET 2
  77. #define S5P_MFC_R2H_CMD_SEQ_DONE_RET 3
  78. #define S5P_MFC_R2H_CMD_INIT_BUFFERS_RET 4
  79. #define S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET 6
  80. #define S5P_MFC_R2H_CMD_SLEEP_RET 7
  81. #define S5P_MFC_R2H_CMD_WAKEUP_RET 8
  82. #define S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET 9
  83. #define S5P_MFC_R2H_CMD_DPB_FLUSH_RET 10
  84. #define S5P_MFC_R2H_CMD_NAL_ABORT_RET 11
  85. #define S5P_MFC_R2H_CMD_FW_STATUS_RET 12
  86. #define S5P_MFC_R2H_CMD_FRAME_DONE_RET 13
  87. #define S5P_MFC_R2H_CMD_FIELD_DONE_RET 14
  88. #define S5P_MFC_R2H_CMD_SLICE_DONE_RET 15
  89. #define S5P_MFC_R2H_CMD_ENC_BUFFER_FUL_RET 16
  90. #define S5P_MFC_R2H_CMD_ERR_RET 32
  91. #define mfc_read(dev, offset) readl(dev->regs_base + (offset))
  92. #define mfc_write(dev, data, offset) writel((data), dev->regs_base + \
  93. (offset))
  94. /**
  95. * enum s5p_mfc_fmt_type - type of the pixelformat
  96. */
  97. enum s5p_mfc_fmt_type {
  98. MFC_FMT_DEC,
  99. MFC_FMT_ENC,
  100. MFC_FMT_RAW,
  101. };
  102. /**
  103. * enum s5p_mfc_inst_type - The type of an MFC instance.
  104. */
  105. enum s5p_mfc_inst_type {
  106. MFCINST_INVALID,
  107. MFCINST_DECODER,
  108. MFCINST_ENCODER,
  109. };
  110. /**
  111. * enum s5p_mfc_inst_state - The state of an MFC instance.
  112. */
  113. enum s5p_mfc_inst_state {
  114. MFCINST_FREE = 0,
  115. MFCINST_INIT = 100,
  116. MFCINST_GOT_INST,
  117. MFCINST_HEAD_PARSED,
  118. MFCINST_HEAD_PRODUCED,
  119. MFCINST_BUFS_SET,
  120. MFCINST_RUNNING,
  121. MFCINST_FINISHING,
  122. MFCINST_FINISHED,
  123. MFCINST_RETURN_INST,
  124. MFCINST_ERROR,
  125. MFCINST_ABORT,
  126. MFCINST_FLUSH,
  127. MFCINST_RES_CHANGE_INIT,
  128. MFCINST_RES_CHANGE_FLUSH,
  129. MFCINST_RES_CHANGE_END,
  130. };
  131. /**
  132. * enum s5p_mfc_queue_state - The state of buffer queue.
  133. */
  134. enum s5p_mfc_queue_state {
  135. QUEUE_FREE,
  136. QUEUE_BUFS_REQUESTED,
  137. QUEUE_BUFS_QUERIED,
  138. QUEUE_BUFS_MMAPED,
  139. };
  140. /**
  141. * enum s5p_mfc_decode_arg - type of frame decoding
  142. */
  143. enum s5p_mfc_decode_arg {
  144. MFC_DEC_FRAME,
  145. MFC_DEC_LAST_FRAME,
  146. MFC_DEC_RES_CHANGE,
  147. };
  148. enum s5p_mfc_fw_ver {
  149. MFC_FW_V1,
  150. MFC_FW_V2,
  151. };
  152. #define MFC_BUF_FLAG_USED (1 << 0)
  153. #define MFC_BUF_FLAG_EOS (1 << 1)
  154. struct s5p_mfc_ctx;
  155. /**
  156. * struct s5p_mfc_buf - MFC buffer
  157. */
  158. struct s5p_mfc_buf {
  159. struct vb2_v4l2_buffer *b;
  160. struct list_head list;
  161. union {
  162. struct {
  163. size_t luma;
  164. size_t chroma;
  165. } raw;
  166. size_t stream;
  167. } cookie;
  168. int flags;
  169. };
  170. /**
  171. * struct s5p_mfc_pm - power management data structure
  172. */
  173. struct s5p_mfc_pm {
  174. struct clk *clock;
  175. struct clk *clock_gate;
  176. atomic_t power;
  177. struct device *device;
  178. };
  179. struct s5p_mfc_buf_size_v5 {
  180. unsigned int h264_ctx;
  181. unsigned int non_h264_ctx;
  182. unsigned int dsc;
  183. unsigned int shm;
  184. };
  185. struct s5p_mfc_buf_size_v6 {
  186. unsigned int dev_ctx;
  187. unsigned int h264_dec_ctx;
  188. unsigned int other_dec_ctx;
  189. unsigned int h264_enc_ctx;
  190. unsigned int other_enc_ctx;
  191. };
  192. struct s5p_mfc_buf_size {
  193. unsigned int fw;
  194. unsigned int cpb;
  195. void *priv;
  196. };
  197. struct s5p_mfc_buf_align {
  198. unsigned int base;
  199. };
  200. struct s5p_mfc_variant {
  201. unsigned int version;
  202. unsigned int port_num;
  203. u32 version_bit;
  204. struct s5p_mfc_buf_size *buf_size;
  205. struct s5p_mfc_buf_align *buf_align;
  206. char *fw_name[MFC_FW_MAX_VERSIONS];
  207. };
  208. /**
  209. * struct s5p_mfc_priv_buf - represents internal used buffer
  210. * @ofs: offset of each buffer, will be used for MFC
  211. * @virt: kernel virtual address, only valid when the
  212. * buffer accessed by driver
  213. * @dma: DMA address, only valid when kernel DMA API used
  214. * @size: size of the buffer
  215. */
  216. struct s5p_mfc_priv_buf {
  217. unsigned long ofs;
  218. void *virt;
  219. dma_addr_t dma;
  220. size_t size;
  221. };
  222. /**
  223. * struct s5p_mfc_dev - The struct containing driver internal parameters.
  224. *
  225. * @v4l2_dev: v4l2_device
  226. * @vfd_dec: video device for decoding
  227. * @vfd_enc: video device for encoding
  228. * @plat_dev: platform device
  229. * @mem_dev_l: child device of the left memory bank (0)
  230. * @mem_dev_r: child device of the right memory bank (1)
  231. * @regs_base: base address of the MFC hw registers
  232. * @irq: irq resource
  233. * @dec_ctrl_handler: control framework handler for decoding
  234. * @enc_ctrl_handler: control framework handler for encoding
  235. * @pm: power management control
  236. * @variant: MFC hardware variant information
  237. * @num_inst: couter of active MFC instances
  238. * @irqlock: lock for operations on videobuf2 queues
  239. * @condlock: lock for changing/checking if a context is ready to be
  240. * processed
  241. * @mfc_mutex: lock for video_device
  242. * @int_cond: variable used by the waitqueue
  243. * @int_type: type of last interrupt
  244. * @int_err: error number for last interrupt
  245. * @queue: waitqueue for waiting for completion of device commands
  246. * @fw_size: size of firmware
  247. * @fw_virt_addr: virtual firmware address
  248. * @bank1: address of the beginning of bank 1 memory
  249. * @bank2: address of the beginning of bank 2 memory
  250. * @hw_lock: used for hardware locking
  251. * @ctx: array of driver contexts
  252. * @curr_ctx: number of the currently running context
  253. * @ctx_work_bits: used to mark which contexts are waiting for hardware
  254. * @watchdog_cnt: counter for the watchdog
  255. * @watchdog_workqueue: workqueue for the watchdog
  256. * @watchdog_work: worker for the watchdog
  257. * @enter_suspend: flag set when entering suspend
  258. * @ctx_buf: common context memory (MFCv6)
  259. * @warn_start: hardware error code from which warnings start
  260. * @mfc_ops: ops structure holding HW operation function pointers
  261. * @mfc_cmds: cmd structure holding HW commands function pointers
  262. * @mfc_regs: structure holding MFC registers
  263. * @fw_ver: loaded firmware sub-version
  264. * risc_on: flag indicates RISC is on or off
  265. *
  266. */
  267. struct s5p_mfc_dev {
  268. struct v4l2_device v4l2_dev;
  269. struct video_device *vfd_dec;
  270. struct video_device *vfd_enc;
  271. struct platform_device *plat_dev;
  272. struct device *mem_dev_l;
  273. struct device *mem_dev_r;
  274. void __iomem *regs_base;
  275. int irq;
  276. struct v4l2_ctrl_handler dec_ctrl_handler;
  277. struct v4l2_ctrl_handler enc_ctrl_handler;
  278. struct s5p_mfc_pm pm;
  279. struct s5p_mfc_variant *variant;
  280. int num_inst;
  281. spinlock_t irqlock; /* lock when operating on context */
  282. spinlock_t condlock; /* lock when changing/checking if a context is
  283. ready to be processed */
  284. struct mutex mfc_mutex; /* video_device lock */
  285. int int_cond;
  286. int int_type;
  287. unsigned int int_err;
  288. wait_queue_head_t queue;
  289. size_t fw_size;
  290. void *fw_virt_addr;
  291. dma_addr_t bank1;
  292. dma_addr_t bank2;
  293. unsigned long hw_lock;
  294. struct s5p_mfc_ctx *ctx[MFC_NUM_CONTEXTS];
  295. int curr_ctx;
  296. unsigned long ctx_work_bits;
  297. atomic_t watchdog_cnt;
  298. struct timer_list watchdog_timer;
  299. struct workqueue_struct *watchdog_workqueue;
  300. struct work_struct watchdog_work;
  301. unsigned long enter_suspend;
  302. struct s5p_mfc_priv_buf ctx_buf;
  303. int warn_start;
  304. struct s5p_mfc_hw_ops *mfc_ops;
  305. struct s5p_mfc_hw_cmds *mfc_cmds;
  306. const struct s5p_mfc_regs *mfc_regs;
  307. enum s5p_mfc_fw_ver fw_ver;
  308. bool risc_on; /* indicates if RISC is on or off */
  309. };
  310. /**
  311. * struct s5p_mfc_h264_enc_params - encoding parameters for h264
  312. */
  313. struct s5p_mfc_h264_enc_params {
  314. enum v4l2_mpeg_video_h264_profile profile;
  315. enum v4l2_mpeg_video_h264_loop_filter_mode loop_filter_mode;
  316. s8 loop_filter_alpha;
  317. s8 loop_filter_beta;
  318. enum v4l2_mpeg_video_h264_entropy_mode entropy_mode;
  319. u8 max_ref_pic;
  320. u8 num_ref_pic_4p;
  321. int _8x8_transform;
  322. int rc_mb_dark;
  323. int rc_mb_smooth;
  324. int rc_mb_static;
  325. int rc_mb_activity;
  326. int vui_sar;
  327. u8 vui_sar_idc;
  328. u16 vui_ext_sar_width;
  329. u16 vui_ext_sar_height;
  330. int open_gop;
  331. u16 open_gop_size;
  332. u8 rc_frame_qp;
  333. u8 rc_min_qp;
  334. u8 rc_max_qp;
  335. u8 rc_p_frame_qp;
  336. u8 rc_b_frame_qp;
  337. enum v4l2_mpeg_video_h264_level level_v4l2;
  338. int level;
  339. u16 cpb_size;
  340. int interlace;
  341. u8 hier_qp;
  342. u8 hier_qp_type;
  343. u8 hier_qp_layer;
  344. u8 hier_qp_layer_qp[7];
  345. u8 sei_frame_packing;
  346. u8 sei_fp_curr_frame_0;
  347. u8 sei_fp_arrangement_type;
  348. u8 fmo;
  349. u8 fmo_map_type;
  350. u8 fmo_slice_grp;
  351. u8 fmo_chg_dir;
  352. u32 fmo_chg_rate;
  353. u32 fmo_run_len[4];
  354. u8 aso;
  355. u32 aso_slice_order[8];
  356. };
  357. /**
  358. * struct s5p_mfc_mpeg4_enc_params - encoding parameters for h263 and mpeg4
  359. */
  360. struct s5p_mfc_mpeg4_enc_params {
  361. /* MPEG4 Only */
  362. enum v4l2_mpeg_video_mpeg4_profile profile;
  363. int quarter_pixel;
  364. /* Common for MPEG4, H263 */
  365. u16 vop_time_res;
  366. u16 vop_frm_delta;
  367. u8 rc_frame_qp;
  368. u8 rc_min_qp;
  369. u8 rc_max_qp;
  370. u8 rc_p_frame_qp;
  371. u8 rc_b_frame_qp;
  372. enum v4l2_mpeg_video_mpeg4_level level_v4l2;
  373. int level;
  374. };
  375. /**
  376. * struct s5p_mfc_vp8_enc_params - encoding parameters for vp8
  377. */
  378. struct s5p_mfc_vp8_enc_params {
  379. u8 imd_4x4;
  380. enum v4l2_vp8_num_partitions num_partitions;
  381. enum v4l2_vp8_num_ref_frames num_ref;
  382. u8 filter_level;
  383. u8 filter_sharpness;
  384. u32 golden_frame_ref_period;
  385. enum v4l2_vp8_golden_frame_sel golden_frame_sel;
  386. u8 hier_layer;
  387. u8 hier_layer_qp[3];
  388. u8 rc_min_qp;
  389. u8 rc_max_qp;
  390. u8 rc_frame_qp;
  391. u8 rc_p_frame_qp;
  392. u8 profile;
  393. };
  394. /**
  395. * struct s5p_mfc_enc_params - general encoding parameters
  396. */
  397. struct s5p_mfc_enc_params {
  398. u16 width;
  399. u16 height;
  400. u32 mv_h_range;
  401. u32 mv_v_range;
  402. u16 gop_size;
  403. enum v4l2_mpeg_video_multi_slice_mode slice_mode;
  404. u16 slice_mb;
  405. u32 slice_bit;
  406. u16 intra_refresh_mb;
  407. int pad;
  408. u8 pad_luma;
  409. u8 pad_cb;
  410. u8 pad_cr;
  411. int rc_frame;
  412. int rc_mb;
  413. u32 rc_bitrate;
  414. u16 rc_reaction_coeff;
  415. u16 vbv_size;
  416. u32 vbv_delay;
  417. enum v4l2_mpeg_video_header_mode seq_hdr_mode;
  418. enum v4l2_mpeg_mfc51_video_frame_skip_mode frame_skip_mode;
  419. int fixed_target_bit;
  420. u8 num_b_frame;
  421. u32 rc_framerate_num;
  422. u32 rc_framerate_denom;
  423. struct {
  424. struct s5p_mfc_h264_enc_params h264;
  425. struct s5p_mfc_mpeg4_enc_params mpeg4;
  426. struct s5p_mfc_vp8_enc_params vp8;
  427. } codec;
  428. };
  429. /**
  430. * struct s5p_mfc_codec_ops - codec ops, used by encoding
  431. */
  432. struct s5p_mfc_codec_ops {
  433. /* initialization routines */
  434. int (*pre_seq_start) (struct s5p_mfc_ctx *ctx);
  435. int (*post_seq_start) (struct s5p_mfc_ctx *ctx);
  436. /* execution routines */
  437. int (*pre_frame_start) (struct s5p_mfc_ctx *ctx);
  438. int (*post_frame_start) (struct s5p_mfc_ctx *ctx);
  439. };
  440. #define call_cop(c, op, args...) \
  441. (((c)->c_ops->op) ? \
  442. ((c)->c_ops->op(args)) : 0)
  443. /**
  444. * struct s5p_mfc_ctx - This struct contains the instance context
  445. *
  446. * @dev: pointer to the s5p_mfc_dev of the device
  447. * @fh: struct v4l2_fh
  448. * @num: number of the context that this structure describes
  449. * @int_cond: variable used by the waitqueue
  450. * @int_type: type of the last interrupt
  451. * @int_err: error number received from MFC hw in the interrupt
  452. * @queue: waitqueue that can be used to wait for this context to
  453. * finish
  454. * @src_fmt: source pixelformat information
  455. * @dst_fmt: destination pixelformat information
  456. * @vq_src: vb2 queue for source buffers
  457. * @vq_dst: vb2 queue for destination buffers
  458. * @src_queue: driver internal queue for source buffers
  459. * @dst_queue: driver internal queue for destination buffers
  460. * @src_queue_cnt: number of buffers queued on the source internal queue
  461. * @dst_queue_cnt: number of buffers queued on the dest internal queue
  462. * @type: type of the instance - decoder or encoder
  463. * @state: state of the context
  464. * @inst_no: number of hw instance associated with the context
  465. * @img_width: width of the image that is decoded or encoded
  466. * @img_height: height of the image that is decoded or encoded
  467. * @buf_width: width of the buffer for processed image
  468. * @buf_height: height of the buffer for processed image
  469. * @luma_size: size of a luma plane
  470. * @chroma_size: size of a chroma plane
  471. * @mv_size: size of a motion vectors buffer
  472. * @consumed_stream: number of bytes that have been used so far from the
  473. * decoding buffer
  474. * @dpb_flush_flag: flag used to indicate that a DPB buffers are being
  475. * flushed
  476. * @head_processed: flag mentioning whether the header data is processed
  477. * completely or not
  478. * @bank1: handle to memory allocated for temporary buffers from
  479. * memory bank 1
  480. * @bank2: handle to memory allocated for temporary buffers from
  481. * memory bank 2
  482. * @capture_state: state of the capture buffers queue
  483. * @output_state: state of the output buffers queue
  484. * @src_bufs: information on allocated source buffers
  485. * @dst_bufs: information on allocated destination buffers
  486. * @sequence: counter for the sequence number for v4l2
  487. * @dec_dst_flag: flags for buffers queued in the hardware
  488. * @dec_src_buf_size: size of the buffer for source buffers in decoding
  489. * @codec_mode: number of codec mode used by MFC hw
  490. * @slice_interface: slice interface flag
  491. * @loop_filter_mpeg4: loop filter for MPEG4 flag
  492. * @display_delay: value of the display delay for H264
  493. * @display_delay_enable: display delay for H264 enable flag
  494. * @after_packed_pb: flag used to track buffer when stream is in
  495. * Packed PB format
  496. * @sei_fp_parse: enable/disable parsing of frame packing SEI information
  497. * @dpb_count: count of the DPB buffers required by MFC hw
  498. * @total_dpb_count: count of DPB buffers with additional buffers
  499. * requested by the application
  500. * @ctx: context buffer information
  501. * @dsc: descriptor buffer information
  502. * @shm: shared memory buffer information
  503. * @mv_count: number of MV buffers allocated for decoding
  504. * @enc_params: encoding parameters for MFC
  505. * @enc_dst_buf_size: size of the buffers for encoder output
  506. * @luma_dpb_size: dpb buffer size for luma
  507. * @chroma_dpb_size: dpb buffer size for chroma
  508. * @me_buffer_size: size of the motion estimation buffer
  509. * @tmv_buffer_size: size of temporal predictor motion vector buffer
  510. * @frame_type: used to force the type of the next encoded frame
  511. * @ref_queue: list of the reference buffers for encoding
  512. * @ref_queue_cnt: number of the buffers in the reference list
  513. * @c_ops: ops for encoding
  514. * @ctrls: array of controls, used when adding controls to the
  515. * v4l2 control framework
  516. * @ctrl_handler: handler for v4l2 framework
  517. */
  518. struct s5p_mfc_ctx {
  519. struct s5p_mfc_dev *dev;
  520. struct v4l2_fh fh;
  521. int num;
  522. int int_cond;
  523. int int_type;
  524. unsigned int int_err;
  525. wait_queue_head_t queue;
  526. struct s5p_mfc_fmt *src_fmt;
  527. struct s5p_mfc_fmt *dst_fmt;
  528. struct vb2_queue vq_src;
  529. struct vb2_queue vq_dst;
  530. struct list_head src_queue;
  531. struct list_head dst_queue;
  532. unsigned int src_queue_cnt;
  533. unsigned int dst_queue_cnt;
  534. enum s5p_mfc_inst_type type;
  535. enum s5p_mfc_inst_state state;
  536. int inst_no;
  537. /* Image parameters */
  538. int img_width;
  539. int img_height;
  540. int buf_width;
  541. int buf_height;
  542. int luma_size;
  543. int chroma_size;
  544. int mv_size;
  545. unsigned long consumed_stream;
  546. unsigned int dpb_flush_flag;
  547. unsigned int head_processed;
  548. struct s5p_mfc_priv_buf bank1;
  549. struct s5p_mfc_priv_buf bank2;
  550. enum s5p_mfc_queue_state capture_state;
  551. enum s5p_mfc_queue_state output_state;
  552. struct s5p_mfc_buf src_bufs[MFC_MAX_BUFFERS];
  553. int src_bufs_cnt;
  554. struct s5p_mfc_buf dst_bufs[MFC_MAX_BUFFERS];
  555. int dst_bufs_cnt;
  556. unsigned int sequence;
  557. unsigned long dec_dst_flag;
  558. size_t dec_src_buf_size;
  559. /* Control values */
  560. int codec_mode;
  561. int slice_interface;
  562. int loop_filter_mpeg4;
  563. int display_delay;
  564. int display_delay_enable;
  565. int after_packed_pb;
  566. int sei_fp_parse;
  567. int pb_count;
  568. int total_dpb_count;
  569. int mv_count;
  570. /* Buffers */
  571. struct s5p_mfc_priv_buf ctx;
  572. struct s5p_mfc_priv_buf dsc;
  573. struct s5p_mfc_priv_buf shm;
  574. struct s5p_mfc_enc_params enc_params;
  575. size_t enc_dst_buf_size;
  576. size_t luma_dpb_size;
  577. size_t chroma_dpb_size;
  578. size_t me_buffer_size;
  579. size_t tmv_buffer_size;
  580. enum v4l2_mpeg_mfc51_video_force_frame_type force_frame_type;
  581. struct list_head ref_queue;
  582. unsigned int ref_queue_cnt;
  583. enum v4l2_mpeg_video_multi_slice_mode slice_mode;
  584. union {
  585. unsigned int mb;
  586. unsigned int bits;
  587. } slice_size;
  588. const struct s5p_mfc_codec_ops *c_ops;
  589. struct v4l2_ctrl *ctrls[MFC_MAX_CTRLS];
  590. struct v4l2_ctrl_handler ctrl_handler;
  591. unsigned int frame_tag;
  592. size_t scratch_buf_size;
  593. };
  594. /*
  595. * struct s5p_mfc_fmt - structure used to store information about pixelformats
  596. * used by the MFC
  597. */
  598. struct s5p_mfc_fmt {
  599. char *name;
  600. u32 fourcc;
  601. u32 codec_mode;
  602. enum s5p_mfc_fmt_type type;
  603. u32 num_planes;
  604. u32 versions;
  605. };
  606. /**
  607. * struct mfc_control - structure used to store information about MFC controls
  608. * it is used to initialize the control framework.
  609. */
  610. struct mfc_control {
  611. __u32 id;
  612. enum v4l2_ctrl_type type;
  613. __u8 name[32]; /* Whatever */
  614. __s32 minimum; /* Note signedness */
  615. __s32 maximum;
  616. __s32 step;
  617. __u32 menu_skip_mask;
  618. __s32 default_value;
  619. __u32 flags;
  620. __u32 reserved[2];
  621. __u8 is_volatile;
  622. };
  623. /* Macro for making hardware specific calls */
  624. #define s5p_mfc_hw_call(f, op, args...) \
  625. ((f && f->op) ? f->op(args) : (typeof(f->op(args)))(-ENODEV))
  626. #define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh)
  627. #define ctrl_to_ctx(__ctrl) \
  628. container_of((__ctrl)->handler, struct s5p_mfc_ctx, ctrl_handler)
  629. void clear_work_bit(struct s5p_mfc_ctx *ctx);
  630. void set_work_bit(struct s5p_mfc_ctx *ctx);
  631. void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
  632. void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
  633. int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev);
  634. void s5p_mfc_cleanup_queue(struct list_head *lh, struct vb2_queue *vq);
  635. #define HAS_PORTNUM(dev) (dev ? (dev->variant ? \
  636. (dev->variant->port_num ? 1 : 0) : 0) : 0)
  637. #define IS_TWOPORT(dev) (dev->variant->port_num == 2 ? 1 : 0)
  638. #define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
  639. #define IS_MFCV7_PLUS(dev) (dev->variant->version >= 0x70 ? 1 : 0)
  640. #define IS_MFCV8(dev) (dev->variant->version >= 0x80 ? 1 : 0)
  641. #define MFC_V5_BIT BIT(0)
  642. #define MFC_V6_BIT BIT(1)
  643. #define MFC_V7_BIT BIT(2)
  644. #define MFC_V8_BIT BIT(3)
  645. #endif /* S5P_MFC_COMMON_H_ */