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