Merge "msm: camera: memmgr: Re-structure ion alloc usage" into camera-kernel.lnx.5.0
This commit is contained in:

committed by
Gerrit - the friendly Code Review server

commit
541b3d709a
@@ -409,72 +409,48 @@ end:
|
|||||||
EXPORT_SYMBOL(cam_mem_mgr_cache_ops);
|
EXPORT_SYMBOL(cam_mem_mgr_cache_ops);
|
||||||
|
|
||||||
static int cam_mem_util_get_dma_buf(size_t len,
|
static int cam_mem_util_get_dma_buf(size_t len,
|
||||||
unsigned int heap_id_mask,
|
unsigned int cam_flags,
|
||||||
unsigned int flags,
|
|
||||||
struct dma_buf **buf)
|
struct dma_buf **buf)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
unsigned int heap_id;
|
||||||
|
int32_t ion_flag = 0;
|
||||||
|
struct timespec64 ts1, ts2;
|
||||||
|
long microsec = 0;
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
CAM_ERR(CAM_MEM, "Invalid params");
|
CAM_ERR(CAM_MEM, "Invalid params");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tbl.force_cache_allocs && (!(flags & ION_FLAG_SECURE)))
|
|
||||||
flags |= ION_FLAG_CACHED;
|
|
||||||
|
|
||||||
*buf = ion_alloc(len, heap_id_mask, flags);
|
|
||||||
if (IS_ERR_OR_NULL(*buf))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cam_mem_util_get_dma_buf_fd(size_t len,
|
|
||||||
size_t align,
|
|
||||||
unsigned int heap_id_mask,
|
|
||||||
unsigned int flags,
|
|
||||||
struct dma_buf **buf,
|
|
||||||
int *fd)
|
|
||||||
{
|
|
||||||
struct dma_buf *dmabuf = NULL;
|
|
||||||
int rc = 0;
|
|
||||||
struct timespec64 ts1, ts2;
|
|
||||||
long microsec = 0;
|
|
||||||
|
|
||||||
if (!buf || !fd) {
|
|
||||||
CAM_ERR(CAM_MEM, "Invalid params, buf=%pK, fd=%pK", buf, fd);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tbl.alloc_profile_enable)
|
if (tbl.alloc_profile_enable)
|
||||||
CAM_GET_TIMESTAMP(ts1);
|
CAM_GET_TIMESTAMP(ts1);
|
||||||
|
|
||||||
if (tbl.force_cache_allocs && (!(flags & ION_FLAG_SECURE)))
|
if ((cam_flags & CAM_MEM_FLAG_PROTECTED_MODE) &&
|
||||||
flags |= ION_FLAG_CACHED;
|
(cam_flags & CAM_MEM_FLAG_CDSP_OUTPUT)) {
|
||||||
|
heap_id = ION_HEAP(ION_SECURE_DISPLAY_HEAP_ID);
|
||||||
|
ion_flag |=
|
||||||
|
ION_FLAG_SECURE | ION_FLAG_CP_CAMERA | ION_FLAG_CP_CDSP;
|
||||||
|
} else if (cam_flags & CAM_MEM_FLAG_PROTECTED_MODE) {
|
||||||
|
heap_id = ION_HEAP(ION_SECURE_DISPLAY_HEAP_ID);
|
||||||
|
ion_flag |= ION_FLAG_SECURE | ION_FLAG_CP_CAMERA;
|
||||||
|
} else {
|
||||||
|
heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID) |
|
||||||
|
ION_HEAP(ION_CAMERA_HEAP_ID);
|
||||||
|
}
|
||||||
|
|
||||||
*buf = ion_alloc(len, heap_id_mask, flags);
|
if (cam_flags & CAM_MEM_FLAG_CACHE)
|
||||||
|
ion_flag |= ION_FLAG_CACHED;
|
||||||
|
else
|
||||||
|
ion_flag &= ~ION_FLAG_CACHED;
|
||||||
|
|
||||||
|
if (tbl.force_cache_allocs && (!(ion_flag & ION_FLAG_SECURE)))
|
||||||
|
ion_flag |= ION_FLAG_CACHED;
|
||||||
|
|
||||||
|
*buf = ion_alloc(len, heap_id, ion_flag);
|
||||||
if (IS_ERR_OR_NULL(*buf))
|
if (IS_ERR_OR_NULL(*buf))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*fd = dma_buf_fd(*buf, O_CLOEXEC);
|
|
||||||
if (*fd < 0) {
|
|
||||||
CAM_ERR(CAM_MEM, "get fd fail, *fd=%d", *fd);
|
|
||||||
rc = -EINVAL;
|
|
||||||
goto get_fd_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* increment the ref count so that ref count becomes 2 here
|
|
||||||
* when we close fd, refcount becomes 1 and when we do
|
|
||||||
* dmap_put_buf, ref count becomes 0 and memory will be freed.
|
|
||||||
*/
|
|
||||||
dmabuf = dma_buf_get(*fd);
|
|
||||||
if (IS_ERR_OR_NULL(dmabuf)) {
|
|
||||||
CAM_ERR(CAM_MEM, "dma_buf_get failed, *fd=%d", *fd);
|
|
||||||
rc = -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tbl.alloc_profile_enable) {
|
if (tbl.alloc_profile_enable) {
|
||||||
CAM_GET_TIMESTAMP(ts2);
|
CAM_GET_TIMESTAMP(ts2);
|
||||||
CAM_GET_TIMESTAMP_DIFF_IN_MICRO(ts1, ts2, microsec);
|
CAM_GET_TIMESTAMP_DIFF_IN_MICRO(ts1, ts2, microsec);
|
||||||
@@ -483,48 +459,50 @@ static int cam_mem_util_get_dma_buf_fd(size_t len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
get_fd_fail:
|
|
||||||
dma_buf_put(*buf);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cam_mem_util_ion_alloc(struct cam_mem_mgr_alloc_cmd *cmd,
|
static int cam_mem_util_ion_alloc(struct cam_mem_mgr_alloc_cmd *cmd,
|
||||||
struct dma_buf **dmabuf,
|
struct dma_buf **dmabuf,
|
||||||
int *fd)
|
int *fd)
|
||||||
{
|
{
|
||||||
uint32_t heap_id;
|
|
||||||
uint32_t ion_flag = 0;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
struct dma_buf *temp_dmabuf = NULL;
|
||||||
|
|
||||||
if ((cmd->flags & CAM_MEM_FLAG_PROTECTED_MODE) &&
|
rc = cam_mem_util_get_dma_buf(cmd->len,
|
||||||
(cmd->flags & CAM_MEM_FLAG_CDSP_OUTPUT)) {
|
cmd->flags,
|
||||||
heap_id = ION_HEAP(ION_SECURE_DISPLAY_HEAP_ID);
|
dmabuf);
|
||||||
ion_flag |=
|
if (rc) {
|
||||||
ION_FLAG_SECURE | ION_FLAG_CP_CAMERA | ION_FLAG_CP_CDSP;
|
CAM_ERR(CAM_MEM,
|
||||||
} else if (cmd->flags & CAM_MEM_FLAG_PROTECTED_MODE) {
|
"Error allocating dma buf : len=%llu, flags=0x%x",
|
||||||
heap_id = ION_HEAP(ION_SECURE_DISPLAY_HEAP_ID);
|
cmd->len, cmd->flags);
|
||||||
ion_flag |= ION_FLAG_SECURE | ION_FLAG_CP_CAMERA;
|
return rc;
|
||||||
} else {
|
|
||||||
heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID) |
|
|
||||||
ION_HEAP(ION_CAMERA_HEAP_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->flags & CAM_MEM_FLAG_CACHE)
|
*fd = dma_buf_fd(*dmabuf, O_CLOEXEC);
|
||||||
ion_flag |= ION_FLAG_CACHED;
|
if (*fd < 0) {
|
||||||
else
|
CAM_ERR(CAM_MEM, "get fd fail, *fd=%d", *fd);
|
||||||
ion_flag &= ~ION_FLAG_CACHED;
|
rc = -EINVAL;
|
||||||
|
goto put_buf;
|
||||||
|
}
|
||||||
|
|
||||||
rc = cam_mem_util_get_dma_buf_fd(cmd->len,
|
/*
|
||||||
cmd->align,
|
* increment the ref count so that ref count becomes 2 here
|
||||||
heap_id,
|
* when we close fd, refcount becomes 1 and when we do
|
||||||
ion_flag,
|
* dmap_put_buf, ref count becomes 0 and memory will be freed.
|
||||||
dmabuf,
|
*/
|
||||||
fd);
|
temp_dmabuf = dma_buf_get(*fd);
|
||||||
|
if (IS_ERR_OR_NULL(temp_dmabuf)) {
|
||||||
|
CAM_ERR(CAM_MEM, "dma_buf_get failed, *fd=%d", *fd);
|
||||||
|
rc = -EINVAL;
|
||||||
|
goto put_buf;
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
|
||||||
|
|
||||||
|
put_buf:
|
||||||
|
dma_buf_put(*dmabuf);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
static int cam_mem_util_check_alloc_flags(struct cam_mem_mgr_alloc_cmd *cmd)
|
static int cam_mem_util_check_alloc_flags(struct cam_mem_mgr_alloc_cmd *cmd)
|
||||||
{
|
{
|
||||||
@@ -1189,8 +1167,6 @@ int cam_mem_mgr_request_mem(struct cam_mem_mgr_request_desc *inp,
|
|||||||
struct dma_buf *buf = NULL;
|
struct dma_buf *buf = NULL;
|
||||||
int ion_fd = -1;
|
int ion_fd = -1;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
uint32_t heap_id;
|
|
||||||
int32_t ion_flag = 0;
|
|
||||||
uintptr_t kvaddr;
|
uintptr_t kvaddr;
|
||||||
dma_addr_t iova = 0;
|
dma_addr_t iova = 0;
|
||||||
size_t request_len = 0;
|
size_t request_len = 0;
|
||||||
@@ -1218,17 +1194,8 @@ int cam_mem_mgr_request_mem(struct cam_mem_mgr_request_desc *inp,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inp->flags & CAM_MEM_FLAG_CACHE)
|
|
||||||
ion_flag |= ION_FLAG_CACHED;
|
|
||||||
else
|
|
||||||
ion_flag &= ~ION_FLAG_CACHED;
|
|
||||||
|
|
||||||
heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID) |
|
|
||||||
ION_HEAP(ION_CAMERA_HEAP_ID);
|
|
||||||
|
|
||||||
rc = cam_mem_util_get_dma_buf(inp->size,
|
rc = cam_mem_util_get_dma_buf(inp->size,
|
||||||
heap_id,
|
inp->flags,
|
||||||
ion_flag,
|
|
||||||
&buf);
|
&buf);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
@@ -1372,7 +1339,6 @@ int cam_mem_mgr_reserve_memory_region(struct cam_mem_mgr_request_desc *inp,
|
|||||||
struct dma_buf *buf = NULL;
|
struct dma_buf *buf = NULL;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int ion_fd = -1;
|
int ion_fd = -1;
|
||||||
uint32_t heap_id;
|
|
||||||
dma_addr_t iova = 0;
|
dma_addr_t iova = 0;
|
||||||
size_t request_len = 0;
|
size_t request_len = 0;
|
||||||
uint32_t mem_handle;
|
uint32_t mem_handle;
|
||||||
@@ -1400,10 +1366,7 @@ int cam_mem_mgr_reserve_memory_region(struct cam_mem_mgr_request_desc *inp,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID) |
|
|
||||||
ION_HEAP(ION_CAMERA_HEAP_ID);
|
|
||||||
rc = cam_mem_util_get_dma_buf(inp->size,
|
rc = cam_mem_util_get_dma_buf(inp->size,
|
||||||
heap_id,
|
|
||||||
0,
|
0,
|
||||||
&buf);
|
&buf);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user