[ion]: file descriptor for the external buffer

The imported buffer may be released from its origin allocator,
I would suggest to use the new file descriptor from new ion
handle.

The ion only has map_user() to export buffer to userspace,
There is no unmap_user() because the mapping is represented as
a file descriptor in user space. The closing of that file
descriptor will cause the memory to be unmapped from
the calling process.

Change-Id: Ief855aab11793238b40b73da92af853ca3b58349
Signed-off-by: Randy Li <randy.li@rock-chips.com>
Signed-off-by: ayaka <ayaka@soulik.info>
This commit is contained in:
Randy Li
2017-05-10 09:29:42 +08:00
committed by Herman Chen
parent 167c7dd9cf
commit c56a9365f6
2 changed files with 11 additions and 32 deletions

View File

@@ -360,7 +360,7 @@ static MPP_RET allocator_ion_alloc(void *ctx, MppBufferInfo *info)
info->fd = fd; info->fd = fd;
info->ptr = NULL; info->ptr = NULL;
info->hnd = (void *)hnd; info->hnd = (void *)(intptr_t)hnd;
ion_dbg_func("leave: ret %d handle %d fd %d\n", ret, hnd, fd); ion_dbg_func("leave: ret %d handle %d fd %d\n", ret, hnd, fd);
return ret; return ret;
@@ -377,12 +377,13 @@ static MPP_RET allocator_ion_import(void *ctx, MppBufferInfo *data)
fd_data.fd = data->fd; fd_data.fd = data->fd;
ret = ion_ioctl(p->ion_device, ION_IOC_IMPORT, &fd_data); ret = ion_ioctl(p->ion_device, ION_IOC_IMPORT, &fd_data);
if (NULL == (void *)fd_data.handle) { if (0 > fd_data.handle) {
mpp_err_f("fd %d import failed for %s\n", data->fd, strerror(errno)); mpp_err_f("fd %d import failed for %s\n", data->fd, strerror(errno));
goto RET; goto RET;
} }
data->hnd = (void *)fd_data.handle; data->hnd = (void *)(intptr_t)fd_data.handle;
ret = ion_map_fd(p->ion_device, fd_data.handle, &data->fd);
data->ptr = NULL; data->ptr = NULL;
RET: RET:
ion_dbg_func("leave: ret %d handle %d\n", ret, data->hnd); ion_dbg_func("leave: ret %d handle %d\n", ret, data->hnd);
@@ -408,37 +409,11 @@ static MPP_RET allocator_ion_mmap(void *ctx, MppBufferInfo *data)
return ret; return ret;
} }
static MPP_RET allocator_ion_release(void *ctx, MppBufferInfo *data)
{
ion_dbg_func("enter: ctx %p handle %d fd %d ptr %p size %d\n",
ctx, (intptr_t)data->hnd, data->fd, data->ptr, data->size);
allocator_ctx_ion *p = NULL;
if (NULL == ctx) {
mpp_err_f("do not accept NULL input\n");
return MPP_ERR_NULL_PTR;
}
p = (allocator_ctx_ion *)ctx;
if (data->ptr) {
munmap(data->ptr, data->size);
data->ptr = NULL;
}
if (data->hnd) {
ion_free(p->ion_device, (ion_user_handle_t)((intptr_t)data->hnd));
data->hnd = NULL;
}
ion_dbg_func("leave\n");
return MPP_OK;
}
static MPP_RET allocator_ion_free(void *ctx, MppBufferInfo *data) static MPP_RET allocator_ion_free(void *ctx, MppBufferInfo *data)
{ {
allocator_ctx_ion *p = NULL; allocator_ctx_ion *p = NULL;
if (NULL == ctx) { if (NULL == ctx) {
mpp_err("os_allocator_close Android do not accept NULL input\n"); mpp_err_f("do not accept NULL input\n");
return MPP_ERR_NULL_PTR; return MPP_ERR_NULL_PTR;
} }
@@ -450,10 +425,12 @@ static MPP_RET allocator_ion_free(void *ctx, MppBufferInfo *data)
munmap(data->ptr, data->size); munmap(data->ptr, data->size);
data->ptr = NULL; data->ptr = NULL;
} }
if (data->fd > 0) { if (data->fd > 0) {
close(data->fd); close(data->fd);
data->fd = -1; data->fd = -1;
} }
if (data->hnd) { if (data->hnd) {
ion_free(p->ion_device, (ion_user_handle_t)((intptr_t)data->hnd)); ion_free(p->ion_device, (ion_user_handle_t)((intptr_t)data->hnd));
data->hnd = NULL; data->hnd = NULL;
@@ -492,7 +469,7 @@ os_allocator allocator_ion = {
.alloc = allocator_ion_alloc, .alloc = allocator_ion_alloc,
.free = allocator_ion_free, .free = allocator_ion_free,
.import = allocator_ion_import, .import = allocator_ion_import,
.release = allocator_ion_release, .release = allocator_ion_free,
.mmap = allocator_ion_mmap, .mmap = allocator_ion_mmap,
}; };

View File

@@ -18,8 +18,10 @@
#include "mpp_log.h" #include "mpp_log.h"
#include "allocator_std.h" #include "allocator_std.h"
#include "allocator_drm.h"
#include "allocator_ion.h" #include "allocator_ion.h"
#ifdef HAVE_DRM
#include "allocator_drm.h"
#endif
/* /*
* Linux only support MPP_BUFFER_TYPE_NORMAL so far * Linux only support MPP_BUFFER_TYPE_NORMAL so far