Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad380c1a authored by Trishansh Bhardwaj's avatar Trishansh Bhardwaj
Browse files

msm: camera: Adds state variable in mem manager



Add state variable for camera mem manager to show initialization status.
Ensure that all operations are rejected before initialization.

Change-Id: I1ddbaaf6fbed59e4804476562c97f6895d99e916
Signed-off-by: default avatarTrishansh Bhardwaj <tbhardwa@codeaurora.org>
parent a85cf16d
Loading
Loading
Loading
Loading
+53 −1
Original line number Diff line number Diff line
/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -23,6 +23,7 @@
#include "cam_debug_util.h"

static struct cam_mem_table tbl;
static atomic_t cam_mem_mgr_state = ATOMIC_INIT(CAM_MEM_MGR_UNINITIALIZED);

static int cam_mem_util_map_cpu_va(struct ion_handle *hdl,
	uintptr_t *vaddr,
@@ -108,6 +109,7 @@ int cam_mem_mgr_init(void)
		tbl.bufq[i].buf_handle = -1;
	}
	mutex_init(&tbl.m_lock);
	atomic_set(&cam_mem_mgr_state, CAM_MEM_MGR_INITIALIZED);
	return rc;

bitmap_fail:
@@ -151,6 +153,11 @@ int cam_mem_get_io_buf(int32_t buf_handle, int32_t mmu_handle,
{
	int rc = 0, idx;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	idx = CAM_MEM_MGR_GET_HDL_IDX(buf_handle);
	if (idx >= CAM_MEM_BUFQ_MAX || idx <= 0)
		return -EINVAL;
@@ -191,6 +198,10 @@ int cam_mem_get_cpu_buf(int32_t buf_handle, uintptr_t *vaddr_ptr, size_t *len)
	uintptr_t kvaddr = 0;
	size_t klen = 0;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}
	if (!buf_handle || !vaddr_ptr || !len)
		return -EINVAL;

@@ -242,6 +253,11 @@ int cam_mem_mgr_cache_ops(struct cam_mem_cache_ops_cmd *cmd)
	uint32_t ion_cache_ops;
	unsigned long ion_flag = 0;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!cmd)
		return -EINVAL;

@@ -518,6 +534,11 @@ int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd)
	dma_addr_t hw_vaddr = 0;
	size_t len;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!cmd) {
		CAM_ERR(CAM_MEM, " Invalid argument");
		return -EINVAL;
@@ -616,6 +637,11 @@ int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd)
	dma_addr_t hw_vaddr = 0;
	size_t len = 0;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!cmd || (cmd->fd < 0)) {
		CAM_ERR(CAM_MEM, "Invalid argument");
		return -EINVAL;
@@ -801,6 +827,7 @@ static int cam_mem_mgr_cleanup_table(void)

void cam_mem_mgr_deinit(void)
{
	atomic_set(&cam_mem_mgr_state, CAM_MEM_MGR_UNINITIALIZED);
	cam_mem_mgr_cleanup_table();
	mutex_lock(&tbl.m_lock);
	bitmap_zero(tbl.bitmap, tbl.bits);
@@ -889,6 +916,11 @@ int cam_mem_mgr_release(struct cam_mem_mgr_release_cmd *cmd)
	int idx;
	int rc;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!cmd) {
		CAM_ERR(CAM_MEM, "Invalid argument");
		return -EINVAL;
@@ -936,6 +968,11 @@ int cam_mem_mgr_request_mem(struct cam_mem_mgr_request_desc *inp,

	enum cam_smmu_region_id region = CAM_SMMU_REGION_SHARED;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!inp || !out) {
		CAM_ERR(CAM_MEM, "Invalid params");
		return -EINVAL;
@@ -1054,6 +1091,11 @@ int cam_mem_mgr_release_mem(struct cam_mem_mgr_memory_desc *inp)
	int32_t idx;
	int rc;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!inp) {
		CAM_ERR(CAM_MEM, "Invalid argument");
		return -EINVAL;
@@ -1103,6 +1145,11 @@ int cam_mem_mgr_reserve_memory_region(struct cam_mem_mgr_request_desc *inp,
	int32_t smmu_hdl = 0;
	int32_t num_hdl = 0;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!inp || !out) {
		CAM_ERR(CAM_MEM, "Invalid param(s)");
		return -EINVAL;
@@ -1195,6 +1242,11 @@ int cam_mem_mgr_free_memory_region(struct cam_mem_mgr_memory_desc *inp)
	int rc;
	int32_t smmu_hdl;

	if (!atomic_read(&cam_mem_mgr_state)) {
		CAM_ERR(CAM_CRM, "failed. mem_mgr not initialized");
		return -EINVAL;
	}

	if (!inp) {
		CAM_ERR(CAM_MEM, "Invalid argument");
		return -EINVAL;
+7 −1
Original line number Diff line number Diff line
/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -20,6 +20,12 @@

#define CAM_MEM_BUFQ_MAX 1024

/* Enum for possible mem mgr states */
enum cam_mem_mgr_state {
	CAM_MEM_MGR_UNINITIALIZED,
	CAM_MEM_MGR_INITIALIZED,
};

/*Enum for possible SMMU operations */
enum cam_smmu_mapping_client {
	CAM_SMMU_MAPPING_USER,