1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
88
89 import ti.sysbios.knl.Swi;
90 import ti.sdo.utils.MultiProc;
91 import ti.sysbios.gates.GateAll;
92
93 /*!
94 * ======== VirtQueue ========
95 *
96 */
97
98 @InstanceInitError
99 module VirtQueue
100 {
101
102
103
104
105
106 /*!
107 * ======== BasicView ========
108 * @_nodoc
109 */
110 metaonly struct BasicView {
111
112 };
113
114 /*!
115 * ======== ModuleView ========
116 * @_nodoc
117 */
118 metaonly struct ModuleView {
119
120 };
121
122 /*!
123 * ======== rovViewInfo ========
124 * @_nodoc
125 */
126 127 128 129 130 131 132 133 134
135
136
137
138
139 140 141 142
143 config UInt VQ0_SIZE = 256;
144 config UInt VQ1_SIZE = 256;
145
146
147 config UInt RP_MSG_NUM_BUFS = VQ0_SIZE;
148
149 config UInt PAGE_SIZE = 4096;
150
151 152 153 154 155
156 config UInt RP_MSG_VRING_ALIGN = 4096;
157
158 /*!
159 * ======== startup ========
160 *
161 * Plug interrupts, and if host, initialize vring memory and send
162 * startup sequence events to slave.
163 */
164 Void startup(UInt16 remoteProcId, Bool isHost);
165
166 instance:
167
168 /*!
169 * @brief Initialize at runtime the VirtQueue
170 *
171 * Maps to Instance_init function
172 *
173 * @param[in] remoteProcId Remote processor ID associated with this VirtQueue.
174 *
175 * @Returns Returns a handle to a new initialized VirtQueue.
176 */
177 @DirectCall
178 create(UInt16 remoteProcId);
179
180 /*!
181 * @brief Notify other processor of new buffers in the queue.
182 *
183 * After one or more add_buf calls, invoke this to kick the other side.
184 *
185 * @param[in] vq the VirtQueue.
186 *
187 * @sa VirtQueue_addBuf
188 */
189 @DirectCall
190 Void kick();
191
192 /*!
193 * @brief VirtQueue instance returns slave status
194 *
195 * Returns if this VirtQueue instance belongs to a slave
196 *
197 * @param[in] vq the VirtQueue.
198 *
199 */
200 @DirectCall
201 Bool isSlave();
202
203 /*!
204 * @brief VirtQueue instance returns host status
205 *
206 * Returns if this VirtQueue instance belongs to a host
207 *
208 * @param[in] vq the VirtQueue.
209 *
210 */
211 @DirectCall
212 Bool isHost();
213
214 /*!
215 * @brief VirtQueue instance returns queue ID
216 *
217 * Returns VirtQueue instance's queue ID.
218 *
219 * @param[in] vq the VirtQueue.
220 *
221 */
222 @DirectCall
223 UInt16 getId();
224
225 /*!
226 * @brief VirtQueue instance returns Swi handle
227 *
228 * Returns VirtQueue instance Swi handle
229 *
230 * @param[in] vq the VirtQueue.
231 *
232 */
233 @DirectCall
234 Swi.Handle getSwiHandle();
235
236 237 238 239 240
241
242 /*!
243 * @brief Add available buffer to virtqueue's available buffer list.
244 * Only used by Host.
245 *
246 * @param[in] vq the VirtQueue.
247 * @param[in] buf the buffer to be processed by the slave.
248 *
249 * @return Remaining capacity of queue or a negative error.
250 *
251 * @sa VirtQueue_getUsedBuf
252 */
253 @DirectCall
254 Int addAvailBuf(Void *buf);
255
256 /*!
257 * @brief Get the next used buffer.
258 * Only used by Host.
259 *
260 * @param[in] vq the VirtQueue.
261 *
262 * @return Returns NULL or the processed buffer.
263 *
264 * @sa VirtQueue_addAvailBuf
265 */
266 @DirectCall
267 Void *getUsedBuf();
268
269 270 271 272 273
274
275 /*!
276 * @brief Get the next available buffer.
277 * Only used by Slave.
278 *
279 * @param[in] vq the VirtQueue.
280 * @param[out] buf Pointer to location of available buffer;
281 * @param[out] len Length of the available buffer message.
282 *
283 * @return Returns a token used to identify the available buffer, to be
284 * passed back into VirtQueue_addUsedBuf();
285 * token is negative if failure to find an available buffer.
286 *
287 * @sa VirtQueue_addUsedBuf
288 */
289 @DirectCall
290 Int16 getAvailBuf(Void **buf, Int *len);
291
292 /*!
293 * @brief Add used buffer to virtqueue's used buffer list.
294 * Only used by Slave.
295 *
296 * @param[in] vq the VirtQueue.
297 * @param[in] token token of the buffer added to vring used list.
298 * @param[in] len length of the message being added.
299 *
300 * @return Remaining capacity of queue or a negative error.
301 *
302 * @sa VirtQueue_getAvailBuf
303 */
304 @DirectCall
305 Int addUsedBuf(Int16 token, Int len);
306
307
308
309 config Fxn callback = null;
310
311 config Int vqId = 0;
312
313
314
315 internal:
316
317 /*! Statically retrieve procIds to avoid doing this at runtime */
318 config UInt hostProcId = MultiProc.INVALIDID;
319 config UInt dspProcId = MultiProc.INVALIDID;
320
321 /*!
322 * ======== hostIsr ========
323 */
324 Void hostIsr(UArg msg);
325
326 /*!
327 * ======== slaveIsr ========
328 */
329 Void slaveIsr(UArg msg);
330
331 /*!
332 * ======== Module_State ========
333 * @_nodoc
334 */
335 struct Module_State
336 {
337 UInt16 hostSlaveSynced;
338 UInt16 virtQueueInitialized;
339 UInt32 *queueRegistry;
340 Ptr traceBufPtr;
341 }
342
343 /*!
344 * ======== Instance_State ========
345 * @_nodoc
346 */
347 struct Instance_State {
348 Bool hostSlaveSynced;
349 UInt16 id;
350 Fxn callback;
351 Void *vringPtr;
352 UInt16 num_free;
353 UInt16 last_avail_idx;
354 UInt16 last_used_idx;
355 UInt16 procId;
356 GateAll.Handle gateH;
357 };
358 }