etnaviv_gem.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 etnaviv_gem_ops;
  21. struct etnaviv_gem_object;
  22. struct etnaviv_gem_userptr {
  23. uintptr_t ptr;
  24. struct task_struct *task;
  25. struct work_struct *work;
  26. bool ro;
  27. };
  28. struct etnaviv_vram_mapping {
  29. struct list_head obj_node;
  30. struct list_head scan_node;
  31. struct list_head mmu_node;
  32. struct etnaviv_gem_object *object;
  33. struct etnaviv_iommu *mmu;
  34. struct drm_mm_node vram_node;
  35. unsigned int use;
  36. u32 iova;
  37. };
  38. struct etnaviv_gem_object {
  39. struct drm_gem_object base;
  40. const struct etnaviv_gem_ops *ops;
  41. struct mutex lock;
  42. u32 flags;
  43. struct list_head gem_node;
  44. struct etnaviv_gpu *gpu; /* non-null if active */
  45. atomic_t gpu_active;
  46. u32 access;
  47. struct page **pages;
  48. struct sg_table *sgt;
  49. void *vaddr;
  50. /* normally (resv == &_resv) except for imported bo's */
  51. struct reservation_object *resv;
  52. struct reservation_object _resv;
  53. struct list_head vram_list;
  54. /* cache maintenance */
  55. u32 last_cpu_prep_op;
  56. struct etnaviv_gem_userptr userptr;
  57. };
  58. static inline
  59. struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj)
  60. {
  61. return container_of(obj, struct etnaviv_gem_object, base);
  62. }
  63. struct etnaviv_gem_ops {
  64. int (*get_pages)(struct etnaviv_gem_object *);
  65. void (*release)(struct etnaviv_gem_object *);
  66. void *(*vmap)(struct etnaviv_gem_object *);
  67. int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *);
  68. };
  69. static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj)
  70. {
  71. return atomic_read(&etnaviv_obj->gpu_active) != 0;
  72. }
  73. #define MAX_CMDS 4
  74. struct etnaviv_gem_submit_bo {
  75. u32 flags;
  76. struct etnaviv_gem_object *obj;
  77. struct etnaviv_vram_mapping *mapping;
  78. };
  79. /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
  80. * associated with the cmdstream submission for synchronization (and
  81. * make it easier to unwind when things go wrong, etc). This only
  82. * lasts for the duration of the submit-ioctl.
  83. */
  84. struct etnaviv_gem_submit {
  85. struct drm_device *dev;
  86. struct etnaviv_gpu *gpu;
  87. struct ww_acquire_ctx ticket;
  88. u32 fence;
  89. unsigned int nr_bos;
  90. struct etnaviv_gem_submit_bo bos[0];
  91. };
  92. int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
  93. struct timespec *timeout);
  94. int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
  95. struct reservation_object *robj, const struct etnaviv_gem_ops *ops,
  96. struct etnaviv_gem_object **res);
  97. int etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);
  98. struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
  99. void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
  100. struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
  101. struct drm_gem_object *obj, struct etnaviv_gpu *gpu);
  102. void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping *mapping);
  103. void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
  104. #endif /* __ETNAVIV_GEM_H__ */