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);
302 struct gsc_ctx *ctx = fh_to_ctx(fh);
304 return gsc_g_fmt_mplane(ctx, f);
310 struct gsc_ctx *ctx = fh_to_ctx(fh);
312 return gsc_try_fmt_mplane(ctx, f);
318 struct gsc_ctx *ctx = fh_to_ctx(fh);
328 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
336 frame = &ctx->s_frame;
338 frame = &ctx->d_frame;
352 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_DST_FMT, ctx);
354 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_SRC_FMT, ctx);
364 struct gsc_ctx *ctx = fh_to_ctx(fh);
365 struct gsc_dev *gsc = ctx->gsc_dev;
373 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
379 struct gsc_ctx *ctx = fh_to_ctx(fh);
380 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb);
386 struct gsc_ctx *ctx = fh_to_ctx(fh);
387 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
393 struct gsc_ctx *ctx = fh_to_ctx(fh);
394 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
400 struct gsc_ctx *ctx = fh_to_ctx(fh);
401 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
407 struct gsc_ctx *ctx = fh_to_ctx(fh);
411 if (!gsc_ctx_state_is_set(GSC_SRC_FMT, ctx))
413 } else if (!gsc_ctx_state_is_set(GSC_DST_FMT, ctx)) {
417 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
423 struct gsc_ctx *ctx = fh_to_ctx(fh);
424 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
446 struct gsc_ctx *ctx = fh_to_ctx(fh);
452 frame = ctx_get_frame(ctx, s->type);
483 struct gsc_ctx *ctx = fh_to_ctx(fh);
484 struct gsc_variant *variant = ctx->gsc_dev->variant;
492 ret = gsc_try_selection(ctx, &sel);
510 frame = &ctx->s_frame;
516 frame = &ctx->d_frame;
524 if (gsc_ctx_state_is_set(GSC_DST_FMT | GSC_SRC_FMT, ctx)) {
527 sel.r.height, ctx->d_frame.crop.width,
528 ctx->d_frame.crop.height,
529 ctx->gsc_ctrls.rotate->val, ctx->out_path);
532 ctx->s_frame.crop.width,
533 ctx->s_frame.crop.height, sel.r.width,
534 sel.r.height, ctx->gsc_ctrls.rotate->val,
535 ctx->out_path);
546 gsc_ctx_state_lock_set(GSC_PARAMS, ctx);
574 struct gsc_ctx *ctx = priv;
580 src_vq->drv_priv = ctx;
585 src_vq->lock = &ctx->gsc_dev->lock;
586 src_vq->dev = &ctx->gsc_dev->pdev->dev;
595 dst_vq->drv_priv = ctx;
600 dst_vq->lock = &ctx->gsc_dev->lock;
601 dst_vq->dev = &ctx->gsc_dev->pdev->dev;
609 struct gsc_ctx *ctx = NULL;
617 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
618 if (!ctx) {
623 v4l2_fh_init(&ctx->fh, gsc->m2m.vfd);
624 ret = gsc_ctrls_create(ctx);
629 ctx->fh.ctrl_handler = &ctx->ctrl_handler;
630 file->private_data = &ctx->fh;
631 v4l2_fh_add(&ctx->fh);
633 ctx->gsc_dev = gsc;
635 ctx->s_frame.fmt = get_format(0);
636 ctx->d_frame.fmt = get_format(0);
638 ctx->state = GSC_CTX_M2M;
639 ctx->flags = 0;
640 ctx->in_path = GSC_DMA;
641 ctx->out_path = GSC_DMA;
643 ctx->m2m_ctx = v4l2_m2m_ctx_init(gsc->m2m.m2m_dev, ctx, queue_init);
644 if (IS_ERR(ctx->m2m_ctx)) {
646 ret = PTR_ERR(ctx->m2m_ctx);
653 pr_debug("gsc m2m driver is opened, ctx(0x%p)", ctx);
659 gsc_ctrls_delete(ctx);
660 v4l2_fh_del(&ctx->fh);
662 v4l2_fh_exit(&ctx->fh);
663 kfree(ctx);
671 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
672 struct gsc_dev *gsc = ctx->gsc_dev;
679 v4l2_m2m_ctx_release(ctx->m2m_ctx);
680 gsc_ctrls_delete(ctx);
681 v4l2_fh_del(&ctx->fh);
682 v4l2_fh_exit(&ctx->fh);
686 kfree(ctx);
695 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
696 struct gsc_dev *gsc = ctx->gsc_dev;
702 ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
710 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
711 struct gsc_dev *gsc = ctx->gsc_dev;
717 ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);