blob: 4173d81cc8d3058a8c34ce2d6b55b2f82b6d9f2b [file] [log] [blame]
Etienne Carriere41343db2017-03-17 15:38:52 +01001/*
2 * drivers/staging/android/uapi/ion.h
3 *
4 * Copyright (C) 2011 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef _UAPI_LINUX_ION_H
18#define _UAPI_LINUX_ION_H
19
20#include <linux/ioctl.h>
21#include <linux/types.h>
22
Etienne Carriere41343db2017-03-17 15:38:52 +010023/**
24 * enum ion_heap_types - list of all possible types of heaps
25 * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
26 * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
27 * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
28 * carveout heap, allocations are physically
29 * contiguous
30 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
Etienne Carriere8bc31422017-08-24 14:48:30 +020031 * @ION_HEAP_TYPE_UNMAPPED: memory not intended to be mapped into the
32 * linux address space unless for debug cases
Etienne Carriere41343db2017-03-17 15:38:52 +010033 * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
34 * is used to identify the heaps, so only 32
35 * total heap types are supported
36 */
37enum ion_heap_type {
38 ION_HEAP_TYPE_SYSTEM,
39 ION_HEAP_TYPE_SYSTEM_CONTIG,
40 ION_HEAP_TYPE_CARVEOUT,
41 ION_HEAP_TYPE_CHUNK,
42 ION_HEAP_TYPE_DMA,
43 ION_HEAP_TYPE_UNMAPPED,
44 ION_HEAP_TYPE_CUSTOM, /*
45 * must be last so device specific heaps always
46 * are at the end of this enum
47 */
48};
49
50#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
51
52/**
53 * allocation flags - the lower 16 bits are used by core ion, the upper 16
54 * bits are reserved for use by the heaps themselves.
55 */
56
57/*
58 * mappings of this buffer should be cached, ion will do cache maintenance
59 * when the buffer is mapped for dma
60 */
61#define ION_FLAG_CACHED 1
62
63/*
64 * mappings of this buffer will created at mmap time, if this is set
65 * caches must be managed manually
66 */
67#define ION_FLAG_CACHED_NEEDS_SYNC 2
68
69/**
70 * DOC: Ion Userspace API
71 *
72 * create a client by opening /dev/ion
73 * most operations handled via following ioctls
74 *
75 */
76
77/**
78 * struct ion_allocation_data - metadata passed from userspace for allocations
79 * @len: size of the allocation
Etienne Carriere41343db2017-03-17 15:38:52 +010080 * @heap_id_mask: mask of heap ids to allocate from
81 * @flags: flags passed to heap
82 * @handle: pointer that will be populated with a cookie to use to
83 * refer to this allocation
84 *
85 * Provided by userspace as an argument to the ioctl
86 */
87struct ion_allocation_data {
Etienne Carriere8bc31422017-08-24 14:48:30 +020088 __u64 len;
89 __u32 heap_id_mask;
90 __u32 flags;
91 __u32 fd;
92 __u32 unused;
Etienne Carriere41343db2017-03-17 15:38:52 +010093};
94
95#define MAX_HEAP_NAME 32
96
97/**
98 * struct ion_heap_data - data about a heap
99 * @name - first 32 characters of the heap name
100 * @type - heap type
101 * @heap_id - heap id for the heap
102 */
103struct ion_heap_data {
104 char name[MAX_HEAP_NAME];
105 __u32 type;
106 __u32 heap_id;
107 __u32 reserved0;
108 __u32 reserved1;
109 __u32 reserved2;
110};
111
112/**
113 * struct ion_heap_query - collection of data about all heaps
114 * @cnt - total number of heaps to be copied
115 * @heaps - buffer to copy heap data
116 */
117struct ion_heap_query {
118 __u32 cnt; /* Total number of heaps to be copied */
119 __u32 reserved0; /* align to 64bits */
120 __u64 heaps; /* buffer to be populated */
121 __u32 reserved1;
122 __u32 reserved2;
123};
124
125#define ION_IOC_MAGIC 'I'
126
127/**
128 * DOC: ION_IOC_ALLOC - allocate memory
129 *
130 * Takes an ion_allocation_data struct and returns it with the handle field
131 * populated with the opaque handle for the allocation.
132 */
133#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
134 struct ion_allocation_data)
135
136/**
137 * DOC: ION_IOC_FREE - free memory
138 *
139 * Takes an ion_handle_data struct and frees the handle.
140 */
141#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
142
143/**
Etienne Carriere41343db2017-03-17 15:38:52 +0100144 * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
145 *
146 * Takes an ion_fd_data struct with the handle field populated with a valid
147 * opaque handle. Returns the struct with the fd field set to a file
148 * descriptor open in the current address space. This file descriptor
149 * can then be passed to another process. The corresponding opaque handle can
150 * be retrieved via ION_IOC_IMPORT.
151 */
152#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
153
154/**
Etienne Carriere41343db2017-03-17 15:38:52 +0100155 * DOC: ION_IOC_HEAP_QUERY - information about available heaps
156 *
157 * Takes an ion_heap_query structure and populates information about
158 * available Ion heaps.
159 */
160#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
161 struct ion_heap_query)
162
163#endif /* _UAPI_LINUX_ION_H */