blob: d761e1e515b9a6a9aa2afc130d507bc875b1891f [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
Olav Hauganb5be7992011-11-18 14:29:02 -080082/**
83 * Flag to use when allocating to indicate that a heap is secure.
84 */
85#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
86
87/**
88 * Macro should be used with ion_heap_ids defined above.
89 */
90#define ION_HEAP(bit) (1 << (bit))
91
Laura Abbotta2e93632011-08-19 13:36:32 -070092#define ION_VMALLOC_HEAP_NAME "vmalloc"
Olav Hauganb5be7992011-11-18 14:29:02 -080093#define ION_AUDIO_HEAP_NAME "audio"
94#define ION_SF_HEAP_NAME "sf"
95#define ION_MM_HEAP_NAME "mm"
96#define ION_CAMERA_HEAP_NAME "camera_preview"
Laura Abbott8c017362011-09-22 20:59:12 -070097#define ION_IOMMU_HEAP_NAME "iommu"
Olav Hauganb5be7992011-11-18 14:29:02 -080098#define ION_MFC_HEAP_NAME "mfc"
99#define ION_WB_HEAP_NAME "wb"
Olav Haugan42ebe712012-01-10 16:30:58 -0800100#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Olav Haugan80854eb2012-01-12 12:00:23 -0800101#define ION_QSECOM_HEAP_NAME "qsecom"
Laura Abbottcaafeea2011-12-13 11:43:10 -0800102#define ION_FMEM_HEAP_NAME "fmem"
Laura Abbotta2e93632011-08-19 13:36:32 -0700103
Laura Abbott894fd582011-08-19 13:33:56 -0700104#define CACHED 1
105#define UNCACHED 0
106
107#define ION_CACHE_SHIFT 0
108
109#define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT)
110
Laura Abbott35412032011-09-29 09:50:06 -0700111#define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT))
112
Olav Hauganb3676592012-03-02 15:02:25 -0800113/*
114 * This flag allows clients when mapping into the IOMMU to specify to
115 * defer un-mapping from the IOMMU until the buffer memory is freed.
116 */
117#define ION_IOMMU_UNMAP_DELAYED 1
118
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700119#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700120#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700121#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700122struct ion_device;
123struct ion_heap;
124struct ion_mapper;
125struct ion_client;
126struct ion_buffer;
127
128/* This should be removed some day when phys_addr_t's are fully
129 plumbed in the kernel, and all instances of ion_phys_addr_t should
130 be converted to phys_addr_t. For the time being many kernel interfaces
131 do not accept phys_addr_t's that would have to */
132#define ion_phys_addr_t unsigned long
Laura Abbottcaafeea2011-12-13 11:43:10 -0800133#define ion_virt_addr_t unsigned long
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700134
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700135/**
136 * struct ion_platform_heap - defines a heap in the given platform
137 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800138 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800139 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700140 * @name: used for debug purposes
141 * @base: base address of heap in physical memory if applicable
142 * @size: size of the heap in bytes if applicable
Laura Abbottcaafeea2011-12-13 11:43:10 -0800143 * @memory_type:Memory type used for the heap
144 * @extra_data: Extra data specific to each heap type
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700145 */
146struct ion_platform_heap {
147 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700148 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700149 const char *name;
150 ion_phys_addr_t base;
151 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700152 enum ion_memory_types memory_type;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800153 void *extra_data;
154};
155
Laura Abbottcaafeea2011-12-13 11:43:10 -0800156/**
157 * struct ion_cp_heap_pdata - defines a content protection heap in the given
158 * platform
159 * @permission_type: Memory ID used to identify the memory to TZ
160 * @align: Alignment requirement for the memory
161 * @secure_base: Base address for securing the heap.
162 * Note: This might be different from actual base address
163 * of this heap in the case of a shared heap.
164 * @secure_size: Memory size for securing the heap.
165 * Note: This might be different from actual size
166 * of this heap in the case of a shared heap.
167 * @reusable Flag indicating whether this heap is reusable of not.
168 * (see FMEM)
Olav Hauganf6dc7742012-02-15 09:11:55 -0800169 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
170 * or not.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800171 * @virt_addr: Virtual address used when using fmem.
172 * @request_region: function to be called when the number of allocations
173 * goes from 0 -> 1
174 * @release_region: function to be called when the number of allocations
175 * goes from 1 -> 0
176 * @setup_region: function to be called upon ion registration
177 *
178 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800179struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800180 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800181 unsigned int align;
182 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
183 size_t secure_size; /* Size used for securing heap when heap is shared*/
Laura Abbottcaafeea2011-12-13 11:43:10 -0800184 int reusable;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800185 int mem_is_fmem;
Laura Abbottcaafeea2011-12-13 11:43:10 -0800186 ion_virt_addr_t *virt_addr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800187 int (*request_region)(void *);
188 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800189 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700190};
191
Laura Abbottcaafeea2011-12-13 11:43:10 -0800192/**
193 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
194 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
195 * @align: Alignment requirement for the memory
Olav Hauganf6dc7742012-02-15 09:11:55 -0800196 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
197 * or not.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800198 * @request_region: function to be called when the number of allocations
199 * goes from 0 -> 1
200 * @release_region: function to be called when the number of allocations
201 * goes from 1 -> 0
202 * @setup_region: function to be called upon ion registration
203 *
204 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800205struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800206 int adjacent_mem_id;
207 unsigned int align;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800208 int mem_is_fmem;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800209 int (*request_region)(void *);
210 int (*release_region)(void *);
211 void *(*setup_region)(void);
212};
213
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700214/**
215 * struct ion_platform_data - array of platform heaps passed from board file
Alex Bird27ca6612011-11-01 14:40:06 -0700216 * @nr: number of structures in the array
217 * @request_region: function to be called when the number of allocations goes
218 * from 0 -> 1
219 * @release_region: function to be called when the number of allocations goes
220 * from 1 -> 0
221 * @setup_region: function to be called upon ion registration
222 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700223 *
224 * Provided by the board file in the form of platform data to a platform device.
225 */
226struct ion_platform_data {
227 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800228 int (*request_region)(void *);
229 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700230 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700231 struct ion_platform_heap heaps[];
232};
233
Jordan Crouse8cd48322011-10-12 17:05:19 -0600234#ifdef CONFIG_ION
235
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700236/**
237 * ion_client_create() - allocate a client and returns it
238 * @dev: the global ion device
239 * @heap_mask: mask of heaps this client can allocate from
240 * @name: used for debugging
241 */
242struct ion_client *ion_client_create(struct ion_device *dev,
243 unsigned int heap_mask, const char *name);
244
245/**
Laura Abbott302911d2011-08-15 17:12:57 -0700246 * msm_ion_client_create - allocate a client using the ion_device specified in
247 * drivers/gpu/ion/msm/msm_ion.c
248 *
249 * heap_mask and name are the same as ion_client_create, return values
250 * are the same as ion_client_create.
251 */
252
253struct ion_client *msm_ion_client_create(unsigned int heap_mask,
254 const char *name);
255
256/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700257 * ion_client_destroy() - free's a client and all it's handles
258 * @client: the client
259 *
260 * Free the provided client and all it's resources including
261 * any handles it is holding.
262 */
263void ion_client_destroy(struct ion_client *client);
264
265/**
266 * ion_alloc - allocate ion memory
267 * @client: the client
268 * @len: size of the allocation
269 * @align: requested allocation alignment, lots of hardware blocks have
270 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700271 * @flags: mask of heaps to allocate from, if multiple bits are set
272 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700273 *
274 * Allocate memory in one of the heaps provided in heap mask and return
275 * an opaque handle to it.
276 */
277struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
278 size_t align, unsigned int flags);
279
280/**
281 * ion_free - free a handle
282 * @client: the client
283 * @handle: the handle to free
284 *
285 * Free the provided handle.
286 */
287void ion_free(struct ion_client *client, struct ion_handle *handle);
288
289/**
290 * ion_phys - returns the physical address and len of a handle
291 * @client: the client
292 * @handle: the handle
293 * @addr: a pointer to put the address in
294 * @len: a pointer to put the length in
295 *
296 * This function queries the heap for a particular handle to get the
297 * handle's physical address. It't output is only correct if
298 * a heap returns physically contiguous memory -- in other cases
299 * this api should not be implemented -- ion_map_dma should be used
300 * instead. Returns -EINVAL if the handle is invalid. This has
301 * no implications on the reference counting of the handle --
302 * the returned value may not be valid if the caller is not
303 * holding a reference.
304 */
305int ion_phys(struct ion_client *client, struct ion_handle *handle,
306 ion_phys_addr_t *addr, size_t *len);
307
308/**
309 * ion_map_kernel - create mapping for the given handle
310 * @client: the client
311 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700312 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700313 *
314 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700315 * can be used to access this address. If no flags are specified, this
316 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700317 */
Laura Abbott894fd582011-08-19 13:33:56 -0700318void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
319 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700320
321/**
322 * ion_unmap_kernel() - destroy a kernel mapping for a handle
323 * @client: the client
324 * @handle: handle to unmap
325 */
326void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
327
328/**
329 * ion_map_dma - create a dma mapping for a given handle
330 * @client: the client
331 * @handle: handle to map
332 *
333 * Return an sglist describing the given handle
334 */
335struct scatterlist *ion_map_dma(struct ion_client *client,
Laura Abbott894fd582011-08-19 13:33:56 -0700336 struct ion_handle *handle,
337 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700338
339/**
340 * ion_unmap_dma() - destroy a dma mapping for a handle
341 * @client: the client
342 * @handle: handle to unmap
343 */
344void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
345
346/**
347 * ion_share() - given a handle, obtain a buffer to pass to other clients
348 * @client: the client
349 * @handle: the handle to share
350 *
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700351 * Given a handle, return a buffer, which exists in a global name
352 * space, and can be passed to other clients. Should be passed into ion_import
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700353 * to obtain a new handle for this buffer.
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700354 *
355 * NOTE: This function does do not an extra reference. The burden is on the
356 * caller to make sure the buffer doesn't go away while it's being passed to
357 * another client. That is, ion_free should not be called on this handle until
358 * the buffer has been imported into the other client.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700359 */
360struct ion_buffer *ion_share(struct ion_client *client,
361 struct ion_handle *handle);
362
363/**
364 * ion_import() - given an buffer in another client, import it
365 * @client: this blocks client
366 * @buffer: the buffer to import (as obtained from ion_share)
367 *
368 * Given a buffer, add it to the client and return the handle to use to refer
369 * to it further. This is called to share a handle from one kernel client to
370 * another.
371 */
372struct ion_handle *ion_import(struct ion_client *client,
373 struct ion_buffer *buffer);
374
375/**
376 * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
377 * @client: this blocks client
378 * @fd: the fd
379 *
380 * A helper function for drivers that will be recieving ion buffers shared
381 * with them from userspace. These buffers are represented by a file
382 * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
383 * This function coverts that fd into the underlying buffer, and returns
384 * the handle to use to refer to it further.
385 */
386struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700387
Laura Abbott273dd8e2011-10-12 14:26:33 -0700388/**
389 * ion_handle_get_flags - get the flags for a given handle
390 *
391 * @client - client who allocated the handle
392 * @handle - handle to get the flags
393 * @flags - pointer to store the flags
394 *
395 * Gets the current flags for a handle. These flags indicate various options
396 * of the buffer (caching, security, etc.)
397 */
398int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
399 unsigned long *flags);
400
Laura Abbott8c017362011-09-22 20:59:12 -0700401
402/**
403 * ion_map_iommu - map the given handle into an iommu
404 *
405 * @client - client who allocated the handle
406 * @handle - handle to map
407 * @domain_num - domain number to map to
408 * @partition_num - partition number to allocate iova from
409 * @align - alignment for the iova
410 * @iova_length - length of iova to map. If the iova length is
411 * greater than the handle length, the remaining
412 * address space will be mapped to a dummy buffer.
413 * @iova - pointer to store the iova address
414 * @buffer_size - pointer to store the size of the buffer
415 * @flags - flags for options to map
Olav Hauganb3676592012-03-02 15:02:25 -0800416 * @iommu_flags - flags specific to the iommu.
Laura Abbott8c017362011-09-22 20:59:12 -0700417 *
418 * Maps the handle into the iova space specified via domain number. Iova
419 * will be allocated from the partition specified via partition_num.
420 * Returns 0 on success, negative value on error.
421 */
422int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
423 int domain_num, int partition_num, unsigned long align,
424 unsigned long iova_length, unsigned long *iova,
425 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800426 unsigned long flags, unsigned long iommu_flags);
Laura Abbott8c017362011-09-22 20:59:12 -0700427
428
429/**
430 * ion_handle_get_size - get the allocated size of a given handle
431 *
432 * @client - client who allocated the handle
433 * @handle - handle to get the size
434 * @size - pointer to store the size
435 *
436 * gives the allocated size of a handle. returns 0 on success, negative
437 * value on error
438 *
439 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
440 * You should *NOT* rely on this for any other usage.
441 */
442
443int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
444 unsigned long *size);
445
446/**
447 * ion_unmap_iommu - unmap the handle from an iommu
448 *
449 * @client - client who allocated the handle
450 * @handle - handle to unmap
451 * @domain_num - domain to unmap from
452 * @partition_num - partition to unmap from
453 *
454 * Decrement the reference count on the iommu mapping. If the count is
455 * 0, the mapping will be removed from the iommu.
456 */
457void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
458 int domain_num, int partition_num);
459
460
Olav Haugan0a852512012-01-09 10:20:55 -0800461/**
462 * ion_secure_heap - secure a heap
463 *
464 * @client - a client that has allocated from the heap heap_id
465 * @heap_id - heap id to secure.
466 *
467 * Secure a heap
468 * Returns 0 on success
469 */
470int ion_secure_heap(struct ion_device *dev, int heap_id);
471
472/**
473 * ion_unsecure_heap - un-secure a heap
474 *
475 * @client - a client that has allocated from the heap heap_id
476 * @heap_id - heap id to un-secure.
477 *
478 * Un-secure a heap
479 * Returns 0 on success
480 */
481int ion_unsecure_heap(struct ion_device *dev, int heap_id);
482
483/**
484 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
485 *
486 * @heap_id - heap id to secure.
487 *
488 * Secure a heap
489 * Returns 0 on success
490 */
491int msm_ion_secure_heap(int heap_id);
492
493/**
494 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
495 *
496 * @heap_id - heap id to secure.
497 *
498 * Un-secure a heap
499 * Returns 0 on success
500 */
501int msm_ion_unsecure_heap(int heap_id);
502
Olav Haugan41f85792012-02-08 15:28:05 -0800503/**
504 * msm_ion_do_cache_op - do cache operations.
505 *
506 * @client - pointer to ION client.
507 * @handle - pointer to buffer handle.
508 * @vaddr - virtual address to operate on.
509 * @len - Length of data to do cache operation on.
510 * @cmd - Cache operation to perform:
511 * ION_IOC_CLEAN_CACHES
512 * ION_IOC_INV_CACHES
513 * ION_IOC_CLEAN_INV_CACHES
514 *
515 * Returns 0 on success
516 */
517int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle,
518 void *vaddr, unsigned long len, unsigned int cmd);
519
Jordan Crouse8cd48322011-10-12 17:05:19 -0600520#else
521static inline struct ion_client *ion_client_create(struct ion_device *dev,
522 unsigned int heap_mask, const char *name)
523{
524 return ERR_PTR(-ENODEV);
525}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700526
Jordan Crouse8cd48322011-10-12 17:05:19 -0600527static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
528 const char *name)
529{
530 return ERR_PTR(-ENODEV);
531}
532
533static inline void ion_client_destroy(struct ion_client *client) { }
534
535static inline struct ion_handle *ion_alloc(struct ion_client *client,
536 size_t len, size_t align, unsigned int flags)
537{
538 return ERR_PTR(-ENODEV);
539}
540
541static inline void ion_free(struct ion_client *client,
542 struct ion_handle *handle) { }
543
544
545static inline int ion_phys(struct ion_client *client,
546 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
547{
548 return -ENODEV;
549}
550
551static inline void *ion_map_kernel(struct ion_client *client,
552 struct ion_handle *handle, unsigned long flags)
553{
554 return ERR_PTR(-ENODEV);
555}
556
557static inline void ion_unmap_kernel(struct ion_client *client,
558 struct ion_handle *handle) { }
559
560static inline struct scatterlist *ion_map_dma(struct ion_client *client,
561 struct ion_handle *handle, unsigned long flags)
562{
563 return ERR_PTR(-ENODEV);
564}
565
566static inline void ion_unmap_dma(struct ion_client *client,
567 struct ion_handle *handle) { }
568
569static inline struct ion_buffer *ion_share(struct ion_client *client,
570 struct ion_handle *handle)
571{
572 return ERR_PTR(-ENODEV);
573}
574
575static inline struct ion_handle *ion_import(struct ion_client *client,
576 struct ion_buffer *buffer)
577{
578 return ERR_PTR(-ENODEV);
579}
580
581static inline struct ion_handle *ion_import_fd(struct ion_client *client,
582 int fd)
583{
584 return ERR_PTR(-ENODEV);
585}
586
587static inline int ion_handle_get_flags(struct ion_client *client,
588 struct ion_handle *handle, unsigned long *flags)
589{
590 return -ENODEV;
591}
Laura Abbott8c017362011-09-22 20:59:12 -0700592
593static inline int ion_map_iommu(struct ion_client *client,
594 struct ion_handle *handle, int domain_num,
595 int partition_num, unsigned long align,
596 unsigned long iova_length, unsigned long *iova,
Olav Haugan9a27d4c2012-02-23 09:35:16 -0800597 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800598 unsigned long flags,
599 unsigned long iommu_flags)
Laura Abbott8c017362011-09-22 20:59:12 -0700600{
601 return -ENODEV;
602}
603
604static inline void ion_unmap_iommu(struct ion_client *client,
605 struct ion_handle *handle, int domain_num,
606 int partition_num)
607{
608 return;
609}
610
Olav Haugan0a852512012-01-09 10:20:55 -0800611static inline int ion_secure_heap(struct ion_device *dev, int heap_id)
612{
613 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700614
Olav Haugan0a852512012-01-09 10:20:55 -0800615}
616
617static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id)
618{
619 return -ENODEV;
620}
621
622static inline int msm_ion_secure_heap(int heap_id)
623{
624 return -ENODEV;
625
626}
627
628static inline int msm_ion_unsecure_heap(int heap_id)
629{
630 return -ENODEV;
631}
Olav Haugan41f85792012-02-08 15:28:05 -0800632
633static inline int msm_ion_do_cache_op(struct ion_client *client,
634 struct ion_handle *handle, void *vaddr,
635 unsigned long len, unsigned int cmd)
636{
637 return -ENODEV;
638}
639
Jordan Crouse8cd48322011-10-12 17:05:19 -0600640#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700641#endif /* __KERNEL__ */
642
643/**
644 * DOC: Ion Userspace API
645 *
646 * create a client by opening /dev/ion
647 * most operations handled via following ioctls
648 *
649 */
650
651/**
652 * struct ion_allocation_data - metadata passed from userspace for allocations
653 * @len: size of the allocation
654 * @align: required alignment of the allocation
655 * @flags: flags passed to heap
656 * @handle: pointer that will be populated with a cookie to use to refer
657 * to this allocation
658 *
659 * Provided by userspace as an argument to the ioctl
660 */
661struct ion_allocation_data {
662 size_t len;
663 size_t align;
664 unsigned int flags;
665 struct ion_handle *handle;
666};
667
668/**
669 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
670 * @handle: a handle
671 * @fd: a file descriptor representing that handle
672 *
673 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
674 * the handle returned from ion alloc, and the kernel returns the file
675 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
676 * provides the file descriptor and the kernel returns the handle.
677 */
678struct ion_fd_data {
679 struct ion_handle *handle;
680 int fd;
681};
682
683/**
684 * struct ion_handle_data - a handle passed to/from the kernel
685 * @handle: a handle
686 */
687struct ion_handle_data {
688 struct ion_handle *handle;
689};
690
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700691/**
692 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
693 * @cmd: the custom ioctl function to call
694 * @arg: additional data to pass to the custom ioctl, typically a user
695 * pointer to a predefined structure
696 *
697 * This works just like the regular cmd and arg fields of an ioctl.
698 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700699struct ion_custom_data {
700 unsigned int cmd;
701 unsigned long arg;
702};
703
Laura Abbottabcb6f72011-10-04 16:26:49 -0700704
705/* struct ion_flush_data - data passed to ion for flushing caches
706 *
707 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800708 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700709 * @vaddr: userspace virtual address mapped with mmap
710 * @offset: offset into the handle to flush
711 * @length: length of handle to flush
712 *
713 * Performs cache operations on the handle. If p is the start address
714 * of the handle, p + offset through p + offset + length will have
715 * the cache operations performed
716 */
717struct ion_flush_data {
718 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800719 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700720 void *vaddr;
721 unsigned int offset;
722 unsigned int length;
723};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700724
725/* struct ion_flag_data - information about flags for this buffer
726 *
727 * @handle: handle to get flags from
728 * @flags: flags of this handle
729 *
730 * Takes handle as an input and outputs the flags from the handle
731 * in the flag field.
732 */
733struct ion_flag_data {
734 struct ion_handle *handle;
735 unsigned long flags;
736};
737
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700738#define ION_IOC_MAGIC 'I'
739
740/**
741 * DOC: ION_IOC_ALLOC - allocate memory
742 *
743 * Takes an ion_allocation_data struct and returns it with the handle field
744 * populated with the opaque handle for the allocation.
745 */
746#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
747 struct ion_allocation_data)
748
749/**
750 * DOC: ION_IOC_FREE - free memory
751 *
752 * Takes an ion_handle_data struct and frees the handle.
753 */
754#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
755
756/**
757 * DOC: ION_IOC_MAP - get a file descriptor to mmap
758 *
759 * Takes an ion_fd_data struct with the handle field populated with a valid
760 * opaque handle. Returns the struct with the fd field set to a file
761 * descriptor open in the current address space. This file descriptor
762 * can then be used as an argument to mmap.
763 */
764#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
765
766/**
767 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
768 *
769 * Takes an ion_fd_data struct with the handle field populated with a valid
770 * opaque handle. Returns the struct with the fd field set to a file
771 * descriptor open in the current address space. This file descriptor
772 * can then be passed to another process. The corresponding opaque handle can
773 * be retrieved via ION_IOC_IMPORT.
774 */
775#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
776
777/**
778 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
779 *
780 * Takes an ion_fd_data struct with the fd field populated with a valid file
781 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
782 * filed set to the corresponding opaque handle.
783 */
784#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
785
786/**
787 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
788 *
789 * Takes the argument of the architecture specific ioctl to call and
790 * passes appropriate userdata for that ioctl
791 */
792#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
793
Laura Abbottabcb6f72011-10-04 16:26:49 -0700794
795/**
796 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
797 *
798 * Clean the caches of the handle specified.
799 */
800#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
801 struct ion_flush_data)
802/**
803 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
804 *
805 * Invalidate the caches of the handle specified.
806 */
807#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
808 struct ion_flush_data)
809/**
810 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
811 *
812 * Clean and invalidate the caches of the handle specified.
813 */
814#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
815 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700816
817/**
818 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
819 *
820 * Gets the flags of the current handle which indicate cachability,
821 * secure state etc.
822 */
823#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
824 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700825#endif /* _LINUX_ION_H */