uvd_v2_2.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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_HEAP_SIZE >> 3;
  106. WREG32(UVD_VCPU_CACHE_OFFSET1, addr);
  107. WREG32(UVD_VCPU_CACHE_SIZE1, size);
  108. addr += size;
  109. size = (RADEON_UVD_STACK_SIZE +
  110. (RADEON_UVD_SESSION_SIZE * rdev->uvd.max_handles)) >> 3;
  111. WREG32(UVD_VCPU_CACHE_OFFSET2, addr);
  112. WREG32(UVD_VCPU_CACHE_SIZE2, size);
  113. /* bits 28-31 */
  114. addr = (rdev->uvd.gpu_addr >> 28) & 0xF;
  115. WREG32(UVD_LMI_ADDR_EXT, (addr << 12) | (addr << 0));
  116. /* bits 32-39 */
  117. addr = (rdev->uvd.gpu_addr >> 32) & 0xFF;
  118. WREG32(UVD_LMI_EXT40_ADDR, addr | (0x9 << 16) | (0x1 << 31));
  119. /* tell firmware which hardware it is running on */
  120. switch (rdev->family) {
  121. default:
  122. return -EINVAL;
  123. case CHIP_RV710:
  124. chip_id = 0x01000005;
  125. break;
  126. case CHIP_RV730:
  127. chip_id = 0x01000006;
  128. break;
  129. case CHIP_RV740:
  130. chip_id = 0x01000007;
  131. break;
  132. case CHIP_CYPRESS:
  133. case CHIP_HEMLOCK:
  134. chip_id = 0x01000008;
  135. break;
  136. case CHIP_JUNIPER:
  137. chip_id = 0x01000009;
  138. break;
  139. case CHIP_REDWOOD:
  140. chip_id = 0x0100000a;
  141. break;
  142. case CHIP_CEDAR:
  143. chip_id = 0x0100000b;
  144. break;
  145. case CHIP_SUMO:
  146. case CHIP_SUMO2:
  147. chip_id = 0x0100000c;
  148. break;
  149. case CHIP_PALM:
  150. chip_id = 0x0100000e;
  151. break;
  152. case CHIP_CAYMAN:
  153. chip_id = 0x0100000f;
  154. break;
  155. case CHIP_BARTS:
  156. chip_id = 0x01000010;
  157. break;
  158. case CHIP_TURKS:
  159. chip_id = 0x01000011;
  160. break;
  161. case CHIP_CAICOS:
  162. chip_id = 0x01000012;
  163. break;
  164. case CHIP_TAHITI:
  165. chip_id = 0x01000014;
  166. break;
  167. case CHIP_VERDE:
  168. chip_id = 0x01000015;
  169. break;
  170. case CHIP_PITCAIRN:
  171. case CHIP_OLAND:
  172. chip_id = 0x01000016;
  173. break;
  174. case CHIP_ARUBA:
  175. chip_id = 0x01000017;
  176. break;
  177. }
  178. WREG32(UVD_VCPU_CHIP_ID, chip_id);
  179. return 0;
  180. }