s5p_mfc_common.h 19 KB

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