Преглед изворни кода

Merge "msm: camera: memmgr: Add 4K padding for shared buffers" into camera-kernel.lnx.5.0

Haritha Chintalapati пре 4 година
родитељ
комит
811fedab3c

+ 19 - 11
drivers/cam_req_mgr/cam_mem_mgr.c

@@ -19,6 +19,8 @@
 #include "cam_trace.h"
 #include "cam_common_util.h"
 
+#define CAM_MEM_SHARED_BUFFER_PAD_4K (4 * 1024)
+
 static struct cam_mem_table tbl;
 static atomic_t cam_mem_mgr_state = ATOMIC_INIT(CAM_MEM_MGR_UNINITIALIZED);
 
@@ -177,6 +179,8 @@ int cam_mem_mgr_init(void)
 		return -EINVAL;
 	}
 
+	tbl.need_shared_buffer_padding = cam_smmu_need_shared_buffer_padding();
+
 #if IS_REACHABLE(CONFIG_DMABUF_HEAPS)
 	rc = cam_mem_mgr_get_dma_heaps();
 	if (rc) {
@@ -672,20 +676,18 @@ static int cam_mem_util_get_dma_buf(size_t len,
 }
 #endif
 
-static int cam_mem_util_buffer_alloc(struct cam_mem_mgr_alloc_cmd *cmd,
+static int cam_mem_util_buffer_alloc(size_t len, uint32_t flags,
 	struct dma_buf **dmabuf,
 	int *fd)
 {
 	int rc;
 	struct dma_buf *temp_dmabuf = NULL;
 
-	rc = cam_mem_util_get_dma_buf(cmd->len,
-		cmd->flags,
-		dmabuf);
+	rc = cam_mem_util_get_dma_buf(len, flags, dmabuf);
 	if (rc) {
 		CAM_ERR(CAM_MEM,
 			"Error allocating dma buf : len=%llu, flags=0x%x",
-			cmd->len, cmd->flags);
+			len, flags);
 		return rc;
 	}
 
@@ -697,7 +699,7 @@ static int cam_mem_util_buffer_alloc(struct cam_mem_mgr_alloc_cmd *cmd,
 	}
 
 	CAM_DBG(CAM_MEM, "Alloc success : len=%zu, *dmabuf=%pK, fd=%d",
-		cmd->len, *dmabuf, *fd);
+		len, *dmabuf, *fd);
 
 	/*
 	 * increment the ref count so that ref count becomes 2 here
@@ -860,8 +862,16 @@ int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd)
 		CAM_ERR(CAM_MEM, " Invalid argument");
 		return -EINVAL;
 	}
+
 	len = cmd->len;
 
+	if (tbl.need_shared_buffer_padding &&
+		(cmd->flags & CAM_MEM_FLAG_HW_SHARED_ACCESS)) {
+		len += CAM_MEM_SHARED_BUFFER_PAD_4K;
+		CAM_DBG(CAM_MEM, "Pad 4k size, actual %llu, allocating %zu",
+			cmd->len, len);
+	}
+
 	rc = cam_mem_util_check_alloc_flags(cmd);
 	if (rc) {
 		CAM_ERR(CAM_MEM, "Invalid flags: flags = 0x%X, rc=%d",
@@ -869,13 +879,11 @@ int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd)
 		return rc;
 	}
 
-	rc = cam_mem_util_buffer_alloc(cmd,
-		&dmabuf,
-		&fd);
+	rc = cam_mem_util_buffer_alloc(len, cmd->flags, &dmabuf, &fd);
 	if (rc) {
 		CAM_ERR(CAM_MEM,
 			"Ion Alloc failed, len=%llu, align=%llu, flags=0x%x, num_hdl=%d",
-			cmd->len, cmd->align, cmd->flags, cmd->num_hdl);
+			len, cmd->align, cmd->flags, cmd->num_hdl);
 		cam_mem_mgr_print_tbl();
 		return rc;
 	}
@@ -950,7 +958,7 @@ int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd)
 	tbl.bufq[idx].kmdvaddr = kvaddr;
 	tbl.bufq[idx].vaddr = hw_vaddr;
 	tbl.bufq[idx].dma_buf = dmabuf;
-	tbl.bufq[idx].len = cmd->len;
+	tbl.bufq[idx].len = len;
 	tbl.bufq[idx].num_hdl = cmd->num_hdl;
 	memcpy(tbl.bufq[idx].hdls, cmd->mmu_hdls,
 		sizeof(int32_t) * cmd->num_hdl);

+ 8 - 0
drivers/cam_req_mgr/cam_mem_mgr.h

@@ -74,6 +74,13 @@ struct cam_mem_buf_queue {
  * @alloc_profile_enable: Whether to enable alloc profiling
  * @dbg_buf_idx: debug buffer index to get usecases info
  * @force_cache_allocs: Force all internal buffer allocations with cache
+ * @need_shared_buffer_padding: Whether padding is needed for shared buffer
+ *                              allocations.
+ * @system_heap: Handle to system heap
+ * @system_uncached_heap: Handle to system uncached heap
+ * @camera_heap: Handle to camera heap
+ * @camera_uncached_heap: Handle to camera uncached heap
+ * @secure_display_heap: Handle to secure display heap
  */
 struct cam_mem_table {
 	struct mutex m_lock;
@@ -84,6 +91,7 @@ struct cam_mem_table {
 	bool alloc_profile_enable;
 	size_t dbg_buf_idx;
 	bool force_cache_allocs;
+	bool need_shared_buffer_padding;
 #if IS_REACHABLE(CONFIG_DMABUF_HEAPS)
 	struct dma_heap *system_heap;
 	struct dma_heap *system_uncached_heap;

+ 9 - 0
drivers/cam_smmu/cam_smmu_api.c

@@ -183,6 +183,7 @@ struct cam_iommu_cb_set {
 	bool cb_dump_enable;
 	bool map_profile_enable;
 	bool force_cache_allocs;
+	bool need_shared_buffer_padding;
 };
 
 static const struct of_device_id msm_cam_smmu_dt_match[] = {
@@ -365,6 +366,11 @@ static void cam_smmu_dump_monitor_array(
 	}
 }
 
+bool cam_smmu_need_shared_buffer_padding(void)
+{
+	return iommu_cb_set.need_shared_buffer_padding;
+}
+
 int cam_smmu_need_force_alloc_cached(bool *force_alloc_cached)
 {
 	int idx;
@@ -4269,6 +4275,9 @@ static int cam_smmu_component_bind(struct device *dev,
 
 	iommu_cb_set.force_cache_allocs =
 		of_property_read_bool(dev->of_node, "force_cache_allocs");
+	iommu_cb_set.need_shared_buffer_padding =
+		of_property_read_bool(dev->of_node,
+		"need_shared_buffer_padding");
 
 	CAM_DBG(CAM_SMMU, "Main component bound successfully");
 	return 0;

+ 6 - 1
drivers/cam_smmu/cam_smmu_api.h

@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
  */
 
 #ifndef _CAM_SMMU_API_H_
@@ -437,5 +437,10 @@ void cam_smmu_exit_module(void);
  */
 int cam_smmu_need_force_alloc_cached(bool *force_alloc_cached);
 
+/**
+ * @brief : API to determine whether padding is needed for shared buffers
+ */
+bool cam_smmu_need_shared_buffer_padding(void);
+
 
 #endif /* _CAM_SMMU_API_H_ */