Commit 34cb6947 authored by Irui Wang's avatar Irui Wang Committed by Mauro Carvalho Chehab

media: mediatek: vcodec: Add encoder driver support for 34-bit iova

Encoder driver got iova from IOMMU is 34-bit, for example:

Here is the sample code:
encoder input frame buffer dma address is:
frm_buf =
    vb2_dma_contig_plane_dma_addr(&vb2_v4l2_buffer->vb2_buf, 0);
the value of frm_buf is 0x1_ff30_0000.

encoder driver got the frm_buf and send the iova to SCP firmware
through SCP IPI message, then write to encoder hardware in SCP.
The iova is stored in IPI message as uint32_t data type, so the
value will be truncated from *0x1_ff30_0000* to *0xff30_0000*,
and then *0xff30_0000* will be written to encoder hardware, but
IOMMU will help to add the high *0x1_* bit back, so IOMMU can
translate the iova to PA correctly, encoder hardware can access
the correct memory for encoding.
Another reason to do this is the encoder hardware can't access
the 34-bit iova, IOMMU will help to add the remaining high bits
of iova. But for mt8188, encoder hardware can access 34-bit iova
directly, and encoder driver need write all 34 bits because
IOMMU can't help driver do this if the hardware support access
34-bit iova.
For the reasons above, this patch is added to support transfer
34-bit iova between kernel and SCP encoder driver. Use uint64_t
data type to store the iova, for compatibility with old chipsets,
add some new struct definitions for 34-bit.

[hverkuil: initialize wb and wb_34 to NULL]
Signed-off-by: default avatarIrui Wang <irui.wang@mediatek.com>
Reported-by: default avatarkernel test robot <lkp@intel.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent d91105e0
...@@ -401,6 +401,7 @@ struct mtk_vcodec_dec_pdata { ...@@ -401,6 +401,7 @@ struct mtk_vcodec_dec_pdata {
* @output_formats: array of supported output formats * @output_formats: array of supported output formats
* @num_output_formats: number of entries in output_formats * @num_output_formats: number of entries in output_formats
* @core_id: stand for h264 or vp8 encode index * @core_id: stand for h264 or vp8 encode index
* @uses_34bit: whether the encoder uses 34-bit iova
*/ */
struct mtk_vcodec_enc_pdata { struct mtk_vcodec_enc_pdata {
bool uses_ext; bool uses_ext;
...@@ -411,9 +412,11 @@ struct mtk_vcodec_enc_pdata { ...@@ -411,9 +412,11 @@ struct mtk_vcodec_enc_pdata {
const struct mtk_video_fmt *output_formats; const struct mtk_video_fmt *output_formats;
size_t num_output_formats; size_t num_output_formats;
int core_id; int core_id;
bool uses_34bit;
}; };
#define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext) #define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
#define MTK_ENC_IOVA_IS_34BIT(ctx) ((ctx)->dev->venc_pdata->uses_34bit)
/** /**
* struct mtk_vcodec_dev - driver data * struct mtk_vcodec_dev - driver data
......
...@@ -100,6 +100,30 @@ struct venc_ap_ipi_msg_enc_ext { ...@@ -100,6 +100,30 @@ struct venc_ap_ipi_msg_enc_ext {
uint32_t data[32]; uint32_t data[32];
}; };
/**
* struct venc_ap_ipi_msg_enc_ext_34 - AP to SCP extended enc cmd structure
* @msg_id: message id (AP_IPIMSG_XXX_ENC_ENCODE)
* @vpu_inst_addr: VPU encoder instance addr
* @bs_mode: bitstream mode for h264
* @reserved: for struct padding
* @input_addr: input frame buffer 34 bit address
* @bs_addr: output bitstream buffer 34 bit address
* @bs_size: bitstream buffer size
* @data_item: number of items in the data array
* @data: data array to store the set parameters
*/
struct venc_ap_ipi_msg_enc_ext_34 {
u32 msg_id;
u32 vpu_inst_addr;
u32 bs_mode;
u32 reserved;
u64 input_addr[3];
u64 bs_addr;
u32 bs_size;
u32 data_item;
u32 data[32];
};
/** /**
* struct venc_ap_ipi_msg_deinit - AP to VPU deinit cmd structure * struct venc_ap_ipi_msg_deinit - AP to VPU deinit cmd structure
* @msg_id: message id (AP_IPIMSG_XXX_ENC_DEINIT) * @msg_id: message id (AP_IPIMSG_XXX_ENC_DEINIT)
......
...@@ -222,10 +222,11 @@ int vpu_enc_set_param(struct venc_vpu_inst *vpu, ...@@ -222,10 +222,11 @@ int vpu_enc_set_param(struct venc_vpu_inst *vpu,
return 0; return 0;
} }
int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode, static int vpu_enc_encode_32bits(struct venc_vpu_inst *vpu,
struct venc_frm_buf *frm_buf, unsigned int bs_mode,
struct mtk_vcodec_mem *bs_buf, struct venc_frm_buf *frm_buf,
struct venc_frame_info *frame_info) struct mtk_vcodec_mem *bs_buf,
struct venc_frame_info *frame_info)
{ {
const bool is_ext = MTK_ENC_CTX_IS_EXT(vpu->ctx); const bool is_ext = MTK_ENC_CTX_IS_EXT(vpu->ctx);
size_t msg_size = is_ext ? size_t msg_size = is_ext ?
...@@ -267,6 +268,73 @@ int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode, ...@@ -267,6 +268,73 @@ int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode,
return -EINVAL; return -EINVAL;
} }
return 0;
}
static int vpu_enc_encode_34bits(struct venc_vpu_inst *vpu,
unsigned int bs_mode,
struct venc_frm_buf *frm_buf,
struct mtk_vcodec_mem *bs_buf,
struct venc_frame_info *frame_info)
{
struct venc_ap_ipi_msg_enc_ext_34 out;
size_t msg_size = sizeof(struct venc_ap_ipi_msg_enc_ext_34);
mtk_vcodec_debug(vpu, "bs_mode %d ->", bs_mode);
memset(&out, 0, sizeof(out));
out.msg_id = AP_IPIMSG_ENC_ENCODE;
out.vpu_inst_addr = vpu->inst_addr;
out.bs_mode = bs_mode;
if (frm_buf) {
if ((frm_buf->fb_addr[0].dma_addr % 16 == 0) &&
(frm_buf->fb_addr[1].dma_addr % 16 == 0) &&
(frm_buf->fb_addr[2].dma_addr % 16 == 0)) {
out.input_addr[0] = frm_buf->fb_addr[0].dma_addr;
out.input_addr[1] = frm_buf->fb_addr[1].dma_addr;
out.input_addr[2] = frm_buf->fb_addr[2].dma_addr;
} else {
mtk_vcodec_err(vpu, "dma_addr not align to 16");
return -EINVAL;
}
}
if (bs_buf) {
out.bs_addr = bs_buf->dma_addr;
out.bs_size = bs_buf->size;
}
if (frame_info) {
out.data_item = 3;
out.data[0] = frame_info->frm_count;
out.data[1] = frame_info->skip_frm_count;
out.data[2] = frame_info->frm_type;
}
if (vpu_enc_send_msg(vpu, &out, msg_size)) {
mtk_vcodec_err(vpu, "AP_IPIMSG_ENC_ENCODE %d fail",
bs_mode);
return -EINVAL;
}
return 0;
}
int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode,
struct venc_frm_buf *frm_buf,
struct mtk_vcodec_mem *bs_buf,
struct venc_frame_info *frame_info)
{
int ret;
if (MTK_ENC_IOVA_IS_34BIT(vpu->ctx))
ret = vpu_enc_encode_34bits(vpu, bs_mode,
frm_buf, bs_buf, frame_info);
else
ret = vpu_enc_encode_32bits(vpu, bs_mode,
frm_buf, bs_buf, frame_info);
if (ret)
return ret;
mtk_vcodec_debug(vpu, "bs_mode %d state %d size %d key_frm %d <-", mtk_vcodec_debug(vpu, "bs_mode %d state %d size %d key_frm %d <-",
bs_mode, vpu->state, vpu->bs_size, vpu->is_key_frm); bs_mode, vpu->state, vpu->bs_size, vpu->is_key_frm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment