192 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * Copyright (c) 2021 MediaTek Inc.4 * Author: Yunfei Dong <yunfei.dong@mediatek.com>5 */6 7#ifndef _VDEC_MSG_QUEUE_H_8#define _VDEC_MSG_QUEUE_H_9 10#include <linux/sched.h>11#include <linux/semaphore.h>12#include <linux/slab.h>13#include <media/videobuf2-v4l2.h>14 15#define NUM_BUFFER_COUNT 316 17struct vdec_lat_buf;18struct mtk_vcodec_dec_ctx;19struct mtk_vcodec_dec_dev;20typedef int (*core_decode_cb_t)(struct vdec_lat_buf *lat_buf);21 22/**23 * enum core_ctx_status - Context decode status for core hardwre.24 * @CONTEXT_LIST_EMPTY: No buffer queued on core hardware(must always be 0)25 * @CONTEXT_LIST_QUEUED: Buffer queued to core work list26 * @CONTEXT_LIST_DEC_DONE: context decode done27 */28enum core_ctx_status {29 CONTEXT_LIST_EMPTY = 0,30 CONTEXT_LIST_QUEUED,31 CONTEXT_LIST_DEC_DONE,32};33 34/**35 * struct vdec_msg_queue_ctx - represents a queue for buffers ready to be processed36 * @ready_to_use: ready used queue used to signalize when get a job queue37 * @ready_queue: list of ready lat buffer queues38 * @ready_lock: spin lock to protect the lat buffer usage39 * @ready_num: number of buffers ready to be processed40 * @hardware_index: hardware id that this queue is used for41 */42struct vdec_msg_queue_ctx {43 wait_queue_head_t ready_to_use;44 struct list_head ready_queue;45 /* protect lat buffer */46 spinlock_t ready_lock;47 int ready_num;48 int hardware_index;49};50 51/**52 * struct vdec_lat_buf - lat buffer message used to store lat info for core decode53 * @wdma_err_addr: wdma error address used for lat hardware54 * @slice_bc_addr: slice bc address used for lat hardware55 * @rd_mv_addr: mv addr for av1 lat hardware output, core hardware input56 * @tile_addr: tile buffer for av1 core input57 * @ts_info: need to set timestamp from output to capture58 * @src_buf_req: output buffer media request object59 *60 * @private_data: shared information used to lat and core hardware61 * @ctx: mtk vcodec context information62 * @core_decode: different codec use different decode callback function63 * @lat_list: add lat buffer to lat head list64 * @core_list: add lat buffer to core head list65 *66 * @is_last_frame: meaning this buffer is the last frame67 */68struct vdec_lat_buf {69 struct mtk_vcodec_mem wdma_err_addr;70 struct mtk_vcodec_mem slice_bc_addr;71 struct mtk_vcodec_mem rd_mv_addr;72 struct mtk_vcodec_mem tile_addr;73 struct vb2_v4l2_buffer ts_info;74 struct media_request *src_buf_req;75 76 void *private_data;77 struct mtk_vcodec_dec_ctx *ctx;78 core_decode_cb_t core_decode;79 struct list_head lat_list;80 struct list_head core_list;81 82 bool is_last_frame;83};84 85/**86 * struct vdec_msg_queue - used to store lat buffer message87 * @lat_buf: lat buffer used to store lat buffer information88 * @wdma_addr: wdma address used for ube89 * @wdma_rptr_addr: ube read point90 * @wdma_wptr_addr: ube write point91 * @core_work: core hardware work92 * @lat_ctx: used to store lat buffer list93 * @core_ctx: used to store core buffer list94 *95 * @lat_list_cnt: used to record each instance lat list count96 * @core_list_cnt: used to record each instance core list count97 * @flush_done: core flush done status98 * @empty_lat_buf: the last lat buf used to flush decode99 * @core_dec_done: core work queue decode done event100 * @status: current context decode status for core hardware101 * @ctx: mtk vcodec context information102 */103struct vdec_msg_queue {104 struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT];105 106 struct mtk_vcodec_mem wdma_addr;107 u64 wdma_rptr_addr;108 u64 wdma_wptr_addr;109 110 struct work_struct core_work;111 struct vdec_msg_queue_ctx lat_ctx;112 struct vdec_msg_queue_ctx core_ctx;113 114 atomic_t lat_list_cnt;115 atomic_t core_list_cnt;116 bool flush_done;117 struct vdec_lat_buf empty_lat_buf;118 wait_queue_head_t core_dec_done;119 int status;120 struct mtk_vcodec_dec_ctx *ctx;121};122 123/**124 * vdec_msg_queue_init - init lat buffer information.125 * @msg_queue: used to store the lat buffer information126 * @ctx: v4l2 ctx127 * @core_decode: core decode callback for each codec128 * @private_size: the private data size used to share with core129 *130 * Return: returns 0 if init successfully, or fail.131 */132int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,133 struct mtk_vcodec_dec_ctx *ctx, core_decode_cb_t core_decode,134 int private_size);135 136/**137 * vdec_msg_queue_init_ctx - used to init msg queue context information.138 * @ctx: message queue context139 * @hardware_index: hardware index140 */141void vdec_msg_queue_init_ctx(struct vdec_msg_queue_ctx *ctx, int hardware_index);142 143/**144 * vdec_msg_queue_qbuf - enqueue lat buffer to queue list.145 * @ctx: message queue context146 * @buf: current lat buffer147 *148 * Return: returns 0 if qbuf successfully, or fail.149 */150int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *ctx, struct vdec_lat_buf *buf);151 152/**153 * vdec_msg_queue_dqbuf - dequeue lat buffer from queue list.154 * @ctx: message queue context155 *156 * Return: returns not null if dq successfully, or fail.157 */158struct vdec_lat_buf *vdec_msg_queue_dqbuf(struct vdec_msg_queue_ctx *ctx);159 160/**161 * vdec_msg_queue_update_ube_rptr - used to update the ube read point.162 * @msg_queue: used to store the lat buffer information163 * @ube_rptr: current ube read point164 */165void vdec_msg_queue_update_ube_rptr(struct vdec_msg_queue *msg_queue, uint64_t ube_rptr);166 167/**168 * vdec_msg_queue_update_ube_wptr - used to update the ube write point.169 * @msg_queue: used to store the lat buffer information170 * @ube_wptr: current ube write point171 */172void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t ube_wptr);173 174/**175 * vdec_msg_queue_wait_lat_buf_full - used to check whether all lat buffer176 * in lat list.177 * @msg_queue: used to store the lat buffer information178 *179 * Return: returns true if successfully, or fail.180 */181bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue);182 183/**184 * vdec_msg_queue_deinit - deinit lat buffer information.185 * @msg_queue: used to store the lat buffer information186 * @ctx: v4l2 ctx187 */188void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue,189 struct mtk_vcodec_dec_ctx *ctx);190 191#endif192