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