int uvc_request_buffers(struct uvc_video_queue *queue, struct v4l2_requestbuffers *rb) { int ret; mutex_lock(&queue->mutex); ret = vb2_reqbufs(&queue->queue, rb); mutex_unlock(&queue->mutex); return ret ? ret : rb->count; }
static int fimc_lite_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *reqbufs) { struct fimc_lite *fimc = video_drvdata(file); int ret; reqbufs->count = max_t(u32, FLITE_REQ_BUFS_MIN, reqbufs->count); ret = vb2_reqbufs(&fimc->vb_queue, reqbufs); if (!ret) fimc->reqbufs_count = reqbufs->count; return ret; }
/** * __vb2_cleanup_fileio() - free resourced used by file io emulator * @q: videobuf2 queue */ static int __vb2_cleanup_fileio(struct vb2_queue *q) { struct vb2_fileio_data *fileio = q->fileio; if (fileio) { vb2_core_streamoff(q, q->type); q->fileio = NULL; fileio->req.count = 0; vb2_reqbufs(q, &fileio->req); kfree(fileio); dprintk(3, "file io emulator closed\n"); } return 0; }
static int fimc_cap_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *reqbufs) { struct fimc_ctx *ctx = priv; struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap; int ret; ret = vb2_reqbufs(&cap->vbq, reqbufs); if (!ret) cap->reqbufs_count = reqbufs->count; return ret; }
int fimc_is_video_reqbufs(struct file *file, struct fimc_is_video_ctx *vctx, struct v4l2_requestbuffers *request) { int ret = 0; struct fimc_is_framemgr *framemgr; struct fimc_is_queue *queue; BUG_ON(!vctx); BUG_ON(!request); queue = GET_VCTX_QUEUE(vctx, request); if (test_bit(FIMC_IS_QUEUE_STREAM_ON, &queue->state)) { err("video is stream on, not applied"); ret = -EINVAL; goto p_err; } ret = vb2_reqbufs(queue->vbq, request); if (ret) { err("vb2_reqbufs is fail(%d)", ret); goto p_err; } framemgr = &queue->framemgr; queue->buf_maxcount = request->count; if (queue->buf_maxcount == 0) { queue->buf_refcount = 0; clear_bit(FIMC_IS_QUEUE_BUFFER_READY, &queue->state); clear_bit(FIMC_IS_QUEUE_BUFFER_PREPARED, &queue->state); fimc_is_frame_close(framemgr); } else { if (queue->buf_maxcount < queue->buf_rdycount) { err("buffer count is not invalid(%d < %d)", queue->buf_maxcount, queue->buf_rdycount); ret = -EINVAL; goto p_err; } if (!queue->buf_rdycount) set_bit(FIMC_IS_QUEUE_BUFFER_READY, &queue->state); fimc_is_frame_open(framemgr, queue->buf_maxcount); } p_err: return ret; }
int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, struct v4l2_requestbuffers *reqbufs) { struct vb2_queue *vq; int ret; vq = v4l2_m2m_get_vq(m2m_ctx, reqbufs->type); ret = vb2_reqbufs(vq, reqbufs); /* If count == 0, then the owner has released all buffers and he is no longer owner of the queue. Otherwise we have an owner. */ if (ret == 0) vq->owner = reqbufs->count ? file->private_data : NULL; return ret; }
static int at91sam9x5_video_vidioc_reqbufs(struct file *filp, void *fh, struct v4l2_requestbuffers *b) { struct video_device *vdev = filp->private_data; struct at91sam9x5_video_priv *priv = video_get_drvdata(vdev); struct vb2_queue *q = &priv->queue; if (b->type != q->type) { dev_err(&priv->pdev->dev, "invalid buffer type (%d != %d)\n", b->type, q->type); return -EINVAL; } return vb2_reqbufs(q, b); }
static int camera_v4l2_reqbufs(struct file *filep, void *fh, struct v4l2_requestbuffers *req) { int ret; struct msm_session *session; struct camera_v4l2_private *sp = fh_to_private(fh); struct msm_video_device *pvdev = video_drvdata(filep); unsigned int session_id = pvdev->vdev->num; session = msm_session_find(session_id); if (WARN_ON(!session)) return -EIO; mutex_lock(&session->lock); ret = vb2_reqbufs(&sp->vb2_q, req); mutex_unlock(&session->lock); return ret; }
static int gsc_capture_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *reqbufs) { struct gsc_dev *gsc = video_drvdata(file); struct gsc_capture_device *cap = &gsc->cap; struct gsc_frame *frame; int ret; frame = ctx_get_frame(cap->ctx, reqbufs->type); ret = vb2_reqbufs(&cap->vbq, reqbufs); if (!ret) cap->reqbufs_cnt = reqbufs->count; return ret; }
static int fimc_is_isp_video_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *buf) { struct fimc_is_dev *is_dev = video_drvdata(file); struct fimc_is_video_dev *video = file->private_data; int ret; ret = vb2_reqbufs(&video->vbq, buf); if (!ret) is_dev->video[FIMC_IS_VIDEO_NUM_BAYER].num_buf = buf->count; if (buf->count == 0) is_dev->video[FIMC_IS_VIDEO_NUM_BAYER].buf_ref_cnt = 0; printk(KERN_INFO "%s(num_buf : %d)\n", __func__, is_dev->video[FIMC_IS_VIDEO_NUM_BAYER].num_buf); return ret; }
/** * __vb2_cleanup_fileio() - free resourced used by file io emulator * @q: videobuf2 queue */ static int __vb2_cleanup_fileio(struct vb2_queue *q) { struct vb2_fileio_data *fileio = q->fileio; if (fileio) { /* * Hack fileio context to enable direct calls to vb2 ioctl * interface. */ q->fileio = NULL; vb2_streamoff(q, q->type); fileio->req.count = 0; vb2_reqbufs(q, &fileio->req); kfree(fileio); dprintk(3, "file io emulator closed\n"); } return 0; }
static int wfdioc_reqbufs(struct file *filp, void *fh, struct v4l2_requestbuffers *b) { int rc = 0; struct wfd_inst *inst = filp->private_data; unsigned long flags; int i; if (b->type != V4L2_CAP_VIDEO_CAPTURE || b->memory != V4L2_MEMORY_USERPTR) { WFD_MSG_ERR("Only V4L2_CAP_VIDEO_CAPTURE and " "V4L2_CAP_VIDEO_CAPTURE are supported\n"); return -EINVAL; } if (b->count < MIN_BUF_COUNT) b->count = MIN_BUF_COUNT; spin_lock_irqsave(&inst->inst_lock, flags); if (inst->minfo) { for (i = 0; i < inst->buf_count; ++i) kfree(inst->minfo[i]); } kfree(inst->minfo); inst->buf_count = b->count; inst->minfo = kzalloc(sizeof(struct mem_info *) * inst->buf_count, GFP_KERNEL); for (i = 0; i < inst->buf_count; ++i) inst->minfo[i] = kzalloc(sizeof(struct mem_info), GFP_KERNEL); spin_unlock_irqrestore(&inst->inst_lock, flags); rc = vb2_reqbufs(&inst->vid_bufq, b); if (rc) { WFD_MSG_ERR("Failed in videobuf_reqbufs, rc = %d\n", rc); spin_lock_irqsave(&inst->inst_lock, flags); if (inst->minfo) { for (i = 0; i < inst->buf_count; ++i) kfree(inst->minfo[i]); } kfree(inst->minfo); inst->minfo = NULL; spin_unlock_irqrestore(&inst->inst_lock, flags); } return rc; }
static int xvip_dma_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *rb) { struct v4l2_fh *vfh = file->private_data; struct xvip_dma *dma = to_xvip_dma(vfh->vdev); int ret; mutex_lock(&dma->lock); if (dma->queue.owner && dma->queue.owner != vfh) { ret = -EBUSY; goto done; } ret = vb2_reqbufs(&dma->queue, rb); if (ret < 0) goto done; dma->queue.owner = vfh; done: mutex_unlock(&dma->lock); return ret ? ret : rb->count; }
/** * __vb2_init_fileio() - initialize file io emulator * @q: videobuf2 queue * @read: mode selector (1 means read, 0 means write) */ static int __vb2_init_fileio(struct vb2_queue *q, int read) { struct vb2_fileio_data *fileio; int i, ret; unsigned int count = 0; /* * Sanity check */ if ((read && !(q->io_modes & VB2_READ)) || (!read && !(q->io_modes & VB2_WRITE))) BUG(); /* * Check if device supports mapping buffers to kernel virtual space. */ if (!q->mem_ops->vaddr) return -EBUSY; /* * Check if streaming api has not been already activated. */ if (q->streaming || q->num_buffers > 0) return -EBUSY; /* * Start with count 1, driver can increase it in queue_setup() */ count = 1; dprintk(3, "setting up file io: mode %s, count %d, flags %08x\n", (read) ? "read" : "write", count, q->io_flags); fileio = kzalloc(sizeof(struct vb2_fileio_data), GFP_KERNEL); if (fileio == NULL) return -ENOMEM; fileio->flags = q->io_flags; /* * Request buffers and use MMAP type to force driver * to allocate buffers by itself. */ fileio->req.count = count; fileio->req.memory = V4L2_MEMORY_MMAP; fileio->req.type = q->type; ret = vb2_reqbufs(q, &fileio->req); if (ret) goto err_kfree; /* * Check if plane_count is correct * (multiplane buffers are not supported). */ if (q->bufs[0]->num_planes != 1) { fileio->req.count = 0; ret = -EBUSY; goto err_reqbufs; } /* * Get kernel address of each buffer. */ for (i = 0; i < q->num_buffers; i++) { fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0); if (fileio->bufs[i].vaddr == NULL) goto err_reqbufs; fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0); } /* * Read mode requires pre queuing of all buffers. */ if (read) { /* * Queue all buffers. */ for (i = 0; i < q->num_buffers; i++) { struct v4l2_buffer *b = &fileio->b; memset(b, 0, sizeof(*b)); b->type = q->type; b->memory = q->memory; b->index = i; ret = vb2_qbuf(q, b); if (ret) goto err_reqbufs; fileio->bufs[i].queued = 1; } /* * Start streaming. */ ret = vb2_streamon(q, q->type); if (ret) goto err_reqbufs; } q->fileio = fileio; return ret; err_reqbufs: vb2_reqbufs(q, &fileio->req); err_kfree: kfree(fileio); return ret; }
int fimc_is_video_reqbufs(struct file *file, struct fimc_is_video_ctx *vctx, struct v4l2_requestbuffers *request) { int ret = 0; struct fimc_is_queue *queue; struct fimc_is_framemgr *framemgr; BUG_ON(!vctx); BUG_ON(!request); if (!(vctx->state & (BIT(FIMC_IS_VIDEO_S_FORMAT) | BIT(FIMC_IS_VIDEO_STOP) | BIT(FIMC_IS_VIDEO_S_BUFS)))) { err("[V%02d] invalid reqbufs is requested(%lX)", vctx->video->id, vctx->state); return -EINVAL; } queue = GET_QUEUE(vctx); if (test_bit(FIMC_IS_QUEUE_STREAM_ON, &queue->state)) { err("video is stream on, not applied"); ret = -EINVAL; goto p_err; } ret = CALL_QOPS(queue, request_bufs, GET_DEVICE(vctx), request->count); if (ret) { err("request_bufs is fail(%d)", ret); goto p_err; } ret = vb2_reqbufs(queue->vbq, request); if (ret) { err("vb2_reqbufs is fail(%d)", ret); goto p_err; } framemgr = &queue->framemgr; queue->buf_maxcount = request->count; if (queue->buf_maxcount == 0) { queue->buf_req = 0; queue->buf_pre = 0; queue->buf_que = 0; queue->buf_com = 0; queue->buf_dqe = 0; queue->buf_refcount = 0; clear_bit(FIMC_IS_QUEUE_BUFFER_READY, &queue->state); clear_bit(FIMC_IS_QUEUE_BUFFER_PREPARED, &queue->state); fimc_is_frame_close(framemgr); } else { if (queue->buf_maxcount < queue->buf_rdycount) { err("buffer count is not invalid(%d < %d)", queue->buf_maxcount, queue->buf_rdycount); ret = -EINVAL; goto p_err; } ret = fimc_is_frame_open(framemgr, queue->buf_maxcount); if (ret) { err("[V%02d] fimc_is_frame_open is fail(%d)", vctx->video->id, ret); goto p_err; } } vctx->state = BIT(FIMC_IS_VIDEO_S_BUFS); p_err: return ret; }
static int __vb2_init_fileio(struct vb2_queue *q, int read) { struct vb2_fileio_data *fileio; int i, ret; unsigned int count = 0; if ((read && !(q->io_modes & VB2_READ)) || (!read && !(q->io_modes & VB2_WRITE))) BUG(); if (!q->mem_ops->vaddr) return -EBUSY; if (q->streaming || q->num_buffers > 0) return -EBUSY; count = 1; dprintk(3, "setting up file io: mode %s, count %d, flags %08x\n", (read) ? "read" : "write", count, q->io_flags); fileio = kzalloc(sizeof(struct vb2_fileio_data), GFP_KERNEL); if (fileio == NULL) return -ENOMEM; fileio->flags = q->io_flags; fileio->req.count = count; fileio->req.memory = V4L2_MEMORY_MMAP; fileio->req.type = q->type; ret = vb2_reqbufs(q, &fileio->req); if (ret) goto err_kfree; if (q->bufs[0]->num_planes != 1) { fileio->req.count = 0; ret = -EBUSY; goto err_reqbufs; } for (i = 0; i < q->num_buffers; i++) { fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0); if (fileio->bufs[i].vaddr == NULL) goto err_reqbufs; fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0); } if (read) { for (i = 0; i < q->num_buffers; i++) { struct v4l2_buffer *b = &fileio->b; memset(b, 0, sizeof(*b)); b->type = q->type; b->memory = q->memory; b->index = i; ret = vb2_qbuf(q, b); if (ret) goto err_reqbufs; fileio->bufs[i].queued = 1; } ret = vb2_streamon(q, q->type); if (ret) goto err_reqbufs; } q->fileio = fileio; return ret; err_reqbufs: vb2_reqbufs(q, &fileio->req); err_kfree: kfree(fileio); return ret; }
/* Reqeust buffers */ static int vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *reqbufs) { struct s5p_mfc_dev *dev = video_drvdata(file); struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); int ret = 0; if (reqbufs->memory != V4L2_MEMORY_MMAP) { mfc_err("Only V4L2_MEMORY_MAP is supported\n"); return -EINVAL; } if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { /* Can only request buffers after an instance has been opened.*/ if (ctx->state == MFCINST_INIT) { ctx->src_bufs_cnt = 0; if (reqbufs->count == 0) { mfc_debug(2, "Freeing buffers\n"); s5p_mfc_clock_on(); ret = vb2_reqbufs(&ctx->vq_src, reqbufs); s5p_mfc_clock_off(); return ret; } /* Decoding */ if (ctx->output_state != QUEUE_FREE) { mfc_err("Bufs have already been requested\n"); return -EINVAL; } s5p_mfc_clock_on(); ret = vb2_reqbufs(&ctx->vq_src, reqbufs); s5p_mfc_clock_off(); if (ret) { mfc_err("vb2_reqbufs on output failed\n"); return ret; } mfc_debug(2, "vb2_reqbufs: %d\n", ret); ctx->output_state = QUEUE_BUFS_REQUESTED; } } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { ctx->dst_bufs_cnt = 0; if (reqbufs->count == 0) { mfc_debug(2, "Freeing buffers\n"); s5p_mfc_clock_on(); ret = vb2_reqbufs(&ctx->vq_dst, reqbufs); s5p_mfc_clock_off(); return ret; } if (ctx->capture_state != QUEUE_FREE) { mfc_err("Bufs have already been requested\n"); return -EINVAL; } ctx->capture_state = QUEUE_BUFS_REQUESTED; s5p_mfc_clock_on(); ret = vb2_reqbufs(&ctx->vq_dst, reqbufs); s5p_mfc_clock_off(); if (ret) { mfc_err("vb2_reqbufs on capture failed\n"); return ret; } if (reqbufs->count < ctx->dpb_count) { mfc_err("Not enough buffers allocated\n"); reqbufs->count = 0; s5p_mfc_clock_on(); ret = vb2_reqbufs(&ctx->vq_dst, reqbufs); s5p_mfc_clock_off(); return -ENOMEM; } ctx->total_dpb_count = reqbufs->count; ret = s5p_mfc_hw_call(dev->mfc_ops, alloc_codec_buffers, ctx); if (ret) { mfc_err("Failed to allocate decoding buffers\n"); reqbufs->count = 0; s5p_mfc_clock_on(); ret = vb2_reqbufs(&ctx->vq_dst, reqbufs); s5p_mfc_clock_off(); return -ENOMEM; } if (ctx->dst_bufs_cnt == ctx->total_dpb_count) { ctx->capture_state = QUEUE_BUFS_MMAPED; } else { mfc_err("Not all buffers passed to buf_init\n"); reqbufs->count = 0; s5p_mfc_clock_on(); ret = vb2_reqbufs(&ctx->vq_dst, reqbufs); s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers, ctx); s5p_mfc_clock_off(); return -ENOMEM; } if (s5p_mfc_ctx_ready(ctx)) set_work_bit_irqsave(ctx); s5p_mfc_hw_call(dev->mfc_ops, try_run, dev); s5p_mfc_wait_for_done_ctx(ctx, S5P_MFC_R2H_CMD_INIT_BUFFERS_RET, 0); } return ret; }
static int myvivi_vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p) {//上面我们定义的队列为:myvivi_vb_vidqueue return vb2_reqbufs(&myvivi_vb_vidqueue, p); }