diff --git a/inc/mpp_buffer.h b/inc/mpp_buffer.h index 63b9d430..9ff31f84 100644 --- a/inc/mpp_buffer.h +++ b/inc/mpp_buffer.h @@ -155,6 +155,27 @@ typedef enum { MPP_BUFFER_TYPE_BUTT, } MppBufferType; +#define MPP_BUFFER_TYPE_MASK 0x0000FFFF + +/* + * MPP_BUFFER_FLAGS cooperate with MppBufferType + * 16 high bits of MppBufferType are used in flags + * + * eg: + * DRM CMA buffer : MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_CONTIG + * = 0x00010003 + * DRM SECURE buffer: MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_SECURE + * = 0x00080003 + * + * flags originate from drm_rockchip_gem_mem_type + */ + +#define MPP_BUFFER_FLAGS_MASK 0x000f0000 //ROCKCHIP_BO_MASK << 16 +#define MPP_BUFFER_FLAGS_CONTIG 0x00010000 //ROCKCHIP_BO_CONTIG << 16 +#define MPP_BUFFER_FLAGS_CACHABLE 0x00020000 //ROCKCHIP_BO_CACHABLE << 16 +#define MPP_BUFFER_FLAGS_WC 0x00040000 //ROCKCHIP_BO_WC << 16 +#define MPP_BUFFER_FLAGS_SECURE 0x00080000 //ROCKCHIP_BO_SECURE << 16 + /* * MppBufferInfo variable's meaning is different in different MppBufferType * diff --git a/mpp/base/mpp_buffer.cpp b/mpp/base/mpp_buffer.cpp index 28be3a80..47895c8c 100644 --- a/mpp/base/mpp_buffer.cpp +++ b/mpp/base/mpp_buffer.cpp @@ -34,7 +34,8 @@ MPP_RET mpp_buffer_import_with_tag(MppBufferGroup group, MppBufferInfo *info, Mp if (p) { // if group is specified we need to check the parameter - if (p->type != info->type || p->type >= MPP_BUFFER_TYPE_BUTT || + if ((p->type & MPP_BUFFER_TYPE_MASK) != info->type || + (p->type & MPP_BUFFER_TYPE_MASK) >= MPP_BUFFER_TYPE_BUTT || p->mode != MPP_BUFFER_EXTERNAL) { mpp_err("mpp_buffer_commit invalid type found group %d info %d group mode %d\n", p->type, info->type, p->mode); @@ -259,7 +260,7 @@ MPP_RET mpp_buffer_group_get(MppBufferGroup *group, MppBufferType type, MppBuffe { if (NULL == group || mode >= MPP_BUFFER_MODE_BUTT || - type >= MPP_BUFFER_TYPE_BUTT) { + (type & MPP_BUFFER_TYPE_MASK) >= MPP_BUFFER_TYPE_BUTT) { mpp_err_f("input invalid group %p mode %d type %d\n", group, mode, type); return MPP_ERR_UNKNOW; diff --git a/mpp/base/mpp_buffer_impl.cpp b/mpp/base/mpp_buffer_impl.cpp index 9d03ebfe..be3e9157 100644 --- a/mpp/base/mpp_buffer_impl.cpp +++ b/mpp/base/mpp_buffer_impl.cpp @@ -644,6 +644,7 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal MppBufferMode mode, MppBufferType type, RK_U32 is_misc) { + MppBufferType buffer_type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); MppBufferGroupImpl *p = mpp_calloc(MppBufferGroupImpl, 1); if (NULL == p) { mpp_err("MppBufferService failed to allocate group context\n"); @@ -670,7 +671,7 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal } p->caller = caller; p->mode = mode; - p->type = type; + p->type = buffer_type; p->limit = BUFFER_GROUP_SIZE_DEFAULT; p->group_id = id; p->clear_on_exit = (mpp_buffer_debug & MPP_BUF_DBG_CLR_ON_EXIT) ? (1) : (0); @@ -680,10 +681,10 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal buffer_group_add_log(p, NULL, GRP_CREATE, __FUNCTION__); mpp_assert(mode < MPP_BUFFER_MODE_BUTT); - mpp_assert(type < MPP_BUFFER_TYPE_BUTT); + mpp_assert(buffer_type < MPP_BUFFER_TYPE_BUTT); if (is_misc) { - misc[mode][type] = p; + misc[mode][buffer_type] = p; misc_count++; } @@ -692,6 +693,7 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal MppBufferGroupImpl *MppBufferService::get_misc(MppBufferMode mode, MppBufferType type) { + type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); if (type == MPP_BUFFER_TYPE_NORMAL) return NULL; @@ -703,6 +705,7 @@ MppBufferGroupImpl *MppBufferService::get_misc(MppBufferMode mode, MppBufferType void MppBufferService::set_misc(MppBufferMode mode, MppBufferType type, MppBufferGroupImpl *val) { + type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); if (type == MPP_BUFFER_TYPE_NORMAL) return ; diff --git a/osal/allocator/allocator_drm.c b/osal/allocator/allocator_drm.c index 48735c90..a29bf3f5 100644 --- a/osal/allocator/allocator_drm.c +++ b/osal/allocator/allocator_drm.c @@ -78,6 +78,7 @@ static inline void *drm_mmap(void *addr, size_t length, int prot, int flags, typedef struct { RK_U32 alignment; RK_S32 drm_device; + RK_U32 flags; } allocator_ctx_drm; static const char *dev_drm = "/dev/dri/card0"; @@ -144,7 +145,7 @@ static int drm_fd_to_handle(int fd, int map_fd, RK_U32 *handle, RK_U32 flags) return ret; } -static int drm_alloc(int fd, size_t len, size_t align, RK_U32 *handle) +static int drm_alloc(int fd, size_t len, size_t align, RK_U32 *handle, RK_U32 flags) { int ret; struct drm_mode_create_dumb dmcb; @@ -155,6 +156,7 @@ static int drm_alloc(int fd, size_t len, size_t align, RK_U32 *handle) dmcb.bpp = 8; dmcb.width = (len + align - 1) & (~(align - 1)); dmcb.height = 1; + dmcb.flags = flags; if (handle == NULL) return -EINVAL; @@ -179,7 +181,7 @@ 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, size_t alignment) +static MPP_RET os_allocator_drm_open(void **ctx, MppAllocatorCfg *cfg) { RK_S32 fd; allocator_ctx_drm *p; @@ -212,7 +214,8 @@ static MPP_RET os_allocator_drm_open(void **ctx, size_t alignment) /* * default drm use cma, do nothing here */ - p->alignment = alignment; + p->alignment = cfg->alignment; + p->flags = cfg->flags; p->drm_device = fd; *ctx = p; } @@ -235,7 +238,7 @@ static MPP_RET os_allocator_drm_alloc(void *ctx, MppBufferInfo *info) p = (allocator_ctx_drm *)ctx; drm_dbg(DRM_FUNCTION, "alignment %d size %d", p->alignment, info->size); ret = drm_alloc(p->drm_device, info->size, p->alignment, - (RK_U32 *)&info->hnd); + (RK_U32 *)&info->hnd, p->flags); if (ret) { mpp_err("os_allocator_drm_alloc drm_alloc failed ret %d\n", ret); return ret; diff --git a/osal/allocator/allocator_ext_dma.c b/osal/allocator/allocator_ext_dma.c index c017dea2..f5a48ed1 100644 --- a/osal/allocator/allocator_ext_dma.c +++ b/osal/allocator/allocator_ext_dma.c @@ -27,7 +27,7 @@ typedef struct { size_t alignment; } allocator_ctx; -static MPP_RET allocator_ext_dma_open(void **ctx, size_t alignment) +static MPP_RET allocator_ext_dma_open(void **ctx, MppAllocatorCfg *cfg) { MPP_RET ret = MPP_OK; allocator_ctx *p = NULL; @@ -42,7 +42,7 @@ static MPP_RET allocator_ext_dma_open(void **ctx, size_t alignment) mpp_err_f("failed to allocate context\n"); ret = MPP_ERR_MALLOC; } else { - p->alignment = alignment; + p->alignment = cfg->alignment; } *ctx = p; diff --git a/osal/allocator/allocator_ion.c b/osal/allocator/allocator_ion.c index 88f69033..961655cc 100644 --- a/osal/allocator/allocator_ion.c +++ b/osal/allocator/allocator_ion.c @@ -267,7 +267,7 @@ static RK_S32 ion_heap_id = -1; static RK_U32 ion_heap_mask = ION_HEAP_SYSTEM_MASK; static pthread_mutex_t lock; -static MPP_RET allocator_ion_open(void **ctx, size_t alignment) +static MPP_RET allocator_ion_open(void **ctx, MppAllocatorCfg *cfg) { RK_S32 fd; allocator_ctx_ion *p; @@ -329,7 +329,7 @@ static MPP_RET allocator_ion_open(void **ctx, size_t alignment) mpp_log("using ion heap %s\n", heap_name); } pthread_mutex_unlock(&lock); - p->alignment = alignment; + p->alignment = cfg->alignment; p->ion_device = fd; *ctx = p; } diff --git a/osal/allocator/allocator_std.c b/osal/allocator/allocator_std.c index ec809c24..4a048d3a 100644 --- a/osal/allocator/allocator_std.c +++ b/osal/allocator/allocator_std.c @@ -27,7 +27,7 @@ typedef struct { RK_S32 fd_count; } allocator_ctx; -static MPP_RET allocator_std_open(void **ctx, size_t alignment) +static MPP_RET allocator_std_open(void **ctx, MppAllocatorCfg *cfg) { MPP_RET ret = MPP_OK; allocator_ctx *p = NULL; @@ -42,7 +42,7 @@ static MPP_RET allocator_std_open(void **ctx, size_t alignment) mpp_err_f("failed to allocate context\n"); ret = MPP_ERR_MALLOC; } else - p->alignment = alignment; + p->alignment = cfg->alignment; p->fd_count = 0; diff --git a/osal/inc/mpp_allocator.h b/osal/inc/mpp_allocator.h index 973a155a..18643f09 100644 --- a/osal/inc/mpp_allocator.h +++ b/osal/inc/mpp_allocator.h @@ -22,6 +22,12 @@ typedef void *MppAllocator; +typedef struct MppAllocatorCfg_t { + // input + size_t alignment; + RK_U32 flags; +} MppAllocatorCfg; + typedef struct MppAllocatorApi_t { RK_U32 size; RK_U32 version; diff --git a/osal/linux/drm.h b/osal/linux/drm.h index ef8b95b8..e99e01c6 100644 --- a/osal/linux/drm.h +++ b/osal/linux/drm.h @@ -73,6 +73,17 @@ typedef unsigned int drm_context_t; typedef unsigned int drm_drawable_t; typedef unsigned int drm_magic_t; +enum drm_rockchip_gem_mem_type { + /* Physically Continuous memory and used as default. */ + 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, + ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE | ROCKCHIP_BO_WC +}; + /** * Cliprect. * diff --git a/osal/mpp_allocator.cpp b/osal/mpp_allocator.cpp index 358cdbfc..21c515ab 100644 --- a/osal/mpp_allocator.cpp +++ b/osal/mpp_allocator.cpp @@ -23,6 +23,8 @@ #include "os_allocator.h" +#include + #define MPP_ALLOCATOR_LOCK(p) pthread_mutex_lock(&(p)->lock); #define MPP_ALLOCATOR_UNLOCK(p) pthread_mutex_unlock(&(p)->lock); @@ -118,9 +120,12 @@ static MppAllocatorApi mpp_allocator_api = { MPP_RET mpp_allocator_get(MppAllocator *allocator, MppAllocatorApi **api, MppBufferType type) { - if (NULL == allocator || NULL == api || type >= MPP_BUFFER_TYPE_BUTT) { + MppBufferType buffer_type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); + RK_U32 flags = (type & MPP_BUFFER_FLAGS_MASK) >> 16; + + 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, type); + allocator, api, buffer_type); return MPP_ERR_UNKNOW; } @@ -128,14 +133,20 @@ MPP_RET mpp_allocator_get(MppAllocator *allocator, if (NULL == p) { mpp_err("mpp_allocator_get failed to malloc allocator context\n"); return MPP_ERR_NULL_PTR; - } else - p->type = type; + } else { + p->type = buffer_type; + p->flags = flags; + } - MPP_RET ret = os_allocator_get(&p->os_api, type); + MPP_RET ret = os_allocator_get(&p->os_api, buffer_type); + if (MPP_OK == ret) { - p->alignment = SZ_4K; - ret = p->os_api.open(&p->ctx, p->alignment); + MppAllocatorCfg cfg = { + .alignment = SZ_4K, + .flags = flags, + }; + ret = p->os_api.open(&p->ctx, &cfg); } if (MPP_OK == ret) { pthread_mutexattr_t attr; diff --git a/osal/mpp_allocator_impl.h b/osal/mpp_allocator_impl.h index 9fd098c4..086689bd 100644 --- a/osal/mpp_allocator_impl.h +++ b/osal/mpp_allocator_impl.h @@ -23,6 +23,7 @@ typedef struct MppAllocatorImpl_t { pthread_mutex_t lock; MppBufferType type; + RK_U32 flags; size_t alignment; os_allocator os_api; void *ctx; diff --git a/osal/mpp_runtime.cpp b/osal/mpp_runtime.cpp index 9a2926e1..baedabb4 100644 --- a/osal/mpp_runtime.cpp +++ b/osal/mpp_runtime.cpp @@ -70,7 +70,8 @@ public: RK_U32 MppRuntimeService::get_allocator_valid(MppBufferType type) { - return (type < MPP_BUFFER_TYPE_BUTT) ? allocator_valid[type] : (0); + MppBufferType buffer_type = (MppBufferType)(type & MPP_BUFFER_TYPE_MASK); + return (buffer_type < MPP_BUFFER_TYPE_BUTT) ? allocator_valid[buffer_type] : (0); }; MppRuntimeService::MppRuntimeService() diff --git a/osal/os_allocator.h b/osal/os_allocator.h index b349f008..d19098b4 100644 --- a/osal/os_allocator.h +++ b/osal/os_allocator.h @@ -22,7 +22,7 @@ typedef MPP_RET (*OsAllocatorFunc)(void *ctx, MppBufferInfo *info); typedef struct os_allocator_t { - MPP_RET (*open)(void **ctx, size_t alignment); + MPP_RET (*open)(void **ctx, MppAllocatorCfg *cfg); MPP_RET (*close)(void *ctx); OsAllocatorFunc alloc;