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