mtk_vcodec_intr.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: Tiffany Lin <tiffany.lin@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/errno.h>
  15. #include <linux/wait.h>
  16. #include "mtk_vcodec_drv.h"
  17. #include "mtk_vcodec_intr.h"
  18. #include "mtk_vcodec_util.h"
  19. int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command,
  20. unsigned int timeout_ms)
  21. {
  22. wait_queue_head_t *waitqueue;
  23. long timeout_jiff, ret;
  24. int status = 0;
  25. waitqueue = (wait_queue_head_t *)&ctx->queue;
  26. timeout_jiff = msecs_to_jiffies(timeout_ms);
  27. ret = wait_event_interruptible_timeout(*waitqueue,
  28. (ctx->int_cond &&
  29. (ctx->int_type == command)),
  30. timeout_jiff);
  31. if (!ret) {
  32. status = -1; /* timeout */
  33. mtk_v4l2_err("[%d] cmd=%d, ctx->type=%d, wait_event_interruptible_timeout time=%ums out %d %d!",
  34. ctx->id, ctx->type, command, timeout_ms,
  35. ctx->int_cond, ctx->int_type);
  36. } else if (-ERESTARTSYS == ret) {
  37. mtk_v4l2_err("[%d] cmd=%d, ctx->type=%d, wait_event_interruptible_timeout interrupted by a signal %d %d",
  38. ctx->id, ctx->type, command, ctx->int_cond,
  39. ctx->int_type);
  40. status = -1;
  41. }
  42. ctx->int_cond = 0;
  43. ctx->int_type = 0;
  44. return status;
  45. }
  46. EXPORT_SYMBOL(mtk_vcodec_wait_for_done_ctx);