From b1c312eced6e45d542d98bba43cfb4f44a19140e Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Fri, 21 Oct 2022 12:42:11 +0300 Subject: api: shm: add segment info Added odp_shm_segment_info() which can be used to retrieve information of each memory segment of an SHM block. Signed-off-by: Petri Savolainen Reviewed-by: Harman Kalra Reviewed-by: Tuomas Taipale --- include/odp/api/abi-default/shared_memory.h | 3 + include/odp/api/spec/shared_memory.h | 65 ++++++++++++++++++++++ .../include-abi/odp/api/abi/shared_memory.h | 3 + 3 files changed, 71 insertions(+) diff --git a/include/odp/api/abi-default/shared_memory.h b/include/odp/api/abi-default/shared_memory.h index fdc93ea1d..4668927cd 100644 --- a/include/odp/api/abi-default/shared_memory.h +++ b/include/odp/api/abi-default/shared_memory.h @@ -23,6 +23,9 @@ typedef _odp_abi_shm_t *odp_shm_t; #define ODP_SHM_INVALID ((odp_shm_t)0) #define ODP_SHM_NAME_LEN 32 +#define ODP_SHM_IOVA_INVALID ((uint64_t)-1) +#define ODP_SHM_PA_INVALID ODP_SHM_IOVA_INVALID + /** * @} */ diff --git a/include/odp/api/spec/shared_memory.h b/include/odp/api/spec/shared_memory.h index d1955db26..c1ca724c9 100644 --- a/include/odp/api/spec/shared_memory.h +++ b/include/odp/api/spec/shared_memory.h @@ -42,6 +42,16 @@ extern "C" { /* Shared memory flags */ +/** + * @def ODP_SHM_IOVA_INVALID + * Invalid IOVA address + */ + +/** + * @def ODP_SHM_PA_INVALID + * Invalid physical address + */ + /** * Application SW only, no HW access * @@ -123,8 +133,42 @@ typedef struct odp_shm_info_t { /** ODP_SHM_* flags */ uint32_t flags; + + /** + * Number of memory segments + * + * Number of segments in physical (or IOVA) address space that map memory to + * the SHM block. More information about each segment can be retrieved with + * odp_shm_segment_info(). Number of segments is always at least one, also when + * physical (or IOVA) segmentation information is not available. */ + uint32_t num_seg; + } odp_shm_info_t; +/** + * SHM memory segment info + */ +typedef struct odp_shm_segment_info_t { + /** Segment start address (virtual) */ + uintptr_t addr; + + /** Segment start address in IO virtual address (IOVA) space + * + * Value is ODP_SHM_IOVA_INVALID when IOVA address is not available. + */ + uint64_t iova; + + /** Segment start address in physical address space + * + * Value is ODP_SHM_PA_INVALID when physical address is not available. + */ + uint64_t pa; + + /** Segment length in bytes */ + uint64_t len; + +} odp_shm_segment_info_t; + /** * Shared memory capabilities */ @@ -261,6 +305,27 @@ void *odp_shm_addr(odp_shm_t shm); */ int odp_shm_info(odp_shm_t shm, odp_shm_info_t *info); +/** + * SHM block segmentation information + * + * Retrieve information about each memory segment of an SHM block. SHM info call outputs the number + * of memory segments (@see odp_shm_info_t.num_seg). A single segment info call may be used + * to request information for all the segments, or for a subset of those. Use 'index' and 'num' + * parameters to specify the segments. Segment indexing starts from zero and continues to + * odp_shm_info_t.num_seg - 1. Segment infos are written in virtual memory address order and + * without address overlaps. Segment info array must have at least 'num' elements. + * + * @param shm SHM block handle + * @param index Index of the first segment to retrieve information + * @param num Number of segments to retrieve information + * @param[out] info Segment info array for output + * + * @retval 0 on success + * @retval <0 on failure + */ +int odp_shm_segment_info(odp_shm_t shm, uint32_t index, uint32_t num, + odp_shm_segment_info_t info[]); + /** * Print all shared memory blocks */ diff --git a/platform/linux-generic/include-abi/odp/api/abi/shared_memory.h b/platform/linux-generic/include-abi/odp/api/abi/shared_memory.h index 648bd1ee3..551d49e30 100644 --- a/platform/linux-generic/include-abi/odp/api/abi/shared_memory.h +++ b/platform/linux-generic/include-abi/odp/api/abi/shared_memory.h @@ -31,6 +31,9 @@ typedef ODP_HANDLE_T(odp_shm_t); #define ODP_SHM_NAME_LEN 32 +#define ODP_SHM_IOVA_INVALID ((uint64_t)-1) +#define ODP_SHM_PA_INVALID ODP_SHM_IOVA_INVALID + /** * @} */ -- cgit v1.2.3