Lines Matching refs:ctx

27 static int gsc_m2m_ctx_stop_req(struct gsc_ctx *ctx)
30 struct gsc_dev *gsc = ctx->gsc_dev;
34 if (!gsc_m2m_pending(gsc) || (curr_ctx != ctx))
37 gsc_ctx_state_lock_set(GSC_CTX_STOP_REQ, ctx);
39 !gsc_ctx_state_is_set(GSC_CTX_STOP_REQ, ctx),
45 static void __gsc_m2m_job_abort(struct gsc_ctx *ctx)
49 ret = gsc_m2m_ctx_stop_req(ctx);
50 if ((ret == -ETIMEDOUT) || (ctx->state & GSC_CTX_ABORT)) {
51 gsc_ctx_state_lock_clear(GSC_CTX_STOP_REQ | GSC_CTX_ABORT, ctx);
52 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
58 struct gsc_ctx *ctx = q->drv_priv;
60 return pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
63 static void __gsc_m2m_cleanup_queue(struct gsc_ctx *ctx)
67 while (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) > 0) {
68 src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
72 while (v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx) > 0) {
73 dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
80 struct gsc_ctx *ctx = q->drv_priv;
82 __gsc_m2m_job_abort(ctx);
84 __gsc_m2m_cleanup_queue(ctx);
86 pm_runtime_put(&ctx->gsc_dev->pdev->dev);
89 void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state)
93 if (!ctx || !ctx->m2m_ctx)
96 src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
97 dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
110 v4l2_m2m_job_finish(ctx->gsc_dev->m2m.m2m_dev,
111 ctx->m2m_ctx);
120 static int gsc_get_bufs(struct gsc_ctx *ctx)
126 s_frame = &ctx->s_frame;
127 d_frame = &ctx->d_frame;
129 src_vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
130 ret = gsc_prepare_addr(ctx, &src_vb->vb2_buf, s_frame, &s_frame->addr);
134 dst_vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
135 ret = gsc_prepare_addr(ctx, &dst_vb->vb2_buf, d_frame, &d_frame->addr);
146 struct gsc_ctx *ctx = priv;
152 if (WARN(!ctx, "null hardware context\n"))
155 gsc = ctx->gsc_dev;
161 if (gsc->m2m.ctx != ctx) {
162 pr_debug("gsc->m2m.ctx = 0x%p, current_ctx = 0x%p",
163 gsc->m2m.ctx, ctx);
164 ctx->state |= GSC_PARAMS;
165 gsc->m2m.ctx = ctx;
168 is_set = ctx->state & GSC_CTX_STOP_REQ;
170 ctx->state &= ~GSC_CTX_STOP_REQ;
171 ctx->state |= GSC_CTX_ABORT;
176 ret = gsc_get_bufs(ctx);
182 gsc_set_prefbuf(gsc, &ctx->s_frame);
183 gsc_hw_set_input_addr(gsc, &ctx->s_frame.addr, GSC_M2M_BUF_NUM);
184 gsc_hw_set_output_addr(gsc, &ctx->d_frame.addr, GSC_M2M_BUF_NUM);
186 if (ctx->state & GSC_PARAMS) {
192 if (gsc_set_scaler_info(ctx)) {
197 gsc_hw_set_input_path(ctx);
198 gsc_hw_set_in_size(ctx);
199 gsc_hw_set_in_image_format(ctx);
201 gsc_hw_set_output_path(ctx);
202 gsc_hw_set_out_size(ctx);
203 gsc_hw_set_out_image_format(ctx);
205 gsc_hw_set_prescaler(ctx);
206 gsc_hw_set_mainscaler(ctx);
207 gsc_hw_set_rotation(ctx);
208 gsc_hw_set_global_alpha(ctx);
212 gsc_hw_set_sfr_update(ctx);
214 ctx->state &= ~GSC_PARAMS;
221 ctx->state &= ~GSC_PARAMS;
229 struct gsc_ctx *ctx = vb2_get_drv_priv(vq);
233 frame = ctx_get_frame(ctx, vq->type);
248 struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
252 frame = ctx_get_frame(ctx, vb->vb2_queue->type);
267 struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
269 pr_debug("ctx: %p, ctx->state: 0x%x", ctx, ctx->state);
271 if (ctx->m2m_ctx)
272 v4l2_m2m_buf_queue(ctx->m2m_ctx, vbuf);
288 struct gsc_ctx *ctx = fh_to_ctx(fh);
289 struct gsc_dev *gsc = ctx->gsc_dev;
307 struct gsc_ctx *ctx = fh_to_ctx(fh);
309 return gsc_g_fmt_mplane(ctx, f);
315 struct gsc_ctx *ctx = fh_to_ctx(fh);
317 return gsc_try_fmt_mplane(ctx, f);
323 struct gsc_ctx *ctx = fh_to_ctx(fh);
333 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
341 frame = &ctx->s_frame;
343 frame = &ctx->d_frame;
357 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_DST_FMT, ctx);
359 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_SRC_FMT, ctx);
369 struct gsc_ctx *ctx = fh_to_ctx(fh);
370 struct gsc_dev *gsc = ctx->gsc_dev;
378 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
384 struct gsc_ctx *ctx = fh_to_ctx(fh);
385 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb);
391 struct gsc_ctx *ctx = fh_to_ctx(fh);
392 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
398 struct gsc_ctx *ctx = fh_to_ctx(fh);
399 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
405 struct gsc_ctx *ctx = fh_to_ctx(fh);
406 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
412 struct gsc_ctx *ctx = fh_to_ctx(fh);
416 if (!gsc_ctx_state_is_set(GSC_SRC_FMT, ctx))
418 } else if (!gsc_ctx_state_is_set(GSC_DST_FMT, ctx)) {
422 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
428 struct gsc_ctx *ctx = fh_to_ctx(fh);
429 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
451 struct gsc_ctx *ctx = fh_to_ctx(fh);
457 frame = ctx_get_frame(ctx, s->type);
488 struct gsc_ctx *ctx = fh_to_ctx(fh);
489 struct gsc_variant *variant = ctx->gsc_dev->variant;
497 ret = gsc_try_selection(ctx, &sel);
515 frame = &ctx->s_frame;
521 frame = &ctx->d_frame;
529 if (gsc_ctx_state_is_set(GSC_DST_FMT | GSC_SRC_FMT, ctx)) {
532 sel.r.height, ctx->d_frame.crop.width,
533 ctx->d_frame.crop.height,
534 ctx->gsc_ctrls.rotate->val, ctx->out_path);
537 ctx->s_frame.crop.width,
538 ctx->s_frame.crop.height, sel.r.width,
539 sel.r.height, ctx->gsc_ctrls.rotate->val,
540 ctx->out_path);
551 gsc_ctx_state_lock_set(GSC_PARAMS, ctx);
579 struct gsc_ctx *ctx = priv;
585 src_vq->drv_priv = ctx;
590 src_vq->lock = &ctx->gsc_dev->lock;
591 src_vq->dev = &ctx->gsc_dev->pdev->dev;
600 dst_vq->drv_priv = ctx;
605 dst_vq->lock = &ctx->gsc_dev->lock;
606 dst_vq->dev = &ctx->gsc_dev->pdev->dev;
614 struct gsc_ctx *ctx = NULL;
622 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
623 if (!ctx) {
628 v4l2_fh_init(&ctx->fh, gsc->m2m.vfd);
629 ret = gsc_ctrls_create(ctx);
634 ctx->fh.ctrl_handler = &ctx->ctrl_handler;
635 file->private_data = &ctx->fh;
636 v4l2_fh_add(&ctx->fh);
638 ctx->gsc_dev = gsc;
640 ctx->s_frame.fmt = get_format(0);
641 ctx->d_frame.fmt = get_format(0);
643 ctx->state = GSC_CTX_M2M;
644 ctx->flags = 0;
645 ctx->in_path = GSC_DMA;
646 ctx->out_path = GSC_DMA;
648 ctx->m2m_ctx = v4l2_m2m_ctx_init(gsc->m2m.m2m_dev, ctx, queue_init);
649 if (IS_ERR(ctx->m2m_ctx)) {
651 ret = PTR_ERR(ctx->m2m_ctx);
658 pr_debug("gsc m2m driver is opened, ctx(0x%p)", ctx);
664 gsc_ctrls_delete(ctx);
665 v4l2_fh_del(&ctx->fh);
667 v4l2_fh_exit(&ctx->fh);
668 kfree(ctx);
676 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
677 struct gsc_dev *gsc = ctx->gsc_dev;
684 v4l2_m2m_ctx_release(ctx->m2m_ctx);
685 gsc_ctrls_delete(ctx);
686 v4l2_fh_del(&ctx->fh);
687 v4l2_fh_exit(&ctx->fh);
691 kfree(ctx);
700 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
701 struct gsc_dev *gsc = ctx->gsc_dev;
707 ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
715 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
716 struct gsc_dev *gsc = ctx->gsc_dev;
722 ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);