rk: ion: support carveout heap
[firefly-linux-kernel-4.4.55.git] / include / linux / rockchip_ion.h
1 /*
2  *
3  * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #ifndef _LINUX_ROCKCHIP_ION_H
17 #define _LINUX_ROCKCHIP_ION_H
18
19 #ifdef __KERNEL__
20 #include "../../drivers/staging/android/ion/ion.h"
21 #else
22 #include <linux/ion.h>
23 #endif
24
25 enum ion_heap_ids {
26         INVALID_HEAP_ID = -1,
27         ION_CMA_HEAP_ID = 1,
28         ION_IOMMU_HEAP_ID,
29         ION_VMALLOC_HEAP_ID,
30         ION_DRM_HEAP_ID,
31         ION_CARVEOUT_HEAP_ID,
32
33         ION_HEAP_ID_RESERVED = 31
34 };
35
36 #define ION_HEAP(bit) (1 << (bit))
37
38 #define ION_CMA_HEAP_NAME               "cma"
39 #define ION_IOMMU_HEAP_NAME             "iommu"
40 #define ION_VMALLOC_HEAP_NAME   "vmalloc"
41 #define ION_DRM_HEAP_NAME               "drm"
42 #define ION_CARVEOUT_HEAP_NAME  "carveout"
43
44 #define ION_SET_CACHED(__cache)         (__cache | ION_FLAG_CACHED)
45 #define ION_SET_UNCACHED(__cache)       (__cache & ~ION_FLAG_CACHED)
46
47 #define ION_IS_CACHED(__flags)  ((__flags) & ION_FLAG_CACHED)
48
49 /* struct ion_flush_data - data passed to ion for flushing caches
50  *
51  * @handle:     handle with data to flush
52  * @fd:         fd to flush
53  * @vaddr:      userspace virtual address mapped with mmap
54  * @offset:     offset into the handle to flush
55  * @length:     length of handle to flush
56  *
57  * Performs cache operations on the handle. If p is the start address
58  * of the handle, p + offset through p + offset + length will have
59  * the cache operations performed
60  */
61 struct ion_flush_data {
62         ion_user_handle_t handle;
63         int fd;
64         void *vaddr;
65         unsigned int offset;
66         unsigned int length;
67 };
68
69 struct ion_phys_data {
70         ion_user_handle_t handle;
71         unsigned long phys;
72         unsigned long size;
73 };
74
75 struct ion_share_id_data {
76         int fd;
77         unsigned int id;
78 };
79
80 #define ION_IOC_ROCKCHIP_MAGIC 'R'
81
82 /**
83  * Clean the caches of the handle specified.
84  */
85 #define ION_IOC_CLEAN_CACHES    _IOWR(ION_IOC_ROCKCHIP_MAGIC, 0, \
86                                                 struct ion_flush_data)
87 /**
88  * Invalidate the caches of the handle specified.
89  */
90 #define ION_IOC_INV_CACHES      _IOWR(ION_IOC_ROCKCHIP_MAGIC, 1, \
91                                                 struct ion_flush_data)
92 /**
93  * Clean and invalidate the caches of the handle specified.
94  */
95 #define ION_IOC_CLEAN_INV_CACHES        _IOWR(ION_IOC_ROCKCHIP_MAGIC, 2, \
96                                                 struct ion_flush_data)
97
98 /**
99  * Get phys addr of the handle specified.
100  */
101 #define ION_IOC_GET_PHYS        _IOWR(ION_IOC_ROCKCHIP_MAGIC, 3, \
102                                                 struct ion_phys_data)
103
104 /**
105  * Get share object of the fd specified.
106  */
107 #define ION_IOC_GET_SHARE_ID    _IOWR(ION_IOC_ROCKCHIP_MAGIC, 4, \
108                                                 struct ion_share_id_data)
109
110 /**
111  * Set share object and associate new fd.
112  */
113 #define ION_IOC_SHARE_BY_ID     _IOWR(ION_IOC_ROCKCHIP_MAGIC, 5, \
114                                                 struct ion_share_id_data)
115
116 #endif