summaryrefslogtreecommitdiffstats
path: root/exynos4/hal/include/ion.h
blob: dbb88967e050f21520f19f2f34b4136877f436d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef _LIB_ION_H_
#define _LIB_ION_H_

#include <unistd.h> /* size_t */

#define ION_HEAP_SYSTEM_MASK		(1 << 0)
#define ION_HEAP_SYSTEM_CONTIG_MASK	(1 << 1)
#define ION_HEAP_EXYNOS_MASK		(1 << 4)
#define ION_HEAP_EXYNOS_CONTIG_MASK	(1 << 5)

/* ION_MSYNC_FLAGS
 * values of @flags parameter to ion_msync()
 *
 * IMSYNC_DEV_TO_READ: Device only reads the buffer
 * IMSYNC_DEV_TO_WRITE: Device may writes to the buffer
 * IMSYNC_DEV_TO_RW: Device reads and writes to the buffer
 *
 * IMSYNC_SYNC_FOR_DEV: ion_msync() for device to access the buffer
 * IMSYNC_SYNC_FOR_CPU: ion_msync() for CPU to access the buffer after device
 *                      has accessed it.
 *
 * The values must be ORed with one of IMSYNC_DEV_* and one of IMSYNC_SYNC_*.
 * Otherwise, ion_msync() will not effect.
 */
enum ION_MSYNC_FLAGS {
	IMSYNC_DEV_TO_READ = 0,
	IMSYNC_DEV_TO_WRITE = 1,
	IMSYNC_DEV_TO_RW = 2,
	IMSYNC_SYNC_FOR_DEV = 0x10000,
	IMSYNC_SYNC_FOR_CPU = 0x20000,
};

#ifdef __cplusplus
extern "C" {
#endif

/* ion_client
 * An ION client is an object or an entity that needs to use the service of
 * ION and has unique address space. ion_client is an identifier of an ION
 * client and it represents the ION client.
 * All operations on ION needs a valid ion_client value and it can be obtained
 * by ion_client_create().
 */
typedef int ion_client;

/* ion_buffer
 * An identifier of a buffer allocated from ION. You must obtain to access
 * a buffer allocated from ION. If you have an effective ion_buffer, you have
 * three options to work with it.
 * - To access  the buffer, you can request an address (user virtual address)
 *   of the buffer with ion_map().
 * - To pass the buffer to the kernel, you can pass the ion_buffer to the
 *   kernel driver directly, if the kernel driver can work with ION.
 * - To pass the buffer to other processes, you can pass the ion_buffer to
 *   other processes through RPC machanism such as socket communication or
 *   Android Binder because ion_buffer is actually an open file descripotor
 *   of the current process.
 */
typedef int ion_buffer;

/* ion_client_create()
 * @RETURN: new ion_client.
 *          netative value if creating new ion_client is failed.
 *
 * A call to ion_client_create() must be paired with ion_client_destroy(),
 * symmetrically. ion_client_destroy() needs a valid ion_client that
 * is returned by ion_client_create().
 */
ion_client ion_client_create(void);

/* ion_client_destroy()
 * @client: An ion_client value to remove.
 */
void ion_client_destroy(ion_client client);

/* ion_alloc() - Allocates new buffer from ION.
 * @client: A valid ion_client value returned by ion_client_create().
 * @len: Size of a buffer required in bytes.
 * @align: Alignment requirements of @len and the start address of the allocated
 *         buffer. If the @len is not aligned by @align, ION allocates a buffer
 *         that is aligned by @align and the size of the buffer will be larger
 *         than @len.
 * @flags: Additional requirements about buffer. ION_HEAP_SYSTEM_CONTIG_MASK
 *         for allocating physically contiguous buffer and ION_HEAP_SYSTEM_MASK
 *         for virtually contiguous buffer. You can combine those flags or
 *         simply give -1(0xFFFFFFFF) if you do not care about the contiguouty
 *         of the buffer.
 * @RETURN: An ion_buffer that represents the buffer allocated. It is only
 *          unique in the context of the given client, @client.
 *          -error if the allocation failed.
 *          See the description of ion_buffer above for detailed information.
 */
ion_buffer ion_alloc(ion_client client, size_t len, size_t align,
		     unsigned int flags);

/* ion_free() - Frees an existing buffer that is allocated by ION
 * @buffer: An ion_buffer of the buffer to be released.
 */
void ion_free(ion_buffer buffer);

/* ion_map() - Obtains a virtual address of the buffer identied by @buffer
 * @buffer: The buffer to map. The virtual address returned is allocated by the
 *          kernel.
 * @len: The size of the buffer to map. This must not exceed the size of the
 *       buffer represented by @fd_buf. Thus you need to know the size of it
 *       before calling this function. If @len is less than the size of the
 *       buffer, this function just map just the size requested (@len) not the
 *       entire buffer.
 * @offset: How many pages will be ignored while mapping.@offset number of
 *       pages from the start of the buffer will not be mapped.
 * @RETURN: The start virtual addres mapped.
 *          MAP_FAILED if mapping fails.
 *
 * Note that @len + (@offset * PAGE_SIZE) must not exceed the size of the
 * buffer.
 */
void *ion_map(ion_buffer buffer, size_t len, off_t offset);

/* ion_unmap() - Frees the buffer mapped by ion_map()
 * @addr: The address returned by ion_map().
 * @len: The size of the buffer mapped by ion_map().
 * @RETURN: 0 on success, and -1 on failure.
 *          errno is also set on failure.
 */
int ion_unmap(void *addr, size_t len);

/* ion_msync() - Makes sure that data in the buffer are visible to H/W peri.
 * @client: A valid ion_client value returned by ion_client_create().
 * @buffer: The buffer to perform ion_msync().
 * @flags: Direction of access of H/W peri and CPU. See the description of
 *         ION_MSYNC_FLAGS.
 * @size: Size to ion_msync() in bytes.
 * @offset: Where ion_msync() start in @buffer, size in bytes.
 * @RETURN: 0 if successful. -error, otherwise.
 *
 * Note that @offset + @size must not exceed the size of @buffer.
 */
int ion_msync(ion_client client, ion_buffer buffer, long flags,
		size_t size, off_t offset);

#ifdef __cplusplus
}
#endif
#endif /* _LIB_ION_H_ */