vugbm.h 1.5 KB

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