panfrost_gem.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */
  3. #ifndef __PANFROST_GEM_H__
  4. #define __PANFROST_GEM_H__
  5. #include <drm/drm_gem_shmem_helper.h>
  6. #include <drm/drm_mm.h>
  7. struct panfrost_mmu;
  8. struct panfrost_device;
  9. #define PANFROST_BO_LABEL_MAXLEN 4096
  10. enum panfrost_debugfs_gem_state_flags {
  11. /** @PANFROST_DEBUGFS_GEM_STATE_FLAG_IMPORTED: GEM BO is PRIME imported. */
  12. PANFROST_DEBUGFS_GEM_STATE_FLAG_IMPORTED = BIT(0),
  13. /** @PANFROST_DEBUGFS_GEM_STATE_FLAG_EXPORTED: GEM BO is PRIME exported. */
  14. PANFROST_DEBUGFS_GEM_STATE_FLAG_EXPORTED = BIT(1),
  15. /** @PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGED: GEM BO was reclaimed by the shrinker. */
  16. PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGED = BIT(2),
  17. /**
  18. * @PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGEABLE: GEM BO pages were marked as no longer
  19. * needed by UM and can be reclaimed by the shrinker.
  20. */
  21. PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGEABLE = BIT(3),
  22. };
  23. /**
  24. * struct panfrost_gem_debugfs - GEM object's DebugFS list information
  25. */
  26. struct panfrost_gem_debugfs {
  27. /**
  28. * @node: Node used to insert the object in the device-wide list of
  29. * GEM objects, to display information about it through a DebugFS file.
  30. */
  31. struct list_head node;
  32. /** @creator: Information about the UM process which created the GEM. */
  33. struct {
  34. /** @creator.process_name: Group leader name in owning thread's process */
  35. char process_name[TASK_COMM_LEN];
  36. /** @creator.tgid: PID of the thread's group leader within its process */
  37. pid_t tgid;
  38. } creator;
  39. };
  40. struct panfrost_gem_object {
  41. struct drm_gem_shmem_object base;
  42. struct sg_table *sgts;
  43. /*
  44. * Use a list for now. If searching a mapping ever becomes the
  45. * bottleneck, we should consider using an RB-tree, or even better,
  46. * let the core store drm_gem_object_mapping entries (where we
  47. * could place driver specific data) instead of drm_gem_object ones
  48. * in its drm_file->object_idr table.
  49. *
  50. * struct drm_gem_object_mapping {
  51. * struct drm_gem_object *obj;
  52. * void *driver_priv;
  53. * };
  54. */
  55. struct {
  56. struct list_head list;
  57. struct mutex lock;
  58. } mappings;
  59. /*
  60. * Count the number of jobs referencing this BO so we don't let the
  61. * shrinker reclaim this object prematurely.
  62. */
  63. atomic_t gpu_usecount;
  64. /*
  65. * Object chunk size currently mapped onto physical memory
  66. */
  67. size_t heap_rss_size;
  68. /**
  69. * @label: BO tagging fields. The label can be assigned within the
  70. * driver itself or through a specific IOCTL.
  71. */
  72. struct {
  73. /**
  74. * @label.str: Pointer to NULL-terminated string,
  75. */
  76. const char *str;
  77. /** @lock.str: Protects access to the @label.str field. */
  78. struct mutex lock;
  79. } label;
  80. bool noexec :1;
  81. bool is_heap :1;
  82. /* On coherent devices, this reflects the creation flags, not the true
  83. * cacheability attribute of the mapping.
  84. */
  85. bool wb_mmap :1;
  86. #ifdef CONFIG_DEBUG_FS
  87. struct panfrost_gem_debugfs debugfs;
  88. #endif
  89. };
  90. struct panfrost_gem_mapping {
  91. struct list_head node;
  92. struct kref refcount;
  93. struct panfrost_gem_object *obj;
  94. struct drm_mm_node mmnode;
  95. struct panfrost_mmu *mmu;
  96. bool active :1;
  97. };
  98. static inline
  99. struct panfrost_gem_object *to_panfrost_bo(struct drm_gem_object *obj)
  100. {
  101. return container_of(to_drm_gem_shmem_obj(obj), struct panfrost_gem_object, base);
  102. }
  103. static inline struct panfrost_gem_mapping *
  104. drm_mm_node_to_panfrost_mapping(struct drm_mm_node *node)
  105. {
  106. return container_of(node, struct panfrost_gem_mapping, mmnode);
  107. }
  108. void panfrost_gem_init(struct panfrost_device *pfdev);
  109. struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size);
  110. struct drm_gem_object *
  111. panfrost_gem_prime_import_sg_table(struct drm_device *dev,
  112. struct dma_buf_attachment *attach,
  113. struct sg_table *sgt);
  114. struct drm_gem_object *
  115. panfrost_gem_prime_import(struct drm_device *dev,
  116. struct dma_buf *dma_buf);
  117. struct panfrost_gem_object *
  118. panfrost_gem_create(struct drm_device *dev, size_t size, u32 flags);
  119. int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv);
  120. void panfrost_gem_close(struct drm_gem_object *obj,
  121. struct drm_file *file_priv);
  122. struct panfrost_gem_mapping *
  123. panfrost_gem_mapping_get(struct panfrost_gem_object *bo,
  124. struct panfrost_file_priv *priv);
  125. void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping);
  126. void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo);
  127. int panfrost_gem_shrinker_init(struct drm_device *dev);
  128. void panfrost_gem_shrinker_cleanup(struct drm_device *dev);
  129. void panfrost_gem_set_label(struct drm_gem_object *obj, const char *label);
  130. int panfrost_gem_sync(struct drm_gem_object *obj, u32 type,
  131. u32 offset, u32 size);
  132. void panfrost_gem_internal_set_label(struct drm_gem_object *obj, const char *label);
  133. #ifdef CONFIG_DEBUG_FS
  134. void panfrost_gem_debugfs_print_bos(struct panfrost_device *pfdev,
  135. struct seq_file *m);
  136. #endif
  137. #endif /* __PANFROST_GEM_H__ */