aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform
diff options
context:
space:
mode:
authorAndrzej Hajda <a.hajda@samsung.com>2012-08-14 05:13:40 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-10-02 12:58:40 -0400
commit7fb89eca0f2ad21f6e77f3411cb220ed94f340df (patch)
tree8aa5f697f6c5f6cbfd85d801b61652728088197c /drivers/media/platform
parentf9f715a95d07d3868bb30aeb20252b6b05d35d8f (diff)
[media] s5p-mfc: optimized code related to working contextes
All code setting/clearing working context bits has been moved to separate functions. set_bit/clear_bit have been replaced by non-atomic variants - variable is already guarded by spin_lock. Signed-off-by: Andrzej Hajda <a.hajda@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/platform')
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c55
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_common.h5
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_dec.c28
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_enc.c34
4 files changed, 60 insertions, 62 deletions
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 776e6bc241fc..4486a2340532 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -41,16 +41,49 @@ module_param(debug, int, S_IRUGO | S_IWUSR);
41MODULE_PARM_DESC(debug, "Debug level - higher value produces more verbose messages"); 41MODULE_PARM_DESC(debug, "Debug level - higher value produces more verbose messages");
42 42
43/* Helper functions for interrupt processing */ 43/* Helper functions for interrupt processing */
44
44/* Remove from hw execution round robin */ 45/* Remove from hw execution round robin */
45static void clear_work_bit(struct s5p_mfc_ctx *ctx) 46void clear_work_bit(struct s5p_mfc_ctx *ctx)
46{ 47{
47 struct s5p_mfc_dev *dev = ctx->dev; 48 struct s5p_mfc_dev *dev = ctx->dev;
48 49
49 spin_lock(&dev->condlock); 50 spin_lock(&dev->condlock);
50 clear_bit(ctx->num, &dev->ctx_work_bits); 51 __clear_bit(ctx->num, &dev->ctx_work_bits);
51 spin_unlock(&dev->condlock); 52 spin_unlock(&dev->condlock);
52} 53}
53 54
55/* Add to hw execution round robin */
56void set_work_bit(struct s5p_mfc_ctx *ctx)
57{
58 struct s5p_mfc_dev *dev = ctx->dev;
59
60 spin_lock(&dev->condlock);
61 __set_bit(ctx->num, &dev->ctx_work_bits);
62 spin_unlock(&dev->condlock);
63}
64
65/* Remove from hw execution round robin */
66void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx)
67{
68 struct s5p_mfc_dev *dev = ctx->dev;
69 unsigned long flags;
70
71 spin_lock_irqsave(&dev->condlock, flags);
72 __clear_bit(ctx->num, &dev->ctx_work_bits);
73 spin_unlock_irqrestore(&dev->condlock, flags);
74}
75
76/* Add to hw execution round robin */
77void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx)
78{
79 struct s5p_mfc_dev *dev = ctx->dev;
80 unsigned long flags;
81
82 spin_lock_irqsave(&dev->condlock, flags);
83 __set_bit(ctx->num, &dev->ctx_work_bits);
84 spin_unlock_irqrestore(&dev->condlock, flags);
85}
86
54/* Wake up context wait_queue */ 87/* Wake up context wait_queue */
55static void wake_up_ctx(struct s5p_mfc_ctx *ctx, unsigned int reason, 88static void wake_up_ctx(struct s5p_mfc_ctx *ctx, unsigned int reason,
56 unsigned int err) 89 unsigned int err)
@@ -504,9 +537,7 @@ static void s5p_mfc_handle_init_buffers(struct s5p_mfc_ctx *ctx,
504 ctx->int_type = reason; 537 ctx->int_type = reason;
505 ctx->int_err = err; 538 ctx->int_err = err;
506 ctx->int_cond = 1; 539 ctx->int_cond = 1;
507 spin_lock(&dev->condlock); 540 clear_work_bit(ctx);
508 clear_bit(ctx->num, &dev->ctx_work_bits);
509 spin_unlock(&dev->condlock);
510 if (err == 0) { 541 if (err == 0) {
511 ctx->state = MFCINST_RUNNING; 542 ctx->state = MFCINST_RUNNING;
512 if (!ctx->dpb_flush_flag) { 543 if (!ctx->dpb_flush_flag) {
@@ -681,7 +712,6 @@ static int s5p_mfc_open(struct file *file)
681 struct s5p_mfc_dev *dev = video_drvdata(file); 712 struct s5p_mfc_dev *dev = video_drvdata(file);
682 struct s5p_mfc_ctx *ctx = NULL; 713 struct s5p_mfc_ctx *ctx = NULL;
683 struct vb2_queue *q; 714 struct vb2_queue *q;
684 unsigned long flags;
685 int ret = 0; 715 int ret = 0;
686 716
687 mfc_debug_enter(); 717 mfc_debug_enter();
@@ -714,9 +744,7 @@ static int s5p_mfc_open(struct file *file)
714 } 744 }
715 } 745 }
716 /* Mark context as idle */ 746 /* Mark context as idle */
717 spin_lock_irqsave(&dev->condlock, flags); 747 clear_work_bit_irqsave(ctx);
718 clear_bit(ctx->num, &dev->ctx_work_bits);
719 spin_unlock_irqrestore(&dev->condlock, flags);
720 dev->ctx[ctx->num] = ctx; 748 dev->ctx[ctx->num] = ctx;
721 if (s5p_mfc_get_node_type(file) == MFCNODE_DECODER) { 749 if (s5p_mfc_get_node_type(file) == MFCNODE_DECODER) {
722 ctx->type = MFCINST_DECODER; 750 ctx->type = MFCINST_DECODER;
@@ -843,7 +871,6 @@ static int s5p_mfc_release(struct file *file)
843{ 871{
844 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); 872 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data);
845 struct s5p_mfc_dev *dev = ctx->dev; 873 struct s5p_mfc_dev *dev = ctx->dev;
846 unsigned long flags;
847 874
848 mfc_debug_enter(); 875 mfc_debug_enter();
849 mutex_lock(&dev->mfc_mutex); 876 mutex_lock(&dev->mfc_mutex);
@@ -851,17 +878,13 @@ static int s5p_mfc_release(struct file *file)
851 vb2_queue_release(&ctx->vq_src); 878 vb2_queue_release(&ctx->vq_src);
852 vb2_queue_release(&ctx->vq_dst); 879 vb2_queue_release(&ctx->vq_dst);
853 /* Mark context as idle */ 880 /* Mark context as idle */
854 spin_lock_irqsave(&dev->condlock, flags); 881 clear_work_bit_irqsave(ctx);
855 clear_bit(ctx->num, &dev->ctx_work_bits);
856 spin_unlock_irqrestore(&dev->condlock, flags);
857 /* If instance was initialised then 882 /* If instance was initialised then
858 * return instance and free reosurces */ 883 * return instance and free reosurces */
859 if (ctx->inst_no != MFC_NO_INSTANCE_SET) { 884 if (ctx->inst_no != MFC_NO_INSTANCE_SET) {
860 mfc_debug(2, "Has to free instance\n"); 885 mfc_debug(2, "Has to free instance\n");
861 ctx->state = MFCINST_RETURN_INST; 886 ctx->state = MFCINST_RETURN_INST;
862 spin_lock_irqsave(&dev->condlock, flags); 887 set_work_bit_irqsave(ctx);
863 set_bit(ctx->num, &dev->ctx_work_bits);
864 spin_unlock_irqrestore(&dev->condlock, flags);
865 s5p_mfc_clean_ctx_int_flags(ctx); 888 s5p_mfc_clean_ctx_int_flags(ctx);
866 s5p_mfc_try_run(dev); 889 s5p_mfc_try_run(dev);
867 /* Wait until instance is returned or timeout occured */ 890 /* Wait until instance is returned or timeout occured */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 8871f0de6efd..519b0d66d8d1 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -570,4 +570,9 @@ struct mfc_control {
570#define ctrl_to_ctx(__ctrl) \ 570#define ctrl_to_ctx(__ctrl) \
571 container_of((__ctrl)->handler, struct s5p_mfc_ctx, ctrl_handler) 571 container_of((__ctrl)->handler, struct s5p_mfc_ctx, ctrl_handler)
572 572
573void clear_work_bit(struct s5p_mfc_ctx *ctx);
574void set_work_bit(struct s5p_mfc_ctx *ctx);
575void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
576void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
577
573#endif /* S5P_MFC_COMMON_H_ */ 578#endif /* S5P_MFC_COMMON_H_ */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index aef83d13182c..6ee21bb71398 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -415,7 +415,6 @@ static int vidioc_reqbufs(struct file *file, void *priv,
415 struct s5p_mfc_dev *dev = video_drvdata(file); 415 struct s5p_mfc_dev *dev = video_drvdata(file);
416 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); 416 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
417 int ret = 0; 417 int ret = 0;
418 unsigned long flags;
419 418
420 if (reqbufs->memory != V4L2_MEMORY_MMAP) { 419 if (reqbufs->memory != V4L2_MEMORY_MMAP) {
421 mfc_err("Only V4L2_MEMORY_MAP is supported\n"); 420 mfc_err("Only V4L2_MEMORY_MAP is supported\n");
@@ -497,11 +496,8 @@ static int vidioc_reqbufs(struct file *file, void *priv,
497 s5p_mfc_clock_off(); 496 s5p_mfc_clock_off();
498 return -ENOMEM; 497 return -ENOMEM;
499 } 498 }
500 if (s5p_mfc_ctx_ready(ctx)) { 499 if (s5p_mfc_ctx_ready(ctx))
501 spin_lock_irqsave(&dev->condlock, flags); 500 set_work_bit_irqsave(ctx);
502 set_bit(ctx->num, &dev->ctx_work_bits);
503 spin_unlock_irqrestore(&dev->condlock, flags);
504 }
505 s5p_mfc_try_run(dev); 501 s5p_mfc_try_run(dev);
506 s5p_mfc_wait_for_done_ctx(ctx, 502 s5p_mfc_wait_for_done_ctx(ctx,
507 S5P_FIMV_R2H_CMD_INIT_BUFFERS_RET, 0); 503 S5P_FIMV_R2H_CMD_INIT_BUFFERS_RET, 0);
@@ -576,7 +572,6 @@ static int vidioc_streamon(struct file *file, void *priv,
576{ 572{
577 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); 573 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
578 struct s5p_mfc_dev *dev = ctx->dev; 574 struct s5p_mfc_dev *dev = ctx->dev;
579 unsigned long flags;
580 int ret = -EINVAL; 575 int ret = -EINVAL;
581 576
582 mfc_debug_enter(); 577 mfc_debug_enter();
@@ -589,9 +584,7 @@ static int vidioc_streamon(struct file *file, void *priv,
589 ctx->output_state = QUEUE_FREE; 584 ctx->output_state = QUEUE_FREE;
590 s5p_mfc_alloc_instance_buffer(ctx); 585 s5p_mfc_alloc_instance_buffer(ctx);
591 s5p_mfc_alloc_dec_temp_buffers(ctx); 586 s5p_mfc_alloc_dec_temp_buffers(ctx);
592 spin_lock_irqsave(&dev->condlock, flags); 587 set_work_bit_irqsave(ctx);
593 set_bit(ctx->num, &dev->ctx_work_bits);
594 spin_unlock_irqrestore(&dev->condlock, flags);
595 s5p_mfc_clean_ctx_int_flags(ctx); 588 s5p_mfc_clean_ctx_int_flags(ctx);
596 s5p_mfc_try_run(dev); 589 s5p_mfc_try_run(dev);
597 590
@@ -875,18 +868,14 @@ static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
875{ 868{
876 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv); 869 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
877 struct s5p_mfc_dev *dev = ctx->dev; 870 struct s5p_mfc_dev *dev = ctx->dev;
878 unsigned long flags;
879 871
880 v4l2_ctrl_handler_setup(&ctx->ctrl_handler); 872 v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
881 if (ctx->state == MFCINST_FINISHING || 873 if (ctx->state == MFCINST_FINISHING ||
882 ctx->state == MFCINST_FINISHED) 874 ctx->state == MFCINST_FINISHED)
883 ctx->state = MFCINST_RUNNING; 875 ctx->state = MFCINST_RUNNING;
884 /* If context is ready then dev = work->data;schedule it to run */ 876 /* If context is ready then dev = work->data;schedule it to run */
885 if (s5p_mfc_ctx_ready(ctx)) { 877 if (s5p_mfc_ctx_ready(ctx))
886 spin_lock_irqsave(&dev->condlock, flags); 878 set_work_bit_irqsave(ctx);
887 set_bit(ctx->num, &dev->ctx_work_bits);
888 spin_unlock_irqrestore(&dev->condlock, flags);
889 }
890 s5p_mfc_try_run(dev); 879 s5p_mfc_try_run(dev);
891 return 0; 880 return 0;
892} 881}
@@ -953,11 +942,8 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
953 } else { 942 } else {
954 mfc_err("Unsupported buffer type (%d)\n", vq->type); 943 mfc_err("Unsupported buffer type (%d)\n", vq->type);
955 } 944 }
956 if (s5p_mfc_ctx_ready(ctx)) { 945 if (s5p_mfc_ctx_ready(ctx))
957 spin_lock_irqsave(&dev->condlock, flags); 946 set_work_bit_irqsave(ctx);
958 set_bit(ctx->num, &dev->ctx_work_bits);
959 spin_unlock_irqrestore(&dev->condlock, flags);
960 }
961 s5p_mfc_try_run(dev); 947 s5p_mfc_try_run(dev);
962} 948}
963 949
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 075cc5c5f9bc..179e4db60b15 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -643,11 +643,8 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
643 spin_unlock_irqrestore(&dev->irqlock, flags); 643 spin_unlock_irqrestore(&dev->irqlock, flags);
644 } 644 }
645 ctx->state = MFCINST_RUNNING; 645 ctx->state = MFCINST_RUNNING;
646 if (s5p_mfc_ctx_ready(ctx)) { 646 if (s5p_mfc_ctx_ready(ctx))
647 spin_lock_irqsave(&dev->condlock, flags); 647 set_work_bit_irqsave(ctx);
648 set_bit(ctx->num, &dev->ctx_work_bits);
649 spin_unlock_irqrestore(&dev->condlock, flags);
650 }
651 s5p_mfc_try_run(dev); 648 s5p_mfc_try_run(dev);
652 return 0; 649 return 0;
653} 650}
@@ -755,11 +752,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
755 vb2_buffer_done(mb_entry->b, VB2_BUF_STATE_DONE); 752 vb2_buffer_done(mb_entry->b, VB2_BUF_STATE_DONE);
756 } 753 }
757 spin_unlock_irqrestore(&dev->irqlock, flags); 754 spin_unlock_irqrestore(&dev->irqlock, flags);
758 if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0)) { 755 if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0))
759 spin_lock(&dev->condlock); 756 clear_work_bit(ctx);
760 clear_bit(ctx->num, &dev->ctx_work_bits);
761 spin_unlock(&dev->condlock);
762 }
763 return 0; 757 return 0;
764} 758}
765 759
@@ -922,7 +916,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
922 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); 916 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
923 struct s5p_mfc_fmt *fmt; 917 struct s5p_mfc_fmt *fmt;
924 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp; 918 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
925 unsigned long flags;
926 int ret = 0; 919 int ret = 0;
927 920
928 ret = vidioc_try_fmt(file, priv, f); 921 ret = vidioc_try_fmt(file, priv, f);
@@ -947,9 +940,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
947 ctx->dst_bufs_cnt = 0; 940 ctx->dst_bufs_cnt = 0;
948 ctx->capture_state = QUEUE_FREE; 941 ctx->capture_state = QUEUE_FREE;
949 s5p_mfc_alloc_instance_buffer(ctx); 942 s5p_mfc_alloc_instance_buffer(ctx);
950 spin_lock_irqsave(&dev->condlock, flags); 943 set_work_bit_irqsave(ctx);
951 set_bit(ctx->num, &dev->ctx_work_bits);
952 spin_unlock_irqrestore(&dev->condlock, flags);
953 s5p_mfc_clean_ctx_int_flags(ctx); 944 s5p_mfc_clean_ctx_int_flags(ctx);
954 s5p_mfc_try_run(dev); 945 s5p_mfc_try_run(dev);
955 if (s5p_mfc_wait_for_done_ctx(ctx, \ 946 if (s5p_mfc_wait_for_done_ctx(ctx, \
@@ -1719,15 +1710,11 @@ static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
1719{ 1710{
1720 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv); 1711 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
1721 struct s5p_mfc_dev *dev = ctx->dev; 1712 struct s5p_mfc_dev *dev = ctx->dev;
1722 unsigned long flags;
1723 1713
1724 v4l2_ctrl_handler_setup(&ctx->ctrl_handler); 1714 v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
1725 /* If context is ready then dev = work->data;schedule it to run */ 1715 /* If context is ready then dev = work->data;schedule it to run */
1726 if (s5p_mfc_ctx_ready(ctx)) { 1716 if (s5p_mfc_ctx_ready(ctx))
1727 spin_lock_irqsave(&dev->condlock, flags); 1717 set_work_bit_irqsave(ctx);
1728 set_bit(ctx->num, &dev->ctx_work_bits);
1729 spin_unlock_irqrestore(&dev->condlock, flags);
1730 }
1731 s5p_mfc_try_run(dev); 1718 s5p_mfc_try_run(dev);
1732 return 0; 1719 return 0;
1733} 1720}
@@ -1793,11 +1780,8 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
1793 } else { 1780 } else {
1794 mfc_err("unsupported buffer type (%d)\n", vq->type); 1781 mfc_err("unsupported buffer type (%d)\n", vq->type);
1795 } 1782 }
1796 if (s5p_mfc_ctx_ready(ctx)) { 1783 if (s5p_mfc_ctx_ready(ctx))
1797 spin_lock_irqsave(&dev->condlock, flags); 1784 set_work_bit_irqsave(ctx);
1798 set_bit(ctx->num, &dev->ctx_work_bits);
1799 spin_unlock_irqrestore(&dev->condlock, flags);
1800 }
1801 s5p_mfc_try_run(dev); 1785 s5p_mfc_try_run(dev);
1802} 1786}
1803 1787