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"
32 * This should be removed some day when phys_addr_t's are fully
33 * plumbed in the kernel, and all instances of ion_phys_addr_t should
34 * be converted to phys_addr_t. For the time being many kernel interfaces
35 * do not accept phys_addr_t's that would have to
37 #define ion_phys_addr_t unsigned long
40 * struct ion_platform_heap - defines a heap in the given platform
41 * @type: type of the heap from ion_heap_type enum
42 * @id: unique identifier for heap. When allocating higher numbers
43 * will be allocated from first. At allocation these are passed
44 * as a bit mask and therefore can not exceed ION_NUM_HEAP_IDS.
45 * @name: used for debug purposes
46 * @base: base address of heap in physical memory if applicable
47 * @size: size of the heap in bytes if applicable
48 * @align: required alignment in physical memory if applicable
49 * @priv: private info passed from the board file
51 * Provided by the board file.
53 struct ion_platform_heap {
54 enum ion_heap_type type;
59 ion_phys_addr_t align;
64 * struct ion_platform_data - array of platform heaps passed from board file
65 * @nr: number of structures in the array
66 * @heaps: array of platform_heap structions
68 * Provided by the board file in the form of platform data to a platform device.
70 struct ion_platform_data {
72 struct ion_platform_heap *heaps;
76 * ion_client_create() - allocate a client and returns it
77 * @dev: the global ion device
78 * @name: used for debugging
80 struct ion_client *ion_client_create(struct ion_device *dev,
84 * ion_client_destroy() - free's a client and all it's handles
87 * Free the provided client and all it's resources including
88 * any handles it is holding.
90 void ion_client_destroy(struct ion_client *client);
93 * ion_alloc - allocate ion memory
95 * @len: size of the allocation
96 * @align: requested allocation alignment, lots of hardware blocks
97 * have alignment requirements of some kind
98 * @heap_id_mask: mask of heaps to allocate from, if multiple bits are set
99 * heaps will be tried in order from highest to lowest
101 * @flags: heap flags, the low 16 bits are consumed by ion, the
102 * high 16 bits are passed on to the respective heap and
105 * Allocate memory in one of the heaps provided in heap mask and return
106 * an opaque handle to it.
108 struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
109 size_t align, unsigned int heap_id_mask,
112 struct ion_handle *__ion_alloc(struct ion_client *client, size_t len,
113 size_t align, unsigned int heap_id_mask,
114 unsigned int flags, bool grab_handle);
117 * ion_free - free a handle
118 * @client: the client
119 * @handle: the handle to free
121 * Free the provided handle.
123 void ion_free(struct ion_client *client, struct ion_handle *handle);
126 * ion_map_kernel - create mapping for the given handle
127 * @client: the client
128 * @handle: handle to map
130 * Map the given handle into the kernel and return a kernel address that
131 * can be used to access this address.
133 void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle);
136 * ion_unmap_kernel() - destroy a kernel mapping for a handle
137 * @client: the client
138 * @handle: handle to unmap
140 void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
143 * ion_share_dma_buf() - share buffer as dma-buf
144 * @client: the client
145 * @handle: the handle
147 struct dma_buf *ion_share_dma_buf(struct ion_client *client,
148 struct ion_handle *handle);
151 * ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd
152 * @client: the client
153 * @handle: the handle
155 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
158 * ion_import_dma_buf() - get ion_handle from dma-buf
159 * @client: the client
160 * @dmabuf: the dma-buf
162 * Get the ion_buffer associated with the dma-buf and return the ion_handle.
163 * If no ion_handle exists for this buffer, return newly created ion_handle.
164 * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL)
166 struct ion_handle *ion_import_dma_buf(struct ion_client *client,
167 struct dma_buf *dmabuf);
170 * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get handle
171 * @client: the client
172 * @fd: the dma-buf fd
174 * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
175 * import that fd and return a handle representing it. If a dma-buf from
176 * another exporter is passed in this function will return ERR_PTR(-EINVAL)
178 struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd);
180 #endif /* _LINUX_ION_H */