s5p_mfc_common.h 21 KB

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