vce_v2_0.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #define VCE_V2_0_FW_SIZE (256 * 1024)
  33. #define VCE_V2_0_STACK_SIZE (64 * 1024)
  34. #define VCE_V2_0_DATA_SIZE (23552 * RADEON_MAX_VCE_HANDLES)
  35. static void vce_v2_0_set_sw_cg(struct radeon_device *rdev, bool gated)
  36. {
  37. u32 tmp;
  38. if (gated) {
  39. tmp = RREG32(VCE_CLOCK_GATING_B);
  40. tmp |= 0xe70000;
  41. WREG32(VCE_CLOCK_GATING_B, tmp);
  42. tmp = RREG32(VCE_UENC_CLOCK_GATING);
  43. tmp |= 0xff000000;
  44. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  45. tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
  46. tmp &= ~0x3fc;
  47. WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
  48. WREG32(VCE_CGTT_CLK_OVERRIDE, 0);
  49. } else {
  50. tmp = RREG32(VCE_CLOCK_GATING_B);
  51. tmp |= 0xe7;
  52. tmp &= ~0xe70000;
  53. WREG32(VCE_CLOCK_GATING_B, tmp);
  54. tmp = RREG32(VCE_UENC_CLOCK_GATING);
  55. tmp |= 0x1fe000;
  56. tmp &= ~0xff000000;
  57. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  58. tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
  59. tmp |= 0x3fc;
  60. WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
  61. }
  62. }
  63. static void vce_v2_0_set_dyn_cg(struct radeon_device *rdev, bool gated)
  64. {
  65. u32 orig, tmp;
  66. tmp = RREG32(VCE_CLOCK_GATING_B);
  67. tmp &= ~0x00060006;
  68. if (gated) {
  69. tmp |= 0xe10000;
  70. } else {
  71. tmp |= 0xe1;
  72. tmp &= ~0xe10000;
  73. }
  74. WREG32(VCE_CLOCK_GATING_B, tmp);
  75. orig = tmp = RREG32(VCE_UENC_CLOCK_GATING);
  76. tmp &= ~0x1fe000;
  77. tmp &= ~0xff000000;
  78. if (tmp != orig)
  79. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  80. orig = tmp = RREG32(VCE_UENC_REG_CLOCK_GATING);
  81. tmp &= ~0x3fc;
  82. if (tmp != orig)
  83. WREG32(VCE_UENC_REG_CLOCK_GATING, tmp);
  84. if (gated)
  85. WREG32(VCE_CGTT_CLK_OVERRIDE, 0);
  86. }
  87. static void vce_v2_0_disable_cg(struct radeon_device *rdev)
  88. {
  89. WREG32(VCE_CGTT_CLK_OVERRIDE, 7);
  90. }
  91. void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable)
  92. {
  93. bool sw_cg = false;
  94. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_VCE_MGCG)) {
  95. if (sw_cg)
  96. vce_v2_0_set_sw_cg(rdev, true);
  97. else
  98. vce_v2_0_set_dyn_cg(rdev, true);
  99. } else {
  100. vce_v2_0_disable_cg(rdev);
  101. if (sw_cg)
  102. vce_v2_0_set_sw_cg(rdev, false);
  103. else
  104. vce_v2_0_set_dyn_cg(rdev, false);
  105. }
  106. }
  107. static void vce_v2_0_init_cg(struct radeon_device *rdev)
  108. {
  109. u32 tmp;
  110. tmp = RREG32(VCE_CLOCK_GATING_A);
  111. tmp &= ~(CGC_CLK_GATE_DLY_TIMER_MASK | CGC_CLK_GATER_OFF_DLY_TIMER_MASK);
  112. tmp |= (CGC_CLK_GATE_DLY_TIMER(0) | CGC_CLK_GATER_OFF_DLY_TIMER(4));
  113. tmp |= CGC_UENC_WAIT_AWAKE;
  114. WREG32(VCE_CLOCK_GATING_A, tmp);
  115. tmp = RREG32(VCE_UENC_CLOCK_GATING);
  116. tmp &= ~(CLOCK_ON_DELAY_MASK | CLOCK_OFF_DELAY_MASK);
  117. tmp |= (CLOCK_ON_DELAY(0) | CLOCK_OFF_DELAY(4));
  118. WREG32(VCE_UENC_CLOCK_GATING, tmp);
  119. tmp = RREG32(VCE_CLOCK_GATING_B);
  120. tmp |= 0x10;
  121. tmp &= ~0x100000;
  122. WREG32(VCE_CLOCK_GATING_B, tmp);
  123. }
  124. unsigned vce_v2_0_bo_size(struct radeon_device *rdev)
  125. {
  126. WARN_ON(rdev->vce_fw->size > VCE_V2_0_FW_SIZE);
  127. return VCE_V2_0_FW_SIZE + VCE_V2_0_STACK_SIZE + VCE_V2_0_DATA_SIZE;
  128. }
  129. int vce_v2_0_resume(struct radeon_device *rdev)
  130. {
  131. uint64_t addr = rdev->vce.gpu_addr;
  132. uint32_t size;
  133. WREG32_P(VCE_CLOCK_GATING_A, 0, ~(1 << 16));
  134. WREG32_P(VCE_UENC_CLOCK_GATING, 0x1FF000, ~0xFF9FF000);
  135. WREG32_P(VCE_UENC_REG_CLOCK_GATING, 0x3F, ~0x3F);
  136. WREG32(VCE_CLOCK_GATING_B, 0xf7);
  137. WREG32(VCE_LMI_CTRL, 0x00398000);
  138. WREG32_P(VCE_LMI_CACHE_CTRL, 0x0, ~0x1);
  139. WREG32(VCE_LMI_SWAP_CNTL, 0);
  140. WREG32(VCE_LMI_SWAP_CNTL1, 0);
  141. WREG32(VCE_LMI_VM_CTRL, 0);
  142. WREG32(VCE_LMI_VCPU_CACHE_40BIT_BAR, addr >> 8);
  143. addr &= 0xff;
  144. size = VCE_V2_0_FW_SIZE;
  145. WREG32(VCE_VCPU_CACHE_OFFSET0, addr & 0x7fffffff);
  146. WREG32(VCE_VCPU_CACHE_SIZE0, size);
  147. addr += size;
  148. size = VCE_V2_0_STACK_SIZE;
  149. WREG32(VCE_VCPU_CACHE_OFFSET1, addr & 0x7fffffff);
  150. WREG32(VCE_VCPU_CACHE_SIZE1, size);
  151. addr += size;
  152. size = VCE_V2_0_DATA_SIZE;
  153. WREG32(VCE_VCPU_CACHE_OFFSET2, addr & 0x7fffffff);
  154. WREG32(VCE_VCPU_CACHE_SIZE2, size);
  155. WREG32_P(VCE_LMI_CTRL2, 0x0, ~0x100);
  156. WREG32_P(VCE_SYS_INT_EN, VCE_SYS_INT_TRAP_INTERRUPT_EN,
  157. ~VCE_SYS_INT_TRAP_INTERRUPT_EN);
  158. vce_v2_0_init_cg(rdev);
  159. return 0;
  160. }