xref: /openbmc/qemu/contrib/vhost-user-gpu/vugbm.h (revision 2068cabd)
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 
14 #ifdef CONFIG_MEMFD
15 #include <sys/ioctl.h>
16 #endif
17 
18 #ifdef CONFIG_GBM
19 #include <gbm.h>
20 #endif
21 
22 struct vugbm_buffer;
23 
24 struct vugbm_device {
25     bool inited;
26     int fd;
27 #ifdef CONFIG_GBM
28     struct gbm_device *dev;
29 #endif
30 
31     bool (*alloc_bo)(struct vugbm_buffer *buf);
32     void (*free_bo)(struct vugbm_buffer *buf);
33     bool (*get_fd)(struct vugbm_buffer *buf, int *fd);
34     bool (*map_bo)(struct vugbm_buffer *buf);
35     void (*unmap_bo)(struct vugbm_buffer *buf);
36     void (*device_destroy)(struct vugbm_device *dev);
37 };
38 
39 struct vugbm_buffer {
40     struct vugbm_device *dev;
41 
42 #ifdef CONFIG_MEMFD
43     int memfd;
44 #endif
45 #ifdef CONFIG_GBM
46     struct gbm_bo *bo;
47     void *mmap_data;
48 #endif
49 
50     uint8_t *mmap;
51     uint32_t width;
52     uint32_t height;
53     uint32_t stride;
54     uint32_t format;
55 };
56 
57 void vugbm_device_init(struct vugbm_device *dev, int fd);
58 void vugbm_device_destroy(struct vugbm_device *dev);
59 
60 bool vugbm_buffer_create(struct vugbm_buffer *buffer, struct vugbm_device *dev,
61                          uint32_t width, uint32_t height);
62 bool vugbm_buffer_can_get_dmabuf_fd(struct vugbm_buffer *buffer);
63 bool vugbm_buffer_get_dmabuf_fd(struct vugbm_buffer *buffer, int *fd);
64 void vugbm_buffer_destroy(struct vugbm_buffer *buffer);
65 
66 #endif
67