gsp.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/bit_field.h"
  6. #include "core/hle/service/service.h"
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. // Namespace GSP_GPU
  9. namespace GSP_GPU {
  10. /// GSP interrupt ID
  11. enum class InterruptId : u8 {
  12. PSC0 = 0x00,
  13. PSC1 = 0x01,
  14. PDC0 = 0x02, // Seems called every vertical screen line
  15. PDC1 = 0x03, // Seems called every frame
  16. PPF = 0x04,
  17. P3D = 0x05,
  18. DMA = 0x06,
  19. };
  20. /// GSP command ID
  21. enum class CommandId : u32 {
  22. REQUEST_DMA = 0x00,
  23. SET_COMMAND_LIST_LAST = 0x01,
  24. // Fills a given memory range with a particular value
  25. SET_MEMORY_FILL = 0x02,
  26. // Copies an image and optionally performs color-conversion or scaling.
  27. // This is highly similar to the GameCube's EFB copy feature
  28. SET_DISPLAY_TRANSFER = 0x03,
  29. // Conceptionally similar to SET_DISPLAY_TRANSFER and presumable uses the same hardware path
  30. SET_TEXTURE_COPY = 0x04,
  31. SET_COMMAND_LIST_FIRST = 0x05,
  32. };
  33. /// GSP thread interrupt relay queue
  34. struct InterruptRelayQueue {
  35. union {
  36. u32 hex;
  37. // Index of last interrupt in the queue
  38. BitField<0,8,u32> index;
  39. // Number of interrupts remaining to be processed by the userland code
  40. BitField<8,8,u32> number_interrupts;
  41. // Error code - zero on success, otherwise an error has occurred
  42. BitField<16,8,u32> error_code;
  43. };
  44. u32 unk0;
  45. u32 unk1;
  46. InterruptId slot[0x34]; ///< Interrupt ID slots
  47. };
  48. static_assert(sizeof(InterruptRelayQueue) == 0x40,
  49. "InterruptRelayQueue struct has incorrect size");
  50. /// GSP command
  51. struct Command {
  52. BitField<0, 8, CommandId> id;
  53. union {
  54. struct {
  55. u32 source_address;
  56. u32 dest_address;
  57. u32 size;
  58. } dma_request;
  59. struct {
  60. u32 address;
  61. u32 size;
  62. } set_command_list_last;
  63. struct {
  64. u32 start1;
  65. u32 value1;
  66. u32 end1;
  67. u32 start2;
  68. u32 value2;
  69. u32 end2;
  70. } memory_fill;
  71. struct {
  72. u32 in_buffer_address;
  73. u32 out_buffer_address;
  74. u32 in_buffer_size;
  75. u32 out_buffer_size;
  76. u32 flags;
  77. } image_copy;
  78. u8 raw_data[0x1C];
  79. };
  80. };
  81. static_assert(sizeof(Command) == 0x20, "Command struct has incorrect size");
  82. /// GSP shared memory GX command buffer header
  83. struct CommandBuffer {
  84. union {
  85. u32 hex;
  86. // Current command index. This index is updated by GSP module after loading the command
  87. // data, right before the command is processed. When this index is updated by GSP module,
  88. // the total commands field is decreased by one as well.
  89. BitField<0,8,u32> index;
  90. // Total commands to process, must not be value 0 when GSP module handles commands. This
  91. // must be <=15 when writing a command to shared memory. This is incremented by the
  92. // application when writing a command to shared memory, after increasing this value
  93. // TriggerCmdReqQueue is only used if this field is value 1.
  94. BitField<8,8,u32> number_commands;
  95. };
  96. u32 unk[7];
  97. Command commands[0xF];
  98. };
  99. static_assert(sizeof(CommandBuffer) == 0x200, "CommandBuffer struct has incorrect size");
  100. /// Interface to "srv:" service
  101. class Interface : public Service::Interface {
  102. public:
  103. Interface();
  104. ~Interface();
  105. /**
  106. * Gets the string port name used by CTROS for the service
  107. * @return Port name of service
  108. */
  109. std::string GetPortName() const {
  110. return "gsp::Gpu";
  111. }
  112. };
  113. /**
  114. * Signals that the specified interrupt type has occurred to userland code
  115. * @param interrupt_id ID of interrupt that is being signalled
  116. */
  117. void SignalInterrupt(InterruptId interrupt_id);
  118. } // namespace