Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
rtio.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2022 Intel Corporation
3 * SPDX-FileCopyrightText: Copyright (c) 2026 Infineon Technologies AG,
4 * SPDX-FileCopyrightText: or an affiliate of Infineon Technologies AG. All rights reserved.
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
30
31#ifndef ZEPHYR_INCLUDE_RTIO_RTIO_H_
32#define ZEPHYR_INCLUDE_RTIO_RTIO_H_
33
34#include <string.h>
35
37#include <zephyr/device.h>
38#include <zephyr/kernel.h>
39#include <zephyr/sys/__assert.h>
40#include <zephyr/sys/atomic.h>
42#include <zephyr/sys/util.h>
44#include <zephyr/rtio/sqe.h>
45#include <zephyr/rtio/cqe.h>
46#include <zephyr/rtio/iodev.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52
61
62struct rtio;
63
72typedef void (*rtio_cqe_callback_t)(struct rtio *r, void *user_data);
73
85struct rtio {
86#ifdef CONFIG_RTIO_SUBMIT_SEM
87 /* A wait semaphore which may suspend the calling thread
88 * to wait for some number of completions when calling submit
89 */
90 struct k_sem *submit_sem;
91
92 uint32_t submit_count;
93#endif
94
95#ifdef CONFIG_RTIO_CONSUME_SEM
96 /* A wait semaphore which may suspend the calling thread
97 * to wait for some number of completions while consuming
98 * them from the completion queue
99 */
100 struct k_sem *consume_sem;
101#endif
102
105
108
110 struct rtio_sqe_pool *sqe_pool;
111
113 struct rtio_cqe_pool *cqe_pool;
114
115#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
116 /* Mem block pool */
117 struct sys_mem_blocks *block_pool;
118#endif
119
121 struct mpsc sq;
122
124 struct mpsc cq;
125
126#ifdef CONFIG_RTIO_CQE_CALLBACK
127 /* Completion queue event callback */
128 rtio_cqe_callback_t cqe_cb;
129
130 /* Completion queue event callback user data */
131 void *cqe_cb_user_data;
132#endif
133};
134
135/* @cond ignore */
136#define Z_RTIO_DEFINE(name, _sqe_pool, _cqe_pool, _block_pool) \
137 IF_ENABLED(CONFIG_RTIO_SUBMIT_SEM, \
138 (static K_SEM_DEFINE(CONCAT(_submit_sem_, name), 0, K_SEM_MAX_LIMIT))) \
139 IF_ENABLED(CONFIG_RTIO_CONSUME_SEM, \
140 (static K_SEM_DEFINE(CONCAT(_consume_sem_, name), 0, K_SEM_MAX_LIMIT))) \
141 STRUCT_SECTION_ITERABLE(rtio, name) = { \
142 IF_ENABLED(CONFIG_RTIO_SUBMIT_SEM, (.submit_sem = &CONCAT(_submit_sem_, name),)) \
143 IF_ENABLED(CONFIG_RTIO_SUBMIT_SEM, (.submit_count = 0,)) \
144 IF_ENABLED(CONFIG_RTIO_CONSUME_SEM, (.consume_sem = &CONCAT(_consume_sem_, name),))\
145 .cq_count = ATOMIC_INIT(0), \
146 .xcqcnt = ATOMIC_INIT(0), \
147 .sqe_pool = _sqe_pool, \
148 .cqe_pool = _cqe_pool, \
149 IF_ENABLED(CONFIG_RTIO_SYS_MEM_BLOCKS, (.block_pool = _block_pool,)) \
150 .sq = MPSC_INIT((name.sq)), \
151 .cq = MPSC_INIT((name.cq)), \
152 IF_ENABLED(CONFIG_RTIO_CQE_CALLBACK, (.cqe_cb = NULL, .cqe_cb_user_data = NULL,)) \
153 }
154/* @endcond */
155
163#define RTIO_DEFINE(name, sq_sz, cq_sz) \
164 Z_RTIO_SQE_POOL_DEFINE(CONCAT(name, _sqe_pool), sq_sz); \
165 Z_RTIO_CQE_POOL_DEFINE(CONCAT(name, _cqe_pool), cq_sz); \
166 Z_RTIO_DEFINE(name, &CONCAT(name, _sqe_pool), \
167 &CONCAT(name, _cqe_pool), NULL)
168
169
177static inline size_t rtio_mempool_block_size(const struct rtio *r)
178{
179#ifndef CONFIG_RTIO_SYS_MEM_BLOCKS
180 ARG_UNUSED(r);
181 return 0;
182#else
183 if (r == NULL || r->block_pool == NULL) {
184 return 0;
185 }
186 return BIT(r->block_pool->info.blk_sz_shift);
187#endif
188}
189
197#if defined(CONFIG_RTIO_SYS_MEM_BLOCKS) || defined(__DOXYGEN__)
198static inline uint16_t __rtio_compute_mempool_block_index(const struct rtio *r, const void *ptr)
199{
200 uintptr_t addr = (uintptr_t)ptr;
201 struct sys_mem_blocks *mem_pool = r->block_pool;
202 uint32_t block_size = rtio_mempool_block_size(r);
203
204 uintptr_t buff = (uintptr_t)mem_pool->buffer;
205 uint32_t buff_size = mem_pool->info.num_blocks * block_size;
206
207 if (addr < buff || addr >= buff + buff_size) {
208 return UINT16_MAX;
209 }
210 return (addr - buff) / block_size;
211}
212#endif
213
215
216static inline int rtio_block_pool_alloc(struct rtio *r, size_t min_sz,
217 size_t max_sz, uint8_t **buf, uint32_t *buf_len)
218{
219#ifndef CONFIG_RTIO_SYS_MEM_BLOCKS
220 ARG_UNUSED(r);
221 ARG_UNUSED(min_sz);
222 ARG_UNUSED(max_sz);
223 ARG_UNUSED(buf);
224 ARG_UNUSED(buf_len);
225 return -ENOTSUP;
226#else
227 const uint32_t block_size = rtio_mempool_block_size(r);
228 uint32_t bytes = max_sz;
229
230 /* Not every context has a block pool and the block size may return 0 in
231 * that case
232 */
233 if (block_size == 0) {
234 return -ENOMEM;
235 }
236
237 do {
238 size_t num_blks = DIV_ROUND_UP(bytes, block_size);
239 int rc = sys_mem_blocks_alloc_contiguous(r->block_pool, num_blks, (void **)buf);
240
241 if (rc == 0) {
242 *buf_len = num_blks * block_size;
243 return 0;
244 }
245
246 if (bytes <= block_size) {
247 break;
248 }
249
250 bytes -= block_size;
251 } while (bytes >= min_sz);
252
253 return -ENOMEM;
254#endif
255}
256
257static inline void rtio_block_pool_free(struct rtio *r, void *buf, uint32_t buf_len)
258{
259#ifndef CONFIG_RTIO_SYS_MEM_BLOCKS
260 ARG_UNUSED(r);
261 ARG_UNUSED(buf);
262 ARG_UNUSED(buf_len);
263#else
264 /* Round up, a caller may name the bytes it used rather than the whole buffer */
265 size_t num_blks = DIV_ROUND_UP(buf_len, BIT(r->block_pool->info.blk_sz_shift));
266
267 sys_mem_blocks_free_contiguous(r->block_pool, buf, num_blks);
268#endif
269}
270
272
273
275extern struct k_mem_partition rtio_partition;
276
277
278/* Do not try and reformat the macros */
279
289#if CONFIG_RTIO_BLOCK_POOL_PLACEMENT_DTCM
290#define RTIO_BMEM Z_GENERIC_SECTION(".dtcm_bss") static
291#elif defined(CONFIG_RTIO_BLOCK_POOL_PLACEMENT_NOCACHE)
292#define RTIO_BMEM __nocache static
293#else
294#define RTIO_BMEM COND_CODE_1(CONFIG_USERSPACE, (K_APP_BMEM(rtio_partition) static), (static))
295#endif
296
306#if CONFIG_RTIO_BLOCK_POOL_PLACEMENT_DTCM
307#define RTIO_DMEM Z_GENERIC_SECTION(".dtcm_data") static
308#elif defined(CONFIG_RTIO_BLOCK_POOL_PLACEMENT_NOCACHE)
309#define RTIO_DMEM __nocache_load static
310#else
311#define RTIO_DMEM COND_CODE_1(CONFIG_USERSPACE, (K_APP_DMEM(rtio_partition) static), (static))
312#endif
313
314/* clang-format off */
315/* @cond ignore */
316#define Z_RTIO_BLOCK_POOL_DEFINE(name, blk_sz, blk_cnt, blk_align) \
317 RTIO_BMEM uint8_t __aligned(WB_UP(blk_align)) \
318 CONCAT(_block_pool_, name)[(blk_cnt) * WB_UP(blk_sz)]; \
319 _SYS_MEM_BLOCKS_DEFINE_WITH_EXT_BUF(name, WB_UP(blk_sz), (blk_cnt), \
320 CONCAT(_block_pool_, name), RTIO_DMEM)
321
322/* @endcond */
323
324
325/* clang-format on */
326
337#define RTIO_DEFINE_WITH_MEMPOOL(name, sq_sz, cq_sz, num_blks, blk_size, balign) \
338 Z_RTIO_SQE_POOL_DEFINE(name##_sqe_pool, sq_sz); \
339 Z_RTIO_CQE_POOL_DEFINE(name##_cqe_pool, cq_sz); \
340 Z_RTIO_BLOCK_POOL_DEFINE(name##_block_pool, blk_size, num_blks, balign); \
341 Z_RTIO_DEFINE(name, &name##_sqe_pool, &name##_cqe_pool, &name##_block_pool)
342
343/* clang-format on */
344
352static inline uint32_t rtio_sqe_acquirable(struct rtio *r)
353{
354 return r->sqe_pool->pool_free;
355}
356
365static inline struct rtio_sqe *rtio_sqe_acquire(struct rtio *r)
366{
367 SYS_PORT_TRACING_FUNC_ENTER(rtio, sqe_acquire, r);
368 struct rtio_iodev_sqe *iodev_sqe = rtio_sqe_pool_alloc(r->sqe_pool);
369
370 if (iodev_sqe == NULL) {
371 SYS_PORT_TRACING_FUNC_EXIT(rtio, sqe_acquire, r, NULL);
372 return NULL;
373 }
374
375 mpsc_push(&r->sq, &iodev_sqe->q);
376
377 SYS_PORT_TRACING_FUNC_EXIT(rtio, sqe_acquire, r, &iodev_sqe->sqe);
378 return &iodev_sqe->sqe;
379}
380
393static inline int rtio_sqe_acquire_array(struct rtio *r, size_t n, struct rtio_sqe **sqes)
394{
395 struct rtio_iodev_sqe *iodev_sqe;
396 size_t i;
397
398 for (i = 0; i < n; i++) {
399 iodev_sqe = rtio_sqe_pool_alloc(r->sqe_pool);
400 if (iodev_sqe == NULL) {
401 break;
402 }
403 sqes[i] = &iodev_sqe->sqe;
404 }
405
406 /* Not enough SQEs in the pool */
407 if (i < n) {
408 while (i > 0) {
409 i--;
410 iodev_sqe = CONTAINER_OF(sqes[i], struct rtio_iodev_sqe, sqe);
411 rtio_sqe_pool_free(r->sqe_pool, iodev_sqe);
412 sqes[i] = NULL;
413 }
414
415 return -ENOMEM;
416 }
417
418 for (i = 0; i < n; i++) {
419 iodev_sqe = CONTAINER_OF(sqes[i], struct rtio_iodev_sqe, sqe);
420 mpsc_push(&r->sq, &iodev_sqe->q);
421 }
422
423 return 0;
424}
425
431static inline void rtio_sqe_drop_all(struct rtio *r)
432{
433 struct rtio_iodev_sqe *iodev_sqe;
434 struct mpsc_node *node = mpsc_pop(&r->sq);
435
436 while (node != NULL) {
437 iodev_sqe = CONTAINER_OF(node, struct rtio_iodev_sqe, q);
438 rtio_sqe_pool_free(r->sqe_pool, iodev_sqe);
439 node = mpsc_pop(&r->sq);
440 }
441}
442
446static inline struct rtio_cqe *rtio_cqe_acquire(struct rtio *r)
447{
448 SYS_PORT_TRACING_FUNC_ENTER(rtio, cqe_acquire, r);
449 struct rtio_cqe *cqe = rtio_cqe_pool_alloc(r->cqe_pool);
450
451 if (cqe == NULL) {
452 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_acquire, r, NULL);
453 return NULL;
454 }
455
456 memset(cqe, 0, sizeof(struct rtio_cqe));
457
458 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_acquire, r, cqe);
459 return cqe;
460}
461
478static inline int rtio_set_cqe_callback(struct rtio *r,
479 rtio_cqe_callback_t callback,
480 void *user_data)
481{
482#ifdef CONFIG_RTIO_CQE_CALLBACK
483 r->cqe_cb = callback;
484 r->cqe_cb_user_data = user_data;
485
486 return 0;
487#else
488 ARG_UNUSED(r);
489 ARG_UNUSED(callback);
490 ARG_UNUSED(user_data);
491
492 return -ENOTSUP;
493#endif
494}
495
499static inline void rtio_cqe_produce(struct rtio *r, struct rtio_cqe *cqe)
500{
501 mpsc_push(&r->cq, &cqe->q);
502}
503
515static inline struct rtio_cqe *rtio_cqe_consume(struct rtio *r)
516{
517 SYS_PORT_TRACING_FUNC_ENTER(rtio, cqe_consume, r);
518 struct mpsc_node *node;
519 struct rtio_cqe *cqe = NULL;
520
521#ifdef CONFIG_RTIO_CONSUME_SEM
522 if (k_sem_take(r->consume_sem, K_NO_WAIT) != 0) {
523 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_consume, r, NULL);
524 return NULL;
525 }
526#endif
527
528 node = mpsc_pop(&r->cq);
529 if (node == NULL) {
530 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_consume, r, NULL);
531 return NULL;
532 }
533 cqe = CONTAINER_OF(node, struct rtio_cqe, q);
534
535 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_consume, r, cqe);
536 return cqe;
537}
538
549static inline struct rtio_cqe *rtio_cqe_consume_block(struct rtio *r)
550{
551 struct mpsc_node *node;
552 struct rtio_cqe *cqe;
553
554#ifdef CONFIG_RTIO_CONSUME_SEM
555 k_sem_take(r->consume_sem, K_FOREVER);
556#endif
557 node = mpsc_pop(&r->cq);
558 while (node == NULL) {
559 Z_SPIN_DELAY(1);
560 node = mpsc_pop(&r->cq);
561 }
562 cqe = CONTAINER_OF(node, struct rtio_cqe, q);
563
564 return cqe;
565}
566
573static inline void rtio_cqe_release(struct rtio *r, struct rtio_cqe *cqe)
574{
575 SYS_PORT_TRACING_FUNC(rtio, cqe_release, r, cqe);
576 rtio_cqe_pool_free(r->cqe_pool, cqe);
577}
578
587static inline int rtio_flush_completion_queue(struct rtio *r)
588{
589 struct rtio_cqe *cqe;
590 int res = 0;
591
592 do {
593 cqe = rtio_cqe_consume(r);
594 if (cqe != NULL) {
595 if ((cqe->result < 0) && (res == 0)) {
596 res = cqe->result;
597 }
598 rtio_cqe_release(r, cqe);
599 }
600 } while (cqe != NULL);
601
602 return res;
603}
604
616__syscall void rtio_sqe_signal(struct rtio_sqe *sqe);
617
618static inline void z_impl_rtio_sqe_signal(struct rtio_sqe *sqe)
619{
620 struct rtio_iodev_sqe *iodev_sqe = CONTAINER_OF(sqe, struct rtio_iodev_sqe, sqe);
621
622 if (!atomic_cas(&iodev_sqe->rt.await.ok, 0, 1)) {
623 iodev_sqe->rt.await.callback(iodev_sqe, iodev_sqe->rt.await.userdata);
624 }
625}
626
633static inline uint32_t rtio_cqe_compute_flags(struct rtio_iodev_sqe *iodev_sqe)
634{
635 uint32_t flags = 0;
636
637#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
638 if (iodev_sqe->sqe.op == RTIO_OP_RX && iodev_sqe->sqe.flags & RTIO_SQE_MEMPOOL_BUFFER) {
639 struct rtio *r = iodev_sqe->r;
640 struct sys_mem_blocks *mem_pool = r->block_pool;
641 unsigned int blk_index = 0;
642 unsigned int blk_count = 0;
643
644 if (iodev_sqe->rt.rx_bind.buf) {
645 blk_index = (iodev_sqe->rt.rx_bind.buf - mem_pool->buffer) >>
646 mem_pool->info.blk_sz_shift;
647 blk_count = iodev_sqe->rt.rx_bind.buf_len >> mem_pool->info.blk_sz_shift;
648 }
649 flags = RTIO_CQE_FLAG_PREP_MEMPOOL(blk_index, blk_count);
650 }
651#else
652 ARG_UNUSED(iodev_sqe);
653#endif
654
655 return flags;
656}
657
673__syscall int rtio_cqe_get_mempool_buffer(const struct rtio *r, struct rtio_cqe *cqe,
674 uint8_t **buff, uint32_t *buff_len);
675
676static inline int z_impl_rtio_cqe_get_mempool_buffer(const struct rtio *r, struct rtio_cqe *cqe,
677 uint8_t **buff, uint32_t *buff_len)
678{
679#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
681 unsigned int blk_idx = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(cqe->flags);
682 unsigned int blk_count = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_CNT(cqe->flags);
683 uint32_t blk_size = rtio_mempool_block_size(r);
684
685 *buff_len = blk_count * blk_size;
686
687 if (blk_count > 0) {
688 *buff = r->block_pool->buffer + blk_idx * blk_size;
689
690 __ASSERT_NO_MSG(*buff >= r->block_pool->buffer);
691 __ASSERT_NO_MSG(*buff <
692 r->block_pool->buffer + blk_size * r->block_pool->info.num_blocks);
693 } else {
694 *buff = NULL;
695 }
696 return 0;
697 }
698 return -EINVAL;
699#else
700 ARG_UNUSED(r);
701 ARG_UNUSED(cqe);
702 ARG_UNUSED(buff);
703 ARG_UNUSED(buff_len);
704
705 return -ENOTSUP;
706#endif
707}
708
710
711void rtio_executor_submit(struct rtio *r);
712void rtio_executor_ok(struct rtio_iodev_sqe *iodev_sqe, int result);
713void rtio_executor_err(struct rtio_iodev_sqe *iodev_sqe, int result);
714
716
725static inline void rtio_iodev_sqe_ok(struct rtio_iodev_sqe *iodev_sqe, int result)
726{
727 rtio_executor_ok(iodev_sqe, result);
728}
729
738static inline void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int result)
739{
740 rtio_executor_err(iodev_sqe, result);
741}
742
754static inline void rtio_cqe_submit(struct rtio *r, int result, void *userdata, uint32_t flags)
755{
756 SYS_PORT_TRACING_FUNC_ENTER(rtio, cqe_submit, r, result, flags);
757 struct rtio_cqe *cqe = rtio_cqe_acquire(r);
758
759 if (cqe == NULL) {
760 atomic_inc(&r->xcqcnt);
761 } else {
762 cqe->result = result;
763 cqe->userdata = userdata;
764 cqe->flags = flags;
765 rtio_cqe_produce(r, cqe);
766#ifdef CONFIG_RTIO_CONSUME_SEM
767 k_sem_give(r->consume_sem);
768#endif
769#ifdef CONFIG_RTIO_CQE_CALLBACK
770 if (r->cqe_cb != NULL) {
771 r->cqe_cb(r, r->cqe_cb_user_data);
772 }
773#endif
774 }
775
776 /* atomic_t isn't guaranteed to wrap correctly as it could be signed, so
777 * we must resort to a cas loop.
778 */
779 atomic_t val, new_val;
780
781 do {
782 val = atomic_get(&r->cq_count);
783 new_val = (atomic_t)((uintptr_t)val + 1);
784 } while (!atomic_cas(&r->cq_count, val, new_val));
785
786#ifdef CONFIG_RTIO_SUBMIT_SEM
787 if (r->submit_count > 0) {
788 r->submit_count--;
789 if (r->submit_count == 0) {
790 k_sem_give(r->submit_sem);
791 }
792 }
793#endif
794 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_submit, r);
795}
796
797#define __RTIO_MEMPOOL_GET_NUM_BLKS(num_bytes, blk_size) (((num_bytes) + (blk_size)-1) / (blk_size))
798
811static inline int rtio_sqe_rx_buf(struct rtio_iodev_sqe *iodev_sqe, uint32_t min_buf_len,
812 uint32_t max_buf_len, uint8_t **buf, uint32_t *buf_len)
813{
814 const struct rtio_sqe *sqe = &iodev_sqe->sqe;
815
816#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
817 if (sqe->op == RTIO_OP_RX && sqe->flags & RTIO_SQE_MEMPOOL_BUFFER) {
818 struct rtio *r = iodev_sqe->r;
819
820 /* The mempool buffer is bound at runtime and kept in the wrapper so
821 * the submission description itself stays immutable.
822 */
823 if (iodev_sqe->rt.rx_bind.buf != NULL) {
824 if (iodev_sqe->rt.rx_bind.buf_len < min_buf_len) {
825 return -ENOMEM;
826 }
827 *buf = iodev_sqe->rt.rx_bind.buf;
828 *buf_len = iodev_sqe->rt.rx_bind.buf_len;
829 return 0;
830 }
831
832 int rc = rtio_block_pool_alloc(r, min_buf_len, max_buf_len, buf, buf_len);
833
834 if (rc == 0) {
835 iodev_sqe->rt.rx_bind.buf = *buf;
836 iodev_sqe->rt.rx_bind.buf_len = *buf_len;
837 return 0;
838 }
839
840 return -ENOMEM;
841 }
842#else
843 ARG_UNUSED(max_buf_len);
844#endif
845
846 if (sqe->rx.buf_len < min_buf_len) {
847 return -ENOMEM;
848 }
849
850 *buf = sqe->rx.buf;
851 *buf_len = sqe->rx.buf_len;
852 return 0;
853}
854
869__syscall void rtio_release_buffer(struct rtio *r, void *buff, uint32_t buff_len);
870
871static inline void z_impl_rtio_release_buffer(struct rtio *r, void *buff, uint32_t buff_len)
872{
873#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
874 if (r == NULL || buff == NULL || r->block_pool == NULL || buff_len == 0) {
875 return;
876 }
877
878 rtio_block_pool_free(r, buff, buff_len);
879#else
880 ARG_UNUSED(r);
881 ARG_UNUSED(buff);
882 ARG_UNUSED(buff_len);
883#endif
884}
885
892static inline void rtio_access_grant(struct rtio *r, struct k_thread *t)
893{
895
896#ifdef CONFIG_RTIO_SUBMIT_SEM
897 k_object_access_grant(r->submit_sem, t);
898#endif
899
900#ifdef CONFIG_RTIO_CONSUME_SEM
901 k_object_access_grant(r->consume_sem, t);
902#endif
903
904#ifdef CONFIG_RTIO_OP_DELAY
905 /* Delay submissions are dispatched to the shared timeout iodev, so a thread
906 * allowed to use this context must also be able to reference it.
907 */
908 k_object_access_grant(&rtio_timeout_iodev, t);
909#endif
910}
911
912
919static inline void rtio_access_revoke(struct rtio *r, struct k_thread *t)
920{
922
923#ifdef CONFIG_RTIO_SUBMIT_SEM
924 k_object_access_revoke(r->submit_sem, t);
925#endif
926
927#ifdef CONFIG_RTIO_CONSUME_SEM
928 k_object_access_revoke(r->consume_sem, t);
929#endif
930
931#ifdef CONFIG_RTIO_OP_DELAY
932 k_object_access_revoke(&rtio_timeout_iodev, t);
933#endif
934}
935
948static inline rtio_sqe_handle_t rtio_sqe_handle(const struct rtio *r, const struct rtio_sqe *sqe)
949{
950 const struct rtio_iodev_sqe *iodev_sqe = CONTAINER_OF(sqe, struct rtio_iodev_sqe, sqe);
951 uint32_t blk_index = (uint32_t)(iodev_sqe - r->sqe_pool->pool);
952 uint32_t gen = (uint32_t)(atomic_get(&iodev_sqe->status) & RTIO_SQE_GEN_MASK);
953
954 return (blk_index << 16) | gen;
955}
956
970static inline struct rtio_iodev_sqe *rtio_iodev_sqe_from_handle(struct rtio *r,
971 rtio_sqe_handle_t handle)
972{
973 uint32_t blk_index = handle >> 16;
974 uint32_t gen = handle & RTIO_SQE_GEN_MASK;
975
976 if (blk_index >= r->sqe_pool->pool_size) {
977 return NULL;
978 }
979
980 struct rtio_iodev_sqe *iodev_sqe = &r->sqe_pool->pool[blk_index];
981 atomic_val_t status = atomic_get(&iodev_sqe->status);
982
983 if ((status & RTIO_SQE_ALLOCD) == 0 || (uint32_t)(status & RTIO_SQE_GEN_MASK) != gen) {
984 return NULL;
985 }
986
987 return iodev_sqe;
988}
989
1023__syscall int rtio_sqe_cancel(struct rtio *r, rtio_sqe_handle_t handle);
1024
1025static inline int z_impl_rtio_sqe_cancel(struct rtio *r, rtio_sqe_handle_t handle)
1026{
1027 SYS_PORT_TRACING_FUNC(rtio, sqe_cancel, handle);
1028
1029 uint16_t blk_index = rtio_sqe_handle_index(handle);
1031
1032 if (blk_index >= r->sqe_pool->pool_size) {
1033 return 0;
1034 }
1035
1036 struct rtio_iodev_sqe *iodev_sqe = &r->sqe_pool->pool[blk_index];
1037
1038 /* Validate identity and mark canceled in one atomic step so a concurrent
1039 * completion cannot recycle the slot between the check and the mark: if
1040 * the entry is freed meanwhile the CAS fails and the re-read observes the
1041 * bumped generation, turning the cancel into a no-op.
1042 */
1043 while (true) {
1044 atomic_val_t status = atomic_get(&iodev_sqe->status);
1045
1046 if ((status & RTIO_SQE_ALLOCD) == 0 ||
1047 (uint16_t)(status & RTIO_SQE_GEN_MASK) != gen) {
1048 return 0;
1049 }
1050
1051 if (atomic_cas(&iodev_sqe->status, status,
1053 break;
1054 }
1055 }
1056
1057 /* Give the iodev a chance to abort a submission it is already sitting on,
1058 * which nothing else would wake.
1059 *
1060 * The entry is not owned here, so re-read the status after taking the iodev
1061 * out of it: every free bumps the generation, so an unchanged generation
1062 * proves no completion recycled the slot in between and the iodev really is
1063 * this submission's. The hook is handed the handle rather than the entry,
1064 * because the entry may still be completed before the hook runs; the iodev
1065 * resolves the handle under its own lock.
1066 */
1067 const struct rtio_iodev *iodev = iodev_sqe->sqe.iodev;
1068 atomic_val_t status = atomic_get(&iodev_sqe->status);
1069
1070 if ((status & RTIO_SQE_ALLOCD) == 0 || (uint16_t)(status & RTIO_SQE_GEN_MASK) != gen) {
1071 return 0;
1072 }
1073
1074 if (iodev != NULL && iodev->api->cancel != NULL) {
1075 iodev->api->cancel(iodev, r, handle);
1076 }
1077
1078 return 0;
1079}
1080
1100__syscall int rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes,
1101 rtio_sqe_handle_t *handles, size_t sqe_count);
1102
1103static inline int z_impl_rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes,
1104 rtio_sqe_handle_t *handles,
1105 size_t sqe_count)
1106{
1107 struct rtio_sqe *sqe;
1108 uint32_t acquirable = rtio_sqe_acquirable(r);
1109
1110 if (acquirable < sqe_count) {
1111 return -ENOMEM;
1112 }
1113
1114 for (unsigned long i = 0; i < sqe_count; i++) {
1115 sqe = rtio_sqe_acquire(r);
1116 __ASSERT_NO_MSG(sqe != NULL);
1117 if (handles != NULL) {
1118 handles[i] = rtio_sqe_handle(r, sqe);
1119 }
1120 *sqe = sqes[i];
1121 }
1122
1123 return 0;
1124}
1125
1142static inline int rtio_sqe_copy_in(struct rtio *r, const struct rtio_sqe *sqes, size_t sqe_count)
1143{
1144 return rtio_sqe_copy_in_get_handles(r, sqes, NULL, sqe_count);
1145}
1146
1162__syscall int rtio_cqe_copy_out(struct rtio *r,
1163 struct rtio_cqe *cqes,
1164 size_t cqe_count,
1165 k_timeout_t timeout);
1166static inline int z_impl_rtio_cqe_copy_out(struct rtio *r,
1167 struct rtio_cqe *cqes,
1168 size_t cqe_count,
1169 k_timeout_t timeout)
1170{
1171 size_t copied = 0;
1172 struct rtio_cqe *cqe;
1173 k_timepoint_t end = sys_timepoint_calc(timeout);
1174
1175 do {
1176 cqe = K_TIMEOUT_EQ(timeout, K_FOREVER) ? rtio_cqe_consume_block(r)
1177 : rtio_cqe_consume(r);
1178 if (cqe == NULL) {
1179 Z_SPIN_DELAY(25);
1180 continue;
1181 }
1182 cqes[copied++] = *cqe;
1183 rtio_cqe_release(r, cqe);
1184 } while (copied < cqe_count && !sys_timepoint_expired(end));
1185
1186 return copied;
1187}
1188
1206__syscall int rtio_submit(struct rtio *r, uint32_t wait_count);
1207
1208#ifdef CONFIG_RTIO_SUBMIT_SEM
1209static inline int z_impl_rtio_submit(struct rtio *r, uint32_t wait_count)
1210{
1211 SYS_PORT_TRACING_FUNC_ENTER(rtio, submit, r, wait_count);
1212 int res = 0;
1213
1214 if (wait_count > 0) {
1215 __ASSERT(!k_is_in_isr(),
1216 "expected rtio submit with wait count to be called from a thread");
1217
1218 k_sem_reset(r->submit_sem);
1219 r->submit_count = wait_count;
1220 }
1221
1222 rtio_executor_submit(r);
1223
1224 if (wait_count > 0) {
1225 res = k_sem_take(r->submit_sem, K_FOREVER);
1226 __ASSERT(res == 0,
1227 "semaphore was reset or timed out while waiting on completions!");
1228 }
1229
1230 SYS_PORT_TRACING_FUNC_EXIT(rtio, submit, r);
1231 return res;
1232}
1233#else
1234static inline int z_impl_rtio_submit(struct rtio *r, uint32_t wait_count)
1235{
1236
1237 SYS_PORT_TRACING_FUNC_ENTER(rtio, submit, r, wait_count);
1238 int res = 0;
1239 uintptr_t cq_count = (uintptr_t)atomic_get(&r->cq_count);
1240 uintptr_t cq_complete_count = cq_count + wait_count;
1241 bool wraps = cq_complete_count < cq_count;
1242
1243 rtio_executor_submit(r);
1244
1245 if (wraps) {
1246 while ((uintptr_t)atomic_get(&r->cq_count) >= cq_count) {
1247 Z_SPIN_DELAY(10);
1248 k_yield();
1249 }
1250 }
1251
1252 while ((uintptr_t)atomic_get(&r->cq_count) < cq_complete_count) {
1253 Z_SPIN_DELAY(10);
1254 k_yield();
1255 }
1256
1257 SYS_PORT_TRACING_FUNC_EXIT(rtio, submit, r);
1258 return res;
1259}
1260#endif /* CONFIG_RTIO_SUBMIT_SEM */
1261
1268
1270 struct rtio **contexts;
1271
1274};
1275
1284__syscall struct rtio *rtio_pool_acquire(struct rtio_pool *pool);
1285
1286static inline struct rtio *z_impl_rtio_pool_acquire(struct rtio_pool *pool)
1287{
1288 struct rtio *r = NULL;
1289
1290 for (size_t i = 0; i < pool->pool_size; i++) {
1291 if (atomic_test_and_set_bit(pool->used, i) == 0) {
1292 r = pool->contexts[i];
1293 break;
1294 }
1295 }
1296
1297 if (r != NULL) {
1299 }
1300
1301 return r;
1302}
1303
1310__syscall void rtio_pool_release(struct rtio_pool *pool, struct rtio *r);
1311
1312static inline void z_impl_rtio_pool_release(struct rtio_pool *pool, struct rtio *r)
1313{
1314
1315 if (k_is_user_context()) {
1317 }
1318
1319 for (size_t i = 0; i < pool->pool_size; i++) {
1320 if (pool->contexts[i] == r) {
1321 atomic_clear_bit(pool->used, i);
1322 break;
1323 }
1324 }
1325}
1326
1327/* clang-format off */
1328
1330
1331#define Z_RTIO_POOL_NAME_N(n, name) \
1332 name##_##n
1333
1334#define Z_RTIO_POOL_DEFINE_N(n, name, sq_sz, cq_sz) \
1335 RTIO_DEFINE(Z_RTIO_POOL_NAME_N(n, name), sq_sz, cq_sz)
1336
1337#define Z_RTIO_POOL_REF_N(n, name) \
1338 &Z_RTIO_POOL_NAME_N(n, name)
1339
1341
1350#define RTIO_POOL_DEFINE(name, pool_sz, sq_sz, cq_sz) \
1351 LISTIFY(pool_sz, Z_RTIO_POOL_DEFINE_N, (;), name, sq_sz, cq_sz); \
1352 static struct rtio *name##_contexts[] = { \
1353 LISTIFY(pool_sz, Z_RTIO_POOL_REF_N, (,), name) \
1354 }; \
1355 ATOMIC_DEFINE(name##_used, pool_sz); \
1356 STRUCT_SECTION_ITERABLE(rtio_pool, name) = { \
1357 .pool_size = pool_sz, \
1358 .contexts = name##_contexts, \
1359 .used = name##_used, \
1360 }
1361
1362/* clang-format on */
1363
1367
1368#ifdef __cplusplus
1369}
1370#endif
1371
1372#include <zephyr/syscalls/rtio.h>
1373
1374#endif /* ZEPHYR_INCLUDE_RTIO_RTIO_H_ */
Header file for the Atomic operations API.
RTIO Completion Queue Events and Related Functions.
APIs and macros for the Zephyr device model.
static _Bool atomic_test_and_set_bit(atomic_t *target, int bit)
Atomically set a bit and test it.
Definition atomic.h:181
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
static void atomic_clear_bit(atomic_t *target, int bit)
Atomically clear a bit.
Definition atomic.h:227
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_inc(atomic_t *target)
Atomic increment.
_Bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
Atomic compare-and-set.
#define K_FOREVER
Generate infinite timeout delay.
Definition kernel.h:1727
#define K_NO_WAIT
Generate null timeout delay.
Definition kernel.h:1617
k_timepoint_t sys_timepoint_calc(k_timeout_t timeout)
Calculate a timepoint value.
static bool sys_timepoint_expired(k_timepoint_t timepoint)
Indicates if timepoint is expired.
Definition clock.h:386
#define K_TIMEOUT_EQ(a, b)
Compare timeouts for equality.
Definition clock.h:80
bool k_is_in_isr(void)
Determine if code is running at interrupt level.
int sys_mem_blocks_free_contiguous(sys_mem_blocks_t *mem_block, void *block, size_t count)
Free contiguous multiple memory blocks.
int sys_mem_blocks_alloc_contiguous(sys_mem_blocks_t *mem_block, size_t count, void **out_block)
Allocate a contiguous set of memory blocks.
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_CQE_FLAG_MEMPOOL_GET_BLK_CNT(flags)
Get the block count of a mempool flags.
Definition cqe.h:70
#define RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(flags)
Get the block index of a mempool flags.
Definition cqe.h:62
#define RTIO_CQE_FLAG_MEMPOOL_BUFFER
The entry's buffer was allocated from the RTIO's mempool.
Definition cqe.h:46
#define RTIO_CQE_FLAG_PREP_MEMPOOL(blk_idx, blk_cnt)
Prepare CQE flags for a mempool read.
Definition cqe.h:79
#define RTIO_CQE_FLAG_GET(flags)
Get the flag bits of a CQE flags value.
Definition cqe.h:54
#define RTIO_OP_RX
An operation that receives (reads).
Definition sqe.h:157
#define RTIO_SQE_MEMPOOL_BUFFER
The buffer should be allocated by the RTIO mempool.
Definition sqe.h:112
void rtio_pool_release(struct rtio_pool *pool, struct rtio *r)
Return an RTIO context to a pool.
static struct rtio_iodev_sqe * rtio_iodev_sqe_from_handle(struct rtio *r, rtio_sqe_handle_t handle)
Resolve a handle to a live submission, validating identity.
Definition rtio.h:970
static uint32_t rtio_sqe_acquirable(struct rtio *r)
Count of acquirable submission queue events.
Definition rtio.h:352
struct rtio * rtio_pool_acquire(struct rtio_pool *pool)
Obtain an RTIO context from a pool.
#define RTIO_SQE_ALLOCD
Set while the entry is allocated from the pool (i.e.
Definition sqe.h:436
static size_t rtio_mempool_block_size(const struct rtio *r)
Get the mempool block size of the RTIO context.
Definition rtio.h:177
static void rtio_cqe_submit(struct rtio *r, int result, void *userdata, uint32_t flags)
Submit a completion queue event with a given result and userdata.
Definition rtio.h:754
static rtio_sqe_handle_t rtio_sqe_handle(const struct rtio *r, const struct rtio_sqe *sqe)
Capture an opaque, validatable handle for a live submission.
Definition rtio.h:948
void rtio_release_buffer(struct rtio *r, void *buff, uint32_t buff_len)
Release memory that was allocated by the RTIO's memory pool.
static int rtio_sqe_copy_in(struct rtio *r, const struct rtio_sqe *sqes, size_t sqe_count)
Copy an array of SQEs into the queue.
Definition rtio.h:1142
void(* rtio_cqe_callback_t)(struct rtio *r, void *user_data)
RTIO completion queue event callback.
Definition rtio.h:72
static int rtio_sqe_rx_buf(struct rtio_iodev_sqe *iodev_sqe, uint32_t min_buf_len, uint32_t max_buf_len, uint8_t **buf, uint32_t *buf_len)
Get the buffer associate with the RX submission.
Definition rtio.h:811
static void rtio_cqe_produce(struct rtio *r, struct rtio_cqe *cqe)
Produce a complete queue event if available.
Definition rtio.h:499
#define RTIO_SQE_GEN_MASK
Generation counter; bumped on free, compared against a handle's generation.
Definition sqe.h:434
static uint32_t rtio_cqe_compute_flags(struct rtio_iodev_sqe *iodev_sqe)
Compute the CQE flags from the rtio_iodev_sqe entry.
Definition rtio.h:633
int rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes, rtio_sqe_handle_t *handles, size_t sqe_count)
Copy an array of SQEs into the queue and get resulting handles back.
uint32_t rtio_sqe_handle_t
Opaque identity for a submission queue entry.
Definition sqe.h:331
struct k_mem_partition rtio_partition
The memory partition associated with all RTIO context information.
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition rtio.h:365
static uint16_t rtio_sqe_handle_generation(rtio_sqe_handle_t handle)
Generation counter encoded in a handle.
Definition sqe.h:458
static void rtio_sqe_drop_all(struct rtio *r)
Drop all previously acquired sqe.
Definition rtio.h:431
int rtio_cqe_copy_out(struct rtio *r, struct rtio_cqe *cqes, size_t cqe_count, k_timeout_t timeout)
Copy an array of CQEs from the queue.
static int rtio_flush_completion_queue(struct rtio *r)
Flush completion queue.
Definition rtio.h:587
static void rtio_access_revoke(struct rtio *r, struct k_thread *t)
Revoke access to an RTIO context from a user thread.
Definition rtio.h:919
static void rtio_access_grant(struct rtio *r, struct k_thread *t)
Grant access to an RTIO context to a user thread.
Definition rtio.h:892
int rtio_sqe_cancel(struct rtio *r, rtio_sqe_handle_t handle)
Attempt to cancel an SQE.
#define RTIO_SQE_STATUS_CANCELED
Set when cancellation of the submission has been requested.
Definition sqe.h:438
static void rtio_cqe_release(struct rtio *r, struct rtio_cqe *cqe)
Release consumed completion queue event.
Definition rtio.h:573
static uint16_t rtio_sqe_handle_index(rtio_sqe_handle_t handle)
Pool block index encoded in a handle.
Definition sqe.h:447
static int rtio_set_cqe_callback(struct rtio *r, rtio_cqe_callback_t callback, void *user_data)
Set the completion queue event callback.
Definition rtio.h:478
static void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int result)
Inform the executor of a submissions completion with error.
Definition rtio.h:738
static void rtio_iodev_sqe_ok(struct rtio_iodev_sqe *iodev_sqe, int result)
Inform the executor of a submission completion with success.
Definition rtio.h:725
static struct rtio_cqe * rtio_cqe_acquire(struct rtio *r)
Acquire a complete queue event if available.
Definition rtio.h:446
static struct rtio_cqe * rtio_cqe_consume(struct rtio *r)
Consume a single completion queue event if available.
Definition rtio.h:515
void rtio_sqe_signal(struct rtio_sqe *sqe)
Signal an AWAIT SQE.
int rtio_cqe_get_mempool_buffer(const struct rtio *r, struct rtio_cqe *cqe, uint8_t **buff, uint32_t *buff_len)
Retrieve the mempool buffer that was allocated for the CQE.
static struct rtio_cqe * rtio_cqe_consume_block(struct rtio *r)
Wait for and consume a single completion queue event.
Definition rtio.h:549
static int rtio_sqe_acquire_array(struct rtio *r, size_t n, struct rtio_sqe **sqes)
Acquire a number of submission queue events if available.
Definition rtio.h:393
int rtio_submit(struct rtio *r, uint32_t wait_count)
Submit I/O requests to the underlying executor.
void k_sem_reset(struct k_sem *sem)
Resets a semaphore's count to zero.
void k_sem_give(struct k_sem *sem)
Give a semaphore.
int k_sem_take(struct k_sem *sem, k_timeout_t timeout)
Take a semaphore.
#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 SYS_PORT_TRACING_FUNC(type, func,...)
Tracing macro for function calls which are not directly associated with a specific type of object.
Definition tracing_macros.h:233
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a structure containing the element.
Definition util.h:281
#define DIV_ROUND_UP(n, d)
Divide and round up.
Definition util.h:348
#define EINVAL
Invalid argument.
Definition errno.h:61
#define ENOMEM
Not enough core.
Definition errno.h:51
#define ENOTSUP
Unsupported value.
Definition errno.h:115
void k_yield(void)
Yield the current thread.
static __attribute_const__ k_tid_t k_current_get(void)
Get thread ID of the current thread.
Definition kernel.h:859
void k_object_access_grant(const void *object, struct k_thread *thread)
Grant a thread access to a kernel object.
void k_object_access_revoke(const void *object, struct k_thread *thread)
Revoke a thread's access to a kernel object.
RTIO I/O Device and Related Functions.
Public kernel APIs.
Memory Blocks Allocator.
flags
Definition parser.h:86
RTIO Submission Queue Events and Related Functions.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
#define UINT16_MAX
Definition stdint.h:28
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
Memory Partition.
Definition mem_domain.h:55
Semaphore structure.
Definition kernel.h:3752
Thread Structure.
Definition thread.h:258
Kernel timeout type.
Definition clock.h:65
Kernel timepoint type.
Definition clock.h:289
Queue member.
Definition mpsc_lockfree.h:79
MPSC Queue.
Definition mpsc_lockfree.h:86
A completion queue event.
Definition cqe.h:90
void * userdata
Associated userdata with operation.
Definition cqe.h:96
uint32_t flags
Flags associated with the operation.
Definition cqe.h:97
int32_t result
Result from operation.
Definition cqe.h:95
void(* cancel)(const struct rtio_iodev *iodev, struct rtio *r, rtio_sqe_handle_t handle)
Attempt to actively cancel a previously submitted entry.
Definition iodev.h:77
IO device submission queue entry.
Definition sqe.h:468
struct rtio_sqe sqe
The submission queue entry this wraps.
Definition sqe.h:470
uint8_t * buf
Buffer allocated for the read.
Definition sqe.h:490
struct rtio * r
RTIO context that owns this entry.
Definition sqe.h:476
atomic_t ok
Set once the awaited signal arrives.
Definition sqe.h:496
void * userdata
Opaque pointer passed to the callback.
Definition sqe.h:498
uint32_t buf_len
Length of the allocated buffer.
Definition sqe.h:491
struct rtio_iodev_sqe::@236333123355174166163204241333175337261032350217::@217311152202063235124050024351200371271201317264 rx_bind
OP_RX buffer bound at runtime (see RTIO_SQE_MEMPOOL_BUFFER).
atomic_t status
Identity + lifetime word (generation | ALLOCD), see RTIO_SQE_* bits above.
Definition sqe.h:479
struct rtio_iodev_sqe::@236333123355174166163204241333175337261032350217::@173144226234072317163120356060015135125010037312 await
OP_AWAIT signaling state.
struct mpsc_node q
Node used to link the entry into the pool free list and iodev queues.
Definition sqe.h:472
union rtio_iodev_sqe::@236333123355174166163204241333175337261032350217 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:497
An IO device with a function table for submitting requests.
Definition iodev.h:83
const struct rtio_iodev_api * api
Function pointer table.
Definition iodev.h:85
Pool of RTIO contexts to use with dynamically created threads.
Definition rtio.h:1265
struct rtio ** contexts
Array containing contexts of the pool.
Definition rtio.h:1270
atomic_t * used
Atomic bitmap to signal a member is used/unused.
Definition rtio.h:1273
size_t pool_size
Size of the pool.
Definition rtio.h:1267
A submission queue event.
Definition sqe.h:346
uint8_t op
Op code.
Definition sqe.h:347
struct rtio_sqe::@126267262255374054123217063150244034155174062054::@222067021034074304061254367152327164076222165070 rx
OP_RX.
uint32_t buf_len
Length of buffer.
Definition sqe.h:371
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:355
uint16_t flags
Op Flags.
Definition sqe.h:351
const uint8_t * buf
Buffer to write from.
Definition sqe.h:372
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:85
struct rtio_cqe_pool * cqe_pool
Completion queue object pool with free list.
Definition rtio.h:113
struct mpsc sq
Submission queue.
Definition rtio.h:121
atomic_t cq_count
Total number of completions.
Definition rtio.h:104
struct rtio_sqe_pool * sqe_pool
Submission queue object pool with free list.
Definition rtio.h:110
atomic_t xcqcnt
Number of completions dropped because no CQE was available.
Definition rtio.h:107
struct mpsc cq
Completion queue.
Definition rtio.h:124
Iterable sections helpers.
Misc utilities.
static bool k_is_user_context(void)
Indicate whether the CPU is currently in user mode.
Definition syscall.h:120