adreno_gpu.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __ADRENO_GPU_H__
  18. #define __ADRENO_GPU_H__
  19. #include <linux/firmware.h>
  20. #include "msm_gpu.h"
  21. #include "adreno_common.xml.h"
  22. #include "adreno_pm4.xml.h"
  23. struct adreno_rev {
  24. uint8_t core;
  25. uint8_t major;
  26. uint8_t minor;
  27. uint8_t patchid;
  28. };
  29. #define ADRENO_REV(core, major, minor, patchid) \
  30. ((struct adreno_rev){ core, major, minor, patchid })
  31. struct adreno_gpu_funcs {
  32. struct msm_gpu_funcs base;
  33. };
  34. struct adreno_info {
  35. struct adreno_rev rev;
  36. uint32_t revn;
  37. const char *name;
  38. const char *pm4fw, *pfpfw;
  39. uint32_t gmem;
  40. struct msm_gpu *(*init)(struct drm_device *dev);
  41. };
  42. const struct adreno_info *adreno_info(struct adreno_rev rev);
  43. struct adreno_rbmemptrs {
  44. volatile uint32_t rptr;
  45. volatile uint32_t wptr;
  46. volatile uint32_t fence;
  47. };
  48. struct adreno_gpu {
  49. struct msm_gpu base;
  50. struct adreno_rev rev;
  51. const struct adreno_info *info;
  52. uint32_t gmem; /* actual gmem size */
  53. uint32_t revn; /* numeric revision name */
  54. const struct adreno_gpu_funcs *funcs;
  55. /* interesting register offsets to dump: */
  56. const unsigned int *registers;
  57. /* firmware: */
  58. const struct firmware *pm4, *pfp;
  59. /* ringbuffer rptr/wptr: */
  60. // TODO should this be in msm_ringbuffer? I think it would be
  61. // different for z180..
  62. struct adreno_rbmemptrs *memptrs;
  63. struct drm_gem_object *memptrs_bo;
  64. uint32_t memptrs_iova;
  65. };
  66. #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
  67. /* platform config data (ie. from DT, or pdata) */
  68. struct adreno_platform_config {
  69. struct adreno_rev rev;
  70. uint32_t fast_rate, slow_rate, bus_freq;
  71. #ifdef CONFIG_MSM_BUS_SCALING
  72. struct msm_bus_scale_pdata *bus_scale_table;
  73. #endif
  74. };
  75. #define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000)
  76. #define spin_until(X) ({ \
  77. int __ret = -ETIMEDOUT; \
  78. unsigned long __t = jiffies + ADRENO_IDLE_TIMEOUT; \
  79. do { \
  80. if (X) { \
  81. __ret = 0; \
  82. break; \
  83. } \
  84. } while (time_before(jiffies, __t)); \
  85. __ret; \
  86. })
  87. static inline bool adreno_is_a3xx(struct adreno_gpu *gpu)
  88. {
  89. return (gpu->revn >= 300) && (gpu->revn < 400);
  90. }
  91. static inline bool adreno_is_a305(struct adreno_gpu *gpu)
  92. {
  93. return gpu->revn == 305;
  94. }
  95. static inline bool adreno_is_a320(struct adreno_gpu *gpu)
  96. {
  97. return gpu->revn == 320;
  98. }
  99. static inline bool adreno_is_a330(struct adreno_gpu *gpu)
  100. {
  101. return gpu->revn == 330;
  102. }
  103. static inline bool adreno_is_a330v2(struct adreno_gpu *gpu)
  104. {
  105. return adreno_is_a330(gpu) && (gpu->rev.patchid > 0);
  106. }
  107. int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
  108. int adreno_hw_init(struct msm_gpu *gpu);
  109. uint32_t adreno_last_fence(struct msm_gpu *gpu);
  110. void adreno_recover(struct msm_gpu *gpu);
  111. int adreno_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  112. struct msm_file_private *ctx);
  113. void adreno_flush(struct msm_gpu *gpu);
  114. void adreno_idle(struct msm_gpu *gpu);
  115. #ifdef CONFIG_DEBUG_FS
  116. void adreno_show(struct msm_gpu *gpu, struct seq_file *m);
  117. #endif
  118. void adreno_dump(struct msm_gpu *gpu);
  119. void adreno_wait_ring(struct msm_gpu *gpu, uint32_t ndwords);
  120. int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  121. struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs);
  122. void adreno_gpu_cleanup(struct adreno_gpu *gpu);
  123. /* ringbuffer helpers (the parts that are adreno specific) */
  124. static inline void
  125. OUT_PKT0(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt)
  126. {
  127. adreno_wait_ring(ring->gpu, cnt+1);
  128. OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF));
  129. }
  130. /* no-op packet: */
  131. static inline void
  132. OUT_PKT2(struct msm_ringbuffer *ring)
  133. {
  134. adreno_wait_ring(ring->gpu, 1);
  135. OUT_RING(ring, CP_TYPE2_PKT);
  136. }
  137. static inline void
  138. OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt)
  139. {
  140. adreno_wait_ring(ring->gpu, cnt+1);
  141. OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8));
  142. }
  143. #endif /* __ADRENO_GPU_H__ */