kgsl_util.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _KGSL_UTIL_H_
  7. #define _KGSL_UTIL_H_
  8. #include <linux/version.h>
  9. #define KGSL_DRIVER "kgsl_driver"
  10. #define KGSL_ADRENO_DEVICE "kgsl_adreno_device"
  11. #define KGSL_A6XX_DEVICE "kgsl_a6xx_device"
  12. #define KGSL_GEN7_DEVICE "kgsl_gen7_device"
  13. #define KGSL_HWSCHED_DEVICE "kgsl_hwsched_device"
  14. #define KGSL_GEN8_DEVICE "kgsl_gen8_device"
  15. #define KGSL_SCRATCH_ENTRY "kgsl_scratch"
  16. #define KGSL_MEMSTORE_ENTRY "kgsl_memstore"
  17. #define KGSL_GMU_LOG_ENTRY "kgsl_gmu_log"
  18. #define KGSL_GMU_TRACE_ENTRY "kgsl_gmu_trace"
  19. #define KGSL_HFIMEM_ENTRY "kgsl_hfi_mem"
  20. #define KGSL_GMU_DUMPMEM_ENTRY "kgsl_gmu_dump_mem"
  21. #define KGSL_GMU_RB_ENTRY "kgsl_gmu_rb"
  22. #define KGSL_GMU_KERNEL_PROF_ENTRY "kgsl_gmu_kernel_profiling"
  23. #define KGSL_GMU_USER_PROF_ENTRY "kgsl_gmu_user_profiling"
  24. #define KGSL_GMU_CMD_BUFFER_ENTRY "kgsl_gmu_cmd_buffer"
  25. #define KGSL_HFI_BIG_IB_ENTRY "kgsl_hfi_big_ib"
  26. #define KGSL_HFI_BIG_IB_REC_ENTRY "kgsl_hfi_big_ib_rec"
  27. #define KGSL_ADRENO_CTX_ENTRY "kgsl_adreno_ctx"
  28. #define KGSL_PROC_PRIV_ENTRY "kgsl_proc_priv"
  29. #define KGSL_PGTABLE_ENTRY "kgsl_pgtable"
  30. #define KGSL_GMU_VRB_ENTRY "kgsl_gmu_vrb"
  31. #define MAX_VA_MINIDUMP_STR_LEN 32
  32. /**
  33. * Request TZ to program set of access controlled registers that KGSL needs
  34. * irrespective of any features
  35. */
  36. #define GPU_ALWAYS_EN_REQ BIT(0)
  37. /**
  38. * Request TZ to program BCL id to access controlled register when BCL is
  39. * enabled
  40. */
  41. #define GPU_BCL_EN_REQ BIT(1)
  42. /**
  43. * Request TZ to program set of access controlled register for CLX feature
  44. * when enabled
  45. */
  46. #define GPU_CLX_EN_REQ BIT(2)
  47. /**
  48. * Request TZ to program tsense ids to access controlled registers for reading
  49. * gpu temperature sensors
  50. */
  51. #define GPU_TSENSE_EN_REQ BIT(3)
  52. struct regulator;
  53. struct clk_bulk_data;
  54. /**
  55. * struct cpu_gpu_lock - CP spinlock structure for power up list
  56. * @gpu_req: flag value set by CP
  57. * @cpu_req: flag value set by KMD
  58. * @turn: turn variable set by both CP and KMD
  59. * @list_length: this tells CP the last dword in the list:
  60. * 16 + (4 * (List_Length - 1))
  61. * @list_offset: this tells CP the start of preemption only list:
  62. * 16 + (4 * List_Offset)
  63. * @ifpc_list_len: number of static ifpc duplets in the list
  64. * @preemption_list_len: number of static preemption duplets in the list
  65. * @dynamic_list_len: number of dynamically added triplets in the list
  66. */
  67. struct cpu_gpu_lock {
  68. u32 gpu_req;
  69. u32 cpu_req;
  70. u32 turn;
  71. union {
  72. struct {
  73. u16 list_length;
  74. u16 list_offset;
  75. };
  76. struct {
  77. u8 ifpc_list_len;
  78. u8 preemption_list_len;
  79. u16 dynamic_list_len;
  80. };
  81. };
  82. };
  83. /**
  84. * kgsl_hwlock - Try to get the spinlock
  85. * @lock: cpu_gpu_lock structure
  86. *
  87. * Spin while the GPU has the lock.
  88. *
  89. * Return: 0 if lock is successful, -EBUSY if timed out waiting for lock
  90. */
  91. int kgsl_hwlock(struct cpu_gpu_lock *lock);
  92. /**
  93. * kgsl_hwunlock - Release a previously grabbed lock
  94. * @lock: cpu_gpu_lock structure
  95. */
  96. void kgsl_hwunlock(struct cpu_gpu_lock *lock);
  97. /**
  98. * kgsl_regulator_disable_wait - Disable a regulator and wait for it
  99. * @reg: A &struct regulator handle
  100. * @timeout: Time to wait (in milliseconds)
  101. *
  102. * Disable the regulator and wait @timeout milliseconds for it to enter the
  103. * disabled state.
  104. *
  105. * Return: True if the regulator was disabled or false if it timed out
  106. */
  107. bool kgsl_regulator_disable_wait(struct regulator *reg, u32 timeout);
  108. /**
  109. * kgsl_of_clk_by_name - Return a clock device for a given name
  110. * @clks: Pointer to an array of bulk clk data
  111. * @count: Number of entries in the array
  112. * @id: Name of the clock to search for
  113. *
  114. * Returns: A pointer to the clock device for the given name or NULL if not
  115. * found
  116. */
  117. struct clk *kgsl_of_clk_by_name(struct clk_bulk_data *clks, int count,
  118. const char *id);
  119. /**
  120. * kgsl_regulator_set_voltage - Set voltage level for regulator
  121. * @dev: A &struct device pointer
  122. * @reg: A &struct regulator handle
  123. * @voltage: Voltage value to set regulator
  124. *
  125. * Return: 0 on success and negative error on failure.
  126. */
  127. int kgsl_regulator_set_voltage(struct device *dev,
  128. struct regulator *reg, u32 voltage);
  129. /**
  130. * kgsl_clk_set_rate - Set a clock to a given rate
  131. * @clks: Pointer to an array of bulk clk data
  132. * @count: Number of entries in the array
  133. * @id: Name of the clock to search for
  134. * @rate: Rate to st the clock to
  135. *
  136. * Return: 0 on success or negative error on failure
  137. */
  138. int kgsl_clk_set_rate(struct clk_bulk_data *clks, int num_clks,
  139. const char *id, unsigned long rate);
  140. /**
  141. * kgsl_scm_gpu_init_regs - Load secure registers through tz
  142. * @dev: Pointer to the GPU platform device
  143. * @gpu_req: Bit mask of requests to enable
  144. *
  145. * Return: 0 on success or negative on failure and EOPNOTSUPP if scm call
  146. * not supported
  147. */
  148. #if (KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE)
  149. int kgsl_scm_gpu_init_regs(struct device *dev, u32 gpu_req);
  150. #else
  151. static inline int kgsl_scm_gpu_init_regs(struct device *dev, u32 gpu_req)
  152. {
  153. return -EOPNOTSUPP;
  154. }
  155. #endif
  156. /**
  157. * kgsl_zap_shader_load - Load a zap shader
  158. * @dev: Pointer to the struct device for the GPU platform device
  159. * @name: Basename of the zap shader to load (without the postfix)
  160. *
  161. * Load and install the zap shader named @name. Name should be specified without
  162. * the extension for example "a660_zap" instead of "a660_zap.mdt".
  163. *
  164. * Return: 0 on success or negative on failure
  165. */
  166. int kgsl_zap_shader_load(struct device *dev, const char *name);
  167. /**
  168. * kgsl_zap_shader_unload - Unload a zap shader
  169. * @dev: Pointer to the struct device for the GPU platform device
  170. *
  171. * Unload zap_shader and shutdown the peripheral
  172. * Return: 0 on success or negative on failure
  173. */
  174. int kgsl_zap_shader_unload(struct device *dev);
  175. #if IS_ENABLED(CONFIG_QCOM_VA_MINIDUMP)
  176. /**
  177. * kgsl_add_to_minidump - Add a physically contiguous section to minidump
  178. * @name: Name of the section
  179. * @virt_addr: Virtual address of the section
  180. * @phy_addr: Physical address of the section
  181. * @size: Size of the section
  182. */
  183. void kgsl_add_to_minidump(char *name, u64 virt_addr, u64 phy_addr, size_t size);
  184. /**
  185. * kgsl_remove_from_minidump - Remove a contiguous section from minidump
  186. * @name: Name of the section
  187. * @virt_addr: Virtual address of the section
  188. * @phy_addr: Physical address of the section
  189. * @size: Size of the section
  190. */
  191. void kgsl_remove_from_minidump(char *name, u64 virt_addr, u64 phy_addr, size_t size);
  192. /**
  193. * kgsl_add_va_to_minidump - Add a physically non-contiguous section to minidump
  194. * @dev: Pointer to the struct device for the GPU platform device
  195. * @name: Name of the section
  196. * @ptr: Virtual address of the section
  197. * @size: Size of the section
  198. */
  199. int kgsl_add_va_to_minidump(struct device *dev, const char *name, void *ptr,
  200. size_t size);
  201. /**
  202. * kgsl_qcom_va_md_register - Register driver with va-minidump
  203. * @device: Pointer to kgsl device
  204. */
  205. void kgsl_qcom_va_md_register(struct kgsl_device *device);
  206. /**
  207. * kgsl_qcom_va_md_unregister - Unregister driver with va-minidump
  208. * @device: Pointer to kgsl device
  209. */
  210. void kgsl_qcom_va_md_unregister(struct kgsl_device *device);
  211. #else
  212. static inline void kgsl_add_to_minidump(char *name, u64 virt_addr, u64 phy_addr, size_t size)
  213. {
  214. }
  215. static inline void kgsl_remove_from_minidump(char *name, u64 virt_addr, u64 phy_addr, size_t size)
  216. {
  217. }
  218. static inline int kgsl_add_va_to_minidump(struct device *dev, const char *name, void *ptr,
  219. size_t size)
  220. {
  221. return 0;
  222. }
  223. static inline void kgsl_qcom_va_md_register(struct kgsl_device *device)
  224. {
  225. }
  226. static inline void kgsl_qcom_va_md_unregister(struct kgsl_device *device)
  227. {
  228. }
  229. #endif
  230. /**
  231. * isdb_write - Program isdb registers to issue break commands to SP
  232. * @base: Base address of qdss registers to be programmed
  233. * @offset: offset to the SP block
  234. */
  235. void isdb_write(void __iomem *base, u32 offset);
  236. #endif