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