From cf223fa7b3b3c5326d1975be4cb43b004f06cc08 Mon Sep 17 00:00:00 2001 From: Fengjie Chen Date: Tue, 14 Dec 2021 17:55:15 +0800 Subject: [PATCH] msm: camera: memmgr: Set name for dma buffer to help profiling For dma buffer profiling,we don't konw the owner of one dma buffer. So we add it's name to show it's owner. If you use v1 struct to alloc/map dma buffer it will use default buffer name "UNKNOWN". For v2 struct you can set dma buffer name at UMD side. CRs-Fixed: 3131442 Change-Id: I24ce6aa1d97cd9fc26d9bd8796ab2367607008f6 Signed-off-by: Fengjie Chen --- drivers/cam_req_mgr/cam_mem_mgr.c | 22 +++++--- drivers/cam_req_mgr/cam_mem_mgr.h | 4 +- drivers/cam_req_mgr/cam_req_mgr_dev.c | 69 ++++++++++++++++++++++++- drivers/cam_utils/cam_compat.c | 17 ++++++ drivers/cam_utils/cam_compat.h | 2 + include/uapi/camera/media/cam_req_mgr.h | 68 ++++++++++++++++++++++++ 6 files changed, 170 insertions(+), 12 deletions(-) diff --git a/drivers/cam_req_mgr/cam_mem_mgr.c b/drivers/cam_req_mgr/cam_mem_mgr.c index 07666d630d..1310551700 100644 --- a/drivers/cam_req_mgr/cam_mem_mgr.c +++ b/drivers/cam_req_mgr/cam_mem_mgr.c @@ -796,7 +796,7 @@ put_buf: 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_v2 *cmd) { if (cmd->num_hdl > CAM_MEM_MMU_MAX_HANDLE) { CAM_ERR(CAM_MEM, "Num of mmu hdl exceeded maximum(%d)", @@ -820,7 +820,7 @@ static int cam_mem_util_check_alloc_flags(struct cam_mem_mgr_alloc_cmd *cmd) return 0; } -static int cam_mem_util_check_map_flags(struct cam_mem_mgr_map_cmd *cmd) +static int cam_mem_util_check_map_flags(struct cam_mem_mgr_map_cmd_v2 *cmd) { if (!cmd->flags) { CAM_ERR(CAM_MEM, "Invalid flags"); @@ -911,7 +911,7 @@ multi_map_fail: return rc; } -int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd) +int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd_v2 *cmd) { int rc; int32_t idx; @@ -971,6 +971,9 @@ int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd) goto slot_fail; } + if (cam_dma_buf_set_name(dmabuf, cmd->buf_name)) + CAM_ERR(CAM_MEM, "set dma buffer name(%s) failed", cmd->buf_name); + if ((cmd->flags & CAM_MEM_FLAG_HW_READ_WRITE) || (cmd->flags & CAM_MEM_FLAG_HW_SHARED_ACCESS) || (cmd->flags & CAM_MEM_FLAG_PROTECTED_MODE)) { @@ -1049,9 +1052,9 @@ int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd) cmd->out.vaddr = 0; CAM_DBG(CAM_MEM, - "fd=%d, flags=0x%x, num_hdl=%d, idx=%d, buf handle=%x, len=%zu, i_ino=%lu", + "fd=%d, flags=0x%x, num_hdl=%d, idx=%d, buf handle=%x, len=%zu, i_ino=%lu, name:%s", cmd->out.fd, cmd->flags, cmd->num_hdl, idx, cmd->out.buf_handle, - tbl.bufq[idx].len, tbl.bufq[idx].i_ino); + tbl.bufq[idx].len, tbl.bufq[idx].i_ino, cmd->buf_name); return rc; @@ -1081,7 +1084,7 @@ static bool cam_mem_util_is_map_internal(int32_t fd, unsigned i_ino) return is_internal; } -int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd) +int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd_v2 *cmd) { int32_t idx; int rc; @@ -1131,6 +1134,9 @@ int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd) goto slot_fail; } + if (cam_dma_buf_set_name(dmabuf, cmd->buf_name)) + CAM_ERR(CAM_MEM, "set dma buffer name(%s) failed", cmd->buf_name); + if ((cmd->flags & CAM_MEM_FLAG_HW_READ_WRITE) || (cmd->flags & CAM_MEM_FLAG_PROTECTED_MODE)) { rc = cam_mem_util_map_hw_va(cmd->flags, @@ -1185,9 +1191,9 @@ int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd) cmd->out.vaddr = 0; cmd->out.size = (uint32_t)len; CAM_DBG(CAM_MEM, - "fd=%d, flags=0x%x, num_hdl=%d, idx=%d, buf handle=%x, len=%zu, i_ino=%lu", + "fd=%d, flags=0x%x, num_hdl=%d, idx=%d, buf handle=%x, len=%zu, i_ino=%lu, name:%s", cmd->fd, cmd->flags, cmd->num_hdl, idx, cmd->out.buf_handle, - tbl.bufq[idx].len, tbl.bufq[idx].i_ino); + tbl.bufq[idx].len, tbl.bufq[idx].i_ino, cmd->buf_name); return rc; map_fail: diff --git a/drivers/cam_req_mgr/cam_mem_mgr.h b/drivers/cam_req_mgr/cam_mem_mgr.h index 51025b7fbc..174377484e 100644 --- a/drivers/cam_req_mgr/cam_mem_mgr.h +++ b/drivers/cam_req_mgr/cam_mem_mgr.h @@ -139,7 +139,7 @@ struct cam_mem_table_mini_dump { * * @return Status of operation. Negative in case of error. Zero otherwise. */ -int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd); +int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd_v2 *cmd); /** * @brief: Releases a buffer reference @@ -157,7 +157,7 @@ int cam_mem_mgr_release(struct cam_mem_mgr_release_cmd *cmd); * * @return Status of operation. Negative in case of error. Zero otherwise. */ -int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd); +int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd_v2 *cmd); /** * @brief: Perform cache ops on the buffer diff --git a/drivers/cam_req_mgr/cam_req_mgr_dev.c b/drivers/cam_req_mgr/cam_req_mgr_dev.c index 33cd4367a6..43b0adb494 100644 --- a/drivers/cam_req_mgr/cam_req_mgr_dev.c +++ b/drivers/cam_req_mgr/cam_req_mgr_dev.c @@ -493,6 +493,7 @@ static long cam_private_ioctl(struct file *file, void *fh, break; case CAM_REQ_MGR_ALLOC_BUF: { struct cam_mem_mgr_alloc_cmd cmd; + struct cam_mem_mgr_alloc_cmd_v2 cmd_v2 = {0}; if (k_ioctl->size != sizeof(cmd)) return -EINVAL; @@ -504,7 +505,16 @@ static long cam_private_ioctl(struct file *file, void *fh, break; } - rc = cam_mem_mgr_alloc_and_map(&cmd); + strscpy(cmd_v2.buf_name, "UNKNOWN", CAM_DMA_BUF_NAME_LEN); + memcpy(cmd_v2.mmu_hdls, cmd.mmu_hdls, + sizeof(__s32) * CAM_MEM_MMU_MAX_HANDLE); + cmd_v2.num_hdl = cmd.num_hdl; + cmd_v2.flags = cmd.flags; + cmd_v2.len = cmd.len; + cmd_v2.align = cmd.align; + + rc = cam_mem_mgr_alloc_and_map(&cmd_v2); + memcpy(&cmd.out, &cmd_v2.out, sizeof(cmd.out)); if (!rc) if (copy_to_user( u64_to_user_ptr(k_ioctl->handle), @@ -514,8 +524,32 @@ static long cam_private_ioctl(struct file *file, void *fh, } } break; + case CAM_REQ_MGR_ALLOC_BUF_V2: { + struct cam_mem_mgr_alloc_cmd_v2 cmd; + + if (k_ioctl->size != sizeof(cmd)) + return -EINVAL; + + if (copy_from_user(&cmd, + u64_to_user_ptr(k_ioctl->handle), + sizeof(struct cam_mem_mgr_alloc_cmd_v2))) { + rc = -EFAULT; + break; + } + + rc = cam_mem_mgr_alloc_and_map(&cmd); + if (!rc) + if (copy_to_user( + u64_to_user_ptr(k_ioctl->handle), + &cmd, sizeof(struct cam_mem_mgr_alloc_cmd_v2))) { + rc = -EFAULT; + break; + } + } + break; case CAM_REQ_MGR_MAP_BUF: { struct cam_mem_mgr_map_cmd cmd; + struct cam_mem_mgr_map_cmd_v2 cmd_v2 = {0}; if (k_ioctl->size != sizeof(cmd)) return -EINVAL; @@ -527,7 +561,15 @@ static long cam_private_ioctl(struct file *file, void *fh, break; } - rc = cam_mem_mgr_map(&cmd); + strscpy(cmd_v2.buf_name, "UNKNOWN", CAM_DMA_BUF_NAME_LEN); + memcpy(cmd_v2.mmu_hdls, cmd.mmu_hdls, + sizeof(__s32) * CAM_MEM_MMU_MAX_HANDLE); + cmd_v2.num_hdl = cmd.num_hdl; + cmd_v2.flags = cmd.flags; + cmd_v2.fd = cmd.fd; + + rc = cam_mem_mgr_map(&cmd_v2); + memcpy(&cmd.out, &cmd_v2.out, sizeof(cmd.out)); if (!rc) if (copy_to_user( u64_to_user_ptr(k_ioctl->handle), @@ -537,6 +579,29 @@ static long cam_private_ioctl(struct file *file, void *fh, } } break; + case CAM_REQ_MGR_MAP_BUF_V2: { + struct cam_mem_mgr_map_cmd_v2 cmd; + + if (k_ioctl->size != sizeof(cmd)) + return -EINVAL; + + if (copy_from_user(&cmd, + u64_to_user_ptr(k_ioctl->handle), + sizeof(struct cam_mem_mgr_map_cmd_v2))) { + rc = -EFAULT; + break; + } + + rc = cam_mem_mgr_map(&cmd); + if (!rc) + if (copy_to_user( + u64_to_user_ptr(k_ioctl->handle), + &cmd, sizeof(struct cam_mem_mgr_map_cmd_v2))) { + rc = -EFAULT; + break; + } + } + break; case CAM_REQ_MGR_RELEASE_BUF: { struct cam_mem_mgr_release_cmd cmd; diff --git a/drivers/cam_utils/cam_compat.c b/drivers/cam_utils/cam_compat.c index 5ce0353bb3..4111125739 100644 --- a/drivers/cam_utils/cam_compat.c +++ b/drivers/cam_utils/cam_compat.c @@ -5,6 +5,7 @@ */ #include +#include #include #include @@ -417,3 +418,19 @@ int cam_sensor_i3c_driver_remove(struct i3c_device *client) return 0; } #endif + +#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE +long cam_dma_buf_set_name(struct dma_buf *dmabuf, const char *name) +{ + long ret = 0; + + ret = dma_buf_set_name(dmabuf, name); + + return ret; +} +#else +long cam_dma_buf_set_name(struct dma_buf *dmabuf, const char *name) +{ + return 0; +} +#endif diff --git a/drivers/cam_utils/cam_compat.h b/drivers/cam_utils/cam_compat.h index 9285cbf55d..8a1c6a99e7 100644 --- a/drivers/cam_utils/cam_compat.h +++ b/drivers/cam_utils/cam_compat.h @@ -65,4 +65,6 @@ int cam_req_mgr_ordered_list_cmp(void *priv, int cam_sensor_i3c_driver_remove(struct i3c_device *client); #endif +long cam_dma_buf_set_name(struct dma_buf *dmabuf, const char *name); + #endif /* _CAM_COMPAT_H_ */ diff --git a/include/uapi/camera/media/cam_req_mgr.h b/include/uapi/camera/media/cam_req_mgr.h index 98728381d5..378eb23e2a 100644 --- a/include/uapi/camera/media/cam_req_mgr.h +++ b/include/uapi/camera/media/cam_req_mgr.h @@ -69,6 +69,10 @@ #define CAM_REQ_MGR_LINK_ACTIVATE 0 #define CAM_REQ_MGR_LINK_DEACTIVATE 1 +/* DMA buffer name length */ +#define CAM_DMA_BUF_NAME_LEN 128 +#define CAM_REQ_MGR_ALLOC_BUF_WITH_NAME 1 + /** * Request Manager : flush_type * @CAM_REQ_MGR_FLUSH_TYPE_ALL: Req mgr will remove all the pending @@ -338,6 +342,8 @@ struct cam_req_mgr_link_properties { #define CAM_REQ_MGR_REQUEST_DUMP (CAM_COMMON_OPCODE_MAX + 15) #define CAM_REQ_MGR_SCHED_REQ_V2 (CAM_COMMON_OPCODE_MAX + 16) #define CAM_REQ_MGR_LINK_PROPERTIES (CAM_COMMON_OPCODE_MAX + 17) +#define CAM_REQ_MGR_ALLOC_BUF_V2 (CAM_COMMON_OPCODE_MAX + 18) +#define CAM_REQ_MGR_MAP_BUF_V2 (CAM_COMMON_OPCODE_MAX + 19) /* end of cam_req_mgr opcodes */ @@ -450,6 +456,37 @@ struct cam_mem_mgr_alloc_cmd { struct cam_mem_alloc_out_params out; }; +/** + * struct cam_mem_mgr_alloc_cmd_v2 + * @version: Struct version + * @num_hdl: number of handles + * @mmu_hdls: array of mmu handles + * @len: size of buffer to allocate + * @align: alignment of the buffer + * @vmids: reserved + * @buf_name: DMA buffer name + * @flags: flags of the buffer + * @num_valid_params: Valid number of params being used + * @valid_param_mask: Mask to indicate the field types in params + * @params: Additional params + * @out: out params + */ +/* CAM_REQ_MGR_ALLOC_BUF_V2 */ +struct cam_mem_mgr_alloc_cmd_v2 { + __u32 version; + __u32 num_hdl; + __s32 mmu_hdls[CAM_MEM_MMU_MAX_HANDLE]; + __u64 len; + __u64 align; + __u64 vmids; + char buf_name[CAM_DMA_BUF_NAME_LEN]; + __u32 flags; + __u32 num_valid_params; + __u32 valid_param_mask; + __s32 params[5]; + struct cam_mem_alloc_out_params out; +}; + /** * struct cam_mem_mgr_map_cmd * @mmu_hdls: array of mmu handles @@ -470,6 +507,37 @@ struct cam_mem_mgr_map_cmd { struct cam_mem_map_out_params out; }; +/** + * struct cam_mem_mgr_map_cmd_v2 + * @version: Struct version + * @fd: output buffer file descriptor + * @mmu_hdls: array of mmu handles + * @num_hdl: number of handles + * @flags: flags of the buffer + * @vmids: reserved + * @buf_name: DMA buffer name + * @num_valid_params: Valid number of params being used + * @valid_param_mask: Mask to indicate the field types in params + * @params: Additional params + * @out: out params + */ + +/* CAM_REQ_MGR_MAP_BUF_V2 */ +struct cam_mem_mgr_map_cmd_v2 { + __u32 version; + __s32 fd; + __s32 mmu_hdls[CAM_MEM_MMU_MAX_HANDLE]; + __u32 num_hdl; + __u32 flags; + __u64 vmids; + char buf_name[CAM_DMA_BUF_NAME_LEN]; + __u32 num_valid_params; + __u32 valid_param_mask; + __s32 params[4]; + struct cam_mem_map_out_params out; +}; + + /** * struct cam_mem_mgr_map_cmd * @buf_handle: buffer handle