etnaviv_gpu.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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_suballoc;
  70. struct etnaviv_cmdbuf;
  71. struct etnaviv_gpu {
  72. struct drm_device *drm;
  73. struct device *dev;
  74. struct mutex lock;
  75. struct etnaviv_chip_identity identity;
  76. struct etnaviv_file_private *lastctx;
  77. bool switch_context;
  78. /* 'ring'-buffer: */
  79. struct etnaviv_cmdbuf *buffer;
  80. int exec_state;
  81. /* bus base address of memory */
  82. u32 memory_base;
  83. /* event management: */
  84. struct etnaviv_event event[30];
  85. struct completion event_free;
  86. spinlock_t event_spinlock;
  87. /* list of currently in-flight command buffers */
  88. struct list_head active_cmd_list;
  89. u32 idle_mask;
  90. /* Fencing support */
  91. u32 next_fence;
  92. u32 active_fence;
  93. u32 completed_fence;
  94. u32 retired_fence;
  95. wait_queue_head_t fence_event;
  96. u64 fence_context;
  97. spinlock_t fence_spinlock;
  98. /* worker for handling active-list retiring: */
  99. struct work_struct retire_work;
  100. void __iomem *mmio;
  101. int irq;
  102. struct etnaviv_iommu *mmu;
  103. struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
  104. /* Power Control: */
  105. struct clk *clk_bus;
  106. struct clk *clk_core;
  107. struct clk *clk_shader;
  108. /* Hang Detction: */
  109. #define DRM_ETNAVIV_HANGCHECK_PERIOD 500 /* in ms */
  110. #define DRM_ETNAVIV_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_ETNAVIV_HANGCHECK_PERIOD)
  111. struct timer_list hangcheck_timer;
  112. u32 hangcheck_fence;
  113. u32 hangcheck_dma_addr;
  114. struct work_struct recover_work;
  115. };
  116. static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
  117. {
  118. etnaviv_writel(data, gpu->mmio + reg);
  119. }
  120. static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
  121. {
  122. return etnaviv_readl(gpu->mmio + reg);
  123. }
  124. static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence)
  125. {
  126. return fence_after_eq(gpu->completed_fence, fence);
  127. }
  128. static inline bool fence_retired(struct etnaviv_gpu *gpu, u32 fence)
  129. {
  130. return fence_after_eq(gpu->retired_fence, fence);
  131. }
  132. int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
  133. int etnaviv_gpu_init(struct etnaviv_gpu *gpu);
  134. #ifdef CONFIG_DEBUG_FS
  135. int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
  136. #endif
  137. int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj,
  138. unsigned int context, bool exclusive);
  139. void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
  140. int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
  141. u32 fence, struct timespec *timeout);
  142. int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
  143. struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
  144. int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
  145. struct etnaviv_gem_submit *submit, struct etnaviv_cmdbuf *cmdbuf);
  146. int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
  147. void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
  148. int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
  149. void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch);
  150. extern struct platform_driver etnaviv_gpu_driver;
  151. #endif /* __ETNAVIV_GPU_H__ */