adreno_gen7.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _ADRENO_GEN7_H_
  7. #define _ADRENO_GEN7_H_
  8. #include <linux/delay.h>
  9. #include "gen7_reg.h"
  10. #include "adreno_gen7_gmu.h"
  11. /* Forward struct declaration */
  12. struct gen7_snapshot_block_list;
  13. extern const struct adreno_power_ops gen7_gmu_power_ops;
  14. extern const struct adreno_power_ops gen7_hwsched_power_ops;
  15. extern const struct adreno_perfcounters adreno_gen7_perfcounters;
  16. extern const struct adreno_perfcounters adreno_gen7_hwsched_perfcounters;
  17. extern const struct adreno_perfcounters adreno_gen7_9_0_hwsched_perfcounters;
  18. struct gen7_gpudev {
  19. struct adreno_gpudev base;
  20. int (*hfi_probe)(struct adreno_device *adreno_dev);
  21. void (*hfi_remove)(struct adreno_device *adreno_dev);
  22. void (*handle_watchdog)(struct adreno_device *adreno_dev);
  23. };
  24. extern const struct gen7_gpudev adreno_gen7_gmu_gpudev;
  25. extern const struct gen7_gpudev adreno_gen7_hwsched_gpudev;
  26. extern const struct gen7_gpudev adreno_gen7_9_0_hwsched_gpudev;
  27. /**
  28. * struct gen7_device - Container for the gen7_device
  29. */
  30. struct gen7_device {
  31. /** @gmu: Container for the gen7 GMU device */
  32. struct gen7_gmu_device gmu;
  33. /** @adreno_dev: Container for the generic adreno device */
  34. struct adreno_device adreno_dev;
  35. };
  36. /**
  37. * struct gen7_protected_regs - container for a protect register span
  38. */
  39. struct gen7_protected_regs {
  40. /** @reg: Physical protected mode register to write to */
  41. u32 reg;
  42. /** @start: Dword offset of the starting register in the range */
  43. u32 start;
  44. /**
  45. * @end: Dword offset of the ending register in the range
  46. * (inclusive)
  47. */
  48. u32 end;
  49. /**
  50. * @noaccess: 1 if the register should not be accessible from
  51. * userspace, 0 if it can be read (but not written)
  52. */
  53. u32 noaccess;
  54. };
  55. /**
  56. * struct adreno_gen7_core - gen7 specific GPU core definitions
  57. */
  58. struct adreno_gen7_core {
  59. /** @base: Container for the generic GPU definitions */
  60. struct adreno_gpu_core base;
  61. /** @gmu_fw_version: Minimum firmware version required to support this core */
  62. u32 gmu_fw_version;
  63. /** @sqefw_name: Name of the SQE microcode file */
  64. const char *sqefw_name;
  65. /** @aqefw_name: Name of the AQE microcode file */
  66. const char *aqefw_name;
  67. /** @gmufw_name: Name of the GMU firmware file */
  68. const char *gmufw_name;
  69. /** @gmufw_name: Name of the backup GMU firmware file */
  70. const char *gmufw_bak_name;
  71. /** @zap_name: Name of the CPZ zap file */
  72. const char *zap_name;
  73. /** @hwcg: List of registers and values to write for HWCG */
  74. const struct kgsl_regmap_list *hwcg;
  75. /** @hwcg_count: Number of registers in @hwcg */
  76. u32 hwcg_count;
  77. /** @ao_hwcg: List of registers and values to write for HWCG in AO block */
  78. const struct kgsl_regmap_list *ao_hwcg;
  79. /** @ao_hwcg_count: Number of registers in @ao_hwcg */
  80. u32 ao_hwcg_count;
  81. /** @gbif: List of registers and values to write for GBIF */
  82. const struct kgsl_regmap_list *gbif;
  83. /** @gbif_count: Number of registers in @gbif */
  84. u32 gbif_count;
  85. /** @hang_detect_cycles: Hang detect counter timeout value */
  86. u32 hang_detect_cycles;
  87. /** @protected_regs: Array of protected registers for the target */
  88. const struct gen7_protected_regs *protected_regs;
  89. /** @ctxt_record_size: Size of the preemption record in bytes */
  90. u64 ctxt_record_size;
  91. /** @highest_bank_bit: Highest bank bit value */
  92. u32 highest_bank_bit;
  93. /** @gen7_snapshot_block_list: Device-specific blocks dumped in the snapshot */
  94. const struct gen7_snapshot_block_list *gen7_snapshot_block_list;
  95. /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */
  96. u64 gmu_hub_clk_freq;
  97. /**
  98. * @bcl_data: bit 0 contains response type for bcl alarms and bits 1:21 controls sid vals
  99. * to configure throttle levels for bcl alarm levels 0-2. If sid vals are not set,
  100. * gmu fw sets default throttle levels.
  101. */
  102. u32 bcl_data;
  103. /** @preempt_level: Preemption level valid ranges [0 to 2] */
  104. u32 preempt_level;
  105. /** @qos_value: GPU qos value to set for each RB. */
  106. const u32 *qos_value;
  107. /**
  108. * @acv_perfmode_ddr_freq: Vote perfmode when DDR frequency >= acv_perfmode_ddr_freq.
  109. * If not specified, vote perfmode for highest DDR level only.
  110. */
  111. u32 acv_perfmode_ddr_freq;
  112. /** @acv_perfmode_vote: ACV vote for GPU perfmode */
  113. u32 acv_perfmode_vote;
  114. /** @rt_bus_hint: IB level hint for real time clients i.e. RB-0 */
  115. const u32 rt_bus_hint;
  116. /** @fast_bus_hint: Whether or not to increase IB vote on high ddr stall */
  117. bool fast_bus_hint;
  118. /** @noc_timeout_us: GPU config NOC port timeout in usec */
  119. u32 noc_timeout_us;
  120. };
  121. /**
  122. * struct gen7_cp_preemption_record - CP context record for
  123. * preemption.
  124. * @magic: (00) Value at this offset must be equal to
  125. * GEN7_CP_CTXRECORD_MAGIC_REF.
  126. * @info: (04) Type of record. Written non-zero (usually) by CP.
  127. * we must set to zero for all ringbuffers.
  128. * @errno: (08) Error code. Initialize this to GEN7_CP_CTXRECORD_ERROR_NONE.
  129. * CP will update to another value if a preemption error occurs.
  130. * @data: (12) DATA field in YIELD and SET_MARKER packets.
  131. * Written by CP when switching out. Not used on switch-in. Initialized to 0.
  132. * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this.
  133. * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this.
  134. * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this.
  135. * @_pad28: (28) Reserved/padding.
  136. * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize.
  137. * rbase: (40) RB_BASE_LO|HI saved and restored.
  138. * counter: (48) Pointer to preemption counter.
  139. * @bv_rptr_addr: (56) BV_RB_RPTR_ADDR_LO|HI save and restored. We must initialize.
  140. */
  141. struct gen7_cp_preemption_record {
  142. u32 magic;
  143. u32 info;
  144. u32 errno;
  145. u32 data;
  146. u32 cntl;
  147. u32 rptr;
  148. u32 wptr;
  149. u32 _pad28;
  150. u64 rptr_addr;
  151. u64 rbase;
  152. u64 counter;
  153. u64 bv_rptr_addr;
  154. };
  155. /**
  156. * struct gen7_cp_smmu_info - CP preemption SMMU info.
  157. * @magic: (00) The value at this offset must be equal to
  158. * GEN7_CP_SMMU_INFO_MAGIC_REF
  159. * @_pad4: (04) Reserved/padding
  160. * @ttbr0: (08) Base address of the page table for the * incoming context
  161. * @asid: (16) Address Space IDentifier (ASID) of the incoming context
  162. * @context_idr: (20) Context Identification Register value
  163. * @context_bank: (24) Which Context Bank in SMMU to update
  164. */
  165. struct gen7_cp_smmu_info {
  166. u32 magic;
  167. u32 _pad4;
  168. u64 ttbr0;
  169. u32 asid;
  170. u32 context_idr;
  171. u32 context_bank;
  172. };
  173. #define GEN7_CP_SMMU_INFO_MAGIC_REF 0x241350d5UL
  174. #define GEN7_CP_CTXRECORD_MAGIC_REF 0xae399d6eUL
  175. /* Size of each CP preemption record */
  176. #define GEN7_CP_CTXRECORD_SIZE_IN_BYTES (4192 * 1024)
  177. /* Size of the user context record block (in bytes) */
  178. #define GEN7_CP_CTXRECORD_USER_RESTORE_SIZE (192 * 1024)
  179. /* Size of the performance counter save/restore block (in bytes) */
  180. #define GEN7_CP_PERFCOUNTER_SAVE_RESTORE_SIZE (4 * 1024)
  181. #define GEN7_CP_RB_CNTL_DEFAULT \
  182. (FIELD_PREP(GENMASK(7, 0), ilog2(KGSL_RB_DWORDS >> 1)) | \
  183. FIELD_PREP(GENMASK(12, 8), ilog2(4)))
  184. /* Size of the CP_INIT pm4 stream in dwords */
  185. #define GEN7_CP_INIT_DWORDS 10
  186. #define GEN7_INT_MASK \
  187. ((1 << GEN7_INT_AHBERROR) | \
  188. (1 << GEN7_INT_ATBASYNCFIFOOVERFLOW) | \
  189. (1 << GEN7_INT_GPCERROR) | \
  190. (1 << GEN7_INT_SWINTERRUPT) | \
  191. (1 << GEN7_INT_HWERROR) | \
  192. (1 << GEN7_INT_PM4CPINTERRUPT) | \
  193. (1 << GEN7_INT_RB_DONE_TS) | \
  194. (1 << GEN7_INT_CACHE_CLEAN_TS) | \
  195. (1 << GEN7_INT_ATBBUSOVERFLOW) | \
  196. (1 << GEN7_INT_HANGDETECTINTERRUPT) | \
  197. (1 << GEN7_INT_OUTOFBOUNDACCESS) | \
  198. (1 << GEN7_INT_UCHETRAPINTERRUPT) | \
  199. (1 << GEN7_INT_TSBWRITEERROR) | \
  200. (1 << GEN7_INT_SWFUSEVIOLATION))
  201. #define GEN7_HWSCHED_INT_MASK \
  202. ((1 << GEN7_INT_AHBERROR) | \
  203. (1 << GEN7_INT_ATBASYNCFIFOOVERFLOW) | \
  204. (1 << GEN7_INT_ATBBUSOVERFLOW) | \
  205. (1 << GEN7_INT_OUTOFBOUNDACCESS) | \
  206. (1 << GEN7_INT_UCHETRAPINTERRUPT))
  207. /**
  208. * to_gen7_core - return the gen7 specific GPU core struct
  209. * @adreno_dev: An Adreno GPU device handle
  210. *
  211. * Returns:
  212. * A pointer to the gen7 specific GPU core struct
  213. */
  214. static inline const struct adreno_gen7_core *
  215. to_gen7_core(struct adreno_device *adreno_dev)
  216. {
  217. const struct adreno_gpu_core *core = adreno_dev->gpucore;
  218. return container_of(core, struct adreno_gen7_core, base);
  219. }
  220. /* Preemption functions */
  221. void gen7_preemption_trigger(struct adreno_device *adreno_dev, bool atomic);
  222. void gen7_preemption_schedule(struct adreno_device *adreno_dev);
  223. void gen7_preemption_start(struct adreno_device *adreno_dev);
  224. int gen7_preemption_init(struct adreno_device *adreno_dev);
  225. u32 gen7_preemption_post_ibsubmit(struct adreno_device *adreno_dev,
  226. unsigned int *cmds);
  227. u32 gen7_preemption_pre_ibsubmit(struct adreno_device *adreno_dev,
  228. struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
  229. u32 *cmds);
  230. unsigned int gen7_set_marker(unsigned int *cmds,
  231. enum adreno_cp_marker_type type);
  232. void gen7_preemption_callback(struct adreno_device *adreno_dev, int bit);
  233. int gen7_preemption_context_init(struct kgsl_context *context);
  234. void gen7_preemption_context_destroy(struct kgsl_context *context);
  235. void gen7_preemption_prepare_postamble(struct adreno_device *adreno_dev);
  236. void gen7_snapshot(struct adreno_device *adreno_dev,
  237. struct kgsl_snapshot *snapshot);
  238. void gen7_crashdump_init(struct adreno_device *adreno_dev);
  239. /**
  240. * gen7_snapshot_external_core_regs - Dump external registers into snapshot
  241. * @device: Pointer to KGSL device
  242. * @snapshot: Pointer to the snapshot
  243. *
  244. * Dump external core registers like GPUCC, CPR into GPU snapshot.
  245. */
  246. void gen7_snapshot_external_core_regs(struct kgsl_device *device,
  247. struct kgsl_snapshot *snapshot);
  248. /**
  249. * gen7_start - Program gen7 registers
  250. * @adreno_dev: An Adreno GPU handle
  251. *
  252. * This function does all gen7 register programming every
  253. * time we boot the gpu
  254. *
  255. * Return: 0 on success or negative on failure
  256. */
  257. int gen7_start(struct adreno_device *adreno_dev);
  258. /**
  259. * gen7_init - Initialize gen7 resources
  260. * @adreno_dev: An Adreno GPU handle
  261. *
  262. * This function does gen7 specific one time initialization
  263. * and is invoked when the very first client opens a
  264. * kgsl instance
  265. *
  266. * Return: Zero on success and negative error on failure
  267. */
  268. int gen7_init(struct adreno_device *adreno_dev);
  269. /**
  270. * gen7_cx_timer_init - Initialize the CX timer on Gen7 devices
  271. * @adreno_dev: Pointer to the adreno device
  272. *
  273. * Synchronize the GPU CX timer (if we have one) with the CPU timer
  274. */
  275. void gen7_cx_timer_init(struct adreno_device *adreno_dev);
  276. /**
  277. * gen7_get_gpu_feature_info - Get hardware supported feature info
  278. * @adreno_dev: Pointer to the adreno device
  279. *
  280. * Get HW supported feature info and update sofware feature configuration
  281. */
  282. void gen7_get_gpu_feature_info(struct adreno_device *adreno_dev);
  283. /**
  284. * gen7_rb_start - Gen7 specific ringbuffer setup
  285. * @adreno_dev: An Adreno GPU handle
  286. *
  287. * This function does gen7 specific ringbuffer setup and
  288. * attempts to submit CP INIT and bring GPU out of secure mode
  289. *
  290. * Return: Zero on success and negative error on failure
  291. */
  292. int gen7_rb_start(struct adreno_device *adreno_dev);
  293. /**
  294. * gen7_microcode_read - Get the cp microcode from the filesystem
  295. * @adreno_dev: An Adreno GPU handle
  296. *
  297. * This function gets the firmware from filesystem and sets up
  298. * the micorocode global buffer
  299. *
  300. * Return: Zero on success and negative error on failure
  301. */
  302. int gen7_microcode_read(struct adreno_device *adreno_dev);
  303. /**
  304. * gen7_probe_common - Probe common gen7 resources
  305. * @pdev: Pointer to the platform device
  306. * @adreno_dev: Pointer to the adreno device
  307. * @chipid: Chipid of the target
  308. * @gpucore: Pointer to the gpucore strucure
  309. *
  310. * This function sets up the gen7 resources common across all
  311. * gen7 targets
  312. */
  313. int gen7_probe_common(struct platform_device *pdev,
  314. struct adreno_device *adreno_dev, u32 chipid,
  315. const struct adreno_gpu_core *gpucore);
  316. /**
  317. * gen7_hw_isidle - Check whether gen7 gpu is idle or not
  318. * @adreno_dev: An Adreno GPU handle
  319. *
  320. * Return: True if gpu is idle, otherwise false
  321. */
  322. bool gen7_hw_isidle(struct adreno_device *adreno_dev);
  323. /**
  324. * gen7_spin_idle_debug - Debug logging used when gpu fails to idle
  325. * @adreno_dev: An Adreno GPU handle
  326. * @str: String describing the failure
  327. *
  328. * This function logs interesting registers and triggers a snapshot
  329. */
  330. void gen7_spin_idle_debug(struct adreno_device *adreno_dev,
  331. const char *str);
  332. /**
  333. * gen7_perfcounter_update - Update the IFPC perfcounter list
  334. * @adreno_dev: An Adreno GPU handle
  335. * @reg: Perfcounter reg struct to add/remove to the list
  336. * @update_reg: true if the perfcounter needs to be programmed by the CPU
  337. * @pipe: pipe id for CP aperture control
  338. * @flags: Flags set for requested perfcounter group
  339. *
  340. * Return: 0 on success or -EBUSY if the lock couldn't be taken
  341. */
  342. int gen7_perfcounter_update(struct adreno_device *adreno_dev,
  343. struct adreno_perfcount_register *reg, bool update_reg, u32 pipe,
  344. unsigned long flags);
  345. /*
  346. * gen7_ringbuffer_init - Initialize the ringbuffers
  347. * @adreno_dev: An Adreno GPU handle
  348. *
  349. * Initialize the ringbuffer(s) for a5xx.
  350. * Return: 0 on success or negative on failure
  351. */
  352. int gen7_ringbuffer_init(struct adreno_device *adreno_dev);
  353. /**
  354. * gen7_ringbuffer_submitcmd - Submit a user command to the ringbuffer
  355. * @adreno_dev: An Adreno GPU handle
  356. * @cmdobj: Pointer to a user command object
  357. * @flags: Internal submit flags
  358. * @time: Optional pointer to a adreno_submit_time container
  359. *
  360. * Return: 0 on success or negative on failure
  361. */
  362. int gen7_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
  363. struct kgsl_drawobj_cmd *cmdobj, u32 flags,
  364. struct adreno_submit_time *time);
  365. /**
  366. * gen7_ringbuffer_submit - Submit a command to the ringbuffer
  367. * @rb: Ringbuffer pointer
  368. * @time: Optional pointer to a adreno_submit_time container
  369. *
  370. * Return: 0 on success or negative on failure
  371. */
  372. int gen7_ringbuffer_submit(struct adreno_ringbuffer *rb,
  373. struct adreno_submit_time *time);
  374. /**
  375. * gen7_fenced_write - Write to a fenced register
  376. * @adreno_dev: An Adreno GPU handle
  377. * @offset: Register offset
  378. * @value: Value to write
  379. * @mask: Expected FENCE_STATUS for successful write
  380. *
  381. * Return: 0 on success or negative on failure
  382. */
  383. int gen7_fenced_write(struct adreno_device *adreno_dev, u32 offset,
  384. u32 value, u32 mask);
  385. /**
  386. * gen77ringbuffer_addcmds - Wrap and submit commands to the ringbuffer
  387. * @adreno_dev: An Adreno GPU handle
  388. * @rb: Ringbuffer pointer
  389. * @drawctxt: Draw context submitting the commands
  390. * @flags: Submission flags
  391. * @in: Input buffer to write to ringbuffer
  392. * @dwords: Dword length of @in
  393. * @timestamp: Draw context timestamp for the submission
  394. * @time: Optional pointer to a adreno_submit_time container
  395. *
  396. * Return: 0 on success or negative on failure
  397. */
  398. int gen7_ringbuffer_addcmds(struct adreno_device *adreno_dev,
  399. struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
  400. u32 flags, u32 *in, u32 dwords, u32 timestamp,
  401. struct adreno_submit_time *time);
  402. /**
  403. * gen7_cp_init_cmds - Create the CP_INIT commands
  404. * @adreno_dev: An Adreno GPU handle
  405. * @cmd: Buffer to write the CP_INIT commands into
  406. */
  407. void gen7_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds);
  408. /**
  409. * gen7_gmu_hfi_probe - Probe Gen7 HFI specific data
  410. * @adreno_dev: An Adreno GPU handle
  411. *
  412. * Return: 0 on success or negative on failure
  413. */
  414. int gen7_gmu_hfi_probe(struct adreno_device *adreno_dev);
  415. static inline const struct gen7_gpudev *
  416. to_gen7_gpudev(const struct adreno_gpudev *gpudev)
  417. {
  418. return container_of(gpudev, struct gen7_gpudev, base);
  419. }
  420. /**
  421. * gen7_reset_preempt_records - Reset the preemption buffers
  422. * @adreno_dev: Handle to the adreno device
  423. *
  424. * Reset the preemption records at the time of hard reset
  425. */
  426. void gen7_reset_preempt_records(struct adreno_device *adreno_dev);
  427. /**
  428. * gen7_enable_ahb_timeout_detection - Program AHB control registers
  429. * @adreno_dev: An Adreno GPU handle
  430. *
  431. * Program AHB control registers to enable AHB timeout detection.
  432. */
  433. void gen7_enable_ahb_timeout_detection(struct adreno_device *adreno_dev);
  434. /**
  435. * gen7_rdpm_mx_freq_update - Update the mx frequency
  436. * @gmu: An Adreno GMU handle
  437. * @freq: Frequency in KHz
  438. *
  439. * This function communicates GPU mx frequency(in Mhz) changes to rdpm.
  440. */
  441. void gen7_rdpm_mx_freq_update(struct gen7_gmu_device *gmu, u32 freq);
  442. /**
  443. * gen7_rdpm_cx_freq_update - Update the cx frequency
  444. * @gmu: An Adreno GMU handle
  445. * @freq: Frequency in KHz
  446. *
  447. * This function communicates GPU cx frequency(in Mhz) changes to rdpm.
  448. */
  449. void gen7_rdpm_cx_freq_update(struct gen7_gmu_device *gmu, u32 freq);
  450. /**
  451. * gen7_scm_gpu_init_cx_regs - Program gpu regs for feature support
  452. * @adreno_dev: Handle to the adreno device
  453. *
  454. * Program gpu regs for feature support. Scm call for the same
  455. * is added from kernel version 6.0 onwards.
  456. *
  457. * Return: 0 on success or negative on failure
  458. */
  459. int gen7_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev);
  460. #ifdef CONFIG_QCOM_KGSL_CORESIGHT
  461. void gen7_coresight_init(struct adreno_device *device);
  462. #else
  463. static inline void gen7_coresight_init(struct adreno_device *device) { }
  464. #endif
  465. #endif