Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 *
47 * @private_data: shared information used to lat and core hardware
48 * @ctx: mtk vcodec context information
49 * @core_decode: different codec use different decode callback function
50 * @lat_list: add lat buffer to lat head list
51 * @core_list: add lat buffer to core head list
52 */
53struct vdec_lat_buf {
54 struct mtk_vcodec_mem wdma_err_addr;
55 struct mtk_vcodec_mem slice_bc_addr;
56 struct vb2_v4l2_buffer ts_info;
57
58 void *private_data;
59 struct mtk_vcodec_ctx *ctx;
60 core_decode_cb_t core_decode;
61 struct list_head lat_list;
62 struct list_head core_list;
63};
64
65/**
66 * struct vdec_msg_queue - used to store lat buffer message
67 * @lat_buf: lat buffer used to store lat buffer information
68 * @wdma_addr: wdma address used for ube
69 * @wdma_rptr_addr: ube read point
70 * @wdma_wptr_addr: ube write point
71 * @core_work: core hardware work
72 * @lat_ctx: used to store lat buffer list
73 */
74struct vdec_msg_queue {
75 struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT];
76
77 struct mtk_vcodec_mem wdma_addr;
78 u64 wdma_rptr_addr;
79 u64 wdma_wptr_addr;
80
81 struct work_struct core_work;
82 struct vdec_msg_queue_ctx lat_ctx;
83};
84
85/**
86 * vdec_msg_queue_init - init lat buffer information.
87 * @msg_queue: used to store the lat buffer information
88 * @ctx: v4l2 ctx
89 * @core_decode: core decode callback for each codec
90 * @private_size: the private data size used to share with core
91 *
92 * Return: returns 0 if init successfully, or fail.
93 */
94int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
95 struct mtk_vcodec_ctx *ctx, core_decode_cb_t core_decode,
96 int private_size);
97
98/**
99 * vdec_msg_queue_init_ctx - used to init msg queue context information.
100 * @ctx: message queue context
101 * @hardware_index: hardware index
102 */
103void vdec_msg_queue_init_ctx(struct vdec_msg_queue_ctx *ctx, int hardware_index);
104
105/**
106 * vdec_msg_queue_qbuf - enqueue lat buffer to queue list.
107 * @ctx: message queue context
108 * @buf: current lat buffer
109 *
110 * Return: returns 0 if qbuf successfully, or fail.
111 */
112int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *ctx, struct vdec_lat_buf *buf);
113
114/**
115 * vdec_msg_queue_dqbuf - dequeue lat buffer from queue list.
116 * @ctx: message queue context
117 *
118 * Return: returns not null if dq successfully, or fail.
119 */
120struct vdec_lat_buf *vdec_msg_queue_dqbuf(struct vdec_msg_queue_ctx *ctx);
121
122/**
123 * vdec_msg_queue_update_ube_rptr - used to updata the ube read point.
124 * @msg_queue: used to store the lat buffer information
125 * @ube_rptr: current ube read point
126 */
127void vdec_msg_queue_update_ube_rptr(struct vdec_msg_queue *msg_queue, uint64_t ube_rptr);
128
129/**
130 * vdec_msg_queue_update_ube_wptr - used to updata the ube write point.
131 * @msg_queue: used to store the lat buffer information
132 * @ube_wptr: current ube write point
133 */
134void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t ube_wptr);
135
136/**
137 * vdec_msg_queue_wait_lat_buf_full - used to check whether all lat buffer
138 * in lat list.
139 * @msg_queue: used to store the lat buffer information
140 *
141 * Return: returns true if successfully, or fail.
142 */
143bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue);
144
145/**
146 * vdec_msg_queue_deinit - deinit lat buffer information.
147 * @msg_queue: used to store the lat buffer information
148 * @ctx: v4l2 ctx
149 */
150void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue,
151 struct mtk_vcodec_ctx *ctx);
152
153#endif