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