blob: 1d700c223986293003e30b20d4c89a797d130425 [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
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.
36 * @ION_HEAP_END: helper for iterating over heaps
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070037 */
38enum ion_heap_type {
39 ION_HEAP_TYPE_SYSTEM,
40 ION_HEAP_TYPE_SYSTEM_CONTIG,
41 ION_HEAP_TYPE_CARVEOUT,
Laura Abbott8c017362011-09-22 20:59:12 -070042 ION_HEAP_TYPE_IOMMU,
Olav Haugan0a852512012-01-09 10:20:55 -080043 ION_HEAP_TYPE_CP,
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)
Olav Haugan0a852512012-01-09 10:20:55 -080052#define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070053
Mitchel Humpherys97e21232012-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
63/**
64 * These are the only ids that should be used for Ion heap ids.
65 * The ids listed are the order in which allocation will be attempted
66 * if specified. Don't swap the order of heap ids unless you know what
67 * you are doing!
Olav Hauganb5be7992011-11-18 14:29:02 -080068 * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
69 * possible fallbacks)
Laura Abbotta2e93632011-08-19 13:36:32 -070070 */
71
72enum ion_heap_ids {
Olav Haugan42ebe712012-01-10 16:30:58 -080073 INVALID_HEAP_ID = -1,
Olav Hauganb5be7992011-11-18 14:29:02 -080074 ION_CP_MM_HEAP_ID = 8,
75 ION_CP_MFC_HEAP_ID = 12,
76 ION_CP_WB_HEAP_ID = 16, /* 8660 only */
77 ION_CAMERA_HEAP_ID = 20, /* 8660 only */
78 ION_SF_HEAP_ID = 24,
Olav Haugan9e123f92012-02-15 15:41:48 -080079 ION_IOMMU_HEAP_ID = 25,
Olav Haugan80854eb2012-01-12 12:00:23 -080080 ION_QSECOM_HEAP_ID = 27,
Olav Hauganb5be7992011-11-18 14:29:02 -080081 ION_AUDIO_HEAP_ID = 28,
82
Olav Haugan42ebe712012-01-10 16:30:58 -080083 ION_MM_FIRMWARE_HEAP_ID = 29,
Olav Hauganb5be7992011-11-18 14:29:02 -080084 ION_SYSTEM_HEAP_ID = 30,
85
86 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
Laura Abbotta2e93632011-08-19 13:36:32 -070087};
88
Larry Bassel2d8b42d2012-03-12 10:41:26 -070089enum ion_fixed_position {
90 NOT_FIXED,
91 FIXED_LOW,
92 FIXED_MIDDLE,
93 FIXED_HIGH,
94};
95
Laura Abbottd0c83de2012-06-12 18:49:57 -070096enum cp_mem_usage {
97 VIDEO_BITSTREAM = 0x1,
98 VIDEO_PIXEL = 0x2,
99 VIDEO_NONPIXEL = 0x3,
100 MAX_USAGE = 0x4,
101 UNKNOWN = 0x7FFFFFFF,
102};
103
Olav Hauganb5be7992011-11-18 14:29:02 -0800104/**
105 * Flag to use when allocating to indicate that a heap is secure.
106 */
107#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
108
109/**
110 * Macro should be used with ion_heap_ids defined above.
111 */
112#define ION_HEAP(bit) (1 << (bit))
113
Laura Abbotta2e93632011-08-19 13:36:32 -0700114#define ION_VMALLOC_HEAP_NAME "vmalloc"
Olav Hauganb5be7992011-11-18 14:29:02 -0800115#define ION_AUDIO_HEAP_NAME "audio"
116#define ION_SF_HEAP_NAME "sf"
117#define ION_MM_HEAP_NAME "mm"
118#define ION_CAMERA_HEAP_NAME "camera_preview"
Laura Abbott8c017362011-09-22 20:59:12 -0700119#define ION_IOMMU_HEAP_NAME "iommu"
Olav Hauganb5be7992011-11-18 14:29:02 -0800120#define ION_MFC_HEAP_NAME "mfc"
121#define ION_WB_HEAP_NAME "wb"
Olav Haugan42ebe712012-01-10 16:30:58 -0800122#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Olav Haugan80854eb2012-01-12 12:00:23 -0800123#define ION_QSECOM_HEAP_NAME "qsecom"
Laura Abbottcaafeea2011-12-13 11:43:10 -0800124#define ION_FMEM_HEAP_NAME "fmem"
Laura Abbotta2e93632011-08-19 13:36:32 -0700125
Laura Abbott894fd582011-08-19 13:33:56 -0700126#define CACHED 1
127#define UNCACHED 0
128
Mitchel Humpherys97e21232012-09-11 15:59:11 -0700129#define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED)
130#define ION_SET_UNCACHED(__cache) (__cache & ~ION_FLAG_CACHED)
Laura Abbott894fd582011-08-19 13:33:56 -0700131
Mitchel Humpherys97e21232012-09-11 15:59:11 -0700132#define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED)
Laura Abbott894fd582011-08-19 13:33:56 -0700133
Laura Abbott35412032011-09-29 09:50:06 -0700134
Olav Hauganb3676592012-03-02 15:02:25 -0800135/*
136 * This flag allows clients when mapping into the IOMMU to specify to
137 * defer un-mapping from the IOMMU until the buffer memory is freed.
138 */
139#define ION_IOMMU_UNMAP_DELAYED 1
140
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700141#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700142#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700143#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700144struct ion_device;
145struct ion_heap;
146struct ion_mapper;
147struct ion_client;
148struct ion_buffer;
149
150/* This should be removed some day when phys_addr_t's are fully
151 plumbed in the kernel, and all instances of ion_phys_addr_t should
152 be converted to phys_addr_t. For the time being many kernel interfaces
153 do not accept phys_addr_t's that would have to */
154#define ion_phys_addr_t unsigned long
Laura Abbottcaafeea2011-12-13 11:43:10 -0800155#define ion_virt_addr_t unsigned long
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700156
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700157/**
158 * struct ion_platform_heap - defines a heap in the given platform
159 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800160 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800161 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700162 * @name: used for debug purposes
163 * @base: base address of heap in physical memory if applicable
164 * @size: size of the heap in bytes if applicable
Laura Abbottcaafeea2011-12-13 11:43:10 -0800165 * @memory_type:Memory type used for the heap
Olav Haugan85c95402012-05-30 17:32:37 -0700166 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800167 * @extra_data: Extra data specific to each heap type
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700168 */
169struct ion_platform_heap {
170 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700171 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700172 const char *name;
173 ion_phys_addr_t base;
174 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700175 enum ion_memory_types memory_type;
Olav Haugan85c95402012-05-30 17:32:37 -0700176 unsigned int has_outer_cache;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800177 void *extra_data;
178};
179
Laura Abbottcaafeea2011-12-13 11:43:10 -0800180/**
181 * struct ion_cp_heap_pdata - defines a content protection heap in the given
182 * platform
183 * @permission_type: Memory ID used to identify the memory to TZ
184 * @align: Alignment requirement for the memory
185 * @secure_base: Base address for securing the heap.
186 * Note: This might be different from actual base address
187 * of this heap in the case of a shared heap.
188 * @secure_size: Memory size for securing the heap.
189 * Note: This might be different from actual size
190 * of this heap in the case of a shared heap.
191 * @reusable Flag indicating whether this heap is reusable of not.
192 * (see FMEM)
Olav Hauganf6dc7742012-02-15 09:11:55 -0800193 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
194 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700195 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800196 * @virt_addr: Virtual address used when using fmem.
Olav Haugan8726caf2012-05-10 15:11:35 -0700197 * @iommu_map_all: Indicates whether we should map whole heap into IOMMU.
198 * @iommu_2x_map_domain: Indicates the domain to use for overmapping.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800199 * @request_region: function to be called when the number of allocations
200 * goes from 0 -> 1
201 * @release_region: function to be called when the number of allocations
202 * goes from 1 -> 0
203 * @setup_region: function to be called upon ion registration
204 *
205 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800206struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800207 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800208 unsigned int align;
209 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
210 size_t secure_size; /* Size used for securing heap when heap is shared*/
Laura Abbottcaafeea2011-12-13 11:43:10 -0800211 int reusable;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800212 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700213 enum ion_fixed_position fixed_position;
Olav Haugan8726caf2012-05-10 15:11:35 -0700214 int iommu_map_all;
215 int iommu_2x_map_domain;
Laura Abbottcaafeea2011-12-13 11:43:10 -0800216 ion_virt_addr_t *virt_addr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800217 int (*request_region)(void *);
218 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800219 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700220};
221
Laura Abbottcaafeea2011-12-13 11:43:10 -0800222/**
223 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
224 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
225 * @align: Alignment requirement for the memory
Olav Hauganf6dc7742012-02-15 09:11:55 -0800226 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
227 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700228 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800229 * @request_region: function to be called when the number of allocations
230 * goes from 0 -> 1
231 * @release_region: function to be called when the number of allocations
232 * goes from 1 -> 0
233 * @setup_region: function to be called upon ion registration
234 *
235 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800236struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800237 int adjacent_mem_id;
238 unsigned int align;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800239 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700240 enum ion_fixed_position fixed_position;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800241 int (*request_region)(void *);
242 int (*release_region)(void *);
243 void *(*setup_region)(void);
244};
245
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700246/**
247 * struct ion_platform_data - array of platform heaps passed from board file
Olav Haugan85c95402012-05-30 17:32:37 -0700248 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Alex Bird27ca6612011-11-01 14:40:06 -0700249 * @nr: number of structures in the array
250 * @request_region: function to be called when the number of allocations goes
251 * from 0 -> 1
252 * @release_region: function to be called when the number of allocations goes
253 * from 1 -> 0
254 * @setup_region: function to be called upon ion registration
255 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700256 *
257 * Provided by the board file in the form of platform data to a platform device.
258 */
259struct ion_platform_data {
Olav Haugan85c95402012-05-30 17:32:37 -0700260 unsigned int has_outer_cache;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700261 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800262 int (*request_region)(void *);
263 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700264 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700265 struct ion_platform_heap heaps[];
266};
267
Jordan Crouse8cd48322011-10-12 17:05:19 -0600268#ifdef CONFIG_ION
269
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700270/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800271 * ion_reserve() - reserve memory for ion heaps if applicable
272 * @data: platform data specifying starting physical address and
273 * size
274 *
275 * Calls memblock reserve to set aside memory for heaps that are
276 * located at specific memory addresses or of specfic sizes not
277 * managed by the kernel
278 */
279void ion_reserve(struct ion_platform_data *data);
280
281/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700282 * ion_client_create() - allocate a client and returns it
283 * @dev: the global ion device
284 * @heap_mask: mask of heaps this client can allocate from
285 * @name: used for debugging
286 */
287struct ion_client *ion_client_create(struct ion_device *dev,
288 unsigned int heap_mask, const char *name);
289
290/**
Laura Abbott302911d2011-08-15 17:12:57 -0700291 * msm_ion_client_create - allocate a client using the ion_device specified in
292 * drivers/gpu/ion/msm/msm_ion.c
293 *
294 * heap_mask and name are the same as ion_client_create, return values
295 * are the same as ion_client_create.
296 */
297
298struct ion_client *msm_ion_client_create(unsigned int heap_mask,
299 const char *name);
300
301/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700302 * ion_client_destroy() - free's a client and all it's handles
303 * @client: the client
304 *
305 * Free the provided client and all it's resources including
306 * any handles it is holding.
307 */
308void ion_client_destroy(struct ion_client *client);
309
310/**
311 * ion_alloc - allocate ion memory
312 * @client: the client
313 * @len: size of the allocation
314 * @align: requested allocation alignment, lots of hardware blocks have
315 * alignment requirements of some kind
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700316 * @heap_mask: mask of heaps to allocate from, if multiple bits are set
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700317 * heaps will be tried in order from lowest to highest order bit
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700318 * @flags: heap flags, the low 16 bits are consumed by ion, the high 16
319 * bits are passed on to the respective heap and can be heap
320 * custom
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700321 *
322 * Allocate memory in one of the heaps provided in heap mask and return
323 * an opaque handle to it.
324 */
325struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700326 size_t align, unsigned int heap_mask,
327 unsigned int flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700328
329/**
330 * ion_free - free a handle
331 * @client: the client
332 * @handle: the handle to free
333 *
334 * Free the provided handle.
335 */
336void ion_free(struct ion_client *client, struct ion_handle *handle);
337
338/**
339 * ion_phys - returns the physical address and len of a handle
340 * @client: the client
341 * @handle: the handle
342 * @addr: a pointer to put the address in
343 * @len: a pointer to put the length in
344 *
345 * This function queries the heap for a particular handle to get the
346 * handle's physical address. It't output is only correct if
347 * a heap returns physically contiguous memory -- in other cases
Laura Abbottb14ed962012-01-30 14:18:08 -0800348 * this api should not be implemented -- ion_sg_table should be used
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700349 * instead. Returns -EINVAL if the handle is invalid. This has
350 * no implications on the reference counting of the handle --
351 * the returned value may not be valid if the caller is not
352 * holding a reference.
353 */
354int ion_phys(struct ion_client *client, struct ion_handle *handle,
355 ion_phys_addr_t *addr, size_t *len);
356
357/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800358 * ion_map_dma - return an sg_table describing a handle
359 * @client: the client
360 * @handle: the handle
361 *
362 * This function returns the sg_table describing
363 * a particular ion handle.
364 */
365struct sg_table *ion_sg_table(struct ion_client *client,
366 struct ion_handle *handle);
367
368/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700369 * ion_map_kernel - create mapping for the given handle
370 * @client: the client
371 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700372 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700373 *
374 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700375 * can be used to access this address. If no flags are specified, this
376 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700377 */
Laura Abbott894fd582011-08-19 13:33:56 -0700378void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
379 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700380
381/**
382 * ion_unmap_kernel() - destroy a kernel mapping for a handle
383 * @client: the client
384 * @handle: handle to unmap
385 */
386void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
387
388/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800389 * ion_share_dma_buf() - given an ion client, create a dma-buf fd
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700390 * @client: the client
Laura Abbottb14ed962012-01-30 14:18:08 -0800391 * @handle: the handle
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700392 */
Laura Abbottb14ed962012-01-30 14:18:08 -0800393int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700394
395/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800396 * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700397 * @client: the client
Laura Abbottb14ed962012-01-30 14:18:08 -0800398 * @fd: the dma-buf fd
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700399 *
Laura Abbottb14ed962012-01-30 14:18:08 -0800400 * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
401 * import that fd and return a handle representing it. If a dma-buf from
402 * another exporter is passed in this function will return ERR_PTR(-EINVAL)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700403 */
Laura Abbottb14ed962012-01-30 14:18:08 -0800404struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700405
Laura Abbott273dd8e2011-10-12 14:26:33 -0700406/**
407 * ion_handle_get_flags - get the flags for a given handle
408 *
409 * @client - client who allocated the handle
410 * @handle - handle to get the flags
411 * @flags - pointer to store the flags
412 *
413 * Gets the current flags for a handle. These flags indicate various options
414 * of the buffer (caching, security, etc.)
415 */
416int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
417 unsigned long *flags);
418
Laura Abbott8c017362011-09-22 20:59:12 -0700419
420/**
421 * ion_map_iommu - map the given handle into an iommu
422 *
423 * @client - client who allocated the handle
424 * @handle - handle to map
425 * @domain_num - domain number to map to
426 * @partition_num - partition number to allocate iova from
427 * @align - alignment for the iova
428 * @iova_length - length of iova to map. If the iova length is
429 * greater than the handle length, the remaining
430 * address space will be mapped to a dummy buffer.
431 * @iova - pointer to store the iova address
432 * @buffer_size - pointer to store the size of the buffer
433 * @flags - flags for options to map
Olav Hauganb3676592012-03-02 15:02:25 -0800434 * @iommu_flags - flags specific to the iommu.
Laura Abbott8c017362011-09-22 20:59:12 -0700435 *
436 * Maps the handle into the iova space specified via domain number. Iova
437 * will be allocated from the partition specified via partition_num.
438 * Returns 0 on success, negative value on error.
439 */
440int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
441 int domain_num, int partition_num, unsigned long align,
442 unsigned long iova_length, unsigned long *iova,
443 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800444 unsigned long flags, unsigned long iommu_flags);
Laura Abbott8c017362011-09-22 20:59:12 -0700445
446
447/**
448 * ion_handle_get_size - get the allocated size of a given handle
449 *
450 * @client - client who allocated the handle
451 * @handle - handle to get the size
452 * @size - pointer to store the size
453 *
454 * gives the allocated size of a handle. returns 0 on success, negative
455 * value on error
456 *
457 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
458 * You should *NOT* rely on this for any other usage.
459 */
460
461int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
462 unsigned long *size);
463
464/**
465 * ion_unmap_iommu - unmap the handle from an iommu
466 *
467 * @client - client who allocated the handle
468 * @handle - handle to unmap
469 * @domain_num - domain to unmap from
470 * @partition_num - partition to unmap from
471 *
472 * Decrement the reference count on the iommu mapping. If the count is
473 * 0, the mapping will be removed from the iommu.
474 */
475void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
476 int domain_num, int partition_num);
477
478
Olav Haugan0a852512012-01-09 10:20:55 -0800479/**
480 * ion_secure_heap - secure a heap
481 *
482 * @client - a client that has allocated from the heap heap_id
483 * @heap_id - heap id to secure.
Laura Abbott7e446482012-06-13 15:59:39 -0700484 * @version - version of content protection
485 * @data - extra data needed for protection
Olav Haugan0a852512012-01-09 10:20:55 -0800486 *
487 * Secure a heap
488 * Returns 0 on success
489 */
Laura Abbott7e446482012-06-13 15:59:39 -0700490int ion_secure_heap(struct ion_device *dev, int heap_id, int version,
491 void *data);
Olav Haugan0a852512012-01-09 10:20:55 -0800492
493/**
494 * ion_unsecure_heap - un-secure a heap
495 *
496 * @client - a client that has allocated from the heap heap_id
497 * @heap_id - heap id to un-secure.
Laura Abbott7e446482012-06-13 15:59:39 -0700498 * @version - version of content protection
499 * @data - extra data needed for protection
Olav Haugan0a852512012-01-09 10:20:55 -0800500 *
501 * Un-secure a heap
502 * Returns 0 on success
503 */
Laura Abbott7e446482012-06-13 15:59:39 -0700504int ion_unsecure_heap(struct ion_device *dev, int heap_id, int version,
505 void *data);
Olav Haugan0a852512012-01-09 10:20:55 -0800506
507/**
508 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
509 *
510 * @heap_id - heap id to secure.
511 *
512 * Secure a heap
513 * Returns 0 on success
514 */
515int msm_ion_secure_heap(int heap_id);
516
517/**
518 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
519 *
520 * @heap_id - heap id to secure.
521 *
522 * Un-secure a heap
523 * Returns 0 on success
524 */
525int msm_ion_unsecure_heap(int heap_id);
526
Olav Haugan41f85792012-02-08 15:28:05 -0800527/**
Laura Abbott7e446482012-06-13 15:59:39 -0700528 * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs
529 * Wrapper around ion_secure_heap.
530 *
531 * @heap_id - heap id to secure.
532 * @usage - usage hint to TZ
533 *
534 * Secure a heap
535 * Returns 0 on success
536 */
537int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage);
538
539/**
540 * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs.
541 * Wrapper around ion_unsecure_heap.
542 *
543 * @heap_id - heap id to secure.
544 * @usage - usage hint to TZ
545 *
546 * Un-secure a heap
547 * Returns 0 on success
548 */
549int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage);
550
551/**
Olav Haugan41f85792012-02-08 15:28:05 -0800552 * msm_ion_do_cache_op - do cache operations.
553 *
554 * @client - pointer to ION client.
555 * @handle - pointer to buffer handle.
556 * @vaddr - virtual address to operate on.
557 * @len - Length of data to do cache operation on.
558 * @cmd - Cache operation to perform:
559 * ION_IOC_CLEAN_CACHES
560 * ION_IOC_INV_CACHES
561 * ION_IOC_CLEAN_INV_CACHES
562 *
563 * Returns 0 on success
564 */
565int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle,
566 void *vaddr, unsigned long len, unsigned int cmd);
567
Jordan Crouse8cd48322011-10-12 17:05:19 -0600568#else
Laura Abbottb14ed962012-01-30 14:18:08 -0800569static inline void ion_reserve(struct ion_platform_data *data)
570{
571
572}
573
Jordan Crouse8cd48322011-10-12 17:05:19 -0600574static inline struct ion_client *ion_client_create(struct ion_device *dev,
575 unsigned int heap_mask, const char *name)
576{
577 return ERR_PTR(-ENODEV);
578}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700579
Jordan Crouse8cd48322011-10-12 17:05:19 -0600580static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
581 const char *name)
582{
583 return ERR_PTR(-ENODEV);
584}
585
586static inline void ion_client_destroy(struct ion_client *client) { }
587
588static inline struct ion_handle *ion_alloc(struct ion_client *client,
Hanumant Singh2ac41c92012-08-29 18:39:44 -0700589 size_t len, size_t align,
590 unsigned int heap_mask,
591 unsigned int flags)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600592{
593 return ERR_PTR(-ENODEV);
594}
595
596static inline void ion_free(struct ion_client *client,
597 struct ion_handle *handle) { }
598
599
600static inline int ion_phys(struct ion_client *client,
601 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
602{
603 return -ENODEV;
604}
605
Laura Abbottb14ed962012-01-30 14:18:08 -0800606static inline struct sg_table *ion_sg_table(struct ion_client *client,
607 struct ion_handle *handle)
608{
609 return ERR_PTR(-ENODEV);
610}
611
Jordan Crouse8cd48322011-10-12 17:05:19 -0600612static inline void *ion_map_kernel(struct ion_client *client,
613 struct ion_handle *handle, unsigned long flags)
614{
615 return ERR_PTR(-ENODEV);
616}
617
618static inline void ion_unmap_kernel(struct ion_client *client,
619 struct ion_handle *handle) { }
620
Laura Abbottb14ed962012-01-30 14:18:08 -0800621static inline int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600622{
Laura Abbottb14ed962012-01-30 14:18:08 -0800623 return -ENODEV;
Jordan Crouse8cd48322011-10-12 17:05:19 -0600624}
625
Laura Abbottb14ed962012-01-30 14:18:08 -0800626static inline struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600627{
628 return ERR_PTR(-ENODEV);
629}
630
631static inline int ion_handle_get_flags(struct ion_client *client,
632 struct ion_handle *handle, unsigned long *flags)
633{
634 return -ENODEV;
635}
Laura Abbott8c017362011-09-22 20:59:12 -0700636
637static inline int ion_map_iommu(struct ion_client *client,
638 struct ion_handle *handle, int domain_num,
639 int partition_num, unsigned long align,
640 unsigned long iova_length, unsigned long *iova,
Olav Haugan9a27d4c2012-02-23 09:35:16 -0800641 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800642 unsigned long flags,
643 unsigned long iommu_flags)
Laura Abbott8c017362011-09-22 20:59:12 -0700644{
645 return -ENODEV;
646}
647
648static inline void ion_unmap_iommu(struct ion_client *client,
649 struct ion_handle *handle, int domain_num,
650 int partition_num)
651{
652 return;
653}
654
Laura Abbott7e446482012-06-13 15:59:39 -0700655static inline int ion_secure_heap(struct ion_device *dev, int heap_id,
656 int version, void *data)
Olav Haugan0a852512012-01-09 10:20:55 -0800657{
658 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700659
Olav Haugan0a852512012-01-09 10:20:55 -0800660}
661
Laura Abbott7e446482012-06-13 15:59:39 -0700662static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id,
663 int version, void *data)
Olav Haugan0a852512012-01-09 10:20:55 -0800664{
665 return -ENODEV;
666}
667
668static inline int msm_ion_secure_heap(int heap_id)
669{
670 return -ENODEV;
671
672}
673
674static inline int msm_ion_unsecure_heap(int heap_id)
675{
676 return -ENODEV;
677}
Olav Haugan41f85792012-02-08 15:28:05 -0800678
Laura Abbott7e446482012-06-13 15:59:39 -0700679static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage)
680{
681 return -ENODEV;
682}
683
684static inline int msm_ion_unsecure_heap_2_0(int heap_id,
685 enum cp_mem_usage usage)
686{
687 return -ENODEV;
688}
689
Olav Haugan41f85792012-02-08 15:28:05 -0800690static inline int msm_ion_do_cache_op(struct ion_client *client,
691 struct ion_handle *handle, void *vaddr,
692 unsigned long len, unsigned int cmd)
693{
694 return -ENODEV;
695}
696
Jordan Crouse8cd48322011-10-12 17:05:19 -0600697#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700698#endif /* __KERNEL__ */
699
700/**
701 * DOC: Ion Userspace API
702 *
703 * create a client by opening /dev/ion
704 * most operations handled via following ioctls
705 *
706 */
707
708/**
709 * struct ion_allocation_data - metadata passed from userspace for allocations
710 * @len: size of the allocation
711 * @align: required alignment of the allocation
Brian Muramatsub6b0b652012-07-30 22:54:08 -0700712 * @heap_mask: mask of heaps to allocate from
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700713 * @flags: flags passed to heap
714 * @handle: pointer that will be populated with a cookie to use to refer
715 * to this allocation
716 *
717 * Provided by userspace as an argument to the ioctl
718 */
719struct ion_allocation_data {
720 size_t len;
721 size_t align;
Brian Muramatsub6b0b652012-07-30 22:54:08 -0700722 unsigned int heap_mask;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700723 unsigned int flags;
724 struct ion_handle *handle;
725};
726
727/**
728 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
729 * @handle: a handle
730 * @fd: a file descriptor representing that handle
731 *
732 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
733 * the handle returned from ion alloc, and the kernel returns the file
734 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
735 * provides the file descriptor and the kernel returns the handle.
736 */
737struct ion_fd_data {
738 struct ion_handle *handle;
739 int fd;
740};
741
742/**
743 * struct ion_handle_data - a handle passed to/from the kernel
744 * @handle: a handle
745 */
746struct ion_handle_data {
747 struct ion_handle *handle;
748};
749
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700750/**
751 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
752 * @cmd: the custom ioctl function to call
753 * @arg: additional data to pass to the custom ioctl, typically a user
754 * pointer to a predefined structure
755 *
756 * This works just like the regular cmd and arg fields of an ioctl.
757 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700758struct ion_custom_data {
759 unsigned int cmd;
760 unsigned long arg;
761};
762
Laura Abbottabcb6f72011-10-04 16:26:49 -0700763
764/* struct ion_flush_data - data passed to ion for flushing caches
765 *
766 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800767 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700768 * @vaddr: userspace virtual address mapped with mmap
769 * @offset: offset into the handle to flush
770 * @length: length of handle to flush
771 *
772 * Performs cache operations on the handle. If p is the start address
773 * of the handle, p + offset through p + offset + length will have
774 * the cache operations performed
775 */
776struct ion_flush_data {
777 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800778 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700779 void *vaddr;
780 unsigned int offset;
781 unsigned int length;
782};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700783
784/* struct ion_flag_data - information about flags for this buffer
785 *
786 * @handle: handle to get flags from
787 * @flags: flags of this handle
788 *
789 * Takes handle as an input and outputs the flags from the handle
790 * in the flag field.
791 */
792struct ion_flag_data {
793 struct ion_handle *handle;
794 unsigned long flags;
795};
796
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700797#define ION_IOC_MAGIC 'I'
798
799/**
800 * DOC: ION_IOC_ALLOC - allocate memory
801 *
802 * Takes an ion_allocation_data struct and returns it with the handle field
803 * populated with the opaque handle for the allocation.
804 */
805#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
806 struct ion_allocation_data)
807
808/**
809 * DOC: ION_IOC_FREE - free memory
810 *
811 * Takes an ion_handle_data struct and frees the handle.
812 */
813#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
814
815/**
816 * DOC: ION_IOC_MAP - get a file descriptor to mmap
817 *
818 * Takes an ion_fd_data struct with the handle field populated with a valid
819 * opaque handle. Returns the struct with the fd field set to a file
820 * descriptor open in the current address space. This file descriptor
821 * can then be used as an argument to mmap.
822 */
823#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
824
825/**
826 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
827 *
828 * Takes an ion_fd_data struct with the handle field populated with a valid
829 * opaque handle. Returns the struct with the fd field set to a file
830 * descriptor open in the current address space. This file descriptor
831 * can then be passed to another process. The corresponding opaque handle can
832 * be retrieved via ION_IOC_IMPORT.
833 */
834#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
835
836/**
837 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
838 *
839 * Takes an ion_fd_data struct with the fd field populated with a valid file
840 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
841 * filed set to the corresponding opaque handle.
842 */
Ajay Dudanif572d262012-08-29 18:02:11 -0700843#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700844
845/**
846 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
847 *
848 * Takes the argument of the architecture specific ioctl to call and
849 * passes appropriate userdata for that ioctl
850 */
851#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
852
Laura Abbottabcb6f72011-10-04 16:26:49 -0700853
854/**
855 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
856 *
857 * Clean the caches of the handle specified.
858 */
Ajay Dudanif572d262012-08-29 18:02:11 -0700859#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 20, \
Laura Abbottabcb6f72011-10-04 16:26:49 -0700860 struct ion_flush_data)
861/**
862 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
863 *
864 * Invalidate the caches of the handle specified.
865 */
Ajay Dudanif572d262012-08-29 18:02:11 -0700866#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 21, \
Laura Abbottabcb6f72011-10-04 16:26:49 -0700867 struct ion_flush_data)
868/**
869 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
870 *
871 * Clean and invalidate the caches of the handle specified.
872 */
Ajay Dudanif572d262012-08-29 18:02:11 -0700873#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 22, \
Laura Abbottabcb6f72011-10-04 16:26:49 -0700874 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700875
876/**
877 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
878 *
879 * Gets the flags of the current handle which indicate cachability,
880 * secure state etc.
881 */
Ajay Dudanif572d262012-08-29 18:02:11 -0700882#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 23, \
Laura Abbott273dd8e2011-10-12 14:26:33 -0700883 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700884#endif /* _LINUX_ION_H */