a6xx_gmu.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2017 The Linux Foundation. All rights reserved. */
  3. #ifndef _A6XX_GMU_H_
  4. #define _A6XX_GMU_H_
  5. #include <linux/interrupt.h>
  6. #include "msm_drv.h"
  7. #include "a6xx_hfi.h"
  8. struct a6xx_gmu_bo {
  9. void *virt;
  10. size_t size;
  11. u64 iova;
  12. struct page **pages;
  13. };
  14. /*
  15. * These define the different GMU wake up options - these define how both the
  16. * CPU and the GMU bring up the hardware
  17. */
  18. /* THe GMU has already been booted and the rentention registers are active */
  19. #define GMU_WARM_BOOT 0
  20. /* the GMU is coming up for the first time or back from a power collapse */
  21. #define GMU_COLD_BOOT 1
  22. /* The GMU is being soft reset after a fault */
  23. #define GMU_RESET 2
  24. /*
  25. * These define the level of control that the GMU has - the higher the number
  26. * the more things that the GMU hardware controls on its own.
  27. */
  28. /* The GMU does not do any idle state management */
  29. #define GMU_IDLE_STATE_ACTIVE 0
  30. /* The GMU manages SPTP power collapse */
  31. #define GMU_IDLE_STATE_SPTP 2
  32. /* The GMU does automatic IFPC (intra-frame power collapse) */
  33. #define GMU_IDLE_STATE_IFPC 3
  34. struct a6xx_gmu {
  35. struct device *dev;
  36. void * __iomem mmio;
  37. void * __iomem pdc_mmio;
  38. int hfi_irq;
  39. int gmu_irq;
  40. struct regulator *gx;
  41. struct iommu_domain *domain;
  42. u64 uncached_iova_base;
  43. int idle_level;
  44. struct a6xx_gmu_bo *hfi;
  45. struct a6xx_gmu_bo *debug;
  46. int nr_clocks;
  47. struct clk_bulk_data *clocks;
  48. struct clk *core_clk;
  49. int nr_gpu_freqs;
  50. unsigned long gpu_freqs[16];
  51. u32 gx_arc_votes[16];
  52. int nr_gmu_freqs;
  53. unsigned long gmu_freqs[4];
  54. u32 cx_arc_votes[4];
  55. struct a6xx_hfi_queue queues[2];
  56. struct tasklet_struct hfi_tasklet;
  57. };
  58. static inline u32 gmu_read(struct a6xx_gmu *gmu, u32 offset)
  59. {
  60. return msm_readl(gmu->mmio + (offset << 2));
  61. }
  62. static inline void gmu_write(struct a6xx_gmu *gmu, u32 offset, u32 value)
  63. {
  64. return msm_writel(value, gmu->mmio + (offset << 2));
  65. }
  66. static inline void pdc_write(struct a6xx_gmu *gmu, u32 offset, u32 value)
  67. {
  68. return msm_writel(value, gmu->pdc_mmio + (offset << 2));
  69. }
  70. static inline void gmu_rmw(struct a6xx_gmu *gmu, u32 reg, u32 mask, u32 or)
  71. {
  72. u32 val = gmu_read(gmu, reg);
  73. val &= ~mask;
  74. gmu_write(gmu, reg, val | or);
  75. }
  76. #define gmu_poll_timeout(gmu, addr, val, cond, interval, timeout) \
  77. readl_poll_timeout((gmu)->mmio + ((addr) << 2), val, cond, \
  78. interval, timeout)
  79. /*
  80. * These are the available OOB (out of band requests) to the GMU where "out of
  81. * band" means that the CPU talks to the GMU directly and not through HFI.
  82. * Normally this works by writing a ITCM/DTCM register and then triggering a
  83. * interrupt (the "request" bit) and waiting for an acknowledgment (the "ack"
  84. * bit). The state is cleared by writing the "clear' bit to the GMU interrupt.
  85. *
  86. * These are used to force the GMU/GPU to stay on during a critical sequence or
  87. * for hardware workarounds.
  88. */
  89. enum a6xx_gmu_oob_state {
  90. GMU_OOB_BOOT_SLUMBER = 0,
  91. GMU_OOB_GPU_SET,
  92. GMU_OOB_DCVS_SET,
  93. };
  94. /* These are the interrupt / ack bits for each OOB request that are set
  95. * in a6xx_gmu_set_oob and a6xx_clear_oob
  96. */
  97. /*
  98. * Let the GMU know that a boot or slumber operation has started. The value in
  99. * REG_A6XX_GMU_BOOT_SLUMBER_OPTION lets the GMU know which operation we are
  100. * doing
  101. */
  102. #define GMU_OOB_BOOT_SLUMBER_REQUEST 22
  103. #define GMU_OOB_BOOT_SLUMBER_ACK 30
  104. #define GMU_OOB_BOOT_SLUMBER_CLEAR 30
  105. /*
  106. * Set a new power level for the GPU when the CPU is doing frequency scaling
  107. */
  108. #define GMU_OOB_DCVS_REQUEST 23
  109. #define GMU_OOB_DCVS_ACK 31
  110. #define GMU_OOB_DCVS_CLEAR 31
  111. /*
  112. * Let the GMU know to not turn off any GPU registers while the CPU is in a
  113. * critical section
  114. */
  115. #define GMU_OOB_GPU_SET_REQUEST 16
  116. #define GMU_OOB_GPU_SET_ACK 24
  117. #define GMU_OOB_GPU_SET_CLEAR 24
  118. void a6xx_hfi_init(struct a6xx_gmu *gmu);
  119. int a6xx_hfi_start(struct a6xx_gmu *gmu, int boot_state);
  120. void a6xx_hfi_stop(struct a6xx_gmu *gmu);
  121. void a6xx_hfi_task(unsigned long data);
  122. #endif