vdec_vpu_if.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: PC Chen <pc.chen@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 "mtk_vcodec_drv.h"
  15. #include "mtk_vcodec_util.h"
  16. #include "vdec_ipi_msg.h"
  17. #include "vdec_vpu_if.h"
  18. static void handle_init_ack_msg(struct vdec_vpu_ipi_init_ack *msg)
  19. {
  20. struct vdec_vpu_inst *vpu = (struct vdec_vpu_inst *)
  21. (unsigned long)msg->ap_inst_addr;
  22. mtk_vcodec_debug(vpu, "+ ap_inst_addr = 0x%llx", msg->ap_inst_addr);
  23. /* mapping VPU address to kernel virtual address */
  24. /* the content in vsi is initialized to 0 in VPU */
  25. vpu->vsi = vpu_mapping_dm_addr(vpu->dev, msg->vpu_inst_addr);
  26. vpu->inst_addr = msg->vpu_inst_addr;
  27. mtk_vcodec_debug(vpu, "- vpu_inst_addr = 0x%x", vpu->inst_addr);
  28. }
  29. /*
  30. * This function runs in interrupt context and it means there's an IPI MSG
  31. * from VPU.
  32. */
  33. void vpu_dec_ipi_handler(void *data, unsigned int len, void *priv)
  34. {
  35. struct vdec_vpu_ipi_ack *msg = data;
  36. struct vdec_vpu_inst *vpu = (struct vdec_vpu_inst *)
  37. (unsigned long)msg->ap_inst_addr;
  38. mtk_vcodec_debug(vpu, "+ id=%X", msg->msg_id);
  39. if (msg->status == 0) {
  40. switch (msg->msg_id) {
  41. case VPU_IPIMSG_DEC_INIT_ACK:
  42. handle_init_ack_msg(data);
  43. break;
  44. case VPU_IPIMSG_DEC_START_ACK:
  45. case VPU_IPIMSG_DEC_END_ACK:
  46. case VPU_IPIMSG_DEC_DEINIT_ACK:
  47. case VPU_IPIMSG_DEC_RESET_ACK:
  48. break;
  49. default:
  50. mtk_vcodec_err(vpu, "invalid msg=%X", msg->msg_id);
  51. break;
  52. }
  53. }
  54. mtk_vcodec_debug(vpu, "- id=%X", msg->msg_id);
  55. vpu->failure = msg->status;
  56. vpu->signaled = 1;
  57. }
  58. static int vcodec_vpu_send_msg(struct vdec_vpu_inst *vpu, void *msg, int len)
  59. {
  60. int err;
  61. uint32_t msg_id = *(uint32_t *)msg;
  62. mtk_vcodec_debug(vpu, "id=%X", msg_id);
  63. vpu->failure = 0;
  64. vpu->signaled = 0;
  65. err = vpu_ipi_send(vpu->dev, vpu->id, msg, len);
  66. if (err) {
  67. mtk_vcodec_err(vpu, "send fail vpu_id=%d msg_id=%X status=%d",
  68. vpu->id, msg_id, err);
  69. return err;
  70. }
  71. return vpu->failure;
  72. }
  73. static int vcodec_send_ap_ipi(struct vdec_vpu_inst *vpu, unsigned int msg_id)
  74. {
  75. struct vdec_ap_ipi_cmd msg;
  76. int err = 0;
  77. mtk_vcodec_debug(vpu, "+ id=%X", msg_id);
  78. memset(&msg, 0, sizeof(msg));
  79. msg.msg_id = msg_id;
  80. msg.vpu_inst_addr = vpu->inst_addr;
  81. err = vcodec_vpu_send_msg(vpu, &msg, sizeof(msg));
  82. mtk_vcodec_debug(vpu, "- id=%X ret=%d", msg_id, err);
  83. return err;
  84. }
  85. int vpu_dec_init(struct vdec_vpu_inst *vpu)
  86. {
  87. struct vdec_ap_ipi_init msg;
  88. int err;
  89. mtk_vcodec_debug_enter(vpu);
  90. init_waitqueue_head(&vpu->wq);
  91. err = vpu_ipi_register(vpu->dev, vpu->id, vpu->handler, "vdec", NULL);
  92. if (err != 0) {
  93. mtk_vcodec_err(vpu, "vpu_ipi_register fail status=%d", err);
  94. return err;
  95. }
  96. memset(&msg, 0, sizeof(msg));
  97. msg.msg_id = AP_IPIMSG_DEC_INIT;
  98. msg.ap_inst_addr = (unsigned long)vpu;
  99. mtk_vcodec_debug(vpu, "vdec_inst=%p", vpu);
  100. err = vcodec_vpu_send_msg(vpu, (void *)&msg, sizeof(msg));
  101. mtk_vcodec_debug(vpu, "- ret=%d", err);
  102. return err;
  103. }
  104. int vpu_dec_start(struct vdec_vpu_inst *vpu, uint32_t *data, unsigned int len)
  105. {
  106. struct vdec_ap_ipi_dec_start msg;
  107. int i;
  108. int err = 0;
  109. mtk_vcodec_debug_enter(vpu);
  110. if (len > ARRAY_SIZE(msg.data)) {
  111. mtk_vcodec_err(vpu, "invalid len = %d\n", len);
  112. return -EINVAL;
  113. }
  114. memset(&msg, 0, sizeof(msg));
  115. msg.msg_id = AP_IPIMSG_DEC_START;
  116. msg.vpu_inst_addr = vpu->inst_addr;
  117. for (i = 0; i < len; i++)
  118. msg.data[i] = data[i];
  119. err = vcodec_vpu_send_msg(vpu, (void *)&msg, sizeof(msg));
  120. mtk_vcodec_debug(vpu, "- ret=%d", err);
  121. return err;
  122. }
  123. int vpu_dec_end(struct vdec_vpu_inst *vpu)
  124. {
  125. return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_END);
  126. }
  127. int vpu_dec_deinit(struct vdec_vpu_inst *vpu)
  128. {
  129. return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_DEINIT);
  130. }
  131. int vpu_dec_reset(struct vdec_vpu_inst *vpu)
  132. {
  133. return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_RESET);
  134. }