summaryrefslogtreecommitdiff
path: root/vigs/vigs.h
blob: 87c6b0faa20a6a54d780c38d0cadb582faa56e4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* vigs.h
 *
 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
 * Authors:
 * Stanislav Vorobiov <s.vorobiov@samsung.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef __VIGS_H__
#define __VIGS_H__

#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Surface formats.
 */
typedef enum
{
    vigs_drm_surface_bgrx8888 = 0x0,
    vigs_drm_surface_bgra8888 = 0x1,
} vigs_drm_surface_format;

/*
 * Surface access flags.
 */
#define VIGS_DRM_SAF_READ 1
#define VIGS_DRM_SAF_WRITE 2

struct vigs_drm_device
{
    /* DRM fd. */
    int fd;
};

struct vigs_drm_gem
{
    /* VIGS device object. */
    struct vigs_drm_device *dev;

    /* size of the buffer created. */
    uint32_t size;

    /* a gem handle to gem object created. */
    uint32_t handle;

    /* a gem global handle from flink request. initially 0. */
    uint32_t name;

    /* user space address to a gem buffer mmaped. initially NULL. */
    void *vaddr;
};

struct vigs_drm_surface
{
    struct vigs_drm_gem gem;

    uint32_t width;
    uint32_t height;
    uint32_t stride;
    uint32_t format;
    int scanout;
    uint32_t id;
};

struct vigs_drm_execbuffer
{
    struct vigs_drm_gem gem;
};

struct vigs_drm_fence
{
    /* VIGS device object. */
    struct vigs_drm_device *dev;

    /* a handle to fence object. */
    uint32_t handle;

    /* fence sequence number. */
    uint32_t seq;

    /* is fence signaled ? updated on 'vigs_drm_fence_check'. */
    int signaled;
};

/*
 * All functions return 0 on success and < 0 on error, i.e. kernel style:
 * return -ENOMEM;
 */

/*
 * Device functions.
 * @{
 */

/*
 * Returns -EINVAL on driver version mismatch.
 */
int vigs_drm_device_create(int fd, struct vigs_drm_device **dev);

void vigs_drm_device_destroy(struct vigs_drm_device *dev);

int vigs_drm_device_get_protocol_version(struct vigs_drm_device *dev,
                                         uint32_t *protocol_version);

/*
 * @}
 */

/*
 * GEM functions.
 * @{
 */

/*
 * Passing NULL won't hurt, this is for convenience.
 */
void vigs_drm_gem_ref(struct vigs_drm_gem *gem);

/*
 * Passing NULL won't hurt, this is for convenience.
 */
void vigs_drm_gem_unref(struct vigs_drm_gem *gem);

int vigs_drm_gem_get_name(struct vigs_drm_gem *gem);

int vigs_drm_gem_map(struct vigs_drm_gem *gem, int track_access);

void vigs_drm_gem_unmap(struct vigs_drm_gem *gem);

int vigs_drm_gem_wait(struct vigs_drm_gem *gem);

/*
 * @}
 */

/*
 * Surface functions.
 * @{
 */

int vigs_drm_surface_create(struct vigs_drm_device *dev,
                            uint32_t width,
                            uint32_t height,
                            uint32_t stride,
                            uint32_t format,
                            int scanout,
                            struct vigs_drm_surface **sfc);

int vigs_drm_surface_open(struct vigs_drm_device *dev,
                          uint32_t name,
                          struct vigs_drm_surface **sfc);

int vigs_drm_surface_set_gpu_dirty(struct vigs_drm_surface *sfc);

int vigs_drm_surface_start_access(struct vigs_drm_surface *sfc,
                                  uint32_t saf);

int vigs_drm_surface_end_access(struct vigs_drm_surface *sfc,
                                int sync);

/*
 * @}
 */

/*
 * Execbuffer functions.
 * @{
 */

int vigs_drm_execbuffer_create(struct vigs_drm_device *dev,
                               uint32_t size,
                               struct vigs_drm_execbuffer **execbuffer);

int vigs_drm_execbuffer_open(struct vigs_drm_device *dev,
                             uint32_t name,
                             struct vigs_drm_execbuffer **execbuffer);

int vigs_drm_execbuffer_exec(struct vigs_drm_execbuffer *execbuffer);

/*
 * @}
 */

/*
 * Fence functions.
 * @{
 */

int vigs_drm_fence_create(struct vigs_drm_device *dev,
                          int send,
                          struct vigs_drm_fence **fence);

/*
 * Passing NULL won't hurt, this is for convenience.
 */
void vigs_drm_fence_ref(struct vigs_drm_fence *fence);

/*
 * Passing NULL won't hurt, this is for convenience.
 */
void vigs_drm_fence_unref(struct vigs_drm_fence *fence);

int vigs_drm_fence_wait(struct vigs_drm_fence *fence);

int vigs_drm_fence_check(struct vigs_drm_fence *fence);

/*
 * @}
 */

#ifdef __cplusplus
};
#endif /* __cplusplus */

#endif