vdec_vpu_if.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. mtk_vcodec_debug(vpu, "id=%X", *(uint32_t *)msg);
  62. vpu->failure = 0;
  63. vpu->signaled = 0;
  64. err = vpu_ipi_send(vpu->dev, vpu->id, msg, len);
  65. if (err) {
  66. mtk_vcodec_err(vpu, "send fail vpu_id=%d msg_id=%X status=%d",
  67. vpu->id, *(uint32_t *)msg, err);
  68. return err;
  69. }
  70. return vpu->failure;
  71. }
  72. static int vcodec_send_ap_ipi(struct vdec_vpu_inst *vpu, unsigned int msg_id)
  73. {
  74. struct vdec_ap_ipi_cmd msg;
  75. int err = 0;
  76. mtk_vcodec_debug(vpu, "+ id=%X", msg_id);
  77. memset(&msg, 0, sizeof(msg));
  78. msg.msg_id = msg_id;
  79. msg.vpu_inst_addr = vpu->inst_addr;
  80. err = vcodec_vpu_send_msg(vpu, &msg, sizeof(msg));
  81. mtk_vcodec_debug(vpu, "- id=%X ret=%d", msg_id, err);
  82. return err;
  83. }
  84. int vpu_dec_init(struct vdec_vpu_inst *vpu)
  85. {
  86. struct vdec_ap_ipi_init msg;
  87. int err;
  88. mtk_vcodec_debug_enter(vpu);
  89. init_waitqueue_head(&vpu->wq);
  90. err = vpu_ipi_register(vpu->dev, vpu->id, vpu->handler, "vdec", NULL);
  91. if (err != 0) {
  92. mtk_vcodec_err(vpu, "vpu_ipi_register fail status=%d", err);
  93. return err;
  94. }
  95. memset(&msg, 0, sizeof(msg));
  96. msg.msg_id = AP_IPIMSG_DEC_INIT;
  97. msg.ap_inst_addr = (unsigned long)vpu;
  98. mtk_vcodec_debug(vpu, "vdec_inst=%p", vpu);
  99. err = vcodec_vpu_send_msg(vpu, (void *)&msg, sizeof(msg));
  100. mtk_vcodec_debug(vpu, "- ret=%d", err);
  101. return err;
  102. }
  103. int vpu_dec_start(struct vdec_vpu_inst *vpu, uint32_t *data, unsigned int len)
  104. {
  105. struct vdec_ap_ipi_dec_start msg;
  106. int i;
  107. int err = 0;
  108. mtk_vcodec_debug_enter(vpu);
  109. if (len > ARRAY_SIZE(msg.data)) {
  110. mtk_vcodec_err(vpu, "invalid len = %d\n", len);
  111. return -EINVAL;
  112. }
  113. memset(&msg, 0, sizeof(msg));
  114. msg.msg_id = AP_IPIMSG_DEC_START;
  115. msg.vpu_inst_addr = vpu->inst_addr;
  116. for (i = 0; i < len; i++)
  117. msg.data[i] = data[i];
  118. err = vcodec_vpu_send_msg(vpu, (void *)&msg, sizeof(msg));
  119. mtk_vcodec_debug(vpu, "- ret=%d", err);
  120. return err;
  121. }
  122. int vpu_dec_end(struct vdec_vpu_inst *vpu)
  123. {
  124. return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_END);
  125. }
  126. int vpu_dec_deinit(struct vdec_vpu_inst *vpu)
  127. {
  128. return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_DEINIT);
  129. }
  130. int vpu_dec_reset(struct vdec_vpu_inst *vpu)
  131. {
  132. return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_RESET);
  133. }