at v6.4 167 lines 5.2 kB view raw
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#include "mtk_vcodec_util.h" 16 17#define NUM_BUFFER_COUNT 3 18 19struct vdec_lat_buf; 20struct mtk_vcodec_ctx; 21struct mtk_vcodec_dev; 22typedef int (*core_decode_cb_t)(struct vdec_lat_buf *lat_buf); 23 24/** 25 * struct vdec_msg_queue_ctx - represents a queue for buffers ready to be processed 26 * @ready_to_use: ready used queue used to signalize when get a job queue 27 * @ready_queue: list of ready lat buffer queues 28 * @ready_lock: spin lock to protect the lat buffer usage 29 * @ready_num: number of buffers ready to be processed 30 * @hardware_index: hardware id that this queue is used for 31 */ 32struct vdec_msg_queue_ctx { 33 wait_queue_head_t ready_to_use; 34 struct list_head ready_queue; 35 /* protect lat buffer */ 36 spinlock_t ready_lock; 37 int ready_num; 38 int hardware_index; 39}; 40 41/** 42 * struct vdec_lat_buf - lat buffer message used to store lat info for core decode 43 * @wdma_err_addr: wdma error address used for lat hardware 44 * @slice_bc_addr: slice bc address used for lat hardware 45 * @ts_info: need to set timestamp from output to capture 46 * @src_buf_req: output buffer media request object 47 * 48 * @private_data: shared information used to lat and core hardware 49 * @ctx: mtk vcodec context information 50 * @core_decode: different codec use different decode callback function 51 * @lat_list: add lat buffer to lat head list 52 * @core_list: add lat buffer to core head list 53 */ 54struct vdec_lat_buf { 55 struct mtk_vcodec_mem wdma_err_addr; 56 struct mtk_vcodec_mem slice_bc_addr; 57 struct vb2_v4l2_buffer ts_info; 58 struct media_request *src_buf_req; 59 60 void *private_data; 61 struct mtk_vcodec_ctx *ctx; 62 core_decode_cb_t core_decode; 63 struct list_head lat_list; 64 struct list_head core_list; 65}; 66 67/** 68 * struct vdec_msg_queue - used to store lat buffer message 69 * @lat_buf: lat buffer used to store lat buffer information 70 * @wdma_addr: wdma address used for ube 71 * @wdma_rptr_addr: ube read point 72 * @wdma_wptr_addr: ube write point 73 * @core_work: core hardware work 74 * @lat_ctx: used to store lat buffer list 75 * @ctx: point to mtk_vcodec_ctx 76 * 77 * @lat_list_cnt: used to record each instance lat list count 78 * @core_list_cnt: used to record each instance core list count 79 * @core_dec_done: core work queue decode done event 80 * @core_work_cnt: the number of core work in work queue 81 */ 82struct vdec_msg_queue { 83 struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT]; 84 85 struct mtk_vcodec_mem wdma_addr; 86 u64 wdma_rptr_addr; 87 u64 wdma_wptr_addr; 88 89 struct work_struct core_work; 90 struct vdec_msg_queue_ctx lat_ctx; 91 struct mtk_vcodec_ctx *ctx; 92 93 atomic_t lat_list_cnt; 94 atomic_t core_list_cnt; 95 wait_queue_head_t core_dec_done; 96 int core_work_cnt; 97}; 98 99/** 100 * vdec_msg_queue_init - init lat buffer information. 101 * @msg_queue: used to store the lat buffer information 102 * @ctx: v4l2 ctx 103 * @core_decode: core decode callback for each codec 104 * @private_size: the private data size used to share with core 105 * 106 * Return: returns 0 if init successfully, or fail. 107 */ 108int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, 109 struct mtk_vcodec_ctx *ctx, core_decode_cb_t core_decode, 110 int private_size); 111 112/** 113 * vdec_msg_queue_init_ctx - used to init msg queue context information. 114 * @ctx: message queue context 115 * @hardware_index: hardware index 116 */ 117void vdec_msg_queue_init_ctx(struct vdec_msg_queue_ctx *ctx, int hardware_index); 118 119/** 120 * vdec_msg_queue_qbuf - enqueue lat buffer to queue list. 121 * @ctx: message queue context 122 * @buf: current lat buffer 123 * 124 * Return: returns 0 if qbuf successfully, or fail. 125 */ 126int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *ctx, struct vdec_lat_buf *buf); 127 128/** 129 * vdec_msg_queue_dqbuf - dequeue lat buffer from queue list. 130 * @ctx: message queue context 131 * 132 * Return: returns not null if dq successfully, or fail. 133 */ 134struct vdec_lat_buf *vdec_msg_queue_dqbuf(struct vdec_msg_queue_ctx *ctx); 135 136/** 137 * vdec_msg_queue_update_ube_rptr - used to updata the ube read point. 138 * @msg_queue: used to store the lat buffer information 139 * @ube_rptr: current ube read point 140 */ 141void vdec_msg_queue_update_ube_rptr(struct vdec_msg_queue *msg_queue, uint64_t ube_rptr); 142 143/** 144 * vdec_msg_queue_update_ube_wptr - used to updata the ube write point. 145 * @msg_queue: used to store the lat buffer information 146 * @ube_wptr: current ube write point 147 */ 148void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t ube_wptr); 149 150/** 151 * vdec_msg_queue_wait_lat_buf_full - used to check whether all lat buffer 152 * in lat list. 153 * @msg_queue: used to store the lat buffer information 154 * 155 * Return: returns true if successfully, or fail. 156 */ 157bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue); 158 159/** 160 * vdec_msg_queue_deinit - deinit lat buffer information. 161 * @msg_queue: used to store the lat buffer information 162 * @ctx: v4l2 ctx 163 */ 164void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue, 165 struct mtk_vcodec_ctx *ctx); 166 167#endif