blob: 591f14692edb206ed314eb2e016e714c34e86023 [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
Larry Bassel2d8b42d2012-03-12 10:41:26 -070082enum ion_fixed_position {
83 NOT_FIXED,
84 FIXED_LOW,
85 FIXED_MIDDLE,
86 FIXED_HIGH,
87};
88
Laura Abbottd0c83de2012-06-12 18:49:57 -070089enum cp_mem_usage {
90 VIDEO_BITSTREAM = 0x1,
91 VIDEO_PIXEL = 0x2,
92 VIDEO_NONPIXEL = 0x3,
93 MAX_USAGE = 0x4,
94 UNKNOWN = 0x7FFFFFFF,
95};
96
Olav Hauganb5be7992011-11-18 14:29:02 -080097/**
98 * Flag to use when allocating to indicate that a heap is secure.
99 */
100#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
101
102/**
103 * Macro should be used with ion_heap_ids defined above.
104 */
105#define ION_HEAP(bit) (1 << (bit))
106
Laura Abbotta2e93632011-08-19 13:36:32 -0700107#define ION_VMALLOC_HEAP_NAME "vmalloc"
Olav Hauganb5be7992011-11-18 14:29:02 -0800108#define ION_AUDIO_HEAP_NAME "audio"
109#define ION_SF_HEAP_NAME "sf"
110#define ION_MM_HEAP_NAME "mm"
111#define ION_CAMERA_HEAP_NAME "camera_preview"
Laura Abbott8c017362011-09-22 20:59:12 -0700112#define ION_IOMMU_HEAP_NAME "iommu"
Olav Hauganb5be7992011-11-18 14:29:02 -0800113#define ION_MFC_HEAP_NAME "mfc"
114#define ION_WB_HEAP_NAME "wb"
Olav Haugan42ebe712012-01-10 16:30:58 -0800115#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Olav Haugan80854eb2012-01-12 12:00:23 -0800116#define ION_QSECOM_HEAP_NAME "qsecom"
Laura Abbottcaafeea2011-12-13 11:43:10 -0800117#define ION_FMEM_HEAP_NAME "fmem"
Laura Abbotta2e93632011-08-19 13:36:32 -0700118
Laura Abbott894fd582011-08-19 13:33:56 -0700119#define CACHED 1
120#define UNCACHED 0
121
122#define ION_CACHE_SHIFT 0
123
124#define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT)
125
Laura Abbott35412032011-09-29 09:50:06 -0700126#define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT))
127
Olav Hauganb3676592012-03-02 15:02:25 -0800128/*
129 * This flag allows clients when mapping into the IOMMU to specify to
130 * defer un-mapping from the IOMMU until the buffer memory is freed.
131 */
132#define ION_IOMMU_UNMAP_DELAYED 1
133
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700134#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700135#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700136#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700137struct ion_device;
138struct ion_heap;
139struct ion_mapper;
140struct ion_client;
141struct ion_buffer;
142
143/* This should be removed some day when phys_addr_t's are fully
144 plumbed in the kernel, and all instances of ion_phys_addr_t should
145 be converted to phys_addr_t. For the time being many kernel interfaces
146 do not accept phys_addr_t's that would have to */
147#define ion_phys_addr_t unsigned long
Laura Abbottcaafeea2011-12-13 11:43:10 -0800148#define ion_virt_addr_t unsigned long
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700149
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700150/**
151 * struct ion_platform_heap - defines a heap in the given platform
152 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800153 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800154 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700155 * @name: used for debug purposes
156 * @base: base address of heap in physical memory if applicable
157 * @size: size of the heap in bytes if applicable
Laura Abbottcaafeea2011-12-13 11:43:10 -0800158 * @memory_type:Memory type used for the heap
Olav Haugan85c95402012-05-30 17:32:37 -0700159 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800160 * @extra_data: Extra data specific to each heap type
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700161 */
162struct ion_platform_heap {
163 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700164 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700165 const char *name;
166 ion_phys_addr_t base;
167 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700168 enum ion_memory_types memory_type;
Olav Haugan85c95402012-05-30 17:32:37 -0700169 unsigned int has_outer_cache;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800170 void *extra_data;
171};
172
Laura Abbottcaafeea2011-12-13 11:43:10 -0800173/**
174 * struct ion_cp_heap_pdata - defines a content protection heap in the given
175 * platform
176 * @permission_type: Memory ID used to identify the memory to TZ
177 * @align: Alignment requirement for the memory
178 * @secure_base: Base address for securing the heap.
179 * Note: This might be different from actual base address
180 * of this heap in the case of a shared heap.
181 * @secure_size: Memory size for securing the heap.
182 * Note: This might be different from actual size
183 * of this heap in the case of a shared heap.
184 * @reusable Flag indicating whether this heap is reusable of not.
185 * (see FMEM)
Olav Hauganf6dc7742012-02-15 09:11:55 -0800186 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
187 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700188 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800189 * @virt_addr: Virtual address used when using fmem.
Olav Haugan8726caf2012-05-10 15:11:35 -0700190 * @iommu_map_all: Indicates whether we should map whole heap into IOMMU.
191 * @iommu_2x_map_domain: Indicates the domain to use for overmapping.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800192 * @request_region: function to be called when the number of allocations
193 * goes from 0 -> 1
194 * @release_region: function to be called when the number of allocations
195 * goes from 1 -> 0
196 * @setup_region: function to be called upon ion registration
197 *
198 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800199struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800200 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800201 unsigned int align;
202 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
203 size_t secure_size; /* Size used for securing heap when heap is shared*/
Laura Abbottcaafeea2011-12-13 11:43:10 -0800204 int reusable;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800205 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700206 enum ion_fixed_position fixed_position;
Olav Haugan8726caf2012-05-10 15:11:35 -0700207 int iommu_map_all;
208 int iommu_2x_map_domain;
Laura Abbottcaafeea2011-12-13 11:43:10 -0800209 ion_virt_addr_t *virt_addr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800210 int (*request_region)(void *);
211 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800212 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700213};
214
Laura Abbottcaafeea2011-12-13 11:43:10 -0800215/**
216 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
217 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
218 * @align: Alignment requirement for the memory
Olav Hauganf6dc7742012-02-15 09:11:55 -0800219 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
220 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700221 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800222 * @request_region: function to be called when the number of allocations
223 * goes from 0 -> 1
224 * @release_region: function to be called when the number of allocations
225 * goes from 1 -> 0
226 * @setup_region: function to be called upon ion registration
227 *
228 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800229struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800230 int adjacent_mem_id;
231 unsigned int align;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800232 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700233 enum ion_fixed_position fixed_position;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800234 int (*request_region)(void *);
235 int (*release_region)(void *);
236 void *(*setup_region)(void);
237};
238
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700239/**
240 * struct ion_platform_data - array of platform heaps passed from board file
Olav Haugan85c95402012-05-30 17:32:37 -0700241 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Alex Bird27ca6612011-11-01 14:40:06 -0700242 * @nr: number of structures in the array
243 * @request_region: function to be called when the number of allocations goes
244 * from 0 -> 1
245 * @release_region: function to be called when the number of allocations goes
246 * from 1 -> 0
247 * @setup_region: function to be called upon ion registration
248 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700249 *
250 * Provided by the board file in the form of platform data to a platform device.
251 */
252struct ion_platform_data {
Olav Haugan85c95402012-05-30 17:32:37 -0700253 unsigned int has_outer_cache;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700254 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800255 int (*request_region)(void *);
256 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700257 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700258 struct ion_platform_heap heaps[];
259};
260
Jordan Crouse8cd48322011-10-12 17:05:19 -0600261#ifdef CONFIG_ION
262
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700263/**
264 * ion_client_create() - allocate a client and returns it
265 * @dev: the global ion device
266 * @heap_mask: mask of heaps this client can allocate from
267 * @name: used for debugging
268 */
269struct ion_client *ion_client_create(struct ion_device *dev,
270 unsigned int heap_mask, const char *name);
271
272/**
Laura Abbott302911d2011-08-15 17:12:57 -0700273 * msm_ion_client_create - allocate a client using the ion_device specified in
274 * drivers/gpu/ion/msm/msm_ion.c
275 *
276 * heap_mask and name are the same as ion_client_create, return values
277 * are the same as ion_client_create.
278 */
279
280struct ion_client *msm_ion_client_create(unsigned int heap_mask,
281 const char *name);
282
283/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700284 * ion_client_destroy() - free's a client and all it's handles
285 * @client: the client
286 *
287 * Free the provided client and all it's resources including
288 * any handles it is holding.
289 */
290void ion_client_destroy(struct ion_client *client);
291
292/**
293 * ion_alloc - allocate ion memory
294 * @client: the client
295 * @len: size of the allocation
296 * @align: requested allocation alignment, lots of hardware blocks have
297 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700298 * @flags: mask of heaps to allocate from, if multiple bits are set
299 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700300 *
301 * Allocate memory in one of the heaps provided in heap mask and return
302 * an opaque handle to it.
303 */
304struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
305 size_t align, unsigned int flags);
306
307/**
308 * ion_free - free a handle
309 * @client: the client
310 * @handle: the handle to free
311 *
312 * Free the provided handle.
313 */
314void ion_free(struct ion_client *client, struct ion_handle *handle);
315
316/**
317 * ion_phys - returns the physical address and len of a handle
318 * @client: the client
319 * @handle: the handle
320 * @addr: a pointer to put the address in
321 * @len: a pointer to put the length in
322 *
323 * This function queries the heap for a particular handle to get the
324 * handle's physical address. It't output is only correct if
325 * a heap returns physically contiguous memory -- in other cases
326 * this api should not be implemented -- ion_map_dma should be used
327 * instead. Returns -EINVAL if the handle is invalid. This has
328 * no implications on the reference counting of the handle --
329 * the returned value may not be valid if the caller is not
330 * holding a reference.
331 */
332int ion_phys(struct ion_client *client, struct ion_handle *handle,
333 ion_phys_addr_t *addr, size_t *len);
334
335/**
336 * ion_map_kernel - create mapping for the given handle
337 * @client: the client
338 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700339 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700340 *
341 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700342 * can be used to access this address. If no flags are specified, this
343 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700344 */
Laura Abbott894fd582011-08-19 13:33:56 -0700345void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
346 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700347
348/**
349 * ion_unmap_kernel() - destroy a kernel mapping for a handle
350 * @client: the client
351 * @handle: handle to unmap
352 */
353void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
354
355/**
356 * ion_map_dma - create a dma mapping for a given handle
357 * @client: the client
358 * @handle: handle to map
359 *
360 * Return an sglist describing the given handle
361 */
362struct scatterlist *ion_map_dma(struct ion_client *client,
Laura Abbott894fd582011-08-19 13:33:56 -0700363 struct ion_handle *handle,
364 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700365
366/**
367 * ion_unmap_dma() - destroy a dma mapping for a handle
368 * @client: the client
369 * @handle: handle to unmap
370 */
371void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
372
373/**
374 * ion_share() - given a handle, obtain a buffer to pass to other clients
375 * @client: the client
376 * @handle: the handle to share
377 *
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700378 * Given a handle, return a buffer, which exists in a global name
379 * space, and can be passed to other clients. Should be passed into ion_import
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700380 * to obtain a new handle for this buffer.
Iliyan Malchev3fe24362011-08-09 14:42:08 -0700381 *
382 * NOTE: This function does do not an extra reference. The burden is on the
383 * caller to make sure the buffer doesn't go away while it's being passed to
384 * another client. That is, ion_free should not be called on this handle until
385 * the buffer has been imported into the other client.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700386 */
387struct ion_buffer *ion_share(struct ion_client *client,
388 struct ion_handle *handle);
389
390/**
391 * ion_import() - given an buffer in another client, import it
392 * @client: this blocks client
393 * @buffer: the buffer to import (as obtained from ion_share)
394 *
395 * Given a buffer, add it to the client and return the handle to use to refer
396 * to it further. This is called to share a handle from one kernel client to
397 * another.
398 */
399struct ion_handle *ion_import(struct ion_client *client,
400 struct ion_buffer *buffer);
401
402/**
403 * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
404 * @client: this blocks client
405 * @fd: the fd
406 *
407 * A helper function for drivers that will be recieving ion buffers shared
408 * with them from userspace. These buffers are represented by a file
409 * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
410 * This function coverts that fd into the underlying buffer, and returns
411 * the handle to use to refer to it further.
412 */
413struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700414
Laura Abbott273dd8e2011-10-12 14:26:33 -0700415/**
416 * ion_handle_get_flags - get the flags for a given handle
417 *
418 * @client - client who allocated the handle
419 * @handle - handle to get the flags
420 * @flags - pointer to store the flags
421 *
422 * Gets the current flags for a handle. These flags indicate various options
423 * of the buffer (caching, security, etc.)
424 */
425int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
426 unsigned long *flags);
427
Laura Abbott8c017362011-09-22 20:59:12 -0700428
429/**
430 * ion_map_iommu - map the given handle into an iommu
431 *
432 * @client - client who allocated the handle
433 * @handle - handle to map
434 * @domain_num - domain number to map to
435 * @partition_num - partition number to allocate iova from
436 * @align - alignment for the iova
437 * @iova_length - length of iova to map. If the iova length is
438 * greater than the handle length, the remaining
439 * address space will be mapped to a dummy buffer.
440 * @iova - pointer to store the iova address
441 * @buffer_size - pointer to store the size of the buffer
442 * @flags - flags for options to map
Olav Hauganb3676592012-03-02 15:02:25 -0800443 * @iommu_flags - flags specific to the iommu.
Laura Abbott8c017362011-09-22 20:59:12 -0700444 *
445 * Maps the handle into the iova space specified via domain number. Iova
446 * will be allocated from the partition specified via partition_num.
447 * Returns 0 on success, negative value on error.
448 */
449int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
450 int domain_num, int partition_num, unsigned long align,
451 unsigned long iova_length, unsigned long *iova,
452 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800453 unsigned long flags, unsigned long iommu_flags);
Laura Abbott8c017362011-09-22 20:59:12 -0700454
455
456/**
457 * ion_handle_get_size - get the allocated size of a given handle
458 *
459 * @client - client who allocated the handle
460 * @handle - handle to get the size
461 * @size - pointer to store the size
462 *
463 * gives the allocated size of a handle. returns 0 on success, negative
464 * value on error
465 *
466 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
467 * You should *NOT* rely on this for any other usage.
468 */
469
470int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
471 unsigned long *size);
472
473/**
474 * ion_unmap_iommu - unmap the handle from an iommu
475 *
476 * @client - client who allocated the handle
477 * @handle - handle to unmap
478 * @domain_num - domain to unmap from
479 * @partition_num - partition to unmap from
480 *
481 * Decrement the reference count on the iommu mapping. If the count is
482 * 0, the mapping will be removed from the iommu.
483 */
484void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
485 int domain_num, int partition_num);
486
487
Olav Haugan0a852512012-01-09 10:20:55 -0800488/**
489 * ion_secure_heap - secure a heap
490 *
491 * @client - a client that has allocated from the heap heap_id
492 * @heap_id - heap id to secure.
493 *
494 * Secure a heap
495 * Returns 0 on success
496 */
497int ion_secure_heap(struct ion_device *dev, int heap_id);
498
499/**
500 * ion_unsecure_heap - un-secure a heap
501 *
502 * @client - a client that has allocated from the heap heap_id
503 * @heap_id - heap id to un-secure.
504 *
505 * Un-secure a heap
506 * Returns 0 on success
507 */
508int ion_unsecure_heap(struct ion_device *dev, int heap_id);
509
510/**
511 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
512 *
513 * @heap_id - heap id to secure.
514 *
515 * Secure a heap
516 * Returns 0 on success
517 */
518int msm_ion_secure_heap(int heap_id);
519
520/**
521 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
522 *
523 * @heap_id - heap id to secure.
524 *
525 * Un-secure a heap
526 * Returns 0 on success
527 */
528int msm_ion_unsecure_heap(int heap_id);
529
Olav Haugan41f85792012-02-08 15:28:05 -0800530/**
531 * msm_ion_do_cache_op - do cache operations.
532 *
533 * @client - pointer to ION client.
534 * @handle - pointer to buffer handle.
535 * @vaddr - virtual address to operate on.
536 * @len - Length of data to do cache operation on.
537 * @cmd - Cache operation to perform:
538 * ION_IOC_CLEAN_CACHES
539 * ION_IOC_INV_CACHES
540 * ION_IOC_CLEAN_INV_CACHES
541 *
542 * Returns 0 on success
543 */
544int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle,
545 void *vaddr, unsigned long len, unsigned int cmd);
546
Jordan Crouse8cd48322011-10-12 17:05:19 -0600547#else
548static inline struct ion_client *ion_client_create(struct ion_device *dev,
549 unsigned int heap_mask, const char *name)
550{
551 return ERR_PTR(-ENODEV);
552}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700553
Jordan Crouse8cd48322011-10-12 17:05:19 -0600554static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
555 const char *name)
556{
557 return ERR_PTR(-ENODEV);
558}
559
560static inline void ion_client_destroy(struct ion_client *client) { }
561
562static inline struct ion_handle *ion_alloc(struct ion_client *client,
563 size_t len, size_t align, unsigned int flags)
564{
565 return ERR_PTR(-ENODEV);
566}
567
568static inline void ion_free(struct ion_client *client,
569 struct ion_handle *handle) { }
570
571
572static inline int ion_phys(struct ion_client *client,
573 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
574{
575 return -ENODEV;
576}
577
578static inline void *ion_map_kernel(struct ion_client *client,
579 struct ion_handle *handle, unsigned long flags)
580{
581 return ERR_PTR(-ENODEV);
582}
583
584static inline void ion_unmap_kernel(struct ion_client *client,
585 struct ion_handle *handle) { }
586
587static inline struct scatterlist *ion_map_dma(struct ion_client *client,
588 struct ion_handle *handle, unsigned long flags)
589{
590 return ERR_PTR(-ENODEV);
591}
592
593static inline void ion_unmap_dma(struct ion_client *client,
594 struct ion_handle *handle) { }
595
596static inline struct ion_buffer *ion_share(struct ion_client *client,
597 struct ion_handle *handle)
598{
599 return ERR_PTR(-ENODEV);
600}
601
602static inline struct ion_handle *ion_import(struct ion_client *client,
603 struct ion_buffer *buffer)
604{
605 return ERR_PTR(-ENODEV);
606}
607
608static inline struct ion_handle *ion_import_fd(struct ion_client *client,
609 int fd)
610{
611 return ERR_PTR(-ENODEV);
612}
613
614static inline int ion_handle_get_flags(struct ion_client *client,
615 struct ion_handle *handle, unsigned long *flags)
616{
617 return -ENODEV;
618}
Laura Abbott8c017362011-09-22 20:59:12 -0700619
620static inline int ion_map_iommu(struct ion_client *client,
621 struct ion_handle *handle, int domain_num,
622 int partition_num, unsigned long align,
623 unsigned long iova_length, unsigned long *iova,
Olav Haugan9a27d4c2012-02-23 09:35:16 -0800624 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800625 unsigned long flags,
626 unsigned long iommu_flags)
Laura Abbott8c017362011-09-22 20:59:12 -0700627{
628 return -ENODEV;
629}
630
631static inline void ion_unmap_iommu(struct ion_client *client,
632 struct ion_handle *handle, int domain_num,
633 int partition_num)
634{
635 return;
636}
637
Olav Haugan0a852512012-01-09 10:20:55 -0800638static inline int ion_secure_heap(struct ion_device *dev, int heap_id)
639{
640 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700641
Olav Haugan0a852512012-01-09 10:20:55 -0800642}
643
644static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id)
645{
646 return -ENODEV;
647}
648
649static inline int msm_ion_secure_heap(int heap_id)
650{
651 return -ENODEV;
652
653}
654
655static inline int msm_ion_unsecure_heap(int heap_id)
656{
657 return -ENODEV;
658}
Olav Haugan41f85792012-02-08 15:28:05 -0800659
660static inline int msm_ion_do_cache_op(struct ion_client *client,
661 struct ion_handle *handle, void *vaddr,
662 unsigned long len, unsigned int cmd)
663{
664 return -ENODEV;
665}
666
Jordan Crouse8cd48322011-10-12 17:05:19 -0600667#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700668#endif /* __KERNEL__ */
669
670/**
671 * DOC: Ion Userspace API
672 *
673 * create a client by opening /dev/ion
674 * most operations handled via following ioctls
675 *
676 */
677
678/**
679 * struct ion_allocation_data - metadata passed from userspace for allocations
680 * @len: size of the allocation
681 * @align: required alignment of the allocation
682 * @flags: flags passed to heap
683 * @handle: pointer that will be populated with a cookie to use to refer
684 * to this allocation
685 *
686 * Provided by userspace as an argument to the ioctl
687 */
688struct ion_allocation_data {
689 size_t len;
690 size_t align;
691 unsigned int flags;
692 struct ion_handle *handle;
693};
694
695/**
696 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
697 * @handle: a handle
698 * @fd: a file descriptor representing that handle
699 *
700 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
701 * the handle returned from ion alloc, and the kernel returns the file
702 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
703 * provides the file descriptor and the kernel returns the handle.
704 */
705struct ion_fd_data {
706 struct ion_handle *handle;
707 int fd;
708};
709
710/**
711 * struct ion_handle_data - a handle passed to/from the kernel
712 * @handle: a handle
713 */
714struct ion_handle_data {
715 struct ion_handle *handle;
716};
717
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700718/**
719 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
720 * @cmd: the custom ioctl function to call
721 * @arg: additional data to pass to the custom ioctl, typically a user
722 * pointer to a predefined structure
723 *
724 * This works just like the regular cmd and arg fields of an ioctl.
725 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700726struct ion_custom_data {
727 unsigned int cmd;
728 unsigned long arg;
729};
730
Laura Abbottabcb6f72011-10-04 16:26:49 -0700731
732/* struct ion_flush_data - data passed to ion for flushing caches
733 *
734 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800735 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700736 * @vaddr: userspace virtual address mapped with mmap
737 * @offset: offset into the handle to flush
738 * @length: length of handle to flush
739 *
740 * Performs cache operations on the handle. If p is the start address
741 * of the handle, p + offset through p + offset + length will have
742 * the cache operations performed
743 */
744struct ion_flush_data {
745 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800746 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700747 void *vaddr;
748 unsigned int offset;
749 unsigned int length;
750};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700751
752/* struct ion_flag_data - information about flags for this buffer
753 *
754 * @handle: handle to get flags from
755 * @flags: flags of this handle
756 *
757 * Takes handle as an input and outputs the flags from the handle
758 * in the flag field.
759 */
760struct ion_flag_data {
761 struct ion_handle *handle;
762 unsigned long flags;
763};
764
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700765#define ION_IOC_MAGIC 'I'
766
767/**
768 * DOC: ION_IOC_ALLOC - allocate memory
769 *
770 * Takes an ion_allocation_data struct and returns it with the handle field
771 * populated with the opaque handle for the allocation.
772 */
773#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
774 struct ion_allocation_data)
775
776/**
777 * DOC: ION_IOC_FREE - free memory
778 *
779 * Takes an ion_handle_data struct and frees the handle.
780 */
781#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
782
783/**
784 * DOC: ION_IOC_MAP - get a file descriptor to mmap
785 *
786 * Takes an ion_fd_data struct with the handle field populated with a valid
787 * opaque handle. Returns the struct with the fd field set to a file
788 * descriptor open in the current address space. This file descriptor
789 * can then be used as an argument to mmap.
790 */
791#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
792
793/**
794 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
795 *
796 * Takes an ion_fd_data struct with the handle field populated with a valid
797 * opaque handle. Returns the struct with the fd field set to a file
798 * descriptor open in the current address space. This file descriptor
799 * can then be passed to another process. The corresponding opaque handle can
800 * be retrieved via ION_IOC_IMPORT.
801 */
802#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
803
804/**
805 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
806 *
807 * Takes an ion_fd_data struct with the fd field populated with a valid file
808 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
809 * filed set to the corresponding opaque handle.
810 */
811#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
812
813/**
814 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
815 *
816 * Takes the argument of the architecture specific ioctl to call and
817 * passes appropriate userdata for that ioctl
818 */
819#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
820
Laura Abbottabcb6f72011-10-04 16:26:49 -0700821
822/**
823 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
824 *
825 * Clean the caches of the handle specified.
826 */
827#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
828 struct ion_flush_data)
829/**
830 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
831 *
832 * Invalidate the caches of the handle specified.
833 */
834#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
835 struct ion_flush_data)
836/**
837 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
838 *
839 * Clean and invalidate the caches of the handle specified.
840 */
841#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
842 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700843
844/**
845 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
846 *
847 * Gets the flags of the current handle which indicate cachability,
848 * secure state etc.
849 */
850#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
851 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700852#endif /* _LINUX_ION_H */