mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	
						commit
						1ecee38468
					
				
					 6 changed files with 180 additions and 76 deletions
				
			
		|  | @ -4,6 +4,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "audio_core/audio_core.h" | #include "audio_core/audio_core.h" | ||||||
| #include "audio_core/hle/dsp.h" | #include "audio_core/hle/dsp.h" | ||||||
|  | #include "audio_core/hle/pipe.h" | ||||||
| 
 | 
 | ||||||
| #include "core/core_timing.h" | #include "core/core_timing.h" | ||||||
| #include "core/hle/kernel/vm_manager.h" | #include "core/hle/kernel/vm_manager.h" | ||||||
|  | @ -17,10 +18,10 @@ static constexpr u64 audio_frame_ticks = 1310252ull; ///< Units: ARM11 cycles | ||||||
| 
 | 
 | ||||||
| static void AudioTickCallback(u64 /*userdata*/, int cycles_late) { | static void AudioTickCallback(u64 /*userdata*/, int cycles_late) { | ||||||
|     if (DSP::HLE::Tick()) { |     if (DSP::HLE::Tick()) { | ||||||
|         // HACK: We're not signaling the interrups when they should be, but just firing them all off together.
 |         // TODO(merry): Signal all the other interrupts as appropriate.
 | ||||||
|         // It should be only (interrupt_id = 2, channel_id = 2) that's signalled here.
 |         DSP_DSP::SignalPipeInterrupt(DSP::HLE::DspPipe::Audio); | ||||||
|         // TODO(merry): Understand when the other interrupts are fired.
 |         // HACK(merry): Added to prevent regressions. Will remove soon.
 | ||||||
|         DSP_DSP::SignalAllInterrupts(); |         DSP_DSP::SignalPipeInterrupt(DSP::HLE::DspPipe::Binary); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Reschedule recurrent event
 |     // Reschedule recurrent event
 | ||||||
|  |  | ||||||
|  | @ -12,12 +12,14 @@ | ||||||
| #include "common/common_types.h" | #include "common/common_types.h" | ||||||
| #include "common/logging/log.h" | #include "common/logging/log.h" | ||||||
| 
 | 
 | ||||||
|  | #include "core/hle/service/dsp_dsp.h" | ||||||
|  | 
 | ||||||
| namespace DSP { | namespace DSP { | ||||||
| namespace HLE { | namespace HLE { | ||||||
| 
 | 
 | ||||||
| static DspState dsp_state = DspState::Off; | static DspState dsp_state = DspState::Off; | ||||||
| 
 | 
 | ||||||
| static std::array<std::vector<u8>, static_cast<size_t>(DspPipe::DspPipe_MAX)> pipe_data; | static std::array<std::vector<u8>, NUM_DSP_PIPE> pipe_data; | ||||||
| 
 | 
 | ||||||
| void ResetPipes() { | void ResetPipes() { | ||||||
|     for (auto& data : pipe_data) { |     for (auto& data : pipe_data) { | ||||||
|  | @ -27,16 +29,18 @@ void ResetPipes() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { | std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { | ||||||
|     if (pipe_number >= DspPipe::DspPipe_MAX) { |     const size_t pipe_index = static_cast<size_t>(pipe_number); | ||||||
|         LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); | 
 | ||||||
|  |     if (pipe_index >= NUM_DSP_PIPE) { | ||||||
|  |         LOG_ERROR(Audio_DSP, "pipe_number = %zu invalid", pipe_index); | ||||||
|         return {}; |         return {}; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; |     std::vector<u8>& data = pipe_data[pipe_index]; | ||||||
| 
 | 
 | ||||||
|     if (length > data.size()) { |     if (length > data.size()) { | ||||||
|         LOG_WARNING(Audio_DSP, "pipe_number = %u is out of data, application requested read of %u but %zu remain", |         LOG_WARNING(Audio_DSP, "pipe_number = %zu is out of data, application requested read of %u but %zu remain", | ||||||
|                     pipe_number, length, data.size()); |                     pipe_index, length, data.size()); | ||||||
|         length = data.size(); |         length = data.size(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -49,16 +53,20 @@ std::vector<u8> PipeRead(DspPipe pipe_number, u32 length) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| size_t GetPipeReadableSize(DspPipe pipe_number) { | size_t GetPipeReadableSize(DspPipe pipe_number) { | ||||||
|     if (pipe_number >= DspPipe::DspPipe_MAX) { |     const size_t pipe_index = static_cast<size_t>(pipe_number); | ||||||
|         LOG_ERROR(Audio_DSP, "pipe_number = %u invalid", pipe_number); | 
 | ||||||
|  |     if (pipe_index >= NUM_DSP_PIPE) { | ||||||
|  |         LOG_ERROR(Audio_DSP, "pipe_number = %zu invalid", pipe_index); | ||||||
|         return 0; |         return 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return pipe_data[static_cast<size_t>(pipe_number)].size(); |     return pipe_data[pipe_index].size(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void WriteU16(DspPipe pipe_number, u16 value) { | static void WriteU16(DspPipe pipe_number, u16 value) { | ||||||
|     std::vector<u8>& data = pipe_data[static_cast<size_t>(pipe_number)]; |     const size_t pipe_index = static_cast<size_t>(pipe_number); | ||||||
|  | 
 | ||||||
|  |     std::vector<u8>& data = pipe_data.at(pipe_index); | ||||||
|     // Little endian
 |     // Little endian
 | ||||||
|     data.emplace_back(value & 0xFF); |     data.emplace_back(value & 0xFF); | ||||||
|     data.emplace_back(value >> 8); |     data.emplace_back(value >> 8); | ||||||
|  | @ -91,6 +99,8 @@ static void AudioPipeWriteStructAddresses() { | ||||||
|     for (u16 addr : struct_addresses) { |     for (u16 addr : struct_addresses) { | ||||||
|         WriteU16(DspPipe::Audio, addr); |         WriteU16(DspPipe::Audio, addr); | ||||||
|     } |     } | ||||||
|  |     // Signal that we have data on this pipe.
 | ||||||
|  |     DSP_DSP::SignalPipeInterrupt(DspPipe::Audio); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { | void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { | ||||||
|  | @ -145,7 +155,7 @@ void PipeWrite(DspPipe pipe_number, const std::vector<u8>& buffer) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     default: |     default: | ||||||
|         LOG_CRITICAL(Audio_DSP, "pipe_number = %u unimplemented", pipe_number); |         LOG_CRITICAL(Audio_DSP, "pipe_number = %zu unimplemented", static_cast<size_t>(pipe_number)); | ||||||
|         UNIMPLEMENTED(); |         UNIMPLEMENTED(); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -19,9 +19,9 @@ enum class DspPipe { | ||||||
|     Debug = 0, |     Debug = 0, | ||||||
|     Dma = 1, |     Dma = 1, | ||||||
|     Audio = 2, |     Audio = 2, | ||||||
|     Binary = 3, |     Binary = 3 | ||||||
|     DspPipe_MAX |  | ||||||
| }; | }; | ||||||
|  | constexpr size_t NUM_DSP_PIPE = 8; | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Read a DSP pipe. |  * Read a DSP pipe. | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ | ||||||
| /// Detailed description of the error. This listing is likely incomplete.
 | /// Detailed description of the error. This listing is likely incomplete.
 | ||||||
| enum class ErrorDescription : u32 { | enum class ErrorDescription : u32 { | ||||||
|     Success = 0, |     Success = 0, | ||||||
|  |     OS_InvalidBufferDescriptor = 48, | ||||||
|     WrongAddress = 53, |     WrongAddress = 53, | ||||||
|     FS_NotFound = 120, |     FS_NotFound = 120, | ||||||
|     FS_AlreadyExists = 190, |     FS_AlreadyExists = 190, | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| // Licensed under GPLv2 or any later version
 | // Licensed under GPLv2 or any later version
 | ||||||
| // Refer to the license.txt file included.
 | // Refer to the license.txt file included.
 | ||||||
| 
 | 
 | ||||||
|  | #include <algorithm> | ||||||
| #include <cinttypes> | #include <cinttypes> | ||||||
| 
 | 
 | ||||||
| #include "audio_core/hle/pipe.h" | #include "audio_core/hle/pipe.h" | ||||||
|  | @ -12,37 +13,80 @@ | ||||||
| #include "core/hle/kernel/event.h" | #include "core/hle/kernel/event.h" | ||||||
| #include "core/hle/service/dsp_dsp.h" | #include "core/hle/service/dsp_dsp.h" | ||||||
| 
 | 
 | ||||||
|  | using DspPipe = DSP::HLE::DspPipe; | ||||||
|  | 
 | ||||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////
 | ////////////////////////////////////////////////////////////////////////////////////////////////////
 | ||||||
| // Namespace DSP_DSP
 | // Namespace DSP_DSP
 | ||||||
| 
 | 
 | ||||||
| namespace DSP_DSP { | namespace DSP_DSP { | ||||||
| 
 | 
 | ||||||
| static u32 read_pipe_count; |  | ||||||
| static Kernel::SharedPtr<Kernel::Event> semaphore_event; | static Kernel::SharedPtr<Kernel::Event> semaphore_event; | ||||||
| 
 | 
 | ||||||
| struct PairHash { | /// There are three types of interrupts
 | ||||||
|     template <typename T, typename U> | enum class InterruptType { | ||||||
|     std::size_t operator()(const std::pair<T, U> &x) const { |     Zero, One, Pipe | ||||||
|         // TODO(yuriks): Replace with better hash combining function.
 | }; | ||||||
|         return std::hash<T>()(x.first) ^ std::hash<U>()(x.second); | constexpr size_t NUM_INTERRUPT_TYPE = 3; | ||||||
|  | 
 | ||||||
|  | class InterruptEvents final { | ||||||
|  | public: | ||||||
|  |     void Signal(InterruptType type, DspPipe pipe) { | ||||||
|  |         Kernel::SharedPtr<Kernel::Event>& event = Get(type, pipe); | ||||||
|  |         if (event) { | ||||||
|  |             event->Signal(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     Kernel::SharedPtr<Kernel::Event>& Get(InterruptType type, DspPipe dsp_pipe) { | ||||||
|  |         switch (type) { | ||||||
|  |         case InterruptType::Zero: | ||||||
|  |             return zero; | ||||||
|  |         case InterruptType::One: | ||||||
|  |             return one; | ||||||
|  |         case InterruptType::Pipe: { | ||||||
|  |             const size_t pipe_index = static_cast<size_t>(dsp_pipe); | ||||||
|  |             ASSERT(pipe_index < DSP::HLE::NUM_DSP_PIPE); | ||||||
|  |             return pipe[pipe_index]; | ||||||
|  |         } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         UNREACHABLE_MSG("Invalid interrupt type = %zu", static_cast<size_t>(type)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     bool HasTooManyEventsRegistered() const { | ||||||
|  |         // Actual service implementation only has 6 'slots' for interrupts.
 | ||||||
|  |         constexpr size_t max_number_of_interrupt_events = 6; | ||||||
|  | 
 | ||||||
|  |         size_t number = std::count_if(pipe.begin(), pipe.end(), [](const auto& evt) { | ||||||
|  |             return evt != nullptr; | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         if (zero != nullptr) | ||||||
|  |             number++; | ||||||
|  |         if (one != nullptr) | ||||||
|  |             number++; | ||||||
|  | 
 | ||||||
|  |         return number >= max_number_of_interrupt_events; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |     /// Currently unknown purpose
 | ||||||
|  |     Kernel::SharedPtr<Kernel::Event> zero = nullptr; | ||||||
|  |     /// Currently unknown purpose
 | ||||||
|  |     Kernel::SharedPtr<Kernel::Event> one = nullptr; | ||||||
|  |     /// Each DSP pipe has an associated interrupt
 | ||||||
|  |     std::array<Kernel::SharedPtr<Kernel::Event>, DSP::HLE::NUM_DSP_PIPE> pipe = {{}}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /// Map of (audio interrupt number, channel number) to Kernel::Events. See: RegisterInterruptEvents
 | static InterruptEvents interrupt_events; | ||||||
| static std::unordered_map<std::pair<u32, u32>, Kernel::SharedPtr<Kernel::Event>, PairHash> interrupt_events; |  | ||||||
| 
 | 
 | ||||||
| // DSP Interrupts:
 | // DSP Interrupts:
 | ||||||
| // Interrupt #2 occurs every frame tick. Userland programs normally have a thread that's waiting
 | // The audio-pipe interrupt occurs every frame tick. Userland programs normally have a thread
 | ||||||
| // for an interrupt event. Immediately after this interrupt event, userland normally updates the
 | // that's waiting for an interrupt event. Immediately after this interrupt event, userland
 | ||||||
| // state in the next region and increments the relevant frame counter by two.
 | // normally updates the state in the next region and increments the relevant frame counter by
 | ||||||
| void SignalAllInterrupts() { | // two.
 | ||||||
|     // HACK: The other interrupts have currently unknown purpose, we trigger them each tick in any case.
 | void SignalPipeInterrupt(DspPipe pipe) { | ||||||
|     for (auto& interrupt_event : interrupt_events) |     interrupt_events.Signal(InterruptType::Pipe, pipe); | ||||||
|         interrupt_event.second->Signal(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void SignalInterrupt(u32 interrupt, u32 channel) { |  | ||||||
|     interrupt_events[std::make_pair(interrupt, channel)]->Signal(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | @ -58,7 +102,10 @@ static void ConvertProcessAddressFromDspDram(Service::Interface* self) { | ||||||
| 
 | 
 | ||||||
|     u32 addr = cmd_buff[1]; |     u32 addr = cmd_buff[1]; | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0xC, 2, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  | 
 | ||||||
|  |     // TODO(merry): There is a per-region offset missing in this calculation (that seems to be always zero).
 | ||||||
|     cmd_buff[2] = (addr << 1) + (Memory::DSP_RAM_VADDR + 0x40000); |     cmd_buff[2] = (addr << 1) + (Memory::DSP_RAM_VADDR + 0x40000); | ||||||
| 
 | 
 | ||||||
|     LOG_DEBUG(Service_DSP, "addr=0x%08X", addr); |     LOG_DEBUG(Service_DSP, "addr=0x%08X", addr); | ||||||
|  | @ -113,7 +160,9 @@ static void LoadComponent(Service::Interface* self) { | ||||||
| static void GetSemaphoreEventHandle(Service::Interface* self) { | static void GetSemaphoreEventHandle(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x16, 1, 2); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|  |     // cmd_buff[2] not set
 | ||||||
|     cmd_buff[3] = Kernel::g_handle_table.Create(semaphore_event).MoveFrom(); // Event handle
 |     cmd_buff[3] = Kernel::g_handle_table.Create(semaphore_event).MoveFrom(); // Event handle
 | ||||||
| 
 | 
 | ||||||
|     LOG_WARNING(Service_DSP, "(STUBBED) called"); |     LOG_WARNING(Service_DSP, "(STUBBED) called"); | ||||||
|  | @ -138,8 +187,7 @@ static void FlushDataCache(Service::Interface* self) { | ||||||
|     u32 size    = cmd_buff[2]; |     u32 size    = cmd_buff[2]; | ||||||
|     u32 process = cmd_buff[4]; |     u32 process = cmd_buff[4]; | ||||||
| 
 | 
 | ||||||
|     // TODO(purpasmart96): Verify return header on HW
 |     cmd_buff[0] = IPC::MakeHeader(0x13, 1, 0); | ||||||
| 
 |  | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
| 
 | 
 | ||||||
|     LOG_TRACE(Service_DSP, "called address=0x%08X, size=0x%X, process=0x%08X", address, size, process); |     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) { | ||||||
| /**
 | /**
 | ||||||
|  * DSP_DSP::RegisterInterruptEvents service function |  * DSP_DSP::RegisterInterruptEvents service function | ||||||
|  *  Inputs: |  *  Inputs: | ||||||
|  *      1 : Interrupt Number |  *      1 : Interrupt Type | ||||||
|  *      2 : Channel Number |  *      2 : Pipe Number | ||||||
|  *      4 : Interrupt event handle |  *      4 : Interrupt event handle | ||||||
|  *  Outputs: |  *  Outputs: | ||||||
|  *      1 : Result of function, 0 on success, otherwise error code |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  | @ -157,23 +205,40 @@ static void FlushDataCache(Service::Interface* self) { | ||||||
| static void RegisterInterruptEvents(Service::Interface* self) { | static void RegisterInterruptEvents(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|     u32 interrupt = cmd_buff[1]; |     u32 type_index = cmd_buff[1]; | ||||||
|     u32 channel = cmd_buff[2]; |     u32 pipe_index = cmd_buff[2]; | ||||||
|     u32 event_handle = cmd_buff[4]; |     u32 event_handle = cmd_buff[4]; | ||||||
| 
 | 
 | ||||||
|  |     ASSERT_MSG(type_index < NUM_INTERRUPT_TYPE && pipe_index < DSP::HLE::NUM_DSP_PIPE, | ||||||
|  |                "Invalid type or pipe: type = %u, pipe = %u", type_index, pipe_index); | ||||||
|  | 
 | ||||||
|  |     InterruptType type = static_cast<InterruptType>(cmd_buff[1]); | ||||||
|  |     DspPipe pipe = static_cast<DspPipe>(cmd_buff[2]); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x15, 1, 0); | ||||||
|  | 
 | ||||||
|     if (event_handle) { |     if (event_handle) { | ||||||
|         auto evt = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]); |         auto evt = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]); | ||||||
|         if (evt) { | 
 | ||||||
|             interrupt_events[std::make_pair(interrupt, channel)] = evt; |         if (!evt) { | ||||||
|             cmd_buff[1] = RESULT_SUCCESS.raw; |             LOG_INFO(Service_DSP, "Invalid event handle! type=%u, pipe=%u, event_handle=0x%08X", type_index, pipe_index, event_handle); | ||||||
|             LOG_INFO(Service_DSP, "Registered interrupt=%u, channel=%u, event_handle=0x%08X", interrupt, channel, event_handle); |             ASSERT(false); // TODO: This should really be handled at an IPC translation layer.
 | ||||||
|         } else { |  | ||||||
|             LOG_CRITICAL(Service_DSP, "Invalid event handle! interrupt=%u, channel=%u, event_handle=0x%08X", interrupt, channel, event_handle); |  | ||||||
|             ASSERT(false); // This should really be handled at a IPC translation layer.
 |  | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         if (interrupt_events.HasTooManyEventsRegistered()) { | ||||||
|  |             LOG_INFO(Service_DSP, "Ran out of space to register interrupts (Attempted to register type=%u, pipe=%u, event_handle=0x%08X)", | ||||||
|  |                      type_index, pipe_index, event_handle); | ||||||
|  |             cmd_buff[1] = ResultCode(ErrorDescription::InvalidResultValue, ErrorModule::DSP, ErrorSummary::OutOfResource, ErrorLevel::Status).raw; | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         interrupt_events.Get(type, pipe) = evt; | ||||||
|  |         LOG_INFO(Service_DSP, "Registered type=%u, pipe=%u, event_handle=0x%08X", type_index, pipe_index, event_handle); | ||||||
|  |         cmd_buff[1] = RESULT_SUCCESS.raw; | ||||||
|     } else { |     } else { | ||||||
|         interrupt_events.erase(std::make_pair(interrupt, channel)); |         interrupt_events.Get(type, pipe) = nullptr; | ||||||
|         LOG_INFO(Service_DSP, "Unregistered interrupt=%u, channel=%u, event_handle=0x%08X", interrupt, channel, event_handle); |         LOG_INFO(Service_DSP, "Unregistered interrupt=%u, channel=%u, event_handle=0x%08X", type_index, pipe_index, event_handle); | ||||||
|  |         cmd_buff[1] = RESULT_SUCCESS.raw; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -187,6 +252,7 @@ static void RegisterInterruptEvents(Service::Interface* self) { | ||||||
| static void SetSemaphore(Service::Interface* self) { | static void SetSemaphore(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x7, 1, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
| 
 | 
 | ||||||
|     LOG_WARNING(Service_DSP, "(STUBBED) called"); |     LOG_WARNING(Service_DSP, "(STUBBED) called"); | ||||||
|  | @ -195,7 +261,7 @@ static void SetSemaphore(Service::Interface* self) { | ||||||
| /**
 | /**
 | ||||||
|  * DSP_DSP::WriteProcessPipe service function |  * DSP_DSP::WriteProcessPipe service function | ||||||
|  *  Inputs: |  *  Inputs: | ||||||
|  *      1 : Channel |  *      1 : Pipe Number | ||||||
|  *      2 : Size |  *      2 : Size | ||||||
|  *      3 : (size << 14) | 0x402 |  *      3 : (size << 14) | 0x402 | ||||||
|  *      4 : Buffer |  *      4 : Buffer | ||||||
|  | @ -206,24 +272,32 @@ static void SetSemaphore(Service::Interface* self) { | ||||||
| static void WriteProcessPipe(Service::Interface* self) { | static void WriteProcessPipe(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); |     u32 pipe_index = cmd_buff[1]; | ||||||
|     u32 size = cmd_buff[2]; |     u32 size = cmd_buff[2]; | ||||||
|     u32 buffer = cmd_buff[4]; |     u32 buffer = cmd_buff[4]; | ||||||
| 
 | 
 | ||||||
|     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); |     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); | ||||||
|     ASSERT_MSG(Memory::GetPointer(buffer) != nullptr, "Invalid Buffer: pipe=%u, size=0x%X, buffer=0x%08X", pipe, size, buffer); | 
 | ||||||
|  |     if (IPC::StaticBufferDesc(size, 1) != cmd_buff[3]) { | ||||||
|  |         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); | ||||||
|  |         cmd_buff[0] = IPC::MakeHeader(0, 1, 0); | ||||||
|  |         cmd_buff[1] = ResultCode(ErrorDescription::OS_InvalidBufferDescriptor, ErrorModule::OS, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     ASSERT_MSG(Memory::GetPointer(buffer) != nullptr, "Invalid Buffer: pipe=%u, size=0x%X, buffer=0x%08X", pipe_index, size, buffer); | ||||||
| 
 | 
 | ||||||
|     std::vector<u8> message(size); |     std::vector<u8> message(size); | ||||||
| 
 |  | ||||||
|     for (size_t i = 0; i < size; i++) { |     for (size_t i = 0; i < size; i++) { | ||||||
|         message[i] = Memory::Read8(buffer + i); |         message[i] = Memory::Read8(buffer + i); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     DSP::HLE::PipeWrite(pipe, message); |     DSP::HLE::PipeWrite(pipe, message); | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0xD, 1, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
| 
 | 
 | ||||||
|     LOG_DEBUG(Service_DSP, "pipe=%u, size=0x%X, buffer=0x%08X", pipe, size, buffer); |     LOG_DEBUG(Service_DSP, "pipe=%u, size=0x%X, buffer=0x%08X", pipe_index, size, buffer); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | @ -243,13 +317,16 @@ static void WriteProcessPipe(Service::Interface* self) { | ||||||
| static void ReadPipeIfPossible(Service::Interface* self) { | static void ReadPipeIfPossible(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); |     u32 pipe_index = cmd_buff[1]; | ||||||
|     u32 unknown = cmd_buff[2]; |     u32 unknown = cmd_buff[2]; | ||||||
|     u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
 |     u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
 | ||||||
|     VAddr addr = cmd_buff[0x41]; |     VAddr addr = cmd_buff[0x41]; | ||||||
| 
 | 
 | ||||||
|     ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe, unknown, size, addr); |     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); | ||||||
| 
 | 
 | ||||||
|  |     ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=%u, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe_index, unknown, size, addr); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x10, 1, 2); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|     if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { |     if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { | ||||||
|         std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); |         std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); | ||||||
|  | @ -260,8 +337,10 @@ static void ReadPipeIfPossible(Service::Interface* self) { | ||||||
|     } else { |     } else { | ||||||
|         cmd_buff[2] = 0; // Return no data
 |         cmd_buff[2] = 0; // Return no data
 | ||||||
|     } |     } | ||||||
|  |     cmd_buff[3] = IPC::StaticBufferDesc(size, 0); | ||||||
|  |     cmd_buff[4] = addr; | ||||||
| 
 | 
 | ||||||
|     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]); |     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]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | @ -278,26 +357,31 @@ static void ReadPipeIfPossible(Service::Interface* self) { | ||||||
| static void ReadPipe(Service::Interface* self) { | static void ReadPipe(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); |     u32 pipe_index = cmd_buff[1]; | ||||||
|     u32 unknown = cmd_buff[2]; |     u32 unknown = cmd_buff[2]; | ||||||
|     u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
 |     u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
 | ||||||
|     VAddr addr = cmd_buff[0x41]; |     VAddr addr = cmd_buff[0x41]; | ||||||
| 
 | 
 | ||||||
|     ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe, unknown, size, addr); |     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); | ||||||
|  | 
 | ||||||
|  |     ASSERT_MSG(Memory::GetPointer(addr) != nullptr, "Invalid addr: pipe=%u, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe_index, unknown, size, addr); | ||||||
| 
 | 
 | ||||||
|     if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { |     if (DSP::HLE::GetPipeReadableSize(pipe) >= size) { | ||||||
|         std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); |         std::vector<u8> response = DSP::HLE::PipeRead(pipe, size); | ||||||
| 
 | 
 | ||||||
|         Memory::WriteBlock(addr, response.data(), response.size()); |         Memory::WriteBlock(addr, response.data(), response.size()); | ||||||
| 
 | 
 | ||||||
|  |         cmd_buff[0] = IPC::MakeHeader(0xE, 2, 2); | ||||||
|         cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |         cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|         cmd_buff[2] = static_cast<u32>(response.size()); |         cmd_buff[2] = static_cast<u32>(response.size()); | ||||||
|  |         cmd_buff[3] = IPC::StaticBufferDesc(size, 0); | ||||||
|  |         cmd_buff[4] = addr; | ||||||
|     } else { |     } else { | ||||||
|         // No more data is in pipe. Hardware hangs in this case; this should never happen.
 |         // No more data is in pipe. Hardware hangs in this case; this should never happen.
 | ||||||
|         UNREACHABLE(); |         UNREACHABLE(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     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]); |     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]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | @ -312,13 +396,16 @@ static void ReadPipe(Service::Interface* self) { | ||||||
| static void GetPipeReadableSize(Service::Interface* self) { | static void GetPipeReadableSize(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(cmd_buff[1]); |     u32 pipe_index = cmd_buff[1]; | ||||||
|     u32 unknown = cmd_buff[2]; |     u32 unknown = cmd_buff[2]; | ||||||
| 
 | 
 | ||||||
|  |     DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0xF, 2, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|     cmd_buff[2] = DSP::HLE::GetPipeReadableSize(pipe); |     cmd_buff[2] = DSP::HLE::GetPipeReadableSize(pipe); | ||||||
| 
 | 
 | ||||||
|     LOG_DEBUG(Service_DSP, "pipe=0x%08X, unknown=0x%08X, return cmd_buff[2]=0x%08X", pipe, unknown, cmd_buff[2]); |     LOG_DEBUG(Service_DSP, "pipe=%u, unknown=0x%08X, return cmd_buff[2]=0x%08X", pipe_index, unknown, cmd_buff[2]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | @ -333,6 +420,7 @@ static void SetSemaphoreMask(Service::Interface* self) { | ||||||
| 
 | 
 | ||||||
|     u32 mask = cmd_buff[1]; |     u32 mask = cmd_buff[1]; | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x17, 1, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
| 
 | 
 | ||||||
|     LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x%08X", mask); |     LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x%08X", mask); | ||||||
|  | @ -350,6 +438,7 @@ static void SetSemaphoreMask(Service::Interface* self) { | ||||||
| static void GetHeadphoneStatus(Service::Interface* self) { | static void GetHeadphoneStatus(Service::Interface* self) { | ||||||
|     u32* cmd_buff = Kernel::GetCommandBuffer(); |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x1F, 2, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 |     cmd_buff[1] = RESULT_SUCCESS.raw; // No error
 | ||||||
|     cmd_buff[2] = 0; // Not using headphones?
 |     cmd_buff[2] = 0; // Not using headphones?
 | ||||||
| 
 | 
 | ||||||
|  | @ -376,6 +465,7 @@ static void RecvData(Service::Interface* self) { | ||||||
| 
 | 
 | ||||||
|     // Application reads this after requesting DSP shutdown, to verify the DSP has indeed shutdown or slept.
 |     // Application reads this after requesting DSP shutdown, to verify the DSP has indeed shutdown or slept.
 | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x1, 2, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; |     cmd_buff[1] = RESULT_SUCCESS.raw; | ||||||
|     switch (DSP::HLE::GetDspState()) { |     switch (DSP::HLE::GetDspState()) { | ||||||
|     case DSP::HLE::DspState::On: |     case DSP::HLE::DspState::On: | ||||||
|  | @ -411,6 +501,7 @@ static void RecvDataIsReady(Service::Interface* self) { | ||||||
| 
 | 
 | ||||||
|     ASSERT_MSG(register_number == 0, "Unknown register_number %u", register_number); |     ASSERT_MSG(register_number == 0, "Unknown register_number %u", register_number); | ||||||
| 
 | 
 | ||||||
|  |     cmd_buff[0] = IPC::MakeHeader(0x2, 2, 0); | ||||||
|     cmd_buff[1] = RESULT_SUCCESS.raw; |     cmd_buff[1] = RESULT_SUCCESS.raw; | ||||||
|     cmd_buff[2] = 1; // Ready to read
 |     cmd_buff[2] = 1; // Ready to read
 | ||||||
| 
 | 
 | ||||||
|  | @ -458,14 +549,14 @@ const Interface::FunctionInfo FunctionTable[] = { | ||||||
| 
 | 
 | ||||||
| Interface::Interface() { | Interface::Interface() { | ||||||
|     semaphore_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event"); |     semaphore_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event"); | ||||||
|     read_pipe_count = 0; |     interrupt_events = {}; | ||||||
| 
 | 
 | ||||||
|     Register(FunctionTable); |     Register(FunctionTable); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Interface::~Interface() { | Interface::~Interface() { | ||||||
|     semaphore_event = nullptr; |     semaphore_event = nullptr; | ||||||
|     interrupt_events.clear(); |     interrupt_events = {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } // namespace
 | } // namespace
 | ||||||
|  |  | ||||||
|  | @ -8,6 +8,12 @@ | ||||||
| 
 | 
 | ||||||
| #include "core/hle/service/service.h" | #include "core/hle/service/service.h" | ||||||
| 
 | 
 | ||||||
|  | namespace DSP { | ||||||
|  | namespace HLE { | ||||||
|  | enum class DspPipe; | ||||||
|  | } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////
 | ////////////////////////////////////////////////////////////////////////////////////////////////////
 | ||||||
| // Namespace DSP_DSP
 | // Namespace DSP_DSP
 | ||||||
| 
 | 
 | ||||||
|  | @ -23,15 +29,10 @@ public: | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /// Signal all audio related interrupts.
 |  | ||||||
| void SignalAllInterrupts(); |  | ||||||
| 
 |  | ||||||
| /**
 | /**
 | ||||||
|  * Signal a specific audio related interrupt based on interrupt id and channel id. |  * Signal a specific DSP related interrupt of type == InterruptType::Pipe, pipe == pipe. | ||||||
|  * @param interrupt_id The interrupt id |  * @param pipe The DSP pipe for which to signal an interrupt for. | ||||||
|  * @param channel_id The channel id |  | ||||||
|  * The significance of various values of interrupt_id and channel_id is not yet known. |  | ||||||
|  */ |  */ | ||||||
| void SignalInterrupt(u32 interrupt_id, u32 channel_id); | void SignalPipeInterrupt(DSP::HLE::DspPipe pipe); | ||||||
| 
 | 
 | ||||||
| } // namespace
 | } // namespace DSP_DSP
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue