2 * drivers/staging/android/ion/ion.h
4 * Copyright (C) 2011 Google, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
20 #include <linux/types.h>
22 #include "../uapi/ion.h"
31 /* This should be removed some day when phys_addr_t's are fully
32 plumbed in the kernel, and all instances of ion_phys_addr_t should
33 be converted to phys_addr_t. For the time being many kernel interfaces
34 do not accept phys_addr_t's that would have to */
35 #define ion_phys_addr_t unsigned long
38 * struct ion_platform_heap - defines a heap in the given platform
39 * @type: type of the heap from ion_heap_type enum
40 * @id: unique identifier for heap. When allocating higher numbers
41 * will be allocated from first. At allocation these are passed
42 * as a bit mask and therefore can not exceed ION_NUM_HEAP_IDS.
43 * @name: used for debug purposes
44 * @base: base address of heap in physical memory if applicable
45 * @size: size of the heap in bytes if applicable
46 * @align: required alignment in physical memory if applicable
47 * @priv: private info passed from the board file
49 * Provided by the board file.
51 struct ion_platform_heap {
52 enum ion_heap_type type;
57 ion_phys_addr_t align;
62 * struct ion_platform_data - array of platform heaps passed from board file
63 * @nr: number of structures in the array
64 * @heaps: array of platform_heap structions
66 * Provided by the board file in the form of platform data to a platform device.
68 struct ion_platform_data {
70 struct ion_platform_heap *heaps;
74 * ion_reserve() - reserve memory for ion heaps if applicable
75 * @data: platform data specifying starting physical address and
78 * Calls memblock reserve to set aside memory for heaps that are
79 * located at specific memory addresses or of specfic sizes not
80 * managed by the kernel
82 void ion_reserve(struct ion_platform_data *data);
85 * ion_client_create() - allocate a client and returns it
86 * @dev: the global ion device
87 * @heap_type_mask: mask of heaps this client can allocate from
88 * @name: used for debugging
90 struct ion_client *ion_client_create(struct ion_device *dev,
94 * ion_client_destroy() - free's a client and all it's handles
97 * Free the provided client and all it's resources including
98 * any handles it is holding.
100 void ion_client_destroy(struct ion_client *client);
103 * ion_alloc - allocate ion memory
104 * @client: the client
105 * @len: size of the allocation
106 * @align: requested allocation alignment, lots of hardware blocks
107 * have alignment requirements of some kind
108 * @heap_id_mask: mask of heaps to allocate from, if multiple bits are set
109 * heaps will be tried in order from highest to lowest
111 * @flags: heap flags, the low 16 bits are consumed by ion, the
112 * high 16 bits are passed on to the respective heap and
115 * Allocate memory in one of the heaps provided in heap mask and return
116 * an opaque handle to it.
118 struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
119 size_t align, unsigned int heap_id_mask,
123 * ion_free - free a handle
124 * @client: the client
125 * @handle: the handle to free
127 * Free the provided handle.
129 void ion_free(struct ion_client *client, struct ion_handle *handle);
132 * ion_phys - returns the physical address and len of a handle
133 * @client: the client
134 * @handle: the handle
135 * @addr: a pointer to put the address in
136 * @len: a pointer to put the length in
138 * This function queries the heap for a particular handle to get the
139 * handle's physical address. It't output is only correct if
140 * a heap returns physically contiguous memory -- in other cases
141 * this api should not be implemented -- ion_sg_table should be used
142 * instead. Returns -EINVAL if the handle is invalid. This has
143 * no implications on the reference counting of the handle --
144 * the returned value may not be valid if the caller is not
145 * holding a reference.
147 int ion_phys(struct ion_client *client, struct ion_handle *handle,
148 ion_phys_addr_t *addr, size_t *len);
151 * ion_map_dma - return an sg_table describing a handle
152 * @client: the client
153 * @handle: the handle
155 * This function returns the sg_table describing
156 * a particular ion handle.
158 struct sg_table *ion_sg_table(struct ion_client *client,
159 struct ion_handle *handle);
162 * ion_map_kernel - create mapping for the given handle
163 * @client: the client
164 * @handle: handle to map
166 * Map the given handle into the kernel and return a kernel address that
167 * can be used to access this address.
169 void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle);
172 * ion_unmap_kernel() - destroy a kernel mapping for a handle
173 * @client: the client
174 * @handle: handle to unmap
176 void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
179 * ion_share_dma_buf() - share buffer as dma-buf
180 * @client: the client
181 * @handle: the handle
183 struct dma_buf *ion_share_dma_buf(struct ion_client *client,
184 struct ion_handle *handle);
187 * ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd
188 * @client: the client
189 * @handle: the handle
191 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
194 * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
195 * @client: the client
196 * @fd: the dma-buf fd
198 * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
199 * import that fd and return a handle representing it. If a dma-buf from
200 * another exporter is passed in this function will return ERR_PTR(-EINVAL)
202 struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
205 * ion_handle_get() - ref ion buffer.
207 void ion_handle_get(struct ion_handle *handle);
209 * ion_handle_put() - unref ion buffer.
211 int ion_handle_put(struct ion_handle *handle);
213 #ifdef CONFIG_ARCH_ROCKCHIP
216 int ion_map_iommu(struct device *iommu_dev, struct ion_client *client,
217 struct ion_handle *handle, unsigned long *iova,
218 unsigned long *size);
220 void ion_unmap_iommu(struct device *iommu_dev, struct ion_client *client,
221 struct ion_handle *handle);
223 #endif /* _LINUX_ION_H */