diff options
Diffstat (limited to 'drivers/media/platform/s5p-mfc/s5p_mfc_common.h')
-rw-r--r-- | drivers/media/platform/s5p-mfc/s5p_mfc_common.h | 191 |
1 files changed, 155 insertions, 36 deletions
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h index 519b0d66d8d1..f02e0497ca98 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h | |||
@@ -16,13 +16,14 @@ | |||
16 | #ifndef S5P_MFC_COMMON_H_ | 16 | #ifndef S5P_MFC_COMMON_H_ |
17 | #define S5P_MFC_COMMON_H_ | 17 | #define S5P_MFC_COMMON_H_ |
18 | 18 | ||
19 | #include "regs-mfc.h" | ||
20 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
21 | #include <linux/videodev2.h> | 20 | #include <linux/videodev2.h> |
22 | #include <media/v4l2-ctrls.h> | 21 | #include <media/v4l2-ctrls.h> |
23 | #include <media/v4l2-device.h> | 22 | #include <media/v4l2-device.h> |
24 | #include <media/v4l2-ioctl.h> | 23 | #include <media/v4l2-ioctl.h> |
25 | #include <media/videobuf2-core.h> | 24 | #include <media/videobuf2-core.h> |
25 | #include "regs-mfc.h" | ||
26 | #include "regs-mfc-v6.h" | ||
26 | 27 | ||
27 | /* Definitions related to MFC memory */ | 28 | /* Definitions related to MFC memory */ |
28 | 29 | ||
@@ -30,17 +31,6 @@ | |||
30 | * while mmaping */ | 31 | * while mmaping */ |
31 | #define DST_QUEUE_OFF_BASE (TASK_SIZE / 2) | 32 | #define DST_QUEUE_OFF_BASE (TASK_SIZE / 2) |
32 | 33 | ||
33 | /* Offset used by the hardware to store addresses */ | ||
34 | #define MFC_OFFSET_SHIFT 11 | ||
35 | |||
36 | #define FIRMWARE_ALIGN 0x20000 /* 128KB */ | ||
37 | #define MFC_H264_CTX_BUF_SIZE 0x96000 /* 600KB per H264 instance */ | ||
38 | #define MFC_CTX_BUF_SIZE 0x2800 /* 10KB per instance */ | ||
39 | #define DESC_BUF_SIZE 0x20000 /* 128KB for DESC buffer */ | ||
40 | #define SHARED_BUF_SIZE 0x2000 /* 8KB for shared buffer */ | ||
41 | |||
42 | #define DEF_CPB_SIZE 0x40000 /* 512KB */ | ||
43 | |||
44 | #define MFC_BANK1_ALLOC_CTX 0 | 34 | #define MFC_BANK1_ALLOC_CTX 0 |
45 | #define MFC_BANK2_ALLOC_CTX 1 | 35 | #define MFC_BANK2_ALLOC_CTX 1 |
46 | 36 | ||
@@ -74,7 +64,40 @@ static inline dma_addr_t s5p_mfc_mem_cookie(void *a, void *b) | |||
74 | #define MFC_ENC_CAP_PLANE_COUNT 1 | 64 | #define MFC_ENC_CAP_PLANE_COUNT 1 |
75 | #define MFC_ENC_OUT_PLANE_COUNT 2 | 65 | #define MFC_ENC_OUT_PLANE_COUNT 2 |
76 | #define STUFF_BYTE 4 | 66 | #define STUFF_BYTE 4 |
77 | #define MFC_MAX_CTRLS 64 | 67 | #define MFC_MAX_CTRLS 70 |
68 | |||
69 | #define S5P_MFC_CODEC_NONE -1 | ||
70 | #define S5P_MFC_CODEC_H264_DEC 0 | ||
71 | #define S5P_MFC_CODEC_H264_MVC_DEC 1 | ||
72 | #define S5P_MFC_CODEC_VC1_DEC 2 | ||
73 | #define S5P_MFC_CODEC_MPEG4_DEC 3 | ||
74 | #define S5P_MFC_CODEC_MPEG2_DEC 4 | ||
75 | #define S5P_MFC_CODEC_H263_DEC 5 | ||
76 | #define S5P_MFC_CODEC_VC1RCV_DEC 6 | ||
77 | #define S5P_MFC_CODEC_VP8_DEC 7 | ||
78 | |||
79 | #define S5P_MFC_CODEC_H264_ENC 20 | ||
80 | #define S5P_MFC_CODEC_H264_MVC_ENC 21 | ||
81 | #define S5P_MFC_CODEC_MPEG4_ENC 22 | ||
82 | #define S5P_MFC_CODEC_H263_ENC 23 | ||
83 | |||
84 | #define S5P_MFC_R2H_CMD_EMPTY 0 | ||
85 | #define S5P_MFC_R2H_CMD_SYS_INIT_RET 1 | ||
86 | #define S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET 2 | ||
87 | #define S5P_MFC_R2H_CMD_SEQ_DONE_RET 3 | ||
88 | #define S5P_MFC_R2H_CMD_INIT_BUFFERS_RET 4 | ||
89 | #define S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET 6 | ||
90 | #define S5P_MFC_R2H_CMD_SLEEP_RET 7 | ||
91 | #define S5P_MFC_R2H_CMD_WAKEUP_RET 8 | ||
92 | #define S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET 9 | ||
93 | #define S5P_MFC_R2H_CMD_DPB_FLUSH_RET 10 | ||
94 | #define S5P_MFC_R2H_CMD_NAL_ABORT_RET 11 | ||
95 | #define S5P_MFC_R2H_CMD_FW_STATUS_RET 12 | ||
96 | #define S5P_MFC_R2H_CMD_FRAME_DONE_RET 13 | ||
97 | #define S5P_MFC_R2H_CMD_FIELD_DONE_RET 14 | ||
98 | #define S5P_MFC_R2H_CMD_SLICE_DONE_RET 15 | ||
99 | #define S5P_MFC_R2H_CMD_ENC_BUFFER_FUL_RET 16 | ||
100 | #define S5P_MFC_R2H_CMD_ERR_RET 32 | ||
78 | 101 | ||
79 | #define mfc_read(dev, offset) readl(dev->regs_base + (offset)) | 102 | #define mfc_read(dev, offset) readl(dev->regs_base + (offset)) |
80 | #define mfc_write(dev, data, offset) writel((data), dev->regs_base + \ | 103 | #define mfc_write(dev, data, offset) writel((data), dev->regs_base + \ |
@@ -177,6 +200,58 @@ struct s5p_mfc_pm { | |||
177 | struct device *device; | 200 | struct device *device; |
178 | }; | 201 | }; |
179 | 202 | ||
203 | struct s5p_mfc_buf_size_v5 { | ||
204 | unsigned int h264_ctx; | ||
205 | unsigned int non_h264_ctx; | ||
206 | unsigned int dsc; | ||
207 | unsigned int shm; | ||
208 | }; | ||
209 | |||
210 | struct s5p_mfc_buf_size_v6 { | ||
211 | unsigned int dev_ctx; | ||
212 | unsigned int h264_dec_ctx; | ||
213 | unsigned int other_dec_ctx; | ||
214 | unsigned int h264_enc_ctx; | ||
215 | unsigned int other_enc_ctx; | ||
216 | }; | ||
217 | |||
218 | struct s5p_mfc_buf_size { | ||
219 | unsigned int fw; | ||
220 | unsigned int cpb; | ||
221 | void *priv; | ||
222 | }; | ||
223 | |||
224 | struct s5p_mfc_buf_align { | ||
225 | unsigned int base; | ||
226 | }; | ||
227 | |||
228 | struct s5p_mfc_variant { | ||
229 | unsigned int version; | ||
230 | unsigned int port_num; | ||
231 | struct s5p_mfc_buf_size *buf_size; | ||
232 | struct s5p_mfc_buf_align *buf_align; | ||
233 | char *mclk_name; | ||
234 | char *fw_name; | ||
235 | }; | ||
236 | |||
237 | /** | ||
238 | * struct s5p_mfc_priv_buf - represents internal used buffer | ||
239 | * @alloc: allocation-specific context for each buffer | ||
240 | * (videobuf2 allocator) | ||
241 | * @ofs: offset of each buffer, will be used for MFC | ||
242 | * @virt: kernel virtual address, only valid when the | ||
243 | * buffer accessed by driver | ||
244 | * @dma: DMA address, only valid when kernel DMA API used | ||
245 | * @size: size of the buffer | ||
246 | */ | ||
247 | struct s5p_mfc_priv_buf { | ||
248 | void *alloc; | ||
249 | unsigned long ofs; | ||
250 | void *virt; | ||
251 | dma_addr_t dma; | ||
252 | size_t size; | ||
253 | }; | ||
254 | |||
180 | /** | 255 | /** |
181 | * struct s5p_mfc_dev - The struct containing driver internal parameters. | 256 | * struct s5p_mfc_dev - The struct containing driver internal parameters. |
182 | * | 257 | * |
@@ -191,6 +266,7 @@ struct s5p_mfc_pm { | |||
191 | * @dec_ctrl_handler: control framework handler for decoding | 266 | * @dec_ctrl_handler: control framework handler for decoding |
192 | * @enc_ctrl_handler: control framework handler for encoding | 267 | * @enc_ctrl_handler: control framework handler for encoding |
193 | * @pm: power management control | 268 | * @pm: power management control |
269 | * @variant: MFC hardware variant information | ||
194 | * @num_inst: couter of active MFC instances | 270 | * @num_inst: couter of active MFC instances |
195 | * @irqlock: lock for operations on videobuf2 queues | 271 | * @irqlock: lock for operations on videobuf2 queues |
196 | * @condlock: lock for changing/checking if a context is ready to be | 272 | * @condlock: lock for changing/checking if a context is ready to be |
@@ -212,6 +288,10 @@ struct s5p_mfc_pm { | |||
212 | * @watchdog_work: worker for the watchdog | 288 | * @watchdog_work: worker for the watchdog |
213 | * @alloc_ctx: videobuf2 allocator contexts for two memory banks | 289 | * @alloc_ctx: videobuf2 allocator contexts for two memory banks |
214 | * @enter_suspend: flag set when entering suspend | 290 | * @enter_suspend: flag set when entering suspend |
291 | * @ctx_buf: common context memory (MFCv6) | ||
292 | * @warn_start: hardware error code from which warnings start | ||
293 | * @mfc_ops: ops structure holding HW operation function pointers | ||
294 | * @mfc_cmds: cmd structure holding HW commands function pointers | ||
215 | * | 295 | * |
216 | */ | 296 | */ |
217 | struct s5p_mfc_dev { | 297 | struct s5p_mfc_dev { |
@@ -226,6 +306,7 @@ struct s5p_mfc_dev { | |||
226 | struct v4l2_ctrl_handler dec_ctrl_handler; | 306 | struct v4l2_ctrl_handler dec_ctrl_handler; |
227 | struct v4l2_ctrl_handler enc_ctrl_handler; | 307 | struct v4l2_ctrl_handler enc_ctrl_handler; |
228 | struct s5p_mfc_pm pm; | 308 | struct s5p_mfc_pm pm; |
309 | struct s5p_mfc_variant *variant; | ||
229 | int num_inst; | 310 | int num_inst; |
230 | spinlock_t irqlock; /* lock when operating on videobuf2 queues */ | 311 | spinlock_t irqlock; /* lock when operating on videobuf2 queues */ |
231 | spinlock_t condlock; /* lock when changing/checking if a context is | 312 | spinlock_t condlock; /* lock when changing/checking if a context is |
@@ -248,6 +329,11 @@ struct s5p_mfc_dev { | |||
248 | struct work_struct watchdog_work; | 329 | struct work_struct watchdog_work; |
249 | void *alloc_ctx[2]; | 330 | void *alloc_ctx[2]; |
250 | unsigned long enter_suspend; | 331 | unsigned long enter_suspend; |
332 | |||
333 | struct s5p_mfc_priv_buf ctx_buf; | ||
334 | int warn_start; | ||
335 | struct s5p_mfc_hw_ops *mfc_ops; | ||
336 | struct s5p_mfc_hw_cmds *mfc_cmds; | ||
251 | }; | 337 | }; |
252 | 338 | ||
253 | /** | 339 | /** |
@@ -262,7 +348,6 @@ struct s5p_mfc_h264_enc_params { | |||
262 | u8 max_ref_pic; | 348 | u8 max_ref_pic; |
263 | u8 num_ref_pic_4p; | 349 | u8 num_ref_pic_4p; |
264 | int _8x8_transform; | 350 | int _8x8_transform; |
265 | int rc_mb; | ||
266 | int rc_mb_dark; | 351 | int rc_mb_dark; |
267 | int rc_mb_smooth; | 352 | int rc_mb_smooth; |
268 | int rc_mb_static; | 353 | int rc_mb_static; |
@@ -281,6 +366,23 @@ struct s5p_mfc_h264_enc_params { | |||
281 | enum v4l2_mpeg_video_h264_level level_v4l2; | 366 | enum v4l2_mpeg_video_h264_level level_v4l2; |
282 | int level; | 367 | int level; |
283 | u16 cpb_size; | 368 | u16 cpb_size; |
369 | int interlace; | ||
370 | u8 hier_qp; | ||
371 | u8 hier_qp_type; | ||
372 | u8 hier_qp_layer; | ||
373 | u8 hier_qp_layer_qp[7]; | ||
374 | u8 sei_frame_packing; | ||
375 | u8 sei_fp_curr_frame_0; | ||
376 | u8 sei_fp_arrangement_type; | ||
377 | |||
378 | u8 fmo; | ||
379 | u8 fmo_map_type; | ||
380 | u8 fmo_slice_grp; | ||
381 | u8 fmo_chg_dir; | ||
382 | u32 fmo_chg_rate; | ||
383 | u32 fmo_run_len[4]; | ||
384 | u8 aso; | ||
385 | u32 aso_slice_order[8]; | ||
284 | }; | 386 | }; |
285 | 387 | ||
286 | /** | 388 | /** |
@@ -319,9 +421,11 @@ struct s5p_mfc_enc_params { | |||
319 | u8 pad_cb; | 421 | u8 pad_cb; |
320 | u8 pad_cr; | 422 | u8 pad_cr; |
321 | int rc_frame; | 423 | int rc_frame; |
424 | int rc_mb; | ||
322 | u32 rc_bitrate; | 425 | u32 rc_bitrate; |
323 | u16 rc_reaction_coeff; | 426 | u16 rc_reaction_coeff; |
324 | u16 vbv_size; | 427 | u16 vbv_size; |
428 | u32 vbv_delay; | ||
325 | 429 | ||
326 | enum v4l2_mpeg_video_header_mode seq_hdr_mode; | 430 | enum v4l2_mpeg_video_header_mode seq_hdr_mode; |
327 | enum v4l2_mpeg_mfc51_video_frame_skip_mode frame_skip_mode; | 431 | enum v4l2_mpeg_mfc51_video_frame_skip_mode frame_skip_mode; |
@@ -330,7 +434,6 @@ struct s5p_mfc_enc_params { | |||
330 | u8 num_b_frame; | 434 | u8 num_b_frame; |
331 | u32 rc_framerate_num; | 435 | u32 rc_framerate_num; |
332 | u32 rc_framerate_denom; | 436 | u32 rc_framerate_denom; |
333 | int interlace; | ||
334 | 437 | ||
335 | union { | 438 | union { |
336 | struct s5p_mfc_h264_enc_params h264; | 439 | struct s5p_mfc_h264_enc_params h264; |
@@ -388,6 +491,8 @@ struct s5p_mfc_codec_ops { | |||
388 | * decoding buffer | 491 | * decoding buffer |
389 | * @dpb_flush_flag: flag used to indicate that a DPB buffers are being | 492 | * @dpb_flush_flag: flag used to indicate that a DPB buffers are being |
390 | * flushed | 493 | * flushed |
494 | * @head_processed: flag mentioning whether the header data is processed | ||
495 | * completely or not | ||
391 | * @bank1_buf: handle to memory allocated for temporary buffers from | 496 | * @bank1_buf: handle to memory allocated for temporary buffers from |
392 | * memory bank 1 | 497 | * memory bank 1 |
393 | * @bank1_phys: address of the temporary buffers from memory bank 1 | 498 | * @bank1_phys: address of the temporary buffers from memory bank 1 |
@@ -412,19 +517,20 @@ struct s5p_mfc_codec_ops { | |||
412 | * @display_delay_enable: display delay for H264 enable flag | 517 | * @display_delay_enable: display delay for H264 enable flag |
413 | * @after_packed_pb: flag used to track buffer when stream is in | 518 | * @after_packed_pb: flag used to track buffer when stream is in |
414 | * Packed PB format | 519 | * Packed PB format |
520 | * @sei_fp_parse: enable/disable parsing of frame packing SEI information | ||
415 | * @dpb_count: count of the DPB buffers required by MFC hw | 521 | * @dpb_count: count of the DPB buffers required by MFC hw |
416 | * @total_dpb_count: count of DPB buffers with additional buffers | 522 | * @total_dpb_count: count of DPB buffers with additional buffers |
417 | * requested by the application | 523 | * requested by the application |
418 | * @ctx_buf: handle to the memory associated with this context | 524 | * @ctx: context buffer information |
419 | * @ctx_phys: address of the memory associated with this context | 525 | * @dsc: descriptor buffer information |
420 | * @ctx_size: size of the memory associated with this context | 526 | * @shm: shared memory buffer information |
421 | * @desc_buf: description buffer for decoding handle | 527 | * @mv_count: number of MV buffers allocated for decoding |
422 | * @desc_phys: description buffer for decoding address | ||
423 | * @shm_alloc: handle for the shared memory buffer | ||
424 | * @shm: virtual address for the shared memory buffer | ||
425 | * @shm_ofs: address offset for shared memory | ||
426 | * @enc_params: encoding parameters for MFC | 528 | * @enc_params: encoding parameters for MFC |
427 | * @enc_dst_buf_size: size of the buffers for encoder output | 529 | * @enc_dst_buf_size: size of the buffers for encoder output |
530 | * @luma_dpb_size: dpb buffer size for luma | ||
531 | * @chroma_dpb_size: dpb buffer size for chroma | ||
532 | * @me_buffer_size: size of the motion estimation buffer | ||
533 | * @tmv_buffer_size: size of temporal predictor motion vector buffer | ||
428 | * @frame_type: used to force the type of the next encoded frame | 534 | * @frame_type: used to force the type of the next encoded frame |
429 | * @ref_queue: list of the reference buffers for encoding | 535 | * @ref_queue: list of the reference buffers for encoding |
430 | * @ref_queue_cnt: number of the buffers in the reference list | 536 | * @ref_queue_cnt: number of the buffers in the reference list |
@@ -473,6 +579,7 @@ struct s5p_mfc_ctx { | |||
473 | unsigned long consumed_stream; | 579 | unsigned long consumed_stream; |
474 | 580 | ||
475 | unsigned int dpb_flush_flag; | 581 | unsigned int dpb_flush_flag; |
582 | unsigned int head_processed; | ||
476 | 583 | ||
477 | /* Buffers */ | 584 | /* Buffers */ |
478 | void *bank1_buf; | 585 | void *bank1_buf; |
@@ -502,37 +609,41 @@ struct s5p_mfc_ctx { | |||
502 | int display_delay; | 609 | int display_delay; |
503 | int display_delay_enable; | 610 | int display_delay_enable; |
504 | int after_packed_pb; | 611 | int after_packed_pb; |
612 | int sei_fp_parse; | ||
505 | 613 | ||
506 | int dpb_count; | 614 | int dpb_count; |
507 | int total_dpb_count; | 615 | int total_dpb_count; |
508 | 616 | int mv_count; | |
509 | /* Buffers */ | 617 | /* Buffers */ |
510 | void *ctx_buf; | 618 | struct s5p_mfc_priv_buf ctx; |
511 | size_t ctx_phys; | 619 | struct s5p_mfc_priv_buf dsc; |
512 | size_t ctx_ofs; | 620 | struct s5p_mfc_priv_buf shm; |
513 | size_t ctx_size; | ||
514 | |||
515 | void *desc_buf; | ||
516 | size_t desc_phys; | ||
517 | |||
518 | |||
519 | void *shm_alloc; | ||
520 | void *shm; | ||
521 | size_t shm_ofs; | ||
522 | 621 | ||
523 | struct s5p_mfc_enc_params enc_params; | 622 | struct s5p_mfc_enc_params enc_params; |
524 | 623 | ||
525 | size_t enc_dst_buf_size; | 624 | size_t enc_dst_buf_size; |
625 | size_t luma_dpb_size; | ||
626 | size_t chroma_dpb_size; | ||
627 | size_t me_buffer_size; | ||
628 | size_t tmv_buffer_size; | ||
526 | 629 | ||
527 | enum v4l2_mpeg_mfc51_video_force_frame_type force_frame_type; | 630 | enum v4l2_mpeg_mfc51_video_force_frame_type force_frame_type; |
528 | 631 | ||
529 | struct list_head ref_queue; | 632 | struct list_head ref_queue; |
530 | unsigned int ref_queue_cnt; | 633 | unsigned int ref_queue_cnt; |
531 | 634 | ||
635 | enum v4l2_mpeg_video_multi_slice_mode slice_mode; | ||
636 | union { | ||
637 | unsigned int mb; | ||
638 | unsigned int bits; | ||
639 | } slice_size; | ||
640 | |||
532 | struct s5p_mfc_codec_ops *c_ops; | 641 | struct s5p_mfc_codec_ops *c_ops; |
533 | 642 | ||
534 | struct v4l2_ctrl *ctrls[MFC_MAX_CTRLS]; | 643 | struct v4l2_ctrl *ctrls[MFC_MAX_CTRLS]; |
535 | struct v4l2_ctrl_handler ctrl_handler; | 644 | struct v4l2_ctrl_handler ctrl_handler; |
645 | unsigned int frame_tag; | ||
646 | size_t scratch_buf_size; | ||
536 | }; | 647 | }; |
537 | 648 | ||
538 | /* | 649 | /* |
@@ -565,6 +676,9 @@ struct mfc_control { | |||
565 | __u8 is_volatile; | 676 | __u8 is_volatile; |
566 | }; | 677 | }; |
567 | 678 | ||
679 | /* Macro for making hardware specific calls */ | ||
680 | #define s5p_mfc_hw_call(f, op, args...) \ | ||
681 | ((f && f->op) ? f->op(args) : -ENODEV) | ||
568 | 682 | ||
569 | #define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh) | 683 | #define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh) |
570 | #define ctrl_to_ctx(__ctrl) \ | 684 | #define ctrl_to_ctx(__ctrl) \ |
@@ -575,4 +689,9 @@ void set_work_bit(struct s5p_mfc_ctx *ctx); | |||
575 | void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx); | 689 | void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx); |
576 | void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx); | 690 | void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx); |
577 | 691 | ||
692 | #define HAS_PORTNUM(dev) (dev ? (dev->variant ? \ | ||
693 | (dev->variant->port_num ? 1 : 0) : 0) : 0) | ||
694 | #define IS_TWOPORT(dev) (dev->variant->port_num == 2 ? 1 : 0) | ||
695 | #define IS_MFCV6(dev) (dev->variant->version >= 0x60 ? 1 : 0) | ||
696 | |||
578 | #endif /* S5P_MFC_COMMON_H_ */ | 697 | #endif /* S5P_MFC_COMMON_H_ */ |