Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / contrib / vhost-user-gpu / vugbm.h
blob82bc4934e1baf5385a38780740e9421ae7cd31be
1 /*
2 * Virtio vhost-user GPU Device
4 * GBM helpers
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 */
10 #ifndef VHOST_USER_GPU_VUGBM_H
11 #define VHOST_USER_GPU_VUGBM_H
14 #ifdef CONFIG_MEMFD
15 #include <sys/ioctl.h>
16 #endif
18 #ifdef CONFIG_GBM
19 #include <gbm.h>
20 #endif
22 struct vugbm_buffer;
24 struct vugbm_device {
25 bool inited;
26 int fd;
27 #ifdef CONFIG_GBM
28 struct gbm_device *dev;
29 #endif
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);
39 struct vugbm_buffer {
40 struct vugbm_device *dev;
42 #ifdef CONFIG_MEMFD
43 int memfd;
44 #endif
45 #ifdef CONFIG_GBM
46 struct gbm_bo *bo;
47 void *mmap_data;
48 #endif
50 uint8_t *mmap;
51 uint32_t width;
52 uint32_t height;
53 uint32_t stride;
54 uint32_t format;
57 void vugbm_device_init(struct vugbm_device *dev, int fd);
58 void vugbm_device_destroy(struct vugbm_device *dev);
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);
66 #endif