1 /* 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_ION_H_ 18 #define _LIB_ION_H_ 19 20 #include <unistd.h> /* size_t */ 21 22 #define ION_FLAG_CACHED 1 23 24 #define ION_HEAP_SYSTEM_MASK (1 << 0) 25 #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << 1) 26 #define ION_HEAP_EXYNOS_CONTIG_MASK (1 << 4) 27 #define ION_HEAP_EXYNOS_MASK (1 << 5) 28 #define ION_EXYNOS_FIMD_VIDEO_MASK (1 << 28) 29 #define ION_EXYNOS_GSC_MASK (1 << 27) 30 #define ION_EXYNOS_MFC_OUTPUT_MASK (1 << 26) 31 #define ION_EXYNOS_MFC_INPUT_MASK (1 << 25) 32 33 34 /* ION_MSYNC_FLAGS 35 * values of @flags parameter to ion_msync() 36 * 37 * IMSYNC_DEV_TO_READ: Device only reads the buffer 38 * IMSYNC_DEV_TO_WRITE: Device may writes to the buffer 39 * IMSYNC_DEV_TO_RW: Device reads and writes to the buffer 40 * 41 * IMSYNC_SYNC_FOR_DEV: ion_msync() for device to access the buffer 42 * IMSYNC_SYNC_FOR_CPU: ion_msync() for CPU to access the buffer after device 43 * has accessed it. 44 * 45 * The values must be ORed with one of IMSYNC_DEV_* and one of IMSYNC_SYNC_*. 46 * Otherwise, ion_msync() will not effect. 47 */ 48 enum ION_MSYNC_FLAGS { 49 IMSYNC_DEV_TO_READ = 0, 50 IMSYNC_DEV_TO_WRITE = 1, 51 IMSYNC_DEV_TO_RW = 2, 52 IMSYNC_SYNC_FOR_DEV = 0x10000, 53 IMSYNC_SYNC_FOR_CPU = 0x20000, 54 }; 55 56 #ifdef __cplusplus 57 extern "C" { 58 #endif 59 60 /* ion_client 61 * An ION client is an object or an entity that needs to use the service of 62 * ION and has unique address space. ion_client is an identifier of an ION 63 * client and it represents the ION client. 64 * All operations on ION needs a valid ion_client value and it can be obtained 65 * by ion_client_create(). 66 */ 67 typedef int ion_client; 68 69 /* ion_buffer 70 * An identifier of a buffer allocated from ION. You must obtain to access 71 * a buffer allocated from ION. If you have an effective ion_buffer, you have 72 * three options to work with it. 73 * - To access the buffer, you can request an address (user virtual address) 74 * of the buffer with ion_map(). 75 * - To pass the buffer to the kernel, you can pass the ion_buffer to the 76 * kernel driver directly, if the kernel driver can work with ION. 77 * - To pass the buffer to other processes, you can pass the ion_buffer to 78 * other processes through RPC machanism such as socket communication or 79 * Android Binder because ion_buffer is actually an open file descripotor 80 * of the current process. 81 */ 82 typedef int ion_buffer; 83 84 /* ion_client_create() 85 * @RETURN: new ion_client. 86 * netative value if creating new ion_client is failed. 87 * 88 * A call to ion_client_create() must be paired with ion_client_destroy(), 89 * symmetrically. ion_client_destroy() needs a valid ion_client that 90 * is returned by ion_client_create(). 91 */ 92 ion_client ion_client_create(void); 93 94 /* ion_client_destroy() 95 * @client: An ion_client value to remove. 96 */ 97 void ion_client_destroy(ion_client client); 98 99 /* ion_alloc() - Allocates new buffer from ION. 100 * @client: A valid ion_client value returned by ion_client_create(). 101 * @len: Size of a buffer required in bytes. 102 * @align: Alignment requirements of @len and the start address of the allocated 103 * buffer. If the @len is not aligned by @align, ION allocates a buffer 104 * that is aligned by @align and the size of the buffer will be larger 105 * than @len. 106 * @heap_mask: Mask of heaps which you want this allocation to be served from. 107 * @flags: Additional requirements about buffer. ION_FLAG_CACHED for a 108 * buffer you want to have a cached mapping of 109 * @RETURN: An ion_buffer that represents the buffer allocated. It is only 110 * unique in the context of the given client, @client. 111 * -error if the allocation failed. 112 * See the description of ion_buffer above for detailed information. 113 */ 114 ion_buffer ion_alloc(ion_client client, size_t len, size_t align, 115 unsigned int heap_mask, unsigned int flags); 116 117 /* ion_free() - Frees an existing buffer that is allocated by ION 118 * @buffer: An ion_buffer of the buffer to be released. 119 */ 120 void ion_free(ion_buffer buffer); 121 122 /* ion_map() - Obtains a virtual address of the buffer identied by @buffer 123 * @buffer: The buffer to map. The virtual address returned is allocated by the 124 * kernel. 125 * @len: The size of the buffer to map. This must not exceed the size of the 126 * buffer represented by @fd_buf. Thus you need to know the size of it 127 * before calling this function. If @len is less than the size of the 128 * buffer, this function just map just the size requested (@len) not the 129 * entire buffer. 130 * @offset: How many pages will be ignored while mapping.@offset number of 131 * pages from the start of the buffer will not be mapped. 132 * @RETURN: The start virtual addres mapped. 133 * MAP_FAILED if mapping fails. 134 * 135 * Note that @len + (@offset * PAGE_SIZE) must not exceed the size of the 136 * buffer. 137 */ 138 void *ion_map(ion_buffer buffer, size_t len, off_t offset); 139 140 /* ion_unmap() - Frees the buffer mapped by ion_map() 141 * @addr: The address returned by ion_map(). 142 * @len: The size of the buffer mapped by ion_map(). 143 * @RETURN: 0 on success, and -1 on failure. 144 * errno is also set on failure. 145 */ 146 int ion_unmap(void *addr, size_t len); 147 148 /* ion_msync() - Makes sure that data in the buffer are visible to H/W peri. 149 * @client: A valid ion_client value returned by ion_client_create(). 150 * @buffer: The buffer to perform ion_msync(). 151 * @flags: Direction of access of H/W peri and CPU. See the description of 152 * ION_MSYNC_FLAGS. 153 * @size: Size to ion_msync() in bytes. 154 * @offset: Where ion_msync() start in @buffer, size in bytes. 155 * @RETURN: 0 if successful. -error, otherwise. 156 * 157 * Note that @offset + @size must not exceed the size of @buffer. 158 */ 159 int ion_sync(ion_client client, ion_buffer buffer); 160 161 #ifdef __cplusplus 162 } 163 #endif 164 #endif /* _LIB_ION_H_ */ 165