blob: 9e21451149d06fed279289d87c3a7d29163a6ed9 [file] [log] [blame]
Christopher Ferris6ea19f62013-11-20 19:48:48 -08001/*
Christopher Ferrise0845012014-07-09 14:58:51 -07002 * drivers/staging/android/uapi/ion.h
Christopher Ferris6ea19f62013-11-20 19:48:48 -08003 *
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
Christopher Ferrise0845012014-07-09 14:58:51 -070017#ifndef _UAPI_LINUX_ION_H
18#define _UAPI_LINUX_ION_H
Christopher Ferris6ea19f62013-11-20 19:48:48 -080019
Christopher Ferrise0845012014-07-09 14:58:51 -070020#include <linux/ioctl.h>
Christopher Ferris6ea19f62013-11-20 19:48:48 -080021#include <linux/types.h>
22
Christopher Ferris6ea19f62013-11-20 19:48:48 -080023/**
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
Christopher Ferris31475242014-09-02 17:43:51 -070028 * carveout heap, allocations are physically
29 * contiguous
Christopher Ferrise0845012014-07-09 14:58:51 -070030 * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
Christopher Ferris6ea19f62013-11-20 19:48:48 -080031 * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
Christopher Ferris31475242014-09-02 17:43:51 -070032 * is used to identify the heaps, so only 32
33 * total heap types are supported
Christopher Ferris6ea19f62013-11-20 19:48:48 -080034 */
35enum ion_heap_type {
36 ION_HEAP_TYPE_SYSTEM,
37 ION_HEAP_TYPE_SYSTEM_CONTIG,
38 ION_HEAP_TYPE_CARVEOUT,
Christopher Ferrise0845012014-07-09 14:58:51 -070039 ION_HEAP_TYPE_CHUNK,
40 ION_HEAP_TYPE_DMA,
Christopher Ferris12e1f282016-02-04 12:35:07 -080041 ION_HEAP_TYPE_CUSTOM, /*
42 * must be last so device specific heaps always
43 * are at the end of this enum
44 */
Christopher Ferris6ea19f62013-11-20 19:48:48 -080045};
46
Christopher Ferris31475242014-09-02 17:43:51 -070047#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
Christopher Ferris6ea19f62013-11-20 19:48:48 -080048
49/**
Christopher Ferrise0845012014-07-09 14:58:51 -070050 * allocation flags - the lower 16 bits are used by core ion, the upper 16
Christopher Ferris6ea19f62013-11-20 19:48:48 -080051 * bits are reserved for use by the heaps themselves.
52 */
Christopher Ferris33185402017-01-13 13:28:52 -080053
54/*
55 * mappings of this buffer should be cached, ion will do cache maintenance
56 * when the buffer is mapped for dma
57 */
58#define ION_FLAG_CACHED 1
59
Christopher Ferris6ea19f62013-11-20 19:48:48 -080060/**
61 * DOC: Ion Userspace API
62 *
63 * create a client by opening /dev/ion
64 * most operations handled via following ioctls
65 *
66 */
67
68/**
69 * struct ion_allocation_data - metadata passed from userspace for allocations
Christopher Ferrise0845012014-07-09 14:58:51 -070070 * @len: size of the allocation
Christopher Ferrise0845012014-07-09 14:58:51 -070071 * @heap_id_mask: mask of heap ids to allocate from
72 * @flags: flags passed to heap
Christopher Ferris31475242014-09-02 17:43:51 -070073 * @handle: pointer that will be populated with a cookie to use to
Christopher Ferrise0845012014-07-09 14:58:51 -070074 * refer to this allocation
Christopher Ferris6ea19f62013-11-20 19:48:48 -080075 *
76 * Provided by userspace as an argument to the ioctl
77 */
78struct ion_allocation_data {
Christopher Ferris0543f742017-07-26 13:09:46 -070079 __u64 len;
80 __u32 heap_id_mask;
81 __u32 flags;
82 __u32 fd;
83 __u32 unused;
Christopher Ferris6ea19f62013-11-20 19:48:48 -080084};
85
Christopher Ferris33185402017-01-13 13:28:52 -080086#define MAX_HEAP_NAME 32
87
88/**
89 * struct ion_heap_data - data about a heap
90 * @name - first 32 characters of the heap name
91 * @type - heap type
92 * @heap_id - heap id for the heap
93 */
94struct ion_heap_data {
95 char name[MAX_HEAP_NAME];
96 __u32 type;
97 __u32 heap_id;
98 __u32 reserved0;
99 __u32 reserved1;
100 __u32 reserved2;
101};
102
103/**
104 * struct ion_heap_query - collection of data about all heaps
105 * @cnt - total number of heaps to be copied
106 * @heaps - buffer to copy heap data
107 */
108struct ion_heap_query {
109 __u32 cnt; /* Total number of heaps to be copied */
110 __u32 reserved0; /* align to 64bits */
111 __u64 heaps; /* buffer to be populated */
112 __u32 reserved1;
113 __u32 reserved2;
114};
115
Christopher Ferris6ea19f62013-11-20 19:48:48 -0800116#define ION_IOC_MAGIC 'I'
117
118/**
119 * DOC: ION_IOC_ALLOC - allocate memory
120 *
121 * Takes an ion_allocation_data struct and returns it with the handle field
122 * populated with the opaque handle for the allocation.
123 */
124#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
125 struct ion_allocation_data)
126
127/**
Christopher Ferris33185402017-01-13 13:28:52 -0800128 * DOC: ION_IOC_HEAP_QUERY - information about available heaps
129 *
130 * Takes an ion_heap_query structure and populates information about
131 * available Ion heaps.
132 */
133#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
134 struct ion_heap_query)
135
Christopher Ferrise0845012014-07-09 14:58:51 -0700136#endif /* _UAPI_LINUX_ION_H */