The shared memory DRV interface is created, mostly as a wrapper around the internal memory allocator, ishm.
Signed-off-by: Christophe Milard <christophe.mil...@linaro.org> --- include/odp_drv.h | 1 + platform/linux-generic/Makefile.am | 3 + platform/linux-generic/_ishm.c | 6 +- platform/linux-generic/drv_shm.c | 102 +++++++++++++++++++++ .../linux-generic/include/odp/drv/plat/shm_types.h | 46 ++++++++++ platform/linux-generic/include/odp/drv/shm.h | 36 ++++++++ .../linux-generic/include/odp_config_internal.h | 6 ++ 7 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 platform/linux-generic/drv_shm.c create mode 100644 platform/linux-generic/include/odp/drv/plat/shm_types.h create mode 100644 platform/linux-generic/include/odp/drv/shm.h diff --git a/include/odp_drv.h b/include/odp_drv.h index 31c620e..0959879 100644 --- a/include/odp_drv.h +++ b/include/odp_drv.h @@ -23,6 +23,7 @@ extern C { #include <odp/drv/barrier.h> #include <odp/drv/byteorder.h> #include <odp/drv/compiler.h> +#include <odp/drv/shm.h> #include <odp/drv/spinlock.h> #include <odp/drv/std_types.h> #include <odp/drv/sync.h> diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index ac2b2da..4d9b84b 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -99,6 +99,7 @@ odpdrvinclude_HEADERS = \ $(srcdir)/include/odp/drv/barrier.h \ $(srcdir)/include/odp/drv/byteorder.h \ $(srcdir)/include/odp/drv/compiler.h \ + $(srcdir)/include/odp/drv/shm.h \ $(srcdir)/include/odp/drv/spinlock.h \ $(srcdir)/include/odp/drv/std_types.h \ $(srcdir)/include/odp/drv/sync.h @@ -108,6 +109,7 @@ odpdrvplatinclude_HEADERS = \ $(srcdir)/include/odp/drv/plat/atomic_types.h \ $(srcdir)/include/odp/drv/plat/barrier_types.h \ $(srcdir)/include/odp/drv/plat/byteorder_types.h \ + $(srcdir)/include/odp/drv/plat/shm_types.h \ $(srcdir)/include/odp/drv/plat/spinlock_types.h \ $(srcdir)/include/odp/drv/plat/strong_types.h @@ -214,6 +216,7 @@ __LIB__libodp_linux_la_SOURCES = \ odp_weak.c \ drv_atomic.c \ drv_barrier.c \ + drv_shm.c \ drv_spinlock.c \ arch/@ARCH_DIR@/odp_cpu_arch.c \ arch/@ARCH_DIR@/odp_sysinfo_parse.c diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index c79c58e..f4aa6d3 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -52,6 +52,7 @@ #include <odp/api/align.h> #include <odp/api/system_info.h> #include <odp/api/debug.h> +#include <odp/drv/shm.h> #include <odp_shm_internal.h> #include <odp_debug_internal.h> #include <odp_align_internal.h> @@ -79,13 +80,12 @@ * if some of the block ownwers never procsync() after free). This number * should take that into account) */ -#define ISHM_MAX_NB_BLOCKS 128 +#define ISHM_MAX_NB_BLOCKS ODPDRV_CONFIG_SHM_BLOCKS /* * Maximum internal shared memory block name length in chars - * probably taking the same number as SHM name size make sense at this stage */ -#define ISHM_NAME_MAXLEN 32 +#define ISHM_NAME_MAXLEN ODPDRV_SHM_NAME_LEN /* * Linux underlying file name: <directory>/odp-<odp_pid>-ishm-<name> diff --git a/platform/linux-generic/drv_shm.c b/platform/linux-generic/drv_shm.c new file mode 100644 index 0000000..9b2560d --- /dev/null +++ b/platform/linux-generic/drv_shm.c @@ -0,0 +1,102 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp_config_internal.h> +#include <odp/api/std_types.h> +#include <odp/drv/shm.h> +#include <_ishm_internal.h> + +static inline uint32_t from_handle(odpdrv_shm_t shm) +{ + return _odpdrv_typeval(shm) - 1; +} + +static inline odpdrv_shm_t to_handle(uint32_t index) +{ + return _odpdrv_cast_scalar(odpdrv_shm_t, index + 1); +} + +int odpdrv_shm_capability(odpdrv_shm_capability_t *capa) +{ + capa->max_blocks = ODPDRV_CONFIG_SHM_BLOCKS; + capa->max_size = 0; + capa->max_align = 0; + + return 0; +} + +odpdrv_shm_t odpdrv_shm_reserve(const char *name, uint64_t size, uint64_t align, + uint32_t flags) +{ + int block_index; + int flgs = 0; /* internal ishm flags */ + + /* set internal ishm flags according to API flags: */ + flgs |= (flags & ODPDRV_SHM_SINGLE_VA) ? _ODP_ISHM_SINGLE_VA : 0; + flgs |= (flags & ODPDRV_SHM_LOCK) ? _ODP_ISHM_LOCK : 0; + + block_index = _odp_ishm_reserve(name, size, -1, align, flgs, flags); + if (block_index >= 0) + return to_handle(block_index); + else + return ODPDRV_SHM_INVALID; +} + +int odpdrv_shm_free_by_handle(odpdrv_shm_t shm) +{ + return _odp_ishm_free_by_index(from_handle(shm)); +} + +int odpdrv_shm_free_by_name(const char *name) +{ + return _odp_ishm_free_by_name(name); +} + +int odpdrv_shm_free_by_address(void *address) +{ + return _odp_ishm_free_by_address(address); +} + +void *odpdrv_shm_lookup_by_handle(odpdrv_shm_t shm) +{ + return _odp_ishm_lookup_by_index(from_handle(shm)); +} + +odpdrv_shm_t odpdrv_shm_lookup_by_name(const char *name) +{ + return to_handle(_odp_ishm_lookup_by_name(name)); +} + +odpdrv_shm_t odpdrv_shm_lookup_by_address(void *address) +{ + return to_handle(_odp_ishm_lookup_by_address(address)); +} + +void *odpdrv_shm_addr(odpdrv_shm_t shm) +{ + return _odp_ishm_address(from_handle(shm)); +} + +int odpdrv_shm_info(odpdrv_shm_t shm, odpdrv_shm_info_t *info) +{ + _odp_ishm_info_t ishm_info; + + if (_odp_ishm_info(from_handle(shm), &ishm_info)) + return -1; + + info->name = ishm_info.name; + info->addr = ishm_info.addr; + info->size = ishm_info.size; + info->page_size = ishm_info.page_size; + info->flags = ishm_info.user_flags; + + return 0; +} + +int odpdrv_shm_print_all(const char *title) +{ + return _odp_ishm_status(title); +} diff --git a/platform/linux-generic/include/odp/drv/plat/shm_types.h b/platform/linux-generic/include/odp/drv/plat/shm_types.h new file mode 100644 index 0000000..c48eeca --- /dev/null +++ b/platform/linux-generic/include/odp/drv/plat/shm_types.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP shared memory + */ + +#ifndef ODPDRV_SHM_TYPES_H_ +#define ODPDRV_SHM_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <odp/drv/std_types.h> +#include <odp/drv/plat/strong_types.h> + +/** @addtogroup odpdrv_shm ODPDRV SHARED MEMORY + * Operations on driver shared memory. + * @{ + */ + +typedef ODPDRV_HANDLE_T(odpdrv_shm_t); + +#define ODPDRV_SHM_INVALID _odpdrv_cast_scalar(odpdrv_shm_t, 0) + +/** Get printable format of odpdrv_shm_t */ +static inline uint64_t odpdrv_shm_to_u64(odpdrv_shm_t hdl) +{ + return _odpdrv_pri(hdl); +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/drv/shm.h b/platform/linux-generic/include/odp/drv/shm.h new file mode 100644 index 0000000..644b036 --- /dev/null +++ b/platform/linux-generic/include/odp/drv/shm.h @@ -0,0 +1,36 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODPDRV shared memory + */ + +#ifndef ODPDRV_PLAT_SHM_H_ +#define ODPDRV_PLAT_SHM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <odp/drv/plat/shm_types.h> + +/** @ingroup odpdrv_shm + * @{ + */ + +/** + * @} + */ + +#include <odp/drv/spec/shm.h> + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp_config_internal.h b/platform/linux-generic/include/odp_config_internal.h index 3eabc7b..7d5dbeb 100644 --- a/platform/linux-generic/include/odp_config_internal.h +++ b/platform/linux-generic/include/odp_config_internal.h @@ -120,6 +120,12 @@ extern "C" { */ #define ODP_CONFIG_ISHM_VA_PREALLOC_SZ (536870912L) +/* Maximum number of shared memory blocks available on the driver interface. + * + * This the the number of separate SHM areas that can be reserved concurrently + */ +#define ODPDRV_CONFIG_SHM_BLOCKS 48 + #ifdef __cplusplus } #endif -- 2.7.4