etnaviv_gpu.h 5.0 KB

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