a5xx_gpu.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
  3. */
  4. #ifndef __A5XX_GPU_H__
  5. #define __A5XX_GPU_H__
  6. #include "adreno_gpu.h"
  7. /* Bringing over the hack from the previous targets */
  8. #undef ROP_COPY
  9. #undef ROP_XOR
  10. #include "a5xx.xml.h"
  11. struct a5xx_gpu {
  12. struct adreno_gpu base;
  13. struct drm_gem_object *pm4_bo;
  14. uint64_t pm4_iova;
  15. struct drm_gem_object *pfp_bo;
  16. uint64_t pfp_iova;
  17. struct drm_gem_object *gpmu_bo;
  18. uint64_t gpmu_iova;
  19. uint32_t gpmu_dwords;
  20. uint32_t lm_leakage;
  21. struct msm_ringbuffer *cur_ring;
  22. struct msm_ringbuffer *next_ring;
  23. struct drm_gem_object *preempt_bo[MSM_GPU_MAX_RINGS];
  24. struct drm_gem_object *preempt_counters_bo[MSM_GPU_MAX_RINGS];
  25. struct a5xx_preempt_record *preempt[MSM_GPU_MAX_RINGS];
  26. uint64_t preempt_iova[MSM_GPU_MAX_RINGS];
  27. uint32_t last_seqno[MSM_GPU_MAX_RINGS];
  28. atomic_t preempt_state;
  29. spinlock_t preempt_start_lock;
  30. struct timer_list preempt_timer;
  31. struct drm_gem_object *shadow_bo;
  32. uint64_t shadow_iova;
  33. uint32_t *shadow;
  34. /* True if the microcode supports the WHERE_AM_I opcode */
  35. bool has_whereami;
  36. };
  37. #define to_a5xx_gpu(x) container_of(x, struct a5xx_gpu, base)
  38. #ifdef CONFIG_DEBUG_FS
  39. void a5xx_debugfs_init(struct msm_gpu *gpu, struct drm_minor *minor);
  40. #endif
  41. /*
  42. * In order to do lockless preemption we use a simple state machine to progress
  43. * through the process.
  44. *
  45. * PREEMPT_NONE - no preemption in progress. Next state START.
  46. * PREEMPT_START - The trigger is evaulating if preemption is possible. Next
  47. * states: TRIGGERED, NONE
  48. * PREEMPT_ABORT - An intermediate state before moving back to NONE. Next
  49. * state: NONE.
  50. * PREEMPT_TRIGGERED: A preemption has been executed on the hardware. Next
  51. * states: FAULTED, PENDING
  52. * PREEMPT_FAULTED: A preemption timed out (never completed). This will trigger
  53. * recovery. Next state: N/A
  54. * PREEMPT_PENDING: Preemption complete interrupt fired - the callback is
  55. * checking the success of the operation. Next state: FAULTED, NONE.
  56. */
  57. enum preempt_state {
  58. PREEMPT_NONE = 0,
  59. PREEMPT_START,
  60. PREEMPT_ABORT,
  61. PREEMPT_TRIGGERED,
  62. PREEMPT_FAULTED,
  63. PREEMPT_PENDING,
  64. };
  65. /*
  66. * struct a5xx_preempt_record is a shared buffer between the microcode and the
  67. * CPU to store the state for preemption. The record itself is much larger
  68. * (64k) but most of that is used by the CP for storage.
  69. *
  70. * There is a preemption record assigned per ringbuffer. When the CPU triggers a
  71. * preemption, it fills out the record with the useful information (wptr, ring
  72. * base, etc) and the microcode uses that information to set up the CP following
  73. * the preemption. When a ring is switched out, the CP will save the ringbuffer
  74. * state back to the record. In this way, once the records are properly set up
  75. * the CPU can quickly switch back and forth between ringbuffers by only
  76. * updating a few registers (often only the wptr).
  77. *
  78. * These are the CPU aware registers in the record:
  79. * @magic: Must always be 0x27C4BAFC
  80. * @info: Type of the record - written 0 by the CPU, updated by the CP
  81. * @data: Data field from SET_RENDER_MODE or a checkpoint. Written and used by
  82. * the CP
  83. * @cntl: Value of RB_CNTL written by CPU, save/restored by CP
  84. * @rptr: Value of RB_RPTR written by CPU, save/restored by CP
  85. * @wptr: Value of RB_WPTR written by CPU, save/restored by CP
  86. * @rptr_addr: Value of RB_RPTR_ADDR written by CPU, save/restored by CP
  87. * @rbase: Value of RB_BASE written by CPU, save/restored by CP
  88. * @counter: GPU address of the storage area for the performance counters
  89. */
  90. struct a5xx_preempt_record {
  91. uint32_t magic;
  92. uint32_t info;
  93. uint32_t data;
  94. uint32_t cntl;
  95. uint32_t rptr;
  96. uint32_t wptr;
  97. uint64_t rptr_addr;
  98. uint64_t rbase;
  99. uint64_t counter;
  100. };
  101. /* Magic identifier for the preemption record */
  102. #define A5XX_PREEMPT_RECORD_MAGIC 0x27C4BAFCUL
  103. /*
  104. * Even though the structure above is only a few bytes, we need a full 64k to
  105. * store the entire preemption record from the CP
  106. */
  107. #define A5XX_PREEMPT_RECORD_SIZE (64 * 1024)
  108. /*
  109. * The preemption counter block is a storage area for the value of the
  110. * preemption counters that are saved immediately before context switch. We
  111. * append it on to the end of the allocation for the preemption record.
  112. */
  113. #define A5XX_PREEMPT_COUNTER_SIZE (16 * 4)
  114. extern const struct adreno_gpu_funcs a5xx_gpu_funcs;
  115. int a5xx_power_init(struct msm_gpu *gpu);
  116. void a5xx_gpmu_ucode_init(struct msm_gpu *gpu);
  117. static inline int spin_usecs(struct msm_gpu *gpu, uint32_t usecs,
  118. uint32_t reg, uint32_t mask, uint32_t value)
  119. {
  120. while (usecs--) {
  121. udelay(1);
  122. if ((gpu_read(gpu, reg) & mask) == value)
  123. return 0;
  124. cpu_relax();
  125. }
  126. return -ETIMEDOUT;
  127. }
  128. #define shadowptr(a5xx_gpu, ring) ((a5xx_gpu)->shadow_iova + \
  129. ((ring)->id * sizeof(uint32_t)))
  130. bool a5xx_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  131. void a5xx_set_hwcg(struct msm_gpu *gpu, bool state);
  132. void a5xx_preempt_init(struct msm_gpu *gpu);
  133. void a5xx_preempt_hw_init(struct msm_gpu *gpu);
  134. void a5xx_preempt_trigger(struct msm_gpu *gpu);
  135. void a5xx_preempt_irq(struct msm_gpu *gpu);
  136. void a5xx_preempt_fini(struct msm_gpu *gpu);
  137. void a5xx_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring, bool sync);
  138. /* Return true if we are in a preempt state */
  139. static inline bool a5xx_in_preempt(struct a5xx_gpu *a5xx_gpu)
  140. {
  141. int preempt_state = atomic_read(&a5xx_gpu->preempt_state);
  142. return !(preempt_state == PREEMPT_NONE ||
  143. preempt_state == PREEMPT_ABORT);
  144. }
  145. #endif /* __A5XX_GPU_H__ */