vugbm.h 1.5 KB

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