vce_v2_0.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright 2013 Advanced Micro Devices, Inc.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  16. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  17. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  19. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * The above copyright notice and this permission notice (including the
  22. * next paragraph) shall be included in all copies or substantial portions
  23. * of the Software.
  24. *
  25. * Authors: Christian König <christian.koenig@amd.com>
  26. */
  27. #include <linux/firmware.h>
  28. #include <drm/drmP.h>
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include "cikd.h"
  32. static void vce_v2_0_set_sw_cg(struct radeon_device *rdev, bool gated)
  33. {
  34. u32 tmp;
  35. if (gated) {
  36. tmp = RREG32(VCE_CLOCK_GATING_B);
  37. tmp |= 0xe70000;
  38. WREG32(VCE_CLOCK_GATING_B, tmp);
  39. tmp = RREG32(VCE_UENC_CLOCK_GATING);
  40. tmp |= 0xff000000;
  41. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  42. tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
  43. tmp &= ~0x3fc;
  44. WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
  45. WREG32(VCE_CGTT_CLK_OVERRIDE, 0);
  46. } else {
  47. tmp = RREG32(VCE_CLOCK_GATING_B);
  48. tmp |= 0xe7;
  49. tmp &= ~0xe70000;
  50. WREG32(VCE_CLOCK_GATING_B, tmp);
  51. tmp = RREG32(VCE_UENC_CLOCK_GATING);
  52. tmp |= 0x1fe000;
  53. tmp &= ~0xff000000;
  54. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  55. tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
  56. tmp |= 0x3fc;
  57. WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
  58. }
  59. }
  60. static void vce_v2_0_set_dyn_cg(struct radeon_device *rdev, bool gated)
  61. {
  62. u32 orig, tmp;
  63. tmp = RREG32(VCE_CLOCK_GATING_B);
  64. tmp &= ~0x00060006;
  65. if (gated) {
  66. tmp |= 0xe10000;
  67. } else {
  68. tmp |= 0xe1;
  69. tmp &= ~0xe10000;
  70. }
  71. WREG32(VCE_CLOCK_GATING_B, tmp);
  72. orig = tmp = RREG32(VCE_UENC_CLOCK_GATING);
  73. tmp &= ~0x1fe000;
  74. tmp &= ~0xff000000;
  75. if (tmp != orig)
  76. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  77. orig = tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
  78. tmp &= ~0x3fc;
  79. if (tmp != orig)
  80. WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
  81. if (gated)
  82. WREG32(VCE_CGTT_CLK_OVERRIDE, 0);
  83. }
  84. static void vce_v2_0_disable_cg(struct radeon_device *rdev)
  85. {
  86. WREG32(VCE_CGTT_CLK_OVERRIDE, 7);
  87. }
  88. void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable)
  89. {
  90. bool sw_cg = false;
  91. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_VCE_MGCG)) {
  92. if (sw_cg)
  93. vce_v2_0_set_sw_cg(rdev, true);
  94. else
  95. vce_v2_0_set_dyn_cg(rdev, true);
  96. } else {
  97. vce_v2_0_disable_cg(rdev);
  98. if (sw_cg)
  99. vce_v2_0_set_sw_cg(rdev, false);
  100. else
  101. vce_v2_0_set_dyn_cg(rdev, false);
  102. }
  103. }
  104. static void vce_v2_0_init_cg(struct radeon_device *rdev)
  105. {
  106. u32 tmp;
  107. tmp = RREG32(VCE_CLOCK_GATING_A);
  108. tmp &= ~(CGC_CLK_GATE_DLY_TIMER_MASK | CGC_CLK_GATER_OFF_DLY_TIMER_MASK);
  109. tmp |= (CGC_CLK_GATE_DLY_TIMER(0) | CGC_CLK_GATER_OFF_DLY_TIMER(4));
  110. tmp |= CGC_UENC_WAIT_AWAKE;
  111. WREG32(VCE_CLOCK_GATING_A, tmp);
  112. tmp = RREG32(VCE_UENC_CLOCK_GATING);
  113. tmp &= ~(CLOCK_ON_DELAY_MASK | CLOCK_OFF_DELAY_MASK);
  114. tmp |= (CLOCK_ON_DELAY(0) | CLOCK_OFF_DELAY(4));
  115. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  116. tmp = RREG32(VCE_CLOCK_GATING_B);
  117. tmp |= 0x10;
  118. tmp &= ~0x100000;
  119. WREG32(VCE_CLOCK_GATING_B, tmp);
  120. }
  121. int vce_v2_0_resume(struct radeon_device *rdev)
  122. {
  123. uint64_t addr = rdev->vce.gpu_addr;
  124. uint32_t size;
  125. WREG32_P(VCE_CLOCK_GATING_A, 0, ~(1 << 16));
  126. WREG32_P(VCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
  127. WREG32_P(VCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
  128. WREG32(VCE_CLOCK_GATING_B, 0xf7);
  129. WREG32(VCE_LMI_CTRL, 0x00398000);
  130. WREG32_P(VCE_LMI_CACHE_CTRL, 0x0, ~0x1);
  131. WREG32(VCE_LMI_SWAP_CNTL, 0);
  132. WREG32(VCE_LMI_SWAP_CNTL1, 0);
  133. WREG32(VCE_LMI_VM_CTRL, 0);
  134. size = RADEON_GPU_PAGE_ALIGN(rdev->vce_fw->size);
  135. WREG32(VCE_VCPU_CACHE_OFFSET0, addr & 0x7fffffff);
  136. WREG32(VCE_VCPU_CACHE_SIZE0, size);
  137. addr += size;
  138. size = RADEON_VCE_STACK_SIZE;
  139. WREG32(VCE_VCPU_CACHE_OFFSET1, addr & 0x7fffffff);
  140. WREG32(VCE_VCPU_CACHE_SIZE1, size);
  141. addr += size;
  142. size = RADEON_VCE_HEAP_SIZE;
  143. WREG32(VCE_VCPU_CACHE_OFFSET2, addr & 0x7fffffff);
  144. WREG32(VCE_VCPU_CACHE_SIZE2, size);
  145. WREG32_P(VCE_LMI_CTRL2, 0x0, ~0x100);
  146. WREG32_P(VCE_SYS_INT_EN, VCE_SYS_INT_TRAP_INTERRUPT_EN,
  147. ~VCE_SYS_INT_TRAP_INTERRUPT_EN);
  148. vce_v2_0_init_cg(rdev);
  149. return 0;
  150. }