瀏覽代碼

msm: camera: memmgr: Use system movable heap if available

To provide more peak memory space for camera usecase, utilize
system-movable heap. This will first check in standard system
heap for allocation, if memory is not available, allocation will
happen from system-movable heap. As we can not keep memory from
system-movable heap to stay forever (which will regress memory
power features), need to be careful when allocating from this
heap. All camera userspace allocations' lifetime is at the
usecase boundary, so allocate userspace allocations from
system-movable heap if available, fallback to standard system
heap if not available. kmd internal allocations will most likely
stay forever, so allocate them only from standard system heap.

CRs-Fixed: 3450854
Change-Id: Ic6644dea04cb44bf963b6277205de8502bc34bd9
Signed-off-by: Pavan Kumar Chilamkurthi <[email protected]>
Pavan Kumar Chilamkurthi 2 年之前
父節點
當前提交
66619a991e
共有 2 個文件被更改,包括 46 次插入10 次删除
  1. 36 10
      drivers/cam_req_mgr/cam_mem_mgr.c
  2. 10 0
      drivers/cam_req_mgr/cam_mem_mgr.h

+ 36 - 10
drivers/cam_req_mgr/cam_mem_mgr.c

@@ -585,11 +585,13 @@ static int cam_mem_mgr_get_dma_heaps(void)
 	int rc = 0;
 
 	tbl.system_heap = NULL;
+	tbl.system_movable_heap = NULL;
 	tbl.system_uncached_heap = NULL;
 	tbl.camera_heap = NULL;
 	tbl.camera_uncached_heap = NULL;
 	tbl.secure_display_heap = NULL;
 	tbl.ubwc_p_heap = NULL;
+	tbl.ubwc_p_movable_heap = NULL;
 
 	tbl.system_heap = dma_heap_find("qcom,system");
 	if (IS_ERR_OR_NULL(tbl.system_heap)) {
@@ -599,6 +601,14 @@ static int cam_mem_mgr_get_dma_heaps(void)
 		goto put_heaps;
 	}
 
+	tbl.system_movable_heap = dma_heap_find("qcom,system-movable");
+	if (IS_ERR_OR_NULL(tbl.system_movable_heap)) {
+		rc = PTR_ERR(tbl.system_movable_heap);
+		CAM_DBG(CAM_MEM, "qcom system heap not found, rc=%d", rc);
+		tbl.system_movable_heap = NULL;
+		/* not fatal error, we can fallback to system heap */
+	}
+
 	tbl.system_uncached_heap = dma_heap_find("qcom,system-uncached");
 	if (IS_ERR_OR_NULL(tbl.system_uncached_heap)) {
 		if (tbl.force_cache_allocs) {
@@ -624,6 +634,13 @@ static int cam_mem_mgr_get_dma_heaps(void)
 		tbl.ubwc_p_heap = NULL;
 	}
 
+	tbl.ubwc_p_movable_heap = dma_heap_find("qcom,ubwcp-movable");
+	if (IS_ERR_OR_NULL(tbl.ubwc_p_movable_heap)) {
+		CAM_DBG(CAM_MEM, "qcom ubwcp movable heap not found, err=%d",
+			PTR_ERR(tbl.ubwc_p_movable_heap));
+		tbl.ubwc_p_movable_heap = NULL;
+	}
+
 	tbl.secure_display_heap = dma_heap_find("qcom,display");
 	if (IS_ERR_OR_NULL(tbl.secure_display_heap)) {
 		rc = PTR_ERR(tbl.secure_display_heap);
@@ -650,10 +667,10 @@ static int cam_mem_mgr_get_dma_heaps(void)
 	}
 
 	CAM_INFO(CAM_MEM,
-		"Heaps : system=%pK, system_uncached=%pK, camera=%pK, camera-uncached=%pK, secure_display=%pK, ubwc_p_heap=%pK",
-		tbl.system_heap, tbl.system_uncached_heap,
+		"Heaps : system=%pK %pK, system_uncached=%pK, camera=%pK, camera-uncached=%pK, secure_display=%pK, ubwc_p=%pK %pK",
+		tbl.system_heap, tbl.system_movable_heap, tbl.system_uncached_heap,
 		tbl.camera_heap, tbl.camera_uncached_heap,
-		tbl.secure_display_heap, tbl.ubwc_p_heap);
+		tbl.secure_display_heap, tbl.ubwc_p_heap,  tbl.ubwc_p_movable_heap);
 
 	return 0;
 put_heaps:
@@ -671,6 +688,7 @@ bool cam_mem_mgr_ubwc_p_heap_supported(void)
 
 static int cam_mem_util_get_dma_buf(size_t len,
 	unsigned int cam_flags,
+	enum cam_mem_mgr_allocator alloc_type,
 	struct dma_buf **buf,
 	unsigned long *i_ino)
 {
@@ -744,12 +762,19 @@ static int cam_mem_util_get_dma_buf(size_t len,
 			return -EINVAL;
 		}
 
-		heap = tbl.ubwc_p_heap;
-		CAM_DBG(CAM_MEM, "Allocating from ubwc-p heap, size=%d, flags=0x%x",
-			len, cam_flags);
+		if (tbl.ubwc_p_movable_heap && (alloc_type == CAM_MEMMGR_ALLOC_USER))
+			heap = tbl.ubwc_p_movable_heap;
+		else
+			heap = tbl.ubwc_p_heap;
+		CAM_DBG(CAM_MEM, "Allocating from ubwc-p heap %pK, size=%d, flags=0x%x",
+			heap, len, cam_flags);
 	} else if (use_cached_heap) {
 		try_heap = tbl.camera_heap;
-		heap = tbl.system_heap;
+
+		if (tbl.system_movable_heap && (alloc_type == CAM_MEMMGR_ALLOC_USER))
+			heap = tbl.system_movable_heap;
+		else
+			heap = tbl.system_heap;
 	} else {
 		try_heap = tbl.camera_uncached_heap;
 		heap = tbl.system_uncached_heap;
@@ -834,6 +859,7 @@ bool cam_mem_mgr_ubwc_p_heap_supported(void)
 
 static int cam_mem_util_get_dma_buf(size_t len,
 	unsigned int cam_flags,
+	enum cam_mem_mgr_allocator alloc_type,
 	struct dma_buf **buf,
 	unsigned long *i_ino)
 {
@@ -901,7 +927,7 @@ static int cam_mem_util_buffer_alloc(size_t len, uint32_t flags,
 {
 	int rc;
 
-	rc = cam_mem_util_get_dma_buf(len, flags, dmabuf, i_ino);
+	rc = cam_mem_util_get_dma_buf(len, flags, CAM_MEMMGR_ALLOC_USER, dmabuf, i_ino);
 	if (rc) {
 		CAM_ERR(CAM_MEM,
 			"Error allocating dma buf : len=%llu, flags=0x%x",
@@ -1665,7 +1691,7 @@ int cam_mem_mgr_request_mem(struct cam_mem_mgr_request_desc *inp,
 		return -EINVAL;
 	}
 
-	rc = cam_mem_util_get_dma_buf(inp->size, inp->flags, &buf, &i_ino);
+	rc = cam_mem_util_get_dma_buf(inp->size, inp->flags, CAM_MEMMGR_ALLOC_KERNEL, &buf, &i_ino);
 
 	if (rc) {
 		CAM_ERR(CAM_MEM, "ION alloc failed for shared buffer");
@@ -1845,7 +1871,7 @@ int cam_mem_mgr_reserve_memory_region(struct cam_mem_mgr_request_desc *inp,
 		return -EINVAL;
 	}
 
-	rc = cam_mem_util_get_dma_buf(inp->size, 0, &buf, &i_ino);
+	rc = cam_mem_util_get_dma_buf(inp->size, 0, CAM_MEMMGR_ALLOC_KERNEL, &buf, &i_ino);
 
 	if (rc) {
 		CAM_ERR(CAM_MEM, "ION alloc failed for sec heap buffer");

+ 10 - 0
drivers/cam_req_mgr/cam_mem_mgr.h

@@ -21,6 +21,12 @@ enum cam_mem_mgr_state {
 	CAM_MEM_MGR_INITIALIZED,
 };
 
+/*Enum for memory allocation initiator */
+enum cam_mem_mgr_allocator {
+	CAM_MEMMGR_ALLOC_USER,
+	CAM_MEMMGR_ALLOC_KERNEL,
+};
+
 /*Enum for possible SMMU operations */
 enum cam_smmu_mapping_client {
 	CAM_SMMU_MAPPING_USER,
@@ -91,11 +97,13 @@ struct cam_mem_buf_queue {
  *                              allocations.
  * @csf_version: Camera security framework version
  * @system_heap: Handle to system heap
+ * @system_movable_heap: Handle to system movable 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
  * @ubwc_p_heap: Handle to ubwc-p heap
+ * @ubwc_p_movable_heap: Handle to ubwc-p movable heap
  */
 struct cam_mem_table {
 	struct mutex m_lock;
@@ -108,11 +116,13 @@ struct cam_mem_table {
 	struct cam_csf_version csf_version;
 #if IS_REACHABLE(CONFIG_DMABUF_HEAPS)
 	struct dma_heap *system_heap;
+	struct dma_heap *system_movable_heap;
 	struct dma_heap *system_uncached_heap;
 	struct dma_heap *camera_heap;
 	struct dma_heap *camera_uncached_heap;
 	struct dma_heap *secure_display_heap;
 	struct dma_heap *ubwc_p_heap;
+	struct dma_heap *ubwc_p_movable_heap;
 #endif
 
 };