xref: /openbmc/qemu/contrib/vhost-user-gpu/vugbm.h (revision 7f6c3d1a)
1 /*
2  * Virtio vhost-user GPU Device
3  *
4  * GBM helpers
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 
10 #ifndef VHOST_USER_GPU_VUGBM_H
11 #define VHOST_USER_GPU_VUGBM_H
12 
13 #include "qemu/osdep.h"
14 
15 #ifdef CONFIG_MEMFD
16 #include <sys/mman.h>
17 #include <sys/ioctl.h>
18 #endif
19 
20 #ifdef CONFIG_GBM
21 #include <gbm.h>
22 #endif
23 
24 struct vugbm_buffer;
25 
26 struct vugbm_device {
27     bool inited;
28     int fd;
29 #ifdef CONFIG_GBM
30     struct gbm_device *dev;
31 #endif
32 
33     bool (*alloc_bo)(struct vugbm_buffer *buf);
34     void (*free_bo)(struct vugbm_buffer *buf);
35     bool (*get_fd)(struct vugbm_buffer *buf, int *fd);
36     bool (*map_bo)(struct vugbm_buffer *buf);
37     void (*unmap_bo)(struct vugbm_buffer *buf);
38     void (*device_destroy)(struct vugbm_device *dev);
39 };
40 
41 struct vugbm_buffer {
42     struct vugbm_device *dev;
43 
44 #ifdef CONFIG_MEMFD
45     int memfd;
46 #endif
47 #ifdef CONFIG_GBM
48     struct gbm_bo *bo;
49     void *mmap_data;
50 #endif
51 
52     uint8_t *mmap;
53     uint32_t width;
54     uint32_t height;
55     uint32_t stride;
56     uint32_t format;
57 };
58 
59 bool vugbm_device_init(struct vugbm_device *dev, int fd);
60 void vugbm_device_destroy(struct vugbm_device *dev);
61 
62 bool vugbm_buffer_create(struct vugbm_buffer *buffer, struct vugbm_device *dev,
63                          uint32_t width, uint32_t height);
64 bool vugbm_buffer_can_get_dmabuf_fd(struct vugbm_buffer *buffer);
65 bool vugbm_buffer_get_dmabuf_fd(struct vugbm_buffer *buffer, int *fd);
66 void vugbm_buffer_destroy(struct vugbm_buffer *buffer);
67 
68 #endif
69