diff --git a/mpp/base/inc/mpp_buffer_impl.h b/mpp/base/inc/mpp_buffer_impl.h index 61443f07..98fdf815 100644 --- a/mpp/base/inc/mpp_buffer_impl.h +++ b/mpp/base/inc/mpp_buffer_impl.h @@ -119,12 +119,12 @@ struct MppBufferGroupImpl_t { /* parameter store for MppBuffer */ MppAllocator allocator; MppAllocatorApi *alloc_api; + MppAllocFlagType flags; RK_U32 log_runtime_en; RK_U32 log_history_en; RK_U32 group_id; MppBufferMode mode; MppBufferType type; - RK_U32 type_flags; /* group status flag */ // buffer force clear mode flag diff --git a/mpp/base/mpp_buffer_impl.cpp b/mpp/base/mpp_buffer_impl.cpp index a34c6bcc..a36e52e2 100644 --- a/mpp/base/mpp_buffer_impl.cpp +++ b/mpp/base/mpp_buffer_impl.cpp @@ -400,7 +400,7 @@ MPP_RET mpp_buffer_create(const char *tag, const char *caller, p->group_id = group->group_id; p->mode = group->mode; p->type = group->type; - p->uncached = (group->type_flags & MPP_BUFFER_FLAGS_CACHABLE) ? 0 : 1; + p->uncached = (group->flags & MPP_ALLOC_FLAG_CACHABLE) ? 0 : 1; p->logs = group->logs; p->info = *info; @@ -770,6 +770,8 @@ MppBufferService::MppBufferService() INIT_LIST_HEAD(&mListGroup); INIT_LIST_HEAD(&mListOrphan); + mpp_env_get_u32("mpp_buffer_debug", &mpp_buffer_debug, 0); + // NOTE: Do not create misc group at beginning. Only create on when needed. for (i = 0; i < MPP_BUFFER_MODE_BUTT; i++) for (j = 0; j < MPP_BUFFER_TYPE_BUTT; j++) @@ -869,20 +871,65 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal RK_U32 is_misc) { MppBufferType buffer_type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); - RK_U32 flags = (type & MPP_BUFFER_FLAGS_MASK); - RK_U32 allocator_idx = 0; - MppBufferGroupImpl *p = (MppBufferGroupImpl *)mpp_mem_pool_get_f(caller, mpp_buf_grp_pool); - if (NULL == p) { + MppBufferGroupImpl *p = NULL; + RK_U32 flag = MPP_ALLOC_FLAG_NONE; + + /* env update */ + mpp_env_get_u32("mpp_buffer_debug", &mpp_buffer_debug, mpp_buffer_debug); + + if (mode >= MPP_BUFFER_MODE_BUTT || buffer_type >= MPP_BUFFER_TYPE_BUTT) { + mpp_err("MppBufferService get_group found invalid mode %d type %x\n", mode, type); + return NULL; + } + + p = (MppBufferGroupImpl *)mpp_mem_pool_get_f(caller, mpp_buf_grp_pool); + if (!p) { mpp_err("MppBufferService failed to allocate group context\n"); return NULL; } + if (type & MPP_BUFFER_FLAGS_DMA32) + flag += MPP_ALLOC_FLAG_DMA32; + + if (type & MPP_BUFFER_FLAGS_CACHABLE) + flag += MPP_ALLOC_FLAG_CACHABLE; + + if (type & MPP_BUFFER_FLAGS_CONTIG) + flag += MPP_ALLOC_FLAG_CMA; + + p->flags = (MppAllocFlagType)flag; + + { + AutoMutex auto_lock(get_lock()); + MppAllocator allocator = NULL; + MppAllocatorApi *alloc_api = NULL; + + allocator = mAllocator[buffer_type][flag]; + alloc_api = mAllocatorApi[buffer_type]; + + // allocate general buffer first + if (!allocator) { + mpp_allocator_get(&allocator, &alloc_api, type, p->flags); + mAllocator[buffer_type][flag] = allocator; + mAllocatorApi[buffer_type] = alloc_api; + } + + p->allocator = allocator; + p->alloc_api = alloc_api; + p->flags = mpp_allocator_get_flags(allocator); + } + + if (!p->allocator || !p->alloc_api) { + mpp_mem_pool_put_f(caller, mpp_buf_grp_pool, p); + mpp_err("MppBufferService get_group failed to get allocater with mode %d type %x\n", mode, type); + return NULL; + } + INIT_LIST_HEAD(&p->list_group); INIT_LIST_HEAD(&p->list_used); INIT_LIST_HEAD(&p->list_unused); INIT_HLIST_NODE(&p->hlist); - mpp_env_get_u32("mpp_buffer_debug", &mpp_buffer_debug, 0); p->log_runtime_en = (mpp_buffer_debug & MPP_BUF_DBG_OPS_RUNTIME) ? (1) : (0); p->log_history_en = (mpp_buffer_debug & MPP_BUF_DBG_OPS_HISTORY) ? (1) : (0); @@ -890,7 +937,6 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal p->mode = mode; p->type = buffer_type; p->limit = BUFFER_GROUP_SIZE_DEFAULT; - p->type_flags = flags; p->clear_on_exit = (mpp_buffer_debug & MPP_BUF_DBG_CLR_ON_EXIT) ? (1) : (0); p->dump_on_exit = (mpp_buffer_debug & MPP_BUF_DBG_DUMP_ON_EXIT) ? (1) : (0); @@ -900,35 +946,9 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal pthread_mutex_init(&p->buf_lock, &attr); pthread_mutexattr_destroy(&attr); - { - AutoMutex auto_lock(get_lock()); - - if (flags & MPP_BUFFER_FLAGS_CONTIG) - allocator_idx |= 1 << 0; - - if (flags & MPP_BUFFER_FLAGS_CACHABLE) - allocator_idx |= 1 << 1; - - if (flags & MPP_BUFFER_FLAGS_DMA32) - allocator_idx |= 1 << 2; - - // allocate general buffer first - if (!mAllocator[buffer_type][allocator_idx]) - mpp_allocator_get(&mAllocator[buffer_type][allocator_idx], &mAllocatorApi[buffer_type], type); - - p->allocator = mAllocator[buffer_type][allocator_idx]; - p->alloc_api = mAllocatorApi[buffer_type]; - } - - mpp_assert(p->allocator); - mpp_assert(p->alloc_api); - if (p->log_history_en) p->logs = buf_logs_init(BUFFER_OPS_MAX_COUNT); - mpp_assert(mode < MPP_BUFFER_MODE_BUTT); - mpp_assert(buffer_type < MPP_BUFFER_TYPE_BUTT); - AutoMutex auto_lock(get_lock()); RK_U32 id = get_group_id(); diff --git a/mpp/base/test/mpp_buffer_test.c b/mpp/base/test/mpp_buffer_test.c index 81ee5b3b..57dba006 100644 --- a/mpp/base/test/mpp_buffer_test.c +++ b/mpp/base/test/mpp_buffer_test.c @@ -123,7 +123,7 @@ int main() mpp_log("mpp_buffer_test commit mode with used status start\n"); - ret = mpp_allocator_get(&allocator, &api, MPP_BUFFER_TYPE_ION); + ret = mpp_allocator_get(&allocator, &api, MPP_BUFFER_TYPE_ION, 0); if (MPP_OK != ret) { mpp_err("mpp_buffer_test mpp_allocator_get ion failed\n"); goto MPP_BUFFER_failed; diff --git a/osal/CMakeLists.txt b/osal/CMakeLists.txt index f1eae562..e635b551 100644 --- a/osal/CMakeLists.txt +++ b/osal/CMakeLists.txt @@ -56,15 +56,12 @@ add_library(osal STATIC osal_2str.c # Those files have a compiler marco protection, so only target # OS will be built - android/os_allocator.c android/os_mem.c android/os_env.c android/os_log.c - linux/os_allocator.c linux/os_mem.c linux/os_env.c linux/os_log.cpp - windows/os_allocator.c windows/os_mem.c windows/os_env.c windows/os_log.c diff --git a/osal/allocator/allocator_dma_heap.c b/osal/allocator/allocator_dma_heap.c index 08807e4b..dae08cd3 100644 --- a/osal/allocator/allocator_dma_heap.c +++ b/osal/allocator/allocator_dma_heap.c @@ -68,29 +68,21 @@ typedef struct { RK_U32 flags; } allocator_ctx_dmaheap; -typedef enum DmaHeapType_e { - DMA_HEAP_CACHABLE = (1 << 0), - DMA_HEAP_DMA32 = (1 << 1), - DMA_HEAP_CMA = (1 << 2), - DMA_HEAP_TYPE_MASK = DMA_HEAP_CMA | DMA_HEAP_CACHABLE | DMA_HEAP_DMA32, - DMA_HEAP_TYPE_NB, -} DmaHeapType; - typedef struct DmaHeapInfo_t { const char *name; RK_S32 fd; RK_U32 flags; } DmaHeapInfo; -static DmaHeapInfo heap_infos[DMA_HEAP_TYPE_NB] = { - { "system-uncached", -1, 0, }, /* 0 */ - { "system-uncached-dma32", -1, DMA_HEAP_DMA32, }, /* 1 */ - { "system", -1, DMA_HEAP_CACHABLE , }, /* 2 */ - { "system-dma32", -1, DMA_HEAP_CACHABLE | DMA_HEAP_DMA32, }, /* 3 */ - { "cma-uncached", -1, DMA_HEAP_CMA , }, /* 4 */ - { "cma-uncached-dma32", -1, DMA_HEAP_CMA | DMA_HEAP_DMA32, }, /* 5 */ - { "cma", -1, DMA_HEAP_CMA | DMA_HEAP_CACHABLE , }, /* 6 */ - { "cma-dma32", -1, DMA_HEAP_CMA | DMA_HEAP_CACHABLE | DMA_HEAP_DMA32, }, /* 7 */ +static DmaHeapInfo heap_infos[MPP_ALLOC_FLAG_TYPE_NB] = { + { "system-uncached", -1, MPP_ALLOC_FLAG_NONE , }, /* 0 */ + { "system-uncached-dma32", -1, MPP_ALLOC_FLAG_DMA32, }, /* 1 */ + { "system", -1, MPP_ALLOC_FLAG_CACHABLE , }, /* 2 */ + { "system-dma32", -1, MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32, }, /* 3 */ + { "cma-uncached", -1, MPP_ALLOC_FLAG_CMA , }, /* 4 */ + { "cma-uncached-dma32", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_DMA32, }, /* 5 */ + { "cma", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_CACHABLE , }, /* 6 */ + { "cma-dma32", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32, }, /* 7 */ }; static int try_open_path(const char *name) @@ -107,16 +99,16 @@ static int try_open_path(const char *name) return fd; } -static MPP_RET try_flip_flag(DmaHeapType orig, DmaHeapType flag) +static MPP_RET try_flip_flag(RK_U32 orig, RK_U32 flag) { DmaHeapInfo *dst = &heap_infos[orig]; DmaHeapInfo *src; - DmaHeapType used; + RK_U32 used; if (orig & flag) - used = (DmaHeapType)(orig & (~flag)); + used = (RK_U32)(orig & (~flag)); else - used = (DmaHeapType)(orig | flag); + used = (RK_U32)(orig | flag); src = &heap_infos[used]; if (src->fd > 0) { @@ -141,7 +133,7 @@ void dma_heap_init(void) mpp_env_get_u32("dma_heap_debug", &dma_heap_debug, 0); /* go through all heap first */ - for (i = 0; i < DMA_HEAP_TYPE_NB; i++) { + for (i = 0; i < MPP_ARRAY_ELEMS(heap_infos); i++) { info = &heap_infos[i]; if (info->fd > 0) @@ -154,22 +146,22 @@ void dma_heap_init(void) if (!all_success) { /* check remaining failed heap mapping */ - for (i = 0; i < DMA_HEAP_TYPE_NB; i++) { + for (i = 0; i < MPP_ARRAY_ELEMS(heap_infos); i++) { info = &heap_infos[i]; if (info->fd > 0) continue; /* if original heap failed then try revert cacheable flag */ - if (MPP_OK == try_flip_flag((DmaHeapType)i, DMA_HEAP_CACHABLE)) + if (MPP_OK == try_flip_flag((RK_U32)i, MPP_ALLOC_FLAG_CACHABLE)) continue; /* if cacheable heap failed then try revert dma32 flag */ - if (MPP_OK == try_flip_flag((DmaHeapType)i, DMA_HEAP_DMA32)) + if (MPP_OK == try_flip_flag((RK_U32)i, MPP_ALLOC_FLAG_DMA32)) continue; /* if dma32 heap failed then try revert both cacheable and dma32 flag */ - if (MPP_OK == try_flip_flag((DmaHeapType)i, DMA_HEAP_CACHABLE | DMA_HEAP_DMA32)) + if (MPP_OK == try_flip_flag((RK_U32)i, MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32)) continue; dma_heap_dbg_chk("dma-heap type %x - %s remap failed\n", i, info->name); @@ -182,7 +174,7 @@ void dma_heap_deinit(void) { RK_U32 i; - for (i = 0; i < DMA_HEAP_TYPE_NB; i++) { + for (i = 0; i < MPP_ARRAY_ELEMS(heap_infos); i++) { DmaHeapInfo *info = &heap_infos[i]; if (info->fd > 0) { @@ -216,11 +208,11 @@ static int dma_heap_alloc(int fd, size_t len, RK_S32 *dmabuf_fd, RK_U32 flags) return ret; } -static MPP_RET os_allocator_dma_heap_open(void **ctx, MppAllocatorCfg *cfg) +static MPP_RET os_allocator_dma_heap_open(void **ctx, size_t alignment, MppAllocFlagType flags) { allocator_ctx_dmaheap *p; DmaHeapInfo *info = NULL; - DmaHeapType type = 0; + RK_U32 type = 0; mpp_env_get_u32("dma_heap_debug", &dma_heap_debug, dma_heap_debug); @@ -231,16 +223,7 @@ static MPP_RET os_allocator_dma_heap_open(void **ctx, MppAllocatorCfg *cfg) *ctx = NULL; - if (cfg->flags & (MPP_BUFFER_FLAGS_CONTIG >> 16)) - type |= DMA_HEAP_CMA; - - if (cfg->flags & (MPP_BUFFER_FLAGS_CACHABLE >> 16)) - type |= DMA_HEAP_CACHABLE; - - if (cfg->flags & (MPP_BUFFER_FLAGS_DMA32 >> 16)) - type |= DMA_HEAP_DMA32; - - info = &heap_infos[type]; + info = &heap_infos[flags]; if (info->fd <= 0) { mpp_err_f("open dma heap type %x %s failed!\n", type, info->name); return MPP_ERR_UNKNOW; @@ -251,27 +234,13 @@ static MPP_RET os_allocator_dma_heap_open(void **ctx, MppAllocatorCfg *cfg) mpp_err_f("failed to allocate context\n"); return MPP_ERR_MALLOC; } else { - p->alignment = cfg->alignment; + p->alignment = alignment; p->flags = info->flags; p->device = info->fd; *ctx = p; } - dma_heap_dbg_ops("dev %d open heap type %x:%x\n", p->device, cfg->flags, info->flags); - - if (type != info->flags) { - type = cfg->flags; - /* update read dma_heap back to config */ - if (info->flags & DMA_HEAP_CACHABLE) - cfg->flags |= (MPP_BUFFER_FLAGS_CACHABLE >> 16); - else - cfg->flags &= ~(MPP_BUFFER_FLAGS_CACHABLE >> 16); - - if (info->flags & DMA_HEAP_DMA32) - cfg->flags |= (MPP_BUFFER_FLAGS_DMA32 >> 16); - else - cfg->flags &= ~(MPP_BUFFER_FLAGS_DMA32 >> 16); - } + dma_heap_dbg_ops("dev %d open heap type %x:%x\n", p->device, flags, info->flags); return MPP_OK; } @@ -389,6 +358,13 @@ static MPP_RET os_allocator_dma_heap_mmap(void *ctx, MppBufferInfo *data) return ret; } +static MppAllocFlagType os_allocator_dma_heap_flags(void *ctx) +{ + allocator_ctx_dmaheap *p = (allocator_ctx_dmaheap *)ctx; + + return p ? (MppAllocFlagType)p->flags : MPP_ALLOC_FLAG_NONE; +} + os_allocator allocator_dma_heap = { .type = MPP_BUFFER_TYPE_DMA_HEAP, .open = os_allocator_dma_heap_open, @@ -398,4 +374,5 @@ os_allocator allocator_dma_heap = { .import = os_allocator_dma_heap_import, .release = os_allocator_dma_heap_free, .mmap = os_allocator_dma_heap_mmap, + .flags = os_allocator_dma_heap_flags, }; diff --git a/osal/allocator/allocator_dma_heap.h b/osal/allocator/allocator_dma_heap.h index e892e894..60f30f4e 100644 --- a/osal/allocator/allocator_dma_heap.h +++ b/osal/allocator/allocator_dma_heap.h @@ -17,7 +17,7 @@ #ifndef __ALLOCATOR_DMA_HEAP_H__ #define __ALLOCATOR_DMA_HEAP_H__ -#include "os_allocator.h" +#include "mpp_allocator_api.h" extern os_allocator allocator_dma_heap; diff --git a/osal/allocator/allocator_drm.c b/osal/allocator/allocator_drm.c index 3f5e04b2..2a4dc928 100644 --- a/osal/allocator/allocator_drm.c +++ b/osal/allocator/allocator_drm.c @@ -39,11 +39,30 @@ static RK_U32 drm_debug = 0; #define DRM_FUNCTION (0x00000001) #define DRM_DEVICE (0x00000002) -#define DRM_CLIENT (0x00000004) -#define DRM_IOCTL (0x00000008) +#define DRM_IOCTL (0x00000004) #define drm_dbg(flag, fmt, ...) _mpp_dbg_f(drm_debug, flag, fmt, ## __VA_ARGS__) #define drm_dbg_func(fmt, ...) drm_dbg(DRM_FUNCTION, fmt, ## __VA_ARGS__) +#define drm_dbg_dev(fmt, ...) drm_dbg(DRM_DEVICE, fmt, ## __VA_ARGS__) +#define drm_dbg_ioctl(fmt, ...) drm_dbg(DRM_IOCTL, fmt, ## __VA_ARGS__) + +/* memory type definitions. */ +enum drm_rockchip_gem_mem_type { + /* Physically Continuous memory. */ + ROCKCHIP_BO_CONTIG = 1 << 0, + /* cachable mapping. */ + ROCKCHIP_BO_CACHABLE = 1 << 1, + /* write-combine mapping. */ + ROCKCHIP_BO_WC = 1 << 2, + ROCKCHIP_BO_SECURE = 1 << 3, + /* keep kmap for cma buffer or alloc kmap for other type memory */ + ROCKCHIP_BO_ALLOC_KMAP = 1 << 4, + /* alloc page with gfp_dma32 */ + ROCKCHIP_BO_DMA32 = 1 << 5, + ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE | + ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE | ROCKCHIP_BO_ALLOC_KMAP | + ROCKCHIP_BO_DMA32, +}; typedef struct { RK_U32 alignment; @@ -53,6 +72,22 @@ typedef struct { static const char *dev_drm = "/dev/dri/card0"; +static RK_U32 to_rockchip_gem_mem_flag(RK_U32 flags) +{ + RK_U32 ret = 0; + + if (flags & MPP_ALLOC_FLAG_DMA32) + ret |= ROCKCHIP_BO_DMA32; + + if (flags & MPP_ALLOC_FLAG_CACHABLE) + ret |= ROCKCHIP_BO_CACHABLE; + + if (flags & MPP_ALLOC_FLAG_CMA) + ret |= ROCKCHIP_BO_CONTIG; + + return ret; +} + static int drm_ioctl(int fd, int req, void *arg) { int ret; @@ -61,8 +96,7 @@ static int drm_ioctl(int fd, int req, void *arg) ret = ioctl(fd, req, arg); } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - drm_dbg(DRM_IOCTL, "%x with code %d: %s\n", req, - ret, strerror(errno)); + drm_dbg_ioctl("%x ret %d: %s\n", req, ret, strerror(errno)); return ret; } @@ -86,7 +120,7 @@ static int drm_handle_to_fd(int fd, RK_U32 handle, int *map_fd, RK_U32 flags) *map_fd = dph.fd; - drm_dbg_func("dev %d handle %d get fd %d\n", fd, handle, *map_fd); + drm_dbg_func("dev %d handle %d flags %x get fd %d\n", fd, handle, dph.flags, *map_fd); if (*map_fd < 0) { mpp_err_f("map ioctl returned negative fd\n"); @@ -105,7 +139,7 @@ static int drm_alloc(int fd, size_t len, size_t align, RK_U32 *handle, RK_U32 fl dmcb.bpp = 8; dmcb.width = (len + align - 1) & (~(align - 1)); dmcb.height = 1; - dmcb.flags = flags; + dmcb.flags = to_rockchip_gem_mem_flag(flags); if (handle == NULL) return -EINVAL; @@ -115,8 +149,8 @@ static int drm_alloc(int fd, size_t len, size_t align, RK_U32 *handle, RK_U32 fl return ret; *handle = dmcb.handle; - drm_dbg_func("dev %d alloc aligned %d handle %d size %lld\n", fd, - align, dmcb.handle, dmcb.size); + drm_dbg_func("dev %d alloc aligned %d flags %x handle %d size %lld\n", fd, + align, dmcb.flags, dmcb.handle, dmcb.size); return ret; } @@ -129,13 +163,11 @@ static int drm_free(int fd, RK_U32 handle) return drm_ioctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &data); } -static MPP_RET os_allocator_drm_open(void **ctx, MppAllocatorCfg *cfg) +static MPP_RET os_allocator_drm_open(void **ctx, size_t alignment, MppAllocFlagType flags) { RK_S32 fd; allocator_ctx_drm *p; - drm_dbg_func("enter\n"); - if (NULL == ctx) { mpp_err_f("does not accept NULL input\n"); return MPP_ERR_NULL_PTR; @@ -151,7 +183,7 @@ static MPP_RET os_allocator_drm_open(void **ctx, MppAllocatorCfg *cfg) return MPP_ERR_UNKNOW; } - drm_dbg(DRM_DEVICE, "open drm dev fd %d\n", fd); + drm_dbg_dev("open drm dev fd %d flags %x\n", fd, flags); p = mpp_malloc(allocator_ctx_drm, 1); if (NULL == p) { @@ -162,14 +194,12 @@ static MPP_RET os_allocator_drm_open(void **ctx, MppAllocatorCfg *cfg) /* * default drm use cma, do nothing here */ - p->alignment = cfg->alignment; - p->flags = cfg->flags; + p->alignment = alignment; + p->flags = flags; p->drm_device = fd; *ctx = p; } - drm_dbg_func("leave dev %d\n", fd); - return MPP_OK; } @@ -321,6 +351,13 @@ static MPP_RET os_allocator_drm_mmap(void *ctx, MppBufferInfo *data) return ret; } +static MppAllocFlagType os_allocator_drm_flags(void *ctx) +{ + allocator_ctx_drm *p = (allocator_ctx_drm *)ctx; + + return p ? (MppAllocFlagType)p->flags : MPP_ALLOC_FLAG_NONE; +} + os_allocator allocator_drm = { .type = MPP_BUFFER_TYPE_DRM, .open = os_allocator_drm_open, @@ -330,4 +367,5 @@ os_allocator allocator_drm = { .import = os_allocator_drm_import, .release = os_allocator_drm_free, .mmap = os_allocator_drm_mmap, + .flags = os_allocator_drm_flags, }; diff --git a/osal/allocator/allocator_drm.h b/osal/allocator/allocator_drm.h index f39f91e1..eb86b0bf 100644 --- a/osal/allocator/allocator_drm.h +++ b/osal/allocator/allocator_drm.h @@ -17,7 +17,7 @@ #ifndef __ALLOCATOR_DRM_H__ #define __ALLOCATOR_DRM_H__ -#include "os_allocator.h" +#include "mpp_allocator_api.h" extern os_allocator allocator_drm; diff --git a/osal/allocator/allocator_ext_dma.c b/osal/allocator/allocator_ext_dma.c index 0c7163f8..b3aeb102 100644 --- a/osal/allocator/allocator_ext_dma.c +++ b/osal/allocator/allocator_ext_dma.c @@ -23,10 +23,11 @@ #include "allocator_ext_dma.h" typedef struct { - size_t alignment; + size_t alignment; + MppAllocFlagType flags; } allocator_ctx; -static MPP_RET allocator_ext_dma_open(void **ctx, MppAllocatorCfg *cfg) +static MPP_RET allocator_ext_dma_open(void **ctx, size_t alignment, MppAllocFlagType flags) { MPP_RET ret = MPP_OK; allocator_ctx *p = NULL; @@ -41,7 +42,8 @@ static MPP_RET allocator_ext_dma_open(void **ctx, MppAllocatorCfg *cfg) mpp_err_f("failed to allocate context\n"); ret = MPP_ERR_MALLOC; } else { - p->alignment = cfg->alignment; + p->alignment = alignment; + p->flags = flags; } *ctx = p; @@ -134,6 +136,13 @@ static MPP_RET allocator_ext_dma_close(void *ctx) return MPP_ERR_VALUE; } +static MppAllocFlagType os_allocator_ext_dma_flags(void *ctx) +{ + allocator_ctx *p = (allocator_ctx *)ctx; + + return p ? (MppAllocFlagType)p->flags : MPP_ALLOC_FLAG_NONE; +} + os_allocator allocator_ext_dma = { .type = MPP_BUFFER_TYPE_EXT_DMA, .open = allocator_ext_dma_open, @@ -143,4 +152,5 @@ os_allocator allocator_ext_dma = { .import = allocator_ext_dma_import, .release = allocator_ext_dma_release, .mmap = allocator_ext_dma_mmap, + .flags = os_allocator_ext_dma_flags, }; diff --git a/osal/allocator/allocator_ext_dma.h b/osal/allocator/allocator_ext_dma.h index a911edc3..9e5c2589 100644 --- a/osal/allocator/allocator_ext_dma.h +++ b/osal/allocator/allocator_ext_dma.h @@ -17,7 +17,7 @@ #ifndef __ALLOCATOR_EXT_DMA_H__ #define __ALLOCATOR_EXT_DMA_H__ -#include "os_allocator.h" +#include "mpp_allocator_api.h" extern os_allocator allocator_ext_dma; diff --git a/osal/allocator/allocator_ion.c b/osal/allocator/allocator_ion.c index aa7f871c..f466b4d4 100644 --- a/osal/allocator/allocator_ion.c +++ b/osal/allocator/allocator_ion.c @@ -272,8 +272,9 @@ static RK_S32 check_sysfs_iommu() } typedef struct { - RK_U32 alignment; - RK_S32 ion_device; + size_t alignment; + RK_S32 ion_device; + MppAllocFlagType flags; } allocator_ctx_ion; static const char *dev_ion = "/dev/ion"; @@ -281,7 +282,7 @@ static RK_S32 ion_heap_id = -1; static RK_U32 ion_heap_mask = (1 << ION_HEAP_TYPE_SYSTEM); static pthread_mutex_t lock; -static MPP_RET allocator_ion_open(void **ctx, MppAllocatorCfg *cfg) +static MPP_RET allocator_ion_open(void **ctx, size_t alignment, MppAllocFlagType flags) { RK_S32 fd; allocator_ctx_ion *p; @@ -343,7 +344,8 @@ static MPP_RET allocator_ion_open(void **ctx, MppAllocatorCfg *cfg) mpp_log("using ion heap %s\n", heap_name); } pthread_mutex_unlock(&lock); - p->alignment = cfg->alignment; + p->alignment = alignment; + p->flags = flags; p->ion_device = fd; *ctx = p; } @@ -481,6 +483,13 @@ static MPP_RET allocator_ion_close(void *ctx) return ret; } +static MppAllocFlagType os_allocator_ion_flags(void *ctx) +{ + allocator_ctx_ion *p = (allocator_ctx_ion *)ctx; + + return p ? p->flags : MPP_ALLOC_FLAG_NONE; +} + os_allocator allocator_ion = { .type = MPP_BUFFER_TYPE_ION, .open = allocator_ion_open, @@ -490,5 +499,5 @@ os_allocator allocator_ion = { .import = allocator_ion_import, .release = allocator_ion_free, .mmap = allocator_ion_mmap, + .flags = os_allocator_ion_flags, }; - diff --git a/osal/allocator/allocator_ion.h b/osal/allocator/allocator_ion.h index e2cb37e7..fcb1e13e 100644 --- a/osal/allocator/allocator_ion.h +++ b/osal/allocator/allocator_ion.h @@ -17,7 +17,7 @@ #ifndef __ALLOCATOR_ION_H__ #define __ALLOCATOR_ION_H__ -#include "os_allocator.h" +#include "mpp_allocator_api.h" extern os_allocator allocator_ion; diff --git a/osal/allocator/allocator_std.c b/osal/allocator/allocator_std.c index b1464546..1e324f4d 100644 --- a/osal/allocator/allocator_std.c +++ b/osal/allocator/allocator_std.c @@ -23,22 +23,31 @@ #include "allocator_std.h" typedef struct { - size_t alignment; - RK_S32 fd_count; + size_t alignment; + MppAllocFlagType flags; + RK_S32 fd_count; } allocator_ctx; -static MPP_RET allocator_std_open(void **ctx, MppAllocatorCfg *cfg) +static MPP_RET allocator_std_open(void **ctx, size_t alignment, MppAllocFlagType flags) { + allocator_ctx *p = NULL; + if (NULL == ctx) { mpp_err_f("do not accept NULL input\n"); return MPP_ERR_NULL_PTR; } mpp_err_f("Warning: std allocator should be used on simulation mode only\n"); - (void)cfg; - *ctx = NULL; - return MPP_NOK; + p = mpp_malloc(allocator_ctx, 1); + if (p) { + p->alignment = alignment; + p->flags = flags; + p->fd_count = 0; + } + + *ctx = p; + return p ? MPP_OK : MPP_NOK; } static MPP_RET allocator_std_alloc(void *ctx, MppBufferInfo *info) @@ -95,12 +104,14 @@ static MPP_RET allocator_std_mmap(void *ctx, MppBufferInfo *info) static MPP_RET allocator_std_close(void *ctx) { - if (ctx) { - mpp_free(ctx); - return MPP_OK; - } - mpp_err_f("found NULL context input\n"); - return MPP_NOK; + MPP_FREE(ctx); + return MPP_OK; +} + +static MppAllocFlagType os_allocator_std_flags(void *ctx) +{ + (void) ctx; + return MPP_ALLOC_FLAG_NONE; } os_allocator allocator_std = { @@ -112,5 +123,5 @@ os_allocator allocator_std = { .import = allocator_std_import, .release = allocator_std_release, .mmap = allocator_std_mmap, + .flags = os_allocator_std_flags, }; - diff --git a/osal/allocator/allocator_std.h b/osal/allocator/allocator_std.h index bff47944..a690d14b 100644 --- a/osal/allocator/allocator_std.h +++ b/osal/allocator/allocator_std.h @@ -17,7 +17,7 @@ #ifndef __ALLOCATOR_STD_H__ #define __ALLOCATOR_STD_H__ -#include "os_allocator.h" +#include "mpp_allocator_api.h" extern os_allocator allocator_std; diff --git a/osal/android/os_allocator.c b/osal/android/os_allocator.c deleted file mode 100644 index d1e602fb..00000000 --- a/osal/android/os_allocator.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2015 Rockchip Electronics Co. LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if defined(__ANDROID__) -#include "allocator_dma_heap.h" -#include "allocator_drm.h" -#include "allocator_ext_dma.h" -#include "allocator_ion.h" -#include "allocator_std.h" -#include "mpp_runtime.h" - -MPP_RET os_allocator_get(os_allocator *api, MppBufferType type) -{ - MPP_RET ret = MPP_OK; - - switch (type) { - case MPP_BUFFER_TYPE_NORMAL : - *api = allocator_std; - case MPP_BUFFER_TYPE_ION : { - *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion : -#if HAVE_DRM - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm : -#endif - allocator_std; - } break; - case MPP_BUFFER_TYPE_EXT_DMA: { - *api = allocator_ext_dma; - } break; - case MPP_BUFFER_TYPE_DRM : { - *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : -#if HAVE_DRM - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm : -#endif - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion : - allocator_std; - } break; - case MPP_BUFFER_TYPE_DMA_HEAP: { - *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : - allocator_std; - } break; - default : { - ret = MPP_NOK; - } break; - } - return ret; -} -#endif diff --git a/osal/inc/mpp_allocator.h b/osal/inc/mpp_allocator.h index 4e1c1e1f..b268fdce 100644 --- a/osal/inc/mpp_allocator.h +++ b/osal/inc/mpp_allocator.h @@ -17,16 +17,18 @@ #ifndef __MPP_ALLOCATOR_H__ #define __MPP_ALLOCATOR_H__ -#include "rk_type.h" #include "mpp_buffer.h" -typedef void *MppAllocator; +typedef enum MppAllocFlagType_e { + MPP_ALLOC_FLAG_NONE = 0, + MPP_ALLOC_FLAG_DMA32 = (1 << 0), + MPP_ALLOC_FLAG_CACHABLE = (1 << 1), + MPP_ALLOC_FLAG_CMA = (1 << 2), + MPP_ALLOC_FLAG_TYPE_MASK = MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32, + MPP_ALLOC_FLAG_TYPE_NB, +} MppAllocFlagType; -typedef struct MppAllocatorCfg_t { - // input - size_t alignment; - RK_U32 flags; -} MppAllocatorCfg; +typedef void *MppAllocator; typedef struct MppAllocatorApi_t { RK_U32 size; @@ -43,14 +45,14 @@ typedef struct MppAllocatorApi_t { extern "C" { #endif -MPP_RET mpp_allocator_get(MppAllocator *allocator, - MppAllocatorApi **api, MppBufferType type); +/* NOTE: flag may be updated by allocator */ +MPP_RET mpp_allocator_get(MppAllocator *allocator, MppAllocatorApi **api, + MppBufferType type, MppAllocFlagType flag); MPP_RET mpp_allocator_put(MppAllocator *allocator); -MppBufferType get_real_allocator_type(const MppAllocator allocator); +MppAllocFlagType mpp_allocator_get_flags(const MppAllocator allocator); #ifdef __cplusplus } #endif #endif /*__MPP_ALLOCATOR_H__*/ - diff --git a/osal/linux/os_allocator.c b/osal/linux/os_allocator.c deleted file mode 100644 index c38cb7e0..00000000 --- a/osal/linux/os_allocator.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2015 Rockchip Electronics Co. LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if defined(linux) && !defined(__ANDROID__) -#include "mpp_log.h" -#include "mpp_runtime.h" - -#include "allocator_dma_heap.h" -#include "allocator_drm.h" -#include "allocator_ext_dma.h" -#include "allocator_ion.h" -#include "allocator_std.h" - -/* - * Linux only support MPP_BUFFER_TYPE_NORMAL so far - * we can support MPP_BUFFER_TYPE_V4L2 later - */ - -MPP_RET os_allocator_get(os_allocator *api, MppBufferType type) -{ - MPP_RET ret = MPP_OK; - switch (type) { - case MPP_BUFFER_TYPE_NORMAL : { - *api = allocator_std; - } break; - case MPP_BUFFER_TYPE_ION : { - *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion : -#if HAVE_DRM - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm : -#endif - allocator_std; - } break; - case MPP_BUFFER_TYPE_EXT_DMA: { - *api = allocator_ext_dma; - } break; - case MPP_BUFFER_TYPE_DRM : { - *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : -#if HAVE_DRM - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm : -#endif - (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion : - allocator_std; - } break; - case MPP_BUFFER_TYPE_DMA_HEAP: { - *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : - allocator_std; - } break; - default : { - ret = MPP_NOK; - } break; - } - return ret; -} - -#endif diff --git a/osal/mpp_allocator.cpp b/osal/mpp_allocator.cpp index d4db1290..8d18835d 100644 --- a/osal/mpp_allocator.cpp +++ b/osal/mpp_allocator.cpp @@ -19,10 +19,15 @@ #include "mpp_mem.h" #include "mpp_debug.h" #include "mpp_common.h" +#include "mpp_runtime.h" +#include "mpp_thread.h" #include "mpp_allocator.h" -#include "mpp_allocator_impl.h" -#include "os_allocator.h" +#include "allocator_std.h" +#include "allocator_ion.h" +#include "allocator_drm.h" +#include "allocator_ext_dma.h" +#include "allocator_dma_heap.h" #include @@ -38,6 +43,15 @@ typedef enum OsAllocatorApiId_e { ALLOC_API_BUTT, } OsAllocatorApiId; +typedef struct MppAllocatorImpl_t { + pthread_mutex_t lock; + MppBufferType type; + MppAllocFlagType flags; + size_t alignment; + os_allocator os_api; + void *ctx; +} MppAllocatorImpl; + static MPP_RET mpp_allocator_api_wrapper(MppAllocator allocator, MppBufferInfo *info, OsAllocatorApiId id) @@ -118,56 +132,83 @@ static MppAllocatorApi mpp_allocator_api = { .mmap = mpp_allocator_mmap, }; -MPP_RET mpp_allocator_get(MppAllocator *allocator, - MppAllocatorApi **api, MppBufferType type) +MPP_RET mpp_allocator_get(MppAllocator *allocator, MppAllocatorApi **api, + MppBufferType type, MppAllocFlagType flags) { MppBufferType buffer_type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); - RK_U32 flags = (type & MPP_BUFFER_FLAGS_MASK) >> 16; + MppAllocatorImpl *p = NULL; - if (NULL == allocator || NULL == api || buffer_type >= MPP_BUFFER_TYPE_BUTT) { - mpp_err_f("invalid input: allocator %p api %p type %d\n", - allocator, api, buffer_type); - return MPP_ERR_UNKNOW; - } + do { + if (NULL == allocator || NULL == api || buffer_type >= MPP_BUFFER_TYPE_BUTT) { + mpp_err_f("invalid input: allocator %p api %p type %d\n", + allocator, api, buffer_type); + break; + } + + p = mpp_malloc(MppAllocatorImpl, 1); + if (!p) { + mpp_err_f("failed to malloc allocator context\n"); + break; + } - MppAllocatorImpl *p = mpp_malloc(MppAllocatorImpl, 1); - if (NULL == p) { - mpp_err("mpp_allocator_get failed to malloc allocator context\n"); - return MPP_ERR_NULL_PTR; - } else { p->type = buffer_type; p->flags = flags; - } - MPP_RET ret = os_allocator_get(&p->os_api, buffer_type); + switch (buffer_type) { + case MPP_BUFFER_TYPE_NORMAL : { + p->os_api = allocator_std; + } break; + case MPP_BUFFER_TYPE_ION : { + p->os_api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : + (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion : + (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm : + allocator_std; + } break; + case MPP_BUFFER_TYPE_EXT_DMA: { + p->os_api = allocator_ext_dma; + } break; + case MPP_BUFFER_TYPE_DRM : { + p->os_api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : + (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm : + (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion : + allocator_std; + } break; + case MPP_BUFFER_TYPE_DMA_HEAP: { + p->os_api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap : + allocator_std; + } break; + default : { + } break; + } - if (MPP_OK == ret) { - MppAllocatorCfg cfg = { - .alignment = SZ_4K, - .flags = flags, - }; - ret = p->os_api.open(&p->ctx, &cfg); + if (p->os_api.open(&p->ctx, SZ_4K, flags)) + break; - /* NOTE: allocator may update the flags for compatibility */ - p->flags = cfg.flags; - } - if (MPP_OK == ret) { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&p->lock, &attr); - pthread_mutexattr_destroy(&attr); + /* update the real buffer type and flags */ + p->type = p->os_api.type; + if (p->os_api.flags) + p->flags = p->os_api.flags(p->ctx); - *allocator = p; - *api = &mpp_allocator_api; - } else { - mpp_err("mpp_allocator_get type %d failed\n", type); - mpp_free(p); - *allocator = NULL; - *api = NULL; - } + { + pthread_mutexattr_t attr; - return ret; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&p->lock, &attr); + pthread_mutexattr_destroy(&attr); + } + + *allocator = p; + *api = &mpp_allocator_api; + + return MPP_OK; + } while (0); + + MPP_FREE(p); + *allocator = NULL; + *api = NULL; + + return MPP_NOK; } MPP_RET mpp_allocator_put(MppAllocator *allocator) @@ -191,10 +232,9 @@ MPP_RET mpp_allocator_put(MppAllocator *allocator) return MPP_OK; } -MppBufferType get_real_allocator_type(const MppAllocator allocator) +MppAllocFlagType mpp_allocator_get_flags(const MppAllocator allocator) { MppAllocatorImpl *p = (MppAllocatorImpl *)allocator; - MppBufferType type = allocator ? p->os_api.type : MPP_BUFFER_TYPE_BUTT; - return type; -} \ No newline at end of file + return p ? p->flags : MPP_ALLOC_FLAG_NONE; +} diff --git a/osal/mpp_allocator_api.h b/osal/mpp_allocator_api.h new file mode 100644 index 00000000..1f5722f0 --- /dev/null +++ b/osal/mpp_allocator_api.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: Apache-2.0 OR MIT */ +/* + * Copyright (c) 2023 Rockchip Electronics Co., Ltd. + */ + +#ifndef __MPP_ALLOCATOR_API_H__ +#define __MPP_ALLOCATOR_API_H__ + +#include "mpp_allocator.h" + +typedef MPP_RET (*OsAllocatorFunc)(void *ctx, MppBufferInfo *info); + +typedef struct os_allocator_t { + MppBufferType type; + + MPP_RET (*open)(void **ctx, size_t alignment, MppAllocFlagType flags); + MPP_RET (*close)(void *ctx); + + OsAllocatorFunc alloc; + OsAllocatorFunc free; + OsAllocatorFunc import; + OsAllocatorFunc release; + OsAllocatorFunc mmap; + + /* allocator real flag update callback */ + MppAllocFlagType (*flags)(void *ctx); +} os_allocator; + +#endif /* __MPP_ALLOCATOR_API_H__ */ diff --git a/osal/mpp_allocator_impl.h b/osal/mpp_allocator_impl.h deleted file mode 100644 index 086689bd..00000000 --- a/osal/mpp_allocator_impl.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2015 Rockchip Electronics Co. LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __MPP_ALLOCATOR_IMPL_H__ -#define __MPP_ALLOCATOR_IMPL_H__ - -#include "mpp_thread.h" -#include "os_allocator.h" - -typedef struct MppAllocatorImpl_t { - pthread_mutex_t lock; - MppBufferType type; - RK_U32 flags; - size_t alignment; - os_allocator os_api; - void *ctx; -} MppAllocatorImpl; - -#endif /*__MPP_ALLOCATOR_IMPL_H__*/ - diff --git a/osal/mpp_dmabuf.cpp b/osal/mpp_dmabuf.cpp index 16844225..fcd7cdba 100644 --- a/osal/mpp_dmabuf.cpp +++ b/osal/mpp_dmabuf.cpp @@ -8,6 +8,7 @@ #include #include +#include "mpp_env.h" #include "mpp_log.h" #include "mpp_dmabuf.h" @@ -38,6 +39,18 @@ struct dma_buf_sync_partial { static RK_U32 has_partial_ops = 1; +__attribute__ ((constructor)) +void mpp_dmabuf_init(void) +{ + /* + * update has_partial_ops by env + * NOTE: When dmaheap is enabled the dmaheap fd partial ops is fine. + * But the drm fd partial ops may have error when kernel version above 4.19 + * So we provide the mpp_dmabuf_has_partial_ops env to disable partial ops. + */ + mpp_env_get_u32("mpp_dmabuf_has_partial_ops", &has_partial_ops, has_partial_ops); +} + MPP_RET mpp_dmabuf_sync_begin(RK_S32 fd, RK_S32 ro, const char *caller) { struct dma_buf_sync sync; diff --git a/osal/os_allocator.h b/osal/os_allocator.h deleted file mode 100644 index 0ffa8fc5..00000000 --- a/osal/os_allocator.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2015 Rockchip Electronics Co. LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __OS_ALLOCATOR_H__ -#define __OS_ALLOCATOR_H__ - -#include "mpp_allocator.h" - -typedef MPP_RET (*OsAllocatorFunc)(void *ctx, MppBufferInfo *info); - -typedef struct os_allocator_t { - MppBufferType type; - - MPP_RET (*open)(void **ctx, MppAllocatorCfg *cfg); - MPP_RET (*close)(void *ctx); - - OsAllocatorFunc alloc; - OsAllocatorFunc free; - OsAllocatorFunc import; - OsAllocatorFunc release; - OsAllocatorFunc mmap; -} os_allocator; - -#ifdef __cplusplus -extern "C" { -#endif - -MPP_RET os_allocator_get(os_allocator *api, MppBufferType type); - -#ifdef __cplusplus -} -#endif - -#endif /*__OS_ALLOCATOR_H__*/ - - diff --git a/osal/windows/os_allocator.c b/osal/windows/os_allocator.c deleted file mode 100644 index cebb2619..00000000 --- a/osal/windows/os_allocator.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2015 Rockchip Electronics Co. LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if defined(_WIN32) -#include "os_allocator.h" -#include "allocator_std.h" - -/* - * window only support MPP_BUFFER_TYPE_NORMAL - */ - -MPP_RET os_allocator_get(os_allocator *api, MppBufferType type) -{ - MPP_RET ret = MPP_OK; - switch (type) { - case MPP_BUFFER_TYPE_NORMAL : - case MPP_BUFFER_TYPE_ION : - case MPP_BUFFER_TYPE_V4L2 : { - *api = allocator_std; - } break; - default : { - ret = MPP_NOK; - } break; - } - return ret; -} - -#endif