adreno_gpu.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_rbmemptrs {
  36. volatile uint32_t rptr;
  37. volatile uint32_t wptr;
  38. volatile uint32_t fence;
  39. };
  40. struct adreno_gpu {
  41. struct msm_gpu base;
  42. struct adreno_rev rev;
  43. const struct adreno_info *info;
  44. uint32_t gmem; /* actual gmem size */
  45. uint32_t revn; /* numeric revision name */
  46. const struct adreno_gpu_funcs *funcs;
  47. /* firmware: */
  48. const struct firmware *pm4, *pfp;
  49. /* ringbuffer rptr/wptr: */
  50. // TODO should this be in msm_ringbuffer? I think it would be
  51. // different for z180..
  52. struct adreno_rbmemptrs *memptrs;
  53. struct drm_gem_object *memptrs_bo;
  54. uint32_t memptrs_iova;
  55. };
  56. #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
  57. /* platform config data (ie. from DT, or pdata) */
  58. struct adreno_platform_config {
  59. struct adreno_rev rev;
  60. uint32_t fast_rate, slow_rate, bus_freq;
  61. #ifdef CONFIG_MSM_BUS_SCALING
  62. struct msm_bus_scale_pdata *bus_scale_table;
  63. #endif
  64. };
  65. #define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000)
  66. #define spin_until(X) ({ \
  67. int __ret = -ETIMEDOUT; \
  68. unsigned long __t = jiffies + ADRENO_IDLE_TIMEOUT; \
  69. do { \
  70. if (X) { \
  71. __ret = 0; \
  72. break; \
  73. } \
  74. } while (time_before(jiffies, __t)); \
  75. __ret; \
  76. })
  77. static inline bool adreno_is_a3xx(struct adreno_gpu *gpu)
  78. {
  79. return (gpu->revn >= 300) && (gpu->revn < 400);
  80. }
  81. static inline bool adreno_is_a305(struct adreno_gpu *gpu)
  82. {
  83. return gpu->revn == 305;
  84. }
  85. static inline bool adreno_is_a320(struct adreno_gpu *gpu)
  86. {
  87. return gpu->revn == 320;
  88. }
  89. static inline bool adreno_is_a330(struct adreno_gpu *gpu)
  90. {
  91. return gpu->revn == 330;
  92. }
  93. static inline bool adreno_is_a330v2(struct adreno_gpu *gpu)
  94. {
  95. return adreno_is_a330(gpu) && (gpu->rev.patchid > 0);
  96. }
  97. int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
  98. int adreno_hw_init(struct msm_gpu *gpu);
  99. uint32_t adreno_last_fence(struct msm_gpu *gpu);
  100. void adreno_recover(struct msm_gpu *gpu);
  101. int adreno_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  102. struct msm_file_private *ctx);
  103. void adreno_flush(struct msm_gpu *gpu);
  104. void adreno_idle(struct msm_gpu *gpu);
  105. #ifdef CONFIG_DEBUG_FS
  106. void adreno_show(struct msm_gpu *gpu, struct seq_file *m);
  107. #endif
  108. void adreno_dump(struct msm_gpu *gpu);
  109. void adreno_wait_ring(struct msm_gpu *gpu, uint32_t ndwords);
  110. int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  111. struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs,
  112. struct adreno_rev rev);
  113. void adreno_gpu_cleanup(struct adreno_gpu *gpu);
  114. /* ringbuffer helpers (the parts that are adreno specific) */
  115. static inline void
  116. OUT_PKT0(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt)
  117. {
  118. adreno_wait_ring(ring->gpu, cnt+1);
  119. OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF));
  120. }
  121. /* no-op packet: */
  122. static inline void
  123. OUT_PKT2(struct msm_ringbuffer *ring)
  124. {
  125. adreno_wait_ring(ring->gpu, 1);
  126. OUT_RING(ring, CP_TYPE2_PKT);
  127. }
  128. static inline void
  129. OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt)
  130. {
  131. adreno_wait_ring(ring->gpu, cnt+1);
  132. OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8));
  133. }
  134. #endif /* __ADRENO_GPU_H__ */