1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: Tiffany Lin <tiffany.lin@mediatek.com>
5 */
6 
7 #include <linux/errno.h>
8 #include <linux/wait.h>
9 
10 #include "mtk_vcodec_drv.h"
11 #include "mtk_vcodec_intr.h"
12 #include "mtk_vcodec_util.h"
13 
mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx * ctx,int command,unsigned int timeout_ms)14 int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx  *ctx, int command,
15 				 unsigned int timeout_ms)
16 {
17 	wait_queue_head_t *waitqueue;
18 	long timeout_jiff, ret;
19 	int status = 0;
20 
21 	waitqueue = (wait_queue_head_t *)&ctx->queue;
22 	timeout_jiff = msecs_to_jiffies(timeout_ms);
23 
24 	ret = wait_event_interruptible_timeout(*waitqueue,
25 				ctx->int_cond,
26 				timeout_jiff);
27 
28 	if (!ret) {
29 		status = -1;	/* timeout */
30 		mtk_v4l2_err("[%d] ctx->type=%d, cmd=%d, wait_event_interruptible_timeout time=%ums out %d %d!",
31 			     ctx->id, ctx->type, command, timeout_ms,
32 			     ctx->int_cond, ctx->int_type);
33 	} else if (-ERESTARTSYS == ret) {
34 		mtk_v4l2_err("[%d] ctx->type=%d, cmd=%d, wait_event_interruptible_timeout interrupted by a signal %d %d",
35 			     ctx->id, ctx->type, command, ctx->int_cond,
36 			     ctx->int_type);
37 		status = -1;
38 	}
39 
40 	ctx->int_cond = 0;
41 	ctx->int_type = 0;
42 
43 	return status;
44 }
45 EXPORT_SYMBOL(mtk_vcodec_wait_for_done_ctx);
46