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

Commit 2c807855 authored by Raja Mallik's avatar Raja Mallik Committed by Gerrit - the friendly Code Review server
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: Ie620f7fbe183702b427d6aa9ce08d3030cb57361
Signed-off-by: default avatarRaja Mallik <rmallik@codeaurora.org>
parent 3bd0aae4
Loading
Loading
Loading
Loading
+53 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include "cam_debug_util.h"
#include "cam_debug_util.h"


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


bitmap_fail:
bitmap_fail:
@@ -151,6 +153,11 @@ int cam_mem_get_io_buf(int32_t buf_handle, int32_t mmu_handle,
{
{
	int rc = 0, idx;
	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);
	idx = CAM_MEM_MGR_GET_HDL_IDX(buf_handle);
	if (idx >= CAM_MEM_BUFQ_MAX || idx <= 0)
	if (idx >= CAM_MEM_BUFQ_MAX || idx <= 0)
		return -EINVAL;
		return -EINVAL;
@@ -191,6 +198,11 @@ int cam_mem_get_cpu_buf(int32_t buf_handle, uintptr_t *vaddr_ptr, size_t *len)
	uintptr_t kvaddr = 0;
	uintptr_t kvaddr = 0;
	size_t klen = 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)
	if (!buf_handle || !vaddr_ptr || !len)
		return -EINVAL;
		return -EINVAL;


@@ -254,6 +266,11 @@ int cam_mem_mgr_cache_ops(struct cam_mem_cache_ops_cmd *cmd)
	uint32_t ion_cache_ops;
	uint32_t ion_cache_ops;
	unsigned long ion_flag = 0;
	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)
	if (!cmd)
		return -EINVAL;
		return -EINVAL;


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


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

	if (!cmd) {
	if (!cmd) {
		CAM_ERR(CAM_MEM, " Invalid argument");
		CAM_ERR(CAM_MEM, " Invalid argument");
		return -EINVAL;
		return -EINVAL;
@@ -628,6 +650,11 @@ int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd)
	dma_addr_t hw_vaddr = 0;
	dma_addr_t hw_vaddr = 0;
	size_t len = 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)) {
	if (!cmd || (cmd->fd < 0)) {
		CAM_ERR(CAM_MEM, "Invalid argument");
		CAM_ERR(CAM_MEM, "Invalid argument");
		return -EINVAL;
		return -EINVAL;
@@ -813,6 +840,7 @@ static int cam_mem_mgr_cleanup_table(void)


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


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

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


	enum cam_smmu_region_id region = CAM_SMMU_REGION_SHARED;
	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) {
	if (!inp || !out) {
		CAM_ERR(CAM_MEM, "Invalid params");
		CAM_ERR(CAM_MEM, "Invalid params");
		return -EINVAL;
		return -EINVAL;
@@ -1066,6 +1104,11 @@ int cam_mem_mgr_release_mem(struct cam_mem_mgr_memory_desc *inp)
	int32_t idx;
	int32_t idx;
	int rc;
	int rc;


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

	if (!inp) {
	if (!inp) {
		CAM_ERR(CAM_MEM, "Invalid argument");
		CAM_ERR(CAM_MEM, "Invalid argument");
		return -EINVAL;
		return -EINVAL;
@@ -1115,6 +1158,11 @@ int cam_mem_mgr_reserve_memory_region(struct cam_mem_mgr_request_desc *inp,
	int32_t smmu_hdl = 0;
	int32_t smmu_hdl = 0;
	int32_t num_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) {
	if (!inp || !out) {
		CAM_ERR(CAM_MEM, "Invalid param(s)");
		CAM_ERR(CAM_MEM, "Invalid param(s)");
		return -EINVAL;
		return -EINVAL;
@@ -1207,6 +1255,11 @@ int cam_mem_mgr_free_memory_region(struct cam_mem_mgr_memory_desc *inp)
	int rc;
	int rc;
	int32_t smmu_hdl;
	int32_t smmu_hdl;


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

	if (!inp) {
	if (!inp) {
		CAM_ERR(CAM_MEM, "Invalid argument");
		CAM_ERR(CAM_MEM, "Invalid argument");
		return -EINVAL;
		return -EINVAL;
+7 −1
Original line number Original line 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
 * 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
 * it under the terms of the GNU General Public License version 2 and
@@ -20,6 +20,12 @@


#define CAM_MEM_BUFQ_MAX 1024
#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 for possible SMMU operations */
enum cam_smmu_mapping_client {
enum cam_smmu_mapping_client {
	CAM_SMMU_MAPPING_USER,
	CAM_SMMU_MAPPING_USER,