blob: 83727d20e68568f4c363fd7cd36bc63cf9b963da [file] [log] [blame]
Seemanta Dutta1c827da2017-04-05 17:34:05 -07001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _CAM_MEM_MGR_H_
14#define _CAM_MEM_MGR_H_
15
Jing Zhou6b7522c2017-05-08 23:42:09 -070016#include <linux/mutex.h>
Karthik Anantha Ram92a044d2017-10-27 18:53:25 -070017#include <linux/dma-buf.h>
Seemanta Dutta1c827da2017-04-05 17:34:05 -070018#include <media/cam_req_mgr.h>
19#include "cam_mem_mgr_api.h"
20
21#define CAM_MEM_BUFQ_MAX 1024
22
Karthik Anantha Ram92a044d2017-10-27 18:53:25 -070023/*Enum for possible SMMU operations */
24enum cam_smmu_mapping_client {
25 CAM_SMMU_MAPPING_USER,
26 CAM_SMMU_MAPPING_KERNEL,
27};
28
Seemanta Dutta1c827da2017-04-05 17:34:05 -070029/**
30 * struct cam_mem_buf_queue
31 *
32 * @i_hdl: ion handle for the buffer
Karthik Anantha Ram92a044d2017-10-27 18:53:25 -070033 * @dma_buf: pointer to the allocated dma_buf in the table
Seemanta Dutta1c827da2017-04-05 17:34:05 -070034 * @q_lock: mutex lock for buffer
35 * @hdls: list of mapped handles
36 * @num_hdl: number of handles
37 * @fd: file descriptor of buffer
38 * @buf_handle: unique handle for buffer
39 * @align: alignment for allocation
40 * @len: size of buffer
41 * @flags: attributes of buffer
42 * @vaddr: IOVA of buffer
43 * @kmdvaddr: Kernel virtual address
44 * @active: state of the buffer
45 * @is_imported: Flag indicating if buffer is imported from an FD in user space
46 */
47struct cam_mem_buf_queue {
48 struct ion_handle *i_hdl;
Karthik Anantha Ram92a044d2017-10-27 18:53:25 -070049 struct dma_buf *dma_buf;
Seemanta Dutta1c827da2017-04-05 17:34:05 -070050 struct mutex q_lock;
51 int32_t hdls[CAM_MEM_MMU_MAX_HANDLE];
52 int32_t num_hdl;
53 int32_t fd;
54 int32_t buf_handle;
55 int32_t align;
56 size_t len;
57 uint32_t flags;
58 uint64_t vaddr;
59 uint64_t kmdvaddr;
60 bool active;
61 bool is_imported;
62};
63
64/**
65 * struct cam_mem_table
66 *
67 * @m_lock: mutex lock for table
68 * @bitmap: bitmap of the mem mgr utility
69 * @bits: max bits of the utility
70 * @client: ion client pointer
71 * @bufq: array of buffers
72 */
73struct cam_mem_table {
74 struct mutex m_lock;
75 void *bitmap;
76 size_t bits;
77 struct ion_client *client;
78 struct cam_mem_buf_queue bufq[CAM_MEM_BUFQ_MAX];
79};
80
81/**
82 * @brief: Allocates and maps buffer
83 *
84 * @cmd: Allocation information
85 *
86 * @return Status of operation. Negative in case of error. Zero otherwise.
87 */
88int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd);
89
90/**
91 * @brief: Releases a buffer reference
92 *
93 * @cmd: Buffer release information
94 *
95 * @return Status of operation. Negative in case of error. Zero otherwise.
96 */
97int cam_mem_mgr_release(struct cam_mem_mgr_release_cmd *cmd);
98
99/**
100 * @brief Maps a buffer
101 *
102 * @cmd: Buffer mapping information
103 *
104 * @return Status of operation. Negative in case of error. Zero otherwise.
105 */
106int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd);
107
108/**
109 * @brief: Perform cache ops on the buffer
110 *
111 * @cmd: Cache ops information
112 *
113 * @return Status of operation. Negative in case of error. Zero otherwise.
114 */
115int cam_mem_mgr_cache_ops(struct cam_mem_cache_ops_cmd *cmd);
116
117/**
118 * @brief: Initializes the memory manager
119 *
120 * @return Status of operation. Negative in case of error. Zero otherwise.
121 */
122int cam_mem_mgr_init(void);
123
124/**
125 * @brief: Tears down the memory manager
126 *
127 * @return None
128 */
129void cam_mem_mgr_deinit(void);
130
131#endif /* _CAM_MEM_MGR_H_ */