blob: fd7404d8453cb1a53843301fcabc33ac53fb168d [file] [log] [blame]
angelslee21f4b2013-02-18 18:48:53 +08001/*
2 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _LIB_SECION_H_
18#define _LIB_SECION_H_
19
Javi Ferrercc488562014-11-21 04:05:51 +053020#include <unistd.h> /* size_t */
angelslee21f4b2013-02-18 18:48:53 +080021
Javi Ferrercc488562014-11-21 04:05:51 +053022
23/* ion_client
24 * An ION client is an object or an entity that needs to use the service of
25 * ION and has unique address space. ion_client is an identifier of an ION
26 * client and it represents the ION client.
27 * All operations on ION needs a valid ion_client value and it can be obtained
28 * by ion_client_create().
29 */
angelslee21f4b2013-02-18 18:48:53 +080030typedef int ion_client;
Javi Ferrercc488562014-11-21 04:05:51 +053031
32/* ion_buffer
33 * An identifier of a buffer allocated from ION. You must obtain to access
34 * a buffer allocated from ION. If you have an effective ion_buffer, you have
35 * three options to work with it.
36 * - To access the buffer, you can request an address (user virtual address)
37 * of the buffer with ion_map().
38 * - To pass the buffer to the kernel, you can pass the ion_buffer to the
39 * kernel driver directly, if the kernel driver can work with ION.
40 * - To pass the buffer to other processes, you can pass the ion_buffer to
41 * other processes through RPC machanism such as socket communication or
42 * Android Binder because ion_buffer is actually an open file descripotor
43 * of the current process.
44 */
angelslee21f4b2013-02-18 18:48:53 +080045typedef int ion_buffer;
46
Javi Ferrercc488562014-11-21 04:05:51 +053047typedef unsigned long ion_phys_addr_t;
48
49
50#define ION_HEAP_SYSTEM_MASK (1 << 0)
51#define ION_HEAP_SYSTEM_CONTIG_MASK (1 << 1)
52#define ION_HEAP_EXYNOS_CONTIG_MASK (1 << 4)
53#define ION_HEAP_EXYNOS_MASK (1 << 5)
54#define ION_HEAP_EXYNOS_USER_MASK (1 << 6)
55#define ION_EXYNOS_NONCACHE_MASK (1 << (32 - 2)) /* it was BITS_PER_LONG */
56#define ION_EXYNOS_WRITE_MASK (1 << (32 - 1)) /* it was BITS_PER_LONG */
57
58/* ION_MSYNC_FLAGS
59 * values of @flags parameter to ion_msync()
60 *
61 * IMSYNC_DEV_TO_READ: Device only reads the buffer
62 * IMSYNC_DEV_TO_WRITE: Device may writes to the buffer
63 * IMSYNC_DEV_TO_RW: Device reads and writes to the buffer
64 *
65 * IMSYNC_SYNC_FOR_DEV: ion_msync() for device to access the buffer
66 * IMSYNC_SYNC_FOR_CPU: ion_msync() for CPU to access the buffer after device
67 * has accessed it.
68 *
69 * The values must be ORed with one of IMSYNC_DEV_* and one of IMSYNC_SYNC_*.
70 * Otherwise, ion_msync() will not effect.
71 */
angelslee21f4b2013-02-18 18:48:53 +080072enum ION_MSYNC_FLAGS {
73 IMSYNC_DEV_TO_READ = 0,
74 IMSYNC_DEV_TO_WRITE = 1,
75 IMSYNC_DEV_TO_RW = 2,
76 IMSYNC_SYNC_FOR_DEV = 0x10000,
77 IMSYNC_SYNC_FOR_CPU = 0x20000,
78};
79
80struct secion_param {
81 ion_client client;
82 ion_buffer buffer;
83 size_t size;
84 void *memory;
85 ion_phys_addr_t physaddr;
86};
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
Javi Ferrercc488562014-11-21 04:05:51 +053092/* ion_client_create()
93 * @RETURN: new ion_client.
94 * netative value if creating new ion_client is failed.
95 *
96 * A call to ion_client_create() must be paired with ion_client_destroy(),
97 * symmetrically. ion_client_destroy() needs a valid ion_client that
98 * is returned by ion_client_create().
99 */
angelslee21f4b2013-02-18 18:48:53 +0800100ion_client ion_client_create(void);
Javi Ferrercc488562014-11-21 04:05:51 +0530101
102/* ion_client_destroy()
103 * @client: An ion_client value to remove.
104 */
angelslee21f4b2013-02-18 18:48:53 +0800105void ion_client_destroy(ion_client client);
Javi Ferrercc488562014-11-21 04:05:51 +0530106
107/* ion_alloc() - Allocates new buffer from ION.
108 * @client: A valid ion_client value returned by ion_client_create().
109 * @len: Size of a buffer required in bytes.
110 * @align: Alignment requirements of @len and the start address of the allocated
111 * buffer. If the @len is not aligned by @align, ION allocates a buffer
112 * that is aligned by @align and the size of the buffer will be larger
113 * than @len.
114 * @flags: Additional requirements about buffer. ION_HEAP_SYSTEM_CONTIG_MASK
115 * for allocating physically contiguous buffer and ION_HEAP_SYSTEM_MASK
116 * for virtually contiguous buffer. You can combine those flags or
117 * simply give -1(0xFFFFFFFF) if you do not care about the contiguouty
118 * of the buffer.
119 * @RETURN: An ion_buffer that represents the buffer allocated. It is only
120 * unique in the context of the given client, @client.
121 * -error if the allocation failed.
122 * See the description of ion_buffer above for detailed information.
123 */
angelslee21f4b2013-02-18 18:48:53 +0800124ion_buffer ion_alloc(ion_client client, size_t len, size_t align, unsigned int flags);
Javi Ferrercc488562014-11-21 04:05:51 +0530125
126/* ion_free() - Frees an existing buffer that is allocated by ION
127 * @buffer: An ion_buffer of the buffer to be released.
128 */
angelslee21f4b2013-02-18 18:48:53 +0800129void ion_free(ion_buffer buffer);
Javi Ferrercc488562014-11-21 04:05:51 +0530130
131/* ion_map() - Obtains a virtual address of the buffer identied by @buffer
132 * @buffer: The buffer to map. The virtual address returned is allocated by the
133 * kernel.
134 * @len: The size of the buffer to map. This must not exceed the size of the
135 * buffer represented by @fd_buf. Thus you need to know the size of it
136 * before calling this function. If @len is less than the size of the
137 * buffer, this function just map just the size requested (@len) not the
138 * entire buffer.
139 * @offset: How many pages will be ignored while mapping.@offset number of
140 * pages from the start of the buffer will not be mapped.
141 * @RETURN: The start virtual addres mapped.
142 * MAP_FAILED if mapping fails.
143 *
144 * Note that @len + (@offset * PAGE_SIZE) must not exceed the size of the
145 * buffer.
146 */
angelslee21f4b2013-02-18 18:48:53 +0800147void *ion_map(ion_buffer buffer, size_t len, off_t offset);
Javi Ferrercc488562014-11-21 04:05:51 +0530148
149/* ion_unmap() - Frees the buffer mapped by ion_map()
150 * @addr: The address returned by ion_map().
151 * @len: The size of the buffer mapped by ion_map().
152 * @RETURN: 0 on success, and -1 on failure.
153 * errno is also set on failure.
154 */
angelslee21f4b2013-02-18 18:48:53 +0800155int ion_unmap(void *addr, size_t len);
Javi Ferrercc488562014-11-21 04:05:51 +0530156
157/* ion_msync() - Makes sure that data in the buffer are visible to H/W peri.
158 * @client: A valid ion_client value returned by ion_client_create().
159 * @buffer: The buffer to perform ion_msync().
160 * @flags: Direction of access of H/W peri and CPU. See the description of
161 * ION_MSYNC_FLAGS.
162 * @size: Size to ion_msync() in bytes.
163 * @offset: Where ion_msync() start in @buffer, size in bytes.
164 * @RETURN: 0 if successful. -error, otherwise.
165 *
166 * Note that @offset + @size must not exceed the size of @buffer.
167 */
168int ion_msync(ion_client client, ion_buffer buffer, long flags, size_t size, off_t offset);
169
170
171
172
angelslee21f4b2013-02-18 18:48:53 +0800173ion_phys_addr_t ion_getphys(ion_client client, ion_buffer buffer);
174int createIONMem(struct secion_param *param, size_t size, unsigned int flags);
175int destroyIONMem(struct secion_param *param);
176
177#ifdef __cplusplus
178}
179#endif
180#endif /* _LIB_SECION_H_ */