blob: 251927064f69e2af73a66e89ac9ef9110e3034bd [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
Laura Abbotta2e93632011-08-19 13:36:32 -070054
55/**
56 * These are the only ids that should be used for Ion heap ids.
57 * The ids listed are the order in which allocation will be attempted
58 * if specified. Don't swap the order of heap ids unless you know what
59 * you are doing!
Olav Hauganb5be7992011-11-18 14:29:02 -080060 * Id's are spaced by purpose to allow new Id's to be inserted in-between (for
61 * possible fallbacks)
Laura Abbotta2e93632011-08-19 13:36:32 -070062 */
63
64enum ion_heap_ids {
Olav Haugan42ebe712012-01-10 16:30:58 -080065 INVALID_HEAP_ID = -1,
Olav Hauganb5be7992011-11-18 14:29:02 -080066 ION_CP_MM_HEAP_ID = 8,
67 ION_CP_MFC_HEAP_ID = 12,
68 ION_CP_WB_HEAP_ID = 16, /* 8660 only */
69 ION_CAMERA_HEAP_ID = 20, /* 8660 only */
70 ION_SF_HEAP_ID = 24,
Olav Haugan9e123f92012-02-15 15:41:48 -080071 ION_IOMMU_HEAP_ID = 25,
Olav Haugan80854eb2012-01-12 12:00:23 -080072 ION_QSECOM_HEAP_ID = 27,
Olav Hauganb5be7992011-11-18 14:29:02 -080073 ION_AUDIO_HEAP_ID = 28,
74
Olav Haugan42ebe712012-01-10 16:30:58 -080075 ION_MM_FIRMWARE_HEAP_ID = 29,
Olav Hauganb5be7992011-11-18 14:29:02 -080076 ION_SYSTEM_HEAP_ID = 30,
77
78 ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */
Laura Abbotta2e93632011-08-19 13:36:32 -070079};
80
Larry Bassel2d8b42d2012-03-12 10:41:26 -070081enum ion_fixed_position {
82 NOT_FIXED,
83 FIXED_LOW,
84 FIXED_MIDDLE,
85 FIXED_HIGH,
86};
87
Laura Abbottd0c83de2012-06-12 18:49:57 -070088enum cp_mem_usage {
89 VIDEO_BITSTREAM = 0x1,
90 VIDEO_PIXEL = 0x2,
91 VIDEO_NONPIXEL = 0x3,
92 MAX_USAGE = 0x4,
93 UNKNOWN = 0x7FFFFFFF,
94};
95
Olav Hauganb5be7992011-11-18 14:29:02 -080096/**
97 * Flag to use when allocating to indicate that a heap is secure.
98 */
99#define ION_SECURE (1 << ION_HEAP_ID_RESERVED)
100
101/**
102 * Macro should be used with ion_heap_ids defined above.
103 */
104#define ION_HEAP(bit) (1 << (bit))
105
Laura Abbotta2e93632011-08-19 13:36:32 -0700106#define ION_VMALLOC_HEAP_NAME "vmalloc"
Olav Hauganb5be7992011-11-18 14:29:02 -0800107#define ION_AUDIO_HEAP_NAME "audio"
108#define ION_SF_HEAP_NAME "sf"
109#define ION_MM_HEAP_NAME "mm"
110#define ION_CAMERA_HEAP_NAME "camera_preview"
Laura Abbott8c017362011-09-22 20:59:12 -0700111#define ION_IOMMU_HEAP_NAME "iommu"
Olav Hauganb5be7992011-11-18 14:29:02 -0800112#define ION_MFC_HEAP_NAME "mfc"
113#define ION_WB_HEAP_NAME "wb"
Olav Haugan42ebe712012-01-10 16:30:58 -0800114#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw"
Olav Haugan80854eb2012-01-12 12:00:23 -0800115#define ION_QSECOM_HEAP_NAME "qsecom"
Laura Abbottcaafeea2011-12-13 11:43:10 -0800116#define ION_FMEM_HEAP_NAME "fmem"
Laura Abbotta2e93632011-08-19 13:36:32 -0700117
Laura Abbott894fd582011-08-19 13:33:56 -0700118#define CACHED 1
119#define UNCACHED 0
120
121#define ION_CACHE_SHIFT 0
122
123#define ION_SET_CACHE(__cache) ((__cache) << ION_CACHE_SHIFT)
124
Laura Abbott35412032011-09-29 09:50:06 -0700125#define ION_IS_CACHED(__flags) ((__flags) & (1 << ION_CACHE_SHIFT))
126
Olav Hauganb3676592012-03-02 15:02:25 -0800127/*
128 * This flag allows clients when mapping into the IOMMU to specify to
129 * defer un-mapping from the IOMMU until the buffer memory is freed.
130 */
131#define ION_IOMMU_UNMAP_DELAYED 1
132
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700133#ifdef __KERNEL__
Laura Abbott65576962011-10-31 12:13:25 -0700134#include <linux/err.h>
Laura Abbottcffdff52011-09-23 10:40:19 -0700135#include <mach/ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700136struct ion_device;
137struct ion_heap;
138struct ion_mapper;
139struct ion_client;
140struct ion_buffer;
141
142/* This should be removed some day when phys_addr_t's are fully
143 plumbed in the kernel, and all instances of ion_phys_addr_t should
144 be converted to phys_addr_t. For the time being many kernel interfaces
145 do not accept phys_addr_t's that would have to */
146#define ion_phys_addr_t unsigned long
Laura Abbottcaafeea2011-12-13 11:43:10 -0800147#define ion_virt_addr_t unsigned long
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700148
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700149/**
150 * struct ion_platform_heap - defines a heap in the given platform
151 * @type: type of the heap from ion_heap_type enum
Olav Hauganee0f7802011-12-19 13:28:57 -0800152 * @id: unique identifier for heap. When allocating (lower numbers
Olav Hauganb5be7992011-11-18 14:29:02 -0800153 * will be allocated from first)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700154 * @name: used for debug purposes
155 * @base: base address of heap in physical memory if applicable
156 * @size: size of the heap in bytes if applicable
Laura Abbottcaafeea2011-12-13 11:43:10 -0800157 * @memory_type:Memory type used for the heap
Olav Haugan85c95402012-05-30 17:32:37 -0700158 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800159 * @extra_data: Extra data specific to each heap type
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700160 */
161struct ion_platform_heap {
162 enum ion_heap_type type;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700163 unsigned int id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700164 const char *name;
165 ion_phys_addr_t base;
166 size_t size;
Laura Abbotta2e93632011-08-19 13:36:32 -0700167 enum ion_memory_types memory_type;
Olav Haugan85c95402012-05-30 17:32:37 -0700168 unsigned int has_outer_cache;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800169 void *extra_data;
170};
171
Laura Abbottcaafeea2011-12-13 11:43:10 -0800172/**
173 * struct ion_cp_heap_pdata - defines a content protection heap in the given
174 * platform
175 * @permission_type: Memory ID used to identify the memory to TZ
176 * @align: Alignment requirement for the memory
177 * @secure_base: Base address for securing the heap.
178 * Note: This might be different from actual base address
179 * of this heap in the case of a shared heap.
180 * @secure_size: Memory size for securing the heap.
181 * Note: This might be different from actual size
182 * of this heap in the case of a shared heap.
183 * @reusable Flag indicating whether this heap is reusable of not.
184 * (see FMEM)
Olav Hauganf6dc7742012-02-15 09:11:55 -0800185 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
186 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700187 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800188 * @virt_addr: Virtual address used when using fmem.
Olav Haugan8726caf2012-05-10 15:11:35 -0700189 * @iommu_map_all: Indicates whether we should map whole heap into IOMMU.
190 * @iommu_2x_map_domain: Indicates the domain to use for overmapping.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800191 * @request_region: function to be called when the number of allocations
192 * goes from 0 -> 1
193 * @release_region: function to be called when the number of allocations
194 * goes from 1 -> 0
195 * @setup_region: function to be called upon ion registration
196 *
197 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800198struct ion_cp_heap_pdata {
Olav Haugan0a852512012-01-09 10:20:55 -0800199 enum ion_permission_type permission_type;
Olav Haugan42ebe712012-01-10 16:30:58 -0800200 unsigned int align;
201 ion_phys_addr_t secure_base; /* Base addr used when heap is shared */
202 size_t secure_size; /* Size used for securing heap when heap is shared*/
Laura Abbottcaafeea2011-12-13 11:43:10 -0800203 int reusable;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800204 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700205 enum ion_fixed_position fixed_position;
Olav Haugan8726caf2012-05-10 15:11:35 -0700206 int iommu_map_all;
207 int iommu_2x_map_domain;
Laura Abbottcaafeea2011-12-13 11:43:10 -0800208 ion_virt_addr_t *virt_addr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800209 int (*request_region)(void *);
210 int (*release_region)(void *);
Alex Bird8a3ede32011-11-07 12:33:42 -0800211 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700212};
213
Laura Abbottcaafeea2011-12-13 11:43:10 -0800214/**
215 * struct ion_co_heap_pdata - defines a carveout heap in the given platform
216 * @adjacent_mem_id: Id of heap that this heap must be adjacent to.
217 * @align: Alignment requirement for the memory
Olav Hauganf6dc7742012-02-15 09:11:55 -0800218 * @mem_is_fmem Flag indicating whether this memory is coming from fmem
219 * or not.
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700220 * @fixed_position If nonzero, position in the fixed area.
Laura Abbottcaafeea2011-12-13 11:43:10 -0800221 * @request_region: function to be called when the number of allocations
222 * goes from 0 -> 1
223 * @release_region: function to be called when the number of allocations
224 * goes from 1 -> 0
225 * @setup_region: function to be called upon ion registration
226 *
227 */
Olav Haugan0703dbf2011-12-19 17:53:38 -0800228struct ion_co_heap_pdata {
Olav Haugan42ebe712012-01-10 16:30:58 -0800229 int adjacent_mem_id;
230 unsigned int align;
Olav Hauganf6dc7742012-02-15 09:11:55 -0800231 int mem_is_fmem;
Larry Bassel2d8b42d2012-03-12 10:41:26 -0700232 enum ion_fixed_position fixed_position;
Olav Haugan0703dbf2011-12-19 17:53:38 -0800233 int (*request_region)(void *);
234 int (*release_region)(void *);
235 void *(*setup_region)(void);
236};
237
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700238/**
239 * struct ion_platform_data - array of platform heaps passed from board file
Olav Haugan85c95402012-05-30 17:32:37 -0700240 * @has_outer_cache: set to 1 if outer cache is used, 0 otherwise.
Alex Bird27ca6612011-11-01 14:40:06 -0700241 * @nr: number of structures in the array
242 * @request_region: function to be called when the number of allocations goes
243 * from 0 -> 1
244 * @release_region: function to be called when the number of allocations goes
245 * from 1 -> 0
246 * @setup_region: function to be called upon ion registration
247 * @heaps: array of platform_heap structions
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700248 *
249 * Provided by the board file in the form of platform data to a platform device.
250 */
251struct ion_platform_data {
Olav Haugan85c95402012-05-30 17:32:37 -0700252 unsigned int has_outer_cache;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700253 int nr;
Olav Hauganee0f7802011-12-19 13:28:57 -0800254 int (*request_region)(void *);
255 int (*release_region)(void *);
Alex Bird27ca6612011-11-01 14:40:06 -0700256 void *(*setup_region)(void);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700257 struct ion_platform_heap heaps[];
258};
259
Jordan Crouse8cd48322011-10-12 17:05:19 -0600260#ifdef CONFIG_ION
261
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700262/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800263 * ion_reserve() - reserve memory for ion heaps if applicable
264 * @data: platform data specifying starting physical address and
265 * size
266 *
267 * Calls memblock reserve to set aside memory for heaps that are
268 * located at specific memory addresses or of specfic sizes not
269 * managed by the kernel
270 */
271void ion_reserve(struct ion_platform_data *data);
272
273/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700274 * ion_client_create() - allocate a client and returns it
275 * @dev: the global ion device
276 * @heap_mask: mask of heaps this client can allocate from
277 * @name: used for debugging
278 */
279struct ion_client *ion_client_create(struct ion_device *dev,
280 unsigned int heap_mask, const char *name);
281
282/**
Laura Abbott302911d2011-08-15 17:12:57 -0700283 * msm_ion_client_create - allocate a client using the ion_device specified in
284 * drivers/gpu/ion/msm/msm_ion.c
285 *
286 * heap_mask and name are the same as ion_client_create, return values
287 * are the same as ion_client_create.
288 */
289
290struct ion_client *msm_ion_client_create(unsigned int heap_mask,
291 const char *name);
292
293/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700294 * ion_client_destroy() - free's a client and all it's handles
295 * @client: the client
296 *
297 * Free the provided client and all it's resources including
298 * any handles it is holding.
299 */
300void ion_client_destroy(struct ion_client *client);
301
302/**
303 * ion_alloc - allocate ion memory
304 * @client: the client
305 * @len: size of the allocation
306 * @align: requested allocation alignment, lots of hardware blocks have
307 * alignment requirements of some kind
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700308 * @flags: mask of heaps to allocate from, if multiple bits are set
309 * heaps will be tried in order from lowest to highest order bit
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700310 *
311 * Allocate memory in one of the heaps provided in heap mask and return
312 * an opaque handle to it.
313 */
314struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
315 size_t align, unsigned int flags);
316
317/**
318 * ion_free - free a handle
319 * @client: the client
320 * @handle: the handle to free
321 *
322 * Free the provided handle.
323 */
324void ion_free(struct ion_client *client, struct ion_handle *handle);
325
326/**
327 * ion_phys - returns the physical address and len of a handle
328 * @client: the client
329 * @handle: the handle
330 * @addr: a pointer to put the address in
331 * @len: a pointer to put the length in
332 *
333 * This function queries the heap for a particular handle to get the
334 * handle's physical address. It't output is only correct if
335 * a heap returns physically contiguous memory -- in other cases
Laura Abbottb14ed962012-01-30 14:18:08 -0800336 * this api should not be implemented -- ion_sg_table should be used
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700337 * instead. Returns -EINVAL if the handle is invalid. This has
338 * no implications on the reference counting of the handle --
339 * the returned value may not be valid if the caller is not
340 * holding a reference.
341 */
342int ion_phys(struct ion_client *client, struct ion_handle *handle,
343 ion_phys_addr_t *addr, size_t *len);
344
345/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800346 * ion_map_dma - return an sg_table describing a handle
347 * @client: the client
348 * @handle: the handle
349 *
350 * This function returns the sg_table describing
351 * a particular ion handle.
352 */
353struct sg_table *ion_sg_table(struct ion_client *client,
354 struct ion_handle *handle);
355
356/**
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700357 * ion_map_kernel - create mapping for the given handle
358 * @client: the client
359 * @handle: handle to map
Laura Abbott894fd582011-08-19 13:33:56 -0700360 * @flags: flags for this mapping
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700361 *
362 * Map the given handle into the kernel and return a kernel address that
Laura Abbott894fd582011-08-19 13:33:56 -0700363 * can be used to access this address. If no flags are specified, this
364 * will return a non-secure uncached mapping.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700365 */
Laura Abbott894fd582011-08-19 13:33:56 -0700366void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle,
367 unsigned long flags);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700368
369/**
370 * ion_unmap_kernel() - destroy a kernel mapping for a handle
371 * @client: the client
372 * @handle: handle to unmap
373 */
374void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
375
376/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800377 * ion_share_dma_buf() - given an ion client, create a dma-buf fd
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700378 * @client: the client
Laura Abbottb14ed962012-01-30 14:18:08 -0800379 * @handle: the handle
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700380 */
Laura Abbottb14ed962012-01-30 14:18:08 -0800381int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700382
383/**
Laura Abbottb14ed962012-01-30 14:18:08 -0800384 * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700385 * @client: the client
Laura Abbottb14ed962012-01-30 14:18:08 -0800386 * @fd: the dma-buf fd
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700387 *
Laura Abbottb14ed962012-01-30 14:18:08 -0800388 * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
389 * import that fd and return a handle representing it. If a dma-buf from
390 * another exporter is passed in this function will return ERR_PTR(-EINVAL)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700391 */
Laura Abbottb14ed962012-01-30 14:18:08 -0800392struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
Laura Abbott273dd8e2011-10-12 14:26:33 -0700393
Laura Abbott273dd8e2011-10-12 14:26:33 -0700394/**
395 * ion_handle_get_flags - get the flags for a given handle
396 *
397 * @client - client who allocated the handle
398 * @handle - handle to get the flags
399 * @flags - pointer to store the flags
400 *
401 * Gets the current flags for a handle. These flags indicate various options
402 * of the buffer (caching, security, etc.)
403 */
404int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle,
405 unsigned long *flags);
406
Laura Abbott8c017362011-09-22 20:59:12 -0700407
408/**
409 * ion_map_iommu - map the given handle into an iommu
410 *
411 * @client - client who allocated the handle
412 * @handle - handle to map
413 * @domain_num - domain number to map to
414 * @partition_num - partition number to allocate iova from
415 * @align - alignment for the iova
416 * @iova_length - length of iova to map. If the iova length is
417 * greater than the handle length, the remaining
418 * address space will be mapped to a dummy buffer.
419 * @iova - pointer to store the iova address
420 * @buffer_size - pointer to store the size of the buffer
421 * @flags - flags for options to map
Olav Hauganb3676592012-03-02 15:02:25 -0800422 * @iommu_flags - flags specific to the iommu.
Laura Abbott8c017362011-09-22 20:59:12 -0700423 *
424 * Maps the handle into the iova space specified via domain number. Iova
425 * will be allocated from the partition specified via partition_num.
426 * Returns 0 on success, negative value on error.
427 */
428int ion_map_iommu(struct ion_client *client, struct ion_handle *handle,
429 int domain_num, int partition_num, unsigned long align,
430 unsigned long iova_length, unsigned long *iova,
431 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800432 unsigned long flags, unsigned long iommu_flags);
Laura Abbott8c017362011-09-22 20:59:12 -0700433
434
435/**
436 * ion_handle_get_size - get the allocated size of a given handle
437 *
438 * @client - client who allocated the handle
439 * @handle - handle to get the size
440 * @size - pointer to store the size
441 *
442 * gives the allocated size of a handle. returns 0 on success, negative
443 * value on error
444 *
445 * NOTE: This is intended to be used only to get a size to pass to map_iommu.
446 * You should *NOT* rely on this for any other usage.
447 */
448
449int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
450 unsigned long *size);
451
452/**
453 * ion_unmap_iommu - unmap the handle from an iommu
454 *
455 * @client - client who allocated the handle
456 * @handle - handle to unmap
457 * @domain_num - domain to unmap from
458 * @partition_num - partition to unmap from
459 *
460 * Decrement the reference count on the iommu mapping. If the count is
461 * 0, the mapping will be removed from the iommu.
462 */
463void ion_unmap_iommu(struct ion_client *client, struct ion_handle *handle,
464 int domain_num, int partition_num);
465
466
Olav Haugan0a852512012-01-09 10:20:55 -0800467/**
468 * ion_secure_heap - secure a heap
469 *
470 * @client - a client that has allocated from the heap heap_id
471 * @heap_id - heap id to secure.
Laura Abbott7e446482012-06-13 15:59:39 -0700472 * @version - version of content protection
473 * @data - extra data needed for protection
Olav Haugan0a852512012-01-09 10:20:55 -0800474 *
475 * Secure a heap
476 * Returns 0 on success
477 */
Laura Abbott7e446482012-06-13 15:59:39 -0700478int ion_secure_heap(struct ion_device *dev, int heap_id, int version,
479 void *data);
Olav Haugan0a852512012-01-09 10:20:55 -0800480
481/**
482 * ion_unsecure_heap - un-secure a heap
483 *
484 * @client - a client that has allocated from the heap heap_id
485 * @heap_id - heap id to un-secure.
Laura Abbott7e446482012-06-13 15:59:39 -0700486 * @version - version of content protection
487 * @data - extra data needed for protection
Olav Haugan0a852512012-01-09 10:20:55 -0800488 *
489 * Un-secure a heap
490 * Returns 0 on success
491 */
Laura Abbott7e446482012-06-13 15:59:39 -0700492int ion_unsecure_heap(struct ion_device *dev, int heap_id, int version,
493 void *data);
Olav Haugan0a852512012-01-09 10:20:55 -0800494
495/**
496 * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap.
497 *
498 * @heap_id - heap id to secure.
499 *
500 * Secure a heap
501 * Returns 0 on success
502 */
503int msm_ion_secure_heap(int heap_id);
504
505/**
506 * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap.
507 *
508 * @heap_id - heap id to secure.
509 *
510 * Un-secure a heap
511 * Returns 0 on success
512 */
513int msm_ion_unsecure_heap(int heap_id);
514
Olav Haugan41f85792012-02-08 15:28:05 -0800515/**
Laura Abbott7e446482012-06-13 15:59:39 -0700516 * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs
517 * Wrapper around ion_secure_heap.
518 *
519 * @heap_id - heap id to secure.
520 * @usage - usage hint to TZ
521 *
522 * Secure a heap
523 * Returns 0 on success
524 */
525int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage);
526
527/**
528 * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs.
529 * Wrapper around ion_unsecure_heap.
530 *
531 * @heap_id - heap id to secure.
532 * @usage - usage hint to TZ
533 *
534 * Un-secure a heap
535 * Returns 0 on success
536 */
537int msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage);
538
539/**
Olav Haugan41f85792012-02-08 15:28:05 -0800540 * msm_ion_do_cache_op - do cache operations.
541 *
542 * @client - pointer to ION client.
543 * @handle - pointer to buffer handle.
544 * @vaddr - virtual address to operate on.
545 * @len - Length of data to do cache operation on.
546 * @cmd - Cache operation to perform:
547 * ION_IOC_CLEAN_CACHES
548 * ION_IOC_INV_CACHES
549 * ION_IOC_CLEAN_INV_CACHES
550 *
551 * Returns 0 on success
552 */
553int msm_ion_do_cache_op(struct ion_client *client, struct ion_handle *handle,
554 void *vaddr, unsigned long len, unsigned int cmd);
555
Jordan Crouse8cd48322011-10-12 17:05:19 -0600556#else
Laura Abbottb14ed962012-01-30 14:18:08 -0800557static inline void ion_reserve(struct ion_platform_data *data)
558{
559
560}
561
Jordan Crouse8cd48322011-10-12 17:05:19 -0600562static inline struct ion_client *ion_client_create(struct ion_device *dev,
563 unsigned int heap_mask, const char *name)
564{
565 return ERR_PTR(-ENODEV);
566}
Laura Abbott273dd8e2011-10-12 14:26:33 -0700567
Jordan Crouse8cd48322011-10-12 17:05:19 -0600568static inline struct ion_client *msm_ion_client_create(unsigned int heap_mask,
569 const char *name)
570{
571 return ERR_PTR(-ENODEV);
572}
573
574static inline void ion_client_destroy(struct ion_client *client) { }
575
576static inline struct ion_handle *ion_alloc(struct ion_client *client,
577 size_t len, size_t align, unsigned int flags)
578{
579 return ERR_PTR(-ENODEV);
580}
581
582static inline void ion_free(struct ion_client *client,
583 struct ion_handle *handle) { }
584
585
586static inline int ion_phys(struct ion_client *client,
587 struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len)
588{
589 return -ENODEV;
590}
591
Laura Abbottb14ed962012-01-30 14:18:08 -0800592static inline struct sg_table *ion_sg_table(struct ion_client *client,
593 struct ion_handle *handle)
594{
595 return ERR_PTR(-ENODEV);
596}
597
Jordan Crouse8cd48322011-10-12 17:05:19 -0600598static inline void *ion_map_kernel(struct ion_client *client,
599 struct ion_handle *handle, unsigned long flags)
600{
601 return ERR_PTR(-ENODEV);
602}
603
604static inline void ion_unmap_kernel(struct ion_client *client,
605 struct ion_handle *handle) { }
606
Laura Abbottb14ed962012-01-30 14:18:08 -0800607static inline int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600608{
Laura Abbottb14ed962012-01-30 14:18:08 -0800609 return -ENODEV;
Jordan Crouse8cd48322011-10-12 17:05:19 -0600610}
611
Laura Abbottb14ed962012-01-30 14:18:08 -0800612static inline struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
Jordan Crouse8cd48322011-10-12 17:05:19 -0600613{
614 return ERR_PTR(-ENODEV);
615}
616
617static inline int ion_handle_get_flags(struct ion_client *client,
618 struct ion_handle *handle, unsigned long *flags)
619{
620 return -ENODEV;
621}
Laura Abbott8c017362011-09-22 20:59:12 -0700622
623static inline int ion_map_iommu(struct ion_client *client,
624 struct ion_handle *handle, int domain_num,
625 int partition_num, unsigned long align,
626 unsigned long iova_length, unsigned long *iova,
Olav Haugan9a27d4c2012-02-23 09:35:16 -0800627 unsigned long *buffer_size,
Olav Hauganb3676592012-03-02 15:02:25 -0800628 unsigned long flags,
629 unsigned long iommu_flags)
Laura Abbott8c017362011-09-22 20:59:12 -0700630{
631 return -ENODEV;
632}
633
634static inline void ion_unmap_iommu(struct ion_client *client,
635 struct ion_handle *handle, int domain_num,
636 int partition_num)
637{
638 return;
639}
640
Laura Abbott7e446482012-06-13 15:59:39 -0700641static inline int ion_secure_heap(struct ion_device *dev, int heap_id,
642 int version, void *data)
Olav Haugan0a852512012-01-09 10:20:55 -0800643{
644 return -ENODEV;
Laura Abbott8c017362011-09-22 20:59:12 -0700645
Olav Haugan0a852512012-01-09 10:20:55 -0800646}
647
Laura Abbott7e446482012-06-13 15:59:39 -0700648static inline int ion_unsecure_heap(struct ion_device *dev, int heap_id,
649 int version, void *data)
Olav Haugan0a852512012-01-09 10:20:55 -0800650{
651 return -ENODEV;
652}
653
654static inline int msm_ion_secure_heap(int heap_id)
655{
656 return -ENODEV;
657
658}
659
660static inline int msm_ion_unsecure_heap(int heap_id)
661{
662 return -ENODEV;
663}
Olav Haugan41f85792012-02-08 15:28:05 -0800664
Laura Abbott7e446482012-06-13 15:59:39 -0700665static inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage)
666{
667 return -ENODEV;
668}
669
670static inline int msm_ion_unsecure_heap_2_0(int heap_id,
671 enum cp_mem_usage usage)
672{
673 return -ENODEV;
674}
675
Olav Haugan41f85792012-02-08 15:28:05 -0800676static inline int msm_ion_do_cache_op(struct ion_client *client,
677 struct ion_handle *handle, void *vaddr,
678 unsigned long len, unsigned int cmd)
679{
680 return -ENODEV;
681}
682
Jordan Crouse8cd48322011-10-12 17:05:19 -0600683#endif /* CONFIG_ION */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700684#endif /* __KERNEL__ */
685
686/**
687 * DOC: Ion Userspace API
688 *
689 * create a client by opening /dev/ion
690 * most operations handled via following ioctls
691 *
692 */
693
694/**
695 * struct ion_allocation_data - metadata passed from userspace for allocations
696 * @len: size of the allocation
697 * @align: required alignment of the allocation
698 * @flags: flags passed to heap
699 * @handle: pointer that will be populated with a cookie to use to refer
700 * to this allocation
701 *
702 * Provided by userspace as an argument to the ioctl
703 */
704struct ion_allocation_data {
705 size_t len;
706 size_t align;
707 unsigned int flags;
708 struct ion_handle *handle;
709};
710
711/**
712 * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
713 * @handle: a handle
714 * @fd: a file descriptor representing that handle
715 *
716 * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
717 * the handle returned from ion alloc, and the kernel returns the file
718 * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
719 * provides the file descriptor and the kernel returns the handle.
720 */
721struct ion_fd_data {
722 struct ion_handle *handle;
723 int fd;
724};
725
726/**
727 * struct ion_handle_data - a handle passed to/from the kernel
728 * @handle: a handle
729 */
730struct ion_handle_data {
731 struct ion_handle *handle;
732};
733
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -0700734/**
735 * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
736 * @cmd: the custom ioctl function to call
737 * @arg: additional data to pass to the custom ioctl, typically a user
738 * pointer to a predefined structure
739 *
740 * This works just like the regular cmd and arg fields of an ioctl.
741 */
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700742struct ion_custom_data {
743 unsigned int cmd;
744 unsigned long arg;
745};
746
Laura Abbottabcb6f72011-10-04 16:26:49 -0700747
748/* struct ion_flush_data - data passed to ion for flushing caches
749 *
750 * @handle: handle with data to flush
Laura Abbotte80ea012011-11-18 18:36:47 -0800751 * @fd: fd to flush
Laura Abbottabcb6f72011-10-04 16:26:49 -0700752 * @vaddr: userspace virtual address mapped with mmap
753 * @offset: offset into the handle to flush
754 * @length: length of handle to flush
755 *
756 * Performs cache operations on the handle. If p is the start address
757 * of the handle, p + offset through p + offset + length will have
758 * the cache operations performed
759 */
760struct ion_flush_data {
761 struct ion_handle *handle;
Laura Abbotte80ea012011-11-18 18:36:47 -0800762 int fd;
Laura Abbottabcb6f72011-10-04 16:26:49 -0700763 void *vaddr;
764 unsigned int offset;
765 unsigned int length;
766};
Laura Abbott273dd8e2011-10-12 14:26:33 -0700767
768/* struct ion_flag_data - information about flags for this buffer
769 *
770 * @handle: handle to get flags from
771 * @flags: flags of this handle
772 *
773 * Takes handle as an input and outputs the flags from the handle
774 * in the flag field.
775 */
776struct ion_flag_data {
777 struct ion_handle *handle;
778 unsigned long flags;
779};
780
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700781#define ION_IOC_MAGIC 'I'
782
783/**
784 * DOC: ION_IOC_ALLOC - allocate memory
785 *
786 * Takes an ion_allocation_data struct and returns it with the handle field
787 * populated with the opaque handle for the allocation.
788 */
789#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
790 struct ion_allocation_data)
791
792/**
793 * DOC: ION_IOC_FREE - free memory
794 *
795 * Takes an ion_handle_data struct and frees the handle.
796 */
797#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
798
799/**
800 * DOC: ION_IOC_MAP - get a file descriptor to mmap
801 *
802 * Takes an ion_fd_data struct with the handle field populated with a valid
803 * opaque handle. Returns the struct with the fd field set to a file
804 * descriptor open in the current address space. This file descriptor
805 * can then be used as an argument to mmap.
806 */
807#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
808
809/**
810 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
811 *
812 * Takes an ion_fd_data struct with the handle field populated with a valid
813 * opaque handle. Returns the struct with the fd field set to a file
814 * descriptor open in the current address space. This file descriptor
815 * can then be passed to another process. The corresponding opaque handle can
816 * be retrieved via ION_IOC_IMPORT.
817 */
818#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
819
820/**
821 * DOC: ION_IOC_IMPORT - imports a shared file descriptor
822 *
823 * Takes an ion_fd_data struct with the fd field populated with a valid file
824 * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
825 * filed set to the corresponding opaque handle.
826 */
827#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int)
828
829/**
830 * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
831 *
832 * Takes the argument of the architecture specific ioctl to call and
833 * passes appropriate userdata for that ioctl
834 */
835#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
836
Laura Abbottabcb6f72011-10-04 16:26:49 -0700837
838/**
839 * DOC: ION_IOC_CLEAN_CACHES - clean the caches
840 *
841 * Clean the caches of the handle specified.
842 */
843#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MAGIC, 7, \
844 struct ion_flush_data)
845/**
846 * DOC: ION_MSM_IOC_INV_CACHES - invalidate the caches
847 *
848 * Invalidate the caches of the handle specified.
849 */
850#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MAGIC, 8, \
851 struct ion_flush_data)
852/**
853 * DOC: ION_MSM_IOC_CLEAN_CACHES - clean and invalidate the caches
854 *
855 * Clean and invalidate the caches of the handle specified.
856 */
857#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \
858 struct ion_flush_data)
Laura Abbott273dd8e2011-10-12 14:26:33 -0700859
860/**
861 * DOC: ION_IOC_GET_FLAGS - get the flags of the handle
862 *
863 * Gets the flags of the current handle which indicate cachability,
864 * secure state etc.
865 */
866#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \
867 struct ion_flag_data)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700868#endif /* _LINUX_ION_H */