diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2014-11-18 07:51:01 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2014-11-25 05:55:32 -0500 |
commit | 0c3a14c177aa85afb991e7c2be3921aa9a52a893 (patch) | |
tree | de833b66ee640393292bc404e16c8f43a49ae89c /drivers/media | |
parent | e5ae8fa739f8a1d5c292c5b13fa33ac64166e5a0 (diff) |
[media] vb2-dma-sg: add allocation context to dma-sg
Require that dma-sg also uses an allocation context. This is in preparation
for adding prepare/finish memops to sync the memory between DMA and CPU.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Pawel Osciak <pawel@osciak.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/pci/cx23885/cx23885-417.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/cx23885/cx23885-core.c | 10 | ||||
-rw-r--r-- | drivers/media/pci/cx23885/cx23885-dvb.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/cx23885/cx23885-vbi.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/cx23885/cx23885-video.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/cx23885/cx23885.h | 1 | ||||
-rw-r--r-- | drivers/media/pci/saa7134/saa7134-core.c | 18 | ||||
-rw-r--r-- | drivers/media/pci/saa7134/saa7134-ts.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/saa7134/saa7134-vbi.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/saa7134/saa7134-video.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/saa7134/saa7134.h | 1 | ||||
-rw-r--r-- | drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c | 10 | ||||
-rw-r--r-- | drivers/media/pci/solo6x10/solo6x10.h | 1 | ||||
-rw-r--r-- | drivers/media/pci/tw68/tw68-core.c | 15 | ||||
-rw-r--r-- | drivers/media/pci/tw68/tw68-video.c | 1 | ||||
-rw-r--r-- | drivers/media/pci/tw68/tw68.h | 1 | ||||
-rw-r--r-- | drivers/media/platform/marvell-ccic/mcam-core.c | 13 | ||||
-rw-r--r-- | drivers/media/platform/marvell-ccic/mcam-core.h | 1 | ||||
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-dma-sg.c | 32 |
19 files changed, 101 insertions, 10 deletions
diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c index 3948db386fb5..d72a3ec348ef 100644 --- a/drivers/media/pci/cx23885/cx23885-417.c +++ b/drivers/media/pci/cx23885/cx23885-417.c | |||
@@ -1148,6 +1148,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
1148 | dev->ts1.ts_packet_count = mpeglines; | 1148 | dev->ts1.ts_packet_count = mpeglines; |
1149 | *num_planes = 1; | 1149 | *num_planes = 1; |
1150 | sizes[0] = mpeglinesize * mpeglines; | 1150 | sizes[0] = mpeglinesize * mpeglines; |
1151 | alloc_ctxs[0] = dev->alloc_ctx; | ||
1151 | *num_buffers = mpegbufs; | 1152 | *num_buffers = mpegbufs; |
1152 | return 0; | 1153 | return 0; |
1153 | } | 1154 | } |
diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c index 331eddac7222..d452b5c076e6 100644 --- a/drivers/media/pci/cx23885/cx23885-core.c +++ b/drivers/media/pci/cx23885/cx23885-core.c | |||
@@ -1997,9 +1997,14 @@ static int cx23885_initdev(struct pci_dev *pci_dev, | |||
1997 | if (!pci_dma_supported(pci_dev, 0xffffffff)) { | 1997 | if (!pci_dma_supported(pci_dev, 0xffffffff)) { |
1998 | printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name); | 1998 | printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name); |
1999 | err = -EIO; | 1999 | err = -EIO; |
2000 | goto fail_irq; | 2000 | goto fail_context; |
2001 | } | 2001 | } |
2002 | 2002 | ||
2003 | dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev); | ||
2004 | if (IS_ERR(dev->alloc_ctx)) { | ||
2005 | err = PTR_ERR(dev->alloc_ctx); | ||
2006 | goto fail_context; | ||
2007 | } | ||
2003 | err = request_irq(pci_dev->irq, cx23885_irq, | 2008 | err = request_irq(pci_dev->irq, cx23885_irq, |
2004 | IRQF_SHARED, dev->name, dev); | 2009 | IRQF_SHARED, dev->name, dev); |
2005 | if (err < 0) { | 2010 | if (err < 0) { |
@@ -2028,6 +2033,8 @@ static int cx23885_initdev(struct pci_dev *pci_dev, | |||
2028 | return 0; | 2033 | return 0; |
2029 | 2034 | ||
2030 | fail_irq: | 2035 | fail_irq: |
2036 | vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); | ||
2037 | fail_context: | ||
2031 | cx23885_dev_unregister(dev); | 2038 | cx23885_dev_unregister(dev); |
2032 | fail_ctrl: | 2039 | fail_ctrl: |
2033 | v4l2_ctrl_handler_free(hdl); | 2040 | v4l2_ctrl_handler_free(hdl); |
@@ -2053,6 +2060,7 @@ static void cx23885_finidev(struct pci_dev *pci_dev) | |||
2053 | free_irq(pci_dev->irq, dev); | 2060 | free_irq(pci_dev->irq, dev); |
2054 | 2061 | ||
2055 | cx23885_dev_unregister(dev); | 2062 | cx23885_dev_unregister(dev); |
2063 | vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); | ||
2056 | v4l2_ctrl_handler_free(&dev->ctrl_handler); | 2064 | v4l2_ctrl_handler_free(&dev->ctrl_handler); |
2057 | v4l2_device_unregister(v4l2_dev); | 2065 | v4l2_device_unregister(v4l2_dev); |
2058 | kfree(dev); | 2066 | kfree(dev); |
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c index 1ed92eeb46d1..44fafba65c6f 100644 --- a/drivers/media/pci/cx23885/cx23885-dvb.c +++ b/drivers/media/pci/cx23885/cx23885-dvb.c | |||
@@ -102,6 +102,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
102 | port->ts_packet_count = 32; | 102 | port->ts_packet_count = 32; |
103 | *num_planes = 1; | 103 | *num_planes = 1; |
104 | sizes[0] = port->ts_packet_size * port->ts_packet_count; | 104 | sizes[0] = port->ts_packet_size * port->ts_packet_count; |
105 | alloc_ctxs[0] = port->dev->alloc_ctx; | ||
105 | *num_buffers = 32; | 106 | *num_buffers = 32; |
106 | return 0; | 107 | return 0; |
107 | } | 108 | } |
diff --git a/drivers/media/pci/cx23885/cx23885-vbi.c b/drivers/media/pci/cx23885/cx23885-vbi.c index a7c6ef8f3ea3..1d339a69f0c8 100644 --- a/drivers/media/pci/cx23885/cx23885-vbi.c +++ b/drivers/media/pci/cx23885/cx23885-vbi.c | |||
@@ -132,6 +132,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
132 | lines = VBI_NTSC_LINE_COUNT; | 132 | lines = VBI_NTSC_LINE_COUNT; |
133 | *num_planes = 1; | 133 | *num_planes = 1; |
134 | sizes[0] = lines * VBI_LINE_LENGTH * 2; | 134 | sizes[0] = lines * VBI_LINE_LENGTH * 2; |
135 | alloc_ctxs[0] = dev->alloc_ctx; | ||
135 | return 0; | 136 | return 0; |
136 | } | 137 | } |
137 | 138 | ||
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c index 091f5dbe65a8..371eecfe7b32 100644 --- a/drivers/media/pci/cx23885/cx23885-video.c +++ b/drivers/media/pci/cx23885/cx23885-video.c | |||
@@ -323,6 +323,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
323 | 323 | ||
324 | *num_planes = 1; | 324 | *num_planes = 1; |
325 | sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3; | 325 | sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3; |
326 | alloc_ctxs[0] = dev->alloc_ctx; | ||
326 | return 0; | 327 | return 0; |
327 | } | 328 | } |
328 | 329 | ||
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h index cf4efa461ce2..f55cd12da0fd 100644 --- a/drivers/media/pci/cx23885/cx23885.h +++ b/drivers/media/pci/cx23885/cx23885.h | |||
@@ -425,6 +425,7 @@ struct cx23885_dev { | |||
425 | struct vb2_queue vb2_vidq; | 425 | struct vb2_queue vb2_vidq; |
426 | struct cx23885_dmaqueue vbiq; | 426 | struct cx23885_dmaqueue vbiq; |
427 | struct vb2_queue vb2_vbiq; | 427 | struct vb2_queue vb2_vbiq; |
428 | void *alloc_ctx; | ||
428 | 429 | ||
429 | spinlock_t slock; | 430 | spinlock_t slock; |
430 | 431 | ||
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c index 236ed725f933..a349e964e0bc 100644 --- a/drivers/media/pci/saa7134/saa7134-core.c +++ b/drivers/media/pci/saa7134/saa7134-core.c | |||
@@ -1001,13 +1001,18 @@ static int saa7134_initdev(struct pci_dev *pci_dev, | |||
1001 | saa7134_board_init1(dev); | 1001 | saa7134_board_init1(dev); |
1002 | saa7134_hwinit1(dev); | 1002 | saa7134_hwinit1(dev); |
1003 | 1003 | ||
1004 | dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev); | ||
1005 | if (IS_ERR(dev->alloc_ctx)) { | ||
1006 | err = PTR_ERR(dev->alloc_ctx); | ||
1007 | goto fail3; | ||
1008 | } | ||
1004 | /* get irq */ | 1009 | /* get irq */ |
1005 | err = request_irq(pci_dev->irq, saa7134_irq, | 1010 | err = request_irq(pci_dev->irq, saa7134_irq, |
1006 | IRQF_SHARED, dev->name, dev); | 1011 | IRQF_SHARED, dev->name, dev); |
1007 | if (err < 0) { | 1012 | if (err < 0) { |
1008 | printk(KERN_ERR "%s: can't get IRQ %d\n", | 1013 | printk(KERN_ERR "%s: can't get IRQ %d\n", |
1009 | dev->name,pci_dev->irq); | 1014 | dev->name,pci_dev->irq); |
1010 | goto fail3; | 1015 | goto fail4; |
1011 | } | 1016 | } |
1012 | 1017 | ||
1013 | /* wait a bit, register i2c bus */ | 1018 | /* wait a bit, register i2c bus */ |
@@ -1065,7 +1070,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev, | |||
1065 | if (err < 0) { | 1070 | if (err < 0) { |
1066 | printk(KERN_INFO "%s: can't register video device\n", | 1071 | printk(KERN_INFO "%s: can't register video device\n", |
1067 | dev->name); | 1072 | dev->name); |
1068 | goto fail4; | 1073 | goto fail5; |
1069 | } | 1074 | } |
1070 | printk(KERN_INFO "%s: registered device %s [v4l2]\n", | 1075 | printk(KERN_INFO "%s: registered device %s [v4l2]\n", |
1071 | dev->name, video_device_node_name(dev->video_dev)); | 1076 | dev->name, video_device_node_name(dev->video_dev)); |
@@ -1078,7 +1083,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev, | |||
1078 | err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, | 1083 | err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, |
1079 | vbi_nr[dev->nr]); | 1084 | vbi_nr[dev->nr]); |
1080 | if (err < 0) | 1085 | if (err < 0) |
1081 | goto fail4; | 1086 | goto fail5; |
1082 | printk(KERN_INFO "%s: registered device %s\n", | 1087 | printk(KERN_INFO "%s: registered device %s\n", |
1083 | dev->name, video_device_node_name(dev->vbi_dev)); | 1088 | dev->name, video_device_node_name(dev->vbi_dev)); |
1084 | 1089 | ||
@@ -1089,7 +1094,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev, | |||
1089 | err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO, | 1094 | err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO, |
1090 | radio_nr[dev->nr]); | 1095 | radio_nr[dev->nr]); |
1091 | if (err < 0) | 1096 | if (err < 0) |
1092 | goto fail4; | 1097 | goto fail5; |
1093 | printk(KERN_INFO "%s: registered device %s\n", | 1098 | printk(KERN_INFO "%s: registered device %s\n", |
1094 | dev->name, video_device_node_name(dev->radio_dev)); | 1099 | dev->name, video_device_node_name(dev->radio_dev)); |
1095 | } | 1100 | } |
@@ -1103,10 +1108,12 @@ static int saa7134_initdev(struct pci_dev *pci_dev, | |||
1103 | request_submodules(dev); | 1108 | request_submodules(dev); |
1104 | return 0; | 1109 | return 0; |
1105 | 1110 | ||
1106 | fail4: | 1111 | fail5: |
1107 | saa7134_unregister_video(dev); | 1112 | saa7134_unregister_video(dev); |
1108 | saa7134_i2c_unregister(dev); | 1113 | saa7134_i2c_unregister(dev); |
1109 | free_irq(pci_dev->irq, dev); | 1114 | free_irq(pci_dev->irq, dev); |
1115 | fail4: | ||
1116 | vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); | ||
1110 | fail3: | 1117 | fail3: |
1111 | saa7134_hwfini(dev); | 1118 | saa7134_hwfini(dev); |
1112 | iounmap(dev->lmmio); | 1119 | iounmap(dev->lmmio); |
@@ -1173,6 +1180,7 @@ static void saa7134_finidev(struct pci_dev *pci_dev) | |||
1173 | 1180 | ||
1174 | /* release resources */ | 1181 | /* release resources */ |
1175 | free_irq(pci_dev->irq, dev); | 1182 | free_irq(pci_dev->irq, dev); |
1183 | vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); | ||
1176 | iounmap(dev->lmmio); | 1184 | iounmap(dev->lmmio); |
1177 | release_mem_region(pci_resource_start(pci_dev,0), | 1185 | release_mem_region(pci_resource_start(pci_dev,0), |
1178 | pci_resource_len(pci_dev,0)); | 1186 | pci_resource_len(pci_dev,0)); |
diff --git a/drivers/media/pci/saa7134/saa7134-ts.c b/drivers/media/pci/saa7134/saa7134-ts.c index bd25323bd947..8eff4a7d8ba3 100644 --- a/drivers/media/pci/saa7134/saa7134-ts.c +++ b/drivers/media/pci/saa7134/saa7134-ts.c | |||
@@ -142,6 +142,7 @@ int saa7134_ts_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
142 | *nbuffers = 3; | 142 | *nbuffers = 3; |
143 | *nplanes = 1; | 143 | *nplanes = 1; |
144 | sizes[0] = size; | 144 | sizes[0] = size; |
145 | alloc_ctxs[0] = dev->alloc_ctx; | ||
145 | return 0; | 146 | return 0; |
146 | } | 147 | } |
147 | EXPORT_SYMBOL_GPL(saa7134_ts_queue_setup); | 148 | EXPORT_SYMBOL_GPL(saa7134_ts_queue_setup); |
diff --git a/drivers/media/pci/saa7134/saa7134-vbi.c b/drivers/media/pci/saa7134/saa7134-vbi.c index 4f0b1012e4f3..e2cc684a7c12 100644 --- a/drivers/media/pci/saa7134/saa7134-vbi.c +++ b/drivers/media/pci/saa7134/saa7134-vbi.c | |||
@@ -156,6 +156,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
156 | *nbuffers = saa7134_buffer_count(size, *nbuffers); | 156 | *nbuffers = saa7134_buffer_count(size, *nbuffers); |
157 | *nplanes = 1; | 157 | *nplanes = 1; |
158 | sizes[0] = size; | 158 | sizes[0] = size; |
159 | alloc_ctxs[0] = dev->alloc_ctx; | ||
159 | return 0; | 160 | return 0; |
160 | } | 161 | } |
161 | 162 | ||
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c index fc4a427cb51f..ba029953db9d 100644 --- a/drivers/media/pci/saa7134/saa7134-video.c +++ b/drivers/media/pci/saa7134/saa7134-video.c | |||
@@ -932,6 +932,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
932 | *nbuffers = saa7134_buffer_count(size, *nbuffers); | 932 | *nbuffers = saa7134_buffer_count(size, *nbuffers); |
933 | *nplanes = 1; | 933 | *nplanes = 1; |
934 | sizes[0] = size; | 934 | sizes[0] = size; |
935 | alloc_ctxs[0] = dev->alloc_ctx; | ||
935 | return 0; | 936 | return 0; |
936 | } | 937 | } |
937 | 938 | ||
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h index 1a82dd07205b..c644c7da6859 100644 --- a/drivers/media/pci/saa7134/saa7134.h +++ b/drivers/media/pci/saa7134/saa7134.h | |||
@@ -588,6 +588,7 @@ struct saa7134_dev { | |||
588 | 588 | ||
589 | 589 | ||
590 | /* video+ts+vbi capture */ | 590 | /* video+ts+vbi capture */ |
591 | void *alloc_ctx; | ||
591 | struct saa7134_dmaqueue video_q; | 592 | struct saa7134_dmaqueue video_q; |
592 | struct vb2_queue video_vbq; | 593 | struct vb2_queue video_vbq; |
593 | struct saa7134_dmaqueue vbi_q; | 594 | struct saa7134_dmaqueue vbi_q; |
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c index 30e09d935ce1..4f6bfba58065 100644 --- a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c +++ b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c | |||
@@ -718,7 +718,10 @@ static int solo_enc_queue_setup(struct vb2_queue *q, | |||
718 | unsigned int *num_planes, unsigned int sizes[], | 718 | unsigned int *num_planes, unsigned int sizes[], |
719 | void *alloc_ctxs[]) | 719 | void *alloc_ctxs[]) |
720 | { | 720 | { |
721 | struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q); | ||
722 | |||
721 | sizes[0] = FRAME_BUF_SIZE; | 723 | sizes[0] = FRAME_BUF_SIZE; |
724 | alloc_ctxs[0] = solo_enc->alloc_ctx; | ||
722 | *num_planes = 1; | 725 | *num_planes = 1; |
723 | 726 | ||
724 | if (*num_buffers < MIN_VID_BUFFERS) | 727 | if (*num_buffers < MIN_VID_BUFFERS) |
@@ -1266,6 +1269,11 @@ static struct solo_enc_dev *solo_enc_alloc(struct solo_dev *solo_dev, | |||
1266 | return ERR_PTR(-ENOMEM); | 1269 | return ERR_PTR(-ENOMEM); |
1267 | 1270 | ||
1268 | hdl = &solo_enc->hdl; | 1271 | hdl = &solo_enc->hdl; |
1272 | solo_enc->alloc_ctx = vb2_dma_sg_init_ctx(&solo_dev->pdev->dev); | ||
1273 | if (IS_ERR(solo_enc->alloc_ctx)) { | ||
1274 | ret = PTR_ERR(solo_enc->alloc_ctx); | ||
1275 | goto hdl_free; | ||
1276 | } | ||
1269 | v4l2_ctrl_handler_init(hdl, 10); | 1277 | v4l2_ctrl_handler_init(hdl, 10); |
1270 | v4l2_ctrl_new_std(hdl, &solo_ctrl_ops, | 1278 | v4l2_ctrl_new_std(hdl, &solo_ctrl_ops, |
1271 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); | 1279 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); |
@@ -1369,6 +1377,7 @@ pci_free: | |||
1369 | solo_enc->desc_items, solo_enc->desc_dma); | 1377 | solo_enc->desc_items, solo_enc->desc_dma); |
1370 | hdl_free: | 1378 | hdl_free: |
1371 | v4l2_ctrl_handler_free(hdl); | 1379 | v4l2_ctrl_handler_free(hdl); |
1380 | vb2_dma_sg_cleanup_ctx(solo_enc->alloc_ctx); | ||
1372 | kfree(solo_enc); | 1381 | kfree(solo_enc); |
1373 | return ERR_PTR(ret); | 1382 | return ERR_PTR(ret); |
1374 | } | 1383 | } |
@@ -1383,6 +1392,7 @@ static void solo_enc_free(struct solo_enc_dev *solo_enc) | |||
1383 | solo_enc->desc_items, solo_enc->desc_dma); | 1392 | solo_enc->desc_items, solo_enc->desc_dma); |
1384 | video_unregister_device(solo_enc->vfd); | 1393 | video_unregister_device(solo_enc->vfd); |
1385 | v4l2_ctrl_handler_free(&solo_enc->hdl); | 1394 | v4l2_ctrl_handler_free(&solo_enc->hdl); |
1395 | vb2_dma_sg_cleanup_ctx(solo_enc->alloc_ctx); | ||
1386 | kfree(solo_enc); | 1396 | kfree(solo_enc); |
1387 | } | 1397 | } |
1388 | 1398 | ||
diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h index 72017b7f0a75..bd8edfa319b8 100644 --- a/drivers/media/pci/solo6x10/solo6x10.h +++ b/drivers/media/pci/solo6x10/solo6x10.h | |||
@@ -180,6 +180,7 @@ struct solo_enc_dev { | |||
180 | u32 sequence; | 180 | u32 sequence; |
181 | struct vb2_queue vidq; | 181 | struct vb2_queue vidq; |
182 | struct list_head vidq_active; | 182 | struct list_head vidq_active; |
183 | void *alloc_ctx; | ||
183 | int desc_count; | 184 | int desc_count; |
184 | int desc_nelts; | 185 | int desc_nelts; |
185 | struct solo_p2m_desc *desc_items; | 186 | struct solo_p2m_desc *desc_items; |
diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c index 63f0b64057cb..c135165a8b26 100644 --- a/drivers/media/pci/tw68/tw68-core.c +++ b/drivers/media/pci/tw68/tw68-core.c | |||
@@ -304,13 +304,19 @@ static int tw68_initdev(struct pci_dev *pci_dev, | |||
304 | /* Then do any initialisation wanted before interrupts are on */ | 304 | /* Then do any initialisation wanted before interrupts are on */ |
305 | tw68_hw_init1(dev); | 305 | tw68_hw_init1(dev); |
306 | 306 | ||
307 | dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev); | ||
308 | if (IS_ERR(dev->alloc_ctx)) { | ||
309 | err = PTR_ERR(dev->alloc_ctx); | ||
310 | goto fail3; | ||
311 | } | ||
312 | |||
307 | /* get irq */ | 313 | /* get irq */ |
308 | err = devm_request_irq(&pci_dev->dev, pci_dev->irq, tw68_irq, | 314 | err = devm_request_irq(&pci_dev->dev, pci_dev->irq, tw68_irq, |
309 | IRQF_SHARED, dev->name, dev); | 315 | IRQF_SHARED, dev->name, dev); |
310 | if (err < 0) { | 316 | if (err < 0) { |
311 | pr_err("%s: can't get IRQ %d\n", | 317 | pr_err("%s: can't get IRQ %d\n", |
312 | dev->name, pci_dev->irq); | 318 | dev->name, pci_dev->irq); |
313 | goto fail3; | 319 | goto fail4; |
314 | } | 320 | } |
315 | 321 | ||
316 | /* | 322 | /* |
@@ -324,7 +330,7 @@ static int tw68_initdev(struct pci_dev *pci_dev, | |||
324 | if (err < 0) { | 330 | if (err < 0) { |
325 | pr_err("%s: can't register video device\n", | 331 | pr_err("%s: can't register video device\n", |
326 | dev->name); | 332 | dev->name); |
327 | goto fail4; | 333 | goto fail5; |
328 | } | 334 | } |
329 | tw_setl(TW68_INTMASK, dev->pci_irqmask); | 335 | tw_setl(TW68_INTMASK, dev->pci_irqmask); |
330 | 336 | ||
@@ -333,8 +339,10 @@ static int tw68_initdev(struct pci_dev *pci_dev, | |||
333 | 339 | ||
334 | return 0; | 340 | return 0; |
335 | 341 | ||
336 | fail4: | 342 | fail5: |
337 | video_unregister_device(&dev->vdev); | 343 | video_unregister_device(&dev->vdev); |
344 | fail4: | ||
345 | vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); | ||
338 | fail3: | 346 | fail3: |
339 | iounmap(dev->lmmio); | 347 | iounmap(dev->lmmio); |
340 | fail2: | 348 | fail2: |
@@ -358,6 +366,7 @@ static void tw68_finidev(struct pci_dev *pci_dev) | |||
358 | /* unregister */ | 366 | /* unregister */ |
359 | video_unregister_device(&dev->vdev); | 367 | video_unregister_device(&dev->vdev); |
360 | v4l2_ctrl_handler_free(&dev->hdl); | 368 | v4l2_ctrl_handler_free(&dev->hdl); |
369 | vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); | ||
361 | 370 | ||
362 | /* release resources */ | 371 | /* release resources */ |
363 | iounmap(dev->lmmio); | 372 | iounmap(dev->lmmio); |
diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c index 5c94ac7c88d9..50dcce6251f6 100644 --- a/drivers/media/pci/tw68/tw68-video.c +++ b/drivers/media/pci/tw68/tw68-video.c | |||
@@ -384,6 +384,7 @@ static int tw68_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, | |||
384 | unsigned tot_bufs = q->num_buffers + *num_buffers; | 384 | unsigned tot_bufs = q->num_buffers + *num_buffers; |
385 | 385 | ||
386 | sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3; | 386 | sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3; |
387 | alloc_ctxs[0] = dev->alloc_ctx; | ||
387 | /* | 388 | /* |
388 | * We allow create_bufs, but only if the sizeimage is the same as the | 389 | * We allow create_bufs, but only if the sizeimage is the same as the |
389 | * current sizeimage. The tw68_buffer_count calculation becomes quite | 390 | * current sizeimage. The tw68_buffer_count calculation becomes quite |
diff --git a/drivers/media/pci/tw68/tw68.h b/drivers/media/pci/tw68/tw68.h index 2c8abe26b13b..7a7501bd165f 100644 --- a/drivers/media/pci/tw68/tw68.h +++ b/drivers/media/pci/tw68/tw68.h | |||
@@ -181,6 +181,7 @@ struct tw68_dev { | |||
181 | unsigned field; | 181 | unsigned field; |
182 | struct vb2_queue vidq; | 182 | struct vb2_queue vidq; |
183 | struct list_head active; | 183 | struct list_head active; |
184 | void *alloc_ctx; | ||
184 | 185 | ||
185 | /* various v4l controls */ | 186 | /* various v4l controls */ |
186 | const struct tw68_tvnorm *tvnorm; /* video */ | 187 | const struct tw68_tvnorm *tvnorm; /* video */ |
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c index f0eeb6cd262c..c3ff5388aeb3 100644 --- a/drivers/media/platform/marvell-ccic/mcam-core.c +++ b/drivers/media/platform/marvell-ccic/mcam-core.c | |||
@@ -1079,6 +1079,8 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq, | |||
1079 | *nbufs = minbufs; | 1079 | *nbufs = minbufs; |
1080 | if (cam->buffer_mode == B_DMA_contig) | 1080 | if (cam->buffer_mode == B_DMA_contig) |
1081 | alloc_ctxs[0] = cam->vb_alloc_ctx; | 1081 | alloc_ctxs[0] = cam->vb_alloc_ctx; |
1082 | else if (cam->buffer_mode == B_DMA_sg) | ||
1083 | alloc_ctxs[0] = cam->vb_alloc_ctx_sg; | ||
1082 | return 0; | 1084 | return 0; |
1083 | } | 1085 | } |
1084 | 1086 | ||
@@ -1286,10 +1288,12 @@ static int mcam_setup_vb2(struct mcam_camera *cam) | |||
1286 | vq->ops = &mcam_vb2_ops; | 1288 | vq->ops = &mcam_vb2_ops; |
1287 | vq->mem_ops = &vb2_dma_contig_memops; | 1289 | vq->mem_ops = &vb2_dma_contig_memops; |
1288 | vq->buf_struct_size = sizeof(struct mcam_vb_buffer); | 1290 | vq->buf_struct_size = sizeof(struct mcam_vb_buffer); |
1289 | cam->vb_alloc_ctx = vb2_dma_contig_init_ctx(cam->dev); | ||
1290 | vq->io_modes = VB2_MMAP | VB2_USERPTR; | 1291 | vq->io_modes = VB2_MMAP | VB2_USERPTR; |
1291 | cam->dma_setup = mcam_ctlr_dma_contig; | 1292 | cam->dma_setup = mcam_ctlr_dma_contig; |
1292 | cam->frame_complete = mcam_dma_contig_done; | 1293 | cam->frame_complete = mcam_dma_contig_done; |
1294 | cam->vb_alloc_ctx = vb2_dma_contig_init_ctx(cam->dev); | ||
1295 | if (IS_ERR(cam->vb_alloc_ctx)) | ||
1296 | return PTR_ERR(cam->vb_alloc_ctx); | ||
1293 | #endif | 1297 | #endif |
1294 | break; | 1298 | break; |
1295 | case B_DMA_sg: | 1299 | case B_DMA_sg: |
@@ -1300,6 +1304,9 @@ static int mcam_setup_vb2(struct mcam_camera *cam) | |||
1300 | vq->io_modes = VB2_MMAP | VB2_USERPTR; | 1304 | vq->io_modes = VB2_MMAP | VB2_USERPTR; |
1301 | cam->dma_setup = mcam_ctlr_dma_sg; | 1305 | cam->dma_setup = mcam_ctlr_dma_sg; |
1302 | cam->frame_complete = mcam_dma_sg_done; | 1306 | cam->frame_complete = mcam_dma_sg_done; |
1307 | cam->vb_alloc_ctx_sg = vb2_dma_sg_init_ctx(cam->dev); | ||
1308 | if (IS_ERR(cam->vb_alloc_ctx_sg)) | ||
1309 | return PTR_ERR(cam->vb_alloc_ctx_sg); | ||
1303 | #endif | 1310 | #endif |
1304 | break; | 1311 | break; |
1305 | case B_vmalloc: | 1312 | case B_vmalloc: |
@@ -1325,6 +1332,10 @@ static void mcam_cleanup_vb2(struct mcam_camera *cam) | |||
1325 | if (cam->buffer_mode == B_DMA_contig) | 1332 | if (cam->buffer_mode == B_DMA_contig) |
1326 | vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx); | 1333 | vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx); |
1327 | #endif | 1334 | #endif |
1335 | #ifdef MCAM_MODE_DMA_SG | ||
1336 | if (cam->buffer_mode == B_DMA_sg) | ||
1337 | vb2_dma_sg_cleanup_ctx(cam->vb_alloc_ctx_sg); | ||
1338 | #endif | ||
1328 | } | 1339 | } |
1329 | 1340 | ||
1330 | 1341 | ||
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h index 60a8e1cfeff7..aa0c6eac254a 100644 --- a/drivers/media/platform/marvell-ccic/mcam-core.h +++ b/drivers/media/platform/marvell-ccic/mcam-core.h | |||
@@ -176,6 +176,7 @@ struct mcam_camera { | |||
176 | /* DMA buffers - DMA modes */ | 176 | /* DMA buffers - DMA modes */ |
177 | struct mcam_vb_buffer *vb_bufs[MAX_DMA_BUFS]; | 177 | struct mcam_vb_buffer *vb_bufs[MAX_DMA_BUFS]; |
178 | struct vb2_alloc_ctx *vb_alloc_ctx; | 178 | struct vb2_alloc_ctx *vb_alloc_ctx; |
179 | struct vb2_alloc_ctx *vb_alloc_ctx_sg; | ||
179 | 180 | ||
180 | /* Mode-specific ops, set at open time */ | 181 | /* Mode-specific ops, set at open time */ |
181 | void (*dma_setup)(struct mcam_camera *cam); | 182 | void (*dma_setup)(struct mcam_camera *cam); |
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c index 2529b831725b..2bf13dc4df34 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c | |||
@@ -30,7 +30,12 @@ module_param(debug, int, 0644); | |||
30 | printk(KERN_DEBUG "vb2-dma-sg: " fmt, ## arg); \ | 30 | printk(KERN_DEBUG "vb2-dma-sg: " fmt, ## arg); \ |
31 | } while (0) | 31 | } while (0) |
32 | 32 | ||
33 | struct vb2_dma_sg_conf { | ||
34 | struct device *dev; | ||
35 | }; | ||
36 | |||
33 | struct vb2_dma_sg_buf { | 37 | struct vb2_dma_sg_buf { |
38 | struct device *dev; | ||
34 | void *vaddr; | 39 | void *vaddr; |
35 | struct page **pages; | 40 | struct page **pages; |
36 | int offset; | 41 | int offset; |
@@ -89,10 +94,13 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, | |||
89 | static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, | 94 | static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, |
90 | enum dma_data_direction dma_dir, gfp_t gfp_flags) | 95 | enum dma_data_direction dma_dir, gfp_t gfp_flags) |
91 | { | 96 | { |
97 | struct vb2_dma_sg_conf *conf = alloc_ctx; | ||
92 | struct vb2_dma_sg_buf *buf; | 98 | struct vb2_dma_sg_buf *buf; |
93 | int ret; | 99 | int ret; |
94 | int num_pages; | 100 | int num_pages; |
95 | 101 | ||
102 | if (WARN_ON(alloc_ctx == NULL)) | ||
103 | return NULL; | ||
96 | buf = kzalloc(sizeof *buf, GFP_KERNEL); | 104 | buf = kzalloc(sizeof *buf, GFP_KERNEL); |
97 | if (!buf) | 105 | if (!buf) |
98 | return NULL; | 106 | return NULL; |
@@ -118,6 +126,8 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, | |||
118 | if (ret) | 126 | if (ret) |
119 | goto fail_table_alloc; | 127 | goto fail_table_alloc; |
120 | 128 | ||
129 | /* Prevent the device from being released while the buffer is used */ | ||
130 | buf->dev = get_device(conf->dev); | ||
121 | buf->handler.refcount = &buf->refcount; | 131 | buf->handler.refcount = &buf->refcount; |
122 | buf->handler.put = vb2_dma_sg_put; | 132 | buf->handler.put = vb2_dma_sg_put; |
123 | buf->handler.arg = buf; | 133 | buf->handler.arg = buf; |
@@ -153,6 +163,7 @@ static void vb2_dma_sg_put(void *buf_priv) | |||
153 | while (--i >= 0) | 163 | while (--i >= 0) |
154 | __free_page(buf->pages[i]); | 164 | __free_page(buf->pages[i]); |
155 | kfree(buf->pages); | 165 | kfree(buf->pages); |
166 | put_device(buf->dev); | ||
156 | kfree(buf); | 167 | kfree(buf); |
157 | } | 168 | } |
158 | } | 169 | } |
@@ -356,6 +367,27 @@ const struct vb2_mem_ops vb2_dma_sg_memops = { | |||
356 | }; | 367 | }; |
357 | EXPORT_SYMBOL_GPL(vb2_dma_sg_memops); | 368 | EXPORT_SYMBOL_GPL(vb2_dma_sg_memops); |
358 | 369 | ||
370 | void *vb2_dma_sg_init_ctx(struct device *dev) | ||
371 | { | ||
372 | struct vb2_dma_sg_conf *conf; | ||
373 | |||
374 | conf = kzalloc(sizeof(*conf), GFP_KERNEL); | ||
375 | if (!conf) | ||
376 | return ERR_PTR(-ENOMEM); | ||
377 | |||
378 | conf->dev = dev; | ||
379 | |||
380 | return conf; | ||
381 | } | ||
382 | EXPORT_SYMBOL_GPL(vb2_dma_sg_init_ctx); | ||
383 | |||
384 | void vb2_dma_sg_cleanup_ctx(void *alloc_ctx) | ||
385 | { | ||
386 | if (!IS_ERR_OR_NULL(alloc_ctx)) | ||
387 | kfree(alloc_ctx); | ||
388 | } | ||
389 | EXPORT_SYMBOL_GPL(vb2_dma_sg_cleanup_ctx); | ||
390 | |||
359 | MODULE_DESCRIPTION("dma scatter/gather memory handling routines for videobuf2"); | 391 | MODULE_DESCRIPTION("dma scatter/gather memory handling routines for videobuf2"); |
360 | MODULE_AUTHOR("Andrzej Pietrasiewicz"); | 392 | MODULE_AUTHOR("Andrzej Pietrasiewicz"); |
361 | MODULE_LICENSE("GPL"); | 393 | MODULE_LICENSE("GPL"); |