uvd_v2_2.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright 2013 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Christian König <christian.koenig@amd.com>
  23. */
  24. #include <linux/firmware.h>
  25. #include <drm/drmP.h>
  26. #include "radeon.h"
  27. #include "radeon_asic.h"
  28. #include "rv770d.h"
  29. /**
  30. * uvd_v2_2_fence_emit - emit an fence & trap command
  31. *
  32. * @rdev: radeon_device pointer
  33. * @fence: fence to emit
  34. *
  35. * Write a fence and a trap command to the ring.
  36. */
  37. void uvd_v2_2_fence_emit(struct radeon_device *rdev,
  38. struct radeon_fence *fence)
  39. {
  40. struct radeon_ring *ring = &rdev->ring[fence->ring];
  41. uint64_t addr = rdev->fence_drv[fence->ring].gpu_addr;
  42. radeon_ring_write(ring, PACKET0(UVD_CONTEXT_ID, 0));
  43. radeon_ring_write(ring, fence->seq);
  44. radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA0, 0));
  45. radeon_ring_write(ring, lower_32_bits(addr));
  46. radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA1, 0));
  47. radeon_ring_write(ring, upper_32_bits(addr) & 0xff);
  48. radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_CMD, 0));
  49. radeon_ring_write(ring, 0);
  50. radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA0, 0));
  51. radeon_ring_write(ring, 0);
  52. radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_DATA1, 0));
  53. radeon_ring_write(ring, 0);
  54. radeon_ring_write(ring, PACKET0(UVD_GPCOM_VCPU_CMD, 0));
  55. radeon_ring_write(ring, 2);
  56. }
  57. /**
  58. * uvd_v2_2_semaphore_emit - emit semaphore command
  59. *
  60. * @rdev: radeon_device pointer
  61. * @ring: radeon_ring pointer
  62. * @semaphore: semaphore to emit commands for
  63. * @emit_wait: true if we should emit a wait command
  64. *
  65. * Emit a semaphore command (either wait or signal) to the UVD ring.
  66. */
  67. bool uvd_v2_2_semaphore_emit(struct radeon_device *rdev,
  68. struct radeon_ring *ring,
  69. struct radeon_semaphore *semaphore,
  70. bool emit_wait)
  71. {
  72. uint64_t addr = semaphore->gpu_addr;
  73. radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_LOW, 0));
  74. radeon_ring_write(ring, (addr >> 3) & 0x000FFFFF);
  75. radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_HIGH, 0));
  76. radeon_ring_write(ring, (addr >> 23) & 0x000FFFFF);
  77. radeon_ring_write(ring, PACKET0(UVD_SEMA_CMD, 0));
  78. radeon_ring_write(ring, emit_wait ? 1 : 0);
  79. return true;
  80. }
  81. /**
  82. * uvd_v2_2_resume - memory controller programming
  83. *
  84. * @rdev: radeon_device pointer
  85. *
  86. * Let the UVD memory controller know it's offsets
  87. */
  88. int uvd_v2_2_resume(struct radeon_device *rdev)
  89. {
  90. uint64_t addr;
  91. uint32_t chip_id, size;
  92. int r;
  93. /* RV770 uses V1.0 MC */
  94. if (rdev->family == CHIP_RV770)
  95. return uvd_v1_0_resume(rdev);
  96. r = radeon_uvd_resume(rdev);
  97. if (r)
  98. return r;
  99. /* programm the VCPU memory controller bits 0-27 */
  100. addr = rdev->uvd.gpu_addr >> 3;
  101. size = RADEON_GPU_PAGE_ALIGN(rdev->uvd_fw->size + 4) >> 3;
  102. WREG32(UVD_VCPU_CACHE_OFFSET0, addr);
  103. WREG32(UVD_VCPU_CACHE_SIZE0, size);
  104. addr += size;
  105. size = RADEON_UVD_STACK_SIZE >> 3;
  106. WREG32(UVD_VCPU_CACHE_OFFSET1, addr);
  107. WREG32(UVD_VCPU_CACHE_SIZE1, size);
  108. addr += size;
  109. size = RADEON_UVD_HEAP_SIZE >> 3;
  110. WREG32(UVD_VCPU_CACHE_OFFSET2, addr);
  111. WREG32(UVD_VCPU_CACHE_SIZE2, size);
  112. /* bits 28-31 */
  113. addr = (rdev->uvd.gpu_addr >> 28) & 0xF;
  114. WREG32(UVD_LMI_ADDR_EXT, (addr << 12) | (addr << 0));
  115. /* bits 32-39 */
  116. addr = (rdev->uvd.gpu_addr >> 32) & 0xFF;
  117. WREG32(UVD_LMI_EXT40_ADDR, addr | (0x9 << 16) | (0x1 << 31));
  118. /* tell firmware which hardware it is running on */
  119. switch (rdev->family) {
  120. default:
  121. return -EINVAL;
  122. case CHIP_RV710:
  123. chip_id = 0x01000005;
  124. break;
  125. case CHIP_RV730:
  126. chip_id = 0x01000006;
  127. break;
  128. case CHIP_RV740:
  129. chip_id = 0x01000007;
  130. break;
  131. case CHIP_CYPRESS:
  132. case CHIP_HEMLOCK:
  133. chip_id = 0x01000008;
  134. break;
  135. case CHIP_JUNIPER:
  136. chip_id = 0x01000009;
  137. break;
  138. case CHIP_REDWOOD:
  139. chip_id = 0x0100000a;
  140. break;
  141. case CHIP_CEDAR:
  142. chip_id = 0x0100000b;
  143. break;
  144. case CHIP_SUMO:
  145. case CHIP_SUMO2:
  146. chip_id = 0x0100000c;
  147. break;
  148. case CHIP_PALM:
  149. chip_id = 0x0100000e;
  150. break;
  151. case CHIP_CAYMAN:
  152. chip_id = 0x0100000f;
  153. break;
  154. case CHIP_BARTS:
  155. chip_id = 0x01000010;
  156. break;
  157. case CHIP_TURKS:
  158. chip_id = 0x01000011;
  159. break;
  160. case CHIP_CAICOS:
  161. chip_id = 0x01000012;
  162. break;
  163. case CHIP_TAHITI:
  164. chip_id = 0x01000014;
  165. break;
  166. case CHIP_VERDE:
  167. chip_id = 0x01000015;
  168. break;
  169. case CHIP_PITCAIRN:
  170. case CHIP_OLAND:
  171. chip_id = 0x01000016;
  172. break;
  173. case CHIP_ARUBA:
  174. chip_id = 0x01000017;
  175. break;
  176. }
  177. WREG32(UVD_VCPU_CHIP_ID, chip_id);
  178. return 0;
  179. }