[hal_jpege]: Add dma heap options for JPEG encode.

use cachable dma buffer to reduce copy time.

Signed-off-by: xueman.ruan <xueman.ruan@rock-chips.com>
Change-Id: I7fcc0fa5942ea5aa4e247b5f10677843d006ff28
This commit is contained in:
xueman.ruan 2023-02-14 10:03:23 +08:00 committed by Herman Chen
parent 59f7ccc6ed
commit 062c175265
12 changed files with 68 additions and 11 deletions

View File

@ -142,9 +142,14 @@ typedef enum {
* DRM SECURE buffer: MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_SECURE
* = 0x00080003
*
* The dma buffer source can also be set by format: flags | type.
* dma buffer source flags:
* MPP_BUFFER_FLAGS_CONTIG means cma
* MPP_BUFFER_FLAGS_CACHABLE means cachable
* MPP_BUFFER_FLAGS_DMA32 means dma32
*
* flags originate from drm_rockchip_gem_mem_type
*/
#define MPP_BUFFER_FLAGS_MASK 0x003f0000 //ROCKCHIP_BO_MASK << 16
#define MPP_BUFFER_FLAGS_CONTIG 0x00010000 //ROCKCHIP_BO_CONTIG << 16
#define MPP_BUFFER_FLAGS_CACHABLE 0x00020000 //ROCKCHIP_BO_CACHABLE << 16

View File

@ -29,6 +29,7 @@
#define MAX_GROUP_BIT 8
#define MAX_MISC_GROUP_BIT 3
#define BUFFER_OPS_MAX_COUNT 1024
#define MPP_BUFFER_SPECIAL_DMA_HEAP_NUM 8
#define SEARCH_GROUP_BY_ID(id) ((MppBufferService::get_instance())->get_group_by_id(id))
@ -63,6 +64,8 @@ private:
/* preset allocator apis */
MppAllocator mAllocator[MPP_BUFFER_TYPE_BUTT];
MppAllocatorApi *mAllocatorApi[MPP_BUFFER_TYPE_BUTT];
/* special dma heap allocator apis */
MppAllocator mAllocatorDmaHeapWithFlag[MPP_BUFFER_SPECIAL_DMA_HEAP_NUM];
struct list_head mListGroup;
DECLARE_HASHTABLE(mHashGroup, MAX_GROUP_BIT);
@ -777,9 +780,6 @@ MppBufferService::MppBufferService()
for (i = 0; i < (RK_S32)HASH_SIZE(mHashGroup); i++)
INIT_HLIST_HEAD(&mHashGroup[i]);
for (i = 0; i < MPP_BUFFER_TYPE_BUTT; i++)
mpp_allocator_get(&mAllocator[i], &mAllocatorApi[i], (MppBufferType)i);
}
#include "mpp_time.h"
@ -833,6 +833,9 @@ MppBufferService::~MppBufferService()
for (i = 0; i < MPP_BUFFER_TYPE_BUTT; i++)
mpp_allocator_put(&mAllocator[i]);
for (i = 1; i < MPP_BUFFER_SPECIAL_DMA_HEAP_NUM; i++)
mpp_allocator_put(&mAllocatorDmaHeapWithFlag[i]);
}
RK_U32 MppBufferService::get_group_id()
@ -868,6 +871,7 @@ 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);
MppBufferGroupImpl *p = (MppBufferGroupImpl *)mpp_mem_pool_get_f(caller, mpp_buf_grp_pool);
if (NULL == p) {
mpp_err("MppBufferService failed to allocate group context\n");
@ -896,8 +900,38 @@ MppBufferGroupImpl *MppBufferService::get_group(const char *tag, const char *cal
pthread_mutex_init(&p->buf_lock, &attr);
pthread_mutexattr_destroy(&attr);
p->allocator = mAllocator[type];
p->alloc_api = mAllocatorApi[type];
{
AutoMutex auto_lock(get_lock());
// allocate general buffer first
if (!mAllocator[buffer_type])
mpp_allocator_get(&mAllocator[buffer_type], &mAllocatorApi[buffer_type], buffer_type);
p->allocator = mAllocator[buffer_type];
p->alloc_api = mAllocatorApi[buffer_type];
// allocate extra dma heap buffer if necessary
if (flags && MPP_BUFFER_TYPE_DMA_HEAP == get_real_allocator_type(p->allocator)) {
RK_U32 extra_allocator_idx = 0;
// calculate index of extra allocator
if (flags & MPP_BUFFER_FLAGS_CONTIG)
extra_allocator_idx |= 1 << 0;
if (flags & MPP_BUFFER_FLAGS_CACHABLE)
extra_allocator_idx |= 1 << 1;
if (flags & MPP_BUFFER_FLAGS_DMA32)
extra_allocator_idx |= 1 << 2;
if (!mAllocatorDmaHeapWithFlag[extra_allocator_idx])
mpp_allocator_get(&mAllocatorDmaHeapWithFlag[extra_allocator_idx],
&p->alloc_api, type);
if (mAllocatorDmaHeapWithFlag[extra_allocator_idx])
p->allocator = mAllocatorDmaHeapWithFlag[extra_allocator_idx];
}
}
mpp_assert(p->allocator);
mpp_assert(p->alloc_api);

View File

@ -208,8 +208,11 @@ MPP_RET hal_jpege_vepu2_get_task(void *hal, HalEncTask *task)
mpp_assert(ctx_ext);
if (!ctx_ext->partions_group)
mpp_buffer_group_get_internal(&ctx_ext->partions_group, MPP_BUFFER_TYPE_ION);
if (!ctx_ext->partions_group) {
mpp_buffer_group_get_internal(&ctx_ext->partions_group, MPP_BUFFER_TYPE_DMA_HEAP | MPP_BUFFER_FLAGS_CACHABLE);
if (!ctx_ext->partions_group)
mpp_buffer_group_get_internal(&ctx_ext->partions_group, MPP_BUFFER_TYPE_ION);
}
mpp_assert(ctx_ext->partions_group);

View File

@ -100,7 +100,7 @@ static int dma_heap_alloc(int fd, size_t len, RK_S32 *dmabuf_fd, RK_U32 flags)
memset(&data, 0, sizeof(data));
data.len = len;
data.fd_flags = O_RDWR | O_CLOEXEC;
data.heap_flags = flags;
data.heap_flags = 0; // heap_flags should be set to 0
ret = ioctl(fd, DMA_HEAP_IOCTL_ALLOC, &data);
@ -132,7 +132,7 @@ static int heap_fd_open(DmaHeapType type)
int fd;
snprintf(name, sizeof(name) - 1, "%s%s", heap_path, heap_names[type]);
fd = open(name, O_RDWR | O_CLOEXEC);
fd = open(name, O_RDONLY | O_CLOEXEC); // read authority is enough
mpp_assert(fd > 0);
dma_heap_dbg(DMA_HEAP_DEVICE, "open dma heap dev %s fd %d\n", name, fd);
@ -320,6 +320,7 @@ static MPP_RET os_allocator_dma_heap_mmap(void *ctx, MppBufferInfo *data)
}
os_allocator allocator_dma_heap = {
.type = MPP_BUFFER_TYPE_DMA_HEAP,
.open = os_allocator_dma_heap_open,
.close = os_allocator_dma_heap_close,
.alloc = os_allocator_dma_heap_alloc,

View File

@ -322,6 +322,7 @@ static MPP_RET os_allocator_drm_mmap(void *ctx, MppBufferInfo *data)
}
os_allocator allocator_drm = {
.type = MPP_BUFFER_TYPE_DRM,
.open = os_allocator_drm_open,
.close = os_allocator_drm_close,
.alloc = os_allocator_drm_alloc,

View File

@ -135,6 +135,7 @@ static MPP_RET allocator_ext_dma_close(void *ctx)
}
os_allocator allocator_ext_dma = {
.type = MPP_BUFFER_TYPE_EXT_DMA,
.open = allocator_ext_dma_open,
.close = allocator_ext_dma_close,
.alloc = allocator_ext_dma_alloc,

View File

@ -482,6 +482,7 @@ static MPP_RET allocator_ion_close(void *ctx)
}
os_allocator allocator_ion = {
.type = MPP_BUFFER_TYPE_ION,
.open = allocator_ion_open,
.close = allocator_ion_close,
.alloc = allocator_ion_alloc,

View File

@ -114,6 +114,7 @@ static MPP_RET allocator_std_close(void *ctx)
}
os_allocator allocator_std = {
.type = MPP_BUFFER_TYPE_NORMAL,
.open = allocator_std_open,
.close = allocator_std_close,
.alloc = allocator_std_alloc,

View File

@ -46,6 +46,7 @@ extern "C" {
MPP_RET mpp_allocator_get(MppAllocator *allocator,
MppAllocatorApi **api, MppBufferType type);
MPP_RET mpp_allocator_put(MppAllocator *allocator);
MppBufferType get_real_allocator_type(const MppAllocator allocator);
#ifdef __cplusplus
}

View File

@ -189,3 +189,10 @@ MPP_RET mpp_allocator_put(MppAllocator *allocator)
return MPP_OK;
}
MppBufferType get_real_allocator_type(const MppAllocator allocator)
{
MppAllocatorImpl *p = (MppAllocatorImpl *)allocator;
MppBufferType type = allocator ? p->os_api.type : MPP_BUFFER_TYPE_BUTT;
return type;
}

View File

@ -86,7 +86,7 @@ MppRuntimeService::MppRuntimeService()
allocator_valid[MPP_BUFFER_TYPE_NORMAL] = 1;
allocator_valid[MPP_BUFFER_TYPE_ION] = !access("/dev/ion", F_OK | R_OK | W_OK);
allocator_valid[MPP_BUFFER_TYPE_DRM] = !access("/dev/dri/card0", F_OK | R_OK | W_OK);
allocator_valid[MPP_BUFFER_TYPE_DMA_HEAP] = !access("/dev/dma_heap", F_OK | R_OK | W_OK);
allocator_valid[MPP_BUFFER_TYPE_DMA_HEAP] = !access("/dev/dma_heap", F_OK | R_OK);
if (!allocator_valid[MPP_BUFFER_TYPE_ION] &&
!allocator_valid[MPP_BUFFER_TYPE_DRM] &&

View File

@ -22,6 +22,8 @@
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);