2014-11-12 21:13:08 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-12 21:13:08 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-10-28 20:10:21 +00:00
|
|
|
#include <cstring>
|
2016-04-18 02:07:52 +00:00
|
|
|
#include "common/alignment.h"
|
2017-06-06 08:29:46 +00:00
|
|
|
#include "core/hle/ipc.h"
|
|
|
|
#include "core/hle/kernel/handle_table.h"
|
2015-10-27 21:40:34 +00:00
|
|
|
#include "core/hle/kernel/mutex.h"
|
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
2016-09-21 06:52:38 +00:00
|
|
|
#include "core/hle/service/csnd_snd.h"
|
2017-06-06 08:29:46 +00:00
|
|
|
#include "core/memory.h"
|
2014-11-12 21:13:08 +00:00
|
|
|
|
2016-12-10 12:51:50 +00:00
|
|
|
namespace Service {
|
|
|
|
namespace CSND {
|
2014-11-12 21:13:08 +00:00
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
struct Type0Command {
|
|
|
|
// command id and next command offset
|
|
|
|
u32 command_id;
|
|
|
|
u32 finished;
|
|
|
|
u32 flags;
|
|
|
|
u8 parameters[20];
|
2014-11-12 21:13:08 +00:00
|
|
|
};
|
2016-12-08 09:11:54 +00:00
|
|
|
static_assert(sizeof(Type0Command) == 0x20, "Type0Command structure size is wrong");
|
2014-11-12 21:13:08 +00:00
|
|
|
|
2015-10-27 21:40:34 +00:00
|
|
|
static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory = nullptr;
|
|
|
|
static Kernel::SharedPtr<Kernel::Mutex> mutex = nullptr;
|
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
/**
|
|
|
|
* CSND_SND::Initialize service function
|
|
|
|
* Inputs:
|
|
|
|
* 0 : Header Code[0x00010140]
|
|
|
|
* 1 : Shared memory block size, for mem-block creation
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : Handle-list header
|
|
|
|
* 3 : Mutex handle
|
|
|
|
* 4 : Shared memory block handle
|
|
|
|
*/
|
|
|
|
static void Initialize(Interface* self) {
|
2015-10-27 21:40:34 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
2016-04-18 02:07:52 +00:00
|
|
|
u32 size = Common::AlignUp(cmd_buff[1], Memory::PAGE_SIZE);
|
2016-12-08 09:11:54 +00:00
|
|
|
|
2016-04-18 02:07:52 +00:00
|
|
|
using Kernel::MemoryPermission;
|
2016-09-18 00:38:01 +00:00
|
|
|
shared_memory = Kernel::SharedMemory::Create(nullptr, size, MemoryPermission::ReadWrite,
|
|
|
|
MemoryPermission::ReadWrite, 0,
|
|
|
|
Kernel::MemoryRegion::BASE, "CSND:SharedMemory");
|
2015-10-27 21:40:34 +00:00
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
mutex = Kernel::Mutex::Create(false, "CSND:mutex");
|
2015-10-27 21:40:34 +00:00
|
|
|
|
2016-04-18 02:07:52 +00:00
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
2016-07-30 16:19:00 +00:00
|
|
|
cmd_buff[2] = IPC::CopyHandleDesc(2);
|
2017-06-19 02:03:15 +00:00
|
|
|
cmd_buff[3] = Kernel::g_handle_table.Create(mutex).Unwrap();
|
|
|
|
cmd_buff[4] = Kernel::g_handle_table.Create(shared_memory).Unwrap();
|
2016-12-08 09:11:54 +00:00
|
|
|
|
2018-06-19 23:30:59 +00:00
|
|
|
NGLOG_WARNING(Service_CSND, "(STUBBED) called");
|
2015-10-27 21:40:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
/**
|
|
|
|
* CSND_SND::Shutdown service function
|
|
|
|
* Inputs:
|
|
|
|
* 0 : Header Code[0x00020000]
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
*/
|
|
|
|
static void Shutdown(Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
shared_memory = nullptr;
|
|
|
|
mutex = nullptr;
|
2015-10-28 20:10:21 +00:00
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
2018-06-19 23:30:59 +00:00
|
|
|
NGLOG_WARNING(Service_CSND, "(STUBBED) called");
|
2016-12-08 09:11:54 +00:00
|
|
|
}
|
2015-10-28 20:10:21 +00:00
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
/**
|
|
|
|
* CSND_SND::ExecuteCommands service function
|
|
|
|
* Inputs:
|
|
|
|
* 0 : Header Code[0x00030040]
|
|
|
|
* 1 : Command offset in shared memory.
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : Available channel bit mask
|
|
|
|
*/
|
|
|
|
static void ExecuteCommands(Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
2015-10-27 21:40:34 +00:00
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
if (shared_memory == nullptr) {
|
2015-10-27 21:40:34 +00:00
|
|
|
cmd_buff[1] = 1;
|
2018-06-19 23:30:59 +00:00
|
|
|
NGLOG_ERROR(Service_CSND, "called, shared memory not allocated");
|
2016-12-08 09:11:54 +00:00
|
|
|
return;
|
2015-10-27 21:40:34 +00:00
|
|
|
}
|
2016-12-08 09:11:54 +00:00
|
|
|
|
|
|
|
VAddr addr = cmd_buff[1];
|
|
|
|
u8* ptr = shared_memory->GetPointer(addr);
|
|
|
|
|
|
|
|
Type0Command command;
|
|
|
|
std::memcpy(&command, ptr, sizeof(Type0Command));
|
|
|
|
command.finished |= 1;
|
|
|
|
std::memcpy(ptr, &command, sizeof(Type0Command));
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
|
|
|
|
2018-06-19 23:30:59 +00:00
|
|
|
NGLOG_WARNING(Service_CSND, "(STUBBED) called, addr=0x{:08X}", addr);
|
2015-10-27 21:40:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
/**
|
|
|
|
* CSND_SND::AcquireSoundChannels service function
|
|
|
|
* Inputs:
|
|
|
|
* 0 : Header Code[0x00050000]
|
|
|
|
* Outputs:
|
|
|
|
* 1 : Result of function, 0 on success, otherwise error code
|
|
|
|
* 2 : Available channel bit mask
|
|
|
|
*/
|
|
|
|
static void AcquireSoundChannels(Interface* self) {
|
2015-10-27 21:40:34 +00:00
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
2016-12-08 09:11:54 +00:00
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
2015-10-27 21:40:34 +00:00
|
|
|
cmd_buff[2] = 0xFFFFFF00;
|
2018-06-19 23:30:59 +00:00
|
|
|
NGLOG_WARNING(Service_CSND, "(STUBBED) called");
|
2015-10-27 21:40:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 09:11:54 +00:00
|
|
|
const Interface::FunctionInfo FunctionTable[] = {
|
|
|
|
{0x00010140, Initialize, "Initialize"},
|
|
|
|
{0x00020000, Shutdown, "Shutdown"},
|
|
|
|
{0x00030040, ExecuteCommands, "ExecuteCommands"},
|
|
|
|
{0x00040080, nullptr, "ExecuteType1Commands"},
|
|
|
|
{0x00050000, AcquireSoundChannels, "AcquireSoundChannels"},
|
|
|
|
{0x00060000, nullptr, "ReleaseSoundChannels"},
|
|
|
|
{0x00070000, nullptr, "AcquireCaptureDevice"},
|
|
|
|
{0x00080040, nullptr, "ReleaseCaptureDevice"},
|
|
|
|
{0x00090082, nullptr, "FlushDataCache"},
|
|
|
|
{0x000A0082, nullptr, "StoreDataCache"},
|
|
|
|
{0x000B0082, nullptr, "InvalidateDataCache"},
|
|
|
|
{0x000C0000, nullptr, "Reset"},
|
|
|
|
};
|
|
|
|
|
|
|
|
CSND_SND::CSND_SND() {
|
|
|
|
Register(FunctionTable);
|
2015-10-27 21:40:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-10 12:51:50 +00:00
|
|
|
} // namespace CSND
|
|
|
|
} // namespace Service
|