1 #ifndef ION_GEM_H
2 #define ION_GEM_H
3 
4 #include "igt.h"
5 #include "gem.h"
6 
7 /**
8  * ion_get_heap_id:
9  * @ion_fd: open ion device fd
10  * @heap_type: ION_HEAP_TYPE_* constant
11  * Returns: the index of the first heap with type matching heap_type, or -1 on
12  * failure
13  **/
14 int ion_get_heap_id(int ion_fd, uint32_t heap_type);
15 
16 /**
17  * ion_alloc_one_fd
18  * @ion_fd: open ion device fd
19  * @size: size of the desired ion buffer
20  * @heap_id: index of the heap to allocate from
21  * @ion_buffer_fd: (out) ion buffer fd
22  * Returns: 0 on success; not 0 otherwise
23  **/
24 int ion_alloc_one_fd(int ion_fd, size_t size, int heap_id, int *ion_buffer_fd);
25 
26 /**
27  * ion_mmap
28  * @ptr: (out) pointer to the buffer in the user process's memory
29  * @ion_buffer_fd: ion buffer fd
30  * @size: size of the desired mapping
31  * Returns: 0 on success; not 0 otherwise
32  **/
33 int ion_mmap(void **ptr, int ion_buffer_fd, size_t size);
34 
35 /**
36  * ion_munmap
37  * @ptr: pointer to the buffer in the user process's memory
38  * @size: exact size of the mapping
39  * Returns: 0 on success; not 0 otherwise
40  **/
41 int ion_munmap(void *ptr, size_t size);
42 
43 /**
44  * drm_check_prime_caps
45  * drm_fd: open DRM device fd
46  * Returns: 0 if the device supports Prime import/export; -1 otherwise
47  **/
48 int drm_check_prime_caps(int drm_fd);
49 
50 /**
51  * gem_handle_for_ion_buffer
52  * drm_fd: open DRM device fd
53  * gem_handle: (out) GEM handle
54  * ion_fd: ion buffer fd
55  *
56  * Imports an ion buffer into GEM
57  *
58  * Returns: 0 if the ion buffer could be imported; -1 otherwise
59  **/
60 int gem_handle_for_ion_buffer(int drm_fd, uint32_t *gem_handle, int ion_buffer_fd);
61 
62 /**
63  * ion_fd_for_gem_handle
64  * drm_fd: open DRM device fd
65  * ion_fd: ion buffer fd
66  *
67  * Exports a GEM buffer into ion
68  *
69  * Returns: 0 if the buffer could be exported; -1 otherwise
70  **/
71 int ion_fd_for_gem_handle(int drm_fd, int *ion_bufferfd, uint32_t gem_handle);
72 
73 /**
74  * drm_fb_for_ion_buffer
75  * drm_fd: open DRM device fd
76  * fb_id: (out) id of the DRM KMS fb
77  * ion_fd: ion buffer fd
78  * fb_config: metadata for the fb
79  *
80  * Converts an ion buffer into a DRM KMS fb
81  *
82  * Returns: 0 if the buffer could be exported; -1 otherwise
83  **/
84 int drm_fb_for_ion_buffer(int drm_fd, uint32_t *fb_id, int ion_buffer_fd,
85 			  const struct fb_configuration *fb_config);
86 
87 /**
88  * drm_release_fb
89  * drm_fd: open DRM device fd
90  * fb_id: id of the DRM KMS fb
91  *
92  * Releases the DRM KMS fb
93  **/
94 void drm_release_fb(int drm_fd, uint32_t fb_id);
95 
96 /**
97  * ion_clone_fd_via_gem
98  * drm_fd: open DRM device fd
99  * cloned_fd: (out) cloned buffer fd
100  * ion_fd: ion buffer fd
101  *
102  * Uses GEM to clone an ion fd by importing and re-exporting it.
103  *
104  * Returns: 0 if the buffer could be cloned; -1 otherwise
105  **/
106 int ion_clone_fd_via_gem(int drm_fd, int *cloned_fd, int ion_buffer_fd);
107 
108 #endif
109