citra-emu
/
citra-canary
Archived
1
0
Fork 0

service/dsp: Migrate to ServiceFramework (#3915)

* service/dsp: Migrate to ServiceFramework

* service/dsp: Removed redundant buffer copy

* service/dsp: Addressed comment about pushing u32 instead of bool

* service/dsp: Fix clang format

* service/dsp: Addressed comment about minimizing global state

* service/dsp: Addressed comments and fixed log call issue

* service/dsp: Fix missed clang format
This commit is contained in:
NarcolepticK 2018-07-12 10:54:26 -04:00 committed by Weiyi Wang
parent 331c6f4d38
commit c39daa3c01
7 changed files with 689 additions and 655 deletions

View File

@ -13,7 +13,7 @@
#include "common/common_types.h"
#include "common/logging/log.h"
#include "core/core_timing.h"
#include "core/hle/service/dsp_dsp.h"
#include "core/hle/service/dsp/dsp_dsp.h"
namespace AudioCore {
@ -231,7 +231,7 @@ void DspHle::Impl::AudioPipeWriteStructAddresses() {
WriteU16(DspPipe::Audio, addr);
}
// Signal that we have data on this pipe.
Service::DSP_DSP::SignalPipeInterrupt(DspPipe::Audio);
Service::DSP::SignalPipeInterrupt(DspPipe::Audio);
}
size_t DspHle::Impl::CurrentRegionIndex() const {
@ -307,9 +307,9 @@ bool DspHle::Impl::Tick() {
void DspHle::Impl::AudioTickCallback(int cycles_late) {
if (Tick()) {
// TODO(merry): Signal all the other interrupts as appropriate.
Service::DSP_DSP::SignalPipeInterrupt(DspPipe::Audio);
Service::DSP::SignalPipeInterrupt(DspPipe::Audio);
// HACK(merry): Added to prevent regressions. Will remove soon.
Service::DSP_DSP::SignalPipeInterrupt(DspPipe::Binary);
Service::DSP::SignalPipeInterrupt(DspPipe::Binary);
}
// Reschedule recurrent event

View File

@ -224,8 +224,8 @@ add_library(core STATIC
hle/service/dlp/dlp_fkcl.h
hle/service/dlp/dlp_srvr.cpp
hle/service/dlp/dlp_srvr.h
hle/service/dsp_dsp.cpp
hle/service/dsp_dsp.h
hle/service/dsp/dsp_dsp.cpp
hle/service/dsp/dsp_dsp.h
hle/service/err_f.cpp
hle/service/err_f.h
hle/service/frd/frd.cpp

View File

@ -0,0 +1,418 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "audio_core/audio_types.h"
#include "common/assert.h"
#include "common/hash.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/process.h"
#include "core/hle/service/dsp/dsp_dsp.h"
using DspPipe = AudioCore::DspPipe;
using InterruptType = Service::DSP::DSP_DSP::InterruptType;
namespace AudioCore {
enum class DspPipe;
}
namespace Service {
namespace DSP {
static std::weak_ptr<DSP_DSP> dsp_dsp;
void DSP_DSP::RecvData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x01, 1, 0);
const u32 register_number = rp.Pop<u32>();
ASSERT_MSG(register_number == 0, "Unknown register_number {}", register_number);
// Application reads this after requesting DSP shutdown, to verify the DSP has indeed shutdown
// or slept.
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
switch (Core::DSP().GetDspState()) {
case AudioCore::DspState::On:
rb.Push<u32>(0);
break;
case AudioCore::DspState::Off:
case AudioCore::DspState::Sleeping:
rb.Push<u32>(1);
break;
default:
UNREACHABLE();
break;
}
LOG_DEBUG(Service_DSP, "register_number={}", register_number);
}
void DSP_DSP::RecvDataIsReady(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x02, 1, 0);
const u32 register_number = rp.Pop<u32>();
ASSERT_MSG(register_number == 0, "Unknown register_number {}", register_number);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
rb.Push(true); /// 0 = not ready, 1 = ready to read
LOG_DEBUG(Service_DSP, "register_number={}", register_number);
}
void DSP_DSP::SetSemaphore(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x07, 1, 0);
const u16 semaphore_value = rp.Pop<u16>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_DSP, "(STUBBED) called, semaphore_value={:04X}", semaphore_value);
}
void DSP_DSP::ConvertProcessAddressFromDspDram(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x0C, 1, 0);
const u32 address = rp.Pop<u32>();
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
// TODO(merry): There is a per-region offset missing in this calculation (that seems to be
// always zero).
rb.Push<u32>((address << 1) + (Memory::DSP_RAM_VADDR + 0x40000));
LOG_DEBUG(Service_DSP, "address=0x{:08X}", address);
}
void DSP_DSP::WriteProcessPipe(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x0D, 2, 2);
const u32 channel = rp.Pop<u32>();
const u32 size = rp.Pop<u32>();
auto buffer = rp.PopStaticBuffer();
const DspPipe pipe = static_cast<DspPipe>(channel);
// This behaviour was confirmed by RE.
// The likely reason for this is that games tend to pass in garbage at these bytes
// because they read random bytes off the stack.
switch (pipe) {
case DspPipe::Audio:
ASSERT(buffer.size() >= 4);
buffer[2] = 0;
buffer[3] = 0;
break;
case DspPipe::Binary:
ASSERT(buffer.size() >= 8);
buffer[4] = 1;
buffer[5] = 0;
buffer[6] = 0;
buffer[7] = 0;
break;
}
Core::DSP().PipeWrite(pipe, buffer);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_DEBUG(Service_DSP, "channel={}, size=0x{:X}, buffer_size={:X}", channel, size,
buffer.size());
}
void DSP_DSP::ReadPipe(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x0E, 3, 0);
const u32 channel = rp.Pop<u32>();
const u32 peer = rp.Pop<u32>();
const u16 size = rp.Pop<u16>();
const DspPipe pipe = static_cast<DspPipe>(channel);
const u16 pipe_readable_size = static_cast<u16>(Core::DSP().GetPipeReadableSize(pipe));
std::vector<u8> pipe_buffer;
if (pipe_readable_size >= size)
pipe_buffer = Core::DSP().PipeRead(pipe, size);
else
UNREACHABLE(); // No more data is in pipe. Hardware hangs in this case; Should never happen.
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(RESULT_SUCCESS);
rb.PushStaticBuffer(std::move(pipe_buffer), 0);
LOG_DEBUG(Service_DSP, "channel={}, peer={}, size=0x{:04X}, pipe_readable_size=0x{:04X}",
channel, peer, size, pipe_readable_size);
}
void DSP_DSP::GetPipeReadableSize(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x0F, 2, 0);
const u32 channel = rp.Pop<u32>();
const u32 peer = rp.Pop<u32>();
const DspPipe pipe = static_cast<DspPipe>(channel);
const u16 pipe_readable_size = static_cast<u16>(Core::DSP().GetPipeReadableSize(pipe));
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
rb.Push<u16>(pipe_readable_size);
LOG_DEBUG(Service_DSP, "channel={}, peer={}, return pipe_readable_size=0x{:04X}", channel, peer,
pipe_readable_size);
}
void DSP_DSP::ReadPipeIfPossible(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x10, 3, 0);
const u32 channel = rp.Pop<u32>();
const u32 peer = rp.Pop<u32>();
const u16 size = rp.Pop<u16>();
const DspPipe pipe = static_cast<DspPipe>(channel);
const u16 pipe_readable_size = static_cast<u16>(Core::DSP().GetPipeReadableSize(pipe));
std::vector<u8> pipe_buffer;
if (pipe_readable_size >= size)
pipe_buffer = Core::DSP().PipeRead(pipe, size);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
rb.Push(RESULT_SUCCESS);
rb.Push<u16>(pipe_readable_size);
rb.PushStaticBuffer(pipe_buffer, 0);
LOG_DEBUG(Service_DSP, "channel={}, peer={}, size=0x{:04X}, pipe_readable_size=0x{:04X}",
channel, peer, size, pipe_readable_size);
}
void DSP_DSP::LoadComponent(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x11, 3, 2);
const u32 size = rp.Pop<u32>();
const u32 prog_mask = rp.Pop<u32>();
const u32 data_mask = rp.Pop<u32>();
auto& buffer = rp.PopMappedBuffer();
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
rb.Push(RESULT_SUCCESS);
rb.Push(true); /// Pretend that we actually loaded the DSP firmware
rb.PushMappedBuffer(buffer);
// TODO(bunnei): Implement real DSP firmware loading
std::vector<u8> component_data(size);
buffer.Read(component_data.data(), 0, size);
LOG_INFO(Service_DSP, "Firmware hash: {:#018x}",
Common::ComputeHash64(component_data.data(), component_data.size()));
// Some versions of the firmware have the location of DSP structures listed here.
if (size > 0x37C) {
LOG_INFO(Service_DSP, "Structures hash: {:#018x}",
Common::ComputeHash64(component_data.data() + 0x340, 60));
}
LOG_WARNING(Service_DSP, "(STUBBED) called size=0x{:X}, prog_mask=0x{:08X}, data_mask=0x{:08X}",
size, prog_mask, data_mask);
}
void DSP_DSP::FlushDataCache(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x13, 2, 2);
const VAddr address = rp.Pop<u32>();
const u32 size = rp.Pop<u32>();
const auto process = rp.PopObject<Kernel::Process>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_TRACE(Service_DSP, "called address=0x{:08X}, size=0x{:X}, process={}", address, size,
process->process_id);
}
void DSP_DSP::InvalidateDataCache(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x14, 2, 2);
const VAddr address = rp.Pop<u32>();
const u32 size = rp.Pop<u32>();
const auto process = rp.PopObject<Kernel::Process>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_TRACE(Service_DSP, "called address=0x{:08X}, size=0x{:X}, process={}", address, size,
process->process_id);
}
void DSP_DSP::RegisterInterruptEvents(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x15, 2, 2);
const u32 interrupt = rp.Pop<u32>();
const u32 channel = rp.Pop<u32>();
auto event = rp.PopObject<Kernel::Event>();
ASSERT_MSG(interrupt < NUM_INTERRUPT_TYPE && channel < AudioCore::num_dsp_pipe,
"Invalid type or pipe: interrupt = {}, channel = {}", interrupt, channel);
const InterruptType type = static_cast<InterruptType>(interrupt);
const DspPipe pipe = static_cast<DspPipe>(channel);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
if (event) { /// Register interrupt event
if (HasTooManyEventsRegistered()) {
LOG_INFO(Service_DSP,
"Ran out of space to register interrupts (Attempted to register "
"interrupt={}, channel={}, event={})",
interrupt, channel, event->GetName());
rb.Push(ResultCode(ErrorDescription::InvalidResultValue, ErrorModule::DSP,
ErrorSummary::OutOfResource, ErrorLevel::Status));
return;
} else {
GetInterruptEvent(type, pipe) = event;
LOG_INFO(Service_DSP, "Registered interrupt={}, channel={}, event={}", interrupt,
channel, event->GetName());
}
} else { /// Otherwise unregister event
GetInterruptEvent(type, pipe) = nullptr;
LOG_INFO(Service_DSP, "Unregistered interrupt={}, channel={}", interrupt, channel);
}
rb.Push(RESULT_SUCCESS);
}
void DSP_DSP::GetSemaphoreEventHandle(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x16, 0, 0);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(semaphore_event);
LOG_WARNING(Service_DSP, "(STUBBED) called");
}
void DSP_DSP::SetSemaphoreMask(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x17, 1, 0);
const u32 mask = rp.Pop<u32>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x{:08X}", mask);
}
void DSP_DSP::GetHeadphoneStatus(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x1F, 0, 0);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS);
rb.Push(false); /// u8, 0 = not inserted, 1 = inserted
LOG_DEBUG(Service_DSP, "called");
}
void DSP_DSP::ForceHeadphoneOut(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x20, 1, 0);
const u8 force = rp.Pop<u8>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
LOG_DEBUG(Service_DSP, "(STUBBED) called, force={}", force);
}
void DSP_DSP::SignalInterrupt(InterruptType type, DspPipe pipe) {
LOG_DEBUG(Service_DSP, "called, type={}, pipe={}", static_cast<u32>(type),
static_cast<u32>(pipe));
const auto& event = GetInterruptEvent(type, pipe);
if (event)
event->Signal();
}
Kernel::SharedPtr<Kernel::Event>& DSP_DSP::GetInterruptEvent(InterruptType type, DspPipe pipe) {
switch (type) {
case InterruptType::Zero:
return interrupt_zero;
case InterruptType::One:
return interrupt_one;
case InterruptType::Pipe: {
const size_t pipe_index = static_cast<size_t>(pipe);
ASSERT(pipe_index < AudioCore::num_dsp_pipe);
return pipes[pipe_index];
}
}
UNREACHABLE_MSG("Invalid interrupt type = {}", static_cast<size_t>(type));
}
bool DSP_DSP::HasTooManyEventsRegistered() const {
size_t number =
std::count_if(pipes.begin(), pipes.end(), [](const auto& evt) { return evt != nullptr; });
if (interrupt_zero != nullptr)
number++;
if (interrupt_one != nullptr)
number++;
LOG_DEBUG(Service_DSP, "Number of events registered = {}", number);
return number >= max_number_of_interrupt_events;
}
DSP_DSP::DSP_DSP() : ServiceFramework("dsp::DSP", DefaultMaxSessions) {
static const FunctionInfo functions[] = {
// clang-format off
{0x00010040, &DSP_DSP::RecvData, "RecvData"},
{0x00020040, &DSP_DSP::RecvDataIsReady, "RecvDataIsReady"},
{0x00030080, nullptr, "SendData"},
{0x00040040, nullptr, "SendDataIsEmpty"},
{0x000500C2, nullptr, "SendFifoEx"},
{0x000600C0, nullptr, "RecvFifoEx"},
{0x00070040, &DSP_DSP::SetSemaphore, "SetSemaphore"},
{0x00080000, nullptr, "GetSemaphore"},
{0x00090040, nullptr, "ClearSemaphore"},
{0x000A0040, nullptr, "MaskSemaphore"},
{0x000B0000, nullptr, "CheckSemaphoreRequest"},
{0x000C0040, &DSP_DSP::ConvertProcessAddressFromDspDram, "ConvertProcessAddressFromDspDram"},
{0x000D0082, &DSP_DSP::WriteProcessPipe, "WriteProcessPipe"},
{0x000E00C0, &DSP_DSP::ReadPipe, "ReadPipe"},
{0x000F0080, &DSP_DSP::GetPipeReadableSize, "GetPipeReadableSize"},
{0x001000C0, &DSP_DSP::ReadPipeIfPossible, "ReadPipeIfPossible"},
{0x001100C2, &DSP_DSP::LoadComponent, "LoadComponent"},
{0x00120000, nullptr, "UnloadComponent"},
{0x00130082, &DSP_DSP::FlushDataCache, "FlushDataCache"},
{0x00140082, &DSP_DSP::InvalidateDataCache, "InvalidateDCache"},
{0x00150082, &DSP_DSP::RegisterInterruptEvents, "RegisterInterruptEvents"},
{0x00160000, &DSP_DSP::GetSemaphoreEventHandle, "GetSemaphoreEventHandle"},
{0x00170040, &DSP_DSP::SetSemaphoreMask, "SetSemaphoreMask"},
{0x00180040, nullptr, "GetPhysicalAddress"},
{0x00190040, nullptr, "GetVirtualAddress"},
{0x001A0042, nullptr, "SetIirFilterI2S1_cmd1"},
{0x001B0042, nullptr, "SetIirFilterI2S1_cmd2"},
{0x001C0082, nullptr, "SetIirFilterEQ"},
{0x001D00C0, nullptr, "ReadMultiEx_SPI2"},
{0x001E00C2, nullptr, "WriteMultiEx_SPI2"},
{0x001F0000, &DSP_DSP::GetHeadphoneStatus, "GetHeadphoneStatus"},
{0x00200040, &DSP_DSP::ForceHeadphoneOut, "ForceHeadphoneOut"},
{0x00210000, nullptr, "GetIsDspOccupied"},
// clang-format on
};
RegisterHandlers(functions);
semaphore_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event");
}
DSP_DSP::~DSP_DSP() {
semaphore_event = nullptr;
pipes = {};
}
// DSP Interrupts:
// The audio-pipe interrupt occurs every frame tick. Userland programs normally have a thread
// that's waiting for an interrupt event. Immediately after this interrupt event, userland
// normally updates the state in the next region and increments the relevant frame counter by two.
void SignalPipeInterrupt(DspPipe pipe) {
auto dsp = dsp_dsp.lock();
ASSERT(dsp != nullptr);
return dsp->SignalInterrupt(InterruptType::Pipe, pipe);
}
void InstallInterfaces(SM::ServiceManager& service_manager) {
auto dsp = std::make_shared<DSP_DSP>();
dsp->InstallAsService(service_manager);
dsp_dsp = dsp;
}
} // namespace DSP
} // namespace Service

View File

@ -0,0 +1,263 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include "audio_core/dsp_interface.h"
#include "core/hle/kernel/event.h"
#include "core/hle/result.h"
#include "core/hle/service/service.h"
namespace Service {
namespace DSP {
class DSP_DSP final : public ServiceFramework<DSP_DSP> {
public:
DSP_DSP();
~DSP_DSP();
/// There are three types of interrupts
static constexpr size_t NUM_INTERRUPT_TYPE = 3;
enum class InterruptType : u32 { Zero = 0, One = 1, Pipe = 2 };
/// Actual service implementation only has 6 'slots' for interrupts.
static constexpr size_t max_number_of_interrupt_events = 6;
/// Signal interrupt on pipe
void SignalInterrupt(InterruptType type, AudioCore::DspPipe pipe);
private:
/**
* DSP_DSP::RecvData service function
* This function reads a value out of a DSP register.
* Inputs:
* 0 : Header Code[0x00010040]
* 1 : Register Number
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : u16, Value in the register
* Notes:
* This function has only been observed being called with a register number of 0.
*/
void RecvData(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::RecvDataIsReady service function
* This function checks whether a DSP register is ready to be read.
* Inputs:
* 0 : Header Code[0x00020040]
* 1 : Register Number
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Reply Register Update Flag (0 = not ready, 1 = ready)
* Note:
* This function has only been observed being called with a register number of 0.
*/
void RecvDataIsReady(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::SetSemaphore service function
* Inputs:
* 0 : Header Code[0x00070040]
* 1 : u16, Semaphore value
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetSemaphore(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::ConvertProcessAddressFromDspDram service function
* Inputs:
* 0 : Header Code[0x000C0040]
* 1 : Address
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Address. (inaddr << 1) + 0x1FF40000 (where 0x1FF00000 is the DSP RAM address)
*/
void ConvertProcessAddressFromDspDram(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::WriteProcessPipe service function
* Inputs:
* 0 : Header Code[0x000D0082]
* 1 : Channel (0 - 7 0:Debug from DSP 1:P-DMA 2:audio 3:binary 4-7: free ?)
* 2 : Size
* 3 : (size << 14) | 0x402
* 4 : Buffer
* Outputs:
* 0 : Return header
* 1 : Result of function, 0 on success, otherwise error code
*/
void WriteProcessPipe(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::ReadPipe service function
* Inputs:
* 0 : Header Code[0x000E00C0]
* 1 : Channel (0 - 7 0:Debug from DSP 1:P-DMA 2:audio 3:binary 4-7: free ?)
* 2 : Peer (0 = from DSP, 1 = from ARM)
* 3 : u16, Size
* 0x41 : Virtual address of memory buffer to write pipe contents to
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void ReadPipe(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::GetPipeReadableSize service function
* Inputs:
* 0 : Header Code[0x000F0080]
* 1 : Channel (0 - 7 0:Debug from DSP 1:P-DMA 2:audio 3:binary 4-7: free ?)
* 2 : Peer (0 = from DSP, 1 = from ARM)
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : u16, Readable size
*/
void GetPipeReadableSize(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::ReadPipeIfPossible service function
* A pipe is a means of communication between the ARM11 and DSP that occurs on
* hardware by writing to/reading from the DSP registers at 0x10203000.
* Pipes are used for initialisation. See also DspInterface::PipeRead.
* Inputs:
* 0 : Header Code[0x001000C0]
* 1 : Channel (0 - 7 0:Debug from DSP 1:P-DMA 2:audio 3:binary 4-7: free ?)
* 2 : Peer (0 = from DSP, 1 = from ARM)
* 3 : u16, Size
* 0x41 : Virtual address of memory buffer to write pipe contents to
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : u16, Actual read size
*/
void ReadPipeIfPossible(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::LoadComponent service function
* Inputs:
* 0 : Header Code[0x001100C2]
* 1 : Size
* 2 : Program mask (observed only half word used)
* 3 : Data mask (observed only half word used)
* 4 : (size << 4) | 0xA
* 5 : Component Buffer
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : u8, Component Loaded (0 = not loaded, 1 = loaded)
* 3 : (Size << 4) | 0xA
* 4 : Component Buffer
*/
void LoadComponent(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::FlushDataCache service function
*
* This Function is a no-op, We aren't emulating the CPU cache any time soon.
*
* Inputs:
* 0 : Header Code[0x00130082]
* 1 : Address
* 2 : Size
* 3 : Value 0, some descriptor for the KProcess Handle
* 4 : KProcess handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void FlushDataCache(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::InvalidateDataCache service function
*
* This Function is a no-op, We aren't emulating the CPU cache any time soon.
*
* Inputs:
* 0 : Header Code[0x00140082]
* 1 : Address
* 2 : Size
* 3 : Value 0, some descriptor for the KProcess Handle
* 4 : KProcess handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void InvalidateDataCache(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::RegisterInterruptEvents service function
* Inputs:
* 0 : Header Code[0x00150082]
* 1 : Interrupt
* 2 : Channel
* 3 : 0x0, some descriptor for the Event Handle
* 4 : Interrupt Event handle (0 = unregister the event that was previous registered)
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void RegisterInterruptEvents(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::GetSemaphoreEventHandle service function
* Inputs:
* 0 : Header Code[0x00160000]
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : 0x0, some descriptor for the Event Handle
* 3 : Semaphore Event Handle
*/
void GetSemaphoreEventHandle(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::SetSemaphoreMask service function
* Inputs:
* 0 : Header Code[0x00170040]
* 1 : u16, Mask
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetSemaphoreMask(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::GetHeadphoneStatus service function
* Inputs:
* 0 : Header Code[0x001F0000]
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : u8, The headphone status response, 0 = Not inserted, 1 = inserted
*/
void GetHeadphoneStatus(Kernel::HLERequestContext& ctx);
/**
* DSP_DSP::ForceHeadphoneOut service function
* Inputs:
* 0 : Header Code[0x00020040]
* 1 : u8, 0 = don't force, 1 = force
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void ForceHeadphoneOut(Kernel::HLERequestContext& ctx);
/// Returns the Interrupt Event for a given pipe
Kernel::SharedPtr<Kernel::Event>& GetInterruptEvent(InterruptType type,
AudioCore::DspPipe pipe);
/// Checks if we are trying to register more than 6 events
bool HasTooManyEventsRegistered() const;
Kernel::SharedPtr<Kernel::Event> semaphore_event;
Kernel::SharedPtr<Kernel::Event> interrupt_zero = nullptr; /// Currently unknown purpose
Kernel::SharedPtr<Kernel::Event> interrupt_one = nullptr; /// Currently unknown purpose
/// Each DSP pipe has an associated interrupt
std::array<Kernel::SharedPtr<Kernel::Event>, AudioCore::num_dsp_pipe> pipes = {{}};
};
/**
* Signal a specific DSP related interrupt of type == InterruptType::Pipe, pipe == pipe.
* @param pipe The DSP pipe for which to signal an interrupt for.
*/
void SignalPipeInterrupt(AudioCore::DspPipe pipe);
void InstallInterfaces(SM::ServiceManager& service_manager);
} // namespace DSP
} // namespace Service

View File

@ -1,613 +0,0 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <algorithm>
#include <array>
#include <cinttypes>
#include "audio_core/audio_types.h"
#include "audio_core/dsp_interface.h"
#include "common/assert.h"
#include "common/hash.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/ipc.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/result.h"
#include "core/hle/service/dsp_dsp.h"
#include "core/memory.h"
using DspPipe = AudioCore::DspPipe;
namespace Service {
namespace DSP_DSP {
static Kernel::SharedPtr<Kernel::Event> semaphore_event;
/// There are three types of interrupts
enum class InterruptType { Zero, One, Pipe };
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 < AudioCore::num_dsp_pipe);
return pipe[pipe_index];
}
}
UNREACHABLE_MSG("Invalid interrupt type = {}", 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>, AudioCore::num_dsp_pipe> pipe = {{}};
};
static InterruptEvents interrupt_events;
// DSP Interrupts:
// The audio-pipe interrupt occurs every frame tick. Userland programs normally have a thread
// that's waiting for an interrupt event. Immediately after this interrupt event, userland
// normally updates the state in the next region and increments the relevant frame counter by
// two.
void SignalPipeInterrupt(DspPipe pipe) {
interrupt_events.Signal(InterruptType::Pipe, pipe);
}
/**
* DSP_DSP::ConvertProcessAddressFromDspDram service function
* Inputs:
* 1 : Address
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : (inaddr << 1) + 0x1FF40000 (where 0x1FF00000 is the DSP RAM address)
*/
static void ConvertProcessAddressFromDspDram(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 addr = cmd_buff[1];
cmd_buff[0] = IPC::MakeHeader(0xC, 2, 0);
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);
LOG_DEBUG(Service_DSP, "addr=0x{:08X}", addr);
}
/**
* DSP_DSP::LoadComponent service function
* Inputs:
* 1 : Size
* 2 : Program mask (observed only half word used)
* 3 : Data mask (observed only half word used)
* 4 : (size << 4) | 0xA
* 5 : Buffer address
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Component loaded, 0 on not loaded, 1 on loaded
*/
static void LoadComponent(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 size = cmd_buff[1];
u32 prog_mask = cmd_buff[2];
u32 data_mask = cmd_buff[3];
u32 desc = cmd_buff[4];
u32 buffer = cmd_buff[5];
cmd_buff[0] = IPC::MakeHeader(0x11, 2, 2);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = 1; // Pretend that we actually loaded the DSP firmware
cmd_buff[3] = desc;
cmd_buff[4] = buffer;
// TODO(bunnei): Implement real DSP firmware loading
ASSERT(Memory::IsValidVirtualAddress(buffer));
std::vector<u8> component_data(size);
Memory::ReadBlock(buffer, component_data.data(), component_data.size());
LOG_INFO(Service_DSP, "Firmware hash: {:#018x}",
Common::ComputeHash64(component_data.data(), component_data.size()));
// Some versions of the firmware have the location of DSP structures listed here.
if (size > 0x37C) {
LOG_INFO(Service_DSP, "Structures hash: {:#018x}",
Common::ComputeHash64(component_data.data() + 0x340, 60));
}
LOG_WARNING(
Service_DSP,
"(STUBBED) called size=0x{:X}, prog_mask=0x{:08X}, data_mask=0x{:08X}, buffer=0x{:08X}",
size, prog_mask, data_mask, buffer);
}
/**
* DSP_DSP::GetSemaphoreEventHandle service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 3 : Semaphore event handle
*/
static void GetSemaphoreEventHandle(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[0] = IPC::MakeHeader(0x16, 1, 2);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
// cmd_buff[2] not set
cmd_buff[3] = Kernel::g_handle_table.Create(semaphore_event).Unwrap(); // Event handle
LOG_WARNING(Service_DSP, "(STUBBED) called");
}
/**
* DSP_DSP::FlushDataCache service function
*
* This Function is a no-op, We aren't emulating the CPU cache any time soon.
*
* Inputs:
* 1 : Address
* 2 : Size
* 3 : Value 0, some descriptor for the KProcess Handle
* 4 : KProcess handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void FlushDataCache(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 address = cmd_buff[1];
u32 size = cmd_buff[2];
u32 process = cmd_buff[4];
cmd_buff[0] = IPC::MakeHeader(0x13, 1, 0);
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);
}
/**
* DSP_DSP::RegisterInterruptEvents service function
* Inputs:
* 1 : Interrupt Type
* 2 : Pipe Number
* 4 : Interrupt event handle
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void RegisterInterruptEvents(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 type_index = cmd_buff[1];
u32 pipe_index = cmd_buff[2];
u32 event_handle = cmd_buff[4];
ASSERT_MSG(type_index < NUM_INTERRUPT_TYPE && pipe_index < AudioCore::num_dsp_pipe,
"Invalid type or pipe: type = {}, pipe = {}", 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) {
auto evt = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
if (!evt) {
LOG_INFO(Service_DSP, "Invalid event handle! type={}, pipe={}, event_handle=0x{:08X}",
type_index, pipe_index, event_handle);
ASSERT(false); // TODO: This should really be handled at an IPC translation layer.
}
if (interrupt_events.HasTooManyEventsRegistered()) {
LOG_INFO(Service_DSP,
"Ran out of space to register interrupts (Attempted to register "
"type={}, pipe={}, 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={}, pipe={}, event_handle=0x{:08X}", type_index,
pipe_index, event_handle);
cmd_buff[1] = RESULT_SUCCESS.raw;
} else {
interrupt_events.Get(type, pipe) = nullptr;
LOG_INFO(Service_DSP, "Unregistered interrupt={}, channel={}, event_handle=0x{:08X}",
type_index, pipe_index, event_handle);
cmd_buff[1] = RESULT_SUCCESS.raw;
}
}
/**
* DSP_DSP::SetSemaphore service function
* Inputs:
* 1 : Unknown (observed only half word used)
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void SetSemaphore(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[0] = IPC::MakeHeader(0x7, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
LOG_WARNING(Service_DSP, "(STUBBED) called");
}
/**
* DSP_DSP::WriteProcessPipe service function
* Inputs:
* 1 : Pipe Number
* 2 : Size
* 3 : (size << 14) | 0x402
* 4 : Buffer
* Outputs:
* 0 : Return header
* 1 : Result of function, 0 on success, otherwise error code
*/
static void WriteProcessPipe(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 pipe_index = cmd_buff[1];
u32 size = cmd_buff[2];
u32 buffer = cmd_buff[4];
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
if (IPC::StaticBufferDesc(size, 1) != cmd_buff[3]) {
LOG_ERROR(Service_DSP,
"IPC static buffer descriptor failed validation (0x{:X}). pipe={}, "
"size=0x{:X}, buffer=0x{:08X}",
cmd_buff[3], pipe_index, size, buffer);
cmd_buff[0] = IPC::MakeHeader(0, 1, 0);
cmd_buff[1] = IPC::ERR_INVALID_BUFFER_DESCRIPTOR.raw;
return;
}
ASSERT_MSG(Memory::IsValidVirtualAddress(buffer),
"Invalid Buffer: pipe={}, size={:#X}, buffer={:#010X}", pipe_index, size, buffer);
std::vector<u8> message(size);
for (u32 i = 0; i < size; i++) {
message[i] = Memory::Read8(buffer + i);
}
// This behaviour was confirmed by RE.
// The likely reason for this is that games tend to pass in garbage at these bytes
// because they read random bytes off the stack.
switch (pipe) {
case AudioCore::DspPipe::Audio:
ASSERT(message.size() >= 4);
message[2] = 0;
message[3] = 0;
break;
case AudioCore::DspPipe::Binary:
ASSERT(message.size() >= 8);
message[4] = 1;
message[5] = 0;
message[6] = 0;
message[7] = 0;
break;
}
Core::DSP().PipeWrite(pipe, message);
cmd_buff[0] = IPC::MakeHeader(0xD, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
LOG_DEBUG(Service_DSP, "pipe={}, size=0x{:X}, buffer=0x{:08X}", pipe_index, size, buffer);
}
/**
* DSP_DSP::ReadPipeIfPossible service function
* A pipe is a means of communication between the ARM11 and DSP that occurs on
* hardware by writing to/reading from the DSP registers at 0x10203000.
* Pipes are used for initialisation. See also DspInterface::PipeRead.
* Inputs:
* 1 : Pipe Number
* 2 : Unknown
* 3 : Size in bytes of read (observed only lower half word used)
* 0x41 : Virtual address of memory buffer to write pipe contents to
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Number of bytes read from pipe
*/
static void ReadPipeIfPossible(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 pipe_index = cmd_buff[1];
u32 unknown = cmd_buff[2];
u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
VAddr addr = cmd_buff[0x41];
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
ASSERT_MSG(Memory::IsValidVirtualAddress(addr),
"Invalid addr: pipe={:#010X}, unknown={:#010X}, size={:#X}, buffer={:#010X}",
pipe_index, unknown, size, addr);
cmd_buff[0] = IPC::MakeHeader(0x10, 1, 2);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
if (Core::DSP().GetPipeReadableSize(pipe) >= size) {
std::vector<u8> response = Core::DSP().PipeRead(pipe, size);
Memory::WriteBlock(addr, response.data(), response.size());
cmd_buff[2] = static_cast<u32>(response.size());
} else {
cmd_buff[2] = 0; // Return no data
}
cmd_buff[3] = IPC::StaticBufferDesc(size, 0);
cmd_buff[4] = addr;
LOG_DEBUG(
Service_DSP,
"pipe={}, unknown=0x{:08X}, size=0x{:X}, buffer=0x{:08X}, return cmd_buff[2]=0x{:08X}",
pipe_index, unknown, size, addr, cmd_buff[2]);
}
/**
* DSP_DSP::ReadPipe service function
* Inputs:
* 1 : Pipe Number
* 2 : Unknown
* 3 : Size in bytes of read (observed only lower half word used)
* 0x41 : Virtual address of memory buffer to write pipe contents to
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Number of bytes read from pipe
*/
static void ReadPipe(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 pipe_index = cmd_buff[1];
u32 unknown = cmd_buff[2];
u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
VAddr addr = cmd_buff[0x41];
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
ASSERT_MSG(Memory::IsValidVirtualAddress(addr),
"Invalid addr: pipe={:#010X}, unknown={:#010X}, size={:#X}, buffer={:#010X}",
pipe_index, unknown, size, addr);
if (Core::DSP().GetPipeReadableSize(pipe) >= size) {
std::vector<u8> response = Core::DSP().PipeRead(pipe, 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[2] = static_cast<u32>(response.size());
cmd_buff[3] = IPC::StaticBufferDesc(size, 0);
cmd_buff[4] = addr;
} else {
// No more data is in pipe. Hardware hangs in this case; this should never happen.
UNREACHABLE();
}
LOG_DEBUG(
Service_DSP,
"pipe={}, unknown=0x{:08X}, size=0x{:X}, buffer=0x{:08X}, return cmd_buff[2]=0x{:08X}",
pipe_index, unknown, size, addr, cmd_buff[2]);
}
/**
* DSP_DSP::GetPipeReadableSize service function
* Inputs:
* 1 : Pipe Number
* 2 : Unknown
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Number of bytes readable from pipe
*/
static void GetPipeReadableSize(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 pipe_index = cmd_buff[1];
u32 unknown = cmd_buff[2];
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
cmd_buff[0] = IPC::MakeHeader(0xF, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = static_cast<u32>(Core::DSP().GetPipeReadableSize(pipe));
LOG_DEBUG(Service_DSP, "pipe={}, unknown=0x{:08X}, return cmd_buff[2]=0x{:08X}", pipe_index,
unknown, cmd_buff[2]);
}
/**
* DSP_DSP::SetSemaphoreMask service function
* Inputs:
* 1 : Mask
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void SetSemaphoreMask(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 mask = cmd_buff[1];
cmd_buff[0] = IPC::MakeHeader(0x17, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
LOG_WARNING(Service_DSP, "(STUBBED) called mask=0x{:08X}", mask);
}
/**
* DSP_DSP::GetHeadphoneStatus service function
* Inputs:
* 1 : None
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : The headphone status response, 0 = Not using headphones?,
* 1 = using headphones?
*/
static void GetHeadphoneStatus(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[0] = IPC::MakeHeader(0x1F, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = 0; // Not using headphones
LOG_DEBUG(Service_DSP, "called");
}
/**
* DSP_DSP::RecvData service function
* This function reads a value out of a DSP register.
* Inputs:
* 1 : Register Number
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Value in the register
* Notes:
* This function has only been observed being called with a register number of 0.
*/
static void RecvData(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 register_number = cmd_buff[1];
ASSERT_MSG(register_number == 0, "Unknown register_number {}", register_number);
// 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;
switch (Core::DSP().GetDspState()) {
case AudioCore::DspState::On:
cmd_buff[2] = 0;
break;
case AudioCore::DspState::Off:
case AudioCore::DspState::Sleeping:
cmd_buff[2] = 1;
break;
default:
UNREACHABLE();
break;
}
LOG_DEBUG(Service_DSP, "register_number={}", register_number);
}
/**
* DSP_DSP::RecvDataIsReady service function
* This function checks whether a DSP register is ready to be read.
* Inputs:
* 1 : Register Number
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : non-zero == ready
* Note:
* This function has only been observed being called with a register number of 0.
*/
static void RecvDataIsReady(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 register_number = cmd_buff[1];
ASSERT_MSG(register_number == 0, "Unknown register_number {}", register_number);
cmd_buff[0] = IPC::MakeHeader(0x2, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = 1; // Ready to read
LOG_DEBUG(Service_DSP, "register_number={}", register_number);
}
const Interface::FunctionInfo FunctionTable[] = {
{0x00010040, RecvData, "RecvData"},
{0x00020040, RecvDataIsReady, "RecvDataIsReady"},
{0x00030080, nullptr, "SendData"},
{0x00040040, nullptr, "SendDataIsEmpty"},
{0x000500C2, nullptr, "SendFifoEx"},
{0x000600C0, nullptr, "RecvFifoEx"},
{0x00070040, SetSemaphore, "SetSemaphore"},
{0x00080000, nullptr, "GetSemaphore"},
{0x00090040, nullptr, "ClearSemaphore"},
{0x000A0040, nullptr, "MaskSemaphore"},
{0x000B0000, nullptr, "CheckSemaphoreRequest"},
{0x000C0040, ConvertProcessAddressFromDspDram, "ConvertProcessAddressFromDspDram"},
{0x000D0082, WriteProcessPipe, "WriteProcessPipe"},
{0x000E00C0, ReadPipe, "ReadPipe"},
{0x000F0080, GetPipeReadableSize, "GetPipeReadableSize"},
{0x001000C0, ReadPipeIfPossible, "ReadPipeIfPossible"},
{0x001100C2, LoadComponent, "LoadComponent"},
{0x00120000, nullptr, "UnloadComponent"},
{0x00130082, FlushDataCache, "FlushDataCache"},
{0x00140082, nullptr, "InvalidateDCache"},
{0x00150082, RegisterInterruptEvents, "RegisterInterruptEvents"},
{0x00160000, GetSemaphoreEventHandle, "GetSemaphoreEventHandle"},
{0x00170040, SetSemaphoreMask, "SetSemaphoreMask"},
{0x00180040, nullptr, "GetPhysicalAddress"},
{0x00190040, nullptr, "GetVirtualAddress"},
{0x001A0042, nullptr, "SetIirFilterI2S1_cmd1"},
{0x001B0042, nullptr, "SetIirFilterI2S1_cmd2"},
{0x001C0082, nullptr, "SetIirFilterEQ"},
{0x001D00C0, nullptr, "ReadMultiEx_SPI2"},
{0x001E00C2, nullptr, "WriteMultiEx_SPI2"},
{0x001F0000, GetHeadphoneStatus, "GetHeadphoneStatus"},
{0x00200040, nullptr, "ForceHeadphoneOut"},
{0x00210000, nullptr, "GetIsDspOccupied"},
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Interface class
Interface::Interface() {
semaphore_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "DSP_DSP::semaphore_event");
interrupt_events = {};
Register(FunctionTable);
}
Interface::~Interface() {
semaphore_event = nullptr;
interrupt_events = {};
}
} // namespace DSP_DSP
} // namespace Service

View File

@ -1,34 +0,0 @@
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "core/hle/service/service.h"
namespace AudioCore {
enum class DspPipe;
}
namespace Service {
namespace DSP_DSP {
class Interface final : public Service::Interface {
public:
Interface();
~Interface() override;
std::string GetPortName() const override {
return "dsp::DSP";
}
};
/**
* Signal a specific DSP related interrupt of type == InterruptType::Pipe, pipe == pipe.
* @param pipe The DSP pipe for which to signal an interrupt for.
*/
void SignalPipeInterrupt(AudioCore::DspPipe pipe);
} // namespace DSP_DSP
} // namespace Service

View File

@ -24,7 +24,7 @@
#include "core/hle/service/cfg/cfg.h"
#include "core/hle/service/csnd_snd.h"
#include "core/hle/service/dlp/dlp.h"
#include "core/hle/service/dsp_dsp.h"
#include "core/hle/service/dsp/dsp_dsp.h"
#include "core/hle/service/err_f.h"
#include "core/hle/service/frd/frd.h"
#include "core/hle/service/fs/archive.h"
@ -242,6 +242,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm) {
CECD::InstallInterfaces(*sm);
CFG::InstallInterfaces(*sm);
DLP::InstallInterfaces(*sm);
DSP::InstallInterfaces(*sm);
FRD::InstallInterfaces(*sm);
GSP::InstallInterfaces(*sm);
HID::InstallInterfaces(*sm);
@ -255,7 +256,6 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm) {
QTM::InstallInterfaces(*sm);
CSND::InstallInterfaces(*sm);
AddService(new DSP_DSP::Interface);
AddService(new HTTP::HTTP_C);
PM::InstallInterfaces(*sm);
AddService(new SOC::SOC_U);