blob: b5495a0bbe2b5dad06ba13c997033841aba047b9 [file] [log] [blame]
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07001/*
2 * include/linux/ion.h
3 *
4 * Copyright (C) 2011 Google, Inc.
Olav Haugan0a852512012-01-09 10:20:55 -08005 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07006 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#ifndef _LINUX_ION_H
19#define _LINUX_ION_H
20
Laura Abbottabcb6f72011-10-04 16:26:49 -070021#include <linux/ioctl.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070022#include <linux/types.h>
23
Laura Abbottabcb6f72011-10-04 16:26:49 -070024
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070025struct ion_handle;
26/**
27 * enum ion_heap_types - list of all possible types of heaps
Iliyan Malchevf22301562011-07-06 16:53:21 -070028 * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
29 * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
30 * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
Olav Hauganb5be7992011-11-18 14:29:02 -080031 * carveout heap, allocations are physically
32 * contiguous
Olav Haugan0a852512012-01-09 10:20:55 -080033 * @ION_HEAP_TYPE_IOMMU: IOMMU memory
34 * @ION_HEAP_TYPE_CP: memory allocated from a prereserved
35 * carveout heap, allocations are physically
36 * contiguous. Used for content protection.
37 * @ION_HEAP_END: helper for iterating over heaps
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070038 */
39enum ion_heap_type {
40 ION_HEAP_TYPE_SYSTEM,
41 ION_HEAP_TYPE_SYSTEM_CONTIG,
42 ION_HEAP_TYPE_CARVEOUT,
Laura Abbott8c017362011-09-22 20:59:12 -070043 ION_HEAP_TYPE_IOMMU,
Olav Haugan0a852512012-01-09 10:20:55 -080044 ION_HEAP_TYPE_CP,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070045 ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always
46 are at the end of this enum */
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070047 ION_NUM_HEAPS,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070048};
49
Iliyan Malchevf22301562011-07-06 16:53:21 -070050#define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM)
51#define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
52#define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
Olav Haugan0a852512012-01-09 10:20:55 -080053#define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070054
Laura Abbotta2e93632011-08-19 13:36:32 -070055
56/**
57 * These are the only ids that should be used for Ion heap ids.
58 * The ids listed are the order in which allocation will be attempted
59 * if specified. Don't swap the order of heap ids unless you know what
60 * you are doing!
Olav Hauganb5be7992011-11-18 14:29:02 -080061 * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
62 * possible fallbacks)
Laura Abbotta2e93632011-08-19 13:36:32 -070063 */
64
65enum ion_heap_ids {
Olav Haugan42ebe712012-01-10 16:30:58 -080066 INVALID_HEAP_ID = -1,
Olav Hauganb5be7992011-11-18 14:29:02 -080067 ION_CP_MM_HEAP_ID = 8,
68 ION_CP_MFC_HEAP_ID = 12,
69 ION_CP_WB_HEAP_ID = 16, /* 8660 only */
70 ION_CAMERA_HEAP_ID = 20, /* 8660 only */
71 ION_SF_HEAP_ID = 24,
Olav Haugan9e123f92012-02-15 15:41:48 -080072 ION_IOMMU_HEAP_ID = 25,
Olav Haugan80854eb2012-01-12 12:00:23 -080073 ION_QSECOM_HEAP_ID = 27,
Olav Hauganb5be7992011-11-18 14:29:02 -080074 ION_AUDIO_HEAP_ID = 28,
75
Olav Haugan42ebe712012-01-10 16:30:58 -080076 ION_MM_FIRMWARE_HEAP_ID = 29,
Olav Hauganb5be7992011-11-18 14:29:02 -080077 ION_SYSTEM_HEAP_ID = 30,
78
79 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
Laura Abbotta2e93632011-08-19 13:36:32 -070080};
81
Larry Bassel2d8b42d2012-03-12 10:41:26 -070082enum ion_fixed_position {
83 NOT_FIXED,
84 FIXED_LOW,
85 FIXED_MIDDLE,
86 FIXED_HIGH,
87};
88
Olav Hauganb5be7992011-11-18 14:29:02 -080089/**
90 * Flag to use when allocating to indicate that a heap is secure.
91 */
92#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
93
94/**
95 * Macro should be used with ion_heap_ids defined above.
96 */
97#define ION_HEAP(bit) (1 << (bit))
98
Laura Abbotta2e93632011-08-19 13:36:32 -070099#define ION_VMALLOC_HEAP_NAME "vmalloc"
Olav Hauganb5be7992011-11-18 14:29:02 -0800100#define ION_AUDIO_HEAP_NAME "audio"
101#define ION_SF_HEAP_NAME "sf"
102#define ION_MM_HEAP_NAME "mm"
103#define ION_CAMERA_HEAP_NAME "camera_preview"
Laura Abbott8c017362011-09-22 20:59:12 -0700104#define ION_IOMMU_HEAP_NAME "iommu"
Olav Hauganb5be7992011-11-18 14:29:02 -0800105#define ION_MFC_HEAP_NAME "mfc"
106#define ION_WB_HEAP_NAME "wb"
Olav Haugan42ebe712012-01-10 16:30:58 -0800107#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Olav Haugan80854eb2012-01-12 12:00:23 -0800108#define ION_QSECOM_HEAP_NAME "qsecom"
Laura Abbottcaafeea2011-12-13 11:43:10 -0800109#define ION_FMEM_HEAP_NAME "fmem"
Laura Abbotta2e93632011-08-19 13:36:32 -0700110
Laura Abbott894fd582011-08-19 13:33:56 -0700111#define CACHED 1
112#define UNCACHED 0
113
114#define ION_CACHE_SHIFT 0
115
116#define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT)
117
Laura Abbott35412032011-09-29 09:50:06 -0700118#define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT))
119
Olav Hauganb3676592012-03-02 15:02:25 -0800120/*
121 * This flag allows clients when mapping into the IOMMU to specify to
122 * defer un-mapping from the IOMMU until the buffer memory is freed.
123 */
124#define ION_IOMMU_UNMAP_DELAYED 1
125
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700126#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700127#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700128#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700129struct ion_device;
130struct ion_heap;
131struct ion_mapper;
132struct ion_client;
133struct ion_buffer;
134
135/* This should be removed some day when phys_addr_t's are fully
136 plumbed in the kernel, and all instances of ion_phys_addr_t should
137 be converted to phys_addr_t. For the time being many kernel interfaces
138 do not accept phys_addr_t's that would have to */
139#define ion_phys_addr_t unsigned long
Laura Abbottcaafeea2011-12-13 11:43:10 -0800140#define ion_virt_addr_t unsigned long
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700141
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700142/**
143 * struct ion_platform_heap - defines a heap in the given platform
144 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800145 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800146 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700147 * @name: used for debug purposes
148 * @base: base address of heap in physical memory if applicable
149 * @size: size of the heap in bytes if applicable
Laura Abbottcaafeea2011-12-13 11:43:10 -0800150 * @memory_type:Memory type used for the heap
151 * @extra_data: Extra data specific to each heap type
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700152 */
153struct ion_platform_heap {
154 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700155 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700156 const char *name;
157 ion_phys_addr_t base;
158 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700159 enum ion_memory_types memory_type;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800160 void *extra_data;
161};
162
Laura Abbottcaafeea2011-12-13 11:43:10 -0800163/**
164 * struct ion_cp_heap_pdata - defines a content protection heap in the given
165 * platform
166 * @permission_type: Memory ID used to identify the memory to TZ
167 * @align: Alignment requirement for the memory
168 * @secure_base: Base address for securing the heap.
169 * Note: This might be different from actual base address
170 * of this heap in the case of a shared heap.
171 * @secure_size: Memory size for securing the heap.
172 * Note: This might be different from actual size
173 * of this heap in the case of a shared heap.
174 * @reusable Flag indicating whether this heap is reusable of not.
175 * (see FMEM)
Olav Hauganf6dc7742012-02-15 09:11:55 -0800176 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
177 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700178 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800179 * @virt_addr: Virtual address used when using fmem.
Olav Haugan8726caf2012-05-10 15:11:35 -0700180 * @iommu_map_all: Indicates whether we should map whole heap into IOMMU.
181 * @iommu_2x_map_domain: Indicates the domain to use for overmapping.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800182 * @request_region: function to be called when the number of allocations
183 * goes from 0 -> 1
184 * @release_region: function to be called when the number of allocations
185 * goes from 1 -> 0
186 * @setup_region: function to be called upon ion registration
187 *
188 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800189struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800190 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800191 unsigned int align;
192 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
193 size_t secure_size; /* Size used for securing heap when heap is shared*/
Laura Abbottcaafeea2011-12-13 11:43:10 -0800194 int reusable;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800195 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700196 enum ion_fixed_position fixed_position;
Olav Haugan8726caf2012-05-10 15:11:35 -0700197 int iommu_map_all;
198 int iommu_2x_map_domain;
Laura Abbottcaafeea2011-12-13 11:43:10 -0800199 ion_virt_addr_t *virt_addr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800200 int (*request_region)(void *);
201 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800202 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700203};
204
Laura Abbottcaafeea2011-12-13 11:43:10 -0800205/**
206 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
207 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
208 * @align: Alignment requirement for the memory
Olav Hauganf6dc7742012-02-15 09:11:55 -0800209 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
210 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700211 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800212 * @request_region: function to be called when the number of allocations
213 * goes from 0 -> 1
214 * @release_region: function to be called when the number of allocations
215 * goes from 1 -> 0
216 * @setup_region: function to be called upon ion registration
217 *
218 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800219struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800220 int adjacent_mem_id;
221 unsigned int align;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800222 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700223 enum ion_fixed_position fixed_position;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800224 int (*request_region)(void *);
225 int (*release_region)(void *);
226 void *(*setup_region)(void);
227};
228
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700229/**
230 * struct ion_platform_data - array of platform heaps passed from board file
Alex Bird27ca6612011-11-01 14:40:06 -0700231 * @nr: number of structures in the array
232 * @request_region: function to be called when the number of allocations goes
233 * from 0 -> 1
234 * @release_region: function to be called when the number of allocations goes
235 * from 1 -> 0
236 * @setup_region: function to be called upon ion registration
237 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700238 *
239 * Provided by the board file in the form of platform data to a platform device.
240 */
241struct ion_platform_data {
242 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800243 int (*request_region)(void *);
244 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700245 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700246 struct ion_platform_heap heaps[];
247};
248
Jordan Crouse8cd48322011-10-12 17:05:19 -0600249#ifdef CONFIG_ION
250
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700251/**
252 * ion_client_create() - allocate a client and returns it
253 * @dev: the global ion device
254 * @heap_mask: mask of heaps this client can allocate from
255 * @name: used for debugging
256 */
257struct ion_client *ion_client_create(struct ion_device *dev,
258 unsigned int heap_mask, const char *name);
259
260/**
Laura Abbott302911d2011-08-15 17:12:57 -0700261 * msm_ion_client_create - allocate a client using the ion_device specified in
262 * drivers/gpu/ion/msm/msm_ion.c
263 *
264 * heap_mask and name are the same as ion_client_create, return values
265 * are the same as ion_client_create.
266 */
267
268struct ion_client *msm_ion_client_create(unsigned int heap_mask,
269 const char *name);
270
271/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700272 * ion_client_destroy() - free's a client and all it's handles
273 * @client: the client
274 *
275 * Free the provided client and all it's resources including
276 * any handles it is holding.
277 */
278void ion_client_destroy(struct ion_client *client);
279
280/**
281 * ion_alloc - allocate ion memory
282 * @client: the client
283 * @len: size of the allocation
284 * @align: requested allocation alignment, lots of hardware blocks have
285 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700286 * @flags: mask of heaps to allocate from, if multiple bits are set
287 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700288 *
289 * Allocate memory in one of the heaps provided in heap mask and return
290 * an opaque handle to it.
291 */
292struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
293 size_t align, unsigned int flags);
294
295/**
296 * ion_free - free a handle
297 * @client: the client
298 * @handle: the handle to free
299 *
300 * Free the provided handle.
301 */
302void ion_free(struct ion_client *client, struct ion_handle *handle);
303
304/**
305 * ion_phys - returns the physical address and len of a handle
306 * @client: the client
307 * @handle: the handle
308 * @addr: a pointer to put the address in
309 * @len: a pointer to put the length in
310 *
311 * This function queries the heap for a particular handle to get the
312 * handle's physical address. It't output is only correct if
313 * a heap returns physically contiguous memory -- in other cases
314 * this api should not be implemented -- ion_map_dma should be used
315 * instead. Returns -EINVAL if the handle is invalid. This has
316 * no implications on the reference counting of the handle --
317 * the returned value may not be valid if the caller is not
318 * holding a reference.
319 */
320int ion_phys(struct ion_client *client, struct ion_handle *handle,
321 ion_phys_addr_t *addr, size_t *len);
322
323/**
324 * ion_map_kernel - create mapping for the given handle
325 * @client: the client
326 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700327 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700328 *
329 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700330 * can be used to access this address. If no flags are specified, this
331 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700332 */
Laura Abbott894fd582011-08-19 13:33:56 -0700333void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
334 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700335
336/**
337 * ion_unmap_kernel() - destroy a kernel mapping for a handle
338 * @client: the client
339 * @handle: handle to unmap
340 */
341void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
342
343/**
344 * ion_map_dma - create a dma mapping for a given handle
345 * @client: the client
346 * @handle: handle to map
347 *
348 * Return an sglist describing the given handle
349 */
350struct scatterlist *ion_map_dma(struct ion_client *client,
Laura Abbott894fd582011-08-19 13:33:56 -0700351 struct ion_handle *handle,
352 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700353
354/**
355 * ion_unmap_dma() - destroy a dma mapping for a handle
356 * @client: the client
357 * @handle: handle to unmap
358 */
359void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
360
361/**
362 * ion_share() - given a handle, obtain a buffer to pass to other clients
363 * @client: the client
364 * @handle: the handle to share
365 *
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700366 * Given a handle, return a buffer, which exists in a global name
367 * space, and can be passed to other clients. Should be passed into ion_import
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700368 * to obtain a new handle for this buffer.
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700369 *
370 * NOTE: This function does do not an extra reference. The burden is on the
371 * caller to make sure the buffer doesn't go away while it's being passed to
372 * another client. That is, ion_free should not be called on this handle until
373 * the buffer has been imported into the other client.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700374 */
375struct ion_buffer *ion_share(struct ion_client *client,
376 struct ion_handle *handle);
377
378/**
379 * ion_import() - given an buffer in another client, import it
380 * @client: this blocks client
381 * @buffer: the buffer to import (as obtained from ion_share)
382 *
383 * Given a buffer, add it to the client and return the handle to use to refer
384 * to it further. This is called to share a handle from one kernel client to
385 * another.
386 */
387struct ion_handle *ion_import(struct ion_client *client,
388 struct ion_buffer *buffer);
389
390/**
391 * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
392 * @client: this blocks client
393 * @fd: the fd
394 *
395 * A helper function for drivers that will be recieving ion buffers shared
396 * with them from userspace. These buffers are represented by a file
397 * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
398 * This function coverts that fd into the underlying buffer, and returns
399 * the handle to use to refer to it further.
400 */
401struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700402
Laura Abbott273dd8e2011-10-12 14:26:33 -0700403/**
404 * ion_handle_get_flags - get the flags for a given handle
405 *
406 * @client - client who allocated the handle
407 * @handle - handle to get the flags
408 * @flags - pointer to store the flags
409 *
410 * Gets the current flags for a handle. These flags indicate various options
411 * of the buffer (caching, security, etc.)
412 */
413int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
414 unsigned long *flags);
415
Laura Abbott8c017362011-09-22 20:59:12 -0700416
417/**
418 * ion_map_iommu - map the given handle into an iommu
419 *
420 * @client - client who allocated the handle
421 * @handle - handle to map
422 * @domain_num - domain number to map to
423 * @partition_num - partition number to allocate iova from
424 * @align - alignment for the iova
425 * @iova_length - length of iova to map. If the iova length is
426 * greater than the handle length, the remaining
427 * address space will be mapped to a dummy buffer.
428 * @iova - pointer to store the iova address
429 * @buffer_size - pointer to store the size of the buffer
430 * @flags - flags for options to map
Olav Hauganb3676592012-03-02 15:02:25 -0800431 * @iommu_flags - flags specific to the iommu.
Laura Abbott8c017362011-09-22 20:59:12 -0700432 *
433 * Maps the handle into the iova space specified via domain number. Iova
434 * will be allocated from the partition specified via partition_num.
435 * Returns 0 on success, negative value on error.
436 */
437int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
438 int domain_num, int partition_num, unsigned long align,
439 unsigned long iova_length, unsigned long *iova,
440 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800441 unsigned long flags, unsigned long iommu_flags);
Laura Abbott8c017362011-09-22 20:59:12 -0700442
443
444/**
445 * ion_handle_get_size - get the allocated size of a given handle
446 *
447 * @client - client who allocated the handle
448 * @handle - handle to get the size
449 * @size - pointer to store the size
450 *
451 * gives the allocated size of a handle. returns 0 on success, negative
452 * value on error
453 *
454 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
455 * You should *NOT* rely on this for any other usage.
456 */
457
458int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
459 unsigned long *size);
460
461/**
462 * ion_unmap_iommu - unmap the handle from an iommu
463 *
464 * @client - client who allocated the handle
465 * @handle - handle to unmap
466 * @domain_num - domain to unmap from
467 * @partition_num - partition to unmap from
468 *
469 * Decrement the reference count on the iommu mapping. If the count is
470 * 0, the mapping will be removed from the iommu.
471 */
472void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
473 int domain_num, int partition_num);
474
475
Olav Haugan0a852512012-01-09 10:20:55 -0800476/**
477 * ion_secure_heap - secure a heap
478 *
479 * @client - a client that has allocated from the heap heap_id
480 * @heap_id - heap id to secure.
481 *
482 * Secure a heap
483 * Returns 0 on success
484 */
485int ion_secure_heap(struct ion_device *dev, int heap_id);
486
487/**
488 * ion_unsecure_heap - un-secure a heap
489 *
490 * @client - a client that has allocated from the heap heap_id
491 * @heap_id - heap id to un-secure.
492 *
493 * Un-secure a heap
494 * Returns 0 on success
495 */
496int ion_unsecure_heap(struct ion_device *dev, int heap_id);
497
498/**
499 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
500 *
501 * @heap_id - heap id to secure.
502 *
503 * Secure a heap
504 * Returns 0 on success
505 */
506int msm_ion_secure_heap(int heap_id);
507
508/**
509 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
510 *
511 * @heap_id - heap id to secure.
512 *
513 * Un-secure a heap
514 * Returns 0 on success
515 */
516int msm_ion_unsecure_heap(int heap_id);
517
Olav Haugan41f85792012-02-08 15:28:05 -0800518/**
519 * msm_ion_do_cache_op - do cache operations.
520 *
521 * @client - pointer to ION client.
522 * @handle - pointer to buffer handle.
523 * @vaddr - virtual address to operate on.
524 * @len - Length of data to do cache operation on.
525 * @cmd - Cache operation to perform:
526 * ION_IOC_CLEAN_CACHES
527 * ION_IOC_INV_CACHES
528 * ION_IOC_CLEAN_INV_CACHES
529 *
530 * Returns 0 on success
531 */
532int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle,
533 void *vaddr, unsigned long len, unsigned int cmd);
534
Jordan Crouse8cd48322011-10-12 17:05:19 -0600535#else
536static inline struct ion_client *ion_client_create(struct ion_device *dev,
537 unsigned int heap_mask, const char *name)
538{
539 return ERR_PTR(-ENODEV);
540}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700541
Jordan Crouse8cd48322011-10-12 17:05:19 -0600542static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
543 const char *name)
544{
545 return ERR_PTR(-ENODEV);
546}
547
548static inline void ion_client_destroy(struct ion_client *client) { }
549
550static inline struct ion_handle *ion_alloc(struct ion_client *client,
551 size_t len, size_t align, unsigned int flags)
552{
553 return ERR_PTR(-ENODEV);
554}
555
556static inline void ion_free(struct ion_client *client,
557 struct ion_handle *handle) { }
558
559
560static inline int ion_phys(struct ion_client *client,
561 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
562{
563 return -ENODEV;
564}
565
566static inline void *ion_map_kernel(struct ion_client *client,
567 struct ion_handle *handle, unsigned long flags)
568{
569 return ERR_PTR(-ENODEV);
570}
571
572static inline void ion_unmap_kernel(struct ion_client *client,
573 struct ion_handle *handle) { }
574
575static inline struct scatterlist *ion_map_dma(struct ion_client *client,
576 struct ion_handle *handle, unsigned long flags)
577{
578 return ERR_PTR(-ENODEV);
579}
580
581static inline void ion_unmap_dma(struct ion_client *client,
582 struct ion_handle *handle) { }
583
584static inline struct ion_buffer *ion_share(struct ion_client *client,
585 struct ion_handle *handle)
586{
587 return ERR_PTR(-ENODEV);
588}
589
590static inline struct ion_handle *ion_import(struct ion_client *client,
591 struct ion_buffer *buffer)
592{
593 return ERR_PTR(-ENODEV);
594}
595
596static inline struct ion_handle *ion_import_fd(struct ion_client *client,
597 int fd)
598{
599 return ERR_PTR(-ENODEV);
600}
601
602static inline int ion_handle_get_flags(struct ion_client *client,
603 struct ion_handle *handle, unsigned long *flags)
604{
605 return -ENODEV;
606}
Laura Abbott8c017362011-09-22 20:59:12 -0700607
608static inline int ion_map_iommu(struct ion_client *client,
609 struct ion_handle *handle, int domain_num,
610 int partition_num, unsigned long align,
611 unsigned long iova_length, unsigned long *iova,
Olav Haugan9a27d4c2012-02-23 09:35:16 -0800612 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800613 unsigned long flags,
614 unsigned long iommu_flags)
Laura Abbott8c017362011-09-22 20:59:12 -0700615{
616 return -ENODEV;
617}
618
619static inline void ion_unmap_iommu(struct ion_client *client,
620 struct ion_handle *handle, int domain_num,
621 int partition_num)
622{
623 return;
624}
625
Olav Haugan0a852512012-01-09 10:20:55 -0800626static inline int ion_secure_heap(struct ion_device *dev, int heap_id)
627{
628 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700629
Olav Haugan0a852512012-01-09 10:20:55 -0800630}
631
632static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id)
633{
634 return -ENODEV;
635}
636
637static inline int msm_ion_secure_heap(int heap_id)
638{
639 return -ENODEV;
640
641}
642
643static inline int msm_ion_unsecure_heap(int heap_id)
644{
645 return -ENODEV;
646}
Olav Haugan41f85792012-02-08 15:28:05 -0800647
648static inline int msm_ion_do_cache_op(struct ion_client *client,
649 struct ion_handle *handle, void *vaddr,
650 unsigned long len, unsigned int cmd)
651{
652 return -ENODEV;
653}
654
Jordan Crouse8cd48322011-10-12 17:05:19 -0600655#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700656#endif /* __KERNEL__ */
657
658/**
659 * DOC: Ion Userspace API
660 *
661 * create a client by opening /dev/ion
662 * most operations handled via following ioctls
663 *
664 */
665
666/**
667 * struct ion_allocation_data - metadata passed from userspace for allocations
668 * @len: size of the allocation
669 * @align: required alignment of the allocation
670 * @flags: flags passed to heap
671 * @handle: pointer that will be populated with a cookie to use to refer
672 * to this allocation
673 *
674 * Provided by userspace as an argument to the ioctl
675 */
676struct ion_allocation_data {
677 size_t len;
678 size_t align;
679 unsigned int flags;
680 struct ion_handle *handle;
681};
682
683/**
684 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
685 * @handle: a handle
686 * @fd: a file descriptor representing that handle
687 *
688 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
689 * the handle returned from ion alloc, and the kernel returns the file
690 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
691 * provides the file descriptor and the kernel returns the handle.
692 */
693struct ion_fd_data {
694 struct ion_handle *handle;
695 int fd;
696};
697
698/**
699 * struct ion_handle_data - a handle passed to/from the kernel
700 * @handle: a handle
701 */
702struct ion_handle_data {
703 struct ion_handle *handle;
704};
705
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700706/**
707 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
708 * @cmd: the custom ioctl function to call
709 * @arg: additional data to pass to the custom ioctl, typically a user
710 * pointer to a predefined structure
711 *
712 * This works just like the regular cmd and arg fields of an ioctl.
713 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700714struct ion_custom_data {
715 unsigned int cmd;
716 unsigned long arg;
717};
718
Laura Abbottabcb6f72011-10-04 16:26:49 -0700719
720/* struct ion_flush_data - data passed to ion for flushing caches
721 *
722 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800723 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700724 * @vaddr: userspace virtual address mapped with mmap
725 * @offset: offset into the handle to flush
726 * @length: length of handle to flush
727 *
728 * Performs cache operations on the handle. If p is the start address
729 * of the handle, p + offset through p + offset + length will have
730 * the cache operations performed
731 */
732struct ion_flush_data {
733 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800734 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700735 void *vaddr;
736 unsigned int offset;
737 unsigned int length;
738};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700739
740/* struct ion_flag_data - information about flags for this buffer
741 *
742 * @handle: handle to get flags from
743 * @flags: flags of this handle
744 *
745 * Takes handle as an input and outputs the flags from the handle
746 * in the flag field.
747 */
748struct ion_flag_data {
749 struct ion_handle *handle;
750 unsigned long flags;
751};
752
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700753#define ION_IOC_MAGIC 'I'
754
755/**
756 * DOC: ION_IOC_ALLOC - allocate memory
757 *
758 * Takes an ion_allocation_data struct and returns it with the handle field
759 * populated with the opaque handle for the allocation.
760 */
761#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
762 struct ion_allocation_data)
763
764/**
765 * DOC: ION_IOC_FREE - free memory
766 *
767 * Takes an ion_handle_data struct and frees the handle.
768 */
769#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
770
771/**
772 * DOC: ION_IOC_MAP - get a file descriptor to mmap
773 *
774 * Takes an ion_fd_data struct with the handle field populated with a valid
775 * opaque handle. Returns the struct with the fd field set to a file
776 * descriptor open in the current address space. This file descriptor
777 * can then be used as an argument to mmap.
778 */
779#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
780
781/**
782 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
783 *
784 * Takes an ion_fd_data struct with the handle field populated with a valid
785 * opaque handle. Returns the struct with the fd field set to a file
786 * descriptor open in the current address space. This file descriptor
787 * can then be passed to another process. The corresponding opaque handle can
788 * be retrieved via ION_IOC_IMPORT.
789 */
790#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
791
792/**
793 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
794 *
795 * Takes an ion_fd_data struct with the fd field populated with a valid file
796 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
797 * filed set to the corresponding opaque handle.
798 */
799#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
800
801/**
802 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
803 *
804 * Takes the argument of the architecture specific ioctl to call and
805 * passes appropriate userdata for that ioctl
806 */
807#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
808
Laura Abbottabcb6f72011-10-04 16:26:49 -0700809
810/**
811 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
812 *
813 * Clean the caches of the handle specified.
814 */
815#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
816 struct ion_flush_data)
817/**
818 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
819 *
820 * Invalidate the caches of the handle specified.
821 */
822#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
823 struct ion_flush_data)
824/**
825 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
826 *
827 * Clean and invalidate the caches of the handle specified.
828 */
829#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
830 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700831
832/**
833 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
834 *
835 * Gets the flags of the current handle which indicate cachability,
836 * secure state etc.
837 */
838#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
839 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700840#endif /* _LINUX_ION_H */