mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-02 08:25:07 +01:00
DSP_DSP: Updated interrupt implementation
This commit is contained in:
parent
555907ce8d
commit
ff6db69c60
@ -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,8 @@ 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.
|
|
||||||
DSP_DSP::SignalAllInterrupts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reschedule recurrent event
|
// Reschedule recurrent event
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#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 {
|
||||||
|
|
||||||
@ -97,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) {
|
||||||
|
@ -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,6 +13,8 @@
|
|||||||
#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
|
||||||
|
|
||||||
@ -19,29 +22,71 @@ namespace DSP_DSP {
|
|||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,8 +192,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
|
||||||
@ -156,23 +201,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +256,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
|
||||||
@ -457,13 +519,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");
|
||||||
|
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…
Reference in New Issue
Block a user