a6xx_gpu.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2017, 2019 The Linux Foundation. All rights reserved. */
  3. #ifndef __A6XX_GPU_H__
  4. #define __A6XX_GPU_H__
  5. #include "adreno_gpu.h"
  6. #include "a6xx_enums.xml.h"
  7. #include "a7xx_enums.xml.h"
  8. #include "a6xx_perfcntrs.xml.h"
  9. #include "a7xx_perfcntrs.xml.h"
  10. #include "a6xx.xml.h"
  11. #include "a6xx_gmu.h"
  12. extern bool hang_debug;
  13. struct cpu_gpu_lock {
  14. uint32_t gpu_req;
  15. uint32_t cpu_req;
  16. uint32_t turn;
  17. union {
  18. struct {
  19. uint16_t list_length;
  20. uint16_t list_offset;
  21. };
  22. struct {
  23. uint8_t ifpc_list_len;
  24. uint8_t preemption_list_len;
  25. uint16_t dynamic_list_len;
  26. };
  27. };
  28. uint64_t regs[62];
  29. };
  30. /**
  31. * struct a6xx_info - a6xx specific information from device table
  32. *
  33. * @hwcg: hw clock gating register sequence
  34. * @protect: CP_PROTECT settings
  35. * @pwrup_reglist pwrup reglist for preemption
  36. */
  37. struct a6xx_info {
  38. const struct adreno_reglist *hwcg;
  39. const struct adreno_protect *protect;
  40. const struct adreno_reglist_list *pwrup_reglist;
  41. const struct adreno_reglist_pipe_list *dyn_pwrup_reglist;
  42. const struct adreno_reglist_list *ifpc_reglist;
  43. const struct adreno_reglist *gbif_cx;
  44. const struct adreno_reglist_pipe *nonctxt_reglist;
  45. u32 max_slices;
  46. u32 gmu_chipid;
  47. u32 gmu_cgc_mode;
  48. u32 prim_fifo_threshold;
  49. const struct a6xx_bcm *bcms;
  50. };
  51. struct a6xx_gpu {
  52. struct adreno_gpu base;
  53. struct drm_gem_object *sqe_bo;
  54. uint64_t sqe_iova;
  55. struct drm_gem_object *aqe_bo;
  56. uint64_t aqe_iova;
  57. struct msm_ringbuffer *cur_ring;
  58. struct msm_ringbuffer *next_ring;
  59. struct drm_gem_object *preempt_bo[MSM_GPU_MAX_RINGS];
  60. void *preempt[MSM_GPU_MAX_RINGS];
  61. uint64_t preempt_iova[MSM_GPU_MAX_RINGS];
  62. struct drm_gem_object *preempt_smmu_bo[MSM_GPU_MAX_RINGS];
  63. void *preempt_smmu[MSM_GPU_MAX_RINGS];
  64. uint64_t preempt_smmu_iova[MSM_GPU_MAX_RINGS];
  65. uint32_t last_seqno[MSM_GPU_MAX_RINGS];
  66. atomic_t preempt_state;
  67. spinlock_t eval_lock;
  68. struct timer_list preempt_timer;
  69. unsigned int preempt_level;
  70. bool uses_gmem;
  71. bool skip_save_restore;
  72. struct drm_gem_object *preempt_postamble_bo;
  73. void *preempt_postamble_ptr;
  74. uint64_t preempt_postamble_iova;
  75. uint64_t preempt_postamble_len;
  76. bool postamble_enabled;
  77. struct a6xx_gmu gmu;
  78. struct drm_gem_object *shadow_bo;
  79. uint64_t shadow_iova;
  80. uint32_t *shadow;
  81. struct drm_gem_object *pwrup_reglist_bo;
  82. void *pwrup_reglist_ptr;
  83. uint64_t pwrup_reglist_iova;
  84. bool pwrup_reglist_emitted;
  85. bool has_whereami;
  86. void __iomem *llc_mmio;
  87. void *llc_slice;
  88. void *htw_llc_slice;
  89. bool have_mmu500;
  90. bool hung;
  91. u32 cached_aperture;
  92. spinlock_t aperture_lock;
  93. u32 slice_mask;
  94. };
  95. #define to_a6xx_gpu(x) container_of(x, struct a6xx_gpu, base)
  96. /*
  97. * In order to do lockless preemption we use a simple state machine to progress
  98. * through the process.
  99. *
  100. * PREEMPT_NONE - no preemption in progress. Next state START.
  101. * PREEMPT_START - The trigger is evaluating if preemption is possible. Next
  102. * states: TRIGGERED, NONE
  103. * PREEMPT_FINISH - An intermediate state before moving back to NONE. Next
  104. * state: NONE.
  105. * PREEMPT_TRIGGERED: A preemption has been executed on the hardware. Next
  106. * states: FAULTED, PENDING
  107. * PREEMPT_FAULTED: A preemption timed out (never completed). This will trigger
  108. * recovery. Next state: N/A
  109. * PREEMPT_PENDING: Preemption complete interrupt fired - the callback is
  110. * checking the success of the operation. Next state: FAULTED, NONE.
  111. */
  112. enum a6xx_preempt_state {
  113. PREEMPT_NONE = 0,
  114. PREEMPT_START,
  115. PREEMPT_FINISH,
  116. PREEMPT_TRIGGERED,
  117. PREEMPT_FAULTED,
  118. PREEMPT_PENDING,
  119. };
  120. /*
  121. * struct a6xx_preempt_record is a shared buffer between the microcode and the
  122. * CPU to store the state for preemption. The record itself is much larger
  123. * (2112k) but most of that is used by the CP for storage.
  124. *
  125. * There is a preemption record assigned per ringbuffer. When the CPU triggers a
  126. * preemption, it fills out the record with the useful information (wptr, ring
  127. * base, etc) and the microcode uses that information to set up the CP following
  128. * the preemption. When a ring is switched out, the CP will save the ringbuffer
  129. * state back to the record. In this way, once the records are properly set up
  130. * the CPU can quickly switch back and forth between ringbuffers by only
  131. * updating a few registers (often only the wptr).
  132. *
  133. * These are the CPU aware registers in the record:
  134. * @magic: Must always be 0xAE399D6EUL
  135. * @info: Type of the record - written 0 by the CPU, updated by the CP
  136. * @errno: preemption error record
  137. * @data: Data field in YIELD and SET_MARKER packets, Written and used by CP
  138. * @cntl: Value of RB_CNTL written by CPU, save/restored by CP
  139. * @rptr: Value of RB_RPTR written by CPU, save/restored by CP
  140. * @wptr: Value of RB_WPTR written by CPU, save/restored by CP
  141. * @_pad: Reserved/padding
  142. * @rptr_addr: Value of RB_RPTR_ADDR_LO|HI written by CPU, save/restored by CP
  143. * @rbase: Value of RB_BASE written by CPU, save/restored by CP
  144. * @counter: GPU address of the storage area for the preemption counters
  145. * @bv_rptr_addr: Value of BV_RB_RPTR_ADDR_LO|HI written by CPU, save/restored by CP
  146. */
  147. struct a6xx_preempt_record {
  148. u32 magic;
  149. u32 info;
  150. u32 errno;
  151. u32 data;
  152. u32 cntl;
  153. u32 rptr;
  154. u32 wptr;
  155. u32 _pad;
  156. u64 rptr_addr;
  157. u64 rbase;
  158. u64 counter;
  159. u64 bv_rptr_addr;
  160. };
  161. #define A6XX_PREEMPT_RECORD_MAGIC 0xAE399D6EUL
  162. #define PREEMPT_SMMU_INFO_SIZE 4096
  163. #define PREEMPT_RECORD_SIZE(adreno_gpu) \
  164. ((adreno_gpu->info->preempt_record_size) == 0 ? \
  165. 4192 * SZ_1K : (adreno_gpu->info->preempt_record_size))
  166. /*
  167. * The preemption counter block is a storage area for the value of the
  168. * preemption counters that are saved immediately before context switch. We
  169. * append it on to the end of the allocation for the preemption record.
  170. */
  171. #define A6XX_PREEMPT_COUNTER_SIZE (16 * 4)
  172. struct a7xx_cp_smmu_info {
  173. u32 magic;
  174. u32 _pad4;
  175. u64 ttbr0;
  176. u32 asid;
  177. u32 context_idr;
  178. u32 context_bank;
  179. };
  180. #define GEN7_CP_SMMU_INFO_MAGIC 0x241350d5UL
  181. /*
  182. * Given a register and a count, return a value to program into
  183. * REG_CP_PROTECT_REG(n) - this will block both reads and writes for
  184. * _len + 1 registers starting at _reg.
  185. */
  186. #define A6XX_PROTECT_NORDWR(_reg, _len) \
  187. ((1 << 31) | \
  188. (((_len) & 0x3FFF) << 18) | ((_reg) & 0x3FFFF))
  189. /*
  190. * Same as above, but allow reads over the range. For areas of mixed use (such
  191. * as performance counters) this allows us to protect a much larger range with a
  192. * single register
  193. */
  194. #define A6XX_PROTECT_RDONLY(_reg, _len) \
  195. ((((_len) & 0x3FFF) << 18) | ((_reg) & 0x3FFFF))
  196. extern const struct adreno_gpu_funcs a6xx_gpu_funcs;
  197. extern const struct adreno_gpu_funcs a6xx_gmuwrapper_funcs;
  198. extern const struct adreno_gpu_funcs a7xx_gpu_funcs;
  199. extern const struct adreno_gpu_funcs a8xx_gpu_funcs;
  200. static inline bool a6xx_has_gbif(struct adreno_gpu *gpu)
  201. {
  202. if(adreno_is_a630(gpu))
  203. return false;
  204. return true;
  205. }
  206. static inline void a6xx_llc_rmw(struct a6xx_gpu *a6xx_gpu, u32 reg, u32 mask, u32 or)
  207. {
  208. return msm_rmw(a6xx_gpu->llc_mmio + (reg << 2), mask, or);
  209. }
  210. static inline u32 a6xx_llc_read(struct a6xx_gpu *a6xx_gpu, u32 reg)
  211. {
  212. return readl(a6xx_gpu->llc_mmio + (reg << 2));
  213. }
  214. static inline void a6xx_llc_write(struct a6xx_gpu *a6xx_gpu, u32 reg, u32 value)
  215. {
  216. writel(value, a6xx_gpu->llc_mmio + (reg << 2));
  217. }
  218. #define shadowptr(_a6xx_gpu, _ring) ((_a6xx_gpu)->shadow_iova + \
  219. ((_ring)->id * sizeof(uint32_t)))
  220. int a6xx_gmu_resume(struct a6xx_gpu *gpu);
  221. int a6xx_gmu_stop(struct a6xx_gpu *gpu);
  222. int a6xx_gmu_wait_for_idle(struct a6xx_gmu *gmu);
  223. bool a6xx_gmu_isidle(struct a6xx_gmu *gmu);
  224. int a6xx_gmu_set_oob(struct a6xx_gmu *gmu, enum a6xx_gmu_oob_state state);
  225. void a6xx_gmu_clear_oob(struct a6xx_gmu *gmu, enum a6xx_gmu_oob_state state);
  226. int a6xx_gmu_init(struct a6xx_gpu *a6xx_gpu, struct device_node *node);
  227. int a6xx_gmu_wrapper_init(struct a6xx_gpu *a6xx_gpu, struct device_node *node);
  228. void a6xx_gmu_remove(struct a6xx_gpu *a6xx_gpu);
  229. void a6xx_gmu_sysprof_setup(struct msm_gpu *gpu);
  230. void a6xx_preempt_init(struct msm_gpu *gpu);
  231. void a6xx_preempt_hw_init(struct msm_gpu *gpu);
  232. void a6xx_preempt_trigger(struct msm_gpu *gpu);
  233. void a6xx_preempt_irq(struct msm_gpu *gpu);
  234. void a6xx_preempt_fini(struct msm_gpu *gpu);
  235. int a6xx_preempt_submitqueue_setup(struct msm_gpu *gpu,
  236. struct msm_gpu_submitqueue *queue);
  237. void a6xx_preempt_submitqueue_close(struct msm_gpu *gpu,
  238. struct msm_gpu_submitqueue *queue);
  239. /* Return true if we are in a preempt state */
  240. static inline bool a6xx_in_preempt(struct a6xx_gpu *a6xx_gpu)
  241. {
  242. /*
  243. * Make sure the read to preempt_state is ordered with respect to reads
  244. * of other variables before ...
  245. */
  246. smp_rmb();
  247. int preempt_state = atomic_read(&a6xx_gpu->preempt_state);
  248. /* ... and after. */
  249. smp_rmb();
  250. return !(preempt_state == PREEMPT_NONE ||
  251. preempt_state == PREEMPT_FINISH);
  252. }
  253. void a6xx_gmu_set_freq(struct msm_gpu *gpu, struct dev_pm_opp *opp,
  254. bool suspended);
  255. unsigned long a6xx_gmu_get_freq(struct msm_gpu *gpu);
  256. void a6xx_show(struct msm_gpu *gpu, struct msm_gpu_state *state,
  257. struct drm_printer *p);
  258. struct msm_gpu_state *a6xx_gpu_state_get(struct msm_gpu *gpu);
  259. int a6xx_gpu_state_put(struct msm_gpu_state *state);
  260. void a6xx_bus_clear_pending_transactions(struct adreno_gpu *adreno_gpu, bool gx_off);
  261. void a6xx_gpu_sw_reset(struct msm_gpu *gpu, bool assert);
  262. int a6xx_fenced_write(struct a6xx_gpu *gpu, u32 offset, u64 value, u32 mask, bool is_64b);
  263. void a6xx_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  264. int a6xx_zap_shader_init(struct msm_gpu *gpu);
  265. void a8xx_bus_clear_pending_transactions(struct adreno_gpu *adreno_gpu, bool gx_off);
  266. int a8xx_fault_handler(void *arg, unsigned long iova, int flags, void *data);
  267. void a8xx_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  268. int a8xx_gmu_get_timestamp(struct msm_gpu *gpu, uint64_t *value);
  269. u64 a8xx_gpu_busy(struct msm_gpu *gpu, unsigned long *out_sample_rate);
  270. int a8xx_gpu_feature_probe(struct msm_gpu *gpu);
  271. void a8xx_gpu_get_slice_info(struct msm_gpu *gpu);
  272. int a8xx_hw_init(struct msm_gpu *gpu);
  273. irqreturn_t a8xx_irq(struct msm_gpu *gpu);
  274. void a8xx_llc_activate(struct a6xx_gpu *a6xx_gpu);
  275. bool a8xx_progress(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  276. void a8xx_recover(struct msm_gpu *gpu);
  277. #endif /* __A6XX_GPU_H__ */