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)
117#define RTIO_SQE_CANCELED BIT(3) __DEPRECATED_MACRO
125#define RTIO_SQE_MULTISHOT BIT(4)
130#define RTIO_SQE_NO_RESPONSE BIT(5)
148#define RTIO_OP_RX (RTIO_OP_NOP+1)
151#define RTIO_OP_TX (RTIO_OP_RX+1)
154#define RTIO_OP_TINY_TX (RTIO_OP_TX+1)
157#define RTIO_OP_CALLBACK (RTIO_OP_TINY_TX+1)
160#define RTIO_OP_TXRX (RTIO_OP_CALLBACK+1)
163#define RTIO_OP_DELAY (RTIO_OP_TXRX+1)
166#define RTIO_OP_I2C_RECOVER (RTIO_OP_DELAY+1)
169#define RTIO_OP_I2C_CONFIGURE (RTIO_OP_I2C_RECOVER+1)
172#define RTIO_OP_I3C_RECOVER (RTIO_OP_I2C_CONFIGURE+1)
175#define RTIO_OP_I3C_CONFIGURE (RTIO_OP_I3C_RECOVER+1)
178#define RTIO_OP_I3C_CCC (RTIO_OP_I3C_CONFIGURE+1)
181#define RTIO_OP_AWAIT (RTIO_OP_I3C_CCC+1)
198#define RTIO_IODEV_I2C_STOP BIT(1)
203#define RTIO_IODEV_I2C_RESTART BIT(2)
208#define RTIO_IODEV_I2C_10_BITS BIT(3)
224#define RTIO_IODEV_I3C_STOP BIT(1)
229#define RTIO_IODEV_I3C_RESTART BIT(2)
234#define RTIO_IODEV_I3C_HDR BIT(3)
239#define RTIO_IODEV_I3C_NBCH BIT(4)
244#define RTIO_IODEV_I3C_NOACK_EXPECTED BIT(5)
249#define RTIO_IODEV_I3C_HDR_MODE_MASK GENMASK(15, 8)
254#define RTIO_IODEV_I3C_HDR_MODE_SET(flags) \
255 FIELD_PREP(RTIO_IODEV_I3C_HDR_MODE_MASK, flags)
260#define RTIO_IODEV_I3C_HDR_MODE_GET(flags) \
261 FIELD_GET(RTIO_IODEV_I3C_HDR_MODE_MASK, flags)
266#define RTIO_IODEV_I3C_HDR_CMD_CODE_MASK GENMASK(22, 16)
271#define RTIO_IODEV_I3C_HDR_CMD_CODE_SET(flags) \
272 FIELD_PREP(RTIO_IODEV_I3C_HDR_CMD_CODE_MASK, flags)
277#define RTIO_IODEV_I3C_HDR_CMD_CODE_GET(flags) \
278 FIELD_GET(RTIO_IODEV_I3C_HDR_CMD_CODE_MASK, flags)
332#define RTIO_SQE_HANDLE_INVALID ((rtio_sqe_handle_t)UINT32_MAX)
391#ifdef CONFIG_RTIO_OP_DELAY
425#define RTIO_SQE_GEN_MASK GENMASK(15, 0)
427#define RTIO_SQE_ALLOCD BIT(16)
429#define RTIO_SQE_STATUS_CANCELED BIT(17)
492#ifdef CONFIG_RTIO_OP_DELAY
502#if CONFIG_RTIO_SQE_CACHELINE_CHECK
503#ifdef CONFIG_DCACHE_LINE_SIZE
504#define RTIO_CACHE_LINE_SIZE CONFIG_DCACHE_LINE_SIZE
506#define RTIO_CACHE_LINE_SIZE 64
509 "RTIO performs best when the submissions queue entries are less than a cache line");
531static inline void _rtio_sqe_prep_read(
struct rtio_sqe *sqe,
558 __ASSERT_NO_MSG(len > 0 && buf !=
NULL);
560 _rtio_sqe_prep_read(sqe, iodev, prio, buf, len, userdata);
572 _rtio_sqe_prep_read(sqe, iodev, prio,
NULL, 0, userdata);
601 __ASSERT_NO_MSG(len > 0 && buf !=
NULL);
625 const uint8_t *tiny_write_data,
629 __ASSERT_NO_MSG(tiny_write_len <=
sizeof(sqe->
tiny_tx.
buf));
630 __ASSERT_NO_MSG(tiny_write_len > 0 && tiny_write_data !=
NULL);
693 __ASSERT_NO_MSG(buf_len > 0 && tx_buf !=
NULL && rx_buf !=
NULL);
743 int8_t prio,
void *userdata)
745 __ASSERT_NO_MSG(iodev !=
NULL);
775#ifdef CONFIG_RTIO_OP_DELAY
791 sqe->
iodev = &rtio_timeout_iodev;
792 sqe->delay.timeout = timeout;
796#define rtio_sqe_prep_delay(sqe, timeout, userdata) \
797 BUILD_ASSERT(false, "CONFIG_RTIO_OP_DELAY not enabled")
879 return iodev_sqe->
next;
938struct rtio_sqe_pool {
942 struct rtio_iodev_sqe *pool;
945static inline struct rtio_iodev_sqe *rtio_sqe_pool_alloc(
struct rtio_sqe_pool *pool)
958 memset(&iodev_sqe->
rt, 0,
sizeof(iodev_sqe->
rt));
976static inline void rtio_sqe_pool_free(
struct rtio_sqe_pool *pool,
struct rtio_iodev_sqe *iodev_sqe)
990#if CONFIG_RTIO_SQE_PLACEMENT_DTCM
991#define RTIO_SQE_MEM Z_GENERIC_SECTION(".dtcm_bss") static
992#elif defined(CONFIG_RTIO_SQE_PLACEMENT_NOCACHE)
993#define RTIO_SQE_MEM __nocache static
995#define RTIO_SQE_MEM static
1001#define Z_RTIO_SQE_POOL_DEFINE(name, sz) \
1002 RTIO_SQE_MEM struct rtio_iodev_sqe CONCAT(_sqe_pool_, name)[sz]; \
1003 STRUCT_SECTION_ITERABLE(rtio_sqe_pool, name) = { \
1004 .free_q = MPSC_INIT((name.free_q)), \
1007 .pool = CONCAT(_sqe_pool_, name), \
workaround assembler barfing for ST r
Definition asm-macro-32-bit-gnu.h:27
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
atomic_val_t atomic_or(atomic_t *target, atomic_val_t value)
Atomic bitwise inclusive OR.
atomic_t atomic_val_t
Value type for atomic integer variables.
Definition atomic_types.h:41
atomic_val_t atomic_get(const atomic_t *target)
Atomic get.
atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
Atomic get-and-set.
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:157
#define RTIO_OP_I2C_RECOVER
An operation to recover I2C buses.
Definition sqe.h:166
#define RTIO_OP_TINY_TX
An operation that transmits tiny writes by copying the data to write.
Definition sqe.h:154
#define RTIO_OP_TX
An operation that transmits (writes).
Definition sqe.h:151
#define RTIO_OP_TXRX
An operation that transceives (reads and writes simultaneously).
Definition sqe.h:160
#define RTIO_OP_NOP
An operation that does nothing and will complete immediately.
Definition sqe.h:145
#define RTIO_OP_AWAIT
An operation to await a signal while blocking the iodev (if one is provided).
Definition sqe.h:181
#define RTIO_OP_I2C_CONFIGURE
An operation to configure I2C buses.
Definition sqe.h:169
#define RTIO_OP_DELAY
An operation that takes a specified amount of time (asynchronously) before completing.
Definition sqe.h:163
#define RTIO_OP_RX
An operation that receives (reads).
Definition sqe.h:148
#define RTIO_SQE_MULTISHOT
The SQE should continue producing CQEs until canceled.
Definition sqe.h:125
#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:130
#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:568
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:816
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:622
#define RTIO_SQE_ALLOCD
Set while the entry is allocated from the pool (i.e.
Definition sqe.h:427
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:516
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:300
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:742
#define RTIO_SQE_GEN_MASK
Generation counter; bumped on free, compared against a handle's generation.
Definition sqe.h:425
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:923
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:594
uint32_t rtio_sqe_handle_t
Opaque identity for a submission queue entry.
Definition sqe.h:322
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:551
static uint16_t rtio_sqe_handle_generation(rtio_sqe_handle_t handle)
Generation counter encoded in a handle.
Definition sqe.h:449
static bool rtio_iodev_sqe_is_canceled(const struct rtio_iodev_sqe *iodev_sqe)
Check whether cancellation of a submission has been requested.
Definition sqe.h:895
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:583
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:649
#define RTIO_SQE_STATUS_CANCELED
Set when cancellation of the submission has been requested.
Definition sqe.h:429
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:759
static uint16_t rtio_sqe_handle_index(rtio_sqe_handle_t handle)
Pool block index encoded in a handle.
Definition sqe.h:438
void(* rtio_signaled_t)(struct rtio_iodev_sqe *iodev_sqe, void *userdata)
Callback signature for RTIO_OP_AWAIT signaled.
Definition sqe.h:308
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:685
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:801
#define rtio_sqe_prep_delay(sqe, timeout, userdata)
Prepare a delay operation submission which completes after the given timeout.
Definition sqe.h:796
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:857
static void rtio_iodev_sqe_set_canceled(struct rtio_iodev_sqe *iodev_sqe)
Mark a submission canceled.
Definition sqe.h:908
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:877
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:673
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:836
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:719
#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:246
#define SYS_PORT_TRACING_FUNC_EXIT(type, func,...)
Tracing macro for when a function ends its execution.
Definition tracing_macros.h:272
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a structure containing the element.
Definition util.h:281
#define NULL
Definition iar_missing_defs.h:20
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:289
Queue member.
Definition mpsc_lockfree.h:79
IO device submission queue entry.
Definition sqe.h:459
struct rtio_iodev_sqe::@330064006263143366064036221227125351044336131221::@020376107202163366036113216314102104241220072312 await
OP_AWAIT signaling state.
struct rtio_iodev_sqe * next
Next entry in a chained or transactional sequence, NULL if none.
Definition sqe.h:465
struct rtio_sqe sqe
The submission queue entry this wraps.
Definition sqe.h:461
uint8_t * buf
Buffer allocated for the read.
Definition sqe.h:481
struct rtio * r
RTIO context that owns this entry.
Definition sqe.h:467
atomic_t ok
Set once the awaited signal arrives.
Definition sqe.h:487
void * userdata
Opaque pointer passed to the callback.
Definition sqe.h:489
uint32_t buf_len
Length of the allocated buffer.
Definition sqe.h:482
atomic_t status
Identity + lifetime word (generation | ALLOCD), see RTIO_SQE_* bits above.
Definition sqe.h:470
struct mpsc_node q
Node used to link the entry into the pool free list and iodev queues.
Definition sqe.h:463
union rtio_iodev_sqe::@330064006263143366064036221227125351044336131221 rt
Runtime scratch state that the subsystem/driver mutates while it owns the submission.
rtio_signaled_t callback
Invoked when the entry is signaled.
Definition sqe.h:488
An IO device with a function table for submitting requests.
Definition iodev.h:83
A submission queue event.
Definition sqe.h:337
uint32_t i2c_config
OP_I2C_CONFIGURE.
Definition sqe.h:399
void * userdata
User provided data which is returned upon operation completion.
Definition sqe.h:355
const uint8_t * tx_buf
Buffer to write from.
Definition sqe.h:387
uint8_t op
Op code.
Definition sqe.h:338
void * arg0
Last argument given to callback.
Definition sqe.h:381
uint8_t * rx_buf
Buffer to read into.
Definition sqe.h:388
struct rtio_sqe::@342363352172076106335370162240320153276337137375::@017245174153135075241134370152236032302025336125 tiny_tx
OP_TINY_TX.
uint8_t prio
Op priority.
Definition sqe.h:340
uint32_t buf_len
Length of buffer.
Definition sqe.h:362
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:346
struct rtio_sqe::@342363352172076106335370162240320153276337137375::@331301263323312231326352370225016114352302103127 txrx
OP_TXRX.
uint32_t iodev_flags
Op iodev flags.
Definition sqe.h:344
void * ccc_payload
OP_I3C_CCC.
Definition sqe.h:410
struct rtio_sqe::@342363352172076106335370162240320153276337137375::@325336075103140057167073177100146101272354232055 tx
OP_TX.
struct rtio_sqe::@342363352172076106335370162240320153276337137375::@110162343014114265152332336213215220201374200140 rx
OP_RX.
int type
Configuration type, an enum i3c_config_type value.
Definition sqe.h:404
uint16_t flags
Op Flags.
Definition sqe.h:342
const uint8_t * buf
Buffer to write from.
Definition sqe.h:363
void * config
Configuration to apply.
Definition sqe.h:405
rtio_callback_t callback
Function to run.
Definition sqe.h:380
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:83
Header file for the Atomic operations API.