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 @InstanceInitError
97 @Template("./VirtQueue.xdt")
98
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 config UInt32 VRING_OFFSET = 0x00080000;
141
142 143 144 145
146 config UInt VQ0_SIZE = 256;
147 config UInt VQ1_SIZE = 256;
148
149
150 config UInt RP_MSG_NUM_BUFS = VQ0_SIZE;
151
152 config UInt PAGE_SIZE = 4096;
153
154 155 156 157 158
159 config UInt RP_MSG_VRING_ALIGN = 4096;
160
161 /*!
162 * ======== startup ========
163 *
164 * Plug interrupts, and if host, initialize vring memory and send
165 * startup sequence events to slave.
166 */
167 Void startup(UInt16 remoteProcId, Bool isHost);
168
169 /*!
170 * ======== cacheWb ========
171 * Flush the SysMin trace buffer
172 *
173 * This function should be configured as an idle function.
174 *
175 * @p(code)
176 * var Idle = xdc.useModule('ti.sysbios.knl.Idle');
177 * Idle.addFunc('&VirtQueue_cacheWb');
178 * @p
179 */
180 Void cacheWb();
181
182 instance:
183
184 /*!
185 * @brief Initialize at runtime the VirtQueue
186 *
187 * Maps to Instance_init function
188 *
189 * @param[in] remoteProcId Remote processor ID associated with this VirtQueue.
190 *
191 * @Returns Returns a handle to a new initialized VirtQueue.
192 */
193 @DirectCall
194 create(UInt16 remoteProcId);
195
196 /*!
197 * @brief Notify other processor of new buffers in the queue.
198 *
199 * After one or more add_buf calls, invoke this to kick the other side.
200 *
201 * @param[in] vq the VirtQueue.
202 *
203 * @sa VirtQueue_addBuf
204 */
205 @DirectCall
206 Void kick();
207
208 /*!
209 * @brief VirtQueue instance returns slave status
210 *
211 * Returns if this VirtQueue instance belongs to a slave
212 *
213 * @param[in] vq the VirtQueue.
214 *
215 */
216 @DirectCall
217 Bool isSlave();
218
219 /*!
220 * @brief VirtQueue instance returns host status
221 *
222 * Returns if this VirtQueue instance belongs to a host
223 *
224 * @param[in] vq the VirtQueue.
225 *
226 */
227 @DirectCall
228 Bool isHost();
229
230 /*!
231 * @brief VirtQueue instance returns queue ID
232 *
233 * Returns VirtQueue instance's queue ID.
234 *
235 * @param[in] vq the VirtQueue.
236 *
237 */
238 @DirectCall
239 UInt16 getId();
240
241 /*!
242 * @brief VirtQueue instance returns Swi handle
243 *
244 * Returns VirtQueue instance Swi handle
245 *
246 * @param[in] vq the VirtQueue.
247 *
248 */
249 @DirectCall
250 Swi.Handle getSwiHandle();
251
252 253 254 255 256
257
258 /*!
259 * @brief Add available buffer to virtqueue's available buffer list.
260 * Only used by Host.
261 *
262 * @param[in] vq the VirtQueue.
263 * @param[in] buf the buffer to be processed by the slave.
264 *
265 * @return Remaining capacity of queue or a negative error.
266 *
267 * @sa VirtQueue_getUsedBuf
268 */
269 @DirectCall
270 Int addAvailBuf(Void *buf);
271
272 /*!
273 * @brief Get the next used buffer.
274 * Only used by Host.
275 *
276 * @param[in] vq the VirtQueue.
277 *
278 * @return Returns NULL or the processed buffer.
279 *
280 * @sa VirtQueue_addAvailBuf
281 */
282 @DirectCall
283 Void *getUsedBuf();
284
285 286 287 288 289
290
291 /*!
292 * @brief Get the next available buffer.
293 * Only used by Slave.
294 *
295 * @param[in] vq the VirtQueue.
296 * @param[out] buf Pointer to location of available buffer;
297 * @param[out] len Length of the available buffer message.
298 *
299 * @return Returns a token used to identify the available buffer, to be
300 * passed back into VirtQueue_addUsedBuf();
301 * token is negative if failure to find an available buffer.
302 *
303 * @sa VirtQueue_addUsedBuf
304 */
305 @DirectCall
306 Int16 getAvailBuf(Void **buf, Int *len);
307
308 /*!
309 * @brief Add used buffer to virtqueue's used buffer list.
310 * Only used by Slave.
311 *
312 * @param[in] vq the VirtQueue.
313 * @param[in] token token of the buffer added to vring used list.
314 * @param[in] len length of the message being added.
315 *
316 * @return Remaining capacity of queue or a negative error.
317 *
318 * @sa VirtQueue_getAvailBuf
319 */
320 @DirectCall
321 Int addUsedBuf(Int16 token, Int len);
322
323
324
325 config Bool host = false;
326
327 config Fxn callback = null;
328
329 config Swi.Handle swiHandle = null;
330
331 config UInt intVectorId = ~1u;
332
333 config Int vqId = 0;
334
335
336
337 internal:
338
339 void init();
340
341 /*!
342 * ======== hostIsr ========
343 */
344 Void hostIsr(UArg msg);
345
346 /*!
347 * ======== slaveIsr ========
348 */
349 Void slaveIsr(UArg msg);
350
351 /*!
352 * ======== Module_State ========
353 * @_nodoc
354 */
355 struct Module_State
356 {
357 UInt16 hostSlaveSynced;
358 UInt16 virtQueueInitialized;
359 UInt32 *queueRegistry;
360 Ptr traceBufPtr;
361 }
362
363 /*!
364 * ======== Instance_State ========
365 * @_nodoc
366 */
367 struct Instance_State {
368 Bool hostSlaveSynced;
369 UInt16 id;
370 Fxn callback;
371 Swi.Handle swiHandle;
372 Void *vringPtr;
373 UInt16 num_free;
374 UInt16 last_avail_idx;
375 UInt16 last_used_idx;
376 UInt16 procId;
377 GateAll.Handle gateH;
378 };
379 }