@@ -58,6 +58,9 @@
#define SEG_LVL_ALT_Q 0
#define SECONDARY_FILTER_STRENGTH_NUM_BITS 2
+#define AV1_IQ_TABLE_SIZE 0x12200
+#define AV1_CDF_TABLE_SIZE 0xFE80
+
static const short div_lut[DIV_LUT_NUM + 1] = {
16384, 16320, 16257, 16194, 16132, 16070, 16009, 15948, 15888, 15828, 15768,
15709, 15650, 15592, 15534, 15477, 15420, 15364, 15308, 15252, 15197, 15142,
@@ -641,6 +644,8 @@ struct vdec_av1_slice_fb {
* @frame: current frame info
* @state: status after decode done
* @cur_lst_tile_id: tile id for large scale
+ * @tile_group: tile group info
+ * @reservd: reserved
*/
struct vdec_av1_slice_vsi {
/* lat */
@@ -665,6 +670,8 @@ struct vdec_av1_slice_vsi {
struct vdec_av1_slice_frame frame;
struct vdec_av1_slice_state state;
u32 cur_lst_tile_id;
+ struct vdec_av1_slice_tile_group tile_group;
+ unsigned int reservd[4];
};
/**
@@ -692,7 +699,6 @@ struct vdec_av1_slice_pfc {
* @cdf_temp: cdf temp buffer
* @tile: tile buffer
* @slots: slots info
- * @tile_group: tile_group entry
* @level: level of current resolution
* @width: width of last picture
* @height: height of last picture
@@ -717,7 +723,6 @@ struct vdec_av1_slice_instance {
struct mtk_vcodec_mem cdf_temp;
struct mtk_vcodec_mem tile;
struct vdec_av1_slice_slot slots;
- struct vdec_av1_slice_tile_group tile_group;
/* for resolution change and get_pic_info */
enum vdec_av1_slice_resolution_level level;
@@ -774,24 +779,28 @@ static int vdec_av1_slice_init_cdf_table(struct vdec_av1_slice_instance *instanc
ctx = instance->ctx;
vsi = instance->vpu.vsi;
- remote_cdf_table = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
- (u32)vsi->cdf_table_addr);
- if (IS_ERR(remote_cdf_table)) {
- mtk_vdec_err(ctx, "failed to map cdf table\n");
- return PTR_ERR(remote_cdf_table);
- }
-
- mtk_vdec_debug(ctx, "map cdf table to 0x%p\n", remote_cdf_table);
if (instance->cdf_table.va)
mtk_vcodec_mem_free(ctx, &instance->cdf_table);
+ vsi->cdf_table_size = AV1_CDF_TABLE_SIZE;
+ mtk_vdec_debug(ctx, "svp %d. cdf table size 0x%x\n",
+ instance->ctx->is_secure_playback, vsi->cdf_table_size);
instance->cdf_table.size = vsi->cdf_table_size;
ret = mtk_vcodec_mem_alloc(ctx, &instance->cdf_table);
if (ret)
return ret;
- memcpy(instance->cdf_table.va, remote_cdf_table, vsi->cdf_table_size);
+ if (!instance->ctx->is_secure_playback) {
+ remote_cdf_table = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
+ (u32)vsi->cdf_table_addr);
+ if (IS_ERR(remote_cdf_table)) {
+ mtk_vdec_err(ctx, "failed to map cdf table\n");
+ return PTR_ERR(remote_cdf_table);
+ }
+
+ memcpy(instance->cdf_table.va, remote_cdf_table, vsi->cdf_table_size);
+ }
return 0;
}
@@ -805,25 +814,26 @@ static int vdec_av1_slice_init_iq_table(struct vdec_av1_slice_instance *instance
ctx = instance->ctx;
vsi = instance->vpu.vsi;
- remote_iq_table = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
- (u32)vsi->iq_table_addr);
- if (IS_ERR(remote_iq_table)) {
- mtk_vdec_err(ctx, "failed to map iq table\n");
- return PTR_ERR(remote_iq_table);
- }
-
- mtk_vdec_debug(ctx, "map iq table to 0x%p\n", remote_iq_table);
if (instance->iq_table.va)
mtk_vcodec_mem_free(ctx, &instance->iq_table);
+ vsi->iq_table_size = AV1_IQ_TABLE_SIZE;
instance->iq_table.size = vsi->iq_table_size;
ret = mtk_vcodec_mem_alloc(ctx, &instance->iq_table);
if (ret)
return ret;
- memcpy(instance->iq_table.va, remote_iq_table, vsi->iq_table_size);
+ if (!instance->ctx->is_secure_playback) {
+ remote_iq_table = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
+ (u32)vsi->iq_table_addr);
+ if (IS_ERR(remote_iq_table)) {
+ mtk_vdec_err(ctx, "failed to map iq table\n");
+ return PTR_ERR(remote_iq_table);
+ }
+ memcpy(instance->iq_table.va, remote_iq_table, vsi->iq_table_size);
+ }
return 0;
}
@@ -1380,7 +1390,7 @@ static int vdec_av1_slice_setup_tile_group(struct vdec_av1_slice_instance *insta
struct vdec_av1_slice_vsi *vsi)
{
struct v4l2_ctrl_av1_tile_group_entry *ctrl_tge;
- struct vdec_av1_slice_tile_group *tile_group = &instance->tile_group;
+ struct vdec_av1_slice_tile_group *tile_group = &vsi->tile_group;
struct vdec_av1_slice_uncompressed_header *uh = &vsi->frame.uh;
struct vdec_av1_slice_tile *tile = &uh->tile;
struct v4l2_ctrl *ctrl;
@@ -1621,7 +1631,9 @@ static void vdec_av1_slice_setup_lat_buffer(struct vdec_av1_slice_instance *inst
vsi->tile.buf = instance->tile.dma_addr;
vsi->tile.size = instance->tile.size;
- memcpy(lat_buf->tile_addr.va, instance->tile.va, 64 * instance->tile_group.num_tiles);
+ if (!instance->ctx->is_secure_playback)
+ memcpy(lat_buf->tile_addr.va, instance->tile.va,
+ 64 * vsi->tile_group.num_tiles);
vsi->cdf_table.buf = instance->cdf_table.dma_addr;
vsi->cdf_table.size = instance->cdf_table.size;
@@ -1638,7 +1650,7 @@ static void vdec_av1_slice_setup_seg_buffer(struct vdec_av1_slice_instance *inst
/* reset segment buffer */
if (uh->primary_ref_frame == AV1_PRIMARY_REF_NONE || !uh->seg.segmentation_enabled) {
mtk_vdec_debug(instance->ctx, "reset seg %d\n", vsi->slot_id);
- if (vsi->slot_id != AV1_INVALID_IDX) {
+ if (!instance->ctx->is_secure_playback && vsi->slot_id != AV1_INVALID_IDX) {
buf = &instance->seg[vsi->slot_id];
memset(buf->va, 0, buf->size);
}
@@ -1649,7 +1661,7 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins
struct vdec_av1_slice_vsi *vsi,
struct mtk_vcodec_mem *bs)
{
- struct vdec_av1_slice_tile_group *tile_group = &instance->tile_group;
+ struct vdec_av1_slice_tile_group *tile_group = &vsi->tile_group;
struct vdec_av1_slice_uncompressed_header *uh = &vsi->frame.uh;
struct vdec_av1_slice_tile *tile = &uh->tile;
u32 tile_num, tile_row, tile_col;
@@ -1732,7 +1744,9 @@ static int vdec_av1_slice_setup_lat(struct vdec_av1_slice_instance *instance,
return ret;
vdec_av1_slice_setup_seg_buffer(instance, vsi);
- vdec_av1_slice_setup_tile_buffer(instance, vsi, bs);
+ if (!instance->ctx->is_secure_playback)
+ vdec_av1_slice_setup_tile_buffer(instance, vsi, bs);
+
vdec_av1_slice_setup_lat_buffer(instance, vsi, bs, lat_buf);
return 0;
@@ -1795,10 +1809,15 @@ static int vdec_av1_slice_setup_core_buffer(struct vdec_av1_slice_instance *inst
/* frame buffer */
vsi->fb.y.dma_addr = fb->base_y.dma_addr;
- if (plane == 1)
- vsi->fb.c.dma_addr = fb->base_y.dma_addr + size;
- else
- vsi->fb.c.dma_addr = fb->base_c.dma_addr;
+
+ if (!instance->ctx->is_secure_playback) {
+ if (plane == 1)
+ vsi->fb.c.dma_addr = fb->base_y.dma_addr + size;
+ else
+ vsi->fb.c.dma_addr = fb->base_c.dma_addr;
+ }
+ vsi->fb.y.size = instance->ctx->picinfo.fb_sz[0];
+ vsi->fb.c.size = instance->ctx->picinfo.fb_sz[1];
/* reference buffers */
vq = v4l2_m2m_get_vq(instance->ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
@@ -1821,6 +1840,7 @@ static int vdec_av1_slice_setup_core_buffer(struct vdec_av1_slice_instance *inst
}
vref->y.dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+ vref->y.size = size;
if (plane == 1)
vref->c.dma_addr = vref->y.dma_addr + size;
else
@@ -1897,7 +1917,13 @@ static int vdec_av1_slice_init(struct mtk_vcodec_dec_ctx *ctx)
goto error_vsi;
}
instance->init_vsi = vsi;
- instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler, (u32)vsi->core_vsi);
+ if (ctx->is_secure_playback)
+ instance->core_vsi =
+ mtk_vcodec_dec_get_shm_buffer_va(ctx->dev->optee_private, MTK_VDEC_CORE,
+ OPTEE_DATA_INDEX);
+ else
+ instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
+ (u32)vsi->core_vsi);
if (!instance->core_vsi) {
mtk_vdec_err(ctx, "failed to get AV1 core vsi\n");
@@ -1909,11 +1935,12 @@ static int vdec_av1_slice_init(struct mtk_vcodec_dec_ctx *ctx)
mtk_vdec_err(ctx, "remote vsi size 0x%x mismatch! expected: 0x%zx\n",
vsi->vsi_size, sizeof(struct vdec_av1_slice_vsi));
- instance->irq_enabled = 1;
+ instance->irq_enabled = !ctx->is_secure_playback;
instance->inneracing_mode = IS_VDEC_INNER_RACING(instance->ctx->dev->dec_capability);
- mtk_vdec_debug(ctx, "vsi 0x%p core_vsi 0x%llx 0x%p, inneracing_mode %d\n",
- vsi, vsi->core_vsi, instance->core_vsi, instance->inneracing_mode);
+ mtk_vdec_debug(ctx, "secure %d:vsi 0x%p core_vsi 0x%llx 0x%p, inneracing_mode %d\n",
+ ctx->is_secure_playback, vsi, vsi->core_vsi, instance->core_vsi,
+ instance->inneracing_mode);
ret = vdec_av1_slice_init_cdf_table(instance);
if (ret)
@@ -2106,7 +2133,9 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);
return -EBUSY;
}
- vsi->trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr;
+ if (!instance->ctx->is_secure_playback)
+ vsi->trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr;
+
mtk_vdec_debug(ctx, "lat dma 1 0x%pad 0x%pad\n",
&pfc->vsi.trans.dma_addr, &pfc->vsi.trans.dma_addr_end);