etnaviv_gem.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2015 Etnaviv Project
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published by
  6. * the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ETNAVIV_GEM_H__
  17. #define __ETNAVIV_GEM_H__
  18. #include <linux/reservation.h>
  19. #include "etnaviv_drv.h"
  20. struct dma_fence;
  21. struct etnaviv_gem_ops;
  22. struct etnaviv_gem_object;
  23. struct etnaviv_gem_userptr {
  24. uintptr_t ptr;
  25. struct task_struct *task;
  26. struct work_struct *work;
  27. bool ro;
  28. };
  29. struct etnaviv_vram_mapping {
  30. struct list_head obj_node;
  31. struct list_head scan_node;
  32. struct list_head mmu_node;
  33. struct etnaviv_gem_object *object;
  34. struct etnaviv_iommu *mmu;
  35. struct drm_mm_node vram_node;
  36. unsigned int use;
  37. u32 iova;
  38. };
  39. struct etnaviv_gem_object {
  40. struct drm_gem_object base;
  41. const struct etnaviv_gem_ops *ops;
  42. struct mutex lock;
  43. u32 flags;
  44. struct list_head gem_node;
  45. struct etnaviv_gpu *gpu; /* non-null if active */
  46. atomic_t gpu_active;
  47. u32 access;
  48. struct page **pages;
  49. struct sg_table *sgt;
  50. void *vaddr;
  51. /* normally (resv == &_resv) except for imported bo's */
  52. struct reservation_object *resv;
  53. struct reservation_object _resv;
  54. struct list_head vram_list;
  55. /* cache maintenance */
  56. u32 last_cpu_prep_op;
  57. struct etnaviv_gem_userptr userptr;
  58. };
  59. static inline
  60. struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj)
  61. {
  62. return container_of(obj, struct etnaviv_gem_object, base);
  63. }
  64. struct etnaviv_gem_ops {
  65. int (*get_pages)(struct etnaviv_gem_object *);
  66. void (*release)(struct etnaviv_gem_object *);
  67. void *(*vmap)(struct etnaviv_gem_object *);
  68. int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *);
  69. };
  70. static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj)
  71. {
  72. return atomic_read(&etnaviv_obj->gpu_active) != 0;
  73. }
  74. #define MAX_CMDS 4
  75. struct etnaviv_gem_submit_bo {
  76. u32 flags;
  77. struct etnaviv_gem_object *obj;
  78. struct etnaviv_vram_mapping *mapping;
  79. };
  80. /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
  81. * associated with the cmdstream submission for synchronization (and
  82. * make it easier to unwind when things go wrong, etc). This only
  83. * lasts for the duration of the submit-ioctl.
  84. */
  85. struct etnaviv_gem_submit {
  86. struct drm_device *dev;
  87. struct etnaviv_gpu *gpu;
  88. struct ww_acquire_ctx ticket;
  89. struct dma_fence *fence;
  90. u32 flags;
  91. unsigned int nr_bos;
  92. struct etnaviv_gem_submit_bo bos[0];
  93. /* No new members here, the previous one is variable-length! */
  94. };
  95. int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
  96. struct timespec *timeout);
  97. int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
  98. struct reservation_object *robj, const struct etnaviv_gem_ops *ops,
  99. struct etnaviv_gem_object **res);
  100. int etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);
  101. struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
  102. void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
  103. struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
  104. struct drm_gem_object *obj, struct etnaviv_gpu *gpu);
  105. void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping *mapping);
  106. void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
  107. #endif /* __ETNAVIV_GEM_H__ */