s5p_mfc_common.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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-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_MAX_CLOCKS 4
  92. #define mfc_read(dev, offset) readl(dev->regs_base + (offset))
  93. #define mfc_write(dev, data, offset) writel((data), dev->regs_base + \
  94. (offset))
  95. /**
  96. * enum s5p_mfc_fmt_type - type of the pixelformat
  97. */
  98. enum s5p_mfc_fmt_type {
  99. MFC_FMT_DEC,
  100. MFC_FMT_ENC,
  101. MFC_FMT_RAW,
  102. };
  103. /**
  104. * enum s5p_mfc_inst_type - The type of an MFC instance.
  105. */
  106. enum s5p_mfc_inst_type {
  107. MFCINST_INVALID,
  108. MFCINST_DECODER,
  109. MFCINST_ENCODER,
  110. };
  111. /**
  112. * enum s5p_mfc_inst_state - The state of an MFC instance.
  113. */
  114. enum s5p_mfc_inst_state {
  115. MFCINST_FREE = 0,
  116. MFCINST_INIT = 100,
  117. MFCINST_GOT_INST,
  118. MFCINST_HEAD_PARSED,
  119. MFCINST_HEAD_PRODUCED,
  120. MFCINST_BUFS_SET,
  121. MFCINST_RUNNING,
  122. MFCINST_FINISHING,
  123. MFCINST_FINISHED,
  124. MFCINST_RETURN_INST,
  125. MFCINST_ERROR,
  126. MFCINST_ABORT,
  127. MFCINST_FLUSH,
  128. MFCINST_RES_CHANGE_INIT,
  129. MFCINST_RES_CHANGE_FLUSH,
  130. MFCINST_RES_CHANGE_END,
  131. };
  132. /**
  133. * enum s5p_mfc_queue_state - The state of buffer queue.
  134. */
  135. enum s5p_mfc_queue_state {
  136. QUEUE_FREE,
  137. QUEUE_BUFS_REQUESTED,
  138. QUEUE_BUFS_QUERIED,
  139. QUEUE_BUFS_MMAPED,
  140. };
  141. /**
  142. * enum s5p_mfc_decode_arg - type of frame decoding
  143. */
  144. enum s5p_mfc_decode_arg {
  145. MFC_DEC_FRAME,
  146. MFC_DEC_LAST_FRAME,
  147. MFC_DEC_RES_CHANGE,
  148. };
  149. enum s5p_mfc_fw_ver {
  150. MFC_FW_V1,
  151. MFC_FW_V2,
  152. };
  153. #define MFC_BUF_FLAG_USED (1 << 0)
  154. #define MFC_BUF_FLAG_EOS (1 << 1)
  155. struct s5p_mfc_ctx;
  156. /**
  157. * struct s5p_mfc_buf - MFC buffer
  158. */
  159. struct s5p_mfc_buf {
  160. struct vb2_v4l2_buffer *b;
  161. struct list_head list;
  162. union {
  163. struct {
  164. size_t luma;
  165. size_t chroma;
  166. } raw;
  167. size_t stream;
  168. } cookie;
  169. int flags;
  170. };
  171. /**
  172. * struct s5p_mfc_pm - power management data structure
  173. */
  174. struct s5p_mfc_pm {
  175. struct clk *clock_gate;
  176. const char **clk_names;
  177. struct clk *clocks[MFC_MAX_CLOCKS];
  178. int num_clocks;
  179. bool use_clock_gating;
  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. u32 version_bit;
  207. struct s5p_mfc_buf_size *buf_size;
  208. struct s5p_mfc_buf_align *buf_align;
  209. char *fw_name[MFC_FW_MAX_VERSIONS];
  210. const char *clk_names[MFC_MAX_CLOCKS];
  211. int num_clocks;
  212. bool use_clock_gating;
  213. };
  214. /**
  215. * struct s5p_mfc_priv_buf - represents internal used buffer
  216. * @ofs: offset of each buffer, will be used for MFC
  217. * @virt: kernel virtual address, only valid when the
  218. * buffer accessed by driver
  219. * @dma: DMA address, only valid when kernel DMA API used
  220. * @size: size of the buffer
  221. */
  222. struct s5p_mfc_priv_buf {
  223. unsigned long ofs;
  224. void *virt;
  225. dma_addr_t dma;
  226. size_t size;
  227. };
  228. /**
  229. * struct s5p_mfc_dev - The struct containing driver internal parameters.
  230. *
  231. * @v4l2_dev: v4l2_device
  232. * @vfd_dec: video device for decoding
  233. * @vfd_enc: video device for encoding
  234. * @plat_dev: platform device
  235. * @mem_dev_l: child device of the left memory bank (0)
  236. * @mem_dev_r: child device of the right memory bank (1)
  237. * @regs_base: base address of the MFC hw registers
  238. * @irq: irq resource
  239. * @dec_ctrl_handler: control framework handler for decoding
  240. * @enc_ctrl_handler: control framework handler for encoding
  241. * @pm: power management control
  242. * @variant: MFC hardware variant information
  243. * @num_inst: couter of active MFC instances
  244. * @irqlock: lock for operations on videobuf2 queues
  245. * @condlock: lock for changing/checking if a context is ready to be
  246. * processed
  247. * @mfc_mutex: lock for video_device
  248. * @int_cond: variable used by the waitqueue
  249. * @int_type: type of last interrupt
  250. * @int_err: error number for last interrupt
  251. * @queue: waitqueue for waiting for completion of device commands
  252. * @fw_size: size of firmware
  253. * @fw_virt_addr: virtual firmware address
  254. * @bank1: address of the beginning of bank 1 memory
  255. * @bank2: address of the beginning of bank 2 memory
  256. * @hw_lock: used for hardware locking
  257. * @ctx: array of driver contexts
  258. * @curr_ctx: number of the currently running context
  259. * @ctx_work_bits: used to mark which contexts are waiting for hardware
  260. * @watchdog_cnt: counter for the watchdog
  261. * @watchdog_workqueue: workqueue for the watchdog
  262. * @watchdog_work: worker for the watchdog
  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. * @mfc_regs: structure holding MFC registers
  269. * @fw_ver: loaded firmware sub-version
  270. * risc_on: flag indicates RISC is on or off
  271. *
  272. */
  273. struct s5p_mfc_dev {
  274. struct v4l2_device v4l2_dev;
  275. struct video_device *vfd_dec;
  276. struct video_device *vfd_enc;
  277. struct platform_device *plat_dev;
  278. struct device *mem_dev_l;
  279. struct device *mem_dev_r;
  280. void __iomem *regs_base;
  281. int irq;
  282. struct v4l2_ctrl_handler dec_ctrl_handler;
  283. struct v4l2_ctrl_handler enc_ctrl_handler;
  284. struct s5p_mfc_pm pm;
  285. struct s5p_mfc_variant *variant;
  286. int num_inst;
  287. spinlock_t irqlock; /* lock when operating on context */
  288. spinlock_t condlock; /* lock when changing/checking if a context is
  289. ready to be processed */
  290. struct mutex mfc_mutex; /* video_device lock */
  291. int int_cond;
  292. int int_type;
  293. unsigned int int_err;
  294. wait_queue_head_t queue;
  295. size_t fw_size;
  296. void *fw_virt_addr;
  297. dma_addr_t bank1;
  298. dma_addr_t bank2;
  299. unsigned long hw_lock;
  300. struct s5p_mfc_ctx *ctx[MFC_NUM_CONTEXTS];
  301. int curr_ctx;
  302. unsigned long ctx_work_bits;
  303. atomic_t watchdog_cnt;
  304. struct timer_list watchdog_timer;
  305. struct workqueue_struct *watchdog_workqueue;
  306. struct work_struct watchdog_work;
  307. unsigned long enter_suspend;
  308. struct s5p_mfc_priv_buf ctx_buf;
  309. int warn_start;
  310. struct s5p_mfc_hw_ops *mfc_ops;
  311. struct s5p_mfc_hw_cmds *mfc_cmds;
  312. const struct s5p_mfc_regs *mfc_regs;
  313. enum s5p_mfc_fw_ver fw_ver;
  314. bool risc_on; /* indicates if RISC is on or off */
  315. };
  316. /**
  317. * struct s5p_mfc_h264_enc_params - encoding parameters for h264
  318. */
  319. struct s5p_mfc_h264_enc_params {
  320. enum v4l2_mpeg_video_h264_profile profile;
  321. enum v4l2_mpeg_video_h264_loop_filter_mode loop_filter_mode;
  322. s8 loop_filter_alpha;
  323. s8 loop_filter_beta;
  324. enum v4l2_mpeg_video_h264_entropy_mode entropy_mode;
  325. u8 max_ref_pic;
  326. u8 num_ref_pic_4p;
  327. int _8x8_transform;
  328. int rc_mb_dark;
  329. int rc_mb_smooth;
  330. int rc_mb_static;
  331. int rc_mb_activity;
  332. int vui_sar;
  333. u8 vui_sar_idc;
  334. u16 vui_ext_sar_width;
  335. u16 vui_ext_sar_height;
  336. int open_gop;
  337. u16 open_gop_size;
  338. u8 rc_frame_qp;
  339. u8 rc_min_qp;
  340. u8 rc_max_qp;
  341. u8 rc_p_frame_qp;
  342. u8 rc_b_frame_qp;
  343. enum v4l2_mpeg_video_h264_level level_v4l2;
  344. int level;
  345. u16 cpb_size;
  346. int interlace;
  347. u8 hier_qp;
  348. u8 hier_qp_type;
  349. u8 hier_qp_layer;
  350. u8 hier_qp_layer_qp[7];
  351. u8 sei_frame_packing;
  352. u8 sei_fp_curr_frame_0;
  353. u8 sei_fp_arrangement_type;
  354. u8 fmo;
  355. u8 fmo_map_type;
  356. u8 fmo_slice_grp;
  357. u8 fmo_chg_dir;
  358. u32 fmo_chg_rate;
  359. u32 fmo_run_len[4];
  360. u8 aso;
  361. u32 aso_slice_order[8];
  362. };
  363. /**
  364. * struct s5p_mfc_mpeg4_enc_params - encoding parameters for h263 and mpeg4
  365. */
  366. struct s5p_mfc_mpeg4_enc_params {
  367. /* MPEG4 Only */
  368. enum v4l2_mpeg_video_mpeg4_profile profile;
  369. int quarter_pixel;
  370. /* Common for MPEG4, H263 */
  371. u16 vop_time_res;
  372. u16 vop_frm_delta;
  373. u8 rc_frame_qp;
  374. u8 rc_min_qp;
  375. u8 rc_max_qp;
  376. u8 rc_p_frame_qp;
  377. u8 rc_b_frame_qp;
  378. enum v4l2_mpeg_video_mpeg4_level level_v4l2;
  379. int level;
  380. };
  381. /**
  382. * struct s5p_mfc_vp8_enc_params - encoding parameters for vp8
  383. */
  384. struct s5p_mfc_vp8_enc_params {
  385. u8 imd_4x4;
  386. enum v4l2_vp8_num_partitions num_partitions;
  387. enum v4l2_vp8_num_ref_frames num_ref;
  388. u8 filter_level;
  389. u8 filter_sharpness;
  390. u32 golden_frame_ref_period;
  391. enum v4l2_vp8_golden_frame_sel golden_frame_sel;
  392. u8 hier_layer;
  393. u8 hier_layer_qp[3];
  394. u8 rc_min_qp;
  395. u8 rc_max_qp;
  396. u8 rc_frame_qp;
  397. u8 rc_p_frame_qp;
  398. u8 profile;
  399. };
  400. /**
  401. * struct s5p_mfc_enc_params - general encoding parameters
  402. */
  403. struct s5p_mfc_enc_params {
  404. u16 width;
  405. u16 height;
  406. u32 mv_h_range;
  407. u32 mv_v_range;
  408. u16 gop_size;
  409. enum v4l2_mpeg_video_multi_slice_mode slice_mode;
  410. u16 slice_mb;
  411. u32 slice_bit;
  412. u16 intra_refresh_mb;
  413. int pad;
  414. u8 pad_luma;
  415. u8 pad_cb;
  416. u8 pad_cr;
  417. int rc_frame;
  418. int rc_mb;
  419. u32 rc_bitrate;
  420. u16 rc_reaction_coeff;
  421. u16 vbv_size;
  422. u32 vbv_delay;
  423. enum v4l2_mpeg_video_header_mode seq_hdr_mode;
  424. enum v4l2_mpeg_mfc51_video_frame_skip_mode frame_skip_mode;
  425. int fixed_target_bit;
  426. u8 num_b_frame;
  427. u32 rc_framerate_num;
  428. u32 rc_framerate_denom;
  429. struct {
  430. struct s5p_mfc_h264_enc_params h264;
  431. struct s5p_mfc_mpeg4_enc_params mpeg4;
  432. struct s5p_mfc_vp8_enc_params vp8;
  433. } codec;
  434. };
  435. /**
  436. * struct s5p_mfc_codec_ops - codec ops, used by encoding
  437. */
  438. struct s5p_mfc_codec_ops {
  439. /* initialization routines */
  440. int (*pre_seq_start) (struct s5p_mfc_ctx *ctx);
  441. int (*post_seq_start) (struct s5p_mfc_ctx *ctx);
  442. /* execution routines */
  443. int (*pre_frame_start) (struct s5p_mfc_ctx *ctx);
  444. int (*post_frame_start) (struct s5p_mfc_ctx *ctx);
  445. };
  446. #define call_cop(c, op, args...) \
  447. (((c)->c_ops->op) ? \
  448. ((c)->c_ops->op(args)) : 0)
  449. /**
  450. * struct s5p_mfc_ctx - This struct contains the instance context
  451. *
  452. * @dev: pointer to the s5p_mfc_dev of the device
  453. * @fh: struct v4l2_fh
  454. * @num: number of the context that this structure describes
  455. * @int_cond: variable used by the waitqueue
  456. * @int_type: type of the last interrupt
  457. * @int_err: error number received from MFC hw in the interrupt
  458. * @queue: waitqueue that can be used to wait for this context to
  459. * finish
  460. * @src_fmt: source pixelformat information
  461. * @dst_fmt: destination pixelformat information
  462. * @vq_src: vb2 queue for source buffers
  463. * @vq_dst: vb2 queue for destination buffers
  464. * @src_queue: driver internal queue for source buffers
  465. * @dst_queue: driver internal queue for destination buffers
  466. * @src_queue_cnt: number of buffers queued on the source internal queue
  467. * @dst_queue_cnt: number of buffers queued on the dest internal queue
  468. * @type: type of the instance - decoder or encoder
  469. * @state: state of the context
  470. * @inst_no: number of hw instance associated with the context
  471. * @img_width: width of the image that is decoded or encoded
  472. * @img_height: height of the image that is decoded or encoded
  473. * @buf_width: width of the buffer for processed image
  474. * @buf_height: height of the buffer for processed image
  475. * @luma_size: size of a luma plane
  476. * @chroma_size: size of a chroma plane
  477. * @mv_size: size of a motion vectors buffer
  478. * @consumed_stream: number of bytes that have been used so far from the
  479. * decoding buffer
  480. * @dpb_flush_flag: flag used to indicate that a DPB buffers are being
  481. * flushed
  482. * @head_processed: flag mentioning whether the header data is processed
  483. * completely or not
  484. * @bank1: handle to memory allocated for temporary buffers from
  485. * memory bank 1
  486. * @bank2: handle to memory allocated for temporary buffers from
  487. * memory bank 2
  488. * @capture_state: state of the capture buffers queue
  489. * @output_state: state of the output buffers queue
  490. * @src_bufs: information on allocated source buffers
  491. * @dst_bufs: information on allocated destination buffers
  492. * @sequence: counter for the sequence number for v4l2
  493. * @dec_dst_flag: flags for buffers queued in the hardware
  494. * @dec_src_buf_size: size of the buffer for source buffers in decoding
  495. * @codec_mode: number of codec mode used by MFC hw
  496. * @slice_interface: slice interface flag
  497. * @loop_filter_mpeg4: loop filter for MPEG4 flag
  498. * @display_delay: value of the display delay for H264
  499. * @display_delay_enable: display delay for H264 enable flag
  500. * @after_packed_pb: flag used to track buffer when stream is in
  501. * Packed PB format
  502. * @sei_fp_parse: enable/disable parsing of frame packing SEI information
  503. * @dpb_count: count of the DPB buffers required by MFC hw
  504. * @total_dpb_count: count of DPB buffers with additional buffers
  505. * requested by the application
  506. * @ctx: context buffer information
  507. * @dsc: descriptor buffer information
  508. * @shm: shared memory buffer information
  509. * @mv_count: number of MV buffers allocated for decoding
  510. * @enc_params: encoding parameters for MFC
  511. * @enc_dst_buf_size: size of the buffers for encoder output
  512. * @luma_dpb_size: dpb buffer size for luma
  513. * @chroma_dpb_size: dpb buffer size for chroma
  514. * @me_buffer_size: size of the motion estimation buffer
  515. * @tmv_buffer_size: size of temporal predictor motion vector buffer
  516. * @frame_type: used to force the type of the next encoded frame
  517. * @ref_queue: list of the reference buffers for encoding
  518. * @ref_queue_cnt: number of the buffers in the reference list
  519. * @c_ops: ops for encoding
  520. * @ctrls: array of controls, used when adding controls to the
  521. * v4l2 control framework
  522. * @ctrl_handler: handler for v4l2 framework
  523. */
  524. struct s5p_mfc_ctx {
  525. struct s5p_mfc_dev *dev;
  526. struct v4l2_fh fh;
  527. int num;
  528. int int_cond;
  529. int int_type;
  530. unsigned int int_err;
  531. wait_queue_head_t queue;
  532. struct s5p_mfc_fmt *src_fmt;
  533. struct s5p_mfc_fmt *dst_fmt;
  534. struct vb2_queue vq_src;
  535. struct vb2_queue vq_dst;
  536. struct list_head src_queue;
  537. struct list_head dst_queue;
  538. unsigned int src_queue_cnt;
  539. unsigned int dst_queue_cnt;
  540. enum s5p_mfc_inst_type type;
  541. enum s5p_mfc_inst_state state;
  542. int inst_no;
  543. /* Image parameters */
  544. int img_width;
  545. int img_height;
  546. int buf_width;
  547. int buf_height;
  548. int luma_size;
  549. int chroma_size;
  550. int mv_size;
  551. unsigned long consumed_stream;
  552. unsigned int dpb_flush_flag;
  553. unsigned int head_processed;
  554. struct s5p_mfc_priv_buf bank1;
  555. struct s5p_mfc_priv_buf bank2;
  556. enum s5p_mfc_queue_state capture_state;
  557. enum s5p_mfc_queue_state output_state;
  558. struct s5p_mfc_buf src_bufs[MFC_MAX_BUFFERS];
  559. int src_bufs_cnt;
  560. struct s5p_mfc_buf dst_bufs[MFC_MAX_BUFFERS];
  561. int dst_bufs_cnt;
  562. unsigned int sequence;
  563. unsigned long dec_dst_flag;
  564. size_t dec_src_buf_size;
  565. /* Control values */
  566. int codec_mode;
  567. int slice_interface;
  568. int loop_filter_mpeg4;
  569. int display_delay;
  570. int display_delay_enable;
  571. int after_packed_pb;
  572. int sei_fp_parse;
  573. int pb_count;
  574. int total_dpb_count;
  575. int mv_count;
  576. /* Buffers */
  577. struct s5p_mfc_priv_buf ctx;
  578. struct s5p_mfc_priv_buf dsc;
  579. struct s5p_mfc_priv_buf shm;
  580. struct s5p_mfc_enc_params enc_params;
  581. size_t enc_dst_buf_size;
  582. size_t luma_dpb_size;
  583. size_t chroma_dpb_size;
  584. size_t me_buffer_size;
  585. size_t tmv_buffer_size;
  586. enum v4l2_mpeg_mfc51_video_force_frame_type force_frame_type;
  587. struct list_head ref_queue;
  588. unsigned int ref_queue_cnt;
  589. enum v4l2_mpeg_video_multi_slice_mode slice_mode;
  590. union {
  591. unsigned int mb;
  592. unsigned int bits;
  593. } slice_size;
  594. const struct s5p_mfc_codec_ops *c_ops;
  595. struct v4l2_ctrl *ctrls[MFC_MAX_CTRLS];
  596. struct v4l2_ctrl_handler ctrl_handler;
  597. unsigned int frame_tag;
  598. size_t scratch_buf_size;
  599. };
  600. /*
  601. * struct s5p_mfc_fmt - structure used to store information about pixelformats
  602. * used by the MFC
  603. */
  604. struct s5p_mfc_fmt {
  605. char *name;
  606. u32 fourcc;
  607. u32 codec_mode;
  608. enum s5p_mfc_fmt_type type;
  609. u32 num_planes;
  610. u32 versions;
  611. };
  612. /**
  613. * struct mfc_control - structure used to store information about MFC controls
  614. * it is used to initialize the control framework.
  615. */
  616. struct mfc_control {
  617. __u32 id;
  618. enum v4l2_ctrl_type type;
  619. __u8 name[32]; /* Whatever */
  620. __s32 minimum; /* Note signedness */
  621. __s32 maximum;
  622. __s32 step;
  623. __u32 menu_skip_mask;
  624. __s32 default_value;
  625. __u32 flags;
  626. __u32 reserved[2];
  627. __u8 is_volatile;
  628. };
  629. /* Macro for making hardware specific calls */
  630. #define s5p_mfc_hw_call(f, op, args...) \
  631. ((f && f->op) ? f->op(args) : (typeof(f->op(args)))(-ENODEV))
  632. #define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh)
  633. #define ctrl_to_ctx(__ctrl) \
  634. container_of((__ctrl)->handler, struct s5p_mfc_ctx, ctrl_handler)
  635. void clear_work_bit(struct s5p_mfc_ctx *ctx);
  636. void set_work_bit(struct s5p_mfc_ctx *ctx);
  637. void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
  638. void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
  639. int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev);
  640. void s5p_mfc_cleanup_queue(struct list_head *lh, struct vb2_queue *vq);
  641. #define HAS_PORTNUM(dev) (dev ? (dev->variant ? \
  642. (dev->variant->port_num ? 1 : 0) : 0) : 0)
  643. #define IS_TWOPORT(dev) (dev->variant->port_num == 2 ? 1 : 0)
  644. #define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
  645. #define IS_MFCV7_PLUS(dev) (dev->variant->version >= 0x70 ? 1 : 0)
  646. #define IS_MFCV8(dev) (dev->variant->version >= 0x80 ? 1 : 0)
  647. #define MFC_V5_BIT BIT(0)
  648. #define MFC_V6_BIT BIT(1)
  649. #define MFC_V7_BIT BIT(2)
  650. #define MFC_V8_BIT BIT(3)
  651. #endif /* S5P_MFC_COMMON_H_ */