blob: f46d4784ed2af156f3dafd22fa54fc378d02871b [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,
73 ION_AUDIO_HEAP_ID = 28,
74
Olav Haugan42ebe712012-01-10 16:30:58 -080075 ION_MM_FIRMWARE_HEAP_ID = 29,
Olav Hauganb5be7992011-11-18 14:29:02 -080076 ION_SYSTEM_HEAP_ID = 30,
77
78 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
Laura Abbotta2e93632011-08-19 13:36:32 -070079};
80
Olav Hauganb5be7992011-11-18 14:29:02 -080081/**
82 * Flag to use when allocating to indicate that a heap is secure.
83 */
84#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
85
86/**
87 * Macro should be used with ion_heap_ids defined above.
88 */
89#define ION_HEAP(bit) (1 << (bit))
90
Laura Abbotta2e93632011-08-19 13:36:32 -070091#define ION_VMALLOC_HEAP_NAME "vmalloc"
Olav Hauganb5be7992011-11-18 14:29:02 -080092#define ION_AUDIO_HEAP_NAME "audio"
93#define ION_SF_HEAP_NAME "sf"
94#define ION_MM_HEAP_NAME "mm"
95#define ION_CAMERA_HEAP_NAME "camera_preview"
Laura Abbott8c017362011-09-22 20:59:12 -070096#define ION_IOMMU_HEAP_NAME "iommu"
Olav Hauganb5be7992011-11-18 14:29:02 -080097#define ION_MFC_HEAP_NAME "mfc"
98#define ION_WB_HEAP_NAME "wb"
Olav Haugan42ebe712012-01-10 16:30:58 -080099#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Laura Abbotta2e93632011-08-19 13:36:32 -0700100
Laura Abbott894fd582011-08-19 13:33:56 -0700101#define CACHED 1
102#define UNCACHED 0
103
104#define ION_CACHE_SHIFT 0
105
106#define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT)
107
Laura Abbott35412032011-09-29 09:50:06 -0700108#define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT))
109
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700110#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700111#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700112#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700113struct ion_device;
114struct ion_heap;
115struct ion_mapper;
116struct ion_client;
117struct ion_buffer;
118
119/* This should be removed some day when phys_addr_t's are fully
120 plumbed in the kernel, and all instances of ion_phys_addr_t should
121 be converted to phys_addr_t. For the time being many kernel interfaces
122 do not accept phys_addr_t's that would have to */
123#define ion_phys_addr_t unsigned long
124
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700125/**
126 * struct ion_platform_heap - defines a heap in the given platform
127 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800128 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800129 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700130 * @name: used for debug purposes
131 * @base: base address of heap in physical memory if applicable
132 * @size: size of the heap in bytes if applicable
Olav Haugan0a852512012-01-09 10:20:55 -0800133 * @memory_type: Memory type used for the heap
134 * @ion_memory_id: Memory ID used to identify the memory to TZ
Alex Bird8a3ede32011-11-07 12:33:42 -0800135 * @request_region: function to be called when the number of allocations goes
136 * from 0 -> 1
137 * @release_region: function to be called when the number of allocations goes
138 * from 1 -> 0
139 * @setup_region: function to be called upon ion registration
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700140 *
141 * Provided by the board file.
142 */
143struct ion_platform_heap {
144 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700145 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700146 const char *name;
147 ion_phys_addr_t base;
148 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700149 enum ion_memory_types memory_type;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800150 void *extra_data;
151};
152
153struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800154 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800155 unsigned int align;
156 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
157 size_t secure_size; /* Size used for securing heap when heap is shared*/
Olav Hauganee0f7802011-12-19 13:28:57 -0800158 int (*request_region)(void *);
159 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800160 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700161};
162
Olav Haugan0703dbf2011-12-19 17:53:38 -0800163struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800164 int adjacent_mem_id;
165 unsigned int align;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800166 int (*request_region)(void *);
167 int (*release_region)(void *);
168 void *(*setup_region)(void);
169};
170
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700171/**
172 * struct ion_platform_data - array of platform heaps passed from board file
Alex Bird27ca6612011-11-01 14:40:06 -0700173 * @nr: number of structures in the array
174 * @request_region: function to be called when the number of allocations goes
175 * from 0 -> 1
176 * @release_region: function to be called when the number of allocations goes
177 * from 1 -> 0
178 * @setup_region: function to be called upon ion registration
179 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700180 *
181 * Provided by the board file in the form of platform data to a platform device.
182 */
183struct ion_platform_data {
184 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800185 int (*request_region)(void *);
186 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700187 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700188 struct ion_platform_heap heaps[];
189};
190
Jordan Crouse8cd48322011-10-12 17:05:19 -0600191#ifdef CONFIG_ION
192
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700193/**
194 * ion_client_create() - allocate a client and returns it
195 * @dev: the global ion device
196 * @heap_mask: mask of heaps this client can allocate from
197 * @name: used for debugging
198 */
199struct ion_client *ion_client_create(struct ion_device *dev,
200 unsigned int heap_mask, const char *name);
201
202/**
Laura Abbott302911d2011-08-15 17:12:57 -0700203 * msm_ion_client_create - allocate a client using the ion_device specified in
204 * drivers/gpu/ion/msm/msm_ion.c
205 *
206 * heap_mask and name are the same as ion_client_create, return values
207 * are the same as ion_client_create.
208 */
209
210struct ion_client *msm_ion_client_create(unsigned int heap_mask,
211 const char *name);
212
213/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700214 * ion_client_destroy() - free's a client and all it's handles
215 * @client: the client
216 *
217 * Free the provided client and all it's resources including
218 * any handles it is holding.
219 */
220void ion_client_destroy(struct ion_client *client);
221
222/**
223 * ion_alloc - allocate ion memory
224 * @client: the client
225 * @len: size of the allocation
226 * @align: requested allocation alignment, lots of hardware blocks have
227 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700228 * @flags: mask of heaps to allocate from, if multiple bits are set
229 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700230 *
231 * Allocate memory in one of the heaps provided in heap mask and return
232 * an opaque handle to it.
233 */
234struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
235 size_t align, unsigned int flags);
236
237/**
238 * ion_free - free a handle
239 * @client: the client
240 * @handle: the handle to free
241 *
242 * Free the provided handle.
243 */
244void ion_free(struct ion_client *client, struct ion_handle *handle);
245
246/**
247 * ion_phys - returns the physical address and len of a handle
248 * @client: the client
249 * @handle: the handle
250 * @addr: a pointer to put the address in
251 * @len: a pointer to put the length in
252 *
253 * This function queries the heap for a particular handle to get the
254 * handle's physical address. It't output is only correct if
255 * a heap returns physically contiguous memory -- in other cases
256 * this api should not be implemented -- ion_map_dma should be used
257 * instead. Returns -EINVAL if the handle is invalid. This has
258 * no implications on the reference counting of the handle --
259 * the returned value may not be valid if the caller is not
260 * holding a reference.
261 */
262int ion_phys(struct ion_client *client, struct ion_handle *handle,
263 ion_phys_addr_t *addr, size_t *len);
264
265/**
266 * ion_map_kernel - create mapping for the given handle
267 * @client: the client
268 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700269 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700270 *
271 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700272 * can be used to access this address. If no flags are specified, this
273 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700274 */
Laura Abbott894fd582011-08-19 13:33:56 -0700275void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
276 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700277
278/**
279 * ion_unmap_kernel() - destroy a kernel mapping for a handle
280 * @client: the client
281 * @handle: handle to unmap
282 */
283void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
284
285/**
286 * ion_map_dma - create a dma mapping for a given handle
287 * @client: the client
288 * @handle: handle to map
289 *
290 * Return an sglist describing the given handle
291 */
292struct scatterlist *ion_map_dma(struct ion_client *client,
Laura Abbott894fd582011-08-19 13:33:56 -0700293 struct ion_handle *handle,
294 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700295
296/**
297 * ion_unmap_dma() - destroy a dma mapping for a handle
298 * @client: the client
299 * @handle: handle to unmap
300 */
301void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
302
303/**
304 * ion_share() - given a handle, obtain a buffer to pass to other clients
305 * @client: the client
306 * @handle: the handle to share
307 *
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700308 * Given a handle, return a buffer, which exists in a global name
309 * space, and can be passed to other clients. Should be passed into ion_import
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700310 * to obtain a new handle for this buffer.
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700311 *
312 * NOTE: This function does do not an extra reference. The burden is on the
313 * caller to make sure the buffer doesn't go away while it's being passed to
314 * another client. That is, ion_free should not be called on this handle until
315 * the buffer has been imported into the other client.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700316 */
317struct ion_buffer *ion_share(struct ion_client *client,
318 struct ion_handle *handle);
319
320/**
321 * ion_import() - given an buffer in another client, import it
322 * @client: this blocks client
323 * @buffer: the buffer to import (as obtained from ion_share)
324 *
325 * Given a buffer, add it to the client and return the handle to use to refer
326 * to it further. This is called to share a handle from one kernel client to
327 * another.
328 */
329struct ion_handle *ion_import(struct ion_client *client,
330 struct ion_buffer *buffer);
331
332/**
333 * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
334 * @client: this blocks client
335 * @fd: the fd
336 *
337 * A helper function for drivers that will be recieving ion buffers shared
338 * with them from userspace. These buffers are represented by a file
339 * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
340 * This function coverts that fd into the underlying buffer, and returns
341 * the handle to use to refer to it further.
342 */
343struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700344
Laura Abbott273dd8e2011-10-12 14:26:33 -0700345/**
346 * ion_handle_get_flags - get the flags for a given handle
347 *
348 * @client - client who allocated the handle
349 * @handle - handle to get the flags
350 * @flags - pointer to store the flags
351 *
352 * Gets the current flags for a handle. These flags indicate various options
353 * of the buffer (caching, security, etc.)
354 */
355int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
356 unsigned long *flags);
357
Laura Abbott8c017362011-09-22 20:59:12 -0700358
359/**
360 * ion_map_iommu - map the given handle into an iommu
361 *
362 * @client - client who allocated the handle
363 * @handle - handle to map
364 * @domain_num - domain number to map to
365 * @partition_num - partition number to allocate iova from
366 * @align - alignment for the iova
367 * @iova_length - length of iova to map. If the iova length is
368 * greater than the handle length, the remaining
369 * address space will be mapped to a dummy buffer.
370 * @iova - pointer to store the iova address
371 * @buffer_size - pointer to store the size of the buffer
372 * @flags - flags for options to map
373 *
374 * Maps the handle into the iova space specified via domain number. Iova
375 * will be allocated from the partition specified via partition_num.
376 * Returns 0 on success, negative value on error.
377 */
378int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
379 int domain_num, int partition_num, unsigned long align,
380 unsigned long iova_length, unsigned long *iova,
381 unsigned long *buffer_size,
382 unsigned long flags);
383
384
385/**
386 * ion_handle_get_size - get the allocated size of a given handle
387 *
388 * @client - client who allocated the handle
389 * @handle - handle to get the size
390 * @size - pointer to store the size
391 *
392 * gives the allocated size of a handle. returns 0 on success, negative
393 * value on error
394 *
395 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
396 * You should *NOT* rely on this for any other usage.
397 */
398
399int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
400 unsigned long *size);
401
402/**
403 * ion_unmap_iommu - unmap the handle from an iommu
404 *
405 * @client - client who allocated the handle
406 * @handle - handle to unmap
407 * @domain_num - domain to unmap from
408 * @partition_num - partition to unmap from
409 *
410 * Decrement the reference count on the iommu mapping. If the count is
411 * 0, the mapping will be removed from the iommu.
412 */
413void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
414 int domain_num, int partition_num);
415
416
Olav Haugan0a852512012-01-09 10:20:55 -0800417/**
418 * ion_secure_heap - secure a heap
419 *
420 * @client - a client that has allocated from the heap heap_id
421 * @heap_id - heap id to secure.
422 *
423 * Secure a heap
424 * Returns 0 on success
425 */
426int ion_secure_heap(struct ion_device *dev, int heap_id);
427
428/**
429 * ion_unsecure_heap - un-secure a heap
430 *
431 * @client - a client that has allocated from the heap heap_id
432 * @heap_id - heap id to un-secure.
433 *
434 * Un-secure a heap
435 * Returns 0 on success
436 */
437int ion_unsecure_heap(struct ion_device *dev, int heap_id);
438
439/**
440 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
441 *
442 * @heap_id - heap id to secure.
443 *
444 * Secure a heap
445 * Returns 0 on success
446 */
447int msm_ion_secure_heap(int heap_id);
448
449/**
450 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
451 *
452 * @heap_id - heap id to secure.
453 *
454 * Un-secure a heap
455 * Returns 0 on success
456 */
457int msm_ion_unsecure_heap(int heap_id);
458
Jordan Crouse8cd48322011-10-12 17:05:19 -0600459#else
460static inline struct ion_client *ion_client_create(struct ion_device *dev,
461 unsigned int heap_mask, const char *name)
462{
463 return ERR_PTR(-ENODEV);
464}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700465
Jordan Crouse8cd48322011-10-12 17:05:19 -0600466static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
467 const char *name)
468{
469 return ERR_PTR(-ENODEV);
470}
471
472static inline void ion_client_destroy(struct ion_client *client) { }
473
474static inline struct ion_handle *ion_alloc(struct ion_client *client,
475 size_t len, size_t align, unsigned int flags)
476{
477 return ERR_PTR(-ENODEV);
478}
479
480static inline void ion_free(struct ion_client *client,
481 struct ion_handle *handle) { }
482
483
484static inline int ion_phys(struct ion_client *client,
485 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
486{
487 return -ENODEV;
488}
489
490static inline void *ion_map_kernel(struct ion_client *client,
491 struct ion_handle *handle, unsigned long flags)
492{
493 return ERR_PTR(-ENODEV);
494}
495
496static inline void ion_unmap_kernel(struct ion_client *client,
497 struct ion_handle *handle) { }
498
499static inline struct scatterlist *ion_map_dma(struct ion_client *client,
500 struct ion_handle *handle, unsigned long flags)
501{
502 return ERR_PTR(-ENODEV);
503}
504
505static inline void ion_unmap_dma(struct ion_client *client,
506 struct ion_handle *handle) { }
507
508static inline struct ion_buffer *ion_share(struct ion_client *client,
509 struct ion_handle *handle)
510{
511 return ERR_PTR(-ENODEV);
512}
513
514static inline struct ion_handle *ion_import(struct ion_client *client,
515 struct ion_buffer *buffer)
516{
517 return ERR_PTR(-ENODEV);
518}
519
520static inline struct ion_handle *ion_import_fd(struct ion_client *client,
521 int fd)
522{
523 return ERR_PTR(-ENODEV);
524}
525
526static inline int ion_handle_get_flags(struct ion_client *client,
527 struct ion_handle *handle, unsigned long *flags)
528{
529 return -ENODEV;
530}
Laura Abbott8c017362011-09-22 20:59:12 -0700531
532static inline int ion_map_iommu(struct ion_client *client,
533 struct ion_handle *handle, int domain_num,
534 int partition_num, unsigned long align,
535 unsigned long iova_length, unsigned long *iova,
536 unsigned long flags)
537{
538 return -ENODEV;
539}
540
541static inline void ion_unmap_iommu(struct ion_client *client,
542 struct ion_handle *handle, int domain_num,
543 int partition_num)
544{
545 return;
546}
547
Olav Haugan0a852512012-01-09 10:20:55 -0800548static inline int ion_secure_heap(struct ion_device *dev, int heap_id)
549{
550 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700551
Olav Haugan0a852512012-01-09 10:20:55 -0800552}
553
554static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id)
555{
556 return -ENODEV;
557}
558
559static inline int msm_ion_secure_heap(int heap_id)
560{
561 return -ENODEV;
562
563}
564
565static inline int msm_ion_unsecure_heap(int heap_id)
566{
567 return -ENODEV;
568}
Jordan Crouse8cd48322011-10-12 17:05:19 -0600569#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700570#endif /* __KERNEL__ */
571
572/**
573 * DOC: Ion Userspace API
574 *
575 * create a client by opening /dev/ion
576 * most operations handled via following ioctls
577 *
578 */
579
580/**
581 * struct ion_allocation_data - metadata passed from userspace for allocations
582 * @len: size of the allocation
583 * @align: required alignment of the allocation
584 * @flags: flags passed to heap
585 * @handle: pointer that will be populated with a cookie to use to refer
586 * to this allocation
587 *
588 * Provided by userspace as an argument to the ioctl
589 */
590struct ion_allocation_data {
591 size_t len;
592 size_t align;
593 unsigned int flags;
594 struct ion_handle *handle;
595};
596
597/**
598 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
599 * @handle: a handle
600 * @fd: a file descriptor representing that handle
601 *
602 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
603 * the handle returned from ion alloc, and the kernel returns the file
604 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
605 * provides the file descriptor and the kernel returns the handle.
606 */
607struct ion_fd_data {
608 struct ion_handle *handle;
609 int fd;
610};
611
612/**
613 * struct ion_handle_data - a handle passed to/from the kernel
614 * @handle: a handle
615 */
616struct ion_handle_data {
617 struct ion_handle *handle;
618};
619
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700620/**
621 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
622 * @cmd: the custom ioctl function to call
623 * @arg: additional data to pass to the custom ioctl, typically a user
624 * pointer to a predefined structure
625 *
626 * This works just like the regular cmd and arg fields of an ioctl.
627 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700628struct ion_custom_data {
629 unsigned int cmd;
630 unsigned long arg;
631};
632
Laura Abbottabcb6f72011-10-04 16:26:49 -0700633
634/* struct ion_flush_data - data passed to ion for flushing caches
635 *
636 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800637 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700638 * @vaddr: userspace virtual address mapped with mmap
639 * @offset: offset into the handle to flush
640 * @length: length of handle to flush
641 *
642 * Performs cache operations on the handle. If p is the start address
643 * of the handle, p + offset through p + offset + length will have
644 * the cache operations performed
645 */
646struct ion_flush_data {
647 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800648 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700649 void *vaddr;
650 unsigned int offset;
651 unsigned int length;
652};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700653
654/* struct ion_flag_data - information about flags for this buffer
655 *
656 * @handle: handle to get flags from
657 * @flags: flags of this handle
658 *
659 * Takes handle as an input and outputs the flags from the handle
660 * in the flag field.
661 */
662struct ion_flag_data {
663 struct ion_handle *handle;
664 unsigned long flags;
665};
666
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700667#define ION_IOC_MAGIC 'I'
668
669/**
670 * DOC: ION_IOC_ALLOC - allocate memory
671 *
672 * Takes an ion_allocation_data struct and returns it with the handle field
673 * populated with the opaque handle for the allocation.
674 */
675#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
676 struct ion_allocation_data)
677
678/**
679 * DOC: ION_IOC_FREE - free memory
680 *
681 * Takes an ion_handle_data struct and frees the handle.
682 */
683#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
684
685/**
686 * DOC: ION_IOC_MAP - get a file descriptor to mmap
687 *
688 * Takes an ion_fd_data struct with the handle field populated with a valid
689 * opaque handle. Returns the struct with the fd field set to a file
690 * descriptor open in the current address space. This file descriptor
691 * can then be used as an argument to mmap.
692 */
693#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
694
695/**
696 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
697 *
698 * Takes an ion_fd_data struct with the handle field populated with a valid
699 * opaque handle. Returns the struct with the fd field set to a file
700 * descriptor open in the current address space. This file descriptor
701 * can then be passed to another process. The corresponding opaque handle can
702 * be retrieved via ION_IOC_IMPORT.
703 */
704#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
705
706/**
707 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
708 *
709 * Takes an ion_fd_data struct with the fd field populated with a valid file
710 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
711 * filed set to the corresponding opaque handle.
712 */
713#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
714
715/**
716 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
717 *
718 * Takes the argument of the architecture specific ioctl to call and
719 * passes appropriate userdata for that ioctl
720 */
721#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
722
Laura Abbottabcb6f72011-10-04 16:26:49 -0700723
724/**
725 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
726 *
727 * Clean the caches of the handle specified.
728 */
729#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
730 struct ion_flush_data)
731/**
732 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
733 *
734 * Invalidate the caches of the handle specified.
735 */
736#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
737 struct ion_flush_data)
738/**
739 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
740 *
741 * Clean and invalidate the caches of the handle specified.
742 */
743#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
744 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700745
746/**
747 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
748 *
749 * Gets the flags of the current handle which indicate cachability,
750 * secure state etc.
751 */
752#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
753 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700754#endif /* _LINUX_ION_H */