uvd_v2_2.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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, addr & 0xffffffff);
  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. return;
  57. }
  58. /**
  59. * uvd_v2_2_resume - memory controller programming
  60. *
  61. * @rdev: radeon_device pointer
  62. *
  63. * Let the UVD memory controller know it's offsets
  64. */
  65. int uvd_v2_2_resume(struct radeon_device *rdev)
  66. {
  67. uint64_t addr;
  68. uint32_t chip_id, size;
  69. int r;
  70. r = radeon_uvd_resume(rdev);
  71. if (r)
  72. return r;
  73. /* programm the VCPU memory controller bits 0-27 */
  74. addr = rdev->uvd.gpu_addr >> 3;
  75. size = RADEON_GPU_PAGE_ALIGN(rdev->uvd_fw->size + 4) >> 3;
  76. WREG32(UVD_VCPU_CACHE_OFFSET0, addr);
  77. WREG32(UVD_VCPU_CACHE_SIZE0, size);
  78. addr += size;
  79. size = RADEON_UVD_STACK_SIZE >> 3;
  80. WREG32(UVD_VCPU_CACHE_OFFSET1, addr);
  81. WREG32(UVD_VCPU_CACHE_SIZE1, size);
  82. addr += size;
  83. size = RADEON_UVD_HEAP_SIZE >> 3;
  84. WREG32(UVD_VCPU_CACHE_OFFSET2, addr);
  85. WREG32(UVD_VCPU_CACHE_SIZE2, size);
  86. /* bits 28-31 */
  87. addr = (rdev->uvd.gpu_addr >> 28) & 0xF;
  88. WREG32(UVD_LMI_ADDR_EXT, (addr << 12) | (addr << 0));
  89. /* bits 32-39 */
  90. addr = (rdev->uvd.gpu_addr >> 32) & 0xFF;
  91. WREG32(UVD_LMI_EXT40_ADDR, addr | (0x9 << 16) | (0x1 << 31));
  92. /* tell firmware which hardware it is running on */
  93. switch (rdev->family) {
  94. default:
  95. return -EINVAL;
  96. case CHIP_RV710:
  97. chip_id = 0x01000005;
  98. break;
  99. case CHIP_RV730:
  100. chip_id = 0x01000006;
  101. break;
  102. case CHIP_RV740:
  103. chip_id = 0x01000007;
  104. break;
  105. case CHIP_CYPRESS:
  106. case CHIP_HEMLOCK:
  107. chip_id = 0x01000008;
  108. break;
  109. case CHIP_JUNIPER:
  110. chip_id = 0x01000009;
  111. break;
  112. case CHIP_REDWOOD:
  113. chip_id = 0x0100000a;
  114. break;
  115. case CHIP_CEDAR:
  116. chip_id = 0x0100000b;
  117. break;
  118. case CHIP_SUMO:
  119. case CHIP_SUMO2:
  120. chip_id = 0x0100000c;
  121. break;
  122. case CHIP_PALM:
  123. chip_id = 0x0100000e;
  124. break;
  125. case CHIP_CAYMAN:
  126. chip_id = 0x0100000f;
  127. break;
  128. case CHIP_BARTS:
  129. chip_id = 0x01000010;
  130. break;
  131. case CHIP_TURKS:
  132. chip_id = 0x01000011;
  133. break;
  134. case CHIP_CAICOS:
  135. chip_id = 0x01000012;
  136. break;
  137. case CHIP_TAHITI:
  138. chip_id = 0x01000014;
  139. break;
  140. case CHIP_VERDE:
  141. chip_id = 0x01000015;
  142. break;
  143. case CHIP_PITCAIRN:
  144. chip_id = 0x01000016;
  145. break;
  146. case CHIP_ARUBA:
  147. chip_id = 0x01000017;
  148. break;
  149. }
  150. WREG32(UVD_VCPU_CHIP_ID, chip_id);
  151. return 0;
  152. }