adreno_gen7_gmu.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __ADRENO_GEN7_GMU_H
  7. #define __ADRENO_GEN7_GMU_H
  8. #include <linux/mailbox_client.h>
  9. #include "adreno_gen7_hfi.h"
  10. #include "kgsl_gmu_core.h"
  11. struct gen7_dcvs_table {
  12. u32 gpu_level_num;
  13. u32 gmu_level_num;
  14. struct opp_gx_desc gx_votes[MAX_GX_LEVELS];
  15. struct opp_desc cx_votes[MAX_CX_LEVELS];
  16. };
  17. /**
  18. * struct gen7_gmu_device - GMU device structure
  19. * @ver: GMU Version information
  20. * @irq: GMU interrupt number
  21. * @fw_image: GMU FW image
  22. * @hfi_mem: pointer to HFI shared memory
  23. * @dump_mem: pointer to GMU debug dump memory
  24. * @gmu_log: gmu event log memory
  25. * @hfi: HFI controller
  26. * @num_gpupwrlevels: number GPU frequencies in GPU freq table
  27. * @num_bwlevel: number of GPU BW levels
  28. * @num_cnocbwlevel: number CNOC BW levels
  29. * @rpmh_votes: RPMh TCS command set for GPU, GMU voltage and bw scaling
  30. * @clks: GPU subsystem clocks required for GMU functionality
  31. * @wakeup_pwrlevel: GPU wake up power/DCVS level in case different
  32. * than default power level
  33. * @idle_level: Minimal GPU idle power level
  34. * @fault_count: GMU fault count
  35. * @mailbox: Messages to AOP for ACD enable/disable go through this
  36. * @log_wptr_retention: Store the log wptr offset on slumber
  37. */
  38. struct gen7_gmu_device {
  39. struct {
  40. u32 core;
  41. u32 core_dev;
  42. u32 pwr;
  43. u32 pwr_dev;
  44. u32 hfi;
  45. } ver;
  46. struct platform_device *pdev;
  47. int irq;
  48. const struct firmware *fw_image;
  49. struct kgsl_memdesc *dump_mem;
  50. struct kgsl_memdesc *gmu_log;
  51. /** @gmu_init_scratch: Memory to store the initial HFI messages */
  52. struct kgsl_memdesc *gmu_init_scratch;
  53. /** @gpu_boot_scratch: Memory to store the bootup HFI messages */
  54. struct kgsl_memdesc *gpu_boot_scratch;
  55. /** @vrb: GMU virtual register bank memory */
  56. struct kgsl_memdesc *vrb;
  57. /** @trace: gmu trace container */
  58. struct kgsl_gmu_trace trace;
  59. struct gen7_hfi hfi;
  60. struct clk_bulk_data *clks;
  61. /** @num_clks: Number of entries in the @clks array */
  62. int num_clks;
  63. unsigned int idle_level;
  64. /** @freqs: Array of GMU frequencies */
  65. u32 freqs[GMU_MAX_PWRLEVELS];
  66. /** @vlvls: Array of GMU voltage levels */
  67. u32 vlvls[GMU_MAX_PWRLEVELS];
  68. struct kgsl_mailbox mailbox;
  69. /** @gmu_globals: Array to store gmu global buffers */
  70. struct kgsl_memdesc gmu_globals[GMU_KERNEL_ENTRIES];
  71. /** @global_entries: To keep track of number of gmu buffers */
  72. u32 global_entries;
  73. struct gmu_vma_entry *vma;
  74. unsigned int log_wptr_retention;
  75. /** @cm3_fault: whether gmu received a cm3 fault interrupt */
  76. atomic_t cm3_fault;
  77. /**
  78. * @itcm_shadow: Copy of the itcm block in firmware binary used for
  79. * snapshot
  80. */
  81. void *itcm_shadow;
  82. /** @flags: Internal gmu flags */
  83. unsigned long flags;
  84. /** @rscc_virt: Pointer where RSCC block is mapped */
  85. void __iomem *rscc_virt;
  86. /** @domain: IOMMU domain for the kernel context */
  87. struct iommu_domain *domain;
  88. /** @log_stream_enable: GMU log streaming enable. Disabled by default */
  89. bool log_stream_enable;
  90. /** @log_group_mask: Allows overriding default GMU log group mask */
  91. u32 log_group_mask;
  92. struct kobject log_kobj;
  93. /*
  94. * @perf_ddr_bw: The lowest ddr bandwidth that puts CX at a corner at
  95. * which GMU can run at higher frequency.
  96. */
  97. u32 perf_ddr_bw;
  98. /** @rdpm_cx_virt: Pointer where the RDPM CX block is mapped */
  99. void __iomem *rdpm_cx_virt;
  100. /** @rdpm_mx_virt: Pointer where the RDPM MX block is mapped */
  101. void __iomem *rdpm_mx_virt;
  102. /** @num_oob_perfcntr: Number of active oob_perfcntr requests */
  103. u32 num_oob_perfcntr;
  104. /** @acd_debug_val: DVM value to calibrate ACD for a level */
  105. u32 acd_debug_val;
  106. /** @stats_enable: GMU stats feature enable */
  107. bool stats_enable;
  108. /** @stats_mask: GMU performance countables to enable */
  109. u32 stats_mask;
  110. /** @stats_interval: GMU performance counters sampling interval */
  111. u32 stats_interval;
  112. /** @stats_kobj: kernel object for GMU stats directory in sysfs */
  113. struct kobject stats_kobj;
  114. /** @cp_init_hdr: raw command header for cp_init */
  115. u32 cp_init_hdr;
  116. /** @switch_to_unsec_hdr: raw command header for switch to unsecure packet */
  117. u32 switch_to_unsec_hdr;
  118. /** @dcvs_table: Table for gpu dcvs levels */
  119. struct gen7_dcvs_table dcvs_table;
  120. };
  121. /* Helper function to get to gen7 gmu device from adreno device */
  122. struct gen7_gmu_device *to_gen7_gmu(struct adreno_device *adreno_dev);
  123. /* Helper function to get to adreno device from gen7 gmu device */
  124. struct adreno_device *gen7_gmu_to_adreno(struct gen7_gmu_device *gmu);
  125. /**
  126. * gen7_reserve_gmu_kernel_block() - Allocate a global gmu buffer
  127. * @gmu: Pointer to the gen7 gmu device
  128. * @addr: Desired gmu virtual address
  129. * @size: Size of the buffer in bytes
  130. * @vma_id: Target gmu vma where this buffer should be mapped
  131. * @align: Alignment for the GMU VA and GMU mapping size
  132. *
  133. * This function allocates a global gmu buffer and maps it in
  134. * the desired gmu vma
  135. *
  136. * Return: Pointer to the memory descriptor or error pointer on failure
  137. */
  138. struct kgsl_memdesc *gen7_reserve_gmu_kernel_block(struct gen7_gmu_device *gmu,
  139. u32 addr, u32 size, u32 vma_id, u32 align);
  140. /**
  141. * gen7_reserve_gmu_kernel_block_fixed() - Maps phyical resource address to gmu
  142. * @gmu: Pointer to the gen7 gmu device
  143. * @addr: Desired gmu virtual address
  144. * @size: Size of the buffer in bytes
  145. * @vma_id: Target gmu vma where this buffer should be mapped
  146. * @resource: Name of the resource to get the size and address to allocate
  147. * @attrs: Attributes for the mapping
  148. * @align: Alignment for the GMU VA and GMU mapping size
  149. *
  150. * This function maps the physcial resource address to desired gmu vma
  151. *
  152. * Return: Pointer to the memory descriptor or error pointer on failure
  153. */
  154. struct kgsl_memdesc *gen7_reserve_gmu_kernel_block_fixed(struct gen7_gmu_device *gmu,
  155. u32 addr, u32 size, u32 vma_id, const char *resource, int attrs, u32 align);
  156. /**
  157. * gen7_alloc_gmu_kernel_block() - Allocate a gmu buffer
  158. * @gmu: Pointer to the gen7 gmu device
  159. * @md: Pointer to the memdesc
  160. * @size: Size of the buffer in bytes
  161. * @vma_id: Target gmu vma where this buffer should be mapped
  162. * @attrs: Attributes for the mapping
  163. *
  164. * This function allocates a buffer and maps it in the desired gmu vma
  165. *
  166. * Return: 0 on success or error code on failure
  167. */
  168. int gen7_alloc_gmu_kernel_block(struct gen7_gmu_device *gmu,
  169. struct kgsl_memdesc *md, u32 size, u32 vma_id, int attrs);
  170. /**
  171. * gen7_gmu_import_buffer() - Import a gmu buffer
  172. * @gmu: Pointer to the gen7 gmu device
  173. * @vma_id: Target gmu vma where this buffer should be mapped
  174. * @md: Pointer to the memdesc to be mapped
  175. * @attrs: Attributes for the mapping
  176. * @align: Alignment for the GMU VA and GMU mapping size
  177. *
  178. * This function imports and maps a buffer to a gmu vma
  179. *
  180. * Return: 0 on success or error code on failure
  181. */
  182. int gen7_gmu_import_buffer(struct gen7_gmu_device *gmu, u32 vma_id,
  183. struct kgsl_memdesc *md, u32 attrs, u32 align);
  184. /**
  185. * gen7_free_gmu_block() - Free a gmu buffer
  186. * @gmu: Pointer to the gen7 gmu device
  187. * @md: Pointer to the memdesc that is to be freed
  188. *
  189. * This function frees a gmu block allocated by gen7_reserve_gmu_kernel_block()
  190. */
  191. void gen7_free_gmu_block(struct gen7_gmu_device *gmu, struct kgsl_memdesc *md);
  192. /**
  193. * gen7_build_rpmh_tables - Build the rpmh tables
  194. * @adreno_dev: Pointer to the adreno device
  195. *
  196. * This function creates the gpu dcvs and bw tables
  197. *
  198. * Return: 0 on success and negative error on failure
  199. */
  200. int gen7_build_rpmh_tables(struct adreno_device *adreno_dev);
  201. /**
  202. * gen7_gmu_gx_is_on - Check if GX is on
  203. * @adreno_dev: Pointer to the adreno device
  204. *
  205. * This function reads pwr status registers to check if GX
  206. * is on or off
  207. */
  208. bool gen7_gmu_gx_is_on(struct adreno_device *adreno_dev);
  209. /**
  210. * gen7_gmu_device_probe - GEN7 GMU snapshot function
  211. * @pdev: Pointer to the platform device
  212. * @chipid: Chipid of the target
  213. * @gpucore: Pointer to the gpucore
  214. *
  215. * The target specific probe function for gmu based gen7 targets.
  216. */
  217. int gen7_gmu_device_probe(struct platform_device *pdev,
  218. u32 chipid, const struct adreno_gpu_core *gpucore);
  219. /**
  220. * gen7_gmu_reset - Reset and restart the gmu
  221. * @adreno_dev: Pointer to the adreno device
  222. *
  223. * Return: 0 on success or negative error on failure
  224. */
  225. int gen7_gmu_reset(struct adreno_device *adreno_dev);
  226. /**
  227. * gen7_enable_gpu_irq - Enable gpu interrupt
  228. * @adreno_dev: Pointer to the adreno device
  229. */
  230. void gen7_enable_gpu_irq(struct adreno_device *adreno_dev);
  231. /**
  232. * gen7_disable_gpu_irq - Disable gpu interrupt
  233. * @adreno_dev: Pointer to the adreno device
  234. */
  235. void gen7_disable_gpu_irq(struct adreno_device *adreno_dev);
  236. /**
  237. * gen7_gmu_snapshot- Take snapshot for gmu targets
  238. * @adreno_dev: Pointer to the adreno device
  239. * @snapshot: Pointer to the snapshot structure
  240. *
  241. * Send an NMI to gmu if we hit a gmu fault. Then take gmu
  242. * snapshot and carry on with rest of the gen7 snapshot
  243. */
  244. void gen7_gmu_snapshot(struct adreno_device *adreno_dev,
  245. struct kgsl_snapshot *snapshot);
  246. /**
  247. * gen7_gmu_probe - Probe gen7 gmu resources
  248. * @device: Pointer to the kgsl device
  249. * @pdev: Pointer to the gmu platform device
  250. *
  251. * Probe the gmu and hfi resources
  252. *
  253. * Return: 0 on success or negative error on failure
  254. */
  255. int gen7_gmu_probe(struct kgsl_device *device,
  256. struct platform_device *pdev);
  257. /**
  258. * gen7_gmu_parse_fw - Parse the gmu fw binary
  259. * @adreno_dev: Pointer to the adreno device
  260. *
  261. * Return: 0 on success or negative error on failure
  262. */
  263. int gen7_gmu_parse_fw(struct adreno_device *adreno_dev);
  264. /**
  265. * gen7_gmu_memory_init - Allocate gmu memory
  266. * @adreno_dev: Pointer to the adreno device
  267. *
  268. * Allocates the gmu log buffer and others if ndeeded.
  269. *
  270. * Return: 0 on success or negative error on failure
  271. */
  272. int gen7_gmu_memory_init(struct adreno_device *adreno_dev);
  273. /**
  274. * gen7_gmu_aop_send_acd_state - Enable or disable acd feature in aop
  275. * @gmu: Pointer to the gen7 gmu device
  276. * @flag: Boolean to enable or disable acd in aop
  277. *
  278. * This function enables or disables gpu acd feature using mailbox
  279. */
  280. void gen7_gmu_aop_send_acd_state(struct gen7_gmu_device *gmu, bool flag);
  281. /**
  282. * gen7_gmu_load_fw - Load gmu firmware
  283. * @adreno_dev: Pointer to the adreno device
  284. *
  285. * Loads the gmu firmware binary into TCMs and memory
  286. *
  287. * Return: 0 on success or negative error on failure
  288. */
  289. int gen7_gmu_load_fw(struct adreno_device *adreno_dev);
  290. /**
  291. * gen7_gmu_device_start - Bring gmu out of reset
  292. * @adreno_dev: Pointer to the adreno device
  293. *
  294. * Return: 0 on success or negative error on failure
  295. */
  296. int gen7_gmu_device_start(struct adreno_device *adreno_dev);
  297. /**
  298. * gen7_gmu_hfi_start - Indicate hfi start to gmu
  299. * @device: Pointer to the kgsl device
  300. *
  301. * Return: 0 on success or negative error on failure
  302. */
  303. int gen7_gmu_hfi_start(struct adreno_device *adreno_dev);
  304. /**
  305. * gen7_gmu_itcm_shadow - Create itcm shadow copy for snapshot
  306. * @adreno_dev: Pointer to the adreno device
  307. *
  308. * Return: 0 on success or negative error on failure
  309. */
  310. int gen7_gmu_itcm_shadow(struct adreno_device *adreno_dev);
  311. /**
  312. * gen7_gmu_register_config - gmu register configuration
  313. * @adreno_dev: Pointer to the adreno device
  314. *
  315. * Program gmu regsiters based on features
  316. */
  317. void gen7_gmu_register_config(struct adreno_device *adreno_dev);
  318. /**
  319. * gen7_gmu_version_info - Get gmu firmware version
  320. * @adreno_dev: Pointer to the adreno device
  321. *
  322. * Return: 0 on success or negative error on failure
  323. */
  324. int gen7_gmu_version_info(struct adreno_device *adreno_dev);
  325. /**
  326. * gen7_gmu_irq_enable - Enable gmu interrupts
  327. * @adreno_dev: Pointer to the adreno device
  328. */
  329. void gen7_gmu_irq_enable(struct adreno_device *adreno_dev);
  330. /**
  331. * gen7_gmu_irq_disable - Disaable gmu interrupts
  332. * @adreno_dev: Pointer to the adreno device
  333. */
  334. void gen7_gmu_irq_disable(struct adreno_device *adreno_dev);
  335. /**
  336. * gen7_gmu_suspend - Hard reset the gpu and gmu
  337. * @adreno_dev: Pointer to the adreno device
  338. *
  339. * In case we hit a gmu fault, hard reset the gpu and gmu
  340. * to recover from the fault
  341. */
  342. void gen7_gmu_suspend(struct adreno_device *adreno_dev);
  343. /**
  344. * gen7_gmu_oob_set - send gmu oob request
  345. * @device: Pointer to the kgsl device
  346. * @req: Type of oob request as defined in enum oob_request
  347. *
  348. * Request gmu to keep gpu powered up till the oob is cleared
  349. *
  350. * Return: 0 on success or negative error on failure
  351. */
  352. int gen7_gmu_oob_set(struct kgsl_device *device, enum oob_request oob);
  353. /**
  354. * gen7_gmu_oob_clear - clear an asserted oob request
  355. * @device: Pointer to the kgsl device
  356. * @req: Type of oob request as defined in enum oob_request
  357. *
  358. * Clear a previously requested oob so that gmu can power
  359. * collapse the gpu
  360. */
  361. void gen7_gmu_oob_clear(struct kgsl_device *device, enum oob_request oob);
  362. /**
  363. * gen7_gmu_wait_for_lowest_idle - wait for gmu to complete ifpc
  364. * @adreno_dev: Pointer to the adreno device
  365. *
  366. * If ifpc is enabled, wait for gmu to put gpu into ifpc.
  367. *
  368. * Return: 0 on success or negative error on failure
  369. */
  370. int gen7_gmu_wait_for_lowest_idle(struct adreno_device *adreno_dev);
  371. /**
  372. * gen7_gmu_wait_for_idle - Wait for gmu to become idle
  373. * @adreno_dev: Pointer to the adreno device
  374. *
  375. * Return: 0 on success or negative error on failure
  376. */
  377. int gen7_gmu_wait_for_idle(struct adreno_device *adreno_dev);
  378. /**
  379. * gen7_rscc_sleep_sequence - Trigger rscc sleep sequence
  380. * @adreno_dev: Pointer to the adreno device
  381. *
  382. * Return: 0 on success or negative error on failure
  383. */
  384. int gen7_rscc_sleep_sequence(struct adreno_device *adreno_dev);
  385. /**
  386. * gen7_rscc_wakeup_sequence - Trigger rscc wakeup sequence
  387. * @adreno_dev: Pointer to the adreno device
  388. *
  389. * Return: 0 on success or negative error on failure
  390. */
  391. int gen7_rscc_wakeup_sequence(struct adreno_device *adreno_dev);
  392. /**
  393. * gen7_halt_gbif - Halt CX and GX requests in GBIF
  394. * @adreno_dev: Pointer to the adreno device
  395. *
  396. * Clear any pending GX or CX transactions in GBIF and
  397. * deassert GBIF halt
  398. *
  399. * Return: 0 on success or negative error on failure
  400. */
  401. int gen7_halt_gbif(struct adreno_device *adreno_dev);
  402. /**
  403. * gen7_load_pdc_ucode - Load and enable pdc sequence
  404. * @adreno_dev: Pointer to the adreno device
  405. *
  406. * Return: 0 on success or negative error on failure
  407. */
  408. int gen7_load_pdc_ucode(struct adreno_device *adreno_dev);
  409. /**
  410. * gen7_load_rsc_ucode - Load rscc sequence
  411. * @adreno_dev: Pointer to the adreno device
  412. */
  413. void gen7_load_rsc_ucode(struct adreno_device *adreno_dev);
  414. /**
  415. * gen7_gmu_remove - Clean up gmu probed resources
  416. * @device: Pointer to the kgsl device
  417. */
  418. void gen7_gmu_remove(struct kgsl_device *device);
  419. /**
  420. * gen7_gmu_enable_clks - Enable gmu clocks
  421. * @adreno_dev: Pointer to the adreno device
  422. * @level: GMU frequency level
  423. *
  424. * Return: 0 on success or negative error on failure
  425. */
  426. int gen7_gmu_enable_clks(struct adreno_device *adreno_dev, u32 level);
  427. /**
  428. * gen7_gmu_handle_watchdog - Handle watchdog interrupt
  429. * @adreno_dev: Pointer to the adreno device
  430. */
  431. void gen7_gmu_handle_watchdog(struct adreno_device *adreno_dev);
  432. /**
  433. * gen7_gmu_send_nmi - Send NMI to GMU
  434. * @device: Pointer to the kgsl device
  435. * @force: Boolean to forcefully send NMI irrespective of GMU state
  436. */
  437. void gen7_gmu_send_nmi(struct kgsl_device *device, bool force);
  438. /**
  439. * gen7_gmu_add_to_minidump - Register gen7_device with va minidump
  440. * @adreno_dev: Pointer to the adreno device
  441. */
  442. int gen7_gmu_add_to_minidump(struct adreno_device *adreno_dev);
  443. /**
  444. * gen7_snapshot_gmu_mem - Snapshot a GMU memory descriptor
  445. * @device: Pointer to the kgsl device
  446. * @buf: Destination snapshot buffer
  447. * @remain: Remaining size of the snapshot buffer
  448. * @priv: Opaque handle
  449. *
  450. * Return: Number of bytes written to snapshot buffer
  451. */
  452. size_t gen7_snapshot_gmu_mem(struct kgsl_device *device,
  453. u8 *buf, size_t remain, void *priv);
  454. /**
  455. * gen7_bus_ab_quantize - Calculate the AB vote that needs to be sent to GMU
  456. * @adreno_dev: Handle to the adreno device
  457. * @ab: ab request that needs to be scaled in MBps
  458. *
  459. * Returns the AB value that needs to be prefixed to bandwidth vote in kbps
  460. */
  461. u32 gen7_bus_ab_quantize(struct adreno_device *adreno_dev, u32 ab);
  462. #endif