16#ifndef ZEPHYR_INCLUDE_RTIO_SQE_H_
17#define ZEPHYR_INCLUDE_RTIO_SQE_H_
51#define RTIO_PRIO_LOW 0U
56#define RTIO_PRIO_NORM 127U
61#define RTIO_PRIO_HIGH 255U
82#define RTIO_SQE_CHAINED BIT(0)
94#define RTIO_SQE_TRANSACTION BIT(1)
106#define RTIO_SQE_MEMPOOL_BUFFER BIT(2)
114#define RTIO_SQE_CANCELED BIT(3)
122#define RTIO_SQE_MULTISHOT BIT(4)
127#define RTIO_SQE_NO_RESPONSE BIT(5)
145#define RTIO_OP_RX (RTIO_OP_NOP+1)
148#define RTIO_OP_TX (RTIO_OP_RX+1)
151#define RTIO_OP_TINY_TX (RTIO_OP_TX+1)
154#define RTIO_OP_CALLBACK (RTIO_OP_TINY_TX+1)
157#define RTIO_OP_TXRX (RTIO_OP_CALLBACK+1)
160#define RTIO_OP_DELAY (RTIO_OP_TXRX+1)
163#define RTIO_OP_I2C_RECOVER (RTIO_OP_DELAY+1)
166#define RTIO_OP_I2C_CONFIGURE (RTIO_OP_I2C_RECOVER+1)
169#define RTIO_OP_I3C_RECOVER (RTIO_OP_I2C_CONFIGURE+1)
172#define RTIO_OP_I3C_CONFIGURE (RTIO_OP_I3C_RECOVER+1)
175#define RTIO_OP_I3C_CCC (RTIO_OP_I3C_CONFIGURE+1)
178#define RTIO_OP_AWAIT (RTIO_OP_I3C_CCC+1)
195#define RTIO_IODEV_I2C_STOP BIT(1)
200#define RTIO_IODEV_I2C_RESTART BIT(2)
205#define RTIO_IODEV_I2C_10_BITS BIT(3)
221#define RTIO_IODEV_I3C_STOP BIT(1)
226#define RTIO_IODEV_I3C_RESTART BIT(2)
231#define RTIO_IODEV_I3C_HDR BIT(3)
236#define RTIO_IODEV_I3C_NBCH BIT(4)
241#define RTIO_IODEV_I3C_HDR_MODE_MASK GENMASK(15, 8)
246#define RTIO_IODEV_I3C_HDR_MODE_SET(flags) \
247 FIELD_PREP(RTIO_IODEV_I3C_HDR_MODE_MASK, flags)
252#define RTIO_IODEV_I3C_HDR_MODE_GET(flags) \
253 FIELD_GET(RTIO_IODEV_I3C_HDR_MODE_MASK, flags)
258#define RTIO_IODEV_I3C_HDR_CMD_CODE_MASK GENMASK(22, 16)
263#define RTIO_IODEV_I3C_HDR_CMD_CODE_SET(flags) \
264 FIELD_PREP(RTIO_IODEV_I3C_HDR_CMD_CODE_MASK, flags)
269#define RTIO_IODEV_I3C_HDR_CMD_CODE_GET(flags) \
270 FIELD_GET(RTIO_IODEV_I3C_HDR_CMD_CODE_MASK, flags)
359#ifdef CONFIG_RTIO_OP_DELAY
408#if CONFIG_RTIO_SQE_CACHELINE_CHECK
409#ifdef CONFIG_DCACHE_LINE_SIZE
410#define RTIO_CACHE_LINE_SIZE CONFIG_DCACHE_LINE_SIZE
412#define RTIO_CACHE_LINE_SIZE 64
414BUILD_ASSERT(
sizeof(
struct rtio_iodev_sqe) <= RTIO_CACHE_LINE_SIZE,
415 "RTIO performs best when the submissions queue entries are less than a cache line");
437static inline void _rtio_sqe_prep_read(
struct rtio_sqe *sqe,
464 __ASSERT_NO_MSG(len > 0 && buf != NULL);
466 _rtio_sqe_prep_read(sqe, iodev, prio, buf, len, userdata);
478 _rtio_sqe_prep_read(sqe, iodev, prio, NULL, 0, userdata);
507 __ASSERT_NO_MSG(len > 0 && buf != NULL);
531 const uint8_t *tiny_write_data,
535 __ASSERT_NO_MSG(tiny_write_len <=
sizeof(sqe->
tiny_tx.
buf));
536 __ASSERT_NO_MSG(tiny_write_len > 0 && tiny_write_data != NULL);
599 __ASSERT_NO_MSG(buf_len > 0 && tx_buf != NULL && rx_buf != NULL);
649 int8_t prio,
void *userdata)
651 __ASSERT_NO_MSG(iodev != NULL);
681#ifdef CONFIG_RTIO_OP_DELAY
697 sqe->
iodev = &rtio_timeout_iodev;
698 sqe->delay.timeout = timeout;
702#define rtio_sqe_prep_delay(sqe, timeout, userdata) \
703 BUILD_ASSERT(false, "CONFIG_RTIO_OP_DELAY not enabled")
785 return iodev_sqe->
next;
806 callback(iodev_sqe, userdata);
813struct rtio_sqe_pool {
817 struct rtio_iodev_sqe *pool;
820static inline struct rtio_iodev_sqe *rtio_sqe_pool_alloc(
struct rtio_sqe_pool *pool)
835static inline void rtio_sqe_pool_free(
struct rtio_sqe_pool *pool,
struct rtio_iodev_sqe *iodev_sqe)
842#if CONFIG_RTIO_SQE_PLACEMENT_DTCM
843#define RTIO_SQE_MEM Z_GENERIC_SECTION(".dtcm_bss") static
844#elif defined(CONFIG_RTIO_SQE_PLACEMENT_NOCACHE)
845#define RTIO_SQE_MEM __nocache static
847#define RTIO_SQE_MEM static
853#define Z_RTIO_SQE_POOL_DEFINE(name, sz) \
854 RTIO_SQE_MEM struct rtio_iodev_sqe CONCAT(_sqe_pool_, name)[sz]; \
855 STRUCT_SECTION_ITERABLE(rtio_sqe_pool, name) = { \
856 .free_q = MPSC_INIT((name.free_q)), \
859 .pool = CONCAT(_sqe_pool_, name), \
Header file for the Atomic operations API.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
_Bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
Atomic compare-and-set.
static ALWAYS_INLINE void mpsc_push(struct mpsc *q, struct mpsc_node *n)
Push a node.
Definition mpsc_lockfree.h:126
static struct mpsc_node * mpsc_pop(struct mpsc *q)
Pop a node off of the list.
Definition mpsc_lockfree.h:145
#define RTIO_OP_CALLBACK
An operation that calls a given function (callback).
Definition sqe.h:154
#define RTIO_OP_I2C_RECOVER
An operation to recover I2C buses.
Definition sqe.h:163
#define RTIO_OP_TINY_TX
An operation that transmits tiny writes by copying the data to write.
Definition sqe.h:151
#define RTIO_OP_TX
An operation that transmits (writes).
Definition sqe.h:148
#define RTIO_OP_TXRX
An operation that transceives (reads and writes simultaneously).
Definition sqe.h:157
#define RTIO_OP_NOP
An operation that does nothing and will complete immediately.
Definition sqe.h:142
#define RTIO_OP_AWAIT
An operation to await a signal while blocking the iodev (if one is provided).
Definition sqe.h:178
#define RTIO_OP_I2C_CONFIGURE
An operation to configure I2C buses.
Definition sqe.h:166
#define RTIO_OP_DELAY
An operation that takes a specified amount of time (asynchronously) before completing.
Definition sqe.h:160
#define RTIO_OP_RX
An operation that receives (reads).
Definition sqe.h:145
#define RTIO_SQE_MULTISHOT
The SQE should continue producing CQEs until canceled.
Definition sqe.h:122
#define RTIO_SQE_TRANSACTION
The next request in the queue is part of a transaction.
Definition sqe.h:94
#define RTIO_SQE_MEMPOOL_BUFFER
The buffer should be allocated by the RTIO mempool.
Definition sqe.h:106
#define RTIO_SQE_NO_RESPONSE
The SQE does not produce a CQE.
Definition sqe.h:127
#define RTIO_SQE_CHAINED
The next request in the queue should wait on this one.
Definition sqe.h:82
static void rtio_sqe_prep_read_with_pool(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Prepare a read op submission with context's mempool.
Definition sqe.h:474
static void rtio_sqe_prep_i2c_recover(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Prepare an i2c recover op submission.
Definition sqe.h:722
static void rtio_sqe_prep_tiny_write(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, const uint8_t *tiny_write_data, uint8_t tiny_write_len, void *userdata)
Prepare a tiny write op submission.
Definition sqe.h:528
static void rtio_sqe_prep_nop(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, void *userdata)
Prepare a nop (no op) submission.
Definition sqe.h:422
void(* rtio_callback_t)(struct rtio *r, const struct rtio_sqe *sqe, int res, void *arg0)
Callback signature for RTIO_OP_CALLBACK.
Definition sqe.h:292
static void rtio_sqe_prep_await_iodev(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Prepare an await op submission which blocks an rtio_iodev until completion.
Definition sqe.h:648
static void rtio_iodev_sqe_await_signal(struct rtio_iodev_sqe *iodev_sqe, rtio_signaled_t callback, void *userdata)
Await an AWAIT SQE signal from RTIO IODEV.
Definition sqe.h:798
static void rtio_sqe_prep_write(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, const uint8_t *buf, uint32_t len, void *userdata)
Prepare a write op submission.
Definition sqe.h:500
static void rtio_sqe_prep_read(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *buf, uint32_t len, void *userdata)
Prepare a read op submission.
Definition sqe.h:457
static void rtio_sqe_prep_read_multishot(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Prepare a multishot read op submission with context's mempool.
Definition sqe.h:489
static void rtio_sqe_prep_callback(struct rtio_sqe *sqe, rtio_callback_t callback, void *arg0, void *userdata)
Prepare a callback op submission.
Definition sqe.h:555
static void rtio_sqe_prep_await_executor(struct rtio_sqe *sqe, int8_t prio, void *userdata)
Prepare an await op submission which completes the sqe after being signaled.
Definition sqe.h:665
void(* rtio_signaled_t)(struct rtio_iodev_sqe *iodev_sqe, void *userdata)
Callback signature for RTIO_OP_AWAIT signaled.
Definition sqe.h:300
static void rtio_sqe_prep_transceive(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, const uint8_t *tx_buf, uint8_t *rx_buf, uint32_t buf_len, void *userdata)
Prepare a transceive op submission.
Definition sqe.h:591
static void rtio_sqe_prep_i2c_configure(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint32_t dev_config, void *userdata)
Prepare an i2c configure op submission.
Definition sqe.h:707
#define rtio_sqe_prep_delay(sqe, timeout, userdata)
Prepare a delay operation submission which completes after the given timeout.
Definition sqe.h:702
static struct rtio_iodev_sqe * rtio_chain_next(const struct rtio_iodev_sqe *iodev_sqe)
Get the next sqe in the chain.
Definition sqe.h:763
static struct rtio_iodev_sqe * rtio_iodev_sqe_next(const struct rtio_iodev_sqe *iodev_sqe)
Get the next sqe in the chain or transaction.
Definition sqe.h:783
static void rtio_sqe_prep_callback_no_cqe(struct rtio_sqe *sqe, rtio_callback_t callback, void *arg0, void *userdata)
Prepare a callback op submission that does not create a CQE.
Definition sqe.h:579
static struct rtio_iodev_sqe * rtio_txn_next(const struct rtio_iodev_sqe *iodev_sqe)
Get the next sqe in the transaction.
Definition sqe.h:742
static void rtio_sqe_prep_await(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, void *userdata)
Prepare an await op submission.
Definition sqe.h:625
#define SYS_PORT_TRACING_FUNC_ENTER(type, func,...)
Tracing macro for the entry into a function that might or might not return a value.
Definition tracing_macros.h:257
#define SYS_PORT_TRACING_FUNC_EXIT(type, func,...)
Tracing macro for when a function ends its execution.
Definition tracing_macros.h:283
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a structure containing the element.
Definition util.h:281
A wait-free intrusive multi producer single consumer (MPSC) queue using a singly linked list.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT8_TYPE__ int8_t
Definition stdint.h:72
void * memset(void *buf, int c, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Kernel timeout type.
Definition clock.h:65
Kernel timepoint type.
Definition clock.h:291
Queue member.
Definition mpsc_lockfree.h:79
IO device submission queue entry.
Definition sqe.h:398
struct rtio_iodev_sqe * next
Next entry in the chain or transaction, NULL if last.
Definition sqe.h:401
struct rtio_sqe sqe
Submission this entry carries.
Definition sqe.h:399
struct rtio * r
RTIO context the submission belongs to.
Definition sqe.h:402
struct mpsc_node q
Link used to enqueue this entry.
Definition sqe.h:400
An IO device with a function table for submitting requests.
Definition iodev.h:49
A submission queue event.
Definition sqe.h:305
uint32_t i2c_config
OP_I2C_CONFIGURE.
Definition sqe.h:368
void * userdata
User provided data which is returned upon operation completion.
Definition sqe.h:323
const uint8_t * tx_buf
Buffer to write from.
Definition sqe.h:355
uint8_t op
Op code.
Definition sqe.h:306
struct rtio_sqe::@126267262255374054123217063150244034155174062054::@222067021034074304061254367152327164076222165070 rx
OP_RX.
struct rtio_sqe::@126267262255374054123217063150244034155174062054::@036347012270137154075057170156115300365157200061 tiny_tx
OP_TINY_TX.
void * arg0
Last argument given to callback.
Definition sqe.h:349
uint8_t * rx_buf
Buffer to read into.
Definition sqe.h:356
uint8_t prio
Op priority.
Definition sqe.h:308
struct rtio_sqe::@126267262255374054123217063150244034155174062054::@236333123355174166163204241333175337261032350217 await
OP_AWAIT.
uint32_t buf_len
Length of buffer.
Definition sqe.h:330
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:314
uint32_t iodev_flags
Op iodev flags.
Definition sqe.h:312
void * ccc_payload
OP_I3C_CCC.
Definition sqe.h:379
struct rtio_sqe::@126267262255374054123217063150244034155174062054::@366052340324346171254040100167341103343101366005 txrx
OP_TXRX.
int type
Configuration type, an enum i3c_config_type value.
Definition sqe.h:373
uint16_t flags
Op Flags.
Definition sqe.h:310
const uint8_t * buf
Buffer to write from.
Definition sqe.h:331
void * config
Configuration to apply.
Definition sqe.h:374
struct rtio_sqe::@126267262255374054123217063150244034155174062054::@344335000264002157174077227357232142206143107046 tx
OP_TX.
rtio_callback_t callback
Function to run.
Definition sqe.h:348
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:71