adreno_gpu.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ADRENO_GPU_H__
  20. #define __ADRENO_GPU_H__
  21. #include <linux/firmware.h>
  22. #include "msm_gpu.h"
  23. #include "adreno_common.xml.h"
  24. #include "adreno_pm4.xml.h"
  25. #define REG_ADRENO_DEFINE(_offset, _reg) [_offset] = (_reg) + 1
  26. /**
  27. * adreno_regs: List of registers that are used in across all
  28. * 3D devices. Each device type has different offset value for the same
  29. * register, so an array of register offsets are declared for every device
  30. * and are indexed by the enumeration values defined in this enum
  31. */
  32. enum adreno_regs {
  33. REG_ADRENO_CP_DEBUG,
  34. REG_ADRENO_CP_ME_RAM_WADDR,
  35. REG_ADRENO_CP_ME_RAM_DATA,
  36. REG_ADRENO_CP_PFP_UCODE_DATA,
  37. REG_ADRENO_CP_PFP_UCODE_ADDR,
  38. REG_ADRENO_CP_WFI_PEND_CTR,
  39. REG_ADRENO_CP_RB_BASE,
  40. REG_ADRENO_CP_RB_RPTR_ADDR,
  41. REG_ADRENO_CP_RB_RPTR,
  42. REG_ADRENO_CP_RB_WPTR,
  43. REG_ADRENO_CP_PROTECT_CTRL,
  44. REG_ADRENO_CP_ME_CNTL,
  45. REG_ADRENO_CP_RB_CNTL,
  46. REG_ADRENO_CP_IB1_BASE,
  47. REG_ADRENO_CP_IB1_BUFSZ,
  48. REG_ADRENO_CP_IB2_BASE,
  49. REG_ADRENO_CP_IB2_BUFSZ,
  50. REG_ADRENO_CP_TIMESTAMP,
  51. REG_ADRENO_CP_ME_RAM_RADDR,
  52. REG_ADRENO_CP_ROQ_ADDR,
  53. REG_ADRENO_CP_ROQ_DATA,
  54. REG_ADRENO_CP_MERCIU_ADDR,
  55. REG_ADRENO_CP_MERCIU_DATA,
  56. REG_ADRENO_CP_MERCIU_DATA2,
  57. REG_ADRENO_CP_MEQ_ADDR,
  58. REG_ADRENO_CP_MEQ_DATA,
  59. REG_ADRENO_CP_HW_FAULT,
  60. REG_ADRENO_CP_PROTECT_STATUS,
  61. REG_ADRENO_SCRATCH_ADDR,
  62. REG_ADRENO_SCRATCH_UMSK,
  63. REG_ADRENO_SCRATCH_REG2,
  64. REG_ADRENO_RBBM_STATUS,
  65. REG_ADRENO_RBBM_PERFCTR_CTL,
  66. REG_ADRENO_RBBM_PERFCTR_LOAD_CMD0,
  67. REG_ADRENO_RBBM_PERFCTR_LOAD_CMD1,
  68. REG_ADRENO_RBBM_PERFCTR_LOAD_CMD2,
  69. REG_ADRENO_RBBM_PERFCTR_PWR_1_LO,
  70. REG_ADRENO_RBBM_INT_0_MASK,
  71. REG_ADRENO_RBBM_INT_0_STATUS,
  72. REG_ADRENO_RBBM_AHB_ERROR_STATUS,
  73. REG_ADRENO_RBBM_PM_OVERRIDE2,
  74. REG_ADRENO_RBBM_AHB_CMD,
  75. REG_ADRENO_RBBM_INT_CLEAR_CMD,
  76. REG_ADRENO_RBBM_SW_RESET_CMD,
  77. REG_ADRENO_RBBM_CLOCK_CTL,
  78. REG_ADRENO_RBBM_AHB_ME_SPLIT_STATUS,
  79. REG_ADRENO_RBBM_AHB_PFP_SPLIT_STATUS,
  80. REG_ADRENO_VPC_DEBUG_RAM_SEL,
  81. REG_ADRENO_VPC_DEBUG_RAM_READ,
  82. REG_ADRENO_VSC_SIZE_ADDRESS,
  83. REG_ADRENO_VFD_CONTROL_0,
  84. REG_ADRENO_VFD_INDEX_MAX,
  85. REG_ADRENO_SP_VS_PVT_MEM_ADDR_REG,
  86. REG_ADRENO_SP_FS_PVT_MEM_ADDR_REG,
  87. REG_ADRENO_SP_VS_OBJ_START_REG,
  88. REG_ADRENO_SP_FS_OBJ_START_REG,
  89. REG_ADRENO_PA_SC_AA_CONFIG,
  90. REG_ADRENO_SQ_GPR_MANAGEMENT,
  91. REG_ADRENO_SQ_INST_STORE_MANAGMENT,
  92. REG_ADRENO_TP0_CHICKEN,
  93. REG_ADRENO_RBBM_RBBM_CTL,
  94. REG_ADRENO_UCHE_INVALIDATE0,
  95. REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_LO,
  96. REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_HI,
  97. REG_ADRENO_REGISTER_MAX,
  98. };
  99. struct adreno_rev {
  100. uint8_t core;
  101. uint8_t major;
  102. uint8_t minor;
  103. uint8_t patchid;
  104. };
  105. #define ADRENO_REV(core, major, minor, patchid) \
  106. ((struct adreno_rev){ core, major, minor, patchid })
  107. struct adreno_gpu_funcs {
  108. struct msm_gpu_funcs base;
  109. int (*get_timestamp)(struct msm_gpu *gpu, uint64_t *value);
  110. };
  111. struct adreno_info {
  112. struct adreno_rev rev;
  113. uint32_t revn;
  114. const char *name;
  115. const char *pm4fw, *pfpfw;
  116. uint32_t gmem;
  117. struct msm_gpu *(*init)(struct drm_device *dev);
  118. };
  119. const struct adreno_info *adreno_info(struct adreno_rev rev);
  120. struct adreno_rbmemptrs {
  121. volatile uint32_t rptr;
  122. volatile uint32_t wptr;
  123. volatile uint32_t fence;
  124. };
  125. struct adreno_gpu {
  126. struct msm_gpu base;
  127. struct adreno_rev rev;
  128. const struct adreno_info *info;
  129. uint32_t gmem; /* actual gmem size */
  130. uint32_t revn; /* numeric revision name */
  131. const struct adreno_gpu_funcs *funcs;
  132. /* interesting register offsets to dump: */
  133. const unsigned int *registers;
  134. /* firmware: */
  135. const struct firmware *pm4, *pfp;
  136. /* ringbuffer rptr/wptr: */
  137. // TODO should this be in msm_ringbuffer? I think it would be
  138. // different for z180..
  139. struct adreno_rbmemptrs *memptrs;
  140. struct drm_gem_object *memptrs_bo;
  141. uint32_t memptrs_iova;
  142. /*
  143. * Register offsets are different between some GPUs.
  144. * GPU specific offsets will be exported by GPU specific
  145. * code (a3xx_gpu.c) and stored in this common location.
  146. */
  147. const unsigned int *reg_offsets;
  148. };
  149. #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
  150. /* platform config data (ie. from DT, or pdata) */
  151. struct adreno_platform_config {
  152. struct adreno_rev rev;
  153. uint32_t fast_rate, slow_rate, bus_freq;
  154. #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  155. struct msm_bus_scale_pdata *bus_scale_table;
  156. #endif
  157. };
  158. #define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000)
  159. #define spin_until(X) ({ \
  160. int __ret = -ETIMEDOUT; \
  161. unsigned long __t = jiffies + ADRENO_IDLE_TIMEOUT; \
  162. do { \
  163. if (X) { \
  164. __ret = 0; \
  165. break; \
  166. } \
  167. } while (time_before(jiffies, __t)); \
  168. __ret; \
  169. })
  170. static inline bool adreno_is_a3xx(struct adreno_gpu *gpu)
  171. {
  172. return (gpu->revn >= 300) && (gpu->revn < 400);
  173. }
  174. static inline bool adreno_is_a305(struct adreno_gpu *gpu)
  175. {
  176. return gpu->revn == 305;
  177. }
  178. static inline bool adreno_is_a306(struct adreno_gpu *gpu)
  179. {
  180. /* yes, 307, because a305c is 306 */
  181. return gpu->revn == 307;
  182. }
  183. static inline bool adreno_is_a320(struct adreno_gpu *gpu)
  184. {
  185. return gpu->revn == 320;
  186. }
  187. static inline bool adreno_is_a330(struct adreno_gpu *gpu)
  188. {
  189. return gpu->revn == 330;
  190. }
  191. static inline bool adreno_is_a330v2(struct adreno_gpu *gpu)
  192. {
  193. return adreno_is_a330(gpu) && (gpu->rev.patchid > 0);
  194. }
  195. static inline bool adreno_is_a4xx(struct adreno_gpu *gpu)
  196. {
  197. return (gpu->revn >= 400) && (gpu->revn < 500);
  198. }
  199. static inline int adreno_is_a420(struct adreno_gpu *gpu)
  200. {
  201. return gpu->revn == 420;
  202. }
  203. static inline int adreno_is_a430(struct adreno_gpu *gpu)
  204. {
  205. return gpu->revn == 430;
  206. }
  207. int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
  208. int adreno_hw_init(struct msm_gpu *gpu);
  209. uint32_t adreno_last_fence(struct msm_gpu *gpu);
  210. void adreno_recover(struct msm_gpu *gpu);
  211. int adreno_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  212. struct msm_file_private *ctx);
  213. void adreno_flush(struct msm_gpu *gpu);
  214. void adreno_idle(struct msm_gpu *gpu);
  215. #ifdef CONFIG_DEBUG_FS
  216. void adreno_show(struct msm_gpu *gpu, struct seq_file *m);
  217. #endif
  218. void adreno_dump_info(struct msm_gpu *gpu);
  219. void adreno_dump(struct msm_gpu *gpu);
  220. void adreno_wait_ring(struct msm_gpu *gpu, uint32_t ndwords);
  221. int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  222. struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs);
  223. void adreno_gpu_cleanup(struct adreno_gpu *gpu);
  224. /* ringbuffer helpers (the parts that are adreno specific) */
  225. static inline void
  226. OUT_PKT0(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt)
  227. {
  228. adreno_wait_ring(ring->gpu, cnt+1);
  229. OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF));
  230. }
  231. /* no-op packet: */
  232. static inline void
  233. OUT_PKT2(struct msm_ringbuffer *ring)
  234. {
  235. adreno_wait_ring(ring->gpu, 1);
  236. OUT_RING(ring, CP_TYPE2_PKT);
  237. }
  238. static inline void
  239. OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt)
  240. {
  241. adreno_wait_ring(ring->gpu, cnt+1);
  242. OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8));
  243. }
  244. /*
  245. * adreno_checkreg_off() - Checks the validity of a register enum
  246. * @gpu: Pointer to struct adreno_gpu
  247. * @offset_name: The register enum that is checked
  248. */
  249. static inline bool adreno_reg_check(struct adreno_gpu *gpu,
  250. enum adreno_regs offset_name)
  251. {
  252. if (offset_name >= REG_ADRENO_REGISTER_MAX ||
  253. !gpu->reg_offsets[offset_name]) {
  254. BUG();
  255. }
  256. return true;
  257. }
  258. static inline u32 adreno_gpu_read(struct adreno_gpu *gpu,
  259. enum adreno_regs offset_name)
  260. {
  261. u32 reg = gpu->reg_offsets[offset_name];
  262. u32 val = 0;
  263. if(adreno_reg_check(gpu,offset_name))
  264. val = gpu_read(&gpu->base, reg - 1);
  265. return val;
  266. }
  267. static inline void adreno_gpu_write(struct adreno_gpu *gpu,
  268. enum adreno_regs offset_name, u32 data)
  269. {
  270. u32 reg = gpu->reg_offsets[offset_name];
  271. if(adreno_reg_check(gpu, offset_name))
  272. gpu_write(&gpu->base, reg - 1, data);
  273. }
  274. #endif /* __ADRENO_GPU_H__ */