# Copyright (c) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

menuconfig RTIO
	bool "RTIO"

if RTIO

config RTIO_SUBMIT_SEM
	bool "Use a semaphore when waiting for completions in rtio_submit"
	default n if !MULTITHREADING
	default y
	help
	  When calling rtio_submit a semaphore is available to sleep the calling
	  thread for each completion queue event until the wait count is met. This
	  adds a small RAM overhead for a single semaphore. By default wait_for will
	  use polling on the completion queue with a k_yield() in between iterations.

	  Enabled by default unless !MULTITHREADING

config RTIO_CONSUME_SEM
	bool "Use a semaphore when waiting for completions in rtio_cqe_consume_block"
	default n if !MULTITHREADING
	default y
	help
	  When calling rtio_cqe_consume_block a semaphore is available to sleep the
	  calling thread for each completion queue event until the wait count is met.
	  This adds a small RAM overhead for a single semaphore. By default the call
	  will use polling on the completion queue with a k_yield() in between
	  iterations.

	  Enabled by default unless !MULTIHREADING

config RTIO_SYS_MEM_BLOCKS
	bool "Include system memory blocks as an optional backing read memory pool"
	select SYS_MEM_BLOCKS
	help
	  Enable the RTIO_DEFINE_WITH_MEMPOOL macro which allows queueing reads
	  without a pre-allocated memory buffer. Instead the buffer will be taken
	  from the allocated memory pool associated with the RTIO context.

config RTIO_OP_DELAY
	bool "Delay Operation"
	default y
	help
	  Enable OP_DELAY which allows for, in chains of operations, delaying using a
	  kernel timeout. Delays are handled by a shared timeout iodev, so enabling
	  this does not embed a timeout in each submission queue entry.

config RTIO_SQE_CACHELINE_CHECK
	bool "SQE Cacheline size check"
	help
	  At build time check the size of struct rtio_sqe to ensure it is less than a
	  cache line otherwise the build will fail. This ensures high performance on
	  systems that are sensitive to data cache effects.

choice RTIO_BLOCK_POOL_PLACEMENT
	prompt "RTIO block pool placement"
	default RTIO_BLOCK_POOL_PLACEMENT_DTCM if $(dt_chosen_enabled,$(DT_CHOSEN_Z_DTCM))
	default RTIO_BLOCK_POOL_PLACEMENT_NOCACHE if NOCACHE_MEMORY
	default RTIO_BLOCK_POOL_PLACEMENT_DEFAULT
	help
	  Select where the RTIO block pool is placed.

	  - Default: placed in normal data/BSS
	  - DTCM: placed in DTCM sections (uncached)
	  - No-cache: placed in explicitly non-cacheable sections

config RTIO_BLOCK_POOL_PLACEMENT_DEFAULT
	bool "Default data memory"
	help
	  Place RTIO block pool in the default data/BSS memory region.

config RTIO_BLOCK_POOL_PLACEMENT_DTCM
	bool "DTCM (uncached)"
	depends on $(dt_chosen_enabled,$(DT_CHOSEN_Z_DTCM))
	help
	  Place RTIO block pool in DTCM. On supported architectures DTCM is
	  inherently uncached and typically needs no extra cache maintenance.

config RTIO_BLOCK_POOL_PLACEMENT_NOCACHE
	bool "Non-cacheable memory (NOCACHE)"
	depends on NOCACHE_MEMORY
	help
	  Place RTIO block pool in a non-cacheable memory region. This assumes
	  the board/linker provides corresponding no-cache data/bss sections.

endchoice

choice RTIO_SQE_PLACEMENT
	prompt "RTIO SQE placement"
	default RTIO_SQE_PLACEMENT_DTCM if $(dt_chosen_enabled,$(DT_CHOSEN_Z_DTCM))
	default RTIO_SQE_PLACEMENT_NOCACHE if NOCACHE_MEMORY
	default RTIO_SQE_PLACEMENT_DEFAULT

config RTIO_SQE_PLACEMENT_DEFAULT
	bool "Default data memory"

config RTIO_SQE_PLACEMENT_DTCM
	bool "DTCM (uncached)"
	depends on $(dt_chosen_enabled,$(DT_CHOSEN_Z_DTCM))
	help
	  Place SQE ring in a linker memory region named DTCM (uncached,
	  low-latency)

config RTIO_SQE_PLACEMENT_NOCACHE
	bool "Non-cacheable memory (NOCACHE)"
	depends on NOCACHE_MEMORY
	help
	  Place SQE ring in Zephyr's no-cache region to avoid D-cache
	  coherency side effects for tiny transfers.

endchoice

rsource "Kconfig.workq"

module = RTIO
module-str = RTIO
module-help = Sets log level for RTIO support
source "subsys/logging/Kconfig.template.log_config"

endif
