etnaviv_gem.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_cmdbuf.h"
  20. #include "etnaviv_drv.h"
  21. struct dma_fence;
  22. struct etnaviv_gem_ops;
  23. struct etnaviv_gem_object;
  24. struct etnaviv_gem_userptr {
  25. uintptr_t ptr;
  26. struct mm_struct *mm;
  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. struct dma_fence *excl;
  80. unsigned int nr_shared;
  81. struct dma_fence **shared;
  82. };
  83. /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
  84. * associated with the cmdstream submission for synchronization (and
  85. * make it easier to unwind when things go wrong, etc).
  86. */
  87. struct etnaviv_gem_submit {
  88. struct drm_sched_job sched_job;
  89. struct kref refcount;
  90. struct etnaviv_gpu *gpu;
  91. struct dma_fence *out_fence, *in_fence;
  92. int out_fence_id;
  93. struct list_head node; /* GPU active submit list */
  94. struct etnaviv_cmdbuf cmdbuf;
  95. bool runtime_resumed;
  96. u32 exec_state;
  97. u32 flags;
  98. unsigned int nr_pmrs;
  99. struct etnaviv_perfmon_request *pmrs;
  100. unsigned int nr_bos;
  101. struct etnaviv_gem_submit_bo bos[0];
  102. /* No new members here, the previous one is variable-length! */
  103. };
  104. void etnaviv_submit_put(struct etnaviv_gem_submit * submit);
  105. int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
  106. struct timespec *timeout);
  107. int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
  108. struct reservation_object *robj, const struct etnaviv_gem_ops *ops,
  109. struct etnaviv_gem_object **res);
  110. void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);
  111. struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
  112. void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
  113. struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
  114. struct drm_gem_object *obj, struct etnaviv_gpu *gpu);
  115. void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping *mapping);
  116. void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
  117. #endif /* __ETNAVIV_GEM_H__ */