Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media/platform: convert drivers to use the new vb2_queue dev field

Stop using alloc_ctx and just fill in the device pointer.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Mikhail Ulyanov <mikhail.ulyanov@cogentembedded.com>
Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
1ad70ced dce57314

+17 -107
+2 -13
drivers/media/platform/m2m-deinterlace.c
··· 136 136 struct dma_chan *dma_chan; 137 137 138 138 struct v4l2_m2m_dev *m2m_dev; 139 - struct vb2_alloc_ctx *alloc_ctx; 140 139 }; 141 140 142 141 struct deinterlace_ctx { ··· 819 820 *nbuffers = count; 820 821 sizes[0] = size; 821 822 822 - alloc_ctxs[0] = ctx->dev->alloc_ctx; 823 - 824 823 dprintk(ctx->dev, "get %d buffer(s) of size %d each.\n", count, size); 825 824 826 825 return 0; ··· 871 874 src_vq->ops = &deinterlace_qops; 872 875 src_vq->mem_ops = &vb2_dma_contig_memops; 873 876 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 877 + src_vq->dev = ctx->dev->v4l2_dev.dev; 874 878 q_data[V4L2_M2M_SRC].fmt = &formats[0]; 875 879 q_data[V4L2_M2M_SRC].width = 640; 876 880 q_data[V4L2_M2M_SRC].height = 480; ··· 889 891 dst_vq->ops = &deinterlace_qops; 890 892 dst_vq->mem_ops = &vb2_dma_contig_memops; 891 893 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 894 + dst_vq->dev = ctx->dev->v4l2_dev.dev; 892 895 q_data[V4L2_M2M_DST].fmt = &formats[0]; 893 896 q_data[V4L2_M2M_DST].width = 640; 894 897 q_data[V4L2_M2M_DST].height = 480; ··· 1045 1046 1046 1047 platform_set_drvdata(pdev, pcdev); 1047 1048 1048 - pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1049 - if (IS_ERR(pcdev->alloc_ctx)) { 1050 - v4l2_err(&pcdev->v4l2_dev, "Failed to alloc vb2 context\n"); 1051 - ret = PTR_ERR(pcdev->alloc_ctx); 1052 - goto err_ctx; 1053 - } 1054 - 1055 1049 pcdev->m2m_dev = v4l2_m2m_init(&m2m_ops); 1056 1050 if (IS_ERR(pcdev->m2m_dev)) { 1057 1051 v4l2_err(&pcdev->v4l2_dev, "Failed to init mem2mem device\n"); ··· 1056 1064 1057 1065 err_m2m: 1058 1066 video_unregister_device(&pcdev->vfd); 1059 - err_ctx: 1060 - vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 1061 1067 unreg_dev: 1062 1068 v4l2_device_unregister(&pcdev->v4l2_dev); 1063 1069 rel_dma: ··· 1072 1082 v4l2_m2m_release(pcdev->m2m_dev); 1073 1083 video_unregister_device(&pcdev->vfd); 1074 1084 v4l2_device_unregister(&pcdev->v4l2_dev); 1075 - vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 1076 1085 dma_release_channel(pcdev->dma_chan); 1077 1086 1078 1087 return 0;
+1 -23
drivers/media/platform/marvell-ccic/mcam-core.c
··· 1059 1059 1060 1060 if (*nbufs < minbufs) 1061 1061 *nbufs = minbufs; 1062 - if (cam->buffer_mode == B_DMA_contig) 1063 - alloc_ctxs[0] = cam->vb_alloc_ctx; 1064 - else if (cam->buffer_mode == B_DMA_sg) 1065 - alloc_ctxs[0] = cam->vb_alloc_ctx_sg; 1066 1062 1067 1063 if (*num_planes) 1068 1064 return sizes[0] < size ? -EINVAL : 0; ··· 1267 1271 vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1268 1272 vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; 1269 1273 vq->buf_struct_size = sizeof(struct mcam_vb_buffer); 1274 + vq->dev = cam->dev; 1270 1275 INIT_LIST_HEAD(&cam->buffers); 1271 1276 switch (cam->buffer_mode) { 1272 1277 case B_DMA_contig: ··· 1276 1279 vq->mem_ops = &vb2_dma_contig_memops; 1277 1280 cam->dma_setup = mcam_ctlr_dma_contig; 1278 1281 cam->frame_complete = mcam_dma_contig_done; 1279 - cam->vb_alloc_ctx = vb2_dma_contig_init_ctx(cam->dev); 1280 - if (IS_ERR(cam->vb_alloc_ctx)) 1281 - return PTR_ERR(cam->vb_alloc_ctx); 1282 1282 #endif 1283 1283 break; 1284 1284 case B_DMA_sg: ··· 1284 1290 vq->mem_ops = &vb2_dma_sg_memops; 1285 1291 cam->dma_setup = mcam_ctlr_dma_sg; 1286 1292 cam->frame_complete = mcam_dma_sg_done; 1287 - cam->vb_alloc_ctx_sg = vb2_dma_sg_init_ctx(cam->dev); 1288 - if (IS_ERR(cam->vb_alloc_ctx_sg)) 1289 - return PTR_ERR(cam->vb_alloc_ctx_sg); 1290 1293 #endif 1291 1294 break; 1292 1295 case B_vmalloc: ··· 1298 1307 break; 1299 1308 } 1300 1309 return vb2_queue_init(vq); 1301 - } 1302 - 1303 - static void mcam_cleanup_vb2(struct mcam_camera *cam) 1304 - { 1305 - #ifdef MCAM_MODE_DMA_CONTIG 1306 - if (cam->buffer_mode == B_DMA_contig) 1307 - vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx); 1308 - #endif 1309 - #ifdef MCAM_MODE_DMA_SG 1310 - if (cam->buffer_mode == B_DMA_sg) 1311 - vb2_dma_sg_cleanup_ctx(cam->vb_alloc_ctx_sg); 1312 - #endif 1313 1310 } 1314 1311 1315 1312 ··· 1854 1875 cam_warn(cam, "Removing a device with users!\n"); 1855 1876 mcam_ctlr_power_down(cam); 1856 1877 } 1857 - mcam_cleanup_vb2(cam); 1858 1878 if (cam->buffer_mode == B_vmalloc) 1859 1879 mcam_free_dma_bufs(cam); 1860 1880 video_unregister_device(&cam->vdev);
-2
drivers/media/platform/marvell-ccic/mcam-core.h
··· 176 176 177 177 /* DMA buffers - DMA modes */ 178 178 struct mcam_vb_buffer *vb_bufs[MAX_DMA_BUFS]; 179 - struct vb2_alloc_ctx *vb_alloc_ctx; 180 - struct vb2_alloc_ctx *vb_alloc_ctx_sg; 181 179 182 180 /* Mode-specific ops, set at open time */ 183 181 void (*dma_setup)(struct mcam_camera *cam);
+3 -14
drivers/media/platform/mx2_emmaprp.c
··· 211 211 struct clk *clk_emma_ahb, *clk_emma_ipg; 212 212 213 213 struct v4l2_m2m_dev *m2m_dev; 214 - struct vb2_alloc_ctx *alloc_ctx; 215 214 }; 216 215 217 216 struct emmaprp_ctx { ··· 709 710 *nbuffers = count; 710 711 sizes[0] = size; 711 712 712 - alloc_ctxs[0] = ctx->dev->alloc_ctx; 713 - 714 713 dprintk(ctx->dev, "get %d buffer(s) of size %d each.\n", count, size); 715 714 716 715 return 0; ··· 762 765 src_vq->ops = &emmaprp_qops; 763 766 src_vq->mem_ops = &vb2_dma_contig_memops; 764 767 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 768 + src_vq->dev = ctx->dev->v4l2_dev.dev; 765 769 766 770 ret = vb2_queue_init(src_vq); 767 771 if (ret) ··· 775 777 dst_vq->ops = &emmaprp_qops; 776 778 dst_vq->mem_ops = &vb2_dma_contig_memops; 777 779 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 780 + dst_vq->dev = ctx->dev->v4l2_dev.dev; 778 781 779 782 return vb2_queue_init(dst_vq); 780 783 } ··· 947 948 if (ret) 948 949 goto rel_vdev; 949 950 950 - pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 951 - if (IS_ERR(pcdev->alloc_ctx)) { 952 - v4l2_err(&pcdev->v4l2_dev, "Failed to alloc vb2 context\n"); 953 - ret = PTR_ERR(pcdev->alloc_ctx); 954 - goto rel_vdev; 955 - } 956 - 957 951 pcdev->m2m_dev = v4l2_m2m_init(&m2m_ops); 958 952 if (IS_ERR(pcdev->m2m_dev)) { 959 953 v4l2_err(&pcdev->v4l2_dev, "Failed to init mem2mem device\n"); 960 954 ret = PTR_ERR(pcdev->m2m_dev); 961 - goto rel_ctx; 955 + goto rel_vdev; 962 956 } 963 957 964 958 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); ··· 965 973 966 974 rel_m2m: 967 975 v4l2_m2m_release(pcdev->m2m_dev); 968 - rel_ctx: 969 - vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 970 976 rel_vdev: 971 977 video_device_release(vfd); 972 978 unreg_dev: ··· 983 993 984 994 video_unregister_device(pcdev->vfd); 985 995 v4l2_m2m_release(pcdev->m2m_dev); 986 - vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 987 996 v4l2_device_unregister(&pcdev->v4l2_dev); 988 997 mutex_destroy(&pcdev->dev_mutex); 989 998
+2 -10
drivers/media/platform/omap3isp/ispvideo.c
··· 342 342 if (sizes[0] == 0) 343 343 return -EINVAL; 344 344 345 - alloc_ctxs[0] = video->alloc_ctx; 346 - 347 345 *count = min(*count, video->capture_mem / PAGE_ALIGN(sizes[0])); 348 346 349 347 return 0; ··· 1306 1308 queue->mem_ops = &vb2_dma_contig_memops; 1307 1309 queue->buf_struct_size = sizeof(struct isp_buffer); 1308 1310 queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1311 + queue->dev = video->isp->dev; 1309 1312 1310 1313 ret = vb2_queue_init(&handle->queue); 1311 1314 if (ret < 0) { ··· 1413 1414 return -EINVAL; 1414 1415 } 1415 1416 1416 - video->alloc_ctx = vb2_dma_contig_init_ctx(video->isp->dev); 1417 - if (IS_ERR(video->alloc_ctx)) 1418 - return PTR_ERR(video->alloc_ctx); 1419 - 1420 1417 ret = media_entity_pads_init(&video->video.entity, 1, &video->pad); 1421 - if (ret < 0) { 1422 - vb2_dma_contig_cleanup_ctx(video->alloc_ctx); 1418 + if (ret < 0) 1423 1419 return ret; 1424 - } 1425 1420 1426 1421 mutex_init(&video->mutex); 1427 1422 atomic_set(&video->active, 0); ··· 1444 1451 1445 1452 void omap3isp_video_cleanup(struct isp_video *video) 1446 1453 { 1447 - vb2_dma_contig_cleanup_ctx(video->alloc_ctx); 1448 1454 media_entity_cleanup(&video->video.entity); 1449 1455 mutex_destroy(&video->queue_lock); 1450 1456 mutex_destroy(&video->stream_lock);
-1
drivers/media/platform/omap3isp/ispvideo.h
··· 171 171 bool error; 172 172 173 173 /* Video buffers queue */ 174 - void *alloc_ctx; 175 174 struct vb2_queue *queue; 176 175 struct mutex queue_lock; /* protects the queue */ 177 176 spinlock_t irqlock; /* protects dmaqueue */
+4 -18
drivers/media/platform/rcar_jpu.c
··· 203 203 * @irq: JPEG IP irq 204 204 * @clk: JPEG IP clock 205 205 * @dev: JPEG IP struct device 206 - * @alloc_ctx: videobuf2 memory allocator's context 207 206 * @ref_count: reference counter 208 207 */ 209 208 struct jpu { ··· 219 220 unsigned int irq; 220 221 struct clk *clk; 221 222 struct device *dev; 222 - void *alloc_ctx; 223 223 int ref_count; 224 224 }; 225 225 ··· 1031 1033 1032 1034 if (sizes[i] < q_size) 1033 1035 return -EINVAL; 1034 - alloc_ctxs[i] = ctx->jpu->alloc_ctx; 1035 1036 } 1036 1037 return 0; 1037 1038 } 1038 1039 1039 1040 *nplanes = q_data->format.num_planes; 1040 1041 1041 - for (i = 0; i < *nplanes; i++) { 1042 + for (i = 0; i < *nplanes; i++) 1042 1043 sizes[i] = q_data->format.plane_fmt[i].sizeimage; 1043 - alloc_ctxs[i] = ctx->jpu->alloc_ctx; 1044 - } 1045 1044 1046 1045 return 0; 1047 1046 } ··· 1209 1214 src_vq->mem_ops = &vb2_dma_contig_memops; 1210 1215 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1211 1216 src_vq->lock = &ctx->jpu->mutex; 1217 + src_vq->dev = ctx->jpu->v4l2_dev.dev; 1212 1218 1213 1219 ret = vb2_queue_init(src_vq); 1214 1220 if (ret) ··· 1224 1228 dst_vq->mem_ops = &vb2_dma_contig_memops; 1225 1229 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1226 1230 dst_vq->lock = &ctx->jpu->mutex; 1231 + dst_vq->dev = ctx->jpu->v4l2_dev.dev; 1227 1232 1228 1233 return vb2_queue_init(dst_vq); 1229 1234 } ··· 1673 1676 goto device_register_rollback; 1674 1677 } 1675 1678 1676 - jpu->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1677 - if (IS_ERR(jpu->alloc_ctx)) { 1678 - v4l2_err(&jpu->v4l2_dev, "Failed to init memory allocator\n"); 1679 - ret = PTR_ERR(jpu->alloc_ctx); 1680 - goto m2m_init_rollback; 1681 - } 1682 - 1683 1679 /* fill in qantization and Huffman tables for encoder */ 1684 1680 for (i = 0; i < JPU_MAX_QUALITY; i++) 1685 1681 jpu_generate_hdr(i, (unsigned char *)jpeg_hdrs[i]); ··· 1689 1699 ret = video_register_device(&jpu->vfd_encoder, VFL_TYPE_GRABBER, -1); 1690 1700 if (ret) { 1691 1701 v4l2_err(&jpu->v4l2_dev, "Failed to register video device\n"); 1692 - goto vb2_allocator_rollback; 1702 + goto m2m_init_rollback; 1693 1703 } 1694 1704 1695 1705 video_set_drvdata(&jpu->vfd_encoder, jpu); ··· 1722 1732 enc_vdev_register_rollback: 1723 1733 video_unregister_device(&jpu->vfd_encoder); 1724 1734 1725 - vb2_allocator_rollback: 1726 - vb2_dma_contig_cleanup_ctx(jpu->alloc_ctx); 1727 - 1728 1735 m2m_init_rollback: 1729 1736 v4l2_m2m_release(jpu->m2m_dev); 1730 1737 ··· 1737 1750 1738 1751 video_unregister_device(&jpu->vfd_decoder); 1739 1752 video_unregister_device(&jpu->vfd_encoder); 1740 - vb2_dma_contig_cleanup_ctx(jpu->alloc_ctx); 1741 1753 v4l2_m2m_release(jpu->m2m_dev); 1742 1754 v4l2_device_unregister(&jpu->v4l2_dev); 1743 1755
+3 -14
drivers/media/platform/sh_veu.c
··· 118 118 struct sh_veu_file *output; 119 119 struct mutex fop_lock; 120 120 void __iomem *base; 121 - struct vb2_alloc_ctx *alloc_ctx; 122 121 spinlock_t lock; 123 122 bool is_2h; 124 123 unsigned int xaction; ··· 881 882 *nbuffers = count; 882 883 } 883 884 884 - if (*nplanes) { 885 - alloc_ctxs[0] = veu->alloc_ctx; 885 + if (*nplanes) 886 886 return sizes[0] < size ? -EINVAL : 0; 887 - } 888 887 889 888 *nplanes = 1; 890 889 sizes[0] = size; 891 - alloc_ctxs[0] = veu->alloc_ctx; 892 890 893 891 dev_dbg(veu->dev, "get %d buffer(s) of size %d each.\n", count, size); 894 892 ··· 944 948 src_vq->mem_ops = &vb2_dma_contig_memops; 945 949 src_vq->lock = &veu->fop_lock; 946 950 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 951 + src_vq->dev = veu->v4l2_dev.dev; 947 952 948 953 ret = vb2_queue_init(src_vq); 949 954 if (ret < 0) ··· 959 962 dst_vq->mem_ops = &vb2_dma_contig_memops; 960 963 dst_vq->lock = &veu->fop_lock; 961 964 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 965 + dst_vq->dev = veu->v4l2_dev.dev; 962 966 963 967 return vb2_queue_init(dst_vq); 964 968 } ··· 1146 1148 1147 1149 vdev = &veu->vdev; 1148 1150 1149 - veu->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1150 - if (IS_ERR(veu->alloc_ctx)) { 1151 - ret = PTR_ERR(veu->alloc_ctx); 1152 - goto einitctx; 1153 - } 1154 - 1155 1151 *vdev = sh_veu_videodev; 1156 1152 vdev->v4l2_dev = &veu->v4l2_dev; 1157 1153 spin_lock_init(&veu->lock); ··· 1179 1187 pm_runtime_disable(&pdev->dev); 1180 1188 v4l2_m2m_release(veu->m2m_dev); 1181 1189 em2minit: 1182 - vb2_dma_contig_cleanup_ctx(veu->alloc_ctx); 1183 - einitctx: 1184 1190 v4l2_device_unregister(&veu->v4l2_dev); 1185 1191 return ret; 1186 1192 } ··· 1192 1202 video_unregister_device(&veu->vdev); 1193 1203 pm_runtime_disable(&pdev->dev); 1194 1204 v4l2_m2m_release(veu->m2m_dev); 1195 - vb2_dma_contig_cleanup_ctx(veu->alloc_ctx); 1196 1205 v4l2_device_unregister(&veu->v4l2_dev); 1197 1206 1198 1207 return 0;
+2 -12
drivers/media/platform/sh_vou.c
··· 86 86 v4l2_std_id std; 87 87 int pix_idx; 88 88 struct vb2_queue queue; 89 - struct vb2_alloc_ctx *alloc_ctx; 90 89 struct sh_vou_buffer *active; 91 90 enum sh_vou_status status; 92 91 unsigned sequence; ··· 252 253 253 254 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 254 255 255 - alloc_ctxs[0] = vou_dev->alloc_ctx; 256 256 if (*nplanes) 257 257 return sizes[0] < pix->height * bytes_per_line ? -EINVAL : 0; 258 258 *nplanes = 1; ··· 1302 1304 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1303 1305 q->min_buffers_needed = 2; 1304 1306 q->lock = &vou_dev->fop_lock; 1307 + q->dev = &pdev->dev; 1305 1308 ret = vb2_queue_init(q); 1306 1309 if (ret) 1307 - goto einitctx; 1310 + goto ei2cgadap; 1308 1311 1309 - vou_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1310 - if (IS_ERR(vou_dev->alloc_ctx)) { 1311 - dev_err(&pdev->dev, "Can't allocate buffer context"); 1312 - ret = PTR_ERR(vou_dev->alloc_ctx); 1313 - goto einitctx; 1314 - } 1315 1312 vdev->queue = q; 1316 1313 INIT_LIST_HEAD(&vou_dev->buf_list); 1317 1314 ··· 1341 1348 ereset: 1342 1349 i2c_put_adapter(i2c_adap); 1343 1350 ei2cgadap: 1344 - vb2_dma_contig_cleanup_ctx(vou_dev->alloc_ctx); 1345 - einitctx: 1346 1351 pm_runtime_disable(&pdev->dev); 1347 1352 v4l2_device_unregister(&vou_dev->v4l2_dev); 1348 1353 return ret; ··· 1358 1367 pm_runtime_disable(&pdev->dev); 1359 1368 video_unregister_device(&vou_dev->vdev); 1360 1369 i2c_put_adapter(client->adapter); 1361 - vb2_dma_contig_cleanup_ctx(vou_dev->alloc_ctx); 1362 1370 v4l2_device_unregister(&vou_dev->v4l2_dev); 1363 1371 return 0; 1364 1372 }