cdma_pusher.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // MIT License
  2. //
  3. // Copyright (c) Ryujinx Team and Contributors
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  6. // associated documentation files (the "Software"), to deal in the Software without restriction,
  7. // including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in all copies or
  12. // substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  15. // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  17. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. #include <bit>
  21. #include "command_classes/host1x.h"
  22. #include "command_classes/nvdec.h"
  23. #include "command_classes/vic.h"
  24. #include "video_core/cdma_pusher.h"
  25. #include "video_core/command_classes/nvdec_common.h"
  26. #include "video_core/command_classes/sync_manager.h"
  27. #include "video_core/engines/maxwell_3d.h"
  28. #include "video_core/gpu.h"
  29. #include "video_core/memory_manager.h"
  30. namespace Tegra {
  31. CDmaPusher::CDmaPusher(GPU& gpu_)
  32. : gpu{gpu_}, nvdec_processor(std::make_shared<Nvdec>(gpu)),
  33. vic_processor(std::make_unique<Vic>(gpu, nvdec_processor)),
  34. host1x_processor(std::make_unique<Host1x>(gpu)),
  35. sync_manager(std::make_unique<SyncptIncrManager>(gpu)) {}
  36. CDmaPusher::~CDmaPusher() = default;
  37. void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries) {
  38. for (const auto& value : entries) {
  39. if (mask != 0) {
  40. const auto lbs = static_cast<u32>(std::countr_zero(mask));
  41. mask &= ~(1U << lbs);
  42. ExecuteCommand(offset + lbs, value.raw);
  43. continue;
  44. } else if (count != 0) {
  45. --count;
  46. ExecuteCommand(offset, value.raw);
  47. if (incrementing) {
  48. ++offset;
  49. }
  50. continue;
  51. }
  52. const auto mode = value.submission_mode.Value();
  53. switch (mode) {
  54. case ChSubmissionMode::SetClass: {
  55. mask = value.value & 0x3f;
  56. offset = value.method_offset;
  57. current_class = static_cast<ChClassId>((value.value >> 6) & 0x3ff);
  58. break;
  59. }
  60. case ChSubmissionMode::Incrementing:
  61. case ChSubmissionMode::NonIncrementing:
  62. count = value.value;
  63. offset = value.method_offset;
  64. incrementing = mode == ChSubmissionMode::Incrementing;
  65. break;
  66. case ChSubmissionMode::Mask:
  67. mask = value.value;
  68. offset = value.method_offset;
  69. break;
  70. case ChSubmissionMode::Immediate: {
  71. const u32 data = value.value & 0xfff;
  72. offset = value.method_offset;
  73. ExecuteCommand(offset, data);
  74. break;
  75. }
  76. default:
  77. UNIMPLEMENTED_MSG("ChSubmission mode {} is not implemented!", static_cast<u32>(mode));
  78. break;
  79. }
  80. }
  81. }
  82. void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) {
  83. switch (current_class) {
  84. case ChClassId::NvDec:
  85. ThiStateWrite(nvdec_thi_state, offset, data);
  86. switch (static_cast<ThiMethod>(offset)) {
  87. case ThiMethod::IncSyncpt: {
  88. LOG_DEBUG(Service_NVDRV, "NVDEC Class IncSyncpt Method");
  89. const auto syncpoint_id = static_cast<u32>(data & 0xFF);
  90. const auto cond = static_cast<u32>((data >> 8) & 0xFF);
  91. if (cond == 0) {
  92. sync_manager->Increment(syncpoint_id);
  93. } else {
  94. sync_manager->SignalDone(
  95. sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
  96. }
  97. break;
  98. }
  99. case ThiMethod::SetMethod1:
  100. LOG_DEBUG(Service_NVDRV, "NVDEC method 0x{:X}",
  101. static_cast<u32>(nvdec_thi_state.method_0));
  102. nvdec_processor->ProcessMethod(nvdec_thi_state.method_0, data);
  103. break;
  104. default:
  105. break;
  106. }
  107. break;
  108. case ChClassId::GraphicsVic:
  109. ThiStateWrite(vic_thi_state, static_cast<u32>(state_offset), {data});
  110. switch (static_cast<ThiMethod>(state_offset)) {
  111. case ThiMethod::IncSyncpt: {
  112. LOG_DEBUG(Service_NVDRV, "VIC Class IncSyncpt Method");
  113. const auto syncpoint_id = static_cast<u32>(data & 0xFF);
  114. const auto cond = static_cast<u32>((data >> 8) & 0xFF);
  115. if (cond == 0) {
  116. sync_manager->Increment(syncpoint_id);
  117. } else {
  118. sync_manager->SignalDone(
  119. sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
  120. }
  121. break;
  122. }
  123. case ThiMethod::SetMethod1:
  124. LOG_DEBUG(Service_NVDRV, "VIC method 0x{:X}, Args=({})",
  125. static_cast<u32>(vic_thi_state.method_0), data);
  126. vic_processor->ProcessMethod(static_cast<Vic::Method>(vic_thi_state.method_0), data);
  127. break;
  128. default:
  129. break;
  130. }
  131. break;
  132. case ChClassId::Host1x:
  133. // This device is mainly for syncpoint synchronization
  134. LOG_DEBUG(Service_NVDRV, "Host1X Class Method");
  135. host1x_processor->ProcessMethod(static_cast<Host1x::Method>(offset), data);
  136. break;
  137. default:
  138. UNIMPLEMENTED_MSG("Current class not implemented {:X}", static_cast<u32>(current_class));
  139. break;
  140. }
  141. }
  142. void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset, u32 argument) {
  143. u8* const offset_ptr = reinterpret_cast<u8*>(&state) + sizeof(u32) * state_offset;
  144. std::memcpy(offset_ptr, &argument, sizeof(u32));
  145. }
  146. } // namespace Tegra