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_cmdbuf.h"
  21. #include "etnaviv_drv.h"
  22. struct etnaviv_gem_submit;
  23. struct etnaviv_vram_mapping;
  24. struct etnaviv_chip_identity {
  25. /* Chip model. */
  26. u32 model;
  27. /* Revision value.*/
  28. u32 revision;
  29. /* Supported feature fields. */
  30. u32 features;
  31. /* Supported minor feature fields. */
  32. u32 minor_features0;
  33. u32 minor_features1;
  34. u32 minor_features2;
  35. u32 minor_features3;
  36. u32 minor_features4;
  37. u32 minor_features5;
  38. u32 minor_features6;
  39. u32 minor_features7;
  40. u32 minor_features8;
  41. u32 minor_features9;
  42. u32 minor_features10;
  43. u32 minor_features11;
  44. /* Number of streams supported. */
  45. u32 stream_count;
  46. /* Total number of temporary registers per thread. */
  47. u32 register_max;
  48. /* Maximum number of threads. */
  49. u32 thread_count;
  50. /* Number of shader cores. */
  51. u32 shader_core_count;
  52. /* Size of the vertex cache. */
  53. u32 vertex_cache_size;
  54. /* Number of entries in the vertex output buffer. */
  55. u32 vertex_output_buffer_size;
  56. /* Number of pixel pipes. */
  57. u32 pixel_pipes;
  58. /* Number of instructions. */
  59. u32 instruction_count;
  60. /* Number of constants. */
  61. u32 num_constants;
  62. /* Buffer size */
  63. u32 buffer_size;
  64. /* Number of varyings */
  65. u8 varyings_count;
  66. };
  67. enum etnaviv_sec_mode {
  68. ETNA_SEC_NONE = 0,
  69. ETNA_SEC_KERNEL,
  70. ETNA_SEC_TZ
  71. };
  72. struct etnaviv_event {
  73. struct dma_fence *fence;
  74. struct etnaviv_gem_submit *submit;
  75. void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event);
  76. };
  77. struct etnaviv_cmdbuf_suballoc;
  78. struct etnaviv_cmdbuf;
  79. #define ETNA_NR_EVENTS 30
  80. struct etnaviv_gpu {
  81. struct drm_device *drm;
  82. struct thermal_cooling_device *cooling;
  83. struct device *dev;
  84. struct mutex lock;
  85. struct etnaviv_chip_identity identity;
  86. enum etnaviv_sec_mode sec_mode;
  87. struct etnaviv_file_private *lastctx;
  88. struct workqueue_struct *wq;
  89. struct drm_gpu_scheduler sched;
  90. /* 'ring'-buffer: */
  91. struct etnaviv_cmdbuf buffer;
  92. int exec_state;
  93. /* bus base address of memory */
  94. u32 memory_base;
  95. /* event management: */
  96. DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS);
  97. struct etnaviv_event event[ETNA_NR_EVENTS];
  98. struct completion event_free;
  99. spinlock_t event_spinlock;
  100. u32 idle_mask;
  101. /* Fencing support */
  102. struct mutex fence_idr_lock;
  103. struct idr fence_idr;
  104. u32 next_fence;
  105. u32 active_fence;
  106. u32 completed_fence;
  107. wait_queue_head_t fence_event;
  108. u64 fence_context;
  109. spinlock_t fence_spinlock;
  110. /* worker for handling 'sync' points: */
  111. struct work_struct sync_point_work;
  112. int sync_point_event;
  113. void __iomem *mmio;
  114. int irq;
  115. struct etnaviv_iommu *mmu;
  116. struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
  117. /* Power Control: */
  118. struct clk *clk_bus;
  119. struct clk *clk_reg;
  120. struct clk *clk_core;
  121. struct clk *clk_shader;
  122. unsigned int freq_scale;
  123. unsigned long base_rate_core;
  124. unsigned long base_rate_shader;
  125. };
  126. static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
  127. {
  128. etnaviv_writel(data, gpu->mmio + reg);
  129. }
  130. static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
  131. {
  132. return etnaviv_readl(gpu->mmio + reg);
  133. }
  134. static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence)
  135. {
  136. return fence_after_eq(gpu->completed_fence, fence);
  137. }
  138. int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
  139. int etnaviv_gpu_init(struct etnaviv_gpu *gpu);
  140. bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu);
  141. #ifdef CONFIG_DEBUG_FS
  142. int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
  143. #endif
  144. void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu);
  145. void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
  146. int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
  147. u32 fence, struct timespec *timeout);
  148. int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
  149. struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
  150. struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit);
  151. int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
  152. void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
  153. int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
  154. void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch);
  155. extern struct platform_driver etnaviv_gpu_driver;
  156. #endif /* __ETNAVIV_GPU_H__ */