gsp_gpu.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/bit_field.h"
  5. #include "common/microprofile.h"
  6. #include "core/memory.h"
  7. #include "core/hle/kernel/event.h"
  8. #include "core/hle/kernel/shared_memory.h"
  9. #include "core/hle/result.h"
  10. #include "core/hw/hw.h"
  11. #include "core/hw/gpu.h"
  12. #include "core/hw/lcd.h"
  13. #include "video_core/gpu_debugger.h"
  14. #include "video_core/debug_utils/debug_utils.h"
  15. #include "video_core/renderer_base.h"
  16. #include "video_core/video_core.h"
  17. #include "gsp_gpu.h"
  18. // Main graphics debugger object - TODO: Here is probably not the best place for this
  19. GraphicsDebugger g_debugger;
  20. // Beginning address of HW regs
  21. const static u32 REGS_BEGIN = 0x1EB00000;
  22. ////////////////////////////////////////////////////////////////////////////////////////////////////
  23. // Namespace GSP_GPU
  24. namespace GSP_GPU {
  25. /// Event triggered when GSP interrupt has been signalled
  26. Kernel::SharedPtr<Kernel::Event> g_interrupt_event;
  27. /// GSP shared memoryings
  28. Kernel::SharedPtr<Kernel::SharedMemory> g_shared_memory;
  29. /// Thread index into interrupt relay queue
  30. u32 g_thread_id = 0;
  31. /// Gets a pointer to a thread command buffer in GSP shared memory
  32. static inline u8* GetCommandBuffer(u32 thread_id) {
  33. return g_shared_memory->GetPointer(0x800 + (thread_id * sizeof(CommandBuffer)));
  34. }
  35. FrameBufferUpdate* GetFrameBufferInfo(u32 thread_id, u32 screen_index) {
  36. DEBUG_ASSERT_MSG(screen_index < 2, "Invalid screen index");
  37. // For each thread there are two FrameBufferUpdate fields
  38. u32 offset = 0x200 + (2 * thread_id + screen_index) * sizeof(FrameBufferUpdate);
  39. u8* ptr = g_shared_memory->GetPointer(offset);
  40. return reinterpret_cast<FrameBufferUpdate*>(ptr);
  41. }
  42. /// Gets a pointer to the interrupt relay queue for a given thread index
  43. static inline InterruptRelayQueue* GetInterruptRelayQueue(u32 thread_id) {
  44. u8* ptr = g_shared_memory->GetPointer(sizeof(InterruptRelayQueue) * thread_id);
  45. return reinterpret_cast<InterruptRelayQueue*>(ptr);
  46. }
  47. /**
  48. * Checks if the parameters in a register write call are valid and logs in the case that
  49. * they are not
  50. * @param base_address The first address in the sequence of registers that will be written
  51. * @param size_in_bytes The number of registers that will be written
  52. * @return true if the parameters are valid, false otherwise
  53. */
  54. static bool CheckWriteParameters(u32 base_address, u32 size_in_bytes) {
  55. // TODO: Return proper error codes
  56. if (base_address + size_in_bytes >= 0x420000) {
  57. LOG_ERROR(Service_GSP, "Write address out of range! (address=0x%08x, size=0x%08x)",
  58. base_address, size_in_bytes);
  59. return false;
  60. }
  61. // size should be word-aligned
  62. if ((size_in_bytes % 4) != 0) {
  63. LOG_ERROR(Service_GSP, "Invalid size 0x%08x", size_in_bytes);
  64. return false;
  65. }
  66. return true;
  67. }
  68. /**
  69. * Writes sequential GSP GPU hardware registers using an array of source data
  70. *
  71. * @param base_address The address of the first register in the sequence
  72. * @param size_in_bytes The number of registers to update (size of data)
  73. * @param data A pointer to the source data
  74. */
  75. static void WriteHWRegs(u32 base_address, u32 size_in_bytes, const u32* data) {
  76. // TODO: Return proper error codes
  77. if (!CheckWriteParameters(base_address, size_in_bytes))
  78. return;
  79. while (size_in_bytes > 0) {
  80. HW::Write<u32>(base_address + REGS_BEGIN, *data);
  81. size_in_bytes -= 4;
  82. ++data;
  83. base_address += 4;
  84. }
  85. }
  86. /**
  87. * GSP_GPU::WriteHWRegs service function
  88. *
  89. * Writes sequential GSP GPU hardware registers
  90. *
  91. * Inputs:
  92. * 1 : address of first GPU register
  93. * 2 : number of registers to write sequentially
  94. * 4 : pointer to source data array
  95. */
  96. static void WriteHWRegs(Service::Interface* self) {
  97. u32* cmd_buff = Kernel::GetCommandBuffer();
  98. u32 reg_addr = cmd_buff[1];
  99. u32 size = cmd_buff[2];
  100. u32* src = (u32*)Memory::GetPointer(cmd_buff[4]);
  101. WriteHWRegs(reg_addr, size, src);
  102. }
  103. /**
  104. * Updates sequential GSP GPU hardware registers using parallel arrays of source data and masks.
  105. * For each register, the value is updated only where the mask is high
  106. *
  107. * @param base_address The address of the first register in the sequence
  108. * @param size_in_bytes The number of registers to update (size of data)
  109. * @param data A pointer to the source data to use for updates
  110. * @param masks A pointer to the masks
  111. */
  112. static void WriteHWRegsWithMask(u32 base_address, u32 size_in_bytes, const u32* data, const u32* masks) {
  113. // TODO: Return proper error codes
  114. if (!CheckWriteParameters(base_address, size_in_bytes))
  115. return;
  116. while (size_in_bytes > 0) {
  117. const u32 reg_address = base_address + REGS_BEGIN;
  118. u32 reg_value;
  119. HW::Read<u32>(reg_value, reg_address);
  120. // Update the current value of the register only for set mask bits
  121. reg_value = (reg_value & ~*masks) | (*data | *masks);
  122. HW::Write<u32>(reg_address, reg_value);
  123. size_in_bytes -= 4;
  124. ++data;
  125. ++masks;
  126. base_address += 4;
  127. }
  128. }
  129. /**
  130. * GSP_GPU::WriteHWRegsWithMask service function
  131. *
  132. * Updates sequential GSP GPU hardware registers using masks
  133. *
  134. * Inputs:
  135. * 1 : address of first GPU register
  136. * 2 : number of registers to update sequentially
  137. * 4 : pointer to source data array
  138. * 6 : pointer to mask array
  139. */
  140. static void WriteHWRegsWithMask(Service::Interface* self) {
  141. u32* cmd_buff = Kernel::GetCommandBuffer();
  142. u32 reg_addr = cmd_buff[1];
  143. u32 size = cmd_buff[2];
  144. u32* src_data = (u32*)Memory::GetPointer(cmd_buff[4]);
  145. u32* mask_data = (u32*)Memory::GetPointer(cmd_buff[6]);
  146. WriteHWRegsWithMask(reg_addr, size, src_data, mask_data);
  147. }
  148. /// Read a GSP GPU hardware register
  149. static void ReadHWRegs(Service::Interface* self) {
  150. u32* cmd_buff = Kernel::GetCommandBuffer();
  151. u32 reg_addr = cmd_buff[1];
  152. u32 size = cmd_buff[2];
  153. // TODO: Return proper error codes
  154. if (reg_addr + size >= 0x420000) {
  155. LOG_ERROR(Service_GSP, "Read address out of range! (address=0x%08x, size=0x%08x)", reg_addr, size);
  156. return;
  157. }
  158. // size should be word-aligned
  159. if ((size % 4) != 0) {
  160. LOG_ERROR(Service_GSP, "Invalid size 0x%08x", size);
  161. return;
  162. }
  163. u32* dst = (u32*)Memory::GetPointer(cmd_buff[0x41]);
  164. while (size > 0) {
  165. HW::Read<u32>(*dst, reg_addr + REGS_BEGIN);
  166. size -= 4;
  167. ++dst;
  168. reg_addr += 4;
  169. }
  170. }
  171. void SetBufferSwap(u32 screen_id, const FrameBufferInfo& info) {
  172. u32 base_address = 0x400000;
  173. PAddr phys_address_left = Memory::VirtualToPhysicalAddress(info.address_left);
  174. PAddr phys_address_right = Memory::VirtualToPhysicalAddress(info.address_right);
  175. if (info.active_fb == 0) {
  176. WriteHWRegs(base_address + 4 * static_cast<u32>(GPU_REG_INDEX(framebuffer_config[screen_id].address_left1)), 4,
  177. &phys_address_left);
  178. WriteHWRegs(base_address + 4 * static_cast<u32>(GPU_REG_INDEX(framebuffer_config[screen_id].address_right1)), 4,
  179. &phys_address_right);
  180. } else {
  181. WriteHWRegs(base_address + 4 * static_cast<u32>(GPU_REG_INDEX(framebuffer_config[screen_id].address_left2)), 4,
  182. &phys_address_left);
  183. WriteHWRegs(base_address + 4 * static_cast<u32>(GPU_REG_INDEX(framebuffer_config[screen_id].address_right2)), 4,
  184. &phys_address_right);
  185. }
  186. WriteHWRegs(base_address + 4 * static_cast<u32>(GPU_REG_INDEX(framebuffer_config[screen_id].stride)), 4,
  187. &info.stride);
  188. WriteHWRegs(base_address + 4 * static_cast<u32>(GPU_REG_INDEX(framebuffer_config[screen_id].color_format)), 4,
  189. &info.format);
  190. WriteHWRegs(base_address + 4 * static_cast<u32>(GPU_REG_INDEX(framebuffer_config[screen_id].active_fb)), 4,
  191. &info.shown_fb);
  192. if (Pica::g_debug_context)
  193. Pica::g_debug_context->OnEvent(Pica::DebugContext::Event::BufferSwapped, nullptr);
  194. if (screen_id == 0) {
  195. MicroProfileFlip();
  196. }
  197. }
  198. /**
  199. * GSP_GPU::SetBufferSwap service function
  200. *
  201. * Updates GPU display framebuffer configuration using the specified parameters.
  202. *
  203. * Inputs:
  204. * 1 : Screen ID (0 = top screen, 1 = bottom screen)
  205. * 2-7 : FrameBufferInfo structure
  206. * Outputs:
  207. * 1: Result code
  208. */
  209. static void SetBufferSwap(Service::Interface* self) {
  210. u32* cmd_buff = Kernel::GetCommandBuffer();
  211. u32 screen_id = cmd_buff[1];
  212. FrameBufferInfo* fb_info = (FrameBufferInfo*)&cmd_buff[2];
  213. SetBufferSwap(screen_id, *fb_info);
  214. cmd_buff[1] = 0; // No error
  215. }
  216. /**
  217. * GSP_GPU::FlushDataCache service function
  218. *
  219. * This Function is a no-op, We aren't emulating the CPU cache any time soon.
  220. *
  221. * Inputs:
  222. * 1 : Address
  223. * 2 : Size
  224. * 3 : Value 0, some descriptor for the KProcess Handle
  225. * 4 : KProcess handle
  226. * Outputs:
  227. * 1 : Result of function, 0 on success, otherwise error code
  228. */
  229. static void FlushDataCache(Service::Interface* self) {
  230. u32* cmd_buff = Kernel::GetCommandBuffer();
  231. u32 address = cmd_buff[1];
  232. u32 size = cmd_buff[2];
  233. u32 process = cmd_buff[4];
  234. VideoCore::g_renderer->rasterizer->InvalidateRegion(Memory::VirtualToPhysicalAddress(address), size);
  235. // TODO(purpasmart96): Verify return header on HW
  236. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  237. LOG_DEBUG(Service_GSP, "(STUBBED) called address=0x%08X, size=0x%08X, process=0x%08X",
  238. address, size, process);
  239. }
  240. /**
  241. * GSP_GPU::RegisterInterruptRelayQueue service function
  242. * Inputs:
  243. * 1 : "Flags" field, purpose is unknown
  244. * 3 : Handle to GSP synchronization event
  245. * Outputs:
  246. * 1 : Result of function, 0x2A07 on success, otherwise error code
  247. * 2 : Thread index into GSP command buffer
  248. * 4 : Handle to GSP shared memory
  249. */
  250. static void RegisterInterruptRelayQueue(Service::Interface* self) {
  251. u32* cmd_buff = Kernel::GetCommandBuffer();
  252. u32 flags = cmd_buff[1];
  253. g_interrupt_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[3]);
  254. ASSERT_MSG((g_interrupt_event != nullptr), "handle is not valid!");
  255. Handle shmem_handle = Kernel::g_handle_table.Create(g_shared_memory).MoveFrom();
  256. // This specific code is required for a successful initialization, rather than 0
  257. cmd_buff[1] = ResultCode((ErrorDescription)519, ErrorModule::GX,
  258. ErrorSummary::Success, ErrorLevel::Success).raw;
  259. cmd_buff[2] = g_thread_id++; // Thread ID
  260. cmd_buff[4] = shmem_handle; // GSP shared memory
  261. g_interrupt_event->Signal(); // TODO(bunnei): Is this correct?
  262. }
  263. /**
  264. * Signals that the specified interrupt type has occurred to userland code
  265. * @param interrupt_id ID of interrupt that is being signalled
  266. * @todo This should probably take a thread_id parameter and only signal this thread?
  267. * @todo This probably does not belong in the GSP module, instead move to video_core
  268. */
  269. void SignalInterrupt(InterruptId interrupt_id) {
  270. if (0 == g_interrupt_event) {
  271. LOG_WARNING(Service_GSP, "cannot synchronize until GSP event has been created!");
  272. return;
  273. }
  274. if (nullptr == g_shared_memory) {
  275. LOG_WARNING(Service_GSP, "cannot synchronize until GSP shared memory has been created!");
  276. return;
  277. }
  278. for (int thread_id = 0; thread_id < 0x4; ++thread_id) {
  279. InterruptRelayQueue* interrupt_relay_queue = GetInterruptRelayQueue(thread_id);
  280. u8 next = interrupt_relay_queue->index;
  281. next += interrupt_relay_queue->number_interrupts;
  282. next = next % 0x34; // 0x34 is the number of interrupt slots
  283. interrupt_relay_queue->number_interrupts += 1;
  284. interrupt_relay_queue->slot[next] = interrupt_id;
  285. interrupt_relay_queue->error_code = 0x0; // No error
  286. // Update framebuffer information if requested
  287. // TODO(yuriks): Confirm where this code should be called. It is definitely updated without
  288. // executing any GSP commands, only waiting on the event.
  289. int screen_id = (interrupt_id == InterruptId::PDC0) ? 0 : (interrupt_id == InterruptId::PDC1) ? 1 : -1;
  290. if (screen_id != -1) {
  291. FrameBufferUpdate* info = GetFrameBufferInfo(thread_id, screen_id);
  292. if (info->is_dirty) {
  293. SetBufferSwap(screen_id, info->framebuffer_info[info->index]);
  294. info->is_dirty.Assign(false);
  295. }
  296. }
  297. }
  298. g_interrupt_event->Signal();
  299. }
  300. /// Executes the next GSP command
  301. static void ExecuteCommand(const Command& command, u32 thread_id) {
  302. // Utility function to convert register ID to address
  303. static auto WriteGPURegister = [](u32 id, u32 data) {
  304. GPU::Write<u32>(0x1EF00000 + 4 * id, data);
  305. };
  306. switch (command.id) {
  307. // GX request DMA - typically used for copying memory from GSP heap to VRAM
  308. case CommandId::REQUEST_DMA:
  309. VideoCore::g_renderer->rasterizer->FlushRegion(Memory::VirtualToPhysicalAddress(command.dma_request.source_address),
  310. command.dma_request.size);
  311. memcpy(Memory::GetPointer(command.dma_request.dest_address),
  312. Memory::GetPointer(command.dma_request.source_address),
  313. command.dma_request.size);
  314. SignalInterrupt(InterruptId::DMA);
  315. VideoCore::g_renderer->rasterizer->InvalidateRegion(Memory::VirtualToPhysicalAddress(command.dma_request.dest_address),
  316. command.dma_request.size);
  317. break;
  318. // TODO: This will need some rework in the future. (why?)
  319. case CommandId::SUBMIT_GPU_CMDLIST:
  320. {
  321. auto& params = command.submit_gpu_cmdlist;
  322. if (params.do_flush) {
  323. // This flag flushes the command list (params.address, params.size) from the cache.
  324. // Command lists are not processed by the hardware renderer, so we don't need to
  325. // actually flush them in Citra.
  326. }
  327. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(command_processor_config.address)),
  328. Memory::VirtualToPhysicalAddress(params.address) >> 3);
  329. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(command_processor_config.size)), params.size);
  330. // TODO: Not sure if we are supposed to always write this .. seems to trigger processing though
  331. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(command_processor_config.trigger)), 1);
  332. // TODO(yuriks): Figure out the meaning of the `flags` field.
  333. break;
  334. }
  335. // It's assumed that the two "blocks" behave equivalently.
  336. // Presumably this is done simply to allow two memory fills to run in parallel.
  337. case CommandId::SET_MEMORY_FILL:
  338. {
  339. auto& params = command.memory_fill;
  340. if (params.start1 != 0) {
  341. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].address_start)),
  342. Memory::VirtualToPhysicalAddress(params.start1) >> 3);
  343. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].address_end)),
  344. Memory::VirtualToPhysicalAddress(params.end1) >> 3);
  345. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].value_32bit)), params.value1);
  346. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].control)), params.control1);
  347. }
  348. if (params.start2 != 0) {
  349. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].address_start)),
  350. Memory::VirtualToPhysicalAddress(params.start2) >> 3);
  351. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].address_end)),
  352. Memory::VirtualToPhysicalAddress(params.end2) >> 3);
  353. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].value_32bit)), params.value2);
  354. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].control)), params.control2);
  355. }
  356. break;
  357. }
  358. case CommandId::SET_DISPLAY_TRANSFER:
  359. {
  360. auto& params = command.display_transfer;
  361. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.input_address)),
  362. Memory::VirtualToPhysicalAddress(params.in_buffer_address) >> 3);
  363. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.output_address)),
  364. Memory::VirtualToPhysicalAddress(params.out_buffer_address) >> 3);
  365. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.input_size)), params.in_buffer_size);
  366. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.output_size)), params.out_buffer_size);
  367. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.flags)), params.flags);
  368. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.trigger)), 1);
  369. break;
  370. }
  371. case CommandId::SET_TEXTURE_COPY:
  372. {
  373. auto& params = command.texture_copy;
  374. WriteGPURegister((u32)GPU_REG_INDEX(display_transfer_config.input_address),
  375. Memory::VirtualToPhysicalAddress(params.in_buffer_address) >> 3);
  376. WriteGPURegister((u32)GPU_REG_INDEX(display_transfer_config.output_address),
  377. Memory::VirtualToPhysicalAddress(params.out_buffer_address) >> 3);
  378. WriteGPURegister((u32)GPU_REG_INDEX(display_transfer_config.texture_copy.size),
  379. params.size);
  380. WriteGPURegister((u32)GPU_REG_INDEX(display_transfer_config.texture_copy.input_size),
  381. params.in_width_gap);
  382. WriteGPURegister((u32)GPU_REG_INDEX(display_transfer_config.texture_copy.output_size),
  383. params.out_width_gap);
  384. WriteGPURegister((u32)GPU_REG_INDEX(display_transfer_config.flags),
  385. params.flags);
  386. // NOTE: Actual GSP ORs 1 with current register instead of overwriting. Doesn't seem to matter.
  387. WriteGPURegister((u32)GPU_REG_INDEX(display_transfer_config.trigger), 1);
  388. break;
  389. }
  390. case CommandId::CACHE_FLUSH:
  391. {
  392. for (auto& region : command.cache_flush.regions) {
  393. if (region.size == 0)
  394. break;
  395. VideoCore::g_renderer->rasterizer->InvalidateRegion(
  396. Memory::VirtualToPhysicalAddress(region.address), region.size);
  397. }
  398. break;
  399. }
  400. default:
  401. LOG_ERROR(Service_GSP, "unknown command 0x%08X", (int)command.id.Value());
  402. }
  403. if (Pica::g_debug_context)
  404. Pica::g_debug_context->OnEvent(Pica::DebugContext::Event::GSPCommandProcessed, (void*)&command);
  405. }
  406. /**
  407. * GSP_GPU::SetLcdForceBlack service function
  408. *
  409. * Enable or disable REG_LCDCOLORFILL with the color black.
  410. *
  411. * Inputs:
  412. * 1: Black color fill flag (0 = don't fill, !0 = fill)
  413. * Outputs:
  414. * 1: Result code
  415. */
  416. static void SetLcdForceBlack(Service::Interface* self) {
  417. u32* cmd_buff = Kernel::GetCommandBuffer();
  418. bool enable_black = cmd_buff[1] != 0;
  419. LCD::Regs::ColorFill data = {0};
  420. // Since data is already zeroed, there is no need to explicitly set
  421. // the color to black (all zero).
  422. data.is_enabled.Assign(enable_black);
  423. LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_top), data.raw); // Top LCD
  424. LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_bottom), data.raw); // Bottom LCD
  425. cmd_buff[1] = RESULT_SUCCESS.raw;
  426. }
  427. /// This triggers handling of the GX command written to the command buffer in shared memory.
  428. static void TriggerCmdReqQueue(Service::Interface* self) {
  429. // Iterate through each thread's command queue...
  430. for (unsigned thread_id = 0; thread_id < 0x4; ++thread_id) {
  431. CommandBuffer* command_buffer = (CommandBuffer*)GetCommandBuffer(thread_id);
  432. // Iterate through each command...
  433. for (unsigned i = 0; i < command_buffer->number_commands; ++i) {
  434. g_debugger.GXCommandProcessed((u8*)&command_buffer->commands[i]);
  435. // Decode and execute command
  436. ExecuteCommand(command_buffer->commands[i], thread_id);
  437. // Indicates that command has completed
  438. command_buffer->number_commands.Assign(command_buffer->number_commands - 1);
  439. }
  440. }
  441. u32* cmd_buff = Kernel::GetCommandBuffer();
  442. cmd_buff[1] = 0; // No error
  443. }
  444. /**
  445. * GSP_GPU::ImportDisplayCaptureInfo service function
  446. *
  447. * Returns information about the current framebuffer state
  448. *
  449. * Inputs:
  450. * 0: Header 0x00180000
  451. * Outputs:
  452. * 1: Result code
  453. * 2: Left framebuffer virtual address for the main screen
  454. * 3: Right framebuffer virtual address for the main screen
  455. * 4: Main screen framebuffer format
  456. * 5: Main screen framebuffer width
  457. * 6: Left framebuffer virtual address for the bottom screen
  458. * 7: Right framebuffer virtual address for the bottom screen
  459. * 8: Bottom screen framebuffer format
  460. * 9: Bottom screen framebuffer width
  461. */
  462. static void ImportDisplayCaptureInfo(Service::Interface* self) {
  463. u32* cmd_buff = Kernel::GetCommandBuffer();
  464. // TODO(Subv): We're always returning the framebuffer structures for thread_id = 0,
  465. // because we only support a single running application at a time.
  466. // This should always return the framebuffer data that is currently displayed on the screen.
  467. u32 thread_id = 0;
  468. FrameBufferUpdate* top_screen = GetFrameBufferInfo(thread_id, 0);
  469. FrameBufferUpdate* bottom_screen = GetFrameBufferInfo(thread_id, 1);
  470. cmd_buff[2] = top_screen->framebuffer_info[top_screen->index].address_left;
  471. cmd_buff[3] = top_screen->framebuffer_info[top_screen->index].address_right;
  472. cmd_buff[4] = top_screen->framebuffer_info[top_screen->index].format;
  473. cmd_buff[5] = top_screen->framebuffer_info[top_screen->index].stride;
  474. cmd_buff[6] = bottom_screen->framebuffer_info[bottom_screen->index].address_left;
  475. cmd_buff[7] = bottom_screen->framebuffer_info[bottom_screen->index].address_right;
  476. cmd_buff[8] = bottom_screen->framebuffer_info[bottom_screen->index].format;
  477. cmd_buff[9] = bottom_screen->framebuffer_info[bottom_screen->index].stride;
  478. cmd_buff[1] = RESULT_SUCCESS.raw;
  479. LOG_WARNING(Service_GSP, "called");
  480. }
  481. const Interface::FunctionInfo FunctionTable[] = {
  482. {0x00010082, WriteHWRegs, "WriteHWRegs"},
  483. {0x00020084, WriteHWRegsWithMask, "WriteHWRegsWithMask"},
  484. {0x00030082, nullptr, "WriteHWRegRepeat"},
  485. {0x00040080, ReadHWRegs, "ReadHWRegs"},
  486. {0x00050200, SetBufferSwap, "SetBufferSwap"},
  487. {0x00060082, nullptr, "SetCommandList"},
  488. {0x000700C2, nullptr, "RequestDma"},
  489. {0x00080082, FlushDataCache, "FlushDataCache"},
  490. {0x00090082, nullptr, "InvalidateDataCache"},
  491. {0x000A0044, nullptr, "RegisterInterruptEvents"},
  492. {0x000B0040, SetLcdForceBlack, "SetLcdForceBlack"},
  493. {0x000C0000, TriggerCmdReqQueue, "TriggerCmdReqQueue"},
  494. {0x000D0140, nullptr, "SetDisplayTransfer"},
  495. {0x000E0180, nullptr, "SetTextureCopy"},
  496. {0x000F0200, nullptr, "SetMemoryFill"},
  497. {0x00100040, nullptr, "SetAxiConfigQoSMode"},
  498. {0x00110040, nullptr, "SetPerfLogMode"},
  499. {0x00120000, nullptr, "GetPerfLog"},
  500. {0x00130042, RegisterInterruptRelayQueue, "RegisterInterruptRelayQueue"},
  501. {0x00140000, nullptr, "UnregisterInterruptRelayQueue"},
  502. {0x00150002, nullptr, "TryAcquireRight"},
  503. {0x00160042, nullptr, "AcquireRight"},
  504. {0x00170000, nullptr, "ReleaseRight"},
  505. {0x00180000, ImportDisplayCaptureInfo, "ImportDisplayCaptureInfo"},
  506. {0x00190000, nullptr, "SaveVramSysArea"},
  507. {0x001A0000, nullptr, "RestoreVramSysArea"},
  508. {0x001B0000, nullptr, "ResetGpuCore"},
  509. {0x001C0040, nullptr, "SetLedForceOff"},
  510. {0x001D0040, nullptr, "SetTestCommand"},
  511. {0x001E0080, nullptr, "SetInternalPriorities"},
  512. {0x001F0082, nullptr, "StoreDataCache"},
  513. };
  514. ////////////////////////////////////////////////////////////////////////////////////////////////////
  515. // Interface class
  516. Interface::Interface() {
  517. Register(FunctionTable);
  518. g_interrupt_event = nullptr;
  519. using Kernel::MemoryPermission;
  520. g_shared_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite,
  521. MemoryPermission::ReadWrite, "GSPSharedMem");
  522. g_thread_id = 0;
  523. }
  524. Interface::~Interface() {
  525. g_interrupt_event = nullptr;
  526. g_shared_memory = nullptr;
  527. }
  528. } // namespace