f44027bd059ec2ca181ee77dbc653f6e58bd75e0
[platform/upstream/libdrm.git] / vigs / vigs.h
1 /* vigs.h
2  *
3  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
4  * Authors:
5  * Stanislav Vorobiov <s.vorobiov@samsung.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the next
15  * paragraph) shall be included in all copies or substantial portions of the
16  * Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27 #ifndef __VIGS_H__
28 #define __VIGS_H__
29
30 #include <stdint.h>
31 #include <stdbool.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*
38  * Surface formats.
39  */
40 typedef enum
41 {
42     vigs_drm_surface_bgrx8888 = 0x0,
43     vigs_drm_surface_bgra8888 = 0x1,
44 } vigs_drm_surface_format;
45
46 /*
47  * Surface access flags.
48  */
49 #define VIGS_DRM_SAF_READ 1
50 #define VIGS_DRM_SAF_WRITE 2
51
52 struct vigs_drm_device
53 {
54     /* DRM fd. */
55     int fd;
56 };
57
58 struct vigs_drm_gem
59 {
60     /* VIGS device object. */
61     struct vigs_drm_device *dev;
62
63     /* size of the buffer created. */
64     uint32_t size;
65
66     /* a gem handle to gem object created. */
67     uint32_t handle;
68
69     /* a gem global handle from flink request. initially 0. */
70     uint32_t name;
71
72     /* user space address to a gem buffer mmaped. initially NULL. */
73     void *vaddr;
74 };
75
76 struct vigs_drm_surface
77 {
78     struct vigs_drm_gem gem;
79
80     uint32_t width;
81     uint32_t height;
82     uint32_t stride;
83     uint32_t format;
84     uint32_t id;
85 };
86
87 struct vigs_drm_execbuffer
88 {
89     struct vigs_drm_gem gem;
90 };
91
92 struct vigs_drm_fence
93 {
94     /* VIGS device object. */
95     struct vigs_drm_device *dev;
96
97     /* a handle to fence object. */
98     uint32_t handle;
99
100     /* fence sequence number. */
101     uint32_t seq;
102
103     /* is fence signaled ? updated on 'vigs_drm_fence_check'. */
104     int signaled;
105 };
106
107 /*
108  * All functions return 0 on success and < 0 on error, i.e. kernel style:
109  * return -ENOMEM;
110  */
111
112 /*
113  * Device functions.
114  * @{
115  */
116
117 /*
118  * Returns -EINVAL on driver version mismatch.
119  */
120 int vigs_drm_device_create(int fd, struct vigs_drm_device **dev);
121
122 void vigs_drm_device_destroy(struct vigs_drm_device *dev);
123
124 int vigs_drm_device_get_protocol_version(struct vigs_drm_device *dev,
125                                          uint32_t *protocol_version);
126
127 /*
128  * @}
129  */
130
131 /*
132  * GEM functions.
133  * @{
134  */
135
136 /*
137  * Passing NULL won't hurt, this is for convenience.
138  */
139 void vigs_drm_gem_ref(struct vigs_drm_gem *gem);
140
141 /*
142  * Passing NULL won't hurt, this is for convenience.
143  */
144 void vigs_drm_gem_unref(struct vigs_drm_gem *gem);
145
146 int vigs_drm_gem_get_name(struct vigs_drm_gem *gem);
147
148 int vigs_drm_gem_map(struct vigs_drm_gem *gem, int track_access);
149
150 void vigs_drm_gem_unmap(struct vigs_drm_gem *gem);
151
152 int vigs_drm_gem_wait(struct vigs_drm_gem *gem);
153
154 /*
155  * @}
156  */
157
158 /*
159  * Surface functions.
160  * @{
161  */
162
163 int vigs_drm_surface_create(struct vigs_drm_device *dev,
164                             uint32_t width,
165                             uint32_t height,
166                             uint32_t stride,
167                             uint32_t format,
168                             struct vigs_drm_surface **sfc);
169
170 int vigs_drm_surface_open(struct vigs_drm_device *dev,
171                           uint32_t name,
172                           struct vigs_drm_surface **sfc);
173
174 int vigs_drm_surface_set_gpu_dirty(struct vigs_drm_surface *sfc);
175
176 int vigs_drm_surface_start_access(struct vigs_drm_surface *sfc,
177                                   uint32_t saf);
178
179 int vigs_drm_surface_end_access(struct vigs_drm_surface *sfc,
180                                 int sync);
181
182 /*
183  * @}
184  */
185
186 /*
187  * Execbuffer functions.
188  * @{
189  */
190
191 int vigs_drm_execbuffer_create(struct vigs_drm_device *dev,
192                                uint32_t size,
193                                struct vigs_drm_execbuffer **execbuffer);
194
195 int vigs_drm_execbuffer_open(struct vigs_drm_device *dev,
196                              uint32_t name,
197                              struct vigs_drm_execbuffer **execbuffer);
198
199 int vigs_drm_execbuffer_exec(struct vigs_drm_execbuffer *execbuffer);
200
201 /*
202  * @}
203  */
204
205 /*
206  * Fence functions.
207  * @{
208  */
209
210 int vigs_drm_fence_create(struct vigs_drm_device *dev,
211                           int send,
212                           struct vigs_drm_fence **fence);
213
214 /*
215  * Passing NULL won't hurt, this is for convenience.
216  */
217 void vigs_drm_fence_ref(struct vigs_drm_fence *fence);
218
219 /*
220  * Passing NULL won't hurt, this is for convenience.
221  */
222 void vigs_drm_fence_unref(struct vigs_drm_fence *fence);
223
224 int vigs_drm_fence_wait(struct vigs_drm_fence *fence);
225
226 int vigs_drm_fence_check(struct vigs_drm_fence *fence);
227
228 /*
229  * @}
230  */
231
232 #ifdef __cplusplus
233 };
234 #endif /* __cplusplus */
235
236 #endif