1 /*
2  *  hardware/exynos/ion.h
3  *
4  *   Copyright 2018 Samsung Electronics Co., Ltd.
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */
18 
19 #ifndef __HARDWARE_EXYNOS_ION_H__
20 #define __HARDWARE_EXYNOS_ION_H__
21 
22 #include <sys/types.h>
23 
24 #define ION_EXYNOS_HEAP_ID_SYSTEM        0
25 #define ION_EXYNOS_HEAP_ID_CRYPTO        1
26 #define ION_EXYNOS_HEAP_ID_VIDEO_STREAM  3
27 #define ION_EXYNOS_HEAP_ID_VIDEO_FRAME   5
28 #define ION_EXYNOS_HEAP_ID_VIDEO_SCALER  6
29 #define ION_EXYNOS_HEAP_ID_GPU_CRC       8
30 #define ION_EXYNOS_HEAP_ID_GPU_BUFFER    9
31 #define ION_EXYNOS_HEAP_ID_CAMERA        10
32 #define ION_EXYNOS_HEAP_ID_SECURE_CAMERA 11
33 #define ION_EXYNOS_HEAP_ID_SENSOR_DIRECT 12
34 #define ION_EXYNOS_HEAP_ID_FA_TPU        15
35 #define ION_EXYNOS_HEAP_ID_FA_IMG        16
36 #define ION_EXYNOS_HEAP_ID_FA_RAWIMG     17
37 #define ION_EXYNOS_HEAP_ID_FA_PREV       18
38 #define ION_EXYNOS_HEAP_ID_FA_MODEL      19
39 
40 #define EXYNOS_ION_HEAP_SYSTEM_MASK         (1 << ION_EXYNOS_HEAP_ID_SYSTEM)
41 #define EXYNOS_ION_HEAP_CRYPTO_MASK         (1 << ION_EXYNOS_HEAP_ID_CRYPTO)
42 #define EXYNOS_ION_HEAP_VIDEO_STREAM_MASK   (1 << ION_EXYNOS_HEAP_ID_VIDEO_STREAM)
43 #define EXYNOS_ION_HEAP_VIDEO_FRAME_MASK    (1 << ION_EXYNOS_HEAP_ID_VIDEO_FRAME)
44 #define EXYNOS_ION_HEAP_VIDEO_SCALER_MASK   (1 << ION_EXYNOS_HEAP_ID_VIDEO_SCALER)
45 #define EXYNOS_ION_HEAP_GPU_CRC_MASK        (1 << ION_EXYNOS_HEAP_ID_GPU_CRC)
46 #define EXYNOS_ION_HEAP_GPU_BUFFER_MASK     (1 << ION_EXYNOS_HEAP_ID_GPU_BUFFER)
47 #define EXYNOS_ION_HEAP_CAMERA_MASK         (1 << ION_EXYNOS_HEAP_ID_CAMERA)
48 #define EXYNOS_ION_HEAP_SECURE_CAMERA_MASK  (1 << ION_EXYNOS_HEAP_ID_SECURE_CAMERA)
49 #define EXYNOS_ION_HEAP_SENSOR_DIRECT_MASK  (1 << ION_EXYNOS_HEAP_ID_SENSOR_DIRECT)
50 #define EXYNOS_ION_HEAP_FA_TPU_MASK         (1 << ION_EXYNOS_HEAP_ID_FA_TPU)
51 #define EXYNOS_ION_HEAP_FA_IMG_MASK         (1 << ION_EXYNOS_HEAP_ID_FA_IMG)
52 #define EXYNOS_ION_HEAP_FA_RAWIMG_MASK      (1 << ION_EXYNOS_HEAP_ID_FA_RAWIMG)
53 #define EXYNOS_ION_HEAP_FA_PREV_MASK        (1 << ION_EXYNOS_HEAP_ID_FA_PREV)
54 #define EXYNOS_ION_HEAP_FA_MODEL_MASK       (1 << ION_EXYNOS_HEAP_ID_FA_MODEL)
55 
56 #define ION_EXYNOS_FLAG_PROTECTED (1 << 16)
57 
58 #define ION_FLAG_CACHED 1
59 #define ION_FLAG_CACHED_NEEDS_SYNC 2 /* deprecated in the modern ion */
60 #define ION_FLAG_NOZEROED 8
61 #define ION_FLAG_PROTECTED (16 | ION_EXYNOS_FLAG_PROTECTED)
62 #define ION_FLAG_SYNC_FORCE 32
63 #define ION_FLAG_MAY_HWRENDER 64
64 #define ION_FLAG_HW_EXTRA 128
65 
66 __BEGIN_DECLS
67 
68 int exynos_ion_open(void);
69 int exynos_ion_close(int fd);
70 int exynos_ion_alloc(int ion_fd, size_t len,
71                       unsigned int heap_mask, unsigned int flags);
72 int exynos_ion_import_handle(int ion_fd, int fd, int* handle);
73 int exynos_ion_free_handle(int ion_fd, int handle);
74 int exynos_ion_sync_fd(int ion_fd, int fd);
75 int exynos_ion_sync_fd_partial(int ion_fd, int fd, off_t offset, size_t len);
76 
77 const char *exynos_ion_get_heap_name(unsigned int legacy_heap_id);
78 
79 int exynos_ion_sync_start(int ion_fd, int fd, int direction);
80 int exynos_ion_sync_end(int ion_fd, int fd, int direction);
81 
82 __END_DECLS
83 
84 #endif /* __HARDWARE_EXYNOS_ION_H__ */
85