• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Description:
19 */
20 #ifndef __AML_VCODEC_VFQ_H_
21 #define __AML_VCODEC_VFQ_H_
22 
23 #include <linux/types.h>
24 #include <asm/barrier.h>
25 
26 struct vfq_s {
27 	int rp;
28 	int wp;
29 	int size;
30 	int pre_rp;
31 	int pre_wp;
32 	struct vframe_s **pool;
33 };
34 
vfq_lookup_start(struct vfq_s * q)35 static inline void vfq_lookup_start(struct vfq_s *q)
36 {
37 	q->pre_rp = q->rp;
38 	q->pre_wp = q->wp;
39 }
vfq_lookup_end(struct vfq_s * q)40 static inline void vfq_lookup_end(struct vfq_s *q)
41 {
42 	q->rp = q->pre_rp;
43 	q->wp = q->pre_wp;
44 }
45 
vfq_init(struct vfq_s * q,u32 size,struct vframe_s ** pool)46 static inline void vfq_init(struct vfq_s *q, u32 size, struct vframe_s **pool)
47 {
48 	q->rp = q->wp = 0;
49 	q->size = size;
50 	q->pool = pool;
51 }
52 
vfq_empty(struct vfq_s * q)53 static inline bool vfq_empty(struct vfq_s *q)
54 {
55 	return q->rp == q->wp;
56 }
57 
vfq_push(struct vfq_s * q,struct vframe_s * vf)58 static inline void vfq_push(struct vfq_s *q, struct vframe_s *vf)
59 {
60 	int wp = q->wp;
61 
62 	/*ToDo*/
63 	smp_mb();
64 
65 	q->pool[wp] = vf;
66 
67 	/*ToDo*/
68 	smp_wmb();
69 
70 	q->wp = (wp == (q->size - 1)) ? 0 : (wp + 1);
71 }
72 
vfq_pop(struct vfq_s * q)73 static inline struct vframe_s *vfq_pop(struct vfq_s *q)
74 {
75 	struct vframe_s *vf;
76 	int rp;
77 
78 	if (vfq_empty(q))
79 		return NULL;
80 
81 	rp = q->rp;
82 
83 	/*ToDo*/
84 	smp_rmb();
85 
86 	vf = q->pool[rp];
87 
88 	/*ToDo*/
89 	smp_mb();
90 
91 	q->rp = (rp == (q->size - 1)) ? 0 : (rp + 1);
92 
93 	return vf;
94 }
95 
vfq_peek(struct vfq_s * q)96 static inline struct vframe_s *vfq_peek(struct vfq_s *q)
97 {
98 	return (vfq_empty(q)) ? NULL : q->pool[q->rp];
99 }
100 
vfq_level(struct vfq_s * q)101 static inline int vfq_level(struct vfq_s *q)
102 {
103 	int level = q->wp - q->rp;
104 
105 	if (level < 0)
106 		level += q->size;
107 
108 	return level;
109 }
110 
111 #endif /* __AML_VCODEC_VFQ_H_ */
112 
113