adreno_a5xx.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2017,2019-2020 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022,2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _ADRENO_A5XX_H_
  7. #define _ADRENO_A5XX_H_
  8. #include "a5xx_reg.h"
  9. /**
  10. * struct adreno_a5xx_core - a5xx specific GPU core definitions
  11. */
  12. struct adreno_a5xx_core {
  13. /** @base: Container for the generic &struct adreno_gpu_core */
  14. struct adreno_gpu_core base;
  15. /** @gpmu_tsens: ID for the temperature sensor used by the GPMU */
  16. unsigned int gpmu_tsens;
  17. /** @max_power: Max possible power draw of a core */
  18. unsigned int max_power;
  19. /** pm4fw_name: Name of the PM4 microcode file */
  20. const char *pm4fw_name;
  21. /** pfpfw_name: Name of the PFP microcode file */
  22. const char *pfpfw_name;
  23. /** gpmufw_name: Name of the GPMU microcode file */
  24. const char *gpmufw_name;
  25. /** @regfw_name: Filename for the LM registers if applicable */
  26. const char *regfw_name;
  27. /** @zap_name: Name of the CPZ zap file */
  28. const char *zap_name;
  29. /** @hwcg: List of registers and values to write for HWCG */
  30. const struct kgsl_regmap_list *hwcg;
  31. /** @hwcg_count: Number of registers in @hwcg */
  32. u32 hwcg_count;
  33. /** @vbif: List of registers and values to write for VBIF */
  34. const struct kgsl_regmap_list *vbif;
  35. /** @vbif_count: Number of registers in @vbif */
  36. u32 vbif_count;
  37. /** @highest_bank_bit: The bit of the highest DDR bank */
  38. u32 highest_bank_bit;
  39. };
  40. #define A5XX_CP_CTXRECORD_MAGIC_REF 0x27C4BAFCUL
  41. /* Size of each CP preemption record */
  42. #define A5XX_CP_CTXRECORD_SIZE_IN_BYTES 0x10000
  43. /* Size of the preemption counter block (in bytes) */
  44. #define A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE (16 * 4)
  45. /**
  46. * struct a5xx_cp_preemption_record - CP context record for
  47. * preemption.
  48. * @magic: (00) Value at this offset must be equal to
  49. * A5XX_CP_CTXRECORD_MAGIC_REF.
  50. * @info: (04) Type of record. Written non-zero (usually) by CP.
  51. * we must set to zero for all ringbuffers.
  52. * @data: (08) DATA field in SET_RENDER_MODE or checkpoint packets.
  53. * Written by CP when switching out. Not used on switch-in.
  54. * we must initialize to zero.
  55. * @cntl: (12) RB_CNTL, saved and restored by CP.
  56. * @rptr: (16) RB_RPTR, saved and restored by CP.
  57. * @wptr: (20) RB_WPTR, saved and restored by CP.
  58. * @rptr_addr: (24) RB_RPTR_ADDR_LO|HI saved and restored.
  59. * rbase: (32) RB_BASE_LO|HI saved and restored.
  60. * counter: (40) Pointer to preemption counter
  61. */
  62. struct a5xx_cp_preemption_record {
  63. uint32_t magic;
  64. uint32_t info;
  65. uint32_t data;
  66. uint32_t cntl;
  67. uint32_t rptr;
  68. uint32_t wptr;
  69. uint64_t rptr_addr;
  70. uint64_t rbase;
  71. uint64_t counter;
  72. };
  73. #define A5XX_CP_SMMU_INFO_MAGIC_REF 0x3618CDA3UL
  74. /**
  75. * struct a5xx_cp_smmu_info - CP preemption SMMU info.
  76. * @magic: (00) The value at this offset must be equal to
  77. * A5XX_CP_SMMU_INFO_MAGIC_REF.
  78. * @_pad4: (04) Reserved/padding
  79. * @ttbr0: (08) Base address of the page table for the
  80. * incoming context.
  81. * @context_idr: (16) Context Identification Register value.
  82. */
  83. struct a5xx_cp_smmu_info {
  84. uint32_t magic;
  85. uint32_t _pad4;
  86. uint64_t ttbr0;
  87. uint32_t asid;
  88. uint32_t context_idr;
  89. };
  90. void a5xx_snapshot(struct adreno_device *adreno_dev,
  91. struct kgsl_snapshot *snapshot);
  92. unsigned int a5xx_num_registers(void);
  93. void a5xx_crashdump_init(struct adreno_device *adreno_dev);
  94. void a5xx_hwcg_set(struct adreno_device *adreno_dev, bool on);
  95. #define A5XX_CP_RB_CNTL_DEFAULT ((1 << 27) | ((ilog2(4) << 8) & 0x1F00) | \
  96. (ilog2(KGSL_RB_DWORDS >> 1) & 0x3F))
  97. /* GPMU interrupt multiplexor */
  98. #define FW_INTR_INFO (0)
  99. #define LLM_ACK_ERR_INTR (1)
  100. #define ISENS_TRIM_ERR_INTR (2)
  101. #define ISENS_ERR_INTR (3)
  102. #define ISENS_IDLE_ERR_INTR (4)
  103. #define ISENS_PWR_ON_ERR_INTR (5)
  104. #define WDOG_EXPITED (31)
  105. #define VALID_GPMU_IRQ (\
  106. BIT(FW_INTR_INFO) | \
  107. BIT(LLM_ACK_ERR_INTR) | \
  108. BIT(ISENS_TRIM_ERR_INTR) | \
  109. BIT(ISENS_ERR_INTR) | \
  110. BIT(ISENS_IDLE_ERR_INTR) | \
  111. BIT(ISENS_PWR_ON_ERR_INTR) | \
  112. BIT(WDOG_EXPITED))
  113. /* A5XX_GPMU_GPMU_LLM_GLM_SLEEP_CTRL */
  114. #define STATE_OF_CHILD GENMASK(5, 4)
  115. #define STATE_OF_CHILD_01 BIT(4)
  116. #define STATE_OF_CHILD_11 (BIT(4) | BIT(5))
  117. #define IDLE_FULL_LM_SLEEP BIT(0)
  118. /* A5XX_GPMU_GPMU_LLM_GLM_SLEEP_STATUS */
  119. #define WAKEUP_ACK BIT(1)
  120. #define IDLE_FULL_ACK BIT(0)
  121. /* A5XX_GPMU_GPMU_ISENSE_CTRL */
  122. #define ISENSE_CGC_EN_DISABLE BIT(0)
  123. /* A5XX_GPMU_TEMP_SENSOR_CONFIG */
  124. #define GPMU_BCL_ENABLED BIT(4)
  125. #define GPMU_LLM_ENABLED BIT(9)
  126. #define GPMU_ISENSE_STATUS GENMASK(3, 0)
  127. #define GPMU_ISENSE_END_POINT_CAL_ERR BIT(0)
  128. #define AMP_CALIBRATION_RETRY_CNT 3
  129. #define AMP_CALIBRATION_TIMEOUT 6
  130. /* A5XX_GPMU_GPMU_VOLTAGE_INTR_EN_MASK */
  131. #define VOLTAGE_INTR_EN BIT(0)
  132. /* A5XX_GPMU_GPMU_PWR_THRESHOLD */
  133. #define PWR_THRESHOLD_VALID 0x80000000
  134. /* A5XX_GPMU_GPMU_SP_CLOCK_CONTROL */
  135. #define CNTL_IP_CLK_ENABLE BIT(0)
  136. /* AGC */
  137. #define AGC_INIT_BASE A5XX_GPMU_DATA_RAM_BASE
  138. #define AGC_INIT_MSG_MAGIC (AGC_INIT_BASE + 5)
  139. #define AGC_MSG_BASE (AGC_INIT_BASE + 7)
  140. #define AGC_MSG_STATE (AGC_MSG_BASE + 0)
  141. #define AGC_MSG_COMMAND (AGC_MSG_BASE + 1)
  142. #define AGC_MSG_PAYLOAD_SIZE (AGC_MSG_BASE + 3)
  143. #define AGC_MSG_PAYLOAD (AGC_MSG_BASE + 5)
  144. #define AGC_INIT_MSG_VALUE 0xBABEFACE
  145. #define AGC_POWER_CONFIG_PRODUCTION_ID 1
  146. #define AGC_LM_CONFIG (136/4)
  147. #define AGC_LM_CONFIG_ENABLE_GPMU_ADAPTIVE (1)
  148. #define AGC_LM_CONFIG_ENABLE_ERROR (3 << 4)
  149. #define AGC_LM_CONFIG_ISENSE_ENABLE (1 << 4)
  150. #define AGC_THROTTLE_SEL_DCS (1 << 8)
  151. #define AGC_THROTTLE_DISABLE (2 << 8)
  152. #define AGC_LLM_ENABLED (1 << 16)
  153. #define AGC_GPU_VERSION_MASK GENMASK(18, 17)
  154. #define AGC_GPU_VERSION_SHIFT 17
  155. #define AGC_BCL_DISABLED (1 << 24)
  156. #define AGC_LEVEL_CONFIG (140/4)
  157. #define LM_DCVS_LIMIT 1
  158. /* FW file tages */
  159. #define GPMU_FIRMWARE_ID 2
  160. #define GPMU_SEQUENCE_ID 3
  161. #define GPMU_INST_RAM_SIZE 0xFFF
  162. #define HEADER_MAJOR 1
  163. #define HEADER_MINOR 2
  164. #define HEADER_DATE 3
  165. #define HEADER_TIME 4
  166. #define HEADER_SEQUENCE 5
  167. #define MAX_HEADER_SIZE 10
  168. #define LM_SEQUENCE_ID 1
  169. #define MAX_SEQUENCE_ID 3
  170. #define GPMU_ISENSE_SAVE (A5XX_GPMU_DATA_RAM_BASE + 200/4)
  171. /* LM defaults */
  172. #define LM_DEFAULT_LIMIT 6000
  173. #define A530_DEFAULT_LEAKAGE 0x004E001A
  174. /**
  175. * to_a5xx_core - return the a5xx specific GPU core struct
  176. * @adreno_dev: An Adreno GPU device handle
  177. *
  178. * Returns:
  179. * A pointer to the a5xx specific GPU core struct
  180. */
  181. static inline const struct adreno_a5xx_core *
  182. to_a5xx_core(struct adreno_device *adreno_dev)
  183. {
  184. const struct adreno_gpu_core *core = adreno_dev->gpucore;
  185. return container_of(core, struct adreno_a5xx_core, base);
  186. }
  187. /* Preemption functions */
  188. void a5xx_preemption_trigger(struct adreno_device *adreno_dev);
  189. void a5xx_preemption_schedule(struct adreno_device *adreno_dev);
  190. void a5xx_preemption_start(struct adreno_device *adreno_dev);
  191. int a5xx_preemption_init(struct adreno_device *adreno_dev);
  192. /**
  193. * a5xx_preemption_post_ibsubmit - Insert commands following a submission
  194. * @adreno_dev: Adreno GPU handle
  195. * @cmds: Pointer to the ringbuffer to insert opcodes
  196. *
  197. * Return: The number of opcodes written to @cmds
  198. */
  199. u32 a5xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, u32 *cmds);
  200. /**
  201. * a5xx_preemption_post_ibsubmit - Insert opcodes before a submission
  202. * @adreno_dev: Adreno GPU handle
  203. * @rb: The ringbuffer being written
  204. * @drawctxt: The draw context being written
  205. * @cmds: Pointer to the ringbuffer to insert opcodes
  206. *
  207. * Return: The number of opcodes written to @cmds
  208. */
  209. u32 a5xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev,
  210. struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
  211. u32 *cmds);
  212. void a5xx_preempt_callback(struct adreno_device *adreno_dev, int bit);
  213. u64 a5xx_read_alwayson(struct adreno_device *adreno_dev);
  214. extern const struct adreno_perfcounters adreno_a5xx_perfcounters;
  215. /**
  216. * a5xx_ringbuffer_init - Initialize the ringbuffers
  217. * @adreno_dev: An Adreno GPU handle
  218. *
  219. * Initialize the ringbuffer(s) for a5xx.
  220. * Return: 0 on success or negative on failure
  221. */
  222. int a5xx_ringbuffer_init(struct adreno_device *adreno_dev);
  223. /**
  224. * a5xx_ringbuffer_addcmds - Submit a command to the ringbuffer
  225. * @adreno_dev: An Adreno GPU handle
  226. * @rb: Pointer to the ringbuffer to submit on
  227. * @drawctxt: Pointer to the draw context for the submission, or NULL for
  228. * internal submissions
  229. * @flags: Flags for the submission
  230. * @in: Commands to write to the ringbuffer
  231. * @dwords: Size of @in (in dwords)
  232. * @timestamp: Timestamp for the submission
  233. * @time: Optional pointer to a submit time structure
  234. *
  235. * Submit a command to the ringbuffer.
  236. * Return: 0 on success or negative on failure
  237. */
  238. int a5xx_ringbuffer_addcmds(struct adreno_device *adreno_dev,
  239. struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
  240. u32 flags, u32 *in, u32 dwords, u32 timestamp,
  241. struct adreno_submit_time *time);
  242. /**
  243. * a5xx_ringbuffer_submitcmd - Submit a user command to the ringbuffer
  244. * @adreno_dev: An Adreno GPU handle
  245. * @cmdobj: Pointer to a user command object
  246. * @flags: Internal submit flags
  247. * @time: Optional pointer to a adreno_submit_time container
  248. *
  249. * Return: 0 on success or negative on failure
  250. */
  251. int a5xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
  252. struct kgsl_drawobj_cmd *cmdobj, u32 flags,
  253. struct adreno_submit_time *time);
  254. int a5xx_ringbuffer_submit(struct adreno_ringbuffer *rb,
  255. struct adreno_submit_time *time, bool sync);
  256. static inline bool a5xx_has_gpmu(struct adreno_device *adreno_dev)
  257. {
  258. return (adreno_is_a530(adreno_dev) || adreno_is_a540(adreno_dev));
  259. }
  260. #ifdef CONFIG_QCOM_KGSL_CORESIGHT
  261. void a5xx_coresight_init(struct adreno_device *device);
  262. #else
  263. static inline void a5xx_coresight_init(struct adreno_device *device) { }
  264. #endif
  265. #endif