diff options
Diffstat (limited to '')
| -rw-r--r-- | src/audio_core/audio_core.cpp | 9 | ||||
| -rw-r--r-- | src/audio_core/hle/pipe.cpp | 32 | ||||
| -rw-r--r-- | src/audio_core/hle/pipe.h | 4 | ||||
| -rw-r--r-- | src/core/hle/result.h | 1 | ||||
| -rw-r--r-- | src/core/hle/service/dsp_dsp.cpp | 191 | ||||
| -rw-r--r-- | src/core/hle/service/dsp_dsp.h | 19 |
6 files changed, 180 insertions, 76 deletions
diff --git a/src/audio_core/audio_core.cpp b/src/audio_core/audio_core.cpp index 894f46990..b512b0f9b 100644 --- a/src/audio_core/audio_core.cpp +++ b/src/audio_core/audio_core.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include "audio_core/audio_core.h" | 5 | #include "audio_core/audio_core.h" |
| 6 | #include "audio_core/hle/dsp.h" | 6 | #include "audio_core/hle/dsp.h" |
| 7 | #include "audio_core/hle/pipe.h" | ||
| 7 | 8 | ||
| 8 | #include "core/core_timing.h" | 9 | #include "core/core_timing.h" |
| 9 | #include "core/hle/kernel/vm_manager.h" | 10 | #include "core/hle/kernel/vm_manager.h" |
| @@ -17,10 +18,10 @@ static constexpr u64 audio_frame_ticks = 1310252ull; ///< Units: ARM11 cycles | |||
| 17 | 18 | ||
| 18 | static void AudioTickCallback(u64 /*userdata*/, int cycles_late) { | 19 | static void AudioTickCallback(u64 /*userdata*/, int cycles_late) { |
| 19 | if (DSP::HLE::Tick()) { | 20 | if (DSP::HLE::Tick()) { |
| 20 | // HACK: We're not signaling the interrups when they should be, but just firing them all off together. | 21 | // TODO(merry): Signal all the other interrupts as appropriate. |
| 21 | // It should be only (interrupt_id = 2, channel_id = 2) that's signalled here. | 22 | DSP_DSP::SignalPipeInterrupt(DSP::HLE::DspPipe::Audio); |
| 22 | // TODO(merry): Understand when the other interrupts are fired. | 23 | // HACK(merry): Added to prevent regressions. Will remove soon. |
| 23 | DSP_DSP::SignalAllInterrupts(); | 24 | DSP_DSP::SignalPipeInterrupt(DSP::HLE::DspPipe::Binary); |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | // Reschedule recurrent event | 27 | // Reschedule recurrent event |
diff --git a/src/audio_core/hle/pipe.cpp b/src/audio_core/hle/pipe.cpp index 9381883b4..03280780f 100644 --- a/src/audio_core/hle/pipe.cpp +++ b/src/audio_core/hle/pipe.cpp | |||
| @@ -12,12 +12,14 @@ | |||
| 12 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 14 | 14 | ||
| 15 | #include "core/hle/service/dsp_dsp.h" | ||
| 16 | |||
| 15 | namespace DSP { | 17 | namespace DSP { |
| 16 | namespace HLE { | 18 | namespace HLE { |
| 17 | 19 | ||
| 18 | static DspState dsp_state = DspState::Off; | 20 | static DspState dsp_state = DspState::Off; |
| 19 | 21 | ||
| 20 | static std::array<std::vector<u8>, static_cast<size_t>(DspPipe::DspPipe_MAX)> pipe_data; | 22 | static std::array<std::vector<u8>, NUM_DSP_PIPE> pipe_data; |
| 21 | 23 | ||
| 22 | void ResetPipes() { | 24 | void ResetPipes() { |
| 23 | for (auto& data : pipe_data) { | 25 | for (auto& data : pipe_data) { |
| @@ -27,16 +29,18 @@ void ResetPipes() { | |||
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { | 31 | std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { |
| 30 | if (pipe_number >= DspPipe::DspPipe_MAX) { | 32 | const size_t pipe_index = static_cast<size_t>(pipe_number); |
| 31 | LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); | 33 | |
| 34 | if (pipe_index >= NUM_DSP_PIPE) { | ||
| 35 | LOG_ERROR(Audio_DSP, "pipe_number = %zu invalid", pipe_index); | ||
| 32 | return {}; | 36 | return {}; |
| 33 | } | 37 | } |
| 34 | 38 | ||
| 35 | std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; | 39 | std::vector<u8>& data = pipe_data[pipe_index]; |
| 36 | 40 | ||
| 37 | if (length > data.size()) { | 41 | if (length > data.size()) { |
| 38 | LOG_WARNING(Audio_DSP, "pipe_number = %u is out of data, application requested read of %u but %zu remain", | 42 | LOG_WARNING(Audio_DSP, "pipe_number = %zu is out of data, application requested read of %u but %zu remain", |
| 39 | pipe_number, length, data.size()); | 43 | pipe_index, length, data.size()); |
| 40 | length = data.size(); | 44 | length = data.size(); |
| 41 | } | 45 | } |
| 42 | 46 | ||
| @@ -49,16 +53,20 @@ std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { | |||
| 49 | } | 53 | } |
| 50 | 54 | ||
| 51 | size_t GetPipeReadableSize(DspPipe pipe_number) { | 55 | size_t GetPipeReadableSize(DspPipe pipe_number) { |
| 52 | if (pipe_number >= DspPipe::DspPipe_MAX) { | 56 | const size_t pipe_index = static_cast<size_t>(pipe_number); |
| 53 | LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); | 57 | |
| 58 | if (pipe_index >= NUM_DSP_PIPE) { | ||
| 59 | LOG_ERROR(Audio_DSP, "pipe_number = %zu invalid", pipe_index); | ||
| 54 | return 0; | 60 | return 0; |
| 55 | } | 61 | } |
| 56 | 62 | ||
| 57 | return pipe_data[static_cast<size_t>(pipe_number)].size(); | 63 | return pipe_data[pipe_index].size(); |
| 58 | } | 64 | } |
| 59 | 65 | ||
| 60 | static void WriteU16(DspPipe pipe_number, u16 value) { | 66 | static void WriteU16(DspPipe pipe_number, u16 value) { |
| 61 | std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; | 67 | const size_t pipe_index = static_cast<size_t>(pipe_number); |
| 68 | |||
| 69 | std::vector<u8>& data = pipe_data.at(pipe_index); | ||
| 62 | // Little endian | 70 | // Little endian |
| 63 | data.emplace_back(value & 0xFF); | 71 | data.emplace_back(value & 0xFF); |
| 64 | data.emplace_back(value >> 8); | 72 | data.emplace_back(value >> 8); |
| @@ -91,6 +99,8 @@ static void AudioPipeWriteStructAddresses() { | |||
| 91 | for (u16 addr : struct_addresses) { | 99 | for (u16 addr : struct_addresses) { |
| 92 | WriteU16(DspPipe::Audio, addr); | 100 | WriteU16(DspPipe::Audio, addr); |
| 93 | } | 101 | } |
| 102 | // Signal that we have data on this pipe. | ||
| 103 | DSP_DSP::SignalPipeInterrupt(DspPipe::Audio); | ||
| 94 | } | 104 | } |
| 95 | 105 | ||
| 96 | void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { | 106 | void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { |
| @@ -145,7 +155,7 @@ void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { | |||
| 145 | return; | 155 | return; |
| 146 | } | 156 | } |
| 147 | default: | 157 | default: |
| 148 | LOG_CRITICAL(Audio_DSP, "pipe_number = %u unimplemented", pipe_number); | 158 | LOG_CRITICAL(Audio_DSP, "pipe_number = %zu unimplemented", static_cast<size_t>(pipe_number)); |
| 149 | UNIMPLEMENTED(); | 159 | UNIMPLEMENTED(); |
| 150 | return; | 160 | return; |
| 151 | } | 161 | } |
diff --git a/src/audio_core/hle/pipe.h b/src/audio_core/hle/pipe.h index 382d35e87..64d97f8ba 100644 --- a/src/audio_core/hle/pipe.h +++ b/src/audio_core/hle/pipe.h | |||
| @@ -19,9 +19,9 @@ enum class DspPipe { | |||
| 19 | Debug = 0, | 19 | Debug = 0, |
| 20 | Dma = 1, | 20 | Dma = 1, |
| 21 | Audio = 2, | 21 | Audio = 2, |
| 22 | Binary = 3, | 22 | Binary = 3 |
| 23 | DspPipe_MAX | ||
| 24 | }; | 23 | }; |
| 24 | constexpr size_t NUM_DSP_PIPE = 8; | ||
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| 27 | * Read a DSP pipe. | 27 | * Read a DSP pipe. |
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 2d22652d9..53931a106 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | /// Detailed description of the error. This listing is likely incomplete. | 18 | /// Detailed description of the error. This listing is likely incomplete. |
| 19 | enum class ErrorDescription : u32 { | 19 | enum class ErrorDescription : u32 { |
| 20 | Success = 0, | 20 | Success = 0, |
| 21 | OS_InvalidBufferDescriptor = 48, | ||
| 21 | WrongAddress = 53, | 22 | WrongAddress = 53, |
| 22 | FS_NotFound = 120, | 23 | FS_NotFound = 120, |
| 23 | FS_AlreadyExists = 190, | 24 | FS_AlreadyExists = 190, |
diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 08e437125..995bee3f9 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <cinttypes> | 6 | #include <cinttypes> |
| 6 | 7 | ||
| 7 | #include "audio_core/hle/pipe.h" | 8 | #include "audio_core/hle/pipe.h" |
| @@ -12,37 +13,80 @@ | |||
| 12 | #include "core/hle/kernel/event.h" | 13 | #include "core/hle/kernel/event.h" |
| 13 | #include "core/hle/service/dsp_dsp.h" | 14 | #include "core/hle/service/dsp_dsp.h" |
| 14 | 15 | ||
| 16 | using DspPipe = DSP::HLE::DspPipe; | ||
| 17 | |||
| 15 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 16 | // Namespace DSP_DSP | 19 | // Namespace DSP_DSP |
| 17 | 20 | ||
| 18 | namespace DSP_DSP { | 21 | namespace DSP_DSP { |
| 19 | 22 | ||
| 20 | static u32 read_pipe_count; | ||
| 21 | static Kernel::SharedPtr<Kernel::Event> semaphore_event; | 23 | static Kernel::SharedPtr<Kernel::Event> semaphore_event; |
| 22 | 24 | ||
| 23 | struct PairHash { | 25 | /// There are three types of interrupts |
| 24 | template <typename T, typename U> | 26 | enum class InterruptType { |
| 25 | std::size_t operator()(const std::pair<T, U> &x) const { | 27 | Zero, One, Pipe |
| 26 | // TODO(yuriks): Replace with better hash combining function. | 28 | }; |
| 27 | return std::hash<T>()(x.first) ^ std::hash<U>()(x.second); | 29 | constexpr size_t NUM_INTERRUPT_TYPE = 3; |
| 30 | |||
| 31 | class InterruptEvents final { | ||
| 32 | public: | ||
| 33 | void Signal(InterruptType type, DspPipe pipe) { | ||
| 34 | Kernel::SharedPtr<Kernel::Event>& event = Get(type, pipe); | ||
| 35 | if (event) { | ||
| 36 | event->Signal(); | ||
| 37 | } | ||
| 28 | } | 38 | } |
| 39 | |||
| 40 | Kernel::SharedPtr<Kernel::Event>& Get(InterruptType type, DspPipe dsp_pipe) { | ||
| 41 | switch (type) { | ||
| 42 | case InterruptType::Zero: | ||
| 43 | return zero; | ||
| 44 | case InterruptType::One: | ||
| 45 | return one; | ||
| 46 | case InterruptType::Pipe: { | ||
| 47 | const size_t pipe_index = static_cast<size_t>(dsp_pipe); | ||
| 48 | ASSERT(pipe_index < DSP::HLE::NUM_DSP_PIPE); | ||
| 49 | return pipe[pipe_index]; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | UNREACHABLE_MSG("Invalid interrupt type = %zu", static_cast<size_t>(type)); | ||
| 54 | } | ||
| 55 | |||
| 56 | bool HasTooManyEventsRegistered() const { | ||
| 57 | // Actual service implementation only has 6 'slots' for interrupts. | ||
| 58 | constexpr size_t max_number_of_interrupt_events = 6; | ||
| 59 | |||
| 60 | size_t number = std::count_if(pipe.begin(), pipe.end(), [](const auto& evt) { | ||
| 61 | return evt != nullptr; | ||
| 62 | }); | ||
| 63 | |||
| 64 | if (zero != nullptr) | ||
| 65 | number++; | ||
| 66 | if (one != nullptr) | ||
| 67 | number++; | ||
| 68 | |||
| 69 | return number >= max_number_of_interrupt_events; | ||
| 70 | } | ||
| 71 | |||
| 72 | private: | ||
| 73 | /// Currently unknown purpose | ||
| 74 | Kernel::SharedPtr<Kernel::Event> zero = nullptr; | ||
| 75 | /// Currently unknown purpose | ||
| 76 | Kernel::SharedPtr<Kernel::Event> one = nullptr; | ||
| 77 | /// Each DSP pipe has an associated interrupt | ||
| 78 | std::array<Kernel::SharedPtr<Kernel::Event>, DSP::HLE::NUM_DSP_PIPE> pipe = {{}}; | ||
| 29 | }; | 79 | }; |
| 30 | 80 | ||
| 31 | /// Map of (audio interrupt number, channel number) to Kernel::Events. See: RegisterInterruptEvents | 81 | static InterruptEvents interrupt_events; |
| 32 | static std::unordered_map<std::pair<u32, u32>, Kernel::SharedPtr<Kernel::Event>, PairHash> interrupt_events; | ||
| 33 | 82 | ||
| 34 | // DSP Interrupts: | 83 | // DSP Interrupts: |
| 35 | // Interrupt #2 occurs every frame tick. Userland programs normally have a thread that's waiting | 84 | // The audio-pipe interrupt occurs every frame tick. Userland programs normally have a thread |
| 36 | // for an interrupt event. Immediately after this interrupt event, userland normally updates the | 85 | // that's waiting for an interrupt event. Immediately after this interrupt event, userland |
| 37 | // state in the next region and increments the relevant frame counter by two. | 86 | // normally updates the state in the next region and increments the relevant frame counter by |
| 38 | void SignalAllInterrupts() { | 87 | // two. |
| 39 | // HACK: The other interrupts have currently unknown purpose, we trigger them each tick in any case. | 88 | void SignalPipeInterrupt(DspPipe pipe) { |
| 40 | for (auto& interrupt_event : interrupt_events) | 89 | interrupt_events.Signal(InterruptType::Pipe, pipe); |
| 41 | interrupt_event.second->Signal(); | ||
| 42 | } | ||
| 43 | |||
| 44 | void SignalInterrupt(u32 interrupt, u32 channel) { | ||
| 45 | interrupt_events[std::make_pair(interrupt, channel)]->Signal(); | ||
| 46 | } | 90 | } |
| 47 | 91 | ||
| 48 | /** | 92 | /** |
| @@ -58,7 +102,10 @@ static void ConvertProcessAddressFromDspDram(Service::Interface* self) { | |||
| 58 | 102 | ||
| 59 | u32 addr = cmd_buff[1]; | 103 | u32 addr = cmd_buff[1]; |
| 60 | 104 | ||
| 105 | cmd_buff[0] = IPC::MakeHeader(0xC, 2, 0); | ||
| 61 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 106 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 107 | |||
| 108 | // TODO(merry): There is a per-region offset missing in this calculation (that seems to be always zero). | ||
| 62 | cmd_buff[2] = (addr << 1) + (Memory::DSP_RAM_VADDR + 0x40000); | 109 | cmd_buff[2] = (addr << 1) + (Memory::DSP_RAM_VADDR + 0x40000); |
| 63 | 110 | ||
| 64 | LOG_DEBUG(Service_DSP, "addr=0x%08X", addr); | 111 | LOG_DEBUG(Service_DSP, "addr=0x%08X", addr); |
| @@ -113,7 +160,9 @@ static void LoadComponent(Service::Interface* self) { | |||
| 113 | static void GetSemaphoreEventHandle(Service::Interface* self) { | 160 | static void GetSemaphoreEventHandle(Service::Interface* self) { |
| 114 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 161 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 115 | 162 | ||
| 163 | cmd_buff[0] = IPC::MakeHeader(0x16, 1, 2); | ||
| 116 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 164 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 165 | // cmd_buff[2] not set | ||
| 117 | cmd_buff[3] = Kernel::g_handle_table.Create(semaphore_event).MoveFrom(); // Event handle | 166 | cmd_buff[3] = Kernel::g_handle_table.Create(semaphore_event).MoveFrom(); // Event handle |
| 118 | 167 | ||
| 119 | LOG_WARNING(Service_DSP, "(STUBBED) called"); | 168 | LOG_WARNING(Service_DSP, "(STUBBED) called"); |
| @@ -138,8 +187,7 @@ static void FlushDataCache(Service::Interface* self) { | |||
| 138 | u32 size = cmd_buff[2]; | 187 | u32 size = cmd_buff[2]; |
| 139 | u32 process = cmd_buff[4]; | 188 | u32 process = cmd_buff[4]; |
| 140 | 189 | ||
| 141 | // TODO(purpasmart96): Verify return header on HW | 190 | cmd_buff[0] = IPC::MakeHeader(0x13, 1, 0); |
| 142 | |||
| 143 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 191 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 144 | 192 | ||
| 145 | LOG_TRACE(Service_DSP, "called address=0x%08X, size=0x%X, process=0x%08X", address, size, process); | 193 | LOG_TRACE(Service_DSP, "called address=0x%08X, size=0x%X, process=0x%08X", address, size, process); |
| @@ -148,8 +196,8 @@ static void FlushDataCache(Service::Interface* self) { | |||
| 148 | /** | 196 | /** |
| 149 | * DSP_DSP::RegisterInterruptEvents service function | 197 | * DSP_DSP::RegisterInterruptEvents service function |
| 150 | * Inputs: | 198 | * Inputs: |
| 151 | * 1 : Interrupt Number | 199 | * 1 : Interrupt Type |
| 152 | * 2 : Channel Number | 200 | * 2 : Pipe Number |
| 153 | * 4 : Interrupt event handle | 201 | * 4 : Interrupt event handle |
| 154 | * Outputs: | 202 | * Outputs: |
| 155 | * 1 : Result of function, 0 on success, otherwise error code | 203 | * 1 : Result of function, 0 on success, otherwise error code |
| @@ -157,23 +205,40 @@ static void FlushDataCache(Service::Interface* self) { | |||
| 157 | static void RegisterInterruptEvents(Service::Interface* self) { | 205 | static void RegisterInterruptEvents(Service::Interface* self) { |
| 158 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 206 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 159 | 207 | ||
| 160 | u32 interrupt = cmd_buff[1]; | 208 | u32 type_index = cmd_buff[1]; |
| 161 | u32 channel = cmd_buff[2]; | 209 | u32 pipe_index = cmd_buff[2]; |
| 162 | u32 event_handle = cmd_buff[4]; | 210 | u32 event_handle = cmd_buff[4]; |
| 163 | 211 | ||
| 212 | ASSERT_MSG(type_index < NUM_INTERRUPT_TYPE && pipe_index < DSP::HLE::NUM_DSP_PIPE, | ||
| 213 | "Invalid type or pipe: type = %u, pipe = %u", type_index, pipe_index); | ||
| 214 | |||
| 215 | InterruptType type = static_cast<InterruptType>(cmd_buff[1]); | ||
| 216 | DspPipe pipe = static_cast<DspPipe>(cmd_buff[2]); | ||
| 217 | |||
| 218 | cmd_buff[0] = IPC::MakeHeader(0x15, 1, 0); | ||
| 219 | |||
| 164 | if (event_handle) { | 220 | if (event_handle) { |
| 165 | auto evt = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]); | 221 | auto evt = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]); |
| 166 | if (evt) { | 222 | |
| 167 | interrupt_events[std::make_pair(interrupt, channel)] = evt; | 223 | if (!evt) { |
| 168 | cmd_buff[1] = RESULT_SUCCESS.raw; | 224 | LOG_INFO(Service_DSP, "Invalid event handle! type=%u, pipe=%u, event_handle=0x%08X", type_index, pipe_index, event_handle); |
| 169 | LOG_INFO(Service_DSP, "Registered interrupt=%u, channel=%u, event_handle=0x%08X", interrupt, channel, event_handle); | 225 | ASSERT(false); // TODO: This should really be handled at an IPC translation layer. |
| 170 | } else { | 226 | } |
| 171 | LOG_CRITICAL(Service_DSP, "Invalid event handle! interrupt=%u, channel=%u, event_handle=0x%08X", interrupt, channel, event_handle); | 227 | |
| 172 | ASSERT(false); // This should really be handled at a IPC translation layer. | 228 | if (interrupt_events.HasTooManyEventsRegistered()) { |
| 229 | LOG_INFO(Service_DSP, "Ran out of space to register interrupts (Attempted to register type=%u, pipe=%u, event_handle=0x%08X)", | ||
| 230 | type_index, pipe_index, event_handle); | ||
| 231 | cmd_buff[1] = ResultCode(ErrorDescription::InvalidResultValue, ErrorModule::DSP, ErrorSummary::OutOfResource, ErrorLevel::Status).raw; | ||
| 232 | return; | ||
| 173 | } | 233 | } |
| 234 | |||
| 235 | interrupt_events.Get(type, pipe) = evt; | ||
| 236 | LOG_INFO(Service_DSP, "Registered type=%u, pipe=%u, event_handle=0x%08X", type_index, pipe_index, event_handle); | ||
| 237 | cmd_buff[1] = RESULT_SUCCESS.raw; | ||
| 174 | } else { | 238 | } else { |
| 175 | interrupt_events.erase(std::make_pair(interrupt, channel)); | 239 | interrupt_events.Get(type, pipe) = nullptr; |
| 176 | LOG_INFO(Service_DSP, "Unregistered interrupt=%u, channel=%u, event_handle=0x%08X", interrupt, channel, event_handle); | 240 | LOG_INFO(Service_DSP, "Unregistered interrupt=%u, channel=%u, event_handle=0x%08X", type_index, pipe_index, event_handle); |
| 241 | cmd_buff[1] = RESULT_SUCCESS.raw; | ||
| 177 | } | 242 | } |
| 178 | } | 243 | } |
| 179 | 244 | ||
| @@ -187,6 +252,7 @@ static void RegisterInterruptEvents(Service::Interface* self) { | |||
| 187 | static void SetSemaphore(Service::Interface* self) { | 252 | static void SetSemaphore(Service::Interface* self) { |
| 188 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 253 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 189 | 254 | ||
| 255 | cmd_buff[0] = IPC::MakeHeader(0x7, 1, 0); | ||
| 190 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 256 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 191 | 257 | ||
| 192 | LOG_WARNING(Service_DSP, "(STUBBED) called"); | 258 | LOG_WARNING(Service_DSP, "(STUBBED) called"); |
| @@ -195,7 +261,7 @@ static void SetSemaphore(Service::Interface* self) { | |||
| 195 | /** | 261 | /** |
| 196 | * DSP_DSP::WriteProcessPipe service function | 262 | * DSP_DSP::WriteProcessPipe service function |
| 197 | * Inputs: | 263 | * Inputs: |
| 198 | * 1 : Channel | 264 | * 1 : Pipe Number |
| 199 | * 2 : Size | 265 | * 2 : Size |
| 200 | * 3 : (size << 14) | 0x402 | 266 | * 3 : (size << 14) | 0x402 |
| 201 | * 4 : Buffer | 267 | * 4 : Buffer |
| @@ -206,24 +272,32 @@ static void SetSemaphore(Service::Interface* self) { | |||
| 206 | static void WriteProcessPipe(Service::Interface* self) { | 272 | static void WriteProcessPipe(Service::Interface* self) { |
| 207 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 273 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 208 | 274 | ||
| 209 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); | 275 | u32 pipe_index = cmd_buff[1]; |
| 210 | u32 size = cmd_buff[2]; | 276 | u32 size = cmd_buff[2]; |
| 211 | u32 buffer = cmd_buff[4]; | 277 | u32 buffer = cmd_buff[4]; |
| 212 | 278 | ||
| 213 | ASSERT_MSG(IPC::StaticBufferDesc(size, 1) == cmd_buff[3], "IPC static buffer descriptor failed validation (0x%X). pipe=%u, size=0x%X, buffer=0x%08X", cmd_buff[3], pipe, size, buffer); | 279 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); |
| 214 | ASSERT_MSG(Memory::GetPointer(buffer) != nullptr, "Invalid Buffer: pipe=%u, size=0x%X, buffer=0x%08X", pipe, size, buffer); | ||
| 215 | 280 | ||
| 216 | std::vector<u8> message(size); | 281 | if (IPC::StaticBufferDesc(size, 1) != cmd_buff[3]) { |
| 282 | LOG_ERROR(Service_DSP, "IPC static buffer descriptor failed validation (0x%X). pipe=%u, size=0x%X, buffer=0x%08X", cmd_buff[3], pipe_index, size, buffer); | ||
| 283 | cmd_buff[0] = IPC::MakeHeader(0, 1, 0); | ||
| 284 | cmd_buff[1] = ResultCode(ErrorDescription::OS_InvalidBufferDescriptor, ErrorModule::OS, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; | ||
| 285 | return; | ||
| 286 | } | ||
| 287 | |||
| 288 | ASSERT_MSG(Memory::GetPointer(buffer) != nullptr, "Invalid Buffer: pipe=%u, size=0x%X, buffer=0x%08X", pipe_index, size, buffer); | ||
| 217 | 289 | ||
| 290 | std::vector<u8> message(size); | ||
| 218 | for (size_t i = 0; i < size; i++) { | 291 | for (size_t i = 0; i < size; i++) { |
| 219 | message[i] = Memory::Read8(buffer + i); | 292 | message[i] = Memory::Read8(buffer + i); |
| 220 | } | 293 | } |
| 221 | 294 | ||
| 222 | DSP::HLE::PipeWrite(pipe, message); | 295 | DSP::HLE::PipeWrite(pipe, message); |
| 223 | 296 | ||
| 297 | cmd_buff[0] = IPC::MakeHeader(0xD, 1, 0); | ||
| 224 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 298 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 225 | 299 | ||
| 226 | LOG_DEBUG(Service_DSP, "pipe=%u, size=0x%X, buffer=0x%08X", pipe, size, buffer); | 300 | LOG_DEBUG(Service_DSP, "pipe=%u, size=0x%X, buffer=0x%08X", pipe_index, size, buffer); |
| 227 | } | 301 | } |
| 228 | 302 | ||
| 229 | /** | 303 | /** |
| @@ -243,13 +317,16 @@ static void WriteProcessPipe(Service::Interface* self) { | |||
| 243 | static void ReadPipeIfPossible(Service::Interface* self) { | 317 | static void ReadPipeIfPossible(Service::Interface* self) { |
| 244 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 318 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 245 | 319 | ||
| 246 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); | 320 | u32 pipe_index = cmd_buff[1]; |
| 247 | u32 unknown = cmd_buff[2]; | 321 | u32 unknown = cmd_buff[2]; |
| 248 | u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size | 322 | u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size |
| 249 | VAddr addr = cmd_buff[0x41]; | 323 | VAddr addr = cmd_buff[0x41]; |
| 250 | 324 | ||
| 251 | ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe, unknown, size, addr); | 325 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); |
| 326 | |||
| 327 | ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=%u, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe_index, unknown, size, addr); | ||
| 252 | 328 | ||
| 329 | cmd_buff[0] = IPC::MakeHeader(0x10, 1, 2); | ||
| 253 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 330 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 254 | if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { | 331 | if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { |
| 255 | std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); | 332 | std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); |
| @@ -260,8 +337,10 @@ static void ReadPipeIfPossible(Service::Interface* self) { | |||
| 260 | } else { | 337 | } else { |
| 261 | cmd_buff[2] = 0; // Return no data | 338 | cmd_buff[2] = 0; // Return no data |
| 262 | } | 339 | } |
| 340 | cmd_buff[3] = IPC::StaticBufferDesc(size, 0); | ||
| 341 | cmd_buff[4] = addr; | ||
| 263 | 342 | ||
| 264 | LOG_DEBUG(Service_DSP, "pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X, return cmd_buff[2]=0x%08X", pipe, unknown, size, addr, cmd_buff[2]); | 343 | LOG_DEBUG(Service_DSP, "pipe=%u, unknown=0x%08X, size=0x%X, buffer=0x%08X, return cmd_buff[2]=0x%08X", pipe_index, unknown, size, addr, cmd_buff[2]); |
| 265 | } | 344 | } |
| 266 | 345 | ||
| 267 | /** | 346 | /** |
| @@ -278,26 +357,31 @@ static void ReadPipeIfPossible(Service::Interface* self) { | |||
| 278 | static void ReadPipe(Service::Interface* self) { | 357 | static void ReadPipe(Service::Interface* self) { |
| 279 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 358 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 280 | 359 | ||
| 281 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); | 360 | u32 pipe_index = cmd_buff[1]; |
| 282 | u32 unknown = cmd_buff[2]; | 361 | u32 unknown = cmd_buff[2]; |
| 283 | u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size | 362 | u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size |
| 284 | VAddr addr = cmd_buff[0x41]; | 363 | VAddr addr = cmd_buff[0x41]; |
| 285 | 364 | ||
| 286 | ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe, unknown, size, addr); | 365 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); |
| 366 | |||
| 367 | ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=%u, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe_index, unknown, size, addr); | ||
| 287 | 368 | ||
| 288 | if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { | 369 | if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { |
| 289 | std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); | 370 | std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); |
| 290 | 371 | ||
| 291 | Memory::WriteBlock(addr, response.data(), response.size()); | 372 | Memory::WriteBlock(addr, response.data(), response.size()); |
| 292 | 373 | ||
| 374 | cmd_buff[0] = IPC::MakeHeader(0xE, 2, 2); | ||
| 293 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 375 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 294 | cmd_buff[2] = static_cast<u32>(response.size()); | 376 | cmd_buff[2] = static_cast<u32>(response.size()); |
| 377 | cmd_buff[3] = IPC::StaticBufferDesc(size, 0); | ||
| 378 | cmd_buff[4] = addr; | ||
| 295 | } else { | 379 | } else { |
| 296 | // No more data is in pipe. Hardware hangs in this case; this should never happen. | 380 | // No more data is in pipe. Hardware hangs in this case; this should never happen. |
| 297 | UNREACHABLE(); | 381 | UNREACHABLE(); |
| 298 | } | 382 | } |
| 299 | 383 | ||
| 300 | LOG_DEBUG(Service_DSP, "pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X, return cmd_buff[2]=0x%08X", pipe, unknown, size, addr, cmd_buff[2]); | 384 | LOG_DEBUG(Service_DSP, "pipe=%u, unknown=0x%08X, size=0x%X, buffer=0x%08X, return cmd_buff[2]=0x%08X", pipe_index, unknown, size, addr, cmd_buff[2]); |
| 301 | } | 385 | } |
| 302 | 386 | ||
| 303 | /** | 387 | /** |
| @@ -312,13 +396,16 @@ static void ReadPipe(Service::Interface* self) { | |||
| 312 | static void GetPipeReadableSize(Service::Interface* self) { | 396 | static void GetPipeReadableSize(Service::Interface* self) { |
| 313 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 397 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 314 | 398 | ||
| 315 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); | 399 | u32 pipe_index = cmd_buff[1]; |
| 316 | u32 unknown = cmd_buff[2]; | 400 | u32 unknown = cmd_buff[2]; |
| 317 | 401 | ||
| 402 | DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); | ||
| 403 | |||
| 404 | cmd_buff[0] = IPC::MakeHeader(0xF, 2, 0); | ||
| 318 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 405 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 319 | cmd_buff[2] = DSP::HLE::GetPipeReadableSize(pipe); | 406 | cmd_buff[2] = DSP::HLE::GetPipeReadableSize(pipe); |
| 320 | 407 | ||
| 321 | LOG_DEBUG(Service_DSP, "pipe=0x%08X, unknown=0x%08X, return cmd_buff[2]=0x%08X", pipe, unknown, cmd_buff[2]); | 408 | LOG_DEBUG(Service_DSP, "pipe=%u, unknown=0x%08X, return cmd_buff[2]=0x%08X", pipe_index, unknown, cmd_buff[2]); |
| 322 | } | 409 | } |
| 323 | 410 | ||
| 324 | /** | 411 | /** |
| @@ -333,6 +420,7 @@ static void SetSemaphoreMask(Service::Interface* self) { | |||
| 333 | 420 | ||
| 334 | u32 mask = cmd_buff[1]; | 421 | u32 mask = cmd_buff[1]; |
| 335 | 422 | ||
| 423 | cmd_buff[0] = IPC::MakeHeader(0x17, 1, 0); | ||
| 336 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 424 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 337 | 425 | ||
| 338 | LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x%08X", mask); | 426 | LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x%08X", mask); |
| @@ -350,6 +438,7 @@ static void SetSemaphoreMask(Service::Interface* self) { | |||
| 350 | static void GetHeadphoneStatus(Service::Interface* self) { | 438 | static void GetHeadphoneStatus(Service::Interface* self) { |
| 351 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 439 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 352 | 440 | ||
| 441 | cmd_buff[0] = IPC::MakeHeader(0x1F, 2, 0); | ||
| 353 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 442 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 354 | cmd_buff[2] = 0; // Not using headphones? | 443 | cmd_buff[2] = 0; // Not using headphones? |
| 355 | 444 | ||
| @@ -376,6 +465,7 @@ static void RecvData(Service::Interface* self) { | |||
| 376 | 465 | ||
| 377 | // Application reads this after requesting DSP shutdown, to verify the DSP has indeed shutdown or slept. | 466 | // Application reads this after requesting DSP shutdown, to verify the DSP has indeed shutdown or slept. |
| 378 | 467 | ||
| 468 | cmd_buff[0] = IPC::MakeHeader(0x1, 2, 0); | ||
| 379 | cmd_buff[1] = RESULT_SUCCESS.raw; | 469 | cmd_buff[1] = RESULT_SUCCESS.raw; |
| 380 | switch (DSP::HLE::GetDspState()) { | 470 | switch (DSP::HLE::GetDspState()) { |
| 381 | case DSP::HLE::DspState::On: | 471 | case DSP::HLE::DspState::On: |
| @@ -411,6 +501,7 @@ static void RecvDataIsReady(Service::Interface* self) { | |||
| 411 | 501 | ||
| 412 | ASSERT_MSG(register_number == 0, "Unknown register_number %u", register_number); | 502 | ASSERT_MSG(register_number == 0, "Unknown register_number %u", register_number); |
| 413 | 503 | ||
| 504 | cmd_buff[0] = IPC::MakeHeader(0x2, 2, 0); | ||
| 414 | cmd_buff[1] = RESULT_SUCCESS.raw; | 505 | cmd_buff[1] = RESULT_SUCCESS.raw; |
| 415 | cmd_buff[2] = 1; // Ready to read | 506 | cmd_buff[2] = 1; // Ready to read |
| 416 | 507 | ||
| @@ -458,14 +549,14 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 458 | 549 | ||
| 459 | Interface::Interface() { | 550 | Interface::Interface() { |
| 460 | semaphore_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event"); | 551 | semaphore_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event"); |
| 461 | read_pipe_count = 0; | 552 | interrupt_events = {}; |
| 462 | 553 | ||
| 463 | Register(FunctionTable); | 554 | Register(FunctionTable); |
| 464 | } | 555 | } |
| 465 | 556 | ||
| 466 | Interface::~Interface() { | 557 | Interface::~Interface() { |
| 467 | semaphore_event = nullptr; | 558 | semaphore_event = nullptr; |
| 468 | interrupt_events.clear(); | 559 | interrupt_events = {}; |
| 469 | } | 560 | } |
| 470 | 561 | ||
| 471 | } // namespace | 562 | } // namespace |
diff --git a/src/core/hle/service/dsp_dsp.h b/src/core/hle/service/dsp_dsp.h index 32b89e9bb..22f6687cc 100644 --- a/src/core/hle/service/dsp_dsp.h +++ b/src/core/hle/service/dsp_dsp.h | |||
| @@ -8,6 +8,12 @@ | |||
| 8 | 8 | ||
| 9 | #include "core/hle/service/service.h" | 9 | #include "core/hle/service/service.h" |
| 10 | 10 | ||
| 11 | namespace DSP { | ||
| 12 | namespace HLE { | ||
| 13 | enum class DspPipe; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 12 | // Namespace DSP_DSP | 18 | // Namespace DSP_DSP |
| 13 | 19 | ||
| @@ -23,15 +29,10 @@ public: | |||
| 23 | } | 29 | } |
| 24 | }; | 30 | }; |
| 25 | 31 | ||
| 26 | /// Signal all audio related interrupts. | ||
| 27 | void SignalAllInterrupts(); | ||
| 28 | |||
| 29 | /** | 32 | /** |
| 30 | * Signal a specific audio related interrupt based on interrupt id and channel id. | 33 | * Signal a specific DSP related interrupt of type == InterruptType::Pipe, pipe == pipe. |
| 31 | * @param interrupt_id The interrupt id | 34 | * @param pipe The DSP pipe for which to signal an interrupt for. |
| 32 | * @param channel_id The channel id | ||
| 33 | * The significance of various values of interrupt_id and channel_id is not yet known. | ||
| 34 | */ | 35 | */ |
| 35 | void SignalInterrupt(u32 interrupt_id, u32 channel_id); | 36 | void SignalPipeInterrupt(DSP::HLE::DspPipe pipe); |
| 36 | 37 | ||
| 37 | } // namespace | 38 | } // namespace DSP_DSP |