blob: 2aa3bd95e4d7f08b7e3f5c5a398452199f48cae4 [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
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700113#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700114#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700115#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700116struct ion_device;
117struct ion_heap;
118struct ion_mapper;
119struct ion_client;
120struct ion_buffer;
121
122/* This should be removed some day when phys_addr_t's are fully
123 plumbed in the kernel, and all instances of ion_phys_addr_t should
124 be converted to phys_addr_t. For the time being many kernel interfaces
125 do not accept phys_addr_t's that would have to */
126#define ion_phys_addr_t unsigned long
Laura Abbottcaafeea2011-12-13 11:43:10 -0800127#define ion_virt_addr_t unsigned long
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700128
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700129/**
130 * struct ion_platform_heap - defines a heap in the given platform
131 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800132 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800133 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700134 * @name: used for debug purposes
135 * @base: base address of heap in physical memory if applicable
136 * @size: size of the heap in bytes if applicable
Laura Abbottcaafeea2011-12-13 11:43:10 -0800137 * @memory_type:Memory type used for the heap
138 * @extra_data: Extra data specific to each heap type
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700139 */
140struct ion_platform_heap {
141 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700142 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700143 const char *name;
144 ion_phys_addr_t base;
145 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700146 enum ion_memory_types memory_type;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800147 void *extra_data;
148};
149
Laura Abbottcaafeea2011-12-13 11:43:10 -0800150/**
151 * struct ion_cp_heap_pdata - defines a content protection heap in the given
152 * platform
153 * @permission_type: Memory ID used to identify the memory to TZ
154 * @align: Alignment requirement for the memory
155 * @secure_base: Base address for securing the heap.
156 * Note: This might be different from actual base address
157 * of this heap in the case of a shared heap.
158 * @secure_size: Memory size for securing the heap.
159 * Note: This might be different from actual size
160 * of this heap in the case of a shared heap.
161 * @reusable Flag indicating whether this heap is reusable of not.
162 * (see FMEM)
163 * @virt_addr: Virtual address used when using fmem.
164 * @request_region: function to be called when the number of allocations
165 * goes from 0 -> 1
166 * @release_region: function to be called when the number of allocations
167 * goes from 1 -> 0
168 * @setup_region: function to be called upon ion registration
169 *
170 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800171struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800172 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800173 unsigned int align;
174 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
175 size_t secure_size; /* Size used for securing heap when heap is shared*/
Laura Abbottcaafeea2011-12-13 11:43:10 -0800176 int reusable;
177 ion_virt_addr_t *virt_addr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800178 int (*request_region)(void *);
179 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800180 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700181};
182
Laura Abbottcaafeea2011-12-13 11:43:10 -0800183/**
184 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
185 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
186 * @align: Alignment requirement for the memory
187 * @request_region: function to be called when the number of allocations
188 * goes from 0 -> 1
189 * @release_region: function to be called when the number of allocations
190 * goes from 1 -> 0
191 * @setup_region: function to be called upon ion registration
192 *
193 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800194struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800195 int adjacent_mem_id;
196 unsigned int align;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800197 int (*request_region)(void *);
198 int (*release_region)(void *);
199 void *(*setup_region)(void);
200};
201
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700202/**
203 * struct ion_platform_data - array of platform heaps passed from board file
Alex Bird27ca6612011-11-01 14:40:06 -0700204 * @nr: number of structures in the array
205 * @request_region: function to be called when the number of allocations goes
206 * from 0 -> 1
207 * @release_region: function to be called when the number of allocations goes
208 * from 1 -> 0
209 * @setup_region: function to be called upon ion registration
210 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700211 *
212 * Provided by the board file in the form of platform data to a platform device.
213 */
214struct ion_platform_data {
215 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800216 int (*request_region)(void *);
217 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700218 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700219 struct ion_platform_heap heaps[];
220};
221
Jordan Crouse8cd48322011-10-12 17:05:19 -0600222#ifdef CONFIG_ION
223
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700224/**
225 * ion_client_create() - allocate a client and returns it
226 * @dev: the global ion device
227 * @heap_mask: mask of heaps this client can allocate from
228 * @name: used for debugging
229 */
230struct ion_client *ion_client_create(struct ion_device *dev,
231 unsigned int heap_mask, const char *name);
232
233/**
Laura Abbott302911d2011-08-15 17:12:57 -0700234 * msm_ion_client_create - allocate a client using the ion_device specified in
235 * drivers/gpu/ion/msm/msm_ion.c
236 *
237 * heap_mask and name are the same as ion_client_create, return values
238 * are the same as ion_client_create.
239 */
240
241struct ion_client *msm_ion_client_create(unsigned int heap_mask,
242 const char *name);
243
244/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700245 * ion_client_destroy() - free's a client and all it's handles
246 * @client: the client
247 *
248 * Free the provided client and all it's resources including
249 * any handles it is holding.
250 */
251void ion_client_destroy(struct ion_client *client);
252
253/**
254 * ion_alloc - allocate ion memory
255 * @client: the client
256 * @len: size of the allocation
257 * @align: requested allocation alignment, lots of hardware blocks have
258 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700259 * @flags: mask of heaps to allocate from, if multiple bits are set
260 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700261 *
262 * Allocate memory in one of the heaps provided in heap mask and return
263 * an opaque handle to it.
264 */
265struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
266 size_t align, unsigned int flags);
267
268/**
269 * ion_free - free a handle
270 * @client: the client
271 * @handle: the handle to free
272 *
273 * Free the provided handle.
274 */
275void ion_free(struct ion_client *client, struct ion_handle *handle);
276
277/**
278 * ion_phys - returns the physical address and len of a handle
279 * @client: the client
280 * @handle: the handle
281 * @addr: a pointer to put the address in
282 * @len: a pointer to put the length in
283 *
284 * This function queries the heap for a particular handle to get the
285 * handle's physical address. It't output is only correct if
286 * a heap returns physically contiguous memory -- in other cases
287 * this api should not be implemented -- ion_map_dma should be used
288 * instead. Returns -EINVAL if the handle is invalid. This has
289 * no implications on the reference counting of the handle --
290 * the returned value may not be valid if the caller is not
291 * holding a reference.
292 */
293int ion_phys(struct ion_client *client, struct ion_handle *handle,
294 ion_phys_addr_t *addr, size_t *len);
295
296/**
297 * ion_map_kernel - create mapping for the given handle
298 * @client: the client
299 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700300 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700301 *
302 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700303 * can be used to access this address. If no flags are specified, this
304 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700305 */
Laura Abbott894fd582011-08-19 13:33:56 -0700306void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
307 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700308
309/**
310 * ion_unmap_kernel() - destroy a kernel mapping for a handle
311 * @client: the client
312 * @handle: handle to unmap
313 */
314void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
315
316/**
317 * ion_map_dma - create a dma mapping for a given handle
318 * @client: the client
319 * @handle: handle to map
320 *
321 * Return an sglist describing the given handle
322 */
323struct scatterlist *ion_map_dma(struct ion_client *client,
Laura Abbott894fd582011-08-19 13:33:56 -0700324 struct ion_handle *handle,
325 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700326
327/**
328 * ion_unmap_dma() - destroy a dma mapping for a handle
329 * @client: the client
330 * @handle: handle to unmap
331 */
332void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
333
334/**
335 * ion_share() - given a handle, obtain a buffer to pass to other clients
336 * @client: the client
337 * @handle: the handle to share
338 *
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700339 * Given a handle, return a buffer, which exists in a global name
340 * space, and can be passed to other clients. Should be passed into ion_import
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700341 * to obtain a new handle for this buffer.
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700342 *
343 * NOTE: This function does do not an extra reference. The burden is on the
344 * caller to make sure the buffer doesn't go away while it's being passed to
345 * another client. That is, ion_free should not be called on this handle until
346 * the buffer has been imported into the other client.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700347 */
348struct ion_buffer *ion_share(struct ion_client *client,
349 struct ion_handle *handle);
350
351/**
352 * ion_import() - given an buffer in another client, import it
353 * @client: this blocks client
354 * @buffer: the buffer to import (as obtained from ion_share)
355 *
356 * Given a buffer, add it to the client and return the handle to use to refer
357 * to it further. This is called to share a handle from one kernel client to
358 * another.
359 */
360struct ion_handle *ion_import(struct ion_client *client,
361 struct ion_buffer *buffer);
362
363/**
364 * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
365 * @client: this blocks client
366 * @fd: the fd
367 *
368 * A helper function for drivers that will be recieving ion buffers shared
369 * with them from userspace. These buffers are represented by a file
370 * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
371 * This function coverts that fd into the underlying buffer, and returns
372 * the handle to use to refer to it further.
373 */
374struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700375
Laura Abbott273dd8e2011-10-12 14:26:33 -0700376/**
377 * ion_handle_get_flags - get the flags for a given handle
378 *
379 * @client - client who allocated the handle
380 * @handle - handle to get the flags
381 * @flags - pointer to store the flags
382 *
383 * Gets the current flags for a handle. These flags indicate various options
384 * of the buffer (caching, security, etc.)
385 */
386int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
387 unsigned long *flags);
388
Laura Abbott8c017362011-09-22 20:59:12 -0700389
390/**
391 * ion_map_iommu - map the given handle into an iommu
392 *
393 * @client - client who allocated the handle
394 * @handle - handle to map
395 * @domain_num - domain number to map to
396 * @partition_num - partition number to allocate iova from
397 * @align - alignment for the iova
398 * @iova_length - length of iova to map. If the iova length is
399 * greater than the handle length, the remaining
400 * address space will be mapped to a dummy buffer.
401 * @iova - pointer to store the iova address
402 * @buffer_size - pointer to store the size of the buffer
403 * @flags - flags for options to map
404 *
405 * Maps the handle into the iova space specified via domain number. Iova
406 * will be allocated from the partition specified via partition_num.
407 * Returns 0 on success, negative value on error.
408 */
409int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
410 int domain_num, int partition_num, unsigned long align,
411 unsigned long iova_length, unsigned long *iova,
412 unsigned long *buffer_size,
413 unsigned long flags);
414
415
416/**
417 * ion_handle_get_size - get the allocated size of a given handle
418 *
419 * @client - client who allocated the handle
420 * @handle - handle to get the size
421 * @size - pointer to store the size
422 *
423 * gives the allocated size of a handle. returns 0 on success, negative
424 * value on error
425 *
426 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
427 * You should *NOT* rely on this for any other usage.
428 */
429
430int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
431 unsigned long *size);
432
433/**
434 * ion_unmap_iommu - unmap the handle from an iommu
435 *
436 * @client - client who allocated the handle
437 * @handle - handle to unmap
438 * @domain_num - domain to unmap from
439 * @partition_num - partition to unmap from
440 *
441 * Decrement the reference count on the iommu mapping. If the count is
442 * 0, the mapping will be removed from the iommu.
443 */
444void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
445 int domain_num, int partition_num);
446
447
Olav Haugan0a852512012-01-09 10:20:55 -0800448/**
449 * ion_secure_heap - secure a heap
450 *
451 * @client - a client that has allocated from the heap heap_id
452 * @heap_id - heap id to secure.
453 *
454 * Secure a heap
455 * Returns 0 on success
456 */
457int ion_secure_heap(struct ion_device *dev, int heap_id);
458
459/**
460 * ion_unsecure_heap - un-secure a heap
461 *
462 * @client - a client that has allocated from the heap heap_id
463 * @heap_id - heap id to un-secure.
464 *
465 * Un-secure a heap
466 * Returns 0 on success
467 */
468int ion_unsecure_heap(struct ion_device *dev, int heap_id);
469
470/**
471 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
472 *
473 * @heap_id - heap id to secure.
474 *
475 * Secure a heap
476 * Returns 0 on success
477 */
478int msm_ion_secure_heap(int heap_id);
479
480/**
481 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
482 *
483 * @heap_id - heap id to secure.
484 *
485 * Un-secure a heap
486 * Returns 0 on success
487 */
488int msm_ion_unsecure_heap(int heap_id);
489
Jordan Crouse8cd48322011-10-12 17:05:19 -0600490#else
491static inline struct ion_client *ion_client_create(struct ion_device *dev,
492 unsigned int heap_mask, const char *name)
493{
494 return ERR_PTR(-ENODEV);
495}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700496
Jordan Crouse8cd48322011-10-12 17:05:19 -0600497static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
498 const char *name)
499{
500 return ERR_PTR(-ENODEV);
501}
502
503static inline void ion_client_destroy(struct ion_client *client) { }
504
505static inline struct ion_handle *ion_alloc(struct ion_client *client,
506 size_t len, size_t align, unsigned int flags)
507{
508 return ERR_PTR(-ENODEV);
509}
510
511static inline void ion_free(struct ion_client *client,
512 struct ion_handle *handle) { }
513
514
515static inline int ion_phys(struct ion_client *client,
516 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
517{
518 return -ENODEV;
519}
520
521static inline void *ion_map_kernel(struct ion_client *client,
522 struct ion_handle *handle, unsigned long flags)
523{
524 return ERR_PTR(-ENODEV);
525}
526
527static inline void ion_unmap_kernel(struct ion_client *client,
528 struct ion_handle *handle) { }
529
530static inline struct scatterlist *ion_map_dma(struct ion_client *client,
531 struct ion_handle *handle, unsigned long flags)
532{
533 return ERR_PTR(-ENODEV);
534}
535
536static inline void ion_unmap_dma(struct ion_client *client,
537 struct ion_handle *handle) { }
538
539static inline struct ion_buffer *ion_share(struct ion_client *client,
540 struct ion_handle *handle)
541{
542 return ERR_PTR(-ENODEV);
543}
544
545static inline struct ion_handle *ion_import(struct ion_client *client,
546 struct ion_buffer *buffer)
547{
548 return ERR_PTR(-ENODEV);
549}
550
551static inline struct ion_handle *ion_import_fd(struct ion_client *client,
552 int fd)
553{
554 return ERR_PTR(-ENODEV);
555}
556
557static inline int ion_handle_get_flags(struct ion_client *client,
558 struct ion_handle *handle, unsigned long *flags)
559{
560 return -ENODEV;
561}
Laura Abbott8c017362011-09-22 20:59:12 -0700562
563static inline int ion_map_iommu(struct ion_client *client,
564 struct ion_handle *handle, int domain_num,
565 int partition_num, unsigned long align,
566 unsigned long iova_length, unsigned long *iova,
567 unsigned long flags)
568{
569 return -ENODEV;
570}
571
572static inline void ion_unmap_iommu(struct ion_client *client,
573 struct ion_handle *handle, int domain_num,
574 int partition_num)
575{
576 return;
577}
578
Olav Haugan0a852512012-01-09 10:20:55 -0800579static inline int ion_secure_heap(struct ion_device *dev, int heap_id)
580{
581 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700582
Olav Haugan0a852512012-01-09 10:20:55 -0800583}
584
585static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id)
586{
587 return -ENODEV;
588}
589
590static inline int msm_ion_secure_heap(int heap_id)
591{
592 return -ENODEV;
593
594}
595
596static inline int msm_ion_unsecure_heap(int heap_id)
597{
598 return -ENODEV;
599}
Jordan Crouse8cd48322011-10-12 17:05:19 -0600600#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700601#endif /* __KERNEL__ */
602
603/**
604 * DOC: Ion Userspace API
605 *
606 * create a client by opening /dev/ion
607 * most operations handled via following ioctls
608 *
609 */
610
611/**
612 * struct ion_allocation_data - metadata passed from userspace for allocations
613 * @len: size of the allocation
614 * @align: required alignment of the allocation
615 * @flags: flags passed to heap
616 * @handle: pointer that will be populated with a cookie to use to refer
617 * to this allocation
618 *
619 * Provided by userspace as an argument to the ioctl
620 */
621struct ion_allocation_data {
622 size_t len;
623 size_t align;
624 unsigned int flags;
625 struct ion_handle *handle;
626};
627
628/**
629 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
630 * @handle: a handle
631 * @fd: a file descriptor representing that handle
632 *
633 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
634 * the handle returned from ion alloc, and the kernel returns the file
635 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
636 * provides the file descriptor and the kernel returns the handle.
637 */
638struct ion_fd_data {
639 struct ion_handle *handle;
640 int fd;
641};
642
643/**
644 * struct ion_handle_data - a handle passed to/from the kernel
645 * @handle: a handle
646 */
647struct ion_handle_data {
648 struct ion_handle *handle;
649};
650
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700651/**
652 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
653 * @cmd: the custom ioctl function to call
654 * @arg: additional data to pass to the custom ioctl, typically a user
655 * pointer to a predefined structure
656 *
657 * This works just like the regular cmd and arg fields of an ioctl.
658 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700659struct ion_custom_data {
660 unsigned int cmd;
661 unsigned long arg;
662};
663
Laura Abbottabcb6f72011-10-04 16:26:49 -0700664
665/* struct ion_flush_data - data passed to ion for flushing caches
666 *
667 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800668 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700669 * @vaddr: userspace virtual address mapped with mmap
670 * @offset: offset into the handle to flush
671 * @length: length of handle to flush
672 *
673 * Performs cache operations on the handle. If p is the start address
674 * of the handle, p + offset through p + offset + length will have
675 * the cache operations performed
676 */
677struct ion_flush_data {
678 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800679 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700680 void *vaddr;
681 unsigned int offset;
682 unsigned int length;
683};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700684
685/* struct ion_flag_data - information about flags for this buffer
686 *
687 * @handle: handle to get flags from
688 * @flags: flags of this handle
689 *
690 * Takes handle as an input and outputs the flags from the handle
691 * in the flag field.
692 */
693struct ion_flag_data {
694 struct ion_handle *handle;
695 unsigned long flags;
696};
697
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700698#define ION_IOC_MAGIC 'I'
699
700/**
701 * DOC: ION_IOC_ALLOC - allocate memory
702 *
703 * Takes an ion_allocation_data struct and returns it with the handle field
704 * populated with the opaque handle for the allocation.
705 */
706#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
707 struct ion_allocation_data)
708
709/**
710 * DOC: ION_IOC_FREE - free memory
711 *
712 * Takes an ion_handle_data struct and frees the handle.
713 */
714#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
715
716/**
717 * DOC: ION_IOC_MAP - get a file descriptor to mmap
718 *
719 * Takes an ion_fd_data struct with the handle field populated with a valid
720 * opaque handle. Returns the struct with the fd field set to a file
721 * descriptor open in the current address space. This file descriptor
722 * can then be used as an argument to mmap.
723 */
724#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
725
726/**
727 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
728 *
729 * Takes an ion_fd_data struct with the handle field populated with a valid
730 * opaque handle. Returns the struct with the fd field set to a file
731 * descriptor open in the current address space. This file descriptor
732 * can then be passed to another process. The corresponding opaque handle can
733 * be retrieved via ION_IOC_IMPORT.
734 */
735#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
736
737/**
738 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
739 *
740 * Takes an ion_fd_data struct with the fd field populated with a valid file
741 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
742 * filed set to the corresponding opaque handle.
743 */
744#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
745
746/**
747 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
748 *
749 * Takes the argument of the architecture specific ioctl to call and
750 * passes appropriate userdata for that ioctl
751 */
752#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
753
Laura Abbottabcb6f72011-10-04 16:26:49 -0700754
755/**
756 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
757 *
758 * Clean the caches of the handle specified.
759 */
760#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
761 struct ion_flush_data)
762/**
763 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
764 *
765 * Invalidate the caches of the handle specified.
766 */
767#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
768 struct ion_flush_data)
769/**
770 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
771 *
772 * Clean and invalidate the caches of the handle specified.
773 */
774#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
775 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700776
777/**
778 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
779 *
780 * Gets the flags of the current handle which indicate cachability,
781 * secure state etc.
782 */
783#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
784 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700785#endif /* _LINUX_ION_H */