blob: fb1c5f64ed5090ba12d18773f7faeddd8c35694f [file] [log] [blame]
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07001/*
2 * include/linux/ion.h
3 *
4 * Copyright (C) 2011 Google, Inc.
Mitchel Humpherysa75e4eb2012-12-14 16:12:23 -08005 * Copyright (c) 2011-2013, The Linux Foundation. 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
24struct ion_handle;
25/**
26 * enum ion_heap_types - list of all possible types of heaps
Iliyan Malchevf22301562011-07-06 16:53:21 -070027 * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
28 * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
29 * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
Olav Hauganb5be7992011-11-18 14:29:02 -080030 * carveout heap, allocations are physically
31 * contiguous
Olav Haugan0a852512012-01-09 10:20:55 -080032 * @ION_HEAP_TYPE_IOMMU: IOMMU memory
33 * @ION_HEAP_TYPE_CP: memory allocated from a prereserved
34 * carveout heap, allocations are physically
35 * contiguous. Used for content protection.
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070036 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
Olav Haugan0a852512012-01-09 10:20:55 -080037 * @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,
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070043 ION_HEAP_TYPE_DMA,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070044 ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always
45 are at the end of this enum */
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070046 ION_NUM_HEAPS,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070047};
48
Iliyan Malchevf22301562011-07-06 16:53:21 -070049#define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM)
50#define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
51#define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070052#define ION_HEAP_TYPE_DMA_MASK (1 << ION_HEAP_TYPE_DMA)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070053
Mitchel Humpherys227a6582012-09-11 15:59:11 -070054/**
55 * heap flags - the lower 16 bits are used by core ion, the upper 16
56 * bits are reserved for use by the heaps themselves.
57 */
58#define ION_FLAG_CACHED 1 /* mappings of this buffer should be
59 cached, ion will do cache
60 maintenance when the buffer is
61 mapped for dma */
Laura Abbotta2e93632011-08-19 13:36:32 -070062
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070063#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -070064#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -070065#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070066struct ion_device;
67struct ion_heap;
68struct ion_mapper;
69struct ion_client;
70struct ion_buffer;
71
72/* This should be removed some day when phys_addr_t's are fully
73 plumbed in the kernel, and all instances of ion_phys_addr_t should
74 be converted to phys_addr_t. For the time being many kernel interfaces
75 do not accept phys_addr_t's that would have to */
76#define ion_phys_addr_t unsigned long
77
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070078/**
79 * struct ion_platform_heap - defines a heap in the given platform
80 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -080081 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -080082 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070083 * @name: used for debug purposes
84 * @base: base address of heap in physical memory if applicable
85 * @size: size of the heap in bytes if applicable
Laura Abbottcaafeea2011-12-13 11:43:10 -080086 * @memory_type:Memory type used for the heap
Olav Haugan85c95402012-05-30 17:32:37 -070087 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Laura Abbottcaafeea2011-12-13 11:43:10 -080088 * @extra_data: Extra data specific to each heap type
Benjamin Gaignard8dff0a62012-06-25 15:30:18 -070089 * @priv: heap private data
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070090 */
91struct ion_platform_heap {
92 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070093 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070094 const char *name;
95 ion_phys_addr_t base;
96 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -070097 enum ion_memory_types memory_type;
Olav Haugan85c95402012-05-30 17:32:37 -070098 unsigned int has_outer_cache;
Olav Haugan0703dbf2011-12-19 17:53:38 -080099 void *extra_data;
Benjamin Gaignard8dff0a62012-06-25 15:30:18 -0700100 void *priv;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800101};
102
Laura Abbottcaafeea2011-12-13 11:43:10 -0800103/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700104 * struct ion_platform_data - array of platform heaps passed from board file
Olav Haugan85c95402012-05-30 17:32:37 -0700105 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Alex Bird27ca6612011-11-01 14:40:06 -0700106 * @nr: number of structures in the array
107 * @request_region: function to be called when the number of allocations goes
108 * from 0 -> 1
109 * @release_region: function to be called when the number of allocations goes
110 * from 1 -> 0
111 * @setup_region: function to be called upon ion registration
112 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700113 *
114 * Provided by the board file in the form of platform data to a platform device.
115 */
116struct ion_platform_data {
Olav Haugan85c95402012-05-30 17:32:37 -0700117 unsigned int has_outer_cache;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700118 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800119 int (*request_region)(void *);
120 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700121 void *(*setup_region)(void);
Benjamin Gaignard63d81032012-06-25 15:27:30 -0700122 struct ion_platform_heap *heaps;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700123};
124
Jordan Crouse8cd48322011-10-12 17:05:19 -0600125#ifdef CONFIG_ION
126
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700127/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800128 * ion_reserve() - reserve memory for ion heaps if applicable
129 * @data: platform data specifying starting physical address and
130 * size
131 *
132 * Calls memblock reserve to set aside memory for heaps that are
133 * located at specific memory addresses or of specfic sizes not
134 * managed by the kernel
135 */
136void ion_reserve(struct ion_platform_data *data);
137
138/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700139 * ion_client_create() - allocate a client and returns it
140 * @dev: the global ion device
141 * @heap_mask: mask of heaps this client can allocate from
142 * @name: used for debugging
143 */
144struct ion_client *ion_client_create(struct ion_device *dev,
145 unsigned int heap_mask, const char *name);
146
147/**
Laura Abbott302911d2011-08-15 17:12:57 -0700148 * msm_ion_client_create - allocate a client using the ion_device specified in
149 * drivers/gpu/ion/msm/msm_ion.c
150 *
151 * heap_mask and name are the same as ion_client_create, return values
152 * are the same as ion_client_create.
153 */
154
155struct ion_client *msm_ion_client_create(unsigned int heap_mask,
156 const char *name);
157
158/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700159 * ion_client_destroy() - free's a client and all it's handles
160 * @client: the client
161 *
162 * Free the provided client and all it's resources including
163 * any handles it is holding.
164 */
165void ion_client_destroy(struct ion_client *client);
166
167/**
168 * ion_alloc - allocate ion memory
169 * @client: the client
170 * @len: size of the allocation
171 * @align: requested allocation alignment, lots of hardware blocks have
172 * alignment requirements of some kind
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700173 * @heap_mask: mask of heaps to allocate from, if multiple bits are set
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700174 * heaps will be tried in order from lowest to highest order bit
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700175 * @flags: heap flags, the low 16 bits are consumed by ion, the high 16
176 * bits are passed on to the respective heap and can be heap
177 * custom
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700178 *
179 * Allocate memory in one of the heaps provided in heap mask and return
180 * an opaque handle to it.
181 */
182struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700183 size_t align, unsigned int heap_mask,
184 unsigned int flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700185
186/**
187 * ion_free - free a handle
188 * @client: the client
189 * @handle: the handle to free
190 *
191 * Free the provided handle.
192 */
193void ion_free(struct ion_client *client, struct ion_handle *handle);
194
195/**
196 * ion_phys - returns the physical address and len of a handle
197 * @client: the client
198 * @handle: the handle
199 * @addr: a pointer to put the address in
200 * @len: a pointer to put the length in
201 *
202 * This function queries the heap for a particular handle to get the
203 * handle's physical address. It't output is only correct if
204 * a heap returns physically contiguous memory -- in other cases
Laura Abbottb14ed962012-01-30 14:18:08 -0800205 * this api should not be implemented -- ion_sg_table should be used
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700206 * instead. Returns -EINVAL if the handle is invalid. This has
207 * no implications on the reference counting of the handle --
208 * the returned value may not be valid if the caller is not
209 * holding a reference.
210 */
211int ion_phys(struct ion_client *client, struct ion_handle *handle,
212 ion_phys_addr_t *addr, size_t *len);
213
214/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800215 * ion_map_dma - return an sg_table describing a handle
216 * @client: the client
217 * @handle: the handle
218 *
219 * This function returns the sg_table describing
220 * a particular ion handle.
221 */
222struct sg_table *ion_sg_table(struct ion_client *client,
223 struct ion_handle *handle);
224
225/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700226 * ion_map_kernel - create mapping for the given handle
227 * @client: the client
228 * @handle: handle to map
229 *
230 * Map the given handle into the kernel and return a kernel address that
Mitchel Humpherysc4dba0a2012-11-05 14:06:18 -0800231 * can be used to access this address.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700232 */
Mitchel Humpherys911b4b72012-09-12 14:42:50 -0700233void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700234
235/**
236 * ion_unmap_kernel() - destroy a kernel mapping for a handle
237 * @client: the client
238 * @handle: handle to unmap
239 */
240void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
241
242/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800243 * ion_share_dma_buf() - given an ion client, create a dma-buf fd
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700244 * @client: the client
Laura Abbottb14ed962012-01-30 14:18:08 -0800245 * @handle: the handle
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700246 */
Laura Abbottb14ed962012-01-30 14:18:08 -0800247int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700248
249/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800250 * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700251 * @client: the client
Laura Abbottb14ed962012-01-30 14:18:08 -0800252 * @fd: the dma-buf fd
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700253 *
Laura Abbottb14ed962012-01-30 14:18:08 -0800254 * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
255 * import that fd and return a handle representing it. If a dma-buf from
256 * another exporter is passed in this function will return ERR_PTR(-EINVAL)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700257 */
Laura Abbottb14ed962012-01-30 14:18:08 -0800258struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700259
Laura Abbott273dd8e2011-10-12 14:26:33 -0700260/**
261 * ion_handle_get_flags - get the flags for a given handle
262 *
263 * @client - client who allocated the handle
264 * @handle - handle to get the flags
265 * @flags - pointer to store the flags
266 *
267 * Gets the current flags for a handle. These flags indicate various options
268 * of the buffer (caching, security, etc.)
269 */
270int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
271 unsigned long *flags);
272
Laura Abbott8c017362011-09-22 20:59:12 -0700273
274/**
275 * ion_map_iommu - map the given handle into an iommu
276 *
277 * @client - client who allocated the handle
278 * @handle - handle to map
279 * @domain_num - domain number to map to
280 * @partition_num - partition number to allocate iova from
281 * @align - alignment for the iova
282 * @iova_length - length of iova to map. If the iova length is
283 * greater than the handle length, the remaining
284 * address space will be mapped to a dummy buffer.
285 * @iova - pointer to store the iova address
286 * @buffer_size - pointer to store the size of the buffer
Mitchel Humpherys362b52b2012-09-13 10:53:22 -0700287 * @flags - flags for options to map
Olav Hauganb3676592012-03-02 15:02:25 -0800288 * @iommu_flags - flags specific to the iommu.
Laura Abbott8c017362011-09-22 20:59:12 -0700289 *
290 * Maps the handle into the iova space specified via domain number. Iova
291 * will be allocated from the partition specified via partition_num.
292 * Returns 0 on success, negative value on error.
293 */
294int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
295 int domain_num, int partition_num, unsigned long align,
296 unsigned long iova_length, unsigned long *iova,
297 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800298 unsigned long flags, unsigned long iommu_flags);
Laura Abbott8c017362011-09-22 20:59:12 -0700299
300
301/**
302 * ion_handle_get_size - get the allocated size of a given handle
303 *
304 * @client - client who allocated the handle
305 * @handle - handle to get the size
306 * @size - pointer to store the size
307 *
308 * gives the allocated size of a handle. returns 0 on success, negative
309 * value on error
310 *
311 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
312 * You should *NOT* rely on this for any other usage.
313 */
314
315int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
316 unsigned long *size);
317
318/**
319 * ion_unmap_iommu - unmap the handle from an iommu
320 *
321 * @client - client who allocated the handle
322 * @handle - handle to unmap
323 * @domain_num - domain to unmap from
324 * @partition_num - partition to unmap from
325 *
326 * Decrement the reference count on the iommu mapping. If the count is
327 * 0, the mapping will be removed from the iommu.
328 */
329void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
330 int domain_num, int partition_num);
331
332
Olav Haugan0a852512012-01-09 10:20:55 -0800333/**
334 * ion_secure_heap - secure a heap
335 *
336 * @client - a client that has allocated from the heap heap_id
337 * @heap_id - heap id to secure.
Laura Abbott7e446482012-06-13 15:59:39 -0700338 * @version - version of content protection
339 * @data - extra data needed for protection
Olav Haugan0a852512012-01-09 10:20:55 -0800340 *
341 * Secure a heap
342 * Returns 0 on success
343 */
Laura Abbott7e446482012-06-13 15:59:39 -0700344int ion_secure_heap(struct ion_device *dev, int heap_id, int version,
345 void *data);
Olav Haugan0a852512012-01-09 10:20:55 -0800346
347/**
348 * ion_unsecure_heap - un-secure a heap
349 *
350 * @client - a client that has allocated from the heap heap_id
351 * @heap_id - heap id to un-secure.
Laura Abbott7e446482012-06-13 15:59:39 -0700352 * @version - version of content protection
353 * @data - extra data needed for protection
Olav Haugan0a852512012-01-09 10:20:55 -0800354 *
355 * Un-secure a heap
356 * Returns 0 on success
357 */
Laura Abbott7e446482012-06-13 15:59:39 -0700358int ion_unsecure_heap(struct ion_device *dev, int heap_id, int version,
359 void *data);
Olav Haugan0a852512012-01-09 10:20:55 -0800360
361/**
Olav Haugan41f85792012-02-08 15:28:05 -0800362 * msm_ion_do_cache_op - do cache operations.
363 *
364 * @client - pointer to ION client.
365 * @handle - pointer to buffer handle.
366 * @vaddr - virtual address to operate on.
367 * @len - Length of data to do cache operation on.
368 * @cmd - Cache operation to perform:
369 * ION_IOC_CLEAN_CACHES
370 * ION_IOC_INV_CACHES
371 * ION_IOC_CLEAN_INV_CACHES
372 *
373 * Returns 0 on success
374 */
375int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle,
376 void *vaddr, unsigned long len, unsigned int cmd);
377
Jordan Crouse8cd48322011-10-12 17:05:19 -0600378#else
Laura Abbottb14ed962012-01-30 14:18:08 -0800379static inline void ion_reserve(struct ion_platform_data *data)
380{
381
382}
383
Jordan Crouse8cd48322011-10-12 17:05:19 -0600384static inline struct ion_client *ion_client_create(struct ion_device *dev,
385 unsigned int heap_mask, const char *name)
386{
387 return ERR_PTR(-ENODEV);
388}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700389
Jordan Crouse8cd48322011-10-12 17:05:19 -0600390static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
391 const char *name)
392{
393 return ERR_PTR(-ENODEV);
394}
395
396static inline void ion_client_destroy(struct ion_client *client) { }
397
398static inline struct ion_handle *ion_alloc(struct ion_client *client,
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700399 size_t len, size_t align,
400 unsigned int heap_mask,
401 unsigned int flags)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600402{
403 return ERR_PTR(-ENODEV);
404}
405
406static inline void ion_free(struct ion_client *client,
407 struct ion_handle *handle) { }
408
409
410static inline int ion_phys(struct ion_client *client,
411 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
412{
413 return -ENODEV;
414}
415
Laura Abbottb14ed962012-01-30 14:18:08 -0800416static inline struct sg_table *ion_sg_table(struct ion_client *client,
417 struct ion_handle *handle)
418{
419 return ERR_PTR(-ENODEV);
420}
421
Jordan Crouse8cd48322011-10-12 17:05:19 -0600422static inline void *ion_map_kernel(struct ion_client *client,
Mitchel Humpherysbaa86922012-11-02 16:35:39 -0700423 struct ion_handle *handle)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600424{
425 return ERR_PTR(-ENODEV);
426}
427
428static inline void ion_unmap_kernel(struct ion_client *client,
429 struct ion_handle *handle) { }
430
Laura Abbottb14ed962012-01-30 14:18:08 -0800431static inline int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600432{
Laura Abbottb14ed962012-01-30 14:18:08 -0800433 return -ENODEV;
Jordan Crouse8cd48322011-10-12 17:05:19 -0600434}
435
Laura Abbottb14ed962012-01-30 14:18:08 -0800436static inline struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600437{
438 return ERR_PTR(-ENODEV);
439}
440
441static inline int ion_handle_get_flags(struct ion_client *client,
442 struct ion_handle *handle, unsigned long *flags)
443{
444 return -ENODEV;
445}
Laura Abbott8c017362011-09-22 20:59:12 -0700446
447static inline int ion_map_iommu(struct ion_client *client,
448 struct ion_handle *handle, int domain_num,
449 int partition_num, unsigned long align,
450 unsigned long iova_length, unsigned long *iova,
Olav Haugan9a27d4c2012-02-23 09:35:16 -0800451 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800452 unsigned long flags,
453 unsigned long iommu_flags)
Laura Abbott8c017362011-09-22 20:59:12 -0700454{
455 return -ENODEV;
456}
457
Mitchel Humpherysbaa86922012-11-02 16:35:39 -0700458static inline int ion_handle_get_size(struct ion_client *client,
459 struct ion_handle *handle, unsigned long *size)
460{
461 return -ENODEV;
462}
463
Laura Abbott8c017362011-09-22 20:59:12 -0700464static inline void ion_unmap_iommu(struct ion_client *client,
465 struct ion_handle *handle, int domain_num,
466 int partition_num)
467{
468 return;
469}
470
Laura Abbott7e446482012-06-13 15:59:39 -0700471static inline int ion_secure_heap(struct ion_device *dev, int heap_id,
472 int version, void *data)
Olav Haugan0a852512012-01-09 10:20:55 -0800473{
474 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700475
Olav Haugan0a852512012-01-09 10:20:55 -0800476}
477
Laura Abbott7e446482012-06-13 15:59:39 -0700478static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id,
479 int version, void *data)
Olav Haugan0a852512012-01-09 10:20:55 -0800480{
481 return -ENODEV;
482}
483
Mitchel Humpherysa75e4eb2012-12-14 16:12:23 -0800484static inline void ion_mark_dangling_buffers_locked(struct ion_device *dev)
485{
486}
487
Olav Haugan41f85792012-02-08 15:28:05 -0800488static inline int msm_ion_do_cache_op(struct ion_client *client,
489 struct ion_handle *handle, void *vaddr,
490 unsigned long len, unsigned int cmd)
491{
492 return -ENODEV;
493}
494
Jordan Crouse8cd48322011-10-12 17:05:19 -0600495#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700496#endif /* __KERNEL__ */
497
498/**
499 * DOC: Ion Userspace API
500 *
501 * create a client by opening /dev/ion
502 * most operations handled via following ioctls
503 *
504 */
505
506/**
507 * struct ion_allocation_data - metadata passed from userspace for allocations
508 * @len: size of the allocation
509 * @align: required alignment of the allocation
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700510 * @heap_mask: mask of heaps to allocate from
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700511 * @flags: flags passed to heap
512 * @handle: pointer that will be populated with a cookie to use to refer
513 * to this allocation
514 *
515 * Provided by userspace as an argument to the ioctl
516 */
517struct ion_allocation_data {
518 size_t len;
519 size_t align;
Laura Abbott0eec1512012-08-27 13:14:39 -0700520 unsigned int heap_mask;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700521 unsigned int flags;
522 struct ion_handle *handle;
523};
524
525/**
526 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
527 * @handle: a handle
528 * @fd: a file descriptor representing that handle
529 *
530 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
531 * the handle returned from ion alloc, and the kernel returns the file
532 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
533 * provides the file descriptor and the kernel returns the handle.
534 */
535struct ion_fd_data {
536 struct ion_handle *handle;
537 int fd;
538};
539
540/**
541 * struct ion_handle_data - a handle passed to/from the kernel
542 * @handle: a handle
543 */
544struct ion_handle_data {
545 struct ion_handle *handle;
546};
547
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700548/**
549 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
550 * @cmd: the custom ioctl function to call
551 * @arg: additional data to pass to the custom ioctl, typically a user
552 * pointer to a predefined structure
553 *
554 * This works just like the regular cmd and arg fields of an ioctl.
555 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700556struct ion_custom_data {
557 unsigned int cmd;
558 unsigned long arg;
559};
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700560#define ION_IOC_MAGIC 'I'
561
562/**
563 * DOC: ION_IOC_ALLOC - allocate memory
564 *
565 * Takes an ion_allocation_data struct and returns it with the handle field
566 * populated with the opaque handle for the allocation.
567 */
568#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
569 struct ion_allocation_data)
570
571/**
572 * DOC: ION_IOC_FREE - free memory
573 *
574 * Takes an ion_handle_data struct and frees the handle.
575 */
576#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
577
578/**
579 * DOC: ION_IOC_MAP - get a file descriptor to mmap
580 *
581 * Takes an ion_fd_data struct with the handle field populated with a valid
582 * opaque handle. Returns the struct with the fd field set to a file
583 * descriptor open in the current address space. This file descriptor
584 * can then be used as an argument to mmap.
585 */
586#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
587
588/**
589 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
590 *
591 * Takes an ion_fd_data struct with the handle field populated with a valid
592 * opaque handle. Returns the struct with the fd field set to a file
593 * descriptor open in the current address space. This file descriptor
594 * can then be passed to another process. The corresponding opaque handle can
595 * be retrieved via ION_IOC_IMPORT.
596 */
597#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
598
599/**
600 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
601 *
602 * Takes an ion_fd_data struct with the fd field populated with a valid file
603 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
604 * filed set to the corresponding opaque handle.
605 */
Laura Abbott0eec1512012-08-27 13:14:39 -0700606#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700607
608/**
609 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
610 *
611 * Takes the argument of the architecture specific ioctl to call and
612 * passes appropriate userdata for that ioctl
613 */
614#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
615
Laura Abbottabcb6f72011-10-04 16:26:49 -0700616
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700617#endif /* _LINUX_ION_H */