gsp_gpu.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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 "core/mem_map.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. }
  195. /**
  196. * GSP_GPU::SetBufferSwap service function
  197. *
  198. * Updates GPU display framebuffer configuration using the specified parameters.
  199. *
  200. * Inputs:
  201. * 1 : Screen ID (0 = top screen, 1 = bottom screen)
  202. * 2-7 : FrameBufferInfo structure
  203. * Outputs:
  204. * 1: Result code
  205. */
  206. static void SetBufferSwap(Service::Interface* self) {
  207. u32* cmd_buff = Kernel::GetCommandBuffer();
  208. u32 screen_id = cmd_buff[1];
  209. FrameBufferInfo* fb_info = (FrameBufferInfo*)&cmd_buff[2];
  210. SetBufferSwap(screen_id, *fb_info);
  211. cmd_buff[1] = 0; // No error
  212. }
  213. /**
  214. * GSP_GPU::FlushDataCache service function
  215. *
  216. * This Function is a no-op, We aren't emulating the CPU cache any time soon.
  217. *
  218. * Inputs:
  219. * 1 : Address
  220. * 2 : Size
  221. * 3 : Value 0, some descriptor for the KProcess Handle
  222. * 4 : KProcess handle
  223. * Outputs:
  224. * 1 : Result of function, 0 on success, otherwise error code
  225. */
  226. static void FlushDataCache(Service::Interface* self) {
  227. u32* cmd_buff = Kernel::GetCommandBuffer();
  228. u32 address = cmd_buff[1];
  229. u32 size = cmd_buff[2];
  230. u32 process = cmd_buff[4];
  231. VideoCore::g_renderer->hw_rasterizer->NotifyFlush(Memory::VirtualToPhysicalAddress(address), size);
  232. // TODO(purpasmart96): Verify return header on HW
  233. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  234. LOG_DEBUG(Service_GSP, "(STUBBED) called address=0x%08X, size=0x%08X, process=0x%08X",
  235. address, size, process);
  236. }
  237. /**
  238. * GSP_GPU::RegisterInterruptRelayQueue service function
  239. * Inputs:
  240. * 1 : "Flags" field, purpose is unknown
  241. * 3 : Handle to GSP synchronization event
  242. * Outputs:
  243. * 1 : Result of function, 0x2A07 on success, otherwise error code
  244. * 2 : Thread index into GSP command buffer
  245. * 4 : Handle to GSP shared memory
  246. */
  247. static void RegisterInterruptRelayQueue(Service::Interface* self) {
  248. u32* cmd_buff = Kernel::GetCommandBuffer();
  249. u32 flags = cmd_buff[1];
  250. g_interrupt_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[3]);
  251. ASSERT_MSG((g_interrupt_event != nullptr), "handle is not valid!");
  252. Handle shmem_handle = Kernel::g_handle_table.Create(g_shared_memory).MoveFrom();
  253. // This specific code is required for a successful initialization, rather than 0
  254. cmd_buff[1] = ResultCode((ErrorDescription)519, ErrorModule::GX,
  255. ErrorSummary::Success, ErrorLevel::Success).raw;
  256. cmd_buff[2] = g_thread_id++; // Thread ID
  257. cmd_buff[4] = shmem_handle; // GSP shared memory
  258. g_interrupt_event->Signal(); // TODO(bunnei): Is this correct?
  259. }
  260. /**
  261. * Signals that the specified interrupt type has occurred to userland code
  262. * @param interrupt_id ID of interrupt that is being signalled
  263. * @todo This should probably take a thread_id parameter and only signal this thread?
  264. * @todo This probably does not belong in the GSP module, instead move to video_core
  265. */
  266. void SignalInterrupt(InterruptId interrupt_id) {
  267. if (0 == g_interrupt_event) {
  268. LOG_WARNING(Service_GSP, "cannot synchronize until GSP event has been created!");
  269. return;
  270. }
  271. if (nullptr == g_shared_memory) {
  272. LOG_WARNING(Service_GSP, "cannot synchronize until GSP shared memory has been created!");
  273. return;
  274. }
  275. for (int thread_id = 0; thread_id < 0x4; ++thread_id) {
  276. InterruptRelayQueue* interrupt_relay_queue = GetInterruptRelayQueue(thread_id);
  277. u8 next = interrupt_relay_queue->index;
  278. next += interrupt_relay_queue->number_interrupts;
  279. next = next % 0x34; // 0x34 is the number of interrupt slots
  280. interrupt_relay_queue->number_interrupts += 1;
  281. interrupt_relay_queue->slot[next] = interrupt_id;
  282. interrupt_relay_queue->error_code = 0x0; // No error
  283. // Update framebuffer information if requested
  284. // TODO(yuriks): Confirm where this code should be called. It is definitely updated without
  285. // executing any GSP commands, only waiting on the event.
  286. int screen_id = (interrupt_id == InterruptId::PDC0) ? 0 : (interrupt_id == InterruptId::PDC1) ? 1 : -1;
  287. if (screen_id != -1) {
  288. FrameBufferUpdate* info = GetFrameBufferInfo(thread_id, screen_id);
  289. if (info->is_dirty) {
  290. SetBufferSwap(screen_id, info->framebuffer_info[info->index]);
  291. info->is_dirty = false;
  292. }
  293. }
  294. }
  295. g_interrupt_event->Signal();
  296. }
  297. /// Executes the next GSP command
  298. static void ExecuteCommand(const Command& command, u32 thread_id) {
  299. // Utility function to convert register ID to address
  300. static auto WriteGPURegister = [](u32 id, u32 data) {
  301. GPU::Write<u32>(0x1EF00000 + 4 * id, data);
  302. };
  303. switch (command.id) {
  304. // GX request DMA - typically used for copying memory from GSP heap to VRAM
  305. case CommandId::REQUEST_DMA:
  306. VideoCore::g_renderer->hw_rasterizer->NotifyPreRead(Memory::VirtualToPhysicalAddress(command.dma_request.source_address),
  307. command.dma_request.size);
  308. memcpy(Memory::GetPointer(command.dma_request.dest_address),
  309. Memory::GetPointer(command.dma_request.source_address),
  310. command.dma_request.size);
  311. SignalInterrupt(InterruptId::DMA);
  312. VideoCore::g_renderer->hw_rasterizer->NotifyFlush(Memory::VirtualToPhysicalAddress(command.dma_request.dest_address),
  313. command.dma_request.size);
  314. break;
  315. // ctrulib homebrew sends all relevant command list data with this command,
  316. // hence we do all "interesting" stuff here and do nothing in SET_COMMAND_LIST_FIRST.
  317. // TODO: This will need some rework in the future.
  318. case CommandId::SET_COMMAND_LIST_LAST:
  319. {
  320. auto& params = command.set_command_list_last;
  321. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(command_processor_config.address)),
  322. Memory::VirtualToPhysicalAddress(params.address) >> 3);
  323. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(command_processor_config.size)), params.size);
  324. // TODO: Not sure if we are supposed to always write this .. seems to trigger processing though
  325. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(command_processor_config.trigger)), 1);
  326. break;
  327. }
  328. // It's assumed that the two "blocks" behave equivalently.
  329. // Presumably this is done simply to allow two memory fills to run in parallel.
  330. case CommandId::SET_MEMORY_FILL:
  331. {
  332. auto& params = command.memory_fill;
  333. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].address_start)),
  334. Memory::VirtualToPhysicalAddress(params.start1) >> 3);
  335. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].address_end)),
  336. Memory::VirtualToPhysicalAddress(params.end1) >> 3);
  337. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].value_32bit)), params.value1);
  338. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[0].control)), params.control1);
  339. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].address_start)),
  340. Memory::VirtualToPhysicalAddress(params.start2) >> 3);
  341. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].address_end)),
  342. Memory::VirtualToPhysicalAddress(params.end2) >> 3);
  343. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].value_32bit)), params.value2);
  344. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(memory_fill_config[1].control)), params.control2);
  345. break;
  346. }
  347. case CommandId::SET_DISPLAY_TRANSFER:
  348. {
  349. auto& params = command.image_copy;
  350. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.input_address)),
  351. Memory::VirtualToPhysicalAddress(params.in_buffer_address) >> 3);
  352. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.output_address)),
  353. Memory::VirtualToPhysicalAddress(params.out_buffer_address) >> 3);
  354. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.input_size)), params.in_buffer_size);
  355. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.output_size)), params.out_buffer_size);
  356. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.flags)), params.flags);
  357. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.trigger)), 1);
  358. break;
  359. }
  360. // TODO: Check if texture copies are implemented correctly..
  361. case CommandId::SET_TEXTURE_COPY:
  362. {
  363. auto& params = command.image_copy;
  364. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.input_address)),
  365. Memory::VirtualToPhysicalAddress(params.in_buffer_address) >> 3);
  366. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.output_address)),
  367. Memory::VirtualToPhysicalAddress(params.out_buffer_address) >> 3);
  368. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.input_size)), params.in_buffer_size);
  369. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.output_size)), params.out_buffer_size);
  370. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.flags)), params.flags);
  371. // TODO: Should this register be set to 1 or should instead its value be OR-ed with 1?
  372. WriteGPURegister(static_cast<u32>(GPU_REG_INDEX(display_transfer_config.trigger)), 1);
  373. break;
  374. }
  375. // TODO: Figure out what exactly SET_COMMAND_LIST_FIRST and SET_COMMAND_LIST_LAST
  376. // are supposed to do.
  377. case CommandId::SET_COMMAND_LIST_FIRST:
  378. {
  379. break;
  380. }
  381. default:
  382. LOG_ERROR(Service_GSP, "unknown command 0x%08X", (int)command.id.Value());
  383. }
  384. if (Pica::g_debug_context)
  385. Pica::g_debug_context->OnEvent(Pica::DebugContext::Event::GSPCommandProcessed, (void*)&command);
  386. }
  387. /**
  388. * GSP_GPU::SetLcdForceBlack service function
  389. *
  390. * Enable or disable REG_LCDCOLORFILL with the color black.
  391. *
  392. * Inputs:
  393. * 1: Black color fill flag (0 = don't fill, !0 = fill)
  394. * Outputs:
  395. * 1: Result code
  396. */
  397. static void SetLcdForceBlack(Service::Interface* self) {
  398. u32* cmd_buff = Kernel::GetCommandBuffer();
  399. bool enable_black = cmd_buff[1] != 0;
  400. LCD::Regs::ColorFill data = {0};
  401. // Since data is already zeroed, there is no need to explicitly set
  402. // the color to black (all zero).
  403. data.is_enabled = enable_black;
  404. LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_top), data.raw); // Top LCD
  405. LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_bottom), data.raw); // Bottom LCD
  406. cmd_buff[1] = RESULT_SUCCESS.raw;
  407. }
  408. /// This triggers handling of the GX command written to the command buffer in shared memory.
  409. static void TriggerCmdReqQueue(Service::Interface* self) {
  410. // Iterate through each thread's command queue...
  411. for (unsigned thread_id = 0; thread_id < 0x4; ++thread_id) {
  412. CommandBuffer* command_buffer = (CommandBuffer*)GetCommandBuffer(thread_id);
  413. // Iterate through each command...
  414. for (unsigned i = 0; i < command_buffer->number_commands; ++i) {
  415. g_debugger.GXCommandProcessed((u8*)&command_buffer->commands[i]);
  416. // Decode and execute command
  417. ExecuteCommand(command_buffer->commands[i], thread_id);
  418. // Indicates that command has completed
  419. command_buffer->number_commands = command_buffer->number_commands - 1;
  420. }
  421. }
  422. u32* cmd_buff = Kernel::GetCommandBuffer();
  423. cmd_buff[1] = 0; // No error
  424. }
  425. /**
  426. * GSP_GPU::ImportDisplayCaptureInfo service function
  427. *
  428. * Returns information about the current framebuffer state
  429. *
  430. * Inputs:
  431. * 0: Header 0x00180000
  432. * Outputs:
  433. * 1: Result code
  434. * 2: Left framebuffer virtual address for the main screen
  435. * 3: Right framebuffer virtual address for the main screen
  436. * 4: Main screen framebuffer format
  437. * 5: Main screen framebuffer width
  438. * 6: Left framebuffer virtual address for the bottom screen
  439. * 7: Right framebuffer virtual address for the bottom screen
  440. * 8: Bottom screen framebuffer format
  441. * 9: Bottom screen framebuffer width
  442. */
  443. static void ImportDisplayCaptureInfo(Service::Interface* self) {
  444. u32* cmd_buff = Kernel::GetCommandBuffer();
  445. // TODO(Subv): We're always returning the framebuffer structures for thread_id = 0,
  446. // because we only support a single running application at a time.
  447. // This should always return the framebuffer data that is currently displayed on the screen.
  448. u32 thread_id = 0;
  449. FrameBufferUpdate* top_screen = GetFrameBufferInfo(thread_id, 0);
  450. FrameBufferUpdate* bottom_screen = GetFrameBufferInfo(thread_id, 1);
  451. cmd_buff[2] = top_screen->framebuffer_info[top_screen->index].address_left;
  452. cmd_buff[3] = top_screen->framebuffer_info[top_screen->index].address_right;
  453. cmd_buff[4] = top_screen->framebuffer_info[top_screen->index].format;
  454. cmd_buff[5] = top_screen->framebuffer_info[top_screen->index].stride;
  455. cmd_buff[6] = bottom_screen->framebuffer_info[bottom_screen->index].address_left;
  456. cmd_buff[7] = bottom_screen->framebuffer_info[bottom_screen->index].address_right;
  457. cmd_buff[8] = bottom_screen->framebuffer_info[bottom_screen->index].format;
  458. cmd_buff[9] = bottom_screen->framebuffer_info[bottom_screen->index].stride;
  459. cmd_buff[1] = RESULT_SUCCESS.raw;
  460. LOG_WARNING(Service_GSP, "called");
  461. }
  462. const Interface::FunctionInfo FunctionTable[] = {
  463. {0x00010082, WriteHWRegs, "WriteHWRegs"},
  464. {0x00020084, WriteHWRegsWithMask, "WriteHWRegsWithMask"},
  465. {0x00030082, nullptr, "WriteHWRegRepeat"},
  466. {0x00040080, ReadHWRegs, "ReadHWRegs"},
  467. {0x00050200, SetBufferSwap, "SetBufferSwap"},
  468. {0x00060082, nullptr, "SetCommandList"},
  469. {0x000700C2, nullptr, "RequestDma"},
  470. {0x00080082, FlushDataCache, "FlushDataCache"},
  471. {0x00090082, nullptr, "InvalidateDataCache"},
  472. {0x000A0044, nullptr, "RegisterInterruptEvents"},
  473. {0x000B0040, SetLcdForceBlack, "SetLcdForceBlack"},
  474. {0x000C0000, TriggerCmdReqQueue, "TriggerCmdReqQueue"},
  475. {0x000D0140, nullptr, "SetDisplayTransfer"},
  476. {0x000E0180, nullptr, "SetTextureCopy"},
  477. {0x000F0200, nullptr, "SetMemoryFill"},
  478. {0x00100040, nullptr, "SetAxiConfigQoSMode"},
  479. {0x00110040, nullptr, "SetPerfLogMode"},
  480. {0x00120000, nullptr, "GetPerfLog"},
  481. {0x00130042, RegisterInterruptRelayQueue, "RegisterInterruptRelayQueue"},
  482. {0x00140000, nullptr, "UnregisterInterruptRelayQueue"},
  483. {0x00150002, nullptr, "TryAcquireRight"},
  484. {0x00160042, nullptr, "AcquireRight"},
  485. {0x00170000, nullptr, "ReleaseRight"},
  486. {0x00180000, ImportDisplayCaptureInfo, "ImportDisplayCaptureInfo"},
  487. {0x00190000, nullptr, "SaveVramSysArea"},
  488. {0x001A0000, nullptr, "RestoreVramSysArea"},
  489. {0x001B0000, nullptr, "ResetGpuCore"},
  490. {0x001C0040, nullptr, "SetLedForceOff"},
  491. {0x001D0040, nullptr, "SetTestCommand"},
  492. {0x001E0080, nullptr, "SetInternalPriorities"},
  493. {0x001F0082, nullptr, "StoreDataCache"},
  494. };
  495. ////////////////////////////////////////////////////////////////////////////////////////////////////
  496. // Interface class
  497. Interface::Interface() {
  498. Register(FunctionTable);
  499. g_interrupt_event = nullptr;
  500. using Kernel::MemoryPermission;
  501. g_shared_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite,
  502. MemoryPermission::ReadWrite, "GSPSharedMem");
  503. g_thread_id = 0;
  504. }
  505. Interface::~Interface() {
  506. g_interrupt_event = nullptr;
  507. g_shared_memory = nullptr;
  508. }
  509. } // namespace