etnaviv_gpu.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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_GPU_H__
  17. #define __ETNAVIV_GPU_H__
  18. #include <linux/clk.h>
  19. #include <linux/regulator/consumer.h>
  20. #include "etnaviv_drv.h"
  21. struct etnaviv_gem_submit;
  22. struct etnaviv_vram_mapping;
  23. struct etnaviv_chip_identity {
  24. /* Chip model. */
  25. u32 model;
  26. /* Revision value.*/
  27. u32 revision;
  28. /* Supported feature fields. */
  29. u32 features;
  30. /* Supported minor feature fields. */
  31. u32 minor_features0;
  32. /* Supported minor feature 1 fields. */
  33. u32 minor_features1;
  34. /* Supported minor feature 2 fields. */
  35. u32 minor_features2;
  36. /* Supported minor feature 3 fields. */
  37. u32 minor_features3;
  38. /* Supported minor feature 4 fields. */
  39. u32 minor_features4;
  40. /* Supported minor feature 5 fields. */
  41. u32 minor_features5;
  42. /* Number of streams supported. */
  43. u32 stream_count;
  44. /* Total number of temporary registers per thread. */
  45. u32 register_max;
  46. /* Maximum number of threads. */
  47. u32 thread_count;
  48. /* Number of shader cores. */
  49. u32 shader_core_count;
  50. /* Size of the vertex cache. */
  51. u32 vertex_cache_size;
  52. /* Number of entries in the vertex output buffer. */
  53. u32 vertex_output_buffer_size;
  54. /* Number of pixel pipes. */
  55. u32 pixel_pipes;
  56. /* Number of instructions. */
  57. u32 instruction_count;
  58. /* Number of constants. */
  59. u32 num_constants;
  60. /* Buffer size */
  61. u32 buffer_size;
  62. /* Number of varyings */
  63. u8 varyings_count;
  64. };
  65. struct etnaviv_event {
  66. bool used;
  67. struct dma_fence *fence;
  68. };
  69. struct etnaviv_cmdbuf;
  70. struct etnaviv_gpu {
  71. struct drm_device *drm;
  72. struct device *dev;
  73. struct mutex lock;
  74. struct etnaviv_chip_identity identity;
  75. struct etnaviv_file_private *lastctx;
  76. bool switch_context;
  77. /* 'ring'-buffer: */
  78. struct etnaviv_cmdbuf *buffer;
  79. int exec_state;
  80. /* bus base address of memory */
  81. u32 memory_base;
  82. /* event management: */
  83. struct etnaviv_event event[30];
  84. struct completion event_free;
  85. spinlock_t event_spinlock;
  86. /* list of currently in-flight command buffers */
  87. struct list_head active_cmd_list;
  88. u32 idle_mask;
  89. /* Fencing support */
  90. u32 next_fence;
  91. u32 active_fence;
  92. u32 completed_fence;
  93. u32 retired_fence;
  94. wait_queue_head_t fence_event;
  95. u64 fence_context;
  96. spinlock_t fence_spinlock;
  97. /* worker for handling active-list retiring: */
  98. struct work_struct retire_work;
  99. void __iomem *mmio;
  100. int irq;
  101. struct etnaviv_iommu *mmu;
  102. /* Power Control: */
  103. struct clk *clk_bus;
  104. struct clk *clk_core;
  105. struct clk *clk_shader;
  106. /* Hang Detction: */
  107. #define DRM_ETNAVIV_HANGCHECK_PERIOD 500 /* in ms */
  108. #define DRM_ETNAVIV_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_ETNAVIV_HANGCHECK_PERIOD)
  109. struct timer_list hangcheck_timer;
  110. u32 hangcheck_fence;
  111. u32 hangcheck_dma_addr;
  112. struct work_struct recover_work;
  113. };
  114. struct etnaviv_cmdbuf {
  115. /* device this cmdbuf is allocated for */
  116. struct etnaviv_gpu *gpu;
  117. /* user context key, must be unique between all active users */
  118. struct etnaviv_file_private *ctx;
  119. /* cmdbuf properties */
  120. void *vaddr;
  121. dma_addr_t paddr;
  122. u32 size;
  123. u32 user_size;
  124. /* vram node used if the cmdbuf is mapped through the MMUv2 */
  125. struct drm_mm_node vram_node;
  126. /* fence after which this buffer is to be disposed */
  127. struct dma_fence *fence;
  128. /* target exec state */
  129. u32 exec_state;
  130. /* per GPU in-flight list */
  131. struct list_head node;
  132. /* BOs attached to this command buffer */
  133. unsigned int nr_bos;
  134. struct etnaviv_vram_mapping *bo_map[0];
  135. };
  136. static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
  137. {
  138. etnaviv_writel(data, gpu->mmio + reg);
  139. }
  140. static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
  141. {
  142. return etnaviv_readl(gpu->mmio + reg);
  143. }
  144. static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence)
  145. {
  146. return fence_after_eq(gpu->completed_fence, fence);
  147. }
  148. static inline bool fence_retired(struct etnaviv_gpu *gpu, u32 fence)
  149. {
  150. return fence_after_eq(gpu->retired_fence, fence);
  151. }
  152. int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
  153. int etnaviv_gpu_init(struct etnaviv_gpu *gpu);
  154. #ifdef CONFIG_DEBUG_FS
  155. int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
  156. #endif
  157. int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj,
  158. unsigned int context, bool exclusive);
  159. void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
  160. int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
  161. u32 fence, struct timespec *timeout);
  162. int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
  163. struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
  164. int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
  165. struct etnaviv_gem_submit *submit, struct etnaviv_cmdbuf *cmdbuf);
  166. struct etnaviv_cmdbuf *etnaviv_gpu_cmdbuf_new(struct etnaviv_gpu *gpu,
  167. u32 size, size_t nr_bos);
  168. void etnaviv_gpu_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf);
  169. int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
  170. void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
  171. int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
  172. void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch);
  173. extern struct platform_driver etnaviv_gpu_driver;
  174. #endif /* __ETNAVIV_GPU_H__ */