This source file includes following definitions.
- bcom_get_task_irq
- _bcom_next_index
- _bcom_next_outdex
- bcom_queue_empty
- bcom_queue_full
- bcom_get_bd
- bcom_buffer_done
- bcom_prepare_next_buffer
- bcom_submit_next_buffer
- bcom_retrieve_buffer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #ifndef __BESTCOMM_H__
17 #define __BESTCOMM_H__
18
19
20
21
22
23
24
25
26
27
28 struct bcom_bd {
29 u32 status;
30 u32 data[0];
31 };
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 struct bcom_task {
48 unsigned int tasknum;
49 unsigned int flags;
50 int irq;
51
52 struct bcom_bd *bd;
53 phys_addr_t bd_pa;
54 void **cookie;
55 unsigned short index;
56 unsigned short outdex;
57 unsigned int num_bd;
58 unsigned int bd_size;
59
60 void* priv;
61 };
62
63 #define BCOM_FLAGS_NONE 0x00000000ul
64 #define BCOM_FLAGS_ENABLE_TASK (1ul << 0)
65
66
67
68
69
70
71
72
73 extern void bcom_enable(struct bcom_task *tsk);
74
75
76
77
78
79
80
81
82 extern void bcom_disable(struct bcom_task *tsk);
83
84
85
86
87
88
89 static inline int
90 bcom_get_task_irq(struct bcom_task *tsk) {
91 return tsk->irq;
92 }
93
94
95
96
97
98 #define BCOM_BD_READY 0x40000000ul
99
100
101
102
103
104
105 static inline int
106 _bcom_next_index(struct bcom_task *tsk)
107 {
108 return ((tsk->index + 1) == tsk->num_bd) ? 0 : tsk->index + 1;
109 }
110
111
112
113
114
115
116 static inline int
117 _bcom_next_outdex(struct bcom_task *tsk)
118 {
119 return ((tsk->outdex + 1) == tsk->num_bd) ? 0 : tsk->outdex + 1;
120 }
121
122
123
124
125
126 static inline int
127 bcom_queue_empty(struct bcom_task *tsk)
128 {
129 return tsk->index == tsk->outdex;
130 }
131
132
133
134
135
136 static inline int
137 bcom_queue_full(struct bcom_task *tsk)
138 {
139 return tsk->outdex == _bcom_next_index(tsk);
140 }
141
142
143
144
145
146
147 static inline struct bcom_bd
148 *bcom_get_bd(struct bcom_task *tsk, unsigned int index)
149 {
150
151
152 return ((void *)tsk->bd) + (index * tsk->bd_size);
153 }
154
155
156
157
158
159 static inline int
160 bcom_buffer_done(struct bcom_task *tsk)
161 {
162 struct bcom_bd *bd;
163 if (bcom_queue_empty(tsk))
164 return 0;
165
166 bd = bcom_get_bd(tsk, tsk->outdex);
167 return !(bd->status & BCOM_BD_READY);
168 }
169
170
171
172
173
174
175
176 static inline struct bcom_bd *
177 bcom_prepare_next_buffer(struct bcom_task *tsk)
178 {
179 struct bcom_bd *bd;
180
181 bd = bcom_get_bd(tsk, tsk->index);
182 bd->status = 0;
183 return bd;
184 }
185
186 static inline void
187 bcom_submit_next_buffer(struct bcom_task *tsk, void *cookie)
188 {
189 struct bcom_bd *bd = bcom_get_bd(tsk, tsk->index);
190
191 tsk->cookie[tsk->index] = cookie;
192 mb();
193 bd->status |= BCOM_BD_READY;
194 tsk->index = _bcom_next_index(tsk);
195 if (tsk->flags & BCOM_FLAGS_ENABLE_TASK)
196 bcom_enable(tsk);
197 }
198
199 static inline void *
200 bcom_retrieve_buffer(struct bcom_task *tsk, u32 *p_status, struct bcom_bd **p_bd)
201 {
202 void *cookie = tsk->cookie[tsk->outdex];
203 struct bcom_bd *bd = bcom_get_bd(tsk, tsk->outdex);
204
205 if (p_status)
206 *p_status = bd->status;
207 if (p_bd)
208 *p_bd = bd;
209 tsk->outdex = _bcom_next_outdex(tsk);
210 return cookie;
211 }
212
213 #endif