perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / media / platform / mtk-vcodec / venc_vpu_if.c
blob0d882acf88305c03371ad72595155e8411d0a04a
1 /*
2 * Copyright (c) 2016 MediaTek Inc.
3 * Author: PoChun Lin <pochun.lin@mediatek.com>
5 * This program is free software; you can redistribute it and/or
6 * modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include "mtk_vpu.h"
17 #include "venc_ipi_msg.h"
18 #include "venc_vpu_if.h"
20 static void handle_enc_init_msg(struct venc_vpu_inst *vpu, void *data)
22 struct venc_vpu_ipi_msg_init *msg = data;
24 vpu->inst_addr = msg->vpu_inst_addr;
25 vpu->vsi = vpu_mapping_dm_addr(vpu->dev, msg->vpu_inst_addr);
28 static void handle_enc_encode_msg(struct venc_vpu_inst *vpu, void *data)
30 struct venc_vpu_ipi_msg_enc *msg = data;
32 vpu->state = msg->state;
33 vpu->bs_size = msg->bs_size;
34 vpu->is_key_frm = msg->is_key_frm;
37 static void vpu_enc_ipi_handler(void *data, unsigned int len, void *priv)
39 struct venc_vpu_ipi_msg_common *msg = data;
40 struct venc_vpu_inst *vpu =
41 (struct venc_vpu_inst *)(unsigned long)msg->venc_inst;
43 mtk_vcodec_debug(vpu, "msg_id %x inst %p status %d",
44 msg->msg_id, vpu, msg->status);
46 switch (msg->msg_id) {
47 case VPU_IPIMSG_ENC_INIT_DONE:
48 handle_enc_init_msg(vpu, data);
49 break;
50 case VPU_IPIMSG_ENC_SET_PARAM_DONE:
51 break;
52 case VPU_IPIMSG_ENC_ENCODE_DONE:
53 handle_enc_encode_msg(vpu, data);
54 break;
55 case VPU_IPIMSG_ENC_DEINIT_DONE:
56 break;
57 default:
58 mtk_vcodec_err(vpu, "unknown msg id %x", msg->msg_id);
59 break;
62 vpu->signaled = 1;
63 vpu->failure = (msg->status != VENC_IPI_MSG_STATUS_OK);
65 mtk_vcodec_debug_leave(vpu);
68 static int vpu_enc_send_msg(struct venc_vpu_inst *vpu, void *msg,
69 int len)
71 int status;
73 mtk_vcodec_debug_enter(vpu);
75 if (!vpu->dev) {
76 mtk_vcodec_err(vpu, "inst dev is NULL");
77 return -EINVAL;
80 status = vpu_ipi_send(vpu->dev, vpu->id, msg, len);
81 if (status) {
82 mtk_vcodec_err(vpu, "vpu_ipi_send msg_id %x len %d fail %d",
83 *(uint32_t *)msg, len, status);
84 return -EINVAL;
86 if (vpu->failure)
87 return -EINVAL;
89 mtk_vcodec_debug_leave(vpu);
91 return 0;
94 int vpu_enc_init(struct venc_vpu_inst *vpu)
96 int status;
97 struct venc_ap_ipi_msg_init out;
99 mtk_vcodec_debug_enter(vpu);
101 init_waitqueue_head(&vpu->wq_hd);
102 vpu->signaled = 0;
103 vpu->failure = 0;
105 status = vpu_ipi_register(vpu->dev, vpu->id, vpu_enc_ipi_handler,
106 NULL, NULL);
107 if (status) {
108 mtk_vcodec_err(vpu, "vpu_ipi_register fail %d", status);
109 return -EINVAL;
112 memset(&out, 0, sizeof(out));
113 out.msg_id = AP_IPIMSG_ENC_INIT;
114 out.venc_inst = (unsigned long)vpu;
115 if (vpu_enc_send_msg(vpu, &out, sizeof(out))) {
116 mtk_vcodec_err(vpu, "AP_IPIMSG_ENC_INIT fail");
117 return -EINVAL;
120 mtk_vcodec_debug_leave(vpu);
122 return 0;
125 int vpu_enc_set_param(struct venc_vpu_inst *vpu,
126 enum venc_set_param_type id,
127 struct venc_enc_param *enc_param)
129 struct venc_ap_ipi_msg_set_param out;
131 mtk_vcodec_debug(vpu, "id %d ->", id);
133 memset(&out, 0, sizeof(out));
134 out.msg_id = AP_IPIMSG_ENC_SET_PARAM;
135 out.vpu_inst_addr = vpu->inst_addr;
136 out.param_id = id;
137 switch (id) {
138 case VENC_SET_PARAM_ENC:
139 out.data_item = 0;
140 break;
141 case VENC_SET_PARAM_FORCE_INTRA:
142 out.data_item = 0;
143 break;
144 case VENC_SET_PARAM_ADJUST_BITRATE:
145 out.data_item = 1;
146 out.data[0] = enc_param->bitrate;
147 break;
148 case VENC_SET_PARAM_ADJUST_FRAMERATE:
149 out.data_item = 1;
150 out.data[0] = enc_param->frm_rate;
151 break;
152 case VENC_SET_PARAM_GOP_SIZE:
153 out.data_item = 1;
154 out.data[0] = enc_param->gop_size;
155 break;
156 case VENC_SET_PARAM_INTRA_PERIOD:
157 out.data_item = 1;
158 out.data[0] = enc_param->intra_period;
159 break;
160 case VENC_SET_PARAM_SKIP_FRAME:
161 out.data_item = 0;
162 break;
163 default:
164 mtk_vcodec_err(vpu, "id %d not supported", id);
165 return -EINVAL;
167 if (vpu_enc_send_msg(vpu, &out, sizeof(out))) {
168 mtk_vcodec_err(vpu,
169 "AP_IPIMSG_ENC_SET_PARAM %d fail", id);
170 return -EINVAL;
173 mtk_vcodec_debug(vpu, "id %d <-", id);
175 return 0;
178 int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode,
179 struct venc_frm_buf *frm_buf,
180 struct mtk_vcodec_mem *bs_buf,
181 unsigned int *bs_size)
183 struct venc_ap_ipi_msg_enc out;
185 mtk_vcodec_debug(vpu, "bs_mode %d ->", bs_mode);
187 memset(&out, 0, sizeof(out));
188 out.msg_id = AP_IPIMSG_ENC_ENCODE;
189 out.vpu_inst_addr = vpu->inst_addr;
190 out.bs_mode = bs_mode;
191 if (frm_buf) {
192 if ((frm_buf->fb_addr[0].dma_addr % 16 == 0) &&
193 (frm_buf->fb_addr[1].dma_addr % 16 == 0) &&
194 (frm_buf->fb_addr[2].dma_addr % 16 == 0)) {
195 out.input_addr[0] = frm_buf->fb_addr[0].dma_addr;
196 out.input_addr[1] = frm_buf->fb_addr[1].dma_addr;
197 out.input_addr[2] = frm_buf->fb_addr[2].dma_addr;
198 } else {
199 mtk_vcodec_err(vpu, "dma_addr not align to 16");
200 return -EINVAL;
203 if (bs_buf) {
204 out.bs_addr = bs_buf->dma_addr;
205 out.bs_size = bs_buf->size;
207 if (vpu_enc_send_msg(vpu, &out, sizeof(out))) {
208 mtk_vcodec_err(vpu, "AP_IPIMSG_ENC_ENCODE %d fail",
209 bs_mode);
210 return -EINVAL;
213 mtk_vcodec_debug(vpu, "bs_mode %d state %d size %d key_frm %d <-",
214 bs_mode, vpu->state, vpu->bs_size, vpu->is_key_frm);
216 return 0;
219 int vpu_enc_deinit(struct venc_vpu_inst *vpu)
221 struct venc_ap_ipi_msg_deinit out;
223 mtk_vcodec_debug_enter(vpu);
225 memset(&out, 0, sizeof(out));
226 out.msg_id = AP_IPIMSG_ENC_DEINIT;
227 out.vpu_inst_addr = vpu->inst_addr;
228 if (vpu_enc_send_msg(vpu, &out, sizeof(out))) {
229 mtk_vcodec_err(vpu, "AP_IPIMSG_ENC_DEINIT fail");
230 return -EINVAL;
233 mtk_vcodec_debug_leave(vpu);
235 return 0;