aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform/omap3isp/ispqueue.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2014-03-09 19:57:53 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-05-25 10:19:48 -0400
commit988d54c4b9463bd14bb05e4b8c9a47d04a14d272 (patch)
tree3b730cd6347c953c7f17e11beed24446c5d0930e /drivers/media/platform/omap3isp/ispqueue.c
parent1e345d4ab4a873a0c96ecbdfdd2f9a36998bba6f (diff)
[media] omap3isp: Move queue mutex to isp_video structure
This prepares for the move to videobuf2. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Sakari Ailus <sakari.ailus@iki.fi> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/platform/omap3isp/ispqueue.c')
-rw-r--r--drivers/media/platform/omap3isp/ispqueue.c102
1 files changed, 26 insertions, 76 deletions
diff --git a/drivers/media/platform/omap3isp/ispqueue.c b/drivers/media/platform/omap3isp/ispqueue.c
index 515ed94cec48..dcd9446f01a5 100644
--- a/drivers/media/platform/omap3isp/ispqueue.c
+++ b/drivers/media/platform/omap3isp/ispqueue.c
@@ -660,7 +660,6 @@ int omap3isp_video_queue_init(struct isp_video_queue *queue,
660 struct device *dev, unsigned int bufsize) 660 struct device *dev, unsigned int bufsize)
661{ 661{
662 INIT_LIST_HEAD(&queue->queue); 662 INIT_LIST_HEAD(&queue->queue);
663 mutex_init(&queue->lock);
664 spin_lock_init(&queue->irqlock); 663 spin_lock_init(&queue->irqlock);
665 664
666 queue->type = type; 665 queue->type = type;
@@ -712,18 +711,12 @@ int omap3isp_video_queue_reqbufs(struct isp_video_queue *queue,
712 711
713 nbuffers = min_t(unsigned int, nbuffers, ISP_VIDEO_MAX_BUFFERS); 712 nbuffers = min_t(unsigned int, nbuffers, ISP_VIDEO_MAX_BUFFERS);
714 713
715 mutex_lock(&queue->lock);
716
717 ret = isp_video_queue_alloc(queue, nbuffers, size, rb->memory); 714 ret = isp_video_queue_alloc(queue, nbuffers, size, rb->memory);
718 if (ret < 0) 715 if (ret < 0)
719 goto done; 716 return ret;
720 717
721 rb->count = ret; 718 rb->count = ret;
722 ret = 0; 719 return 0;
723
724done:
725 mutex_unlock(&queue->lock);
726 return ret;
727} 720}
728 721
729/** 722/**
@@ -738,24 +731,17 @@ int omap3isp_video_queue_querybuf(struct isp_video_queue *queue,
738 struct v4l2_buffer *vbuf) 731 struct v4l2_buffer *vbuf)
739{ 732{
740 struct isp_video_buffer *buf; 733 struct isp_video_buffer *buf;
741 int ret = 0;
742 734
743 if (vbuf->type != queue->type) 735 if (vbuf->type != queue->type)
744 return -EINVAL; 736 return -EINVAL;
745 737
746 mutex_lock(&queue->lock); 738 if (vbuf->index >= queue->count)
747 739 return -EINVAL;
748 if (vbuf->index >= queue->count) {
749 ret = -EINVAL;
750 goto done;
751 }
752 740
753 buf = queue->buffers[vbuf->index]; 741 buf = queue->buffers[vbuf->index];
754 isp_video_buffer_query(buf, vbuf); 742 isp_video_buffer_query(buf, vbuf);
755 743
756done: 744 return 0;
757 mutex_unlock(&queue->lock);
758 return ret;
759} 745}
760 746
761/** 747/**
@@ -776,27 +762,25 @@ int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
776{ 762{
777 struct isp_video_buffer *buf; 763 struct isp_video_buffer *buf;
778 unsigned long flags; 764 unsigned long flags;
779 int ret = -EINVAL; 765 int ret;
780 766
781 if (vbuf->type != queue->type) 767 if (vbuf->type != queue->type)
782 goto done; 768 return -EINVAL;
783
784 mutex_lock(&queue->lock);
785 769
786 if (vbuf->index >= queue->count) 770 if (vbuf->index >= queue->count)
787 goto done; 771 return -EINVAL;
788 772
789 buf = queue->buffers[vbuf->index]; 773 buf = queue->buffers[vbuf->index];
790 774
791 if (vbuf->memory != buf->vbuf.memory) 775 if (vbuf->memory != buf->vbuf.memory)
792 goto done; 776 return -EINVAL;
793 777
794 if (buf->state != ISP_BUF_STATE_IDLE) 778 if (buf->state != ISP_BUF_STATE_IDLE)
795 goto done; 779 return -EINVAL;
796 780
797 if (vbuf->memory == V4L2_MEMORY_USERPTR && 781 if (vbuf->memory == V4L2_MEMORY_USERPTR &&
798 vbuf->length < buf->vbuf.length) 782 vbuf->length < buf->vbuf.length)
799 goto done; 783 return -EINVAL;
800 784
801 if (vbuf->memory == V4L2_MEMORY_USERPTR && 785 if (vbuf->memory == V4L2_MEMORY_USERPTR &&
802 vbuf->m.userptr != buf->vbuf.m.userptr) { 786 vbuf->m.userptr != buf->vbuf.m.userptr) {
@@ -808,7 +792,7 @@ int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
808 if (!buf->prepared) { 792 if (!buf->prepared) {
809 ret = isp_video_buffer_prepare(buf); 793 ret = isp_video_buffer_prepare(buf);
810 if (ret < 0) 794 if (ret < 0)
811 goto done; 795 return ret;
812 buf->prepared = 1; 796 buf->prepared = 1;
813 } 797 }
814 798
@@ -823,11 +807,7 @@ int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
823 spin_unlock_irqrestore(&queue->irqlock, flags); 807 spin_unlock_irqrestore(&queue->irqlock, flags);
824 } 808 }
825 809
826 ret = 0; 810 return 0;
827
828done:
829 mutex_unlock(&queue->lock);
830 return ret;
831} 811}
832 812
833/** 813/**
@@ -853,17 +833,13 @@ int omap3isp_video_queue_dqbuf(struct isp_video_queue *queue,
853 if (vbuf->type != queue->type) 833 if (vbuf->type != queue->type)
854 return -EINVAL; 834 return -EINVAL;
855 835
856 mutex_lock(&queue->lock); 836 if (list_empty(&queue->queue))
857 837 return -EINVAL;
858 if (list_empty(&queue->queue)) {
859 ret = -EINVAL;
860 goto done;
861 }
862 838
863 buf = list_first_entry(&queue->queue, struct isp_video_buffer, stream); 839 buf = list_first_entry(&queue->queue, struct isp_video_buffer, stream);
864 ret = isp_video_buffer_wait(buf, nonblocking); 840 ret = isp_video_buffer_wait(buf, nonblocking);
865 if (ret < 0) 841 if (ret < 0)
866 goto done; 842 return ret;
867 843
868 list_del(&buf->stream); 844 list_del(&buf->stream);
869 845
@@ -871,9 +847,7 @@ int omap3isp_video_queue_dqbuf(struct isp_video_queue *queue,
871 buf->state = ISP_BUF_STATE_IDLE; 847 buf->state = ISP_BUF_STATE_IDLE;
872 vbuf->flags &= ~V4L2_BUF_FLAG_QUEUED; 848 vbuf->flags &= ~V4L2_BUF_FLAG_QUEUED;
873 849
874done: 850 return 0;
875 mutex_unlock(&queue->lock);
876 return ret;
877} 851}
878 852
879/** 853/**
@@ -890,10 +864,8 @@ int omap3isp_video_queue_streamon(struct isp_video_queue *queue)
890 struct isp_video_buffer *buf; 864 struct isp_video_buffer *buf;
891 unsigned long flags; 865 unsigned long flags;
892 866
893 mutex_lock(&queue->lock);
894
895 if (queue->streaming) 867 if (queue->streaming)
896 goto done; 868 return 0;
897 869
898 queue->streaming = 1; 870 queue->streaming = 1;
899 871
@@ -902,8 +874,6 @@ int omap3isp_video_queue_streamon(struct isp_video_queue *queue)
902 queue->ops->buffer_queue(buf); 874 queue->ops->buffer_queue(buf);
903 spin_unlock_irqrestore(&queue->irqlock, flags); 875 spin_unlock_irqrestore(&queue->irqlock, flags);
904 876
905done:
906 mutex_unlock(&queue->lock);
907 return 0; 877 return 0;
908} 878}
909 879
@@ -923,10 +893,8 @@ void omap3isp_video_queue_streamoff(struct isp_video_queue *queue)
923 unsigned long flags; 893 unsigned long flags;
924 unsigned int i; 894 unsigned int i;
925 895
926 mutex_lock(&queue->lock);
927
928 if (!queue->streaming) 896 if (!queue->streaming)
929 goto done; 897 return;
930 898
931 queue->streaming = 0; 899 queue->streaming = 0;
932 900
@@ -942,9 +910,6 @@ void omap3isp_video_queue_streamoff(struct isp_video_queue *queue)
942 spin_unlock_irqrestore(&queue->irqlock, flags); 910 spin_unlock_irqrestore(&queue->irqlock, flags);
943 911
944 INIT_LIST_HEAD(&queue->queue); 912 INIT_LIST_HEAD(&queue->queue);
945
946done:
947 mutex_unlock(&queue->lock);
948} 913}
949 914
950/** 915/**
@@ -963,10 +928,8 @@ void omap3isp_video_queue_discard_done(struct isp_video_queue *queue)
963 struct isp_video_buffer *buf; 928 struct isp_video_buffer *buf;
964 unsigned int i; 929 unsigned int i;
965 930
966 mutex_lock(&queue->lock);
967
968 if (!queue->streaming) 931 if (!queue->streaming)
969 goto done; 932 return;
970 933
971 for (i = 0; i < queue->count; ++i) { 934 for (i = 0; i < queue->count; ++i) {
972 buf = queue->buffers[i]; 935 buf = queue->buffers[i];
@@ -974,9 +937,6 @@ void omap3isp_video_queue_discard_done(struct isp_video_queue *queue)
974 if (buf->state == ISP_BUF_STATE_DONE) 937 if (buf->state == ISP_BUF_STATE_DONE)
975 buf->state = ISP_BUF_STATE_ERROR; 938 buf->state = ISP_BUF_STATE_ERROR;
976 } 939 }
977
978done:
979 mutex_unlock(&queue->lock);
980} 940}
981 941
982static void isp_video_queue_vm_open(struct vm_area_struct *vma) 942static void isp_video_queue_vm_open(struct vm_area_struct *vma)
@@ -1014,26 +974,20 @@ int omap3isp_video_queue_mmap(struct isp_video_queue *queue,
1014 unsigned int i; 974 unsigned int i;
1015 int ret = 0; 975 int ret = 0;
1016 976
1017 mutex_lock(&queue->lock);
1018
1019 for (i = 0; i < queue->count; ++i) { 977 for (i = 0; i < queue->count; ++i) {
1020 buf = queue->buffers[i]; 978 buf = queue->buffers[i];
1021 if ((buf->vbuf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff) 979 if ((buf->vbuf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
1022 break; 980 break;
1023 } 981 }
1024 982
1025 if (i == queue->count) { 983 if (i == queue->count)
1026 ret = -EINVAL; 984 return -EINVAL;
1027 goto done;
1028 }
1029 985
1030 size = vma->vm_end - vma->vm_start; 986 size = vma->vm_end - vma->vm_start;
1031 987
1032 if (buf->vbuf.memory != V4L2_MEMORY_MMAP || 988 if (buf->vbuf.memory != V4L2_MEMORY_MMAP ||
1033 size != PAGE_ALIGN(buf->vbuf.length)) { 989 size != PAGE_ALIGN(buf->vbuf.length))
1034 ret = -EINVAL; 990 return -EINVAL;
1035 goto done;
1036 }
1037 991
1038 /* dma_mmap_coherent() uses vm_pgoff as an offset inside the buffer 992 /* dma_mmap_coherent() uses vm_pgoff as an offset inside the buffer
1039 * while we used it to identify the buffer and want to map the whole 993 * while we used it to identify the buffer and want to map the whole
@@ -1043,16 +997,14 @@ int omap3isp_video_queue_mmap(struct isp_video_queue *queue,
1043 997
1044 ret = dma_mmap_coherent(queue->dev, vma, buf->vaddr, buf->dma, size); 998 ret = dma_mmap_coherent(queue->dev, vma, buf->vaddr, buf->dma, size);
1045 if (ret < 0) 999 if (ret < 0)
1046 goto done; 1000 return ret;
1047 1001
1048 vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; 1002 vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
1049 vma->vm_ops = &isp_video_queue_vm_ops; 1003 vma->vm_ops = &isp_video_queue_vm_ops;
1050 vma->vm_private_data = buf; 1004 vma->vm_private_data = buf;
1051 isp_video_queue_vm_open(vma); 1005 isp_video_queue_vm_open(vma);
1052 1006
1053done: 1007 return 0;
1054 mutex_unlock(&queue->lock);
1055 return ret;
1056} 1008}
1057 1009
1058/** 1010/**
@@ -1070,7 +1022,6 @@ unsigned int omap3isp_video_queue_poll(struct isp_video_queue *queue,
1070 struct isp_video_buffer *buf; 1022 struct isp_video_buffer *buf;
1071 unsigned int mask = 0; 1023 unsigned int mask = 0;
1072 1024
1073 mutex_lock(&queue->lock);
1074 if (list_empty(&queue->queue)) { 1025 if (list_empty(&queue->queue)) {
1075 mask |= POLLERR; 1026 mask |= POLLERR;
1076 goto done; 1027 goto done;
@@ -1087,6 +1038,5 @@ unsigned int omap3isp_video_queue_poll(struct isp_video_queue *queue,
1087 } 1038 }
1088 1039
1089done: 1040done:
1090 mutex_unlock(&queue->lock);
1091 return mask; 1041 return mask;
1092} 1042}