|
|
@ -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
|
|
|
|