mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 09:06:50 +08:00
[osal]: add function log to allocator_ion
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1189 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include "os_mem.h"
|
#include "os_mem.h"
|
||||||
#include "allocator_ion.h"
|
#include "allocator_ion.h"
|
||||||
|
|
||||||
|
#include "mpp_env.h"
|
||||||
#include "mpp_mem.h"
|
#include "mpp_mem.h"
|
||||||
#include "mpp_log.h"
|
#include "mpp_log.h"
|
||||||
#include "mpp_common.h"
|
#include "mpp_common.h"
|
||||||
@@ -49,7 +50,9 @@ static RK_U32 ion_debug = 0;
|
|||||||
#define ION_DETECT_IOMMU_ENABLE (0x1) /* use ION_HEAP_TYPE_SYSTEM */
|
#define ION_DETECT_IOMMU_ENABLE (0x1) /* use ION_HEAP_TYPE_SYSTEM */
|
||||||
#define ION_DETECT_NO_DTS (0x2) /* use ION_HEAP_TYPE_CARVEOUT */
|
#define ION_DETECT_NO_DTS (0x2) /* use ION_HEAP_TYPE_CARVEOUT */
|
||||||
|
|
||||||
#define ion_dbg(flag, fmt, ...) _mpp_dbg(ion_debug, flag, fmt, ## __VA_ARGS__)
|
#define ion_dbg(flag, fmt, ...) _mpp_dbg(ion_debug, flag, fmt, ## __VA_ARGS__)
|
||||||
|
#define ion_dbg_f(flag, fmt, ...) _mpp_dbg_f(ion_debug, flag, fmt, ## __VA_ARGS__)
|
||||||
|
#define ion_dbg_func(fmt, ...) ion_dbg_f(ION_FUNCTION, fmt, ## __VA_ARGS__)
|
||||||
|
|
||||||
static int ion_ioctl(int fd, int req, void *arg)
|
static int ion_ioctl(int fd, int req, void *arg)
|
||||||
{
|
{
|
||||||
@@ -65,7 +68,7 @@ static int ion_ioctl(int fd, int req, void *arg)
|
|||||||
static int ion_alloc(int fd, size_t len, size_t align, unsigned int heap_mask,
|
static int ion_alloc(int fd, size_t len, size_t align, unsigned int heap_mask,
|
||||||
unsigned int flags, ion_user_handle_t *handle)
|
unsigned int flags, ion_user_handle_t *handle)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -EINVAL;
|
||||||
struct ion_allocation_data data = {
|
struct ion_allocation_data data = {
|
||||||
.len = len,
|
.len = len,
|
||||||
.align = align,
|
.align = align,
|
||||||
@@ -73,22 +76,31 @@ static int ion_alloc(int fd, size_t len, size_t align, unsigned int heap_mask,
|
|||||||
.flags = flags,
|
.flags = flags,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (handle == NULL)
|
ion_dbg_func("enter: fd %d len %d align %d heap_mask %x flags %x",
|
||||||
return -EINVAL;
|
fd, len, align, heap_mask, flags);
|
||||||
|
|
||||||
|
if (handle) {
|
||||||
|
ret = ion_ioctl(fd, ION_IOC_ALLOC, &data);
|
||||||
|
if (ret >= 0)
|
||||||
|
*handle = data.handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
ion_dbg_func("leave: ret %d\n", ret);
|
||||||
|
|
||||||
ret = ion_ioctl(fd, ION_IOC_ALLOC, &data);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
*handle = data.handle;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ion_free(int fd, ion_user_handle_t handle)
|
static int ion_free(int fd, ion_user_handle_t handle)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
struct ion_handle_data data = {
|
struct ion_handle_data data = {
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
};
|
};
|
||||||
return ion_ioctl(fd, ION_IOC_FREE, &data);
|
|
||||||
|
ion_dbg_func("enter: fd %d\n", fd);
|
||||||
|
ret = ion_ioctl(fd, ION_IOC_FREE, &data);
|
||||||
|
ion_dbg_func("leave: ret %d\n", ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ion_map(int fd, ion_user_handle_t handle, size_t length, int prot,
|
static int ion_map(int fd, ion_user_handle_t handle, size_t length, int prot,
|
||||||
@@ -181,6 +193,8 @@ RK_S32 check_sysfs_iommu()
|
|||||||
"vmalloc",
|
"vmalloc",
|
||||||
"system-heap",
|
"system-heap",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mpp_env_get_u32("ion_debug", &ion_debug, 0);
|
||||||
#ifdef SOFIA_3GR_LINUX
|
#ifdef SOFIA_3GR_LINUX
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
@@ -315,6 +329,8 @@ MPP_RET os_allocator_ion_alloc(void *ctx, MppBufferInfo *info)
|
|||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ion_dbg_func("enter: ctx %p size %d\n", ctx, info->size);
|
||||||
|
|
||||||
p = (allocator_ctx_ion *)ctx;
|
p = (allocator_ctx_ion *)ctx;
|
||||||
ret = ion_alloc(p->ion_device, info->size, p->alignment,
|
ret = ion_alloc(p->ion_device, info->size, p->alignment,
|
||||||
ion_heap_mask, 0,
|
ion_heap_mask, 0,
|
||||||
@@ -328,8 +344,9 @@ MPP_RET os_allocator_ion_alloc(void *ctx, MppBufferInfo *info)
|
|||||||
(unsigned char**)&info->ptr, &info->fd);
|
(unsigned char**)&info->ptr, &info->fd);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("os_allocator_ion_alloc ion_map failed ret %d\n", ret);
|
mpp_err("os_allocator_ion_alloc ion_map failed ret %d\n", ret);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ion_dbg_func("leave: ret %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,6 +356,8 @@ MPP_RET os_allocator_ion_import(void *ctx, MppBufferInfo *data)
|
|||||||
(void)ctx;
|
(void)ctx;
|
||||||
// NOTE: do not use the original buffer fd,
|
// NOTE: do not use the original buffer fd,
|
||||||
// use dup fd to avoid unexpected external fd close
|
// use dup fd to avoid unexpected external fd close
|
||||||
|
ion_dbg_func("enter: ctx %p fd %d size %d\n", ctx, data->fd, data->size);
|
||||||
|
|
||||||
data->fd = dup(data->fd);
|
data->fd = dup(data->fd);
|
||||||
data->ptr = mmap(NULL, data->size, PROT_READ | PROT_WRITE, MAP_SHARED, data->fd, 0);
|
data->ptr = mmap(NULL, data->size, PROT_READ | PROT_WRITE, MAP_SHARED, data->fd, 0);
|
||||||
if (data->ptr == MAP_FAILED) {
|
if (data->ptr == MAP_FAILED) {
|
||||||
@@ -348,14 +367,18 @@ MPP_RET os_allocator_ion_import(void *ctx, MppBufferInfo *data)
|
|||||||
data->fd = -1;
|
data->fd = -1;
|
||||||
data->ptr = NULL;
|
data->ptr = NULL;
|
||||||
}
|
}
|
||||||
|
ion_dbg_func("leave: ret %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPP_RET os_allocator_ion_release(void *ctx, MppBufferInfo *data)
|
MPP_RET os_allocator_ion_release(void *ctx, MppBufferInfo *data)
|
||||||
{
|
{
|
||||||
(void)ctx;
|
ion_dbg_func("enter: ctx %p fd %d ptr %p size %d\n", ctx, data->fd, data->ptr, data->size);
|
||||||
|
|
||||||
munmap(data->ptr, data->size);
|
munmap(data->ptr, data->size);
|
||||||
close(data->fd);
|
close(data->fd);
|
||||||
|
|
||||||
|
ion_dbg_func("leave\n");
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,10 +390,14 @@ MPP_RET os_allocator_ion_free(void *ctx, MppBufferInfo *data)
|
|||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ion_dbg_func("enter: ctx %p fd %d ptr %p size %d\n", ctx, data->fd, data->ptr, data->size);
|
||||||
|
|
||||||
p = (allocator_ctx_ion *)ctx;
|
p = (allocator_ctx_ion *)ctx;
|
||||||
munmap(data->ptr, data->size);
|
munmap(data->ptr, data->size);
|
||||||
close(data->fd);
|
close(data->fd);
|
||||||
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));
|
||||||
|
|
||||||
|
ion_dbg_func("leave\n");
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,12 +411,17 @@ MPP_RET os_allocator_ion_close(void *ctx)
|
|||||||
return MPP_ERR_NULL_PTR;
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ion_dbg_func("enter: ctx\n", ctx);
|
||||||
|
|
||||||
p = (allocator_ctx_ion *)ctx;
|
p = (allocator_ctx_ion *)ctx;
|
||||||
ret = close(p->ion_device);
|
ret = close(p->ion_device);
|
||||||
mpp_free(p);
|
mpp_free(p);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return (MPP_RET) - errno;
|
ret = (MPP_RET) - errno;
|
||||||
return MPP_OK;
|
|
||||||
|
ion_dbg_func("leave: ret %d\n", ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
os_allocator allocator_ion = {
|
os_allocator allocator_ion = {
|
||||||
|
Reference in New Issue
Block a user