blob: 41f99e40139e72b0bc75499b4064b8f5df4c3bce [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_IOMMU_HEAP_ID = 4,
68 ION_CP_MM_HEAP_ID = 8,
69 ION_CP_MFC_HEAP_ID = 12,
70 ION_CP_WB_HEAP_ID = 16, /* 8660 only */
71 ION_CAMERA_HEAP_ID = 20, /* 8660 only */
72 ION_SF_HEAP_ID = 24,
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 Abbotta2e93632011-08-19 13:36:32 -0700102
Laura Abbott894fd582011-08-19 13:33:56 -0700103#define CACHED 1
104#define UNCACHED 0
105
106#define ION_CACHE_SHIFT 0
107
108#define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT)
109
Laura Abbott35412032011-09-29 09:50:06 -0700110#define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT))
111
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700112#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700113#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700114#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700115struct ion_device;
116struct ion_heap;
117struct ion_mapper;
118struct ion_client;
119struct ion_buffer;
120
121/* This should be removed some day when phys_addr_t's are fully
122 plumbed in the kernel, and all instances of ion_phys_addr_t should
123 be converted to phys_addr_t. For the time being many kernel interfaces
124 do not accept phys_addr_t's that would have to */
125#define ion_phys_addr_t unsigned long
126
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700127/**
128 * struct ion_platform_heap - defines a heap in the given platform
129 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800130 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800131 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700132 * @name: used for debug purposes
133 * @base: base address of heap in physical memory if applicable
134 * @size: size of the heap in bytes if applicable
Olav Haugan0a852512012-01-09 10:20:55 -0800135 * @memory_type: Memory type used for the heap
136 * @ion_memory_id: Memory ID used to identify the memory to TZ
Alex Bird8a3ede32011-11-07 12:33:42 -0800137 * @request_region: function to be called when the number of allocations goes
138 * from 0 -> 1
139 * @release_region: function to be called when the number of allocations goes
140 * from 1 -> 0
141 * @setup_region: function to be called upon ion registration
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700142 *
143 * Provided by the board file.
144 */
145struct ion_platform_heap {
146 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700147 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700148 const char *name;
149 ion_phys_addr_t base;
150 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700151 enum ion_memory_types memory_type;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800152 void *extra_data;
153};
154
155struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800156 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800157 unsigned int align;
158 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
159 size_t secure_size; /* Size used for securing heap when heap is shared*/
Olav Hauganee0f7802011-12-19 13:28:57 -0800160 int (*request_region)(void *);
161 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800162 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700163};
164
Olav Haugan0703dbf2011-12-19 17:53:38 -0800165struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800166 int adjacent_mem_id;
167 unsigned int align;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800168 int (*request_region)(void *);
169 int (*release_region)(void *);
170 void *(*setup_region)(void);
171};
172
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700173/**
174 * struct ion_platform_data - array of platform heaps passed from board file
Alex Bird27ca6612011-11-01 14:40:06 -0700175 * @nr: number of structures in the array
176 * @request_region: function to be called when the number of allocations goes
177 * from 0 -> 1
178 * @release_region: function to be called when the number of allocations goes
179 * from 1 -> 0
180 * @setup_region: function to be called upon ion registration
181 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700182 *
183 * Provided by the board file in the form of platform data to a platform device.
184 */
185struct ion_platform_data {
186 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800187 int (*request_region)(void *);
188 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700189 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700190 struct ion_platform_heap heaps[];
191};
192
Jordan Crouse8cd48322011-10-12 17:05:19 -0600193#ifdef CONFIG_ION
194
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700195/**
196 * ion_client_create() - allocate a client and returns it
197 * @dev: the global ion device
198 * @heap_mask: mask of heaps this client can allocate from
199 * @name: used for debugging
200 */
201struct ion_client *ion_client_create(struct ion_device *dev,
202 unsigned int heap_mask, const char *name);
203
204/**
Laura Abbott302911d2011-08-15 17:12:57 -0700205 * msm_ion_client_create - allocate a client using the ion_device specified in
206 * drivers/gpu/ion/msm/msm_ion.c
207 *
208 * heap_mask and name are the same as ion_client_create, return values
209 * are the same as ion_client_create.
210 */
211
212struct ion_client *msm_ion_client_create(unsigned int heap_mask,
213 const char *name);
214
215/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700216 * ion_client_destroy() - free's a client and all it's handles
217 * @client: the client
218 *
219 * Free the provided client and all it's resources including
220 * any handles it is holding.
221 */
222void ion_client_destroy(struct ion_client *client);
223
224/**
225 * ion_alloc - allocate ion memory
226 * @client: the client
227 * @len: size of the allocation
228 * @align: requested allocation alignment, lots of hardware blocks have
229 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700230 * @flags: mask of heaps to allocate from, if multiple bits are set
231 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700232 *
233 * Allocate memory in one of the heaps provided in heap mask and return
234 * an opaque handle to it.
235 */
236struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
237 size_t align, unsigned int flags);
238
239/**
240 * ion_free - free a handle
241 * @client: the client
242 * @handle: the handle to free
243 *
244 * Free the provided handle.
245 */
246void ion_free(struct ion_client *client, struct ion_handle *handle);
247
248/**
249 * ion_phys - returns the physical address and len of a handle
250 * @client: the client
251 * @handle: the handle
252 * @addr: a pointer to put the address in
253 * @len: a pointer to put the length in
254 *
255 * This function queries the heap for a particular handle to get the
256 * handle's physical address. It't output is only correct if
257 * a heap returns physically contiguous memory -- in other cases
258 * this api should not be implemented -- ion_map_dma should be used
259 * instead. Returns -EINVAL if the handle is invalid. This has
260 * no implications on the reference counting of the handle --
261 * the returned value may not be valid if the caller is not
262 * holding a reference.
263 */
264int ion_phys(struct ion_client *client, struct ion_handle *handle,
265 ion_phys_addr_t *addr, size_t *len);
266
267/**
268 * ion_map_kernel - create mapping for the given handle
269 * @client: the client
270 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700271 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700272 *
273 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700274 * can be used to access this address. If no flags are specified, this
275 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700276 */
Laura Abbott894fd582011-08-19 13:33:56 -0700277void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
278 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700279
280/**
281 * ion_unmap_kernel() - destroy a kernel mapping for a handle
282 * @client: the client
283 * @handle: handle to unmap
284 */
285void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
286
287/**
288 * ion_map_dma - create a dma mapping for a given handle
289 * @client: the client
290 * @handle: handle to map
291 *
292 * Return an sglist describing the given handle
293 */
294struct scatterlist *ion_map_dma(struct ion_client *client,
Laura Abbott894fd582011-08-19 13:33:56 -0700295 struct ion_handle *handle,
296 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700297
298/**
299 * ion_unmap_dma() - destroy a dma mapping for a handle
300 * @client: the client
301 * @handle: handle to unmap
302 */
303void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
304
305/**
306 * ion_share() - given a handle, obtain a buffer to pass to other clients
307 * @client: the client
308 * @handle: the handle to share
309 *
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700310 * Given a handle, return a buffer, which exists in a global name
311 * space, and can be passed to other clients. Should be passed into ion_import
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700312 * to obtain a new handle for this buffer.
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700313 *
314 * NOTE: This function does do not an extra reference. The burden is on the
315 * caller to make sure the buffer doesn't go away while it's being passed to
316 * another client. That is, ion_free should not be called on this handle until
317 * the buffer has been imported into the other client.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700318 */
319struct ion_buffer *ion_share(struct ion_client *client,
320 struct ion_handle *handle);
321
322/**
323 * ion_import() - given an buffer in another client, import it
324 * @client: this blocks client
325 * @buffer: the buffer to import (as obtained from ion_share)
326 *
327 * Given a buffer, add it to the client and return the handle to use to refer
328 * to it further. This is called to share a handle from one kernel client to
329 * another.
330 */
331struct ion_handle *ion_import(struct ion_client *client,
332 struct ion_buffer *buffer);
333
334/**
335 * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
336 * @client: this blocks client
337 * @fd: the fd
338 *
339 * A helper function for drivers that will be recieving ion buffers shared
340 * with them from userspace. These buffers are represented by a file
341 * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
342 * This function coverts that fd into the underlying buffer, and returns
343 * the handle to use to refer to it further.
344 */
345struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700346
Laura Abbott273dd8e2011-10-12 14:26:33 -0700347/**
348 * ion_handle_get_flags - get the flags for a given handle
349 *
350 * @client - client who allocated the handle
351 * @handle - handle to get the flags
352 * @flags - pointer to store the flags
353 *
354 * Gets the current flags for a handle. These flags indicate various options
355 * of the buffer (caching, security, etc.)
356 */
357int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
358 unsigned long *flags);
359
Laura Abbott8c017362011-09-22 20:59:12 -0700360
361/**
362 * ion_map_iommu - map the given handle into an iommu
363 *
364 * @client - client who allocated the handle
365 * @handle - handle to map
366 * @domain_num - domain number to map to
367 * @partition_num - partition number to allocate iova from
368 * @align - alignment for the iova
369 * @iova_length - length of iova to map. If the iova length is
370 * greater than the handle length, the remaining
371 * address space will be mapped to a dummy buffer.
372 * @iova - pointer to store the iova address
373 * @buffer_size - pointer to store the size of the buffer
374 * @flags - flags for options to map
375 *
376 * Maps the handle into the iova space specified via domain number. Iova
377 * will be allocated from the partition specified via partition_num.
378 * Returns 0 on success, negative value on error.
379 */
380int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
381 int domain_num, int partition_num, unsigned long align,
382 unsigned long iova_length, unsigned long *iova,
383 unsigned long *buffer_size,
384 unsigned long flags);
385
386
387/**
388 * ion_handle_get_size - get the allocated size of a given handle
389 *
390 * @client - client who allocated the handle
391 * @handle - handle to get the size
392 * @size - pointer to store the size
393 *
394 * gives the allocated size of a handle. returns 0 on success, negative
395 * value on error
396 *
397 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
398 * You should *NOT* rely on this for any other usage.
399 */
400
401int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
402 unsigned long *size);
403
404/**
405 * ion_unmap_iommu - unmap the handle from an iommu
406 *
407 * @client - client who allocated the handle
408 * @handle - handle to unmap
409 * @domain_num - domain to unmap from
410 * @partition_num - partition to unmap from
411 *
412 * Decrement the reference count on the iommu mapping. If the count is
413 * 0, the mapping will be removed from the iommu.
414 */
415void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
416 int domain_num, int partition_num);
417
418
Olav Haugan0a852512012-01-09 10:20:55 -0800419/**
420 * ion_secure_heap - secure a heap
421 *
422 * @client - a client that has allocated from the heap heap_id
423 * @heap_id - heap id to secure.
424 *
425 * Secure a heap
426 * Returns 0 on success
427 */
428int ion_secure_heap(struct ion_device *dev, int heap_id);
429
430/**
431 * ion_unsecure_heap - un-secure a heap
432 *
433 * @client - a client that has allocated from the heap heap_id
434 * @heap_id - heap id to un-secure.
435 *
436 * Un-secure a heap
437 * Returns 0 on success
438 */
439int ion_unsecure_heap(struct ion_device *dev, int heap_id);
440
441/**
442 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
443 *
444 * @heap_id - heap id to secure.
445 *
446 * Secure a heap
447 * Returns 0 on success
448 */
449int msm_ion_secure_heap(int heap_id);
450
451/**
452 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
453 *
454 * @heap_id - heap id to secure.
455 *
456 * Un-secure a heap
457 * Returns 0 on success
458 */
459int msm_ion_unsecure_heap(int heap_id);
460
Jordan Crouse8cd48322011-10-12 17:05:19 -0600461#else
462static inline struct ion_client *ion_client_create(struct ion_device *dev,
463 unsigned int heap_mask, const char *name)
464{
465 return ERR_PTR(-ENODEV);
466}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700467
Jordan Crouse8cd48322011-10-12 17:05:19 -0600468static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
469 const char *name)
470{
471 return ERR_PTR(-ENODEV);
472}
473
474static inline void ion_client_destroy(struct ion_client *client) { }
475
476static inline struct ion_handle *ion_alloc(struct ion_client *client,
477 size_t len, size_t align, unsigned int flags)
478{
479 return ERR_PTR(-ENODEV);
480}
481
482static inline void ion_free(struct ion_client *client,
483 struct ion_handle *handle) { }
484
485
486static inline int ion_phys(struct ion_client *client,
487 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
488{
489 return -ENODEV;
490}
491
492static inline void *ion_map_kernel(struct ion_client *client,
493 struct ion_handle *handle, unsigned long flags)
494{
495 return ERR_PTR(-ENODEV);
496}
497
498static inline void ion_unmap_kernel(struct ion_client *client,
499 struct ion_handle *handle) { }
500
501static inline struct scatterlist *ion_map_dma(struct ion_client *client,
502 struct ion_handle *handle, unsigned long flags)
503{
504 return ERR_PTR(-ENODEV);
505}
506
507static inline void ion_unmap_dma(struct ion_client *client,
508 struct ion_handle *handle) { }
509
510static inline struct ion_buffer *ion_share(struct ion_client *client,
511 struct ion_handle *handle)
512{
513 return ERR_PTR(-ENODEV);
514}
515
516static inline struct ion_handle *ion_import(struct ion_client *client,
517 struct ion_buffer *buffer)
518{
519 return ERR_PTR(-ENODEV);
520}
521
522static inline struct ion_handle *ion_import_fd(struct ion_client *client,
523 int fd)
524{
525 return ERR_PTR(-ENODEV);
526}
527
528static inline int ion_handle_get_flags(struct ion_client *client,
529 struct ion_handle *handle, unsigned long *flags)
530{
531 return -ENODEV;
532}
Laura Abbott8c017362011-09-22 20:59:12 -0700533
534static inline int ion_map_iommu(struct ion_client *client,
535 struct ion_handle *handle, int domain_num,
536 int partition_num, unsigned long align,
537 unsigned long iova_length, unsigned long *iova,
538 unsigned long flags)
539{
540 return -ENODEV;
541}
542
543static inline void ion_unmap_iommu(struct ion_client *client,
544 struct ion_handle *handle, int domain_num,
545 int partition_num)
546{
547 return;
548}
549
Olav Haugan0a852512012-01-09 10:20:55 -0800550static inline int ion_secure_heap(struct ion_device *dev, int heap_id)
551{
552 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700553
Olav Haugan0a852512012-01-09 10:20:55 -0800554}
555
556static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id)
557{
558 return -ENODEV;
559}
560
561static inline int msm_ion_secure_heap(int heap_id)
562{
563 return -ENODEV;
564
565}
566
567static inline int msm_ion_unsecure_heap(int heap_id)
568{
569 return -ENODEV;
570}
Jordan Crouse8cd48322011-10-12 17:05:19 -0600571#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700572#endif /* __KERNEL__ */
573
574/**
575 * DOC: Ion Userspace API
576 *
577 * create a client by opening /dev/ion
578 * most operations handled via following ioctls
579 *
580 */
581
582/**
583 * struct ion_allocation_data - metadata passed from userspace for allocations
584 * @len: size of the allocation
585 * @align: required alignment of the allocation
586 * @flags: flags passed to heap
587 * @handle: pointer that will be populated with a cookie to use to refer
588 * to this allocation
589 *
590 * Provided by userspace as an argument to the ioctl
591 */
592struct ion_allocation_data {
593 size_t len;
594 size_t align;
595 unsigned int flags;
596 struct ion_handle *handle;
597};
598
599/**
600 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
601 * @handle: a handle
602 * @fd: a file descriptor representing that handle
603 *
604 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
605 * the handle returned from ion alloc, and the kernel returns the file
606 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
607 * provides the file descriptor and the kernel returns the handle.
608 */
609struct ion_fd_data {
610 struct ion_handle *handle;
611 int fd;
612};
613
614/**
615 * struct ion_handle_data - a handle passed to/from the kernel
616 * @handle: a handle
617 */
618struct ion_handle_data {
619 struct ion_handle *handle;
620};
621
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700622/**
623 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
624 * @cmd: the custom ioctl function to call
625 * @arg: additional data to pass to the custom ioctl, typically a user
626 * pointer to a predefined structure
627 *
628 * This works just like the regular cmd and arg fields of an ioctl.
629 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700630struct ion_custom_data {
631 unsigned int cmd;
632 unsigned long arg;
633};
634
Laura Abbottabcb6f72011-10-04 16:26:49 -0700635
636/* struct ion_flush_data - data passed to ion for flushing caches
637 *
638 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800639 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700640 * @vaddr: userspace virtual address mapped with mmap
641 * @offset: offset into the handle to flush
642 * @length: length of handle to flush
643 *
644 * Performs cache operations on the handle. If p is the start address
645 * of the handle, p + offset through p + offset + length will have
646 * the cache operations performed
647 */
648struct ion_flush_data {
649 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800650 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700651 void *vaddr;
652 unsigned int offset;
653 unsigned int length;
654};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700655
656/* struct ion_flag_data - information about flags for this buffer
657 *
658 * @handle: handle to get flags from
659 * @flags: flags of this handle
660 *
661 * Takes handle as an input and outputs the flags from the handle
662 * in the flag field.
663 */
664struct ion_flag_data {
665 struct ion_handle *handle;
666 unsigned long flags;
667};
668
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700669#define ION_IOC_MAGIC 'I'
670
671/**
672 * DOC: ION_IOC_ALLOC - allocate memory
673 *
674 * Takes an ion_allocation_data struct and returns it with the handle field
675 * populated with the opaque handle for the allocation.
676 */
677#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
678 struct ion_allocation_data)
679
680/**
681 * DOC: ION_IOC_FREE - free memory
682 *
683 * Takes an ion_handle_data struct and frees the handle.
684 */
685#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
686
687/**
688 * DOC: ION_IOC_MAP - get a file descriptor to mmap
689 *
690 * Takes an ion_fd_data struct with the handle field populated with a valid
691 * opaque handle. Returns the struct with the fd field set to a file
692 * descriptor open in the current address space. This file descriptor
693 * can then be used as an argument to mmap.
694 */
695#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
696
697/**
698 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
699 *
700 * Takes an ion_fd_data struct with the handle field populated with a valid
701 * opaque handle. Returns the struct with the fd field set to a file
702 * descriptor open in the current address space. This file descriptor
703 * can then be passed to another process. The corresponding opaque handle can
704 * be retrieved via ION_IOC_IMPORT.
705 */
706#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
707
708/**
709 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
710 *
711 * Takes an ion_fd_data struct with the fd field populated with a valid file
712 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
713 * filed set to the corresponding opaque handle.
714 */
715#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
716
717/**
718 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
719 *
720 * Takes the argument of the architecture specific ioctl to call and
721 * passes appropriate userdata for that ioctl
722 */
723#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
724
Laura Abbottabcb6f72011-10-04 16:26:49 -0700725
726/**
727 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
728 *
729 * Clean the caches of the handle specified.
730 */
731#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
732 struct ion_flush_data)
733/**
734 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
735 *
736 * Invalidate the caches of the handle specified.
737 */
738#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
739 struct ion_flush_data)
740/**
741 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
742 *
743 * Clean and invalidate the caches of the handle specified.
744 */
745#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
746 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700747
748/**
749 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
750 *
751 * Gets the flags of the current handle which indicate cachability,
752 * secure state etc.
753 */
754#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
755 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700756#endif /* _LINUX_ION_H */