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