3333#define ZEPHYR_INCLUDE_RTIO_RTIO_H_
3434
3535#include <zephyr/rtio/rtio_spsc.h>
36+ #include <zephyr/rtio/rtio_mpsc.h>
3637#include <zephyr/sys/__assert.h>
3738#include <zephyr/sys/atomic.h>
3839#include <zephyr/device.h>
@@ -164,6 +165,7 @@ struct rtio_cq {
164165};
165166
166167struct rtio ;
168+ struct rtio_iodev_sqe ;
167169
168170struct rtio_executor_api {
169171 /**
@@ -179,12 +181,12 @@ struct rtio_executor_api {
179181 /**
180182 * @brief SQE completes successfully
181183 */
182- void (* ok )(struct rtio * r , const struct rtio_sqe * sqe , int result );
184+ void (* ok )(struct rtio_iodev_sqe * iodev_sqe , int result );
183185
184186 /**
185- * @brief SQE fails to complete
187+ * @brief SQE fails to complete successfully
186188 */
187- void (* err )(struct rtio * r , const struct rtio_sqe * sqe , int result );
189+ void (* err )(struct rtio_iodev_sqe * iodev_sqe , int result );
188190};
189191
190192/**
@@ -257,47 +259,32 @@ struct rtio {
257259 struct rtio_cq * cq ;
258260};
259261
262+
260263/**
261- * @brief API that an RTIO IO device should implement
264+ * @brief IO device submission queue entry
262265 */
263- struct rtio_iodev_api {
264- /**
265- * @brief Submission function for a request to the iodev
266- *
267- * The iodev is responsible for doing the operation described
268- * as a submission queue entry and reporting results using using
269- * `rtio_sqe_ok` or `rtio_sqe_err` once done.
270- */
271- void (* submit )(const struct rtio_sqe * sqe ,
272- struct rtio * r );
273-
274- /**
275- * TODO some form of transactional piece is missing here
276- * where we wish to "transact" on an iodev with multiple requests
277- * over a chain.
278- *
279- * Only once explicitly released or the chain fails do we want
280- * to release. Once released any pending iodevs in the queue
281- * should be done.
282- *
283- * Something akin to a lock/unlock pair.
284- */
285- };
286-
287- /* IO device submission queue entry */
288266struct rtio_iodev_sqe {
267+ struct rtio_mpsc_node q ;
289268 const struct rtio_sqe * sqe ;
290269 struct rtio * r ;
291270};
292271
293272/**
294- * @brief IO device submission queue
295- *
296- * This is used for reifying the member of the rtio_iodev struct
273+ * @brief API that an RTIO IO device should implement
297274 */
298- struct rtio_iodev_sq {
299- struct rtio_spsc _spsc ;
300- struct rtio_iodev_sqe buffer [];
275+ struct rtio_iodev_api {
276+ /**
277+ * @brief Submit to the iodev an entry to work on
278+ *
279+ * This call should be short in duration and most likely
280+ * either enqueue or kick off an entry with the hardware.
281+ *
282+ * If polling is required the iodev should add itself to the execution
283+ * context (@see rtio_add_pollable())
284+ *
285+ * @param iodev_sqe Submission queue entry
286+ */
287+ void (* submit )(struct rtio_iodev_sqe * iodev_sqe );
301288};
302289
303290/**
@@ -308,7 +295,7 @@ struct rtio_iodev {
308295 const struct rtio_iodev_api * api ;
309296
310297 /* Queue of RTIO contexts with requests */
311- struct rtio_iodev_sq * iodev_sq ;
298+ struct rtio_mpsc iodev_sq ;
312299
313300 /* Data associated with this iodev */
314301 void * data ;
@@ -389,29 +376,17 @@ static inline void rtio_sqe_prep_write(struct rtio_sqe *sqe,
389376#define RTIO_CQ_DEFINE (name , len ) \
390377 RTIO_SPSC_DEFINE(name, struct rtio_cqe, len)
391378
392-
393- /**
394- * @brief Statically define and initialize a fixed length iodev submission queue
395- *
396- * @param name Name of the queue.
397- * @param len Queue length, power of 2 required
398- */
399- #define RTIO_IODEV_SQ_DEFINE (name , len ) \
400- RTIO_SPSC_DEFINE(name, struct rtio_iodev_sqe, len)
401-
402379/**
403380 * @brief Statically define and initialize an RTIO IODev
404381 *
405382 * @param name Name of the iodev
406383 * @param iodev_api Pointer to struct rtio_iodev_api
407- * @param qsize Size of the submission queue, must be power of 2
408384 * @param iodev_data Data pointer
409385 */
410- #define RTIO_IODEV_DEFINE (name , iodev_api , qsize , iodev_data ) \
411- static RTIO_IODEV_SQ_DEFINE(_iodev_sq_##name, qsize); \
412- const STRUCT_SECTION_ITERABLE(rtio_iodev, name) = { \
386+ #define RTIO_IODEV_DEFINE (name , iodev_api , iodev_data ) \
387+ STRUCT_SECTION_ITERABLE(rtio_iodev, name) = { \
413388 .api = (iodev_api), \
414- .iodev_sq = (struct rtio_iodev_sq *const)&_iodev_sq_## name, \
389+ .iodev_sq = RTIO_MPSC_INIT(( name.iodev_sq)), \
415390 .data = (iodev_data), \
416391 }
417392
@@ -449,14 +424,16 @@ static inline void rtio_set_executor(struct rtio *r, struct rtio_executor *exc)
449424}
450425
451426/**
452- * @brief Perform a submitted operation with an iodev
427+ * @brief Submit to an iodev a submission to work on
453428 *
454- * @param sqe Submission to work on
455- * @param r RTIO context
429+ * Should be called by the executor when it wishes to submit work
430+ * to an iodev.
431+ *
432+ * @param iodev_sqe Submission to work on
456433 */
457- static inline void rtio_iodev_submit (const struct rtio_sqe * sqe , struct rtio * r )
434+ static inline void rtio_iodev_submit (struct rtio_iodev_sqe * iodev_sqe )
458435{
459- sqe -> iodev -> api -> submit (sqe , r );
436+ iodev_sqe -> sqe -> iodev -> api -> submit (iodev_sqe );
460437}
461438
462439/**
@@ -571,27 +548,25 @@ static inline void rtio_cqe_release_all(struct rtio *r)
571548 *
572549 * This may start the next asynchronous request if one is available.
573550 *
574- * @param r RTIO context
575- * @param sqe Submission that has succeeded
551+ * @param iodev_sqe IODev Submission that has succeeded
576552 * @param result Result of the request
577553 */
578- static inline void rtio_sqe_ok (struct rtio * r , const struct rtio_sqe * sqe , int result )
554+ static inline void rtio_iodev_sqe_ok (struct rtio_iodev_sqe * iodev_sqe , int result )
579555{
580- r -> executor -> api -> ok (r , sqe , result );
556+ iodev_sqe -> r -> executor -> api -> ok (iodev_sqe , result );
581557}
582558
583559/**
584560 * @brief Inform the executor of a submissions completion with error
585561 *
586562 * This SHALL fail the remaining submissions in the chain.
587563 *
588- * @param r RTIO context
589- * @param sqe Submission that has failed
564+ * @param iodev_sqe Submission that has failed
590565 * @param result Result of the request
591566 */
592- static inline void rtio_sqe_err (struct rtio * r , const struct rtio_sqe * sqe , int result )
567+ static inline void rtio_iodev_sqe_err (struct rtio_iodev_sqe * iodev_sqe , int result )
593568{
594- r -> executor -> api -> err (r , sqe , result );
569+ iodev_sqe -> r -> executor -> api -> err (iodev_sqe , result );
595570}
596571
597572/**
0 commit comments